예제 #1
0
파일: main.c 프로젝트: finklabs/epicsamples
int main (void)
{
  uint8_t ledState;

  //Set LED1 pin as an output
  GPIOSetDir( LED1_PORT, LED1_PIN, GPIO_OUTPUT);
  GPIOSetValue( LED1_PORT, LED1_PIN, LED_OFF);

  //Set SW2 pin as an input
  GPIOSetDir( SW2_PORT, SW2_PIN, GPIO_INPUT);

  //enter forever loop
  while (1)
  {
    //delay a specified period of time (the sample period)
    delayMS(75);

    //check if push-button is pressed
    if (GPIOGetValue(SW2_PORT, SW2_PIN) == SW_PRESSED)
    {
      //toggle LED
	    if (ledState == LED_ON)
	      ledState = LED_OFF;
	    else
        ledState = LED_ON;
      GPIOSetValue( LED1_PORT, LED1_PIN, ledState);

      //wait until push-button is released
	    while(GPIOGetValue(SW2_PORT, SW2_PIN) == SW_PRESSED)
		    ;
	  }
  }
  return 0;
}
예제 #2
0
// 10ms扫描一次
void ScanRfid(void)
{
	static uint8_t rfidfiltercnt = 0; // 刷卡滤波肌计数
	static uint8_t rfidstatus = 1; // 刷开抬起 1抬起 0未抬起
	
	if((GPIOGetValue(PORT2, 8)&0x100) == 0) // 得到P2_8引脚的电平,如果为电平有刷卡
	{
		
		rfidfiltercnt++;										
		if(rfidfiltercnt > 10)
		{
			rfidfiltercnt = 0; // 100ms滤波
			if(rfidstatus == 1) // 是第一次刷卡  //
			{
				rfidstatus = 2; // 不是第一次刷卡,就是卡一直在放rfid上
				RfidGetFinishFlag = TRUE; // 刷卡成功
			}
		}
	}
	else // 无刷卡
	{
		rfidfiltercnt = 0;
		rfidstatus = 1;
	}
}
예제 #3
0
static void
loop_rfid (void)
{
	int res, line, t;
//  uint32_t counter;
	static unsigned char data[80];

	/* fully initialized */
	GPIOSetValue (LED_PORT, LED_BIT, LED_ON);

	/* read firmware revision */
	debug_printf ("\nreading firmware version...\n");
	data[0] = PN532_CMD_GetFirmwareVersion;
	while ((res = rfid_execute (&data, 1, sizeof (data))) < 0)
	{
		debug_printf ("Reading Firmware Version Error [%i]\n", res);
		pmu_wait_ms (450);
		GPIOSetValue (LED_PORT, LED_BIT, LED_ON);
		pmu_wait_ms (10);
		GPIOSetValue (LED_PORT, LED_BIT, LED_OFF);
	}

	debug_printf ("PN532 Firmware Version: ");
	if (data[1] != 0x32)
		rfid_hexdump (&data[1], data[0]);
	else
		debug_printf ("v%i.%i\n", data[2], data[3]);

	/* Set PN532 to virtual card */
	data[0] = PN532_CMD_SAMConfiguration;
	data[1] = 0x02;																/* Virtual Card Mode */
	data[2] = 0x00;																/* No Timeout Control */
	data[3] = 0x00;																/* No IRQ */
	if ((res = rfid_execute (&data, 4, sizeof (data))) > 0)
	{
		debug_printf ("SAMConfiguration: ");
		rfid_hexdump (&data, res);
	}

	/* init RFID emulator */
	rfid_init_emulator ();

	/* enable debug output */
	GPIOSetValue (LED_PORT, LED_BIT, LED_ON);
	line = 0;
	t = 0;

	while (1)
	{
#if 0
		counter = LPC_TMR32B0->TC;
		pmu_wait_ms (100);
		counter = (LPC_TMR32B0->TC - counter) * 10;

		debug_printf ("LPC_TMR32B0[%08u]: %uHz\n", line++, counter);
#endif
		GPIOSetValue (LED_PORT, LED_BIT, GPIOGetValue (1, 8));
	}
}
예제 #4
0
파일: gpio.c 프로젝트: dihic/iShelfTCM
void DrvGPIO_Open( uint32_t portNum, uint32_t bitPosi, uint32_t dir )
{
	 
	 if (dir== E_IO_OUTPUT)	//1
	 {
	 	
		if ((LPC_GPIO[portNum]->DIR & (1<<bitPosi)) ==0) // current input
		{
			if (GPIOGetValue(portNum,bitPosi)==0)	// low
			{
				GPIOSetValue( portNum, bitPosi,0);	
			}
			else   
			{
				GPIOSetValue( portNum, bitPosi,1); // high
			}
		}
		
	 }
	 GPIOSetDir(portNum,bitPosi,dir);
	 
}
예제 #5
0
/*****************************************************************************
**   Main Function  main()
******************************************************************************/
int main (void) {

   /* Setup SysTick Timer for 10 msec interrupts  */
   if (SysTick_Config(SystemCoreClock / 100)) {
		while (1); /* Capture error */
   }

   if (!(SysTick->CTRL & SysTick_CTRL_CLKSOURCE_Msk)) {
        /* When external reference clock is used(CLKSOURCE in
		Systick Control and register bit 2 is set to 0), the
		SYSTICKCLKDIV must be a non-zero value and 2.5 times
		faster than the reference clock.
		When core clock, or system AHB clock, is used(CLKSOURCE
		in Systick Control and register bit 2 is set to 1), the
		SYSTICKCLKDIV has no effect to the SYSTICK frequency. See
		more on Systick clock and status register in Cortex-M3
		technical Reference Manual. */
		LPC_SYSCON->SYSTICKCLKDIV = 0x08;
	}


   GPIOInit();

   init_timers();


   // The LED on Xpresso
   /* Set port 0_7 to output */
   GPIOSetDir( LED_PORT, LED_BIT, 1 );
   GPIOSetValue( 0, 7, LEDvalue );

   // buttons
   buttons_init();

   power_mgr_init();

   // check for 'next' button
   if (GPIOGetValue(0, 6)) {
	   led_digits_init();
	   led_digits_enable();
	   //led_digits_set_blink(1);
	   led_red_set(1);
	   led_green_set(1);
   }
   else {
	   GPIOSetValue( 0, 7, 1 );
	   delay32Ms(0,500);
	   GPIOSetValue( 0, 7, 0 );
	   delay32Ms(0,500);
	   GPIOSetValue( 0, 7, 1 );
	   delay32Ms(0,500);
	   GPIOSetValue( 0, 7, 0 );
	   delay32Ms(0,500);
	   GPIOSetValue( 0, 7, 1 );
	   delay32Ms(0,500);
	   GPIOSetValue( 0, 7, 0 );
	   delay32Ms(0,500);
   }


   // BARCODE reader
   barcode_init();
   barcode_reset();

   // RFID reader
   rdm630_init();
   rdm630_reset();

   // UART
   UARTInit(115200);
   // Enable the UART Interrupt
   NVIC_EnableIRQ(UART_IRQn);
   LPC_UART->IER = IER_RBR | IER_RLS;

   logger_setEnabled(1);
   logger_logStringln("/O:entering main loop..."); // send online message (means i'm online)

   uint8_t counter = 0;
   for(counter = 0; counter < 100; counter++) {
	   led_digits_set_value(counter);
	   delay32Ms(0, 20);
   }

   for(counter = 0; counter < 10; counter++) {
	   led_digits_set_value_by_chars('0' + counter, '0' + counter);
	   delay32Ms(0, 200);
   }
   delay32Ms(0, 200);
   led_digits_enable();

   signal_boot_up();

   int8_t last_remaining_seconds = -1;
   while (1) {

       /* process logger */
       if (logger_dataAvailable() && UARTTxEmpty) {
         uint8_t iCounter;
         // fill transmit FIFO with 14 bytes
         for (iCounter = 0; iCounter < 14 && logger_dataAvailable(); iCounter++) {
            UARTSendByte(logger_read());
         }
       }

       power_mgr_process(msTicks);

       barcode_process(msTicks);

       rdm630_process(msTicks);

       buttons_process(msTicks);

       led_digits_process(msTicks);


       /*
	   if (power_mgr_is_shutting_down()) {
		   if (power_mgr_get_remaining_player_seconds() != last_remaining_seconds) {
			   last_remaining_seconds = power_mgr_get_remaining_player_seconds();
			   led_digits_set_value(last_remaining_seconds);
		   }
		   if (last_remaining_seconds == 0) {
			   led_green_set(0);
			   led_red_set(1);
			   led_digits_disable();
		   }
		   continue;
	   }
	   */


       main_process_barcode();

       main_process_rfid();

       main_process_buttons();

       main_process_uart();

   }
}
예제 #6
0
파일: gpio.c 프로젝트: dihic/iShelfTCM
// Get value
uint32_t DrvGPIO_GetBit( uint32_t portNum, uint32_t bitPosi )
{
	// Set value
	return GPIOGetValue( portNum, bitPosi);

}
예제 #7
0
파일: main.c 프로젝트: finklabs/epicsamples
int main (void)
{
  uint32_t analogValue;
  uint8_t wantedDutyCycle, wantedDutyCycleB=100;
  uint8_t state = 0;

  //Set LED1-LED8 pins as outputs
  GPIOSetDir( LED1_PORT, LED1_PIN, GPIO_OUTPUT);
  GPIOSetValue( LED1_PORT, LED1_PIN, LED_OFF);
  GPIOSetDir( LED2_PORT, LED2_PIN, GPIO_OUTPUT);
  GPIOSetValue( LED2_PORT, LED2_PIN, LED_OFF);
  GPIOSetDir( LED3_PORT, LED3_PIN, GPIO_OUTPUT);
  GPIOSetValue( LED3_PORT, LED3_PIN, LED_OFF);
  GPIOSetDir( LED4_PORT, LED4_PIN, GPIO_OUTPUT);
  GPIOSetValue( LED4_PORT, LED4_PIN, LED_OFF);
  GPIOSetDir( LED5_PORT, LED5_PIN, GPIO_OUTPUT);
  GPIOSetValue( LED5_PORT, LED5_PIN, LED_OFF);
  GPIOSetDir( LED6_PORT, LED6_PIN, GPIO_OUTPUT);
  GPIOSetValue( LED6_PORT, LED6_PIN, LED_OFF);
  GPIOSetDir( LED7_PORT, LED7_PIN, GPIO_OUTPUT);
  GPIOSetValue( LED7_PORT, LED7_PIN, LED_OFF);
  GPIOSetDir( LED8_PORT, LED8_PIN, GPIO_OUTPUT);
  GPIOSetValue( LED8_PORT, LED8_PIN, LED_OFF);

  //Set SW2/SW3 pins as inputs
  GPIOSetDir( SW2_PORT, SW2_PIN, GPIO_INPUT);
  GPIOSetDir( SW3_PORT, SW3_PIN, GPIO_INPUT);

  //Extra, turn buzzer off
  GPIOSetDir( BUZZ_PORT, BUZZ_PIN, GPIO_OUTPUT);
  GPIOSetValue( BUZZ_PORT, BUZZ_PIN, BUZZ_OFF);

  //Set RGB-LED pins as outputs
  GPIOSetDir( LEDB_PORT, LEDB_PIN, GPIO_OUTPUT);
  GPIOSetValue( LEDB_PORT, LEDB_PIN, LED_OFF);

  initPWM(1000);       //1000us = 1kHz PWM frequency
  updatePWM(0, 100);   //set 100% duty cycle for channel #0 (RED LED will be off)
  updatePWM(1, 100);   //set 100% duty cycle for channel #1 (GREEN LED will be off)
  startPWM();

  //Initialize ADC peripheral and pin-mixing
  ADCInit(4500000);  //4.5MHz ADC clock

  //get initial value
  analogValue = getADC(AIN0);   //AIN0 = trimming pot for intensity

  wantedDutyCycleB = 100;
  state = 0;

  while(1)
  {
    uint8_t loopCounter;
    uint16_t adcCounter;

    //Set BLUE LED output high
    GPIOSetValue( LEDB_PORT, LEDB_PIN, 1);

    //check if time to read analog input
    if (adcCounter++ > 100)
    {
      adcCounter = 0;

      //check push-button SW2
      if (GPIOGetValue(SW2_PORT, SW2_PIN) == SW_PRESSED)
      {
        state++;
        if (state > 2)
          state = 0;

        //wait until push-button is released
        while(GPIOGetValue(SW2_PORT, SW2_PIN) == SW_PRESSED)
          ;
      }

      //Set wanted duty cycle - valid numbers: 0..100 (low number = LED on more)
      wantedDutyCycle = getADC(AIN0) / 10;   //trimming pot

      //extra check to that range is valid
      if (wantedDutyCycle > 99)
        wantedDutyCycle = 99;

      switch(state)
      {
      case 0: updatePWM(0, wantedDutyCycle); break;
      case 1: updatePWM(1, wantedDutyCycle); break;
      case 2: wantedDutyCycleB = wantedDutyCycle;  break;
      default: state = 0;
      }
    }

    //Enter duty cycle generating loop
    for (loopCounter=0; loopCounter<100; loopCounter++)
    {
      //10 corresponds to 1kHz (100*10us), LED flickering starts at around 30-40Hz PWM frequency
      delayUS(10);
      if (loopCounter == wantedDutyCycleB)
        GPIOSetValue( LEDB_PORT, LEDB_PIN, 0);   //Set output low
    }
  }

  return 0;
}
예제 #8
0
파일: soundtest.c 프로젝트: DanBUK/r0ket
int
main (void)
{
  volatile int t;
  int i, mode, index, start;

  /* Get System Clock */
  SystemCoreClockUpdate ();

  /* Initialize GPIO (sets up clock) */
  GPIOInit ();
  GPIOSetDir (BUT1_PORT, BUT1_PIN, 0);
  GPIOSetDir (BUT2_PORT, BUT2_PIN, 0);

  /* Set LED port pin to output */
  LPC_GPIO2->DIR |= 0xF0;
  LPC_GPIO3->DIR |= 0x0F;

  /* Set sound port to PIO1_1 and PIO1_2 */
  LPC_GPIO1->DIR |= 0x6;
  LPC_IOCON->JTAG_TDO_PIO1_1 = 3;
  LPC_IOCON->JTAG_nTRST_PIO1_2 = 3;

  LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 10);
  LPC_TMR32B1->TCR = 2;
  LPC_TMR32B1->MCR = 1 << 4;
  LPC_TMR32B1->EMR = 1 | (0x3 << 4) | (0x3 << 6);

  mode = 2;
  index = 24;
  while (1)
    {
      /* BUTTON1 press cycles through tones */
      if (!GPIOGetValue (BUT1_PORT, BUT1_PIN))
	{
	  mode = (mode + 1) & 0x7;
	  /* debounce */
	  for (t = 0; t < 1000000; t++);
	}

      /* BUTTON2 plays tone */
      if (!GPIOGetValue (BUT2_PORT, BUT2_PIN))
	{
	  set_led (0xFF);
	  /* debounce */

	  switch (mode)
	    {

	    case 0:
	      index++;
	      if (index > TONES_MAX)
		index = 1;
	      tone (index);
	      for (t = 0; t < 2000000; t++);
	      break;

	    case 1:
	      if (index > 1)
		index--;
	      else
		index = TONES_MAX;
	      tone (index);
	      for (t = 0; t < 2000000; t++);
	      break;

	    case 2:
	      tone (index);
	      break;

	    default:
	      start = get_frequency_for_tone (index) - 500;
	      for (i = 100; i > 0; i--)
		{
		  beep (start + (i * 10));
		  for (t = 0; t < (mode * 5000); t++);
		}
	      beep (0);
	      break;
	    }
	}
      else if (mode <= 2)
	tone (0);

      set_led (1 << mode);
    }
}
예제 #9
0
int
main (void)
{
/* accelerometer readings fifo */
		TFifoEntry acc_lowpass;
		TFifoEntry fifo_buf[FIFO_DEPTH];
		int fifo_pos;
		TFifoEntry *fifo;

		uint32_t SSPdiv;
		uint16_t oid_last_seen;
		uint8_t cmd_buffer[64], cmd_pos, c;
		uint8_t volatile *uart;
		int x, y, z, moving;
		volatile int t;
		int i;

		/* wait on boot - debounce */
		for (t = 0; t < 2000000; t++);

		/* Initialize GPIO (sets up clock) */
		GPIOInit ();

		/* initialize pins */
		pin_init ();

		/* fire up LED 1 */
		GPIOSetValue (1, 1, 1);

		/* initialize SPI */
		spi_init ();

		/* read device UUID */
		bzero (&device_uuid, sizeof (device_uuid));
		iap_read_uid (&device_uuid);
		tag_id = crc16 ((uint8_t *) & device_uuid, sizeof (device_uuid));
		random_seed =
				device_uuid[0] ^ device_uuid[1] ^ device_uuid[2] ^ device_uuid[3];

		/************ IF Plugged to computer upon reset ? ******************/
		if (GPIOGetValue (0, 3))
		{
			/* wait some time till Bluetooth is off */
			for (t = 0; t < 2000000; t++);

			/* Init 3D acceleration sensor */
			acc_init (1);
			/* Init Flash Storage with USB */
			storage_init (TRUE, tag_id);
			g_storage_items = storage_items ();

			/* Init Bluetooth */
			bt_init (TRUE, tag_id);

			/* switch to LED 2 */
			GPIOSetValue (1, 1, 0);
			GPIOSetValue (1, 2, 1);

			/* set command buffer to empty */
			cmd_pos = 0;

			/* spin in loop */
			while (1)
			{
				/* reset after USB unplug */
				if (!GPIOGetValue (0, 3))
					NVIC_SystemReset ();

				/* if UART rx send to menue */
				if (UARTCount)
				{
					/* blink LED1 upon Bluetooth command */
					GPIOSetValue (1, 1, 1);
					/* execute menue command with last character received */

					/* scan through whole UART buffer */
					uart = UARTBuffer;
					for (i = UARTCount; i > 0; i--)
					{
						UARTCount--;
						c = *uart++;
						if ((c < ' ') && cmd_pos)
						{
							/* if one-character command - execute */
							if (cmd_pos == 1)
								main_menue (cmd_buffer[0]);
							else
							{
								cmd_buffer[cmd_pos] = 0;
								debug_printf
								("Unknown command '%s' - please press H+[Enter] for help\n# ",
										cmd_buffer);
							}

							/* set command buffer to empty */
							cmd_pos = 0;
						}
						else if (cmd_pos < (sizeof (cmd_buffer) - 2))
							cmd_buffer[cmd_pos++] = c;
					}

					/* reset UART buffer */
					UARTCount = 0;
					/* un-blink LED1 */
					GPIOSetValue (1, 1, 0);
				}
			}
		} /* End of if plugged to computer*/


		/***************** IF UNPLUGGED TO PC ........********/

		/* Init Bluetooth */
		bt_init (FALSE, tag_id);

		/* shut down up LED 1 */
		GPIOSetValue (1, 1, 0);

		/* Init Flash Storage without USB */
		storage_init (FALSE, tag_id);

		/* get current FLASH storage write postition */
		g_storage_items = storage_items ();

		/* initialize power management */
		pmu_init ();

		/* blink once to show initialized flash */
		blink (1);

		/* Init 3D acceleration sensor */
		acc_init (0);
		blink (2);

		/* Initialize OpenBeacon nRF24L01 interface */
		if (!nRFAPI_Init(CONFIG_TRACKER_CHANNEL, broadcast_mac, sizeof (broadcast_mac), 0))
			for (;;)
			{
				GPIOSetValue (1, 2, 1);
				pmu_sleep_ms (500);
				GPIOSetValue (1, 2, 0);
				pmu_sleep_ms (500);
			}
		/* set tx power power to high */
		nRFCMD_Power (1);

		/* blink three times to show flash initialized RF interface */
		blink (3);

		/* blink LED for 1s to show readyness */
		GPIOSetValue (1, 1, 0);
		GPIOSetValue (1, 2, 1);
		pmu_sleep_ms (1000);
		GPIOSetValue (1, 2, 0);

		/* disable unused jobs */
		SSPdiv = LPC_SYSCON->SSPCLKDIV;
		i = 0;
		oid_last_seen = 0;

		/* reset proximity buffer */
		prox_head = prox_tail = 0;
		bzero (&prox, sizeof (prox));

		/*initialize FIFO */
		fifo_pos = 0;
		bzero (&acc_lowpass, sizeof (acc_lowpass));
		bzero (&fifo_buf, sizeof (fifo_buf));

		moving = 0;
		g_sequence = 0;

		while (1)
		{
			
			pmu_sleep_ms (500);

			LPC_SYSCON->SSPCLKDIV = SSPdiv;
			acc_power (1);
			pmu_sleep_ms (20);
			acc_xyz_read (&x, &y, &z);
			acc_power (0);

			fifo = &fifo_buf[fifo_pos];
			if (fifo_pos >= (FIFO_DEPTH - 1))
				fifo_pos = 0;
			else
				fifo_pos++;

			acc_lowpass.x += x - fifo->x;
			fifo->x = x;
			acc_lowpass.y += y - fifo->y;
			fifo->y = y;
			acc_lowpass.z += z - fifo->z;
			fifo->z = z;


			nRFAPI_SetRxMode (0);

			bzero (&g_Beacon, sizeof (g_Beacon));
			g_Beacon.pkt.proto = RFBPROTO_BEACONTRACKER_EXT;
			g_Beacon.pkt.flags = moving ? RFBFLAGS_MOVING : 0;
			g_Beacon.pkt.oid = htons (tag_id);
			g_Beacon.pkt.p.tracker.strength = (i & 1) + TX_STRENGTH_OFFSET;
			g_Beacon.pkt.p.tracker.seq = htonl (LPC_TMR32B0->TC);
			g_Beacon.pkt.p.tracker.oid_last_seen = oid_last_seen;
			g_Beacon.pkt.p.tracker.time = htons ((uint16_t)g_sequence++);
			g_Beacon.pkt.p.tracker.battery = 0;
			g_Beacon.pkt.crc = htons (
					crc16(g_Beacon.byte, sizeof (g_Beacon) - sizeof (g_Beacon.pkt.crc))
					);

			nRFCMD_Power (0);
			nRF_tx (g_Beacon.pkt.p.tracker.strength);
			nRFCMD_Power (1);
			nRFAPI_PowerDown ();
			LPC_SYSCON->SSPCLKDIV = 0x00;
			blink (10);
		}
		

	
	return 0;
}
예제 #10
0
uint8_t
nRFCMD_IRQ (void)
{
  return !GPIOGetValue (RF_IRQ_CPU_PORT, RF_IRQ_CPU_PIN);
}
예제 #11
0
int
main (void)
{

  SystemCoreClockUpdate ();
  GPIOInit ();

  while (GPIOGetValue (BTN_PORT, BTN_PIN) == 0)
    ;

  POWER_ON;

  SSP_IOConfig (SSP_NUM); /* initialize SSP port, share pins with SPI1
   on port2(p2.0-3). */
  SSP_Init (SSP_NUM);
  UARTInit (115200);

  LED1_ON;

  TIMInit (0, 2 * SystemCoreClock);
  TIMInit (1, SystemCoreClock);
  TIMInit16 (1, SystemCoreClock);
  TIMInit16 (0, SystemCoreClock);
  enable_timer16 (0);

  // Initialize SYstick
  SysTick_Config ( SYSTICK_DELAY);

  MSP5701_init ();
  SST25_init ();

  //LED1_BLINK;

  // TODO: insert code here

  NVIC_ClearPendingIRQ (EINT0_IRQn);
  NVIC_ClearPendingIRQ (EINT1_IRQn);
  NVIC_EnableIRQ (EINT0_IRQn);
  NVIC_EnableIRQ (EINT1_IRQn);

  clearAllEvents();

  while (1)
    {

      if (checkEvent(BtnPressed))
	{
	  // Start measuring.
	  //GPIOSetValue(LED1_PORT, LED1_PIN, ~GPIOGetValue(LED1_PORT,LED1_PIN)&0x1);
	  clearEvent(BtnPressed);

	  if (measure == 1)
	    {
	      measure = 0;
	      live = 0;
	      /* Save data info */
	      storage_save_data_info (&actual_record);
	      meas_pointer = 0;
	      stop_systick ();
	    }
	  else
	    {
	      measure = 1;
	      meas_pointer = 0;
	      storage_init (&actual_record);
	      start_systick ();
	    }
	  clearEvent(BtnPressed);
	}
      if (checkEvent(PowerOff))
	{
	  // Turn off device.
	  storage_save_data_info (&actual_record);
	  meas_pointer = 0;
	  measure = 0;
	  LED1_OFF;
	  LED2_OFF;
	  UARTSend ((uint8_t*) "sleep\r\n", 7);
	  POWER_OFF
	  ;
	  while (1)
	    ;
	  clearEvent(PowerOff);

	}
      if (checkEvent(UART_data))
	{
	  clearEvent(UART_data);
	  uint8_t command = get_uart_char ();
	  switch (command)
	    {
	    case 'e':
	      stop_systick ();
	      SST25_erase (0, SIZE_FULL);
	      break;
	    case 'r':
	      measure = 0;
	      /* Save data info */
	      if (actual_record.rec_index != -1)
		{
		  storage_save_data_info (&actual_record);
		}
	      meas_pointer = 0;
	      stop_systick ();
	      send_data ();
	      break;
	    case 'l':
	      sleep = 0;
	      measure = 1;
	      live = 1;
	      start_systick ();
	      break;
	    case 'n':
	      live = 0;
	      measure = 1;
	      storage_init (&actual_record);
	      start_systick ();
	      sleep = 1;
	      break;
	    case 's':
	      live = 0;
	      sleep = 1;
	      measure = 0;
	      /* Save data info */
	      storage_save_data_info (&actual_record);
	      meas_pointer = 0;
	      stop_systick ();
	      break;
	    default:
	      break;
	    }
	}

      if (TimeTick & measure)
	{

	  TimeTick = 0;
	  /* Do stuff */

	  MSP5701_measure_press (&press);
	  if (live == 0)
	    {
	      memcpy ((uint8_t*) (meas_buffer + meas_pointer), &press,
		      sizeof(press));
	      meas_pointer += sizeof(press);
	      if (meas_pointer >= SAMPLE_BUFFER_LENGTH - 1)
		{
		  /* Store samples in external memory */
		  uint32_t length_written = storage_save_data (
		      &actual_record, meas_buffer, SAMPLE_BUFFER_LENGTH);
		  meas_pointer = 0;
		  if (length_written != SAMPLE_BUFFER_LENGTH)
		    {
		      /* Run out of memory - stop measuring */
		      measure = 0;
		      meas_pointer = 0;
		      storage_save_data_info (&actual_record);
		      /* Turn off device */
		      POWER_OFF
		      ;
		    }
		}
	    }
	  else
	    {
	      /*Transmit live*/
	      UARTSend ((uint8_t*) &press, 4);
	      UARTSend ((uint8_t*) "\r\n", 2);

	    }

	}
      if (sleep == 1)
	{
	  __WFI ();
	}
    }
  return 0;
}
uint8_t power_mgr_get_amp_status() {
	return !GPIOGetValue( POWER_MGR_PORT, POWER_MGR_PIN_AMP );
}
uint8_t power_mgr_get_player_status() {
	return !GPIOGetValue( POWER_MGR_PORT, POWER_MGR_PIN_PLAYER );
}