Exemplo n.º 1
0
/* Delay to allow all serial output to be processed before power state change */
static void DelayForSerialOutput(void)
{
	volatile uint32_t tempTimeout;

	/* Delay until all serial processing complete */
	tempTimeout = Chip_RTC_GetCount(LPC_RTC) + 1;
	while (Chip_RTC_GetCount(LPC_RTC) < tempTimeout) {}
}
/**
* This function will return the value of time read from the on board CPU real time clock. Time value must be given in the format of
* the structure wiced_rtc_time_t
*
* @return    WICED_SUCCESS : on success.
* @return    WICED_ERROR   : if an error occurred with any step
*/
OSStatus platform_rtc_get_time( platform_rtc_time_t* time)
{
#ifdef MICO_ENABLE_MCU_RTC
  bool    valid = false;

  if( time == 0 )
  {
    return kParamErr;
  }

  /* get current rtc time */
  convert_units_passed_to_rtc_calendar_values( Chip_RTC_GetCount(LPC_RTC), time );

  MICO_VERIFY_TIME(time, valid);
  if( valid == false )
  {
    return kParamErr;
  }

#if 0
  rtc_log(" return convert_units_passed_to_rtc_calendar_values address = 0x%x ", temp_time);
  rtc_log(" sec     = %d ", temp_time->sec);
  rtc_log(" min     = %d ", temp_time->min);
  rtc_log(" hr      = %d ", temp_time->hr);
  rtc_log(" weekday = %d ", temp_time->weekday);
  rtc_log(" date    = %d ", temp_time->date);
  rtc_log(" month   = %d ", temp_time->month);
  rtc_log(" year    = %d ", temp_time->year);
#endif

  return kNoErr;
#else /* #ifdef WICED_ENABLE_MCU_RTC */
  UNUSED_PARAMETER(time);
  return kUnsupportedErr;
#endif /* #ifdef MICO_ENABLE_MCU_RTC */
}
Exemplo n.º 3
0
/**
 * @brief	Main program body
 * @return	int
 */
int main(void)
{
	CHIP_PMU_MCUPOWER_T crntPowerSetting;

	/* Setup SystemCoreClock and any needed board code */
	SystemCoreClockUpdate();
	Board_Init();
	Board_LED_Set(0, true);

	/* Clear any previously set deep power down and sleep flags */
	Chip_PMU_ClearSleepFlags(LPC_PMU, PMU_PCON_SLEEPFLAG | PMU_PCON_DPDFLAG);
	/* Enable the RTC oscillator, oscillator rate can be determined by
	   calling Chip_Clock_GetRTCOscRate() */
	Chip_Clock_EnableRTCOsc();

	/* Initialize RTC driver (enables RTC clocking) */
	Chip_RTC_Init(LPC_RTC);

	/* RTC reset */
	Chip_RTC_Reset(LPC_RTC);

	/* Start RTC at a count of 0 when RTC is disabled. If the RTC is enabled, you
	   need to disable it before setting the initial RTC count. */
	Chip_RTC_Disable(LPC_RTC);
	Chip_RTC_SetCount(LPC_RTC, 0);

	/* Set a long alarm time so the interrupt won't trigger */
	Chip_RTC_SetAlarm(LPC_RTC, 1000);

	/* Enable RTC */
	Chip_RTC_Enable(LPC_RTC);

	/* Clear latched RTC interrupt statuses */
	Chip_RTC_ClearStatus(LPC_RTC, (RTC_CTRL_OFD | RTC_CTRL_ALARM1HZ | RTC_CTRL_WAKE1KHZ));

	/* Enable RTC interrupt */
	NVIC_EnableIRQ(RTC_ALARM_IRQn);

	/* Enable RTC alarm interrupt */
	Chip_RTC_EnableWakeup(LPC_RTC, RTC_CTRL_ALARMDPD_EN);

	/* Output example's activity banner */
	DEBUGSTR("\r\n");
	DEBUGSTR("-----------------------------------------------------------------\r\n");
#ifdef RESET_POWER_CYCLE_COUNT
	ProcessCycleCounter();
	DEBUGOUT("Power Control Example\r\n");
#else
	DEBUGOUT("Power Control Example   Cycle Count: %d\r\n", ProcessCycleCounter());
#endif
	DEBUGSTR("  System will cycle through SLEEP, DEEP SLEEP, POWER\r\n");
	DEBUGSTR("  DOWN, and DEEP POWER DOWN power states\r\n");
	DEBUGSTR("-----------------------------------------------------------------\r\n\r\n");

	/* Setup alarm, process next power state then wait for alarm to wake-up system */
	crntPowerSetting = PMU_MCU_SLEEP;
	while (1) {
		/* Set alarm to wakeup in POWER_CYCLE_SEC_DELAY seconds */
		Chip_RTC_SetAlarm(LPC_RTC, Chip_RTC_GetCount(LPC_RTC) + POWER_CYCLE_SEC_DELAY);

		/* Enter first (or next) power state */
		ProcessPowerState(crntPowerSetting);

		/* Inc current power setting and test for overflow */
		if (crntPowerSetting == PMU_MCU_DEEP_PWRDOWN) {
			/* Reset to lowest power setting */
			crntPowerSetting = PMU_MCU_SLEEP;
		}
		else {
			crntPowerSetting++;
		}
	}

	return 0;
}
Exemplo n.º 4
0
/**
 * @brief	Main program body
 * @return	int
 */
