void led_toggle(void){


		PIN_setOutputValue(ledPinHandle, Board_LED1, !PIN_getOutputValue(Board_LED1));
		PIN_setOutputValue(ledPinHandle, Board_LED2, !PIN_getOutputValue(Board_LED2));

}
/**
 * @fn      SBL_openTarget
 *
 * @brief   Forces target device into SBL
 *
 * @param   None.
 *
 * @return  uint8_t - SBL_SUCCESS, SBL_FAILURE
 */
uint8_t SBL_openTarget(void)
{
  // Set BL PIN low and then set Reset PIN low to enter SBL
  PIN_setOutputValue(hsblPins, blPIN, 0);
  PIN_setOutputValue(hsblPins, rstPIN, 0);
    
  SBL_utilDelay(15);
  
  // Release Reset PIN while keeping BL pin low
  PIN_setOutputValue(hsblPins, rstPIN, 1);
  
  // Delay to be tuned
  SBL_utilDelay(150); 
  
  // Release BL Pin now that target should be in SBL mode
  PIN_setOutputValue(hsblPins, blPIN, 1);
  
  // Send initial packet so target can detect baud rate
  if (SBL_TL_uartAutoBaud() == SBL_DEV_ACK)
  {
    return SBL_SUCCESS;
  }
  
  return SBL_FAILURE;
}
예제 #3
0
// -----------------------------------------------------------------------------
//! \brief      This callback is invoked on the completion of one transmission
//!             to/from the host MCU. Any bytes receives will be [0,Rxlen) in
//!             npiRxBuf.
//!             If bytes were receives or transmitted, this function notifies
//!             the NPI task via registered call backs
//!
//! \param[in]  Rxlen   - length of the data received
//! \param[in]  Txlen   - length of the data transferred
//!
//! \return     void
// -----------------------------------------------------------------------------
static void NPITL_transmissionCallBack(uint16_t Rxlen, uint16_t Txlen)
{
    npiRxBufHead = 0;
    npiRxBufTail = Rxlen;
    npiTxActive = FALSE;
    //Since the largest valid NPI packet size is 4096
    //valid RxLen fields should only be up to 0x0FFF
    //a larger RxLen value tells the TL that a Rx is in progress
    //and the UART cannot be closed yet
    //in the above case, a CB will be triggered for the Tx, but Rx will wait
    //until ReadCB completes at NPITLUART layer
    if(!(Rxlen & 0x1000))
    {
      //Since we have rx/tx'd a complete packet, it is time to close out the TL
      //and ready the processor for sleep
#ifdef SWHS_DEBUG  
      //Set Pin if in debug mode 
      PIN_setOutputValue(hNpiProfilingPin, Board_LED2, 1);
#endif //SWHS_DEBUG
      transportClose();
      // Open the Pins for ISR
      hNpiUartRxPin = PIN_open(&npiUartRxPin, npiUartRxPinCfg);
      PIN_registerIntCb(hNpiUartRxPin, NPITL_rxPinHwiFxn);
      PIN_setConfig(hNpiUartRxPin, 
                    PIN_BM_IRQ, 
                    Board_UART_RX | PIN_IRQ_BOTHEDGES);

      // Enable wakeup
      PIN_setConfig(hNpiUartRxPin, 
                    PINCC26XX_BM_WAKEUP, 
                    Board_UART_RX | PINCC26XX_WAKEUP_NEGEDGE);
  #ifdef SWHS_DEBUG  
      //Set Pin if in debug mode 
      PIN_setOutputValue(hNpiProfilingPin, Board_LED2, 0);
  #endif //SWHS_DEBUG
      //It is also valid to clear all flags at this point
      trasnportLayerState = TL_closed;
      
        // If Task is registered, invoke transaction complete callback
      if (taskCBs.transCompleteCB)
      {
          taskCBs.transCompleteCB(Rxlen, Txlen);
      }
      NPITL_relPM();
    }
    else
    {
      //be sure to indicate TL is still busy
      trasnportLayerState = TL_busy;
      // If Task is registered, invoke transaction complete callback
      //note that RxLen is zero because the read is incomplete
      if (taskCBs.transCompleteCB)
      {
          taskCBs.transCompleteCB(0, Txlen);
      }
      
    }
}
/*******************************************************************************
 * @fn          devpkLcdSelect
 *
 * @brief       Select/deselect the DevPack on the SensorTag
 *              (this function is called from GrLib only)
 *
 * @param       select - true to select, false to deselect
 *
 * @return      none
 */
