//======================================================
// 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.
//======================================================

#include "common.h"
#include <stdlib.h>

//========================
// Main Routine
//========================
int main(void)
{
    volatile UI32 count;

    #ifdef DEBUG
    debug();
    #endif
    
    //-----------------------
    // Initialize Hardware
    //-----------------------
    Set_System();   // Initialize Clocks
    Init_NVIC();    // Initialize Interrupts with 1ms SysTick
  
    //--------------------
    // Debug Sample
    //--------------------
    count = 0;
    while(1)
    {
        count++;
    }
}

//=============================
// SysTick Handler
//=============================
void Handler_SysTick(void)
{
    static UI32 time_1sec = 0;
    
    time_1sec = (time_1sec + 1) % 1000;
    if (time_1sec == 0)
    {
        Toggle_LED();
    }
}

//=============================
// Toggle LED
//=============================
void Toggle_LED(void)
{
    UI16 od_gpioc;
    
    od_gpioc = GPIO_ReadOutputData(GPIOC);
    if (od_gpioc & 0x0040)
    {
        GPIO_ResetBits(GPIOC, GPIO_Pin_6);
    }
    else
    {
        GPIO_SetBits(GPIOC, GPIO_Pin_6);
    }
}

#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
//======================================================