int main(void)
{
	uint32_t rtcCount;

	/* Starting time for this example used to set the RTC */
	struct tm startTime = {
		56,			/* tm_sec, seconds after the minute, 0 to 59 */
		59,			/* tm_min, minutes after the hour, 0 to 59 */
		23,			/* tm_hour, hours since midnight, 0 to 23 */
		25,			/* tm_mday, day of the month, 1 to 31 */
		9,			/* tm_mon, months since January, 0 to 11 */
		(2014 - TM_YEAR_BASE),	/* tm_year, years since base year (1900) */

		/* The following 3 fields are not used by the ConvertTimeRtc() function,
		   while the ConvertRtcTime() fucntion will generate data in them from an
		   RTC tick (except tm_isdst) */
		0,			/* tm_wday, days since Sunday, 0 to 6 */
		0,			/* tm_yday, days since January 1, 0 to 365 */
		0			/* tm_isdst, Daylight Savings Time flag */
	};

	/* Setup SystemCoreClock and any needed board code */
	SystemCoreClockUpdate();
	Board_Init();
	Board_LED_Set(0, false);

	/* Turn on the RTC 32K Oscillator */
	Chip_SYSCON_PowerUp(SYSCON_PDRUNCFG_PD_32K_OSC);

	/* Enable the RTC oscillator, oscillator rate can be determined by
	   calling Chip_Clock_GetRTCOscRate()	*/
	Chip_Clock_EnableRTCOsc();

	/* Initialize RTC driver (enables RTC clocking) */
	Chip_RTC_Init(LPC_RTC);

	/* RTC reset */
	Chip_RTC_Reset(LPC_RTC);

	/* Start RTC at a count of 0 when RTC is disabled. If the RTC is enabled, you
	   need to disable it before setting the initial RTC count. */
	Chip_RTC_Disable(LPC_RTC);

	/* COnvert tm structure to RTC tick count */
	ConvertTimeRtc(&startTime, &rtcCount);
	Chip_RTC_SetCount(LPC_RTC, rtcCount);

	/* Set alarm to wakeup in 5s */
	DEBUGOUT("Setting alarm to trigger in 5s\r\n");
	rtcCount += 5;
	Chip_RTC_SetAlarm(LPC_RTC, rtcCount);

	/* Enable RTC */
	Chip_RTC_Enable(LPC_RTC);

	/* Clear latched RTC interrupt statuses */
	Chip_RTC_ClearStatus(LPC_RTC, (RTC_CTRL_OFD | RTC_CTRL_ALARM1HZ | RTC_CTRL_WAKE1KHZ));

	/* Enable RTC interrupt */
	NVIC_EnableIRQ(RTC_IRQn);

	/* Enable RTC alarm interrupt */
	Chip_RTC_EnableWakeup(LPC_RTC, (RTC_CTRL_ALARMDPD_EN | RTC_CTRL_WAKEDPD_EN));

	/* Sleep and do all the work in the RTC interrupt handler */
	while (1) {
		/* 10 high resolution ticks that get slower each tick */
		if (rtcAlarm) {
			/* Will not reset alarm */
			DEBUGOUT("Alarm triggered, alarm reset to trigger in 5s\r\n");
			rtcCount = Chip_RTC_GetCount(LPC_RTC) + 5;
			Chip_RTC_SetAlarm(LPC_RTC, rtcCount);
			rtcAlarm = false;
		}

		/* Show RTC time in UT format */
		showTime(Chip_RTC_GetCount(LPC_RTC));

		/* Sleep while waiting for alarm */
		__WFI();
	}
	return 0;
}
Exemplo n.º 5
0
/**
 * @brief	Main program body
 * @return	int
 */
