Esempio n. 1
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  /* Chip errata */
  CHIP_Init();
  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

  /* Initialize LED driver */
  BSP_LedsInit();
  /* Setting state of leds*/
  BSP_LedSet(0);
  BSP_LedSet(1);

  /* Initialize SLEEP driver, no calbacks are used */
  SLEEP_Init(NULL, NULL);
#if (configSLEEP_MODE < 3)
  /* do not let to sleep deeper than define */
  SLEEP_SleepBlockBegin((SLEEP_EnergyMode_t)(configSLEEP_MODE+1));
#endif

  /* Parameters value for taks*/
  static TaskParams_t parametersToTask1 = { pdMS_TO_TICKS(1000), 0 };
  static TaskParams_t parametersToTask2 = { pdMS_TO_TICKS(500), 1 };

  /*Create two task for blinking leds*/
  xTaskCreate( LedBlink, (const char *) "LedBlink1", STACK_SIZE_FOR_TASK, &parametersToTask1, TASK_PRIORITY, NULL);
  xTaskCreate( LedBlink, (const char *) "LedBlink2", STACK_SIZE_FOR_TASK, &parametersToTask2, TASK_PRIORITY, NULL);

  /*Start FreeRTOS Scheduler*/
  vTaskStartScheduler();

  return 0;
}
Esempio n. 2
0
static void prvQueueReceiveTask( void *pvParameters )
{
    uint32_t ulReceivedValue;
    const uint32_t ulExpectedValue = 100UL;
    const TickType_t xShortDelay = pdMS_TO_TICKS( 10 );

    /* Remove compiler warning about unused parameter. */
    ( void ) pvParameters;

    for( ;; ) {
        /* Wait until something arrives in the queue - this task will block
        indefinitely provided INCLUDE_vTaskSuspend is set to 1 in
        FreeRTOSConfig.h. */
        xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );

        /*  To get here something must have been received from the queue, but
        is it the expected value?  If it is, toggle the LED. */
        if( ulReceivedValue == ulExpectedValue ) {
            /* Turn the LED on for a brief time only so it doens't distort the
            energy reading. */
            BSP_LedSet( mainTASK_LED );
            vTaskDelay( xShortDelay );
            BSP_LedClear( mainTASK_LED );
            ulReceivedValue = 0U;
        }
    }
}
Esempio n. 3
0
/***************************************************************************//**
 * @brief
 *   RxTimer, Timer0 IRQHandler.
 ******************************************************************************/
void TIMER0_IRQHandler(void)
{
  uint32_t irqFlags;

  irqFlags = TIMER_IntGet(HIJACK_RX_TIMER);
  TIMER_IntClear(HIJACK_RX_TIMER, irqFlags);

  if (TIMER_IF_CC1 & irqFlags)
  {
	cur_stamp = TIMER_CaptureGet(HIJACK_RX_TIMER, 1);
	TIMER_CounterSet(HIJACK_RX_TIMER, 0);	
	edge_occur = true;
	/* Check what transition it was. */
    if (GPIO_PinInGet(HIJACK_RX_GPIO_PORT, HIJACK_RX_GPIO_PIN))
    {
       	cur_edge = rising;
		BSP_LedSet( 0 );
    }
    else
    {
      	cur_edge = falling;
	 	BSP_LedClear( 0 );
    }
  }
}
Esempio n. 4
0
void SysTick_Handler(void)
{
	msTicks++;
	if (msDelay != 0)
		msDelay--;

	if (Stopwatch_active)
		Stopwatch_ms++;

	if (msLedRunOff != 0)
	{
		if (--msLedRunOff == 0)
		{
			BSP_LedSet(0);
			msLedRunOn = msLedOn;
		}
	}
	if (msLedRunOn != 0)
	{
		if (--msLedRunOn == 0)
		{
			BSP_LedClear(0);
			msLedRunOff = msLedOff;
		}
	}
}
/**************************************************************************//**
 * @brief RTC Handler
 * Interrupt Service Routine for Real Time Counter
 *****************************************************************************/
