/***********************************************************************************************
* Company: Microsemi Corporation
*
* File: main.c
* File history:
*      Revision: 1.0 Date: November 8, 2012
*
* Description:
*
*	Program to blink the LED's on the SmartFusion2 Validation Board. It also prints the status
*	messages on the Serial Console. This is intended for creating the sample application image  
*	to use in the Code Shadowing Demo's
*	
*
* Author: Corporate Applications Engineering
*
************************************************************************************************/

#include "drivers/mss_gpio/mss_gpio.h"
#include "drivers/mss_uart/mss_uart.h"
#include "CMSIS/m2sxxx.h"

void delay(int n);

/*-------------------------------------------------------------------------*//**
 * main() function.
 */
int main()
{
    uint32_t count=0;
    MSS_UART_init( &g_mss_uart1,MSS_UART_57600_BAUD,MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT );

    /*
     * Initialize MSS GPIOs.
     */
    MSS_GPIO_init();
    /*
     * Configure MSS GPIOs.
   */
    MSS_GPIO_config( MSS_GPIO_0 , MSS_GPIO_OUTPUT_MODE );
    MSS_GPIO_config( MSS_GPIO_1 , MSS_GPIO_OUTPUT_MODE );
    MSS_GPIO_config( MSS_GPIO_2 , MSS_GPIO_OUTPUT_MODE );
    MSS_GPIO_config( MSS_GPIO_3 , MSS_GPIO_OUTPUT_MODE );
    MSS_GPIO_config( MSS_GPIO_4 , MSS_GPIO_OUTPUT_MODE );
    MSS_GPIO_config( MSS_GPIO_8 , MSS_GPIO_OUTPUT_MODE );
    MSS_GPIO_config( MSS_GPIO_9 , MSS_GPIO_OUTPUT_MODE );
    MSS_GPIO_config( MSS_GPIO_10 , MSS_GPIO_OUTPUT_MODE );

    delay(100);

    /*
     * Set initial delay used to blink the LED.
     */
    count=0;

    while(1)
    {
      //printf("count value = %d,stored at 0x%08x address\n",count,&count);
      MSS_UART_polled_tx(&g_mss_uart1,(uint8_t *)"LEDs Blinkin\n\r",sizeof("LEDs Blinkin\n\r"));
      count++;
#if 0
      MSS_GPIO_set_output(MSS_GPIO_0, 0);
      delay(400000);
      MSS_GPIO_set_output(MSS_GPIO_0, 1);
      delay(200000);
      MSS_GPIO_set_output(MSS_GPIO_1, 0);
      delay(400000);
      MSS_GPIO_set_output(MSS_GPIO_1, 1);
#endif
      MSS_GPIO_set_output(MSS_GPIO_4, 0);
      delay(200000);
      MSS_GPIO_set_output(MSS_GPIO_4, 1);
      delay(200000);
      MSS_GPIO_set_output(MSS_GPIO_8, 0);
      delay(200000);
      MSS_GPIO_set_output(MSS_GPIO_8, 1);

    }

    return 0;
}
void delay(int n)
{
  while(n>0)
    n--;
}