int main(void)
{
	int stateCounter = 0;

	/* Setup SystemCoreClock and any needed board code */
	SystemCoreClockUpdate();
	Board_Init();
	Board_LED_Set(0, false);

	/* Turn on the RTC 32K Oscillator by clearing the power down bit */
	if ( !Is_Chip_SYSCTL_PowerUp(PDRUNCFG_PD_32K_OSC) ) {
		Chip_SYSCTL_PowerUp(PDRUNCFG_PD_32K_OSC);
	}

	/* Enable the RTC oscillator, oscillator rate can be determined by
	   calling Chip_Clock_GetRTCOscRate()	*/
	Chip_Clock_EnableRTCOsc();

	/* Initialize RTC driver (enables RTC clocking) */
	Chip_RTC_Init(LPC_RTC);

	/* Enable RTC as a peripheral wakeup event */
	Chip_SYSCTL_EnableWakeup(STARTERP0_RTC);

	/* RTC reset */
	Chip_RTC_Reset(LPC_RTC);

	/* Start RTC at a count of 0 when RTC is disabled. If the RTC is enabled, you
	   need to disable it before setting the initial RTC count. */
	Chip_RTC_Disable(LPC_RTC);
	Chip_RTC_SetCount(LPC_RTC, 0);

	/* Set a long alarm time so the interrupt won't trigger */
	Chip_RTC_SetAlarm(LPC_RTC, 1000);

	/* Enable RTC and high resolution timer - this can be done in a single
	   call with Chip_RTC_EnableOptions(LPC_RTC, (RTC_CTRL_RTC1KHZ_EN | RTC_CTRL_RTC_EN)); */
	Chip_RTC_Enable1KHZ(LPC_RTC);
	Chip_RTC_Enable(LPC_RTC);

	/* Clear latched RTC interrupt statuses */
	Chip_RTC_ClearStatus(LPC_RTC, (RTC_CTRL_OFD | RTC_CTRL_ALARM1HZ | RTC_CTRL_WAKE1KHZ));

	/* Enable RTC interrupt */
	NVIC_EnableIRQ(RTC_IRQn);

	/* Enable RTC alarm interrupt */
	Chip_RTC_EnableWakeup(LPC_RTC, (RTC_CTRL_ALARMDPD_EN | RTC_CTRL_WAKEDPD_EN));

	/* Sleep and do all the work in the RTC interrupt handler */
	while (1) {
		DEBUGOUT("Tick number: %d, 1KHZ int:%d, alarm int:%d\r\n",
				 stateCounter, rtcWake, rtcAlarm);
		rtcWake = rtcAlarm = false;

		/* 10 high resolution ticks that get slower each tick */
		if (stateCounter < 10) {
			/* Wakeup in 300, 400, 500, etc. milliSeconds */
			Chip_RTC_SetWake(LPC_RTC, (300 + (stateCounter * 100)));
			stateCounter++;
		}
		else {
			DEBUGOUT("Setting alarm to wake up in 4s\r\n");
			/* Set alarm to wakeup in 4 seconds */
			Chip_RTC_SetAlarm(LPC_RTC, Chip_RTC_GetCount(LPC_RTC) + 4);
			stateCounter = 0;
		}
		// FIXME - Use ROM API's to put chip to power down modes
		/* LPC_PWRD_API->power_mode_configure(PMU_DEEP_POWERDOWN, PDRUNCFG_PD_32K_OSC, 1); */
		__WFI();
	}
	return 0;
}
Exemplo n.º 6
0
char *getTimeStr(){
	time_t rawtime = Chip_RTC_GetCount(LPC_RTC);
	struct tm * timeinfo;
	timeinfo = localtime(&rawtime);
	return asctime(timeinfo);
}
Exemplo n.º 7
0
// Write config object to file
void writeConfigToFile() {
	int i = 0;
	char buf[LINE_SIZE+1];

	// If config.txt doesn't exist, create it.
	if (f_open(&config, "config.txt", FA_CREATE_ALWAYS | FA_WRITE) != FR_OK) {
		error(ERROR_WRITE_CONFIG);
	}
	/**** FW version ****/
	config_printf("FW version: %s\n\n", VERSION);

	/**** DATE / TIME ****/
	config_printf("**** UPDATE DATE+TIME [Y/N] ****\n");
	config_printf("N\n");
	config_printf("    DATE/TIME [YYYY-MM-DD HH:MM:SS]\n");

	time_t t = Chip_RTC_GetCount(LPC_RTC);
	struct tm * tm;
	tm = localtime(&t);
	strftime(buf, LINE_SIZE, "%Y-%m-%d %H:%M:%S", tm);
	config_printf("%s\n\n\n", buf);

	/**** CONFIG ****/
	config_printf("**** UPDATE CONFIG [Y/N] ****\n");
	config_printf("N\n");
	config_printf("    USER HEADER [up to 100 characters]\n");
	config_printf("%s\n", daq.user_comment);
	config_printf("    OUTPUT VOLTAGE [floating point]\n");
	config_printf("%f\n", daq.mv_out/1000.0);
	config_printf("    SAMPLE RATE [HZ, 1 - 10000]\n");
	config_printf("%d\n", daq.sample_rate);
	config_printf("    TRIGGER DELAY [SEC, 0 - 100000]\n");
	config_printf("%d\n", daq.trigger_delay);
	config_printf("    DATA MODE [[R]eadable / [B]inary]\n");
	switch (daq.data_type){
		case READABLE:
			config_printf("R\n");
			break;
		case BINARY:
			config_printf("B\n");
			break;
	}
	for (i = 0; i < MAX_CHAN; i++) {
		config_printf("    CHANNEL %d\n", i+1);
		config_printf("ENABLED         [Y/N]: ");
		if (daq.channel[i].enable) {
			config_printf("Y\n");
		} else {
			config_printf("N\n");
		}
		config_printf("RANGE          [5/24]: ");
		switch (daq.channel[i].range) {
		case V5:
			config_printf("5\n");
			break;
		case V24:
			config_printf("24\n");
			break;
		}
		config_printf("UNITS [up to 8 chars]: ");
		config_printf("%s\n", daq.channel[i].unit_name);
		config_printf("UNITS PER VOLT   [fp]: ");
		fullDecFloatToStr(buf, &daq.channel[i].units_per_volt, 6);
		config_printf("%s\n", buf);
		config_printf("ZERO OFFSET      [fp]: ");
		fixToStr(buf, &daq.channel[i].offset_uV, 6, -6);
		config_printf("%s\n\n", buf);
	}

	/**** CALIBRATION ****/
	config_printf("**** UPDATE CALIBRATION [Y/N] ****\n");
	config_printf("N\n");

	for (i = 0; i < MAX_CHAN; i++){
		config_printf("    CHANNEL %d\n", i+1);
		config_printf("5V ZERO OFFSET  [fp]: ");
		fixToStr(buf, &daq.channel[i].v5_zero_offset, 6, 0);
		config_printf("%s\n", buf);
		config_printf("5V VOLT / LSB   [fp]: ");
		fixToStr(buf, &daq.channel[i].v5_uV_per_LSB, 6, -6);
		config_printf("%s\n", buf);
		config_printf("24V ZERO OFFSET [fp]: ");
		fixToStr(buf, &daq.channel[i].v24_zero_offset, 6, 0);
		config_printf("%s\n", buf);
		config_printf("24V VOLT / LSB  [fp]: ");
		fixToStr(buf, &daq.channel[i].v24_uV_per_LSB, 6, -6);
		config_printf("%s\n\n", buf);
	}

	/* Close config file */
	f_close(&config);
}
Exemplo n.º 8
0
void SysTick_Handler(void){
	static bool lowBat; // Set when battery voltage drops below VBAT_LOW
	static uint32_t sysTickCounter;

	sysTickCounter++; // Used to schedule less frequent tasks

	switch(system_state){
	case STATE_IDLE:
		// Enable USB if VBUS is disconnected
		;bool vBus = Chip_GPIO_GetPinState(LPC_GPIO, 0, VBUS);
		if(!vBus){
			msc_state = MSC_ENABLED;
		}
		// If MSC enabled, VBUS is connected, and SD card is ready, try to connect as MSC
		if (msc_state == MSC_ENABLED && vBus && sd_state == SD_READY){
			f_mount(NULL,"",0); // unmount file system
			if (msc_init() == MSC_OK){
				Board_LED_Color(LED_YELLOW);
				system_state = STATE_MSC;
				break;
			}else{ // Error on MSC initialization
				error(ERROR_MSC_INIT);
			}
		}
		// If user has short pressed PB and SD card is ready, initiate acquisition
		if (pb_shortPress() && sd_state == SD_READY){
			daq_init();
			system_state = STATE_DAQ;
			break;
		}

		// Blink LED if in low battery state, otherwise solid green
		if (lowBat && sysTickCounter % TICKRATE_HZ1 < TICKRATE_HZ1/2){
			Board_LED_Color(LED_OFF);
		} else {
			Board_LED_Color(LED_GREEN);
		}
		break;
	case STATE_MSC:
		// If VBUS is disconnected or button is short pressed
		;bool pb;
		if (Chip_GPIO_GetPinState(LPC_GPIO, 0, VBUS) == 0 || (pb = pb_shortPress())){
			if(pb){
				msc_state = MSC_DISABLED;
			}
			msc_stop();
			f_mount(fatfs,"",0); // mount file system
			Board_LED_Color(LED_GREEN);
			system_state = STATE_IDLE;
			enterIdleTime = Chip_RTC_GetCount(LPC_RTC);
		}
		break;
	case STATE_DAQ:
		// Perform the current asynchronous daq action
		daq_loop();

		// If user has short pressed PB to stop acquisition
		if (pb_shortPress()){
			Board_LED_Color(LED_PURPLE);
			daq_stop();
			Board_LED_Color(LED_GREEN);
			system_state = STATE_IDLE;
			enterIdleTime = Chip_RTC_GetCount(LPC_RTC);
			msc_state = MSC_DISABLED;
		}
		break;
	}

	// Initialize SD card after every insertion
	if (Chip_GPIO_GetPinState(LPC_GPIO, 0, CARD_DETECT)){
		// Card out
		Board_LED_Color(LED_CYAN);
		sd_state = SD_OUT;
	}else{
		// Card in
		if (sd_state == SD_OUT){
			// Delay 100ms to let connections and power stabilize
			DWT_Delay(100000);
			if(init_sd_spi(&cardinfo) != SD_OK) {
				error(ERROR_SD_INIT);
			}
			switch(system_state){
			case STATE_IDLE:
				Board_LED_Color(LED_GREEN);
				break;
			case STATE_MSC:
				Board_LED_Color(LED_YELLOW);
				break;
			case STATE_DAQ:
				Board_LED_Color(LED_RED);
				break;
			}
			sd_state = SD_READY;
		}
	}

	/* Run once per second */
	if(sysTickCounter % TICKRATE_HZ1 == 0){
		float vBat = read_vBat(10);
		lowBat = vBat < VBAT_LOW ? true : false; // Set low battery state
		if (vBat < VBAT_SHUTDOWN){
			shutdown_message("Low Battery");
		}

		if ((Chip_RTC_GetCount(LPC_RTC) - enterIdleTime > TIMEOUT_SECS && system_state == STATE_IDLE) ){
			shutdown_message("Idle Time Out");
		}
	}

	/* Shut down conditions */
	if (pb_longPress()){
		shutdown_message("Power Button Pressed");
	}

	/* Handle errors */
	error_handler();
}
Exemplo n.º 9
0
int main(void) {
	uint32_t sysTickRate;

	Board_Init();

#ifdef DEBUG
	// Set up UART for debug
	init_uart(115200);
	putLineUART("\n");
#endif

	// Enable EEPROM clock and reset EEPROM controller
	Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_EEPROM);
	Chip_SYSCTL_PeriphReset(RESET_EEPROM);

	// Set up clocking for SD lib
	SystemCoreClockUpdate();
	DWT_Init();

	// Set up the FatFS Object
	f_mount(fatfs,"",0);

	// Initialize SD card
	Board_LED_Color(LED_CYAN);
	if(sd_reset(&cardinfo) != SD_OK) {
		error(ERROR_SD_INIT);
	}
	sd_state = SD_READY;

	// Setup config
	Board_LED_Color(LED_CYAN);
	configStart();
	Board_LED_Color(LED_GREEN);

	// Allow MSC mode on startup
	msc_state = MSC_ENABLED;

	// Log startup
	log_string("Startup");

	// Set up ADC for reading battery voltage
	read_vBat_setup();

	// Initialize ring buffer used to buffer raw data samples
	rawBuff = RingBuffer_initWithBuffer(RAW_BUFF_SIZE, RAM1_BASE);

	// Set up MRT used by pb and daq
	Chip_MRT_Init();
	NVIC_ClearPendingIRQ(MRT_IRQn);
	NVIC_EnableIRQ(MRT_IRQn);
	NVIC_SetPriority(MRT_IRQn, 0x02); // Set higher than systick, but lower than sampling

	// Initialize push button
	pb_init();

	// Enable and setup SysTick Timer at a periodic rate
	Chip_Clock_SetSysTickClockDiv(1);
	sysTickRate = Chip_Clock_GetSysTickClockRate();
	SysTick_Config(sysTickRate / TICKRATE_HZ1);

	// Idle and run systick loop until triggered or plugged in as a USB device
	system_state = STATE_IDLE;
	enterIdleTime = Chip_RTC_GetCount(LPC_RTC);

    // Wait for interrupts
    while (1) {
    	__WFI();
    }

    return 0 ;
}
Exemplo n.º 10
0
Arquivo: rtc.c Projeto: 0xBADCA7/lk
/**
 * @brief	Main program body
 * @return	int
 */