void devpkLcdSelect(bool select)
{
  if (select)
  {
    PIN_setOutputValue(hLcdPin,Board_SPI_DEVPK_CS,Board_DEVPK_CS_ON);
  }
  else
  {
    PIN_setOutputValue(hLcdPin,Board_SPI_DEVPK_CS,Board_DEVPK_CS_OFF);
  }
}
void led_init(void){

	/* Open LED pins */
	    ledPinHandle = PIN_open(&ledPinState, ledPinTable);
	    if(!ledPinHandle) {
	        System_abort("Error initializing board LED pins\n");
	    }

	    PIN_setOutputValue(ledPinHandle, Board_LED1, 0);
	    PIN_setOutputValue(ledPinHandle, Board_LED2, 1);
}
/**
 * @fn      SBL_resetTarget
 *
 * @brief   Forces target device to boot from flash image instead of SBL. This
 *          function can be called before SBL_open() or after SBL_open()
 *
 * @param   rstPinID - Board Pin ID of reset PIN
 * @param   blPinID  - Board Pin ID of boot loader PIN
 *
 * @return  uint8_t - SBL_SUCCESS, SBL_FAILURE
 */
uint8_t SBL_resetTarget(uint32_t rstPinID, uint32_t blPinID)
{
  uint8_t openedPins = 0;
  
  if (hsblPins == NULL)
  {
    // Must open pins if SBL_open() has not yet been called
    openedPins = 1;
    
    // Assign PIN IDs to reset and bl
    rstPIN = (rstPinID & IOC_IOID_MASK);
    blPIN = (blPinID & IOC_IOID_MASK);
    
    // Add PIN IDs to PIN Configuration
    sblPinsCfg[RST_PIN_IDX] |= rstPIN;
    sblPinsCfg[BL_PIN_IDX] |= blPIN;
    
    // Initialize SBL Pins
    hsblPins = PIN_open(&sblPins, sblPinsCfg);
    if (hsblPins == NULL)
    {
      return SBL_FAILURE;
    }
  }
  
  // Guarantee that Boot Loader Pin is high during reset toggle
  PIN_setOutputValue(hsblPins, blPIN, 1);
  
  // Set reset PIN low
  PIN_setOutputValue(hsblPins, rstPIN, 0);
  
  SBL_utilDelay(15);
  
  // Release Reset PIN 
  PIN_setOutputValue(hsblPins, rstPIN, 1);

  // Must close Pins if opened in function
  if (openedPins)
  {
    // Clear SBL PIN IDs
    rstPIN = (IOID_UNUSED & IOC_IOID_MASK); // Set to 0x000000FF
    blPIN = (IOID_UNUSED & IOC_IOID_MASK); // Set to 0x000000FF
    
    // Clear PIN IDs from PIN Configuration
    sblPinsCfg[RST_PIN_IDX] &= ~rstPIN; 
    sblPinsCfg[BL_PIN_IDX] &= ~blPIN;
    
    // Close PIN Handle
    PIN_close(hsblPins);
    hsblPins = NULL;
  }
  
  return SBL_SUCCESS;
}
예제 #7
0
/*******************************************************************************
 * @fn      SensorTag_blinkLed
 *
 * @brief   Blinks a led 'n' times, duty-cycle 50-50
 * @param   led - led identifier
 * @param   nBlinks - number of blinks
 *
 * @return  none
 */
void SensorTag_blinkLed(uint8_t led, uint8_t nBlinks)
{
  uint8_t i;

  for (i=0; i<nBlinks; i++)
  {
    PIN_setOutputValue(hGpioPin, led, Board_LED_ON);
    delay_ms(BLINK_DURATION);
    PIN_setOutputValue(hGpioPin, led, Board_LED_OFF);
    delay_ms(BLINK_DURATION);
  }
}
예제 #8
0
/*********************************************************************
 * @fn      SensorTagIO_reset
 *
 * @brief   Reset characteristics
 *
 * @param   none
 *
 * @return  none
 */
