
#include "mcu.h"

/*
 *  Internal Function
 */
static void InitPort(void);



int32_t main(void)
{
    uint32_t period;
    
    InitPort();

    /* set blinking interval */
    period = SystemCoreClock / 100;     // Set to 0.01sec

    /* start to blink LED */
    SysTick_Config(period);
    
    /* loop */
    for(;;) {};
    
}

/*
 *  InitPort
 */
static void InitPort(void)
{
    /*
     * Set I/O Port
     */

    /* LED */
    FM3_GPIO->PFRF_f.P3 = 0;   // PF3 set to GPIO
    FM3_GPIO->PZRF_f.P3 = 1;   // PF3 set to Open-drain mode
    FM3_GPIO->DDRF_f.P3 = 1;   // PF3 set to output
    FM3_GPIO->PDORF_f.P3 = 0;  // PF3 set to lowlevel.

}

/*
 *  SysTick_Handler
 */
void SysTick_Handler(void)
{
    static uint8_t cnt = 0;

    cnt++;
    
    /* count 50 ticks (0.5sec) */
    if (cnt >= 50) {                  
        FM3_GPIO->PDORF_f.P3 = ~FM3_GPIO->PDORF_f.P3; // invert
        cnt = 0;
    }

}