void RTC_IRQHandler(void)
{
  /* Clear interrupt source */
  RTC_IntClear(RTC_IFC_COMP0);

  /* Toggle the LED */
  if (enabled)
  {
    BSP_LedClear(0);
  }
  else
  {
    BSP_LedSet(0);
    /* Change state */
    switch (STATE)
    {
    case EM0:
      STATE = EM1;
      break;
    case EM1:
      STATE = EM2;
      break;
    case EM2:
      STATE = EM0;
      break;
    }
  }
  enabled = !enabled;
}
Esempio n. 6
0
void LOS_EvbLedInit(void)
{

#ifdef EFM32PG1B200F256GM48
		/* Initialize LED driver */
	BSP_LedsInit();
	BSP_LedSet(0);
	BSP_LedClear(1);
#endif

	return ;
}
Esempio n. 7
0
/*************************************************************************************************
 *  function£ºcontrol led on off                                                                 *
 *  param (1) index Led's index                                                                  *
 *        (2) cmd   Led on or off                                                                *
 *  return : None                                                                                *
 *  discription:                                                                                 *
**************************************************************************************************/
void LOS_EvbLedControl(int index, int cmd)
{
#ifdef EFM32PG1B200F256GM48
    switch (index)
    {
        case LOS_LED1:
        {
            if (cmd == LED_ON)
            {
                BSP_LedSet(0); /*led1 on */
            }
            else
            {
                BSP_LedClear(0); /*led1 off */
            }
            break;
        }
        case LOS_LED2:
        {
            if (cmd == LED_ON)
            {
                BSP_LedSet(1); /*led2 on */
            }
            else
            {
                BSP_LedClear(1); /*led2 off */
            }
            break;
        }
        default:
        {
            break;
        }
    }
#endif
	return ;
}
Esempio n. 8
0
/*!
 *  Radio Initialization.
 *
 *  @author Sz. Papp
 *
 *  @note
 *
 */
void vRadio_Init(void)
{
  /* Power Up the radio chip */
  vRadio_PowerUp();

  /* Load radio configuration */
  while (SI446X_SUCCESS != si446x_configuration_init(pRadioConfiguration->Radio_ConfigurationArray))
  {
    /* Error hook */
    BSP_LedSet(0);
    Delay(2);
    BSP_LedClear(0);

    /* Power Up the radio chip */
    vRadio_PowerUp();
  }

  // Read ITs, clear pending ones
  si446x_get_int_status(0u, 0u, 0u);
}
Esempio n. 9
0
File: main.c Progetto: Eclo/FreeRTOS
static void prvSetupHardware( void )
{
EMU_DCDCInit_TypeDef xDCDInit = EMU_DCDCINIT_STK_DEFAULT;
CMU_HFXOInit_TypeDef xHFXOInit = CMU_HFXOINIT_STK_DEFAULT;

	/* Chip errata */
	CHIP_Init();

	/* Init DCDC regulator and HFXO with kit specific parameters */
	EMU_DCDCInit( &xDCDInit );
	CMU_HFXOInit( &xHFXOInit );

	/* Switch HFCLK to HFXO and disable HFRCO */
	CMU_ClockSelectSet( cmuClock_HF, cmuSelect_HFXO );
	CMU_OscillatorEnable( cmuOsc_HFRCO, false, false );

	/* Initialize LED driver. */
	BSP_LedsInit();
	BSP_LedSet( 0 );
	BSP_LedClear( 1 );
}
Esempio n. 10
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  /* Chip errata */
  CHIP_Init();

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

  /* Setup SysTick Timer for 1 msec interrupts  */
  if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) while (1) ;

  /* Initialize LED driver */
  BSP_LedsInit();
  BSP_LedSet(0);

  /* Infinite blink loop */
  while (1)
  {
    BSP_LedToggle(0);
    BSP_LedToggle(1);
    Delay(1000);
  }
}
Esempio n. 11
0
/**************************************************************************//**
 *
 * @brief	Initialize board
 *
 *****************************************************************************/