void SensorTagIO_reset(void)
{
  ioValue = SensorTag_testResult();
  Io_setParameter(SENSOR_DATA, 1, &ioValue);

  ioMode = IO_MODE_LOCAL;
  Io_setParameter(SENSOR_CONF, 1, &ioMode);

  // Normal mode; make sure LEDs and buzzer are off
  PIN_setOutputValue(hGpioPin, IOID_RED_LED, Board_LED_OFF);
  PIN_setOutputValue(hGpioPin, IOID_GREEN_LED, Board_LED_OFF);
  PIN_setOutputValue(hGpioPin, IOID_BLUE_LED, Board_LED_OFF);
}
/*********************************************************************
 * @fn      SensorTagIO_reset
 *
 * @brief   Reset characteristics
 *
 * @param   none
 *
 * @return  none
 */
void SensorTagIO_reset(void)
{
  ioValue = sensorTestResult();
  Io_setParameter( SENSOR_DATA, 1, &ioValue);

  ioMode = IO_MODE_LOCAL;
  Io_setParameter( SENSOR_CONF, 1, &ioMode);
  
  // Normal mode; make sure LEDs and buzzer are off
  PIN_setOutputValue(hGpioPin, Board_LED1, Board_LED_OFF);
  PIN_setOutputValue(hGpioPin, Board_LED2, Board_LED_OFF);
  Clock_stop(buzzClockHandle);
  PIN_setOutputValue(hGpioPin, Board_BUZZER, Board_BUZZER_OFF);
}
static void LCDTask_turnOnLCD(void) {
  
    // Turn on LCD
    PIN_setOutputValue(hGpioPin, Board_LCD_PWR, Board_LCD_PWR_ON);
    delay_ms(250);
    // Initialize LCD
    //bspSpiOpen();
    ILI9341_setup();
    ILI9341_fillScreen(ILI9341_BLACK);
    
    Adafruit_GFX_setTextColorBg(ILI9341_WHITE,ILI9341_BLACK);
    Adafruit_GFX_setTextSize(4);
    Adafruit_GFX_setCursor(45*1+5*4*0, 38*1+8*4*0);
    Adafruit_GFX_print("1");
    Adafruit_GFX_setCursor(45*2+5*4*1, 38*1+8*4*0);
    Adafruit_GFX_print("2");
    Adafruit_GFX_setCursor(45*3+5*4*2, 38*1+8*4*0);
    Adafruit_GFX_print("3");
    Adafruit_GFX_setCursor(45*1+5*4*0, 38*2+8*4*1);
    Adafruit_GFX_print("4");
    Adafruit_GFX_setCursor(45*2+5*4*1, 38*2+8*4*1);
    Adafruit_GFX_print("5");
    Adafruit_GFX_setCursor(45*3+5*4*2, 38*2+8*4*1);
    Adafruit_GFX_print("6");
    Adafruit_GFX_setCursor(45*1+5*4*0, 38*3+8*4*2);
    Adafruit_GFX_print("7");
    Adafruit_GFX_setCursor(45*2+5*4*1, 38*3+8*4*2);
    Adafruit_GFX_print("8");
    Adafruit_GFX_setCursor(45*3+5*4*2, 38*3+8*4*2);
    Adafruit_GFX_print("9");
    Adafruit_GFX_setCursor(45*2+5*4*1, 38*4+8*4*3);
    Adafruit_GFX_print("0");
    
    Adafruit_FT6206_setup(FT6206_DEFAULT_THRESSHOLD);
}
/*********************************************************************
 * @fn      timerIsr
 *
 * @brief   Interrupt service routine for buzzer.
 *
 * @param   none
 *
 * @return  none
 */
static void timerIsr(UArg arg0)
{
  uint32_t v;
  
  v = PIN_getOutputValue(Board_BUZZER);
  PIN_setOutputValue(hGpioPin, Board_BUZZER, !v);
}
/*
 *  ======== main ========
 */