int main(void)
{
	int stateCounter = 0;
	uint32_t ticks = 0;

	/* Setup SystemCoreClock and any needed board code */
	SystemCoreClockUpdate();
	Board_Init();

	/* Enable the RTC oscillator, oscillator rate can be determined by
	   calling Chip_Clock_GetRTCOscRate()	*/
	Chip_Clock_EnableRTCOsc();

	/* Initialize RTC driver (enables RTC clocking) */
	Chip_RTC_Init(LPC_RTC);

	/* Enable RTC as a peripheral wakeup event */
	Chip_SYSCTL_EnableERP1PeriphWakeup(SYSCTL_ERP1_WAKEUP_RTCALARMINT |
									   SYSCTL_ERP1_WAKEUP_RTCWAKEINT);

	/* RTC reset */
	Chip_RTC_Reset(LPC_RTC);

	/* Start RTC at a count of 0 when RTC is disabled. If the RTC is enabled, you
	   need to disable it before setting the initial RTC count. */
	Chip_RTC_Disable(LPC_RTC);
	Chip_RTC_SetCount(LPC_RTC, 0);

	/* Set a long alarm time so the interrupt won't trigger */
	Chip_RTC_SetAlarm(LPC_RTC, 1000);

	/* Enable RTC and high resolution timer - this can be done in a single
	   call with Chip_RTC_EnableOptions(LPC_RTC, (RTC_CTRL_RTC1KHZ_EN | RTC_CTRL_RTC_EN)); */
	Chip_RTC_Enable1KHZ(LPC_RTC);
	Chip_RTC_Enable(LPC_RTC);

	/* Clear latched RTC interrupt statuses */
	Chip_RTC_ClearStatus(LPC_RTC, (RTC_CTRL_OFD | RTC_CTRL_ALARM1HZ | RTC_CTRL_WAKE1KHZ));

	/* Enable RTC wake and alarm interrupts */
	NVIC_EnableIRQ(RTC_ALARM_IRQn);
	NVIC_EnableIRQ(RTC_WAKE_IRQn);

	/* Enable RTC alarm interrupt */
	Chip_RTC_EnableWakeup(LPC_RTC, (RTC_CTRL_ALARMDPD_EN | RTC_CTRL_WAKEDPD_EN));

	/* Sleep and do all the work in the RTC interrupt handler */
	while (1) {
		ticks = 0;
		DEBUGOUT("Tick number: %d, 1KHZ int:%d, alarm int:%d\r\n",
				 stateCounter, rtcWake, rtcAlarm);
		rtcWake = rtcAlarm = false;

		/* 10 high resolution ticks that get slower each tick */
		if (stateCounter < 10) {
			/* Wakeup in 300, 400, 500, etc. milliSeconds */
			Chip_RTC_SetWake(LPC_RTC, (300 + (stateCounter * 100)));

			stateCounter++;
		}
		else {
			DEBUGOUT("Setting alarm to wake up in 4s\r\n");

			/* Set alarm to wakeup in 4 seconds */
			Chip_RTC_SetAlarm(LPC_RTC, Chip_RTC_GetCount(LPC_RTC) + 4);

			stateCounter = 0;
		}

		Chip_SYSCTL_SetWakeup(~(SYSCTL_SLPWAKE_IRCOUT_PD | SYSCTL_SLPWAKE_IRC_PD |
								SYSCTL_SLPWAKE_FLASH_PD | SYSCTL_SLPWAKE_SYSOSC_PD | SYSCTL_SLPWAKE_SYSPLL_PD));
		Chip_SYSCTL_EnableERP1PeriphWakeup(SYSCTL_ERP1_WAKEUP_RTCALARMINT | SYSCTL_ERP1_WAKEUP_RTCWAKEINT);
		
		/* Delay to allow serial transmission to complete*/
		while(ticks++ < 10000) {}

		/* Enter MCU Deep Sleep mode */
		Chip_PMU_DeepSleepState(LPC_PMU);
	}

	return 0;
}