Beispiel #1
0
int main (void) {
  uint32_t interval;

 SystemCoreClockUpdate();

  /* Config CLKOUT, mostly used for debugging. */
  CLKOUT_Setup( CLKOUTCLK_SRC_MAIN_CLK );
  LPC_IOCON->PIO0_1 &= ~0x07;	
  LPC_IOCON->PIO0_1 |= 0x01;		/* CLK OUT */

  /* Enable AHB clock to the GPIO domain. */
  LPC_SYSCON->SYSAHBCLKCTRL |= (1<<6);

  /* TEST_TIMER_NUM is either 0 or 1 for 16-bit timer 0 or 1. */
  interval = SystemCoreClock/1000 - 1;
  if ( interval > 0xFFFF )
  {
	interval = 0xFFFF;
  }
  init_timer16(TEST_TIMER_NUM, interval);
  enable_timer16(TEST_TIMER_NUM);

  /* Set port 2_0 to output */
   GPIOSetDir( 2, 0, 1 );

  while (1)                                /* Loop forever */
  {
#if TEST_TIMER_NUM
	/* I/O configuration and LED setting pending. */
	if ( (timer16_1_counter > 0) && (timer16_1_counter <= 200) )
	{
	  GPIOSetValue( 2, 0, 0 );
	}
	if ( (timer16_1_counter > 200) && (timer16_1_counter <= 400) )
	{
	  GPIOSetValue( 2, 0, 1 );
	}
	else if ( timer16_1_counter > 400 )
	{
	  timer16_1_counter = 0;
	}
#else
	/* I/O configuration and LED setting pending. */
	if ( (timer16_0_counter > 0) && (timer16_0_counter <= 200) )
	{
	  GPIOSetValue( 2, 0, 0 );
	}
	if ( (timer16_0_counter > 200) && (timer16_0_counter <= 400) )
	{
	  GPIOSetValue( 2, 0, 1 );
	}
	else if ( timer16_0_counter > 400 )
	{
	  timer16_0_counter = 0;
	}
#endif
  }
}
Beispiel #2
0
/*****************************************************************************
**   Main Function  main()
******************************************************************************/
int main (void)
{
  /*** The main Function is an endless loop ****/

  // Configure WDT to run from internal WD oscillator at about 8 kHz
  WDTInit();

  init_timer16( 0, TIME_INTERVALmS * 10 );
  enable_timer16( 0 );

  /* Set LED pin to output and make sure it is off */
  GPIOSetDir( LED_PORT, LED_BIT, 1 );
  GPIOSetValue( LED_PORT, LED_BIT, LED_OFF );

  // Check reset status for watchdog reset- if found, blink quickly
  if ((LPC_SYSCON->SYSRSTSTAT & 0x4) == 0x4)
  {
    LPC_SYSCON->SYSRSTSTAT |= 0x4;
    while( 1 ) 
    {
  	  /* I/O configuration and LED setting pending. */
  	  if ( (timer16_0_counter > 0) && (timer16_0_counter <= FAST_LED_TOGGLE_TICKS/2) )
  	  {
  	    GPIOSetValue( LED_PORT, LED_BIT, LED_OFF );
  	  }
  	  if ( (timer16_0_counter > FAST_LED_TOGGLE_TICKS/2) 
			&& (timer16_0_counter <= FAST_LED_TOGGLE_TICKS) )
  	  {
  	    GPIOSetValue( LED_PORT, LED_BIT, LED_ON );
  	  }
  	  else if ( timer16_0_counter > FAST_LED_TOGGLE_TICKS )
  	{
  	    timer16_0_counter = 0;
  	  }
  	}
  }
  else
  { // No watchdog reset- lets blink slowly
  while( 1 )
  {
	  /* I/O configuration and LED setting pending. */
	  if ( (timer16_0_counter > 0) && (timer16_0_counter <= LED_TOGGLE_TICKS/2) )
	  {
	    GPIOSetValue( LED_PORT, LED_BIT, LED_OFF );
	  }
	  if ( (timer16_0_counter > LED_TOGGLE_TICKS/2) && (timer16_0_counter <= LED_TOGGLE_TICKS) )
	  {
	    GPIOSetValue( LED_PORT, LED_BIT, LED_ON );
	  }
	  else if ( timer16_0_counter > LED_TOGGLE_TICKS )
	  {
	    timer16_0_counter = 0;
	  }
    }
  }
}
Beispiel #3
0
int main (void) {

  GPIOInit();

  // Initialize Timer16_0 to tick at rate of 1/2000th of second.
	// Note that as this is a 16 bit timer, the maximum count we can
	// load into timer is 0xFFFF, or 65535. Default clock speed
	// set up by CMSIS SystemInit function - SystemCoreClock - is
	// 48MHz or 48000000 Hz. Dividing this by 2000 is 24000 which is
	// within appropriate timer16 maximum. This could be extended
	// if timer routine extended to make use of Prescale Counter register
	// Note by default LPC_SYSCON->SYSAHBCLKDIV is 1.
  init_timer16(0, (SystemCoreClock/LPC_SYSCON->SYSAHBCLKDIV)/2000 );

  // Initialize counter that counts Timer16_0 ticks
  timer16_0_counter = 0;

  //Enable Timer16_0
  enable_timer16(0);

  // Set port for LED to output
  GPIOSetDir( LED_PORT, LED_BIT, 1 );

  while (1)                                /* Loop forever */
  {

	// LED is on for 1st half-second
	if ( (timer16_0_counter > 0) && (timer16_0_counter <= 1000) )
	{
	  GPIOSetValue( LED_PORT, LED_BIT, LED_OFF );
	}
	// LED is off for 2nd half-second
	if ( (timer16_0_counter > 1000) && (timer16_0_counter <= 2000) )
	{
		GPIOSetValue( LED_PORT, LED_BIT, LED_ON );
	}
	// Reset counter
	else if ( timer16_0_counter > 2000 )
	{
	  timer16_0_counter = 0;
	}
  }
}
Beispiel #4
0
int main (void) 
{
  SystemCoreClockUpdate();
	
  /* Initialize 32-bits timer 0 */
  init_timer32(0, TIME_INTERVAL);
  enable_timer32(0);
	
  /* Initialize the PWM in timer32_1 enabling match0 output */
  init_timer32PWM(1, period, MATCH0);
  setMatch_timer32PWM (1, 0, period/4);
  enable_timer32(1);

  /* Initialize the PWM in timer16_0 enabling match1 output */
  init_timer16PWM(0, period, MATCH1, 0);
  setMatch_timer16PWM (0, 1, period/2);
  enable_timer16(0);

  /* Enable AHB clock to the GPIO domain. */
  LPC_SYSCON->SYSAHBCLKCTRL |= (1<<6);
	
  /* Set port 1_19 to output */
  GPIOSetDir( 1, 6, 1 );
	
  
  while (1)                                /* Loop forever */
  {
	/* I/O configuration and LED setting pending. */
	if ( (timer32_0_counter[0] > 0) && (timer32_0_counter[0] <= 50) )
	{
	  GPIOSetBitValue( 1, 6, 0 );
	}
	if ( (timer32_0_counter[0] > 50) && (timer32_0_counter[0] <= 100) )
	{
	  GPIOSetBitValue( 1, 6, 1 );
	}
	else if ( timer32_0_counter[0] > 100 )
	{
	  timer32_0_counter[0] = 0;
	}
  }
}
Beispiel #5
0
int main (void) 
{  
  SystemInit();

  USBIOClkConfig();

  /* P0.1 is push-button input, P2.0~3 are LED output. */
  LPC_GPIO2->DIR |= (0x1<<0)|(0x1<<1)|(0x1<<2)|(0x1<<3);
  LPC_GPIO0->DIR &= ~(0x1<<1);

  /* 16-bit timer 0. */
  init_timer16(0, TIME_INTERVAL);
  enable_timer16(0);

  /* Set port 2_0 to output */
  GPIOSetDir( 2, 0, 1 );
  USB_Init();                               /* USB Initialization */
  USB_Connect(TRUE);                        /* USB Connect */

  while (1)                                /* Loop forever */
  {
	/* I/O configuration and LED setting pending. */
	if ( (timer16_0_counter > 0) && (timer16_0_counter <= 200) )
	{
	  GPIOSetValue( 2, 0, 0 );
	}
	if ( (timer16_0_counter > 200) && (timer16_0_counter <= 400) )
	{
	  GPIOSetValue( 2, 0, 1 );
	}
	else if ( timer16_0_counter > 400 )
	{
	  timer16_0_counter = 0;
	}
  }
}
Beispiel #6
0
int main (void) {

/* Basic chip initialization is taken care of in SystemInit() called
   * from the startup code. SystemInit() and chip settings are defined
   * in the CMSIS system_<part family>.c file.
   */
/*  SystemInit(); */

  /* Config CLKOUT, mostly used for debugging. */
  CLKOUT_Setup( CLKOUTCLK_SRC_MAIN_CLK );
  LPC_IOCON->PIO0_1 &= ~0x07;	
  LPC_IOCON->PIO0_1 |= 0x01;		/* CLK OUT */

  /* Enable AHB clock to the GPIO domain. */
  LPC_SYSCON->SYSAHBCLKCTRL |= (1<<6);

  /* TEST_TIMER_NUM is either 0 or 1 for 16-bit timer 0 or 1. */
  init_timer16(TEST_TIMER_NUM, TIME_INTERVAL);
  enable_timer16(TEST_TIMER_NUM);

  /* Set port 2_0 to output */
/*  GPIOSetDir( 2, 0, 1 ); */
  /* Set LED port pin to output */
  GPIOSetDir( LED_PORT, LED_BIT, 1 );

  while (1)                                /* Loop forever */
  {
#if TEST_TIMER_NUM
	/* I/O configuration and LED setting pending. */
	if ( (timer16_1_counter > 0) && (timer16_1_counter <= 200) )
	{
	  /* GPIOSetValue( 2, 0, 0 ); */
	  GPIOSetValue( LED_PORT, LED_BIT, LED_OFF );
	}
	if ( (timer16_1_counter > 200) && (timer16_1_counter <= 400) )
	{
	  /* GPIOSetValue( 2, 0, 1 ); */
	  GPIOSetValue( LED_PORT, LED_BIT, LED_ON );
	}
	else if ( timer16_1_counter > 400 )
	{
	  timer16_1_counter = 0;
	}
#else
	/* I/O configuration and LED setting pending. */
	if ( (timer16_0_counter > 0) && (timer16_0_counter <= 200) )
	{
	  /* GPIOSetValue( 2, 0, 0 ); */
	  GPIOSetValue( LED_PORT, LED_BIT, LED_OFF );
	}
	if ( (timer16_0_counter > 200) && (timer16_0_counter <= 400) )
	{
	  /* GPIOSetValue( 2, 0, 1 ); */
	  GPIOSetValue( LED_PORT, LED_BIT, LED_ON );
	}
	else if ( timer16_0_counter > 400 )
	{
	  timer16_0_counter = 0;
	}
#endif
  }
}
Beispiel #7
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;
}