int main(void)
{
    PIN_Handle ledPinHandle;

    /* Call board init functions */
    Board_initGeneral();
    Board_initUART();

    /* Open LED pins */
    ledPinHandle = PIN_open(&ledPinState, ledPinTable);
    if(!ledPinHandle) {
        System_abort("Error initializing board LED pins\n");
    }

    PIN_setOutputValue(ledPinHandle, Board_LED1, 1);

    /* This example has logging and many other debug capabilities enabled */
    System_printf("This example does not attempt to minimize code or data "
                  "footprint\n");
    System_flush();

    System_printf("Starting the UART Echo example\nSystem provider is set to "
                  "SysMin. Halt the target to view any SysMin contents in "
                  "ROV.\n");
    /* SysMin will only print to the console when you call flush or exit */
    System_flush();

    /* Start BIOS */
    BIOS_start();

    return (0);
}
예제 #13
0
/*********************************************************************
 * @fn      SensorTagIO_reset
 *
 * @brief   Reset characteristics
 *
 * @param   none
 *
 * @return  none
 */
void SensorTagIO_reset(void)
{
  ioValue = sensorTestResult();
  Io_setParameter( SENSOR_DATA, 1, &ioValue);

  ioMode = IO_MODE_LOCAL;
  Io_setParameter( SENSOR_CONF, 1, &ioMode);
  
  // Normal mode; make sure LEDs and buzzer are off
  PIN_setOutputValue(hGpioPin, Board_LED1, Board_LED_OFF);
  PIN_setOutputValue(hGpioPin, Board_LED2, Board_LED_OFF);
  
  if (buzzerOn) {
    buzzerClose();
    buzzerOn = false;
  }
}
예제 #14
0
/*******************************************************************************
 * @fn          rFSwitchNotifyCb
 *
 * @brief       Power driver callback to toggle RF switch on Power state
 *              transitions.
 *
 * input parameters
 *
 * @param   eventType - The state change.
 * @param   eventArg  - Not used.
 * @param   clientArg - Not used.
 *
 * @return  Power_NOTIFYDONE to indicate success.
 */
static uint8_t rFSwitchNotifyCb(uint8_t eventType, uint32_t *eventArg,
                                uint32_t *clientArg)
{
  if (eventType == PowerCC26XX_ENTERING_STANDBY)
  {
    // Power down RF Switch
    PIN_setOutputValue(radCtrlHandle, Board_DIO30_SWPWR, 0);
  }
  else if (eventType == PowerCC26XX_AWAKE_STANDBY)
  {
    // Power up RF Switch
    PIN_setOutputValue(radCtrlHandle, Board_DIO30_SWPWR, 1);
  }
  
  // Notification handled successfully
  return Power_NOTIFYDONE;
}
예제 #15
0
// -----------------------------------------------------------------------------
//! \brief      This callback is invoked on the completion of one transmission
//!             to/from the host MCU. Any bytes receives will be [0,Rxlen) in
//!             npiRxBuf.
//!             If bytes were receives or transmitted, this function notifies
//!             the NPI task via registered call backs
//!
//! \param[in]  Rxlen   - length of the data received
//! \param[in]  Txlen   - length of the data transferred
//!
//! \return     void
// -----------------------------------------------------------------------------
static void NPITL_transmissionCallBack(uint16_t Rxlen, uint16_t Txlen)
{
    npiRxBufHead = 0;
    npiRxBufTail = Rxlen;
    npiTxActive = FALSE;
    
    // If Task is registered, invoke transaction complete callback
    if (taskCBs.transCompleteCB)
    {
        taskCBs.transCompleteCB(Rxlen, Txlen);
    }
#ifdef NPI_SW_HANDSHAKING_DEBUG
    //Set the profiling pin high
    PIN_setOutputValue(hNpiProfilingDebugPin, profilingDebugPin, 1);
#endif //NPI_SW_HANDSHAKING_DEBUG
    // Close the UART
    transportClose();
    // Open the Pins for ISR
    hNpiHandshakePins = PIN_open(&npiHandshakePins, npiHandshakePinsCfg);
    	//replace remRdyPIN with Board_UART_RX
    	PIN_registerIntCb(hNpiHandshakePins, NPITL_remRdyPINHwiFxn);
    	PIN_setConfig(hNpiHandshakePins,
    				  PIN_BM_IRQ,
    				  Board_UART_RX | PIN_IRQ_BOTHEDGES);

    	// Enable wakeup
    	PIN_setConfig(hNpiHandshakePins,
    				  PINCC26XX_BM_WAKEUP,
    				  Board_UART_RX | PINCC26XX_WAKEUP_NEGEDGE);
#ifdef NPI_SW_HANDSHAKING_DEBUG
    	//Indicate that we are now asleep in the GPIO state
    	PIN_setOutputValue(hNpiProfilingDebugPin, profilingDebugPin, 0);
#endif //NPI_SW_HANDSHAKING_DEBUG
    	//It is also valid to clear all flags at this point
    	_npiCSKey_t key;
    	key = NPIUtil_EnterCS();
    	handshakingState = HS_GPIO_STATE;
    	NPIUtil_ExitCS(key);
#ifdef POWER_SAVING
    NPITL_relPM();
#endif //POWER_SAVING
}
/*******************************************************************************
 * @fn      SensorTagFactoryReset_extFlashErase
 *
 * @brief   Erase the external flash
 *
 * @return  none
 */
