/**********************************************************************
* $Id$		LedBlinky.c  				2010-05-21
*//**
* @file		LedBlinky.c
* @brief	This example describes how to use GPIO interrupt to drive LEDs
* @version	2.0
* @date		21. May. 2010
* @author	NXP MCU SW Application Team/Micromint USA Support
*
* Copyright(C) 2010, NXP Semiconductor
* All rights reserved.
*
***********************************************************************
* Software that is described herein is for illustrative purposes only
* which provides customers with programming information regarding the
* products. This software is supplied "AS IS" without any warranties.
* NXP Semiconductors assumes no responsibility or liability for the
* use of the software, conveys no license or title under any patent,
* copyright, or mask work right to the product. NXP Semiconductors
* reserves the right to make changes in the software without
* notification. NXP Semiconductors also make no representation or
* warranty that such application will be suitable for the specified
* use without further testing or modification.
**********************************************************************/
#include "lpc17xx_gpio.h"
#include "lpc17xx_libcfg.h"
#include "lincoln_board.h"
/* Example group ----------------------------------------------------------- */
/** @defgroup GPIO_LedBlinky	LedBlinky
 * @ingroup GPIO_Examples
 * @{
 */

/************************** PRIVATE DEFINITIONS *************************/
/* Define LED port and pin: LED1 P1.18, LED2 P3.26 */
const unsigned long led_port[] = { LED1_PORT, LED2_PORT };
const unsigned long led_mask[] = { 1<<LED1_PIN, 1<<LED2_PIN };

/************************** PRIVATE VARIABLES *************************/
/* SysTick Counter */
volatile unsigned long SysTickCnt;

/************************** PRIVATE FUNCTIONS *************************/
void SysTick_Handler (void);
void Delay (unsigned long tick);

/*----------------- INTERRUPT SERVICE ROUTINES --------------------------*/
/*********************************************************************//**
 * @brief		SysTick handler sub-routine (1ms)
 * @param[in]	None
 * @return 		None
 **********************************************************************/
void SysTick_Handler (void)
{
  SysTickCnt++;
}

/*-------------------------PRIVATE FUNCTIONS------------------------------*/
/*********************************************************************//**
 * @brief		Delay function
 * @param[in]	tick - number milisecond of delay time
 * @return 		None
 **********************************************************************/
void Delay (unsigned long tick)
{
  unsigned long systickcnt;
  systickcnt = SysTickCnt;
  while ((SysTickCnt - systickcnt) < tick);
}

int main(void)
{
  unsigned long i;
  SysTick_Config(SystemCoreClock/1000 - 1); /* Generate interrupt each 1 ms   */
  /* Initialize the GPIOs */
  for (i=0; i<NUM_LEDS; i++)
  {
    GPIO_SetDir(led_port[i], led_mask[i], 1);  /* Configure as output */
    GPIO_ClearValue(led_port[i], led_mask[i]);  /* Initialize value to zero */
  }
  /* Loop forever. */
  while(1)
  {
    /* Turn each LED on and off */
    for (i=0; i<NUM_LEDS; i++)
      {
        GPIO_SetValue(led_port[i], led_mask[i]);
        Delay(510);
        GPIO_ClearValue(led_port[i], led_mask[i]);
      }
  }
}

#ifdef  DEBUG
/*******************************************************************************
* @brief		Reports the name of the source file and the source line number
* 				where the CHECK_PARAM error has occurred.
* @param[in]	file Pointer to the source file name
* @param[in]    line assert_param error line source number
* @return		None
*******************************************************************************/
void check_failed(uint8_t *file, uint32_t 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

/*
 * @}
 */