void BoardInit(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;
	USART_InitTypeDef USART_InitStructure;

	Pin_Init();
	
	LED_CLK();
	BSP_LedSet(0);
	GPIO_InitStructure.GPIO_Pin = LED_PIN;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
	GPIO_Init(LED_PORT, &GPIO_InitStructure);

	SystemCoreClockUpdate();
	TimingInit();

	PC_GPIO_CLK();
	GPIO_InitStructure.GPIO_Pin = PC_PIN_RX;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
	GPIO_Init(PC_PIN_PORT, &GPIO_InitStructure);

	GPIO_InitStructure.GPIO_Pin = PC_PIN_TX;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
	GPIO_Init(PC_PIN_PORT, &GPIO_InitStructure);

	PC_UART_CLK();
	USART_InitStructure.USART_BaudRate = 115200;
	USART_InitStructure.USART_WordLength = USART_WordLength_8b;
	USART_InitStructure.USART_StopBits = USART_StopBits_1;
	USART_InitStructure.USART_Parity = USART_Parity_No;
	USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
	USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
	USART_Init(PC_UART, &USART_InitStructure);
	USART_Cmd(PC_UART, ENABLE);
}
Esempio n. 12
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
	{
  CHIP_Init();                                   // This function addresses some chip errata and should be called at the start of every EFM32 application (need em_system.c)
  uint8_t i, front_back, left_right, command;
  char init_message[] = "Start!\n";

  /* Setup SysTick Timer for 1 msec interrupts  */
  if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) while (1) ;

  /* Initialize LED driver */
  BSP_LedsInit();
  BSP_LedSet(0);

  /* initalize clocks */
  CMU->CTRL |= (1 << 14);                         // Set HF clock divider to /2 to keep core frequency <32MHz
  CMU->OSCENCMD |= 0x4;                           // Enable XTAL Oscillator
  while(! (CMU->STATUS & 0x8) );                  // Wait for XTAL osc to stabilize
  CMU->CMD = 0x2;                                 // Select HF XTAL osc as system clock source. 48MHz XTAL, but we divided the system clock by 2, therefore our HF clock should be 24MHz

  usart_init();
  i2cInit();

  // Print test string
  for(i=0; init_message[i] != '\0'; i++) {
    usart_send_data(init_message[i]);
  }

  usart_enable_rx_isr();

  while (1)
  {
	performI2CTransfer();
    BSP_LedToggle(0);
    BSP_LedToggle(1);

    front_back = (uint8_t)(G[1]>>8 & 0xFF);
    left_right = (uint8_t)(G[0]>>8 & 0xFF);

/*
    usart_send_data(0xAA);
    usart_send_data(front_back);
    usart_send_data(0xBB);
    usart_send_data(left_right);
*/
    if (left_right >= 0x30 && front_back <= 0x45){
        	command = 'l';
        }else if (left_right >= 0xC0 && front_back <= 0xDF){
        	command = 'r';
        }else if(front_back >= 0xC0&& front_back <= 0xCD){
    	command = 'f';
    }else if (front_back >= 0x32 && front_back <= 0x35){
    	command = 'b';
    }

    /*else if (left_right >= 0x3E && front_back <= 0x40){
    	command = 'l';
    }else if (left_right >= 0xC4 && front_back <= 0xD0){
    	command = 'r';
    }
    */

    if(command != 0x00){
    	usart_send_data(command);
    	command = 0x00;
    }

    //usart_send_data((uint8_t)(G[0]>>8 & 0xFF));
    //usart_send_data((uint8_t)G[1] & 0xFF);

    Delay(500);
  }
}
Esempio n. 13
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  char buffer[] = "AT";
  uint8_t delay_type = 0;

  /* Chip errata */
  CHIP_Init();

  /* initalize clocks */
  CMU->CTRL |= (1 << 14);                         // Set HF clock divider to /2 to keep core frequency <32MHz
  CMU->OSCENCMD |= 0x4;                           // Enable XTAL Oscillator
  while(! (CMU->STATUS & 0x8) );                  // Wait for XTAL osc to stabilize
  CMU->CMD = 0x2;                                 // Select HF XTAL osc as system clock source. 48MHz XTAL, but we divided the system clock by 2, therefore our HF clock should be 24MHz

  /* Setup SysTick Timer for 1 msec interrupts  */
  if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) while (1) ;

  usart_init();
  motor_init();

  usart_enable_rx_isr();

  BSP_LedsInit();
  BSP_LedSet(0);
  BSP_LedSet(1);

  usart_send_string(buffer);

  /* Infinite loop */
  while (1) {
	  BSP_LedToggle(1);

	  switch(rx_data){
	    case 'f':
		  Move_Forward();
		  delay_type = 1;
		  break;
	    case 'b':
		  Move_Backward();
		  delay_type = 1;
		  break;
	    case 'r':
		  Move_Left();
		  delay_type = 2;
		  break;
	    case 'l':
		  Move_Right();
		  delay_type = 2;
		  break;
	    default:
	      delay_type = 1;
		  Stop_Robot();
		  break;
	  }

	  rx_data = 0;

	  //Chooses the delay depending on the movement
	  if (delay_type == 1){
		  Delay(1000);
	  }else if(delay_type == 2){
		  Delay(200);
	  }

  }
}
Esempio n. 14
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  /* Chip errata */
  CHIP_Init();

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

  /* Initial BSP led driver .  **/
  BSP_LedsInit();
  BSP_LedSet(0);
  BSP_LedClear(0);

  /* timer1 intial to generate wave. */
  enc_init();

  /* Initialize LCD controller without boost */
  SegmentLCD_Init(false);

  /* Disable all segments */
  SegmentLCD_AllOff();

  /* Copy contents of the userpage (flash) into the userData struct */
  //memcpy((void *) &userData, (void *) USERPAGE, sizeof(UserData_TypeDef));

  /* Special case for uninitialized data */
  if (userData.number > 10000)
    userData.number = 0;
  if (userData.numWrites == 0xFFFFFFFF)
    userData.numWrites = 0;

  /* Display the number */
  SegmentLCD_Number(userData.number);

  /* Setup GPIO interrupts. PB0 to increase number, PB1 to save to flash */
  gpioSetup();

  /* No save has occured yet */
  recentlySaved = false;

  /* Main loop - just scroll informative text describing the current state of
   * the system */
  while (1)
  {
	EM2Sleep(125);
#if 0
    switch (currentError)
    {
    case mscReturnInvalidAddr:
      ScrollText("     ERROR: INVALID ADDRESS      ");
      break;
    case mscReturnLocked:
      ScrollText("     ERROR: USER PAGE IS LOCKED      ");
      break;
    case mscReturnTimeOut:
      ScrollText("     ERROR: TIMEOUT OCCURED      ");
      break;
    case mscReturnUnaligned:
      ScrollText("     ERROR: UNALIGNED ACCESS     ");
    default:
      if (recentlySaved)
      {
        recentlySaved = false;
        SegmentLCD_Number(userData.numWrites);
        ScrollText("     SAVE NUMBER       ");
      }
      else
      {
        SegmentLCD_Number(userData.number);
        ScrollText("     PRESS PB0 TO INCREASE NUMBER. PB1 TO SAVE TO INTERNAL FLASH        ");
      }
      break;
    }
#endif
  }
}
Esempio n. 15
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  int i;
  uint8_t data[7];
  SENSOR_DATA_TypeDef axis_converted_avg[33];
  char lcd_data[20];
  /* ADXL345 I2C driver config */
  ADXL345Handle.port = I2C1;
  ADXL345Handle.sclPort = ADXL345_I2C_SCL_PORT;
  ADXL345Handle.sclPin = ADXL345_I2C_SCL_PIN;
  ADXL345Handle.sdaPort = ADXL345_I2C_SDA_PORT;
  ADXL345Handle.sdaPin = ADXL345_I2C_SDA_PIN;
  ADXL345Handle.portLocation = ADXL345_I2C_PORT_LOC;
  /* Chip errata */
  CHIP_Init();

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

  /* Enable two leds to show we're alive */
  BSP_LedsInit();
  BSP_LedSet(0);
  BSP_LedSet(1);

  /* Setup SysTick Timer for 1 msec interrupts  */
  if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) while (1) ;

  /* Enable LCD without voltage boost */
  SegmentLCD_Init(false);
  /* Initialize I2C drivers */
  I2CSPM_Init(&ADXL345Handle);

	ADXL345_INIT(ADXL345Handle.port);
	SegmentLCD_Write("ADXL345");
	Delay(500);
	/* Read Device ID */
	SegmentLCD_Write("DEV_ID");
	Delay(500);
	ADXL345_Read_Reg(ADXL345Handle.port, DEVICEID_REG_ADDR,data,1);
	SegmentLCD_LowerHex(data[0]);
	Delay(500);
	/* Read FIFO CTL */
	SegmentLCD_Write("AXISDATA");
	Delay(500);
	/* Infinite loop with test pattern. */
   while(1)
   {
	   // axis_converted_avg.X =  0;
	   // axis_converted_avg.Y =  0;
	   // axis_converted_avg.Z =  0;
	   ADXL345_Read_Reg(ADXL345Handle.port, 0x30,data,1);
	   if(data[0]&0x02)
	   {
		   
		 ADXL345_READ_FIFO(axis_converted_avg);
		    // sprintf(lcd_data,"X:%d",(int)axis_converted_avg.X/i);
		    // SegmentLCD_Write(lcd_data);
			// Delay(500);
			// sprintf(lcd_data,"Y:%d",(int)axis_converted_avg.Y/i);
		    // SegmentLCD_Write(lcd_data);
			// Delay(500);
			// sprintf(lcd_data,"Z:%d",(int)axis_converted_avg.Z/i);
		    // SegmentLCD_Write(lcd_data);
			// Delay(500);  
		 for(i=0;i<33;i++)
		 {
			ADXL345_STEPCOUNT(axis_converted_avg[i]); 
		 }
		 

	   }
	  SegmentLCD_LowerNumber(STEP_COUNT);
	// SegmentLCD_LowerNumber(ADXL345_DATA_CONVERT(axis_data[0]));
	 Delay(500);        
	// SegmentLCD_LowerNumber(ADXL345_DATA_CONVERT(axis_data[1]));
	// Delay(500);          
	// SegmentLCD_LowerNumber(ADXL345_DATA_CONVERT(axis_data[2]));
	// Delay(500);      	
	// ADXL345_Read_Reg(ADXL345Handle.port, 0x1e,data,1);
	// SegmentLCD_LowerHex(data[0]);
	// Delay(500);   
	// ADXL345_Read_Reg(ADXL345Handle.port, 0x1f,data,1);
	// SegmentLCD_LowerHex(data[0]);
	// Delay(500);  
	// ADXL345_Read_Reg(ADXL345Handle.port, 0x20,data,1);
	// SegmentLCD_LowerHex(data[0]);
	// Delay(500);  

	// SegmentLCD_LowerHex(axis_data[1]<< 8 + axis_data[0]);
	// Delay(500);
	// SegmentLCD_LowerHex(axis_data[3]<< 8 + axis_data[2]);
	// Delay(500);
	// SegmentLCD_LowerHex(axis_data[5]<< 8 + axis_data[4]);
	// Delay(1000);
  }


}
Esempio n. 16
0
void halSetLed(HalBoardLed led)
{
	BSP_LedSet(led);
}