void SensorTagFactoryReset_extFlashErase(void)
{
    SensorTagDisplay_suspend();

    if (ExtFlash_open())
    {
        uint32_t address;

        // Erase entire external flash
        for (address= 0; address<EFL_FLASH_SIZE; address+=EFL_PAGE_SIZE)
        {
            bool ledToggle;

            // Toggle both LEDs for each second page
            ledToggle = (address % (EFL_PAGE_SIZE * 2)) == 0;

            // LED on
            if (ledToggle)
            {
                PIN_setOutputValue(hGpioPin, IOID_GREEN_LED, Board_LED_ON);
                PIN_setOutputValue(hGpioPin, IOID_RED_LED, Board_LED_OFF);
            }

            // Erase the page
            ExtFlash_erase(address,EFL_PAGE_SIZE);

            // LED off
            if (ledToggle)
            {
                PIN_setOutputValue(hGpioPin, IOID_RED_LED, Board_LED_ON);
                PIN_setOutputValue(hGpioPin, IOID_GREEN_LED, Board_LED_OFF);
            }
        }
        PIN_setOutputValue(hGpioPin, IOID_RED_LED, Board_LED_OFF);

        ExtFlash_close();
    }

    SensorTagDisplay_resume();
}
/*******************************************************************************
 * @fn          devpkLcdClose
 *
 * @brief       Turns of the display and releases the LCD control pins
 *
 * @return      true if success
 */
void devpkLcdClose(void)
{
  if (hLcdPin != NULL)
  {
    // Turn off the display
    PIN_setOutputValue(hLcdPin,Board_DEVPK_LCD_DISP,0);

    PIN_close(hLcdPin);
    hLcdPin = NULL;

    bspSpiClose();
  }
}
/*******************************************************************************
 * @fn      SensorTagFactoryReset_applyFactoryImage
 *
 * @brief   Load the factory image from external flash and reboot
 *
 * @return  none
 */
void SensorTagFactoryReset_applyFactoryImage(void)
{
    SensorTagDisplay_suspend();

    if (SensorTagFactoryReset_hasImage())
    {
        // Indicate that factory image is launched
        PIN_setOutputValue(hGpioPin, IOID_GREEN_LED, Board_LED_ON);

        // Load and launch factory image; page 0 and 31 must be omitted
        ((void (*)(uint32_t, uint32_t, uint32_t))BL_OFFSET)
            (EFL_ADDR_RECOVERY + APP_START, // Location in external flash
             EFL_SIZE_RECOVERY - 0x2000,    // Length
             APP_START);                    // Location in internal flash
    }
    else
    {
        // Indicate that factory image launch failed
        PIN_setOutputValue(hGpioPin, IOID_RED_LED, Board_LED_ON);
    }

    SensorTagDisplay_resume();
}
/*******************************************************************************
 * @fn          devpkLcdPower
 *
 * @brief       Enables/disables the display
 *
 * @return      true if success
 */
bool devpkLcdPower(uint8_t state)
{
  bool ret;

  if (hLcdPin != NULL &&
      (state == DEVPK_LCD_POWER_OFF | state == DEVPK_LCD_POWER_ON))
  {
    PIN_setOutputValue(hLcdPin, Board_DEVPK_LCD_DISP, state);
    ret = true;
  }
  else
  {
    ret = false;
  }

  return ret;
}
/*******************************************************************************
 * @fn          devpkLcdOpen
 *
 * @brief       Initialize the LCD
 *
 * @descr       Initializes the pins used by the LCD, creates resource access
 *              protection semaphore, turns on the LCD device, initializes the
 *              frame buffer, initializes to white background/dark foreground,
 *              and finally clears the display.
 *
 * @return      true if success
 */
