//======================================================
// LED
//======================================================
// File Name : main.c
// Function  : Main Routine
//------------------------------------------------------
// Rev.01 2008.03.24 Takanaga Yamazaki
//------------------------------------------------------
// (C) Copyright 2008 Takanaga Yamazaki
//======================================================
// ---- License Information ----------------------------
// Anyone can FREELY use this code fully or partially
// under conditions shown below.
// 1. You should use this code under the GNU GPL.
// 2. You should remain this header text in your codes
//   including Copyright credit and License Information.
// 3. Your codes should inherit this license information.
//======================================================
// ---- Patent Notice ----------------------------------
// I have not cared whether this system (hw + sw) causes 
// infringement on the patent, copyright, trademark,
// or trade secret rights of others. You have all 
// responsibilities for determining if your designs
// and products infringe on the intellectual property
// rights of others, when you use technical information
// included in this system for your business.
//======================================================
// ---- Disclaimers ------------------------------------
// The function and reliability of this system are not 
// guaranteed. They may cause any damages to loss of
// properties, data, money, profits, life, or business.
// By adopting this sytem even partially, you assume
// all responsibility for its use.
//======================================================

/******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
* File Name          : main.c
* Author             : MCD Application Team
* Version            : V1.0
* Date               : 10/08/2007
* Description        : Virtual Com Port Demo main file
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/

/* Includes ------------------------------------------------------------------*/
#include "common.h"
#include <stdlib.h>

//#include "stm32f10x_it.h"
//#include "stm32f10x_lib.h"
//#include "usb_lib.h"
//#include "usb_desc.h"
//#include "hw_config.h"
//#include <stdio.h>
#include <string.h>
#include <math.h>

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Extern variables ----------------------------------------------------------*/
extern u32 count_in;
extern u32 count_out;
extern u8 buffer_out[VIRTUAL_COM_PORT_DATA_SIZE];

volatile FLOT fvar = 0.0;

/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/


//void To_USB_Send_Data(char* buf)
//{
//  count_in = strlen(buf);
//  UserToPMABufferCopy((u8 *)buf, ENDP1_TXADDR, count_in);
//  SetEPTxCount(ENDP1, count_in);
//  SetEPTxValid(ENDP1);
//}

/*******************************************************************************
* Function Name  : main.
* Description    : Main routine.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
int main(void)
{
    u8 mode;
    u8 count;
    volatile double ftest1, ftest2;

    Set_System();

    volatile UI32 i;
    while(1)
    {
  	    GPIO_SetBits(GPIOC, GPIO_Pin_6);
  	    i = 5000000;
  	    fvar = fvar + 0.1;
  	    while(i) i--;
  	    GPIO_ResetBits(GPIOC, GPIO_Pin_6);
  	    i = 5000000;
  	    fvar = fvar + 0.1;
  	    while(i) i--;  	    
    }
    
    UI08 *ptr;
    
    ptr = (UI08*) malloc(sizeof(UI08) * 100);

#ifdef DEBUG
  debug();
#endif
  
  Set_USBClock();
  USB_Interrupts_Config();
  USB_Init();
  
  count = 0;

  while(1)
  {
    mode = 0;
    
    ftest1 = 1.23;
    ftest2 = sin(ftest1) * -3.14;
    
    GPIO_SetBits(GPIOC, GPIO_Pin_6);

    if (count_out != 0)
    {
      if (memcmp(buffer_out, "*", 1) == 0) mode = 1;
      
       count_out = 0;
    }
    
    if (mode == 1)
    {
      USB_Put_Str((UI08*) "Welcome to Star Finder!");
      USB_Put_Int_UI32((UI32) count);
      USB_Put_CRLF();
      USB_Put_Int_SI32(1234);
      USB_Put_CRLF();
      USB_Put_Int_SI32(-567);
      USB_Put_CRLF();
      USB_Put_FLOT(ftest1, 5);
      USB_Put_CRLF();
      USB_Put_FLOT(ftest2, 5);
      USB_Put_CRLF();

    //To_USB_Send_Data((char*) local_buffer);
    //To_USB_Send_Data("Welcome\n\r");
      
      mode = 0;
      count++;
    //if (count > 9) count = 0;


    }
  }
}






#ifdef  DEBUG
/*******************************************************************************
* Function Name  : assert_failed
* Description    : Reports the name of the source file and the source line number
*                  where the assert_param error has occurred.
* Input          : - file: pointer to the source file name
*                  - line: assert_param error line source number
* Output         : None
* Return         : None
*******************************************************************************/
void assert_failed(u8* file, u32 line)
{
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  /* Infinite loop */
  while(1)
  {
  }
}
#endif

/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/

//======================================================
// End of Program
//======================================================