bool devpkLcdOpen(void)
{
  hLcdPin = PIN_open(&pinState, BoardDevpackLCDPinTable);

  if (hLcdPin != 0)
  {
    display.bg = ClrBlack;
    display.fg = ClrWhite;

    // Open the SPI driver
    bspSpiOpen();

    // Exclusive access
    Semaphore_Params_init(&semParamsLCD);
    semParamsLCD.mode = Semaphore_Mode_BINARY;
    Semaphore_construct(&semLCD, 1, &semParamsLCD);
    hSemLCD = Semaphore_handle(&semLCD);

    // Turn on the display
    PIN_setOutputValue(hLcdPin,Board_DEVPK_LCD_DISP,1);

    // Graphics library init
    GrContextInit(&g_sContext, &g_sharp96x96LCD);

    // Graphics properties
    GrContextForegroundSet(&g_sContext, display.fg);
    GrContextBackgroundSet(&g_sContext, display.bg);
    GrContextFontSet(&g_sContext, &g_sFontFixed6x8);

    // Clear display
    GrClearDisplay(&g_sContext);
    GrFlush(&g_sContext);
  }

  return hLcdPin != 0;
}
static void LCDTask_turnOffLCD(void) {
    // Turn off LCD
    PIN_setOutputValue(hGpioPin, Board_LCD_PWR, Board_LCD_PWR_OFF);
}
/*********************************************************************
 * @fn      SensorTagIO_processCharChangeEvt
 *
 * @brief   Process a change in the IO characteristics
 *
 * @return  none
 */
void SensorTagIO_processCharChangeEvt(uint8_t paramID)
{ 
  if( paramID == SENSOR_CONF )
  {
    
    Io_getParameter(SENSOR_CONF, &ioMode);
    if (ioMode == IO_MODE_SELFTEST)
    {
      ioValue = sensorTestResult();
      Io_setParameter(SENSOR_DATA, 1, &ioValue);
    }
    else 
    {
      // Mode change: make sure LEDs and buzzer are off
      Io_setParameter(SENSOR_DATA, 1, &ioValue);
      
      PIN_setOutputValue(hGpioPin, Board_LED1, Board_LED_OFF);
      PIN_setOutputValue(hGpioPin, Board_LED2, Board_LED_OFF);
      Clock_stop(buzzClockHandle);
      PIN_setOutputValue(hGpioPin, Board_BUZZER, Board_BUZZER_OFF);
    }
  } 
  else if (paramID == SENSOR_DATA)
  {
    Io_getParameter(SENSOR_DATA, &ioValue);
  }
  
  if (ioMode == IO_MODE_REMOTE)
  {
    // Control by remote client: 
    // - possible to operate the LEDs and buzzer
    // - right key functionality overridden (will not terminate connection)
    if (!!(ioValue & IO_DATA_LED1))
    {
      PIN_setOutputValue(hGpioPin, Board_LED1, Board_LED_ON);
    }
    else
    {
      PIN_setOutputValue(hGpioPin, Board_LED1, Board_LED_OFF);
    }
    
    if (!!(ioValue & IO_DATA_LED2))
    {
      PIN_setOutputValue(hGpioPin, Board_LED2, Board_LED_ON);
    }
    else
    {
      PIN_setOutputValue(hGpioPin, Board_LED2, Board_LED_OFF);
    }
    
    if (!!((ioValue & IO_DATA_BUZZER)))
    {
      Clock_start(buzzClockHandle);
    }
    else
    {
      Clock_stop(buzzClockHandle);
      PIN_setOutputValue(hGpioPin, Board_BUZZER, Board_BUZZER_OFF);
    }
  }
}
예제 #23
0
/*******************************************************************************
 * @fn      SensorTag_processStateChangeEvt
 *
 * @brief   Process a pending GAP Role state change event.
 *
 * @param   newState - new state
 *
 * @return  none
 */
static void SensorTag_processStateChangeEvt(gaprole_States_t newState)
{
#ifdef PLUS_BROADCASTER
  static bool firstConnFlag = false;
#endif // PLUS_BROADCASTER

  switch (newState)
  {
  case GAPROLE_STARTED:
    {
      uint8_t ownAddress[B_ADDR_LEN];
      uint8_t systemId[DEVINFO_SYSTEM_ID_LEN];

      SensorTag_blinkLed(Board_LED2, 5);

      GAPRole_GetParameter(GAPROLE_BD_ADDR, ownAddress);

      // use 6 bytes of device address for 8 bytes of system ID value
      systemId[0] = ownAddress[0];
      systemId[1] = ownAddress[1];
      systemId[2] = ownAddress[2];

      // set middle bytes to zero
      systemId[4] = 0x00;
      systemId[3] = 0x00;

      // shift three bytes up
      systemId[7] = ownAddress[5];
      systemId[6] = ownAddress[4];
      systemId[5] = ownAddress[3];

      DevInfo_SetParameter(DEVINFO_SYSTEM_ID, DEVINFO_SYSTEM_ID_LEN, systemId);
      LCD_WRITES_STATUS("Initialized");
    }
    break;

  case GAPROLE_ADVERTISING:
    // Start the clock
    if (!Util_isActive(&periodicClock))
    {
      Util_startClock(&periodicClock);
    }

    // Make sure key presses are not stuck
    sensorTag_updateAdvertisingData(0);

    LCD_WRITES_STATUS("Advertising");
    break;

  case GAPROLE_CONNECTED:
    {
      // Start the clock
      if (!Util_isActive(&periodicClock))
      {
        Util_startClock(&periodicClock);
      }

      // Turn of LEDs and buzzer
      PIN_setOutputValue(hGpioPin, Board_LED1, Board_LED_OFF);
      PIN_setOutputValue(hGpioPin, Board_LED2, Board_LED_OFF);
      PIN_setOutputValue(hGpioPin, Board_BUZZER, Board_BUZZER_OFF);
#ifdef FEATURE_OAD
      SensorTagConnectionControl_update();
#endif

#ifdef PLUS_BROADCASTER
      // Only turn advertising on for this state when we first connect
      // otherwise, when we go from connected_advertising back to this state
      // we will be turning advertising back on.
      if (firstConnFlag == false)
      {
        uint8_t advertEnabled = TRUE; // Turn on Advertising

        GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t),
                             &advertEnabled);
        firstConnFlag = true;
      }
#endif // PLUS_BROADCASTER
    }
    LCD_WRITES_STATUS("Connected");
    break;

  case GAPROLE_CONNECTED_ADV:
    break;

  case GAPROLE_WAITING:
  case GAPROLE_WAITING_AFTER_TIMEOUT:
    SensorTag_resetAllSensors();
    LCD_WRITES_STATUS("Waiting...");
    break;

  case GAPROLE_ERROR:
    SensorTag_resetAllSensors();
    PIN_setOutputValue(hGpioPin,Board_LED1, Board_LED_ON);
    LCD_WRITES_STATUS("Error");
    break;

  default:
    break;
  }

  gapProfileState = newState;
}
/*******************************************************************************
 * @fn      SensorTagFactoryReset_storeCurrentImage
 *
 * @brief   Save the current image to external flash as a factory image
 *
 * @return  none
 */
bool SensorTagFactoryReset_storeCurrentImage(void)
{
  bool success;

  success = ExtFlash_open();

  if (success)
  {
    uint32_t address;
    uint16_t imageCRC = 0;

    // Install factory image
    for (address=0; address<EFL_SIZE_RECOVERY && success; address+=EFL_PAGE_SIZE)
    {
        size_t offset;
        bool ledToggle;

        ledToggle = (address % (EFL_PAGE_SIZE * 2)) == 0;

        // LED on
        if (ledToggle)
        {
            PIN_setOutputValue(hGpioPin, IOID_GREEN_LED, Board_LED_ON);
            PIN_setOutputValue(hGpioPin, IOID_RED_LED, Board_LED_OFF);
        }

        // Erase the page
        ExtFlash_erase(address,EFL_PAGE_SIZE);

        for (offset=0; offset<EFL_PAGE_SIZE && success; offset+=sizeof(buf))
        {
            const uint8_t *pIntFlash;
            int i;

            // Copy from internal to external flash
            pIntFlash = (const uint8_t*)address + offset;
            memcpy(buf,pIntFlash,sizeof(buf));
            success = ExtFlash_write(EFL_ADDR_RECOVERY+address+offset,
                                    sizeof(buf), buf);

            if (success)
            {
                // Add CRC
                for (i = 0; i < sizeof(buf); i++)
                {
                    imageCRC = crc16(imageCRC, buf[i]);
                }
            }
        }

        // LED off
        if (ledToggle)
        {
            PIN_setOutputValue(hGpioPin, IOID_GREEN_LED, Board_LED_OFF);
            PIN_setOutputValue(hGpioPin, IOID_RED_LED, Board_LED_ON);
        }
    }

    if (success)
    {
        PIN_setOutputValue(hGpioPin, IOID_RED_LED, Board_LED_OFF);

        imageCRC = crc16(imageCRC, 0);
        imageCRC = crc16(imageCRC, 0);

        // Erase mata-data page
        ExtFlash_erase(EFL_IMAGE_INFO_ADDR_FACTORY, EFL_PAGE_SIZE);

        // Populate meta-data
        imgInfo.crc[0] = imageCRC;
        imgInfo.crc[1]= 0xFFFF;
        imgInfo.addr = 0x0000;
        imgInfo.ver = 0;
        imgInfo.len = EFL_SIZE_RECOVERY / EFL_OAD_ADDR_RESOLUTION;
        imgInfo.imgType = EFL_OAD_IMG_TYPE_FACTORY;
        imgInfo.uid[0]= 'F';
        imgInfo.uid[1]= 'F';
        imgInfo.uid[2]= 'F';
        imgInfo.uid[3]= 'F';
        imgInfo.status = 0xFF;

        // Store CRC in the meta-data region for factory image
        ExtFlash_write(EFL_IMAGE_INFO_ADDR_FACTORY, sizeof(ExtImageInfo_t),
                       (uint8_t*)&imgInfo);
    }
    else
    {
        // Erase the meta-data to invalidate factory image
        ExtFlash_erase(EFL_IMAGE_INFO_ADDR_FACTORY, EFL_PAGE_SIZE);
    }

    ExtFlash_close();
  }

  return success;
}
예제 #25
0
/*********************************************************************
 * @fn      SensorTagIO_processCharChangeEvt
 *
 * @brief   Process a change in the IO characteristics
 *
 * @param   none
 *
 * @return  none
 */
void SensorTagIO_processCharChangeEvt(uint8_t paramID)
{
  if (paramID == SENSOR_CONF)
  {

    Io_getParameter(SENSOR_CONF, &ioMode);
    if (ioMode == IO_MODE_SELFTEST)
    {
      ioValue = SensorTag_testResult();
      Io_setParameter(SENSOR_DATA, 1, &ioValue);
    }
    else
    {
      // Mode change: make sure LEDs are off
      Io_setParameter(SENSOR_DATA, 1, &ioValue);

      PIN_setOutputValue(hGpioPin, IOID_RED_LED, Board_LED_OFF);
      PIN_setOutputValue(hGpioPin, IOID_GREEN_LED, Board_LED_OFF);
      PIN_setOutputValue(hGpioPin, IOID_BLUE_LED, Board_LED_OFF);

    }
  }
  else if (paramID == SENSOR_DATA)
  {
    Io_getParameter(SENSOR_DATA, &ioValue);
  }

  if (ioMode == IO_MODE_REMOTE)
  {
    // Control by remote client:
    // - possible to operate the LEDs and buzzer
    // - right key functionality overridden (will not terminate connection)
    if (!!(ioValue & IO_DATA_LED_R))
    {
      PIN_setOutputValue(hGpioPin, IOID_RED_LED, Board_LED_ON);
    }
    else
    {
      PIN_setOutputValue(hGpioPin, IOID_RED_LED, Board_LED_OFF);
    }

    if (!!(ioValue & IO_DATA_LED_G))
    {
      PIN_setOutputValue(hGpioPin, IOID_GREEN_LED, Board_LED_ON);
    }
    else
    {
      PIN_setOutputValue(hGpioPin, IOID_GREEN_LED, Board_LED_OFF);
    }

    if (!!(ioValue & IO_DATA_LED_B))
    {
      PIN_setOutputValue(hGpioPin, IOID_BLUE_LED, Board_LED_ON);
    }
    else
    {
      PIN_setOutputValue(hGpioPin, IOID_BLUE_LED, Board_LED_OFF);
    }

    if (!!((ioValue & IO_DATA_EXT_FLASH_ERASE)))
    {
        SensorTagFactoryReset_extFlashErase();
    }
  }
}