Exemplo n.º 1
0
/*********************************************************************
 * @fn      Thermometer_Init
 *
 * @brief   Initialization function for the Thermometer App Task.
 *          This is called during initialization and should contain
 *          any application specific initialization (ie. hardware
 *          initialization/setup, table initialization, power up
 *          notificaiton ... ).
 *
 * @param   task_id - the ID assigned by OSAL.  This ID should be
 *                    used to send messages and set timers.
 *
 * @return  none
 */
void Thermometer_Init( uint8 task_id )
{
    thermometerTaskId = task_id;

    /* Use for testing if chip default is 0xFFFFFF
    static uint8 bdAddress[6] = {0x1,0x2,0x3,0x4,0x5,0x6};
    HCI_EXT_SetBDADDRCmd(bdAddress);
    */

    // Setup the GAP Peripheral Role Profile
    {
        // Device doesn't start advertising until button is pressed
        uint8 initial_advertising_enable = FALSE;

        // By setting this to zero, the device will go into the waiting state after
        // being discoverable for 30.72 second, and will not being advertising again
        // until the enabler is set back to TRUE
        uint16 gapRole_AdvertOffTime = 0;

        uint8 enable_update_request = DEFAULT_ENABLE_UPDATE_REQUEST;
        uint16 desired_min_interval = DEFAULT_DESIRED_MIN_CONN_INTERVAL;
        uint16 desired_max_interval = DEFAULT_DESIRED_MAX_CONN_INTERVAL;
        uint16 desired_slave_latency = DEFAULT_DESIRED_SLAVE_LATENCY;
        uint16 desired_conn_timeout = DEFAULT_DESIRED_CONN_TIMEOUT;

        // Set the GAP Role Parameters
        GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &initial_advertising_enable );
        GAPRole_SetParameter( GAPROLE_ADVERT_OFF_TIME, sizeof( uint16 ), &gapRole_AdvertOffTime );

        GAPRole_SetParameter( GAPROLE_SCAN_RSP_DATA, sizeof ( scanResponseData ), scanResponseData );
        GAPRole_SetParameter( GAPROLE_ADVERT_DATA, sizeof( advertData ), advertData );

        GAPRole_SetParameter( GAPROLE_PARAM_UPDATE_ENABLE, sizeof( uint8 ), &enable_update_request );
        GAPRole_SetParameter( GAPROLE_MIN_CONN_INTERVAL, sizeof( uint16 ), &desired_min_interval );
        GAPRole_SetParameter( GAPROLE_MAX_CONN_INTERVAL, sizeof( uint16 ), &desired_max_interval );
        GAPRole_SetParameter( GAPROLE_SLAVE_LATENCY, sizeof( uint16 ), &desired_slave_latency );
        GAPRole_SetParameter( GAPROLE_TIMEOUT_MULTIPLIER, sizeof( uint16 ), &desired_conn_timeout );
    }

    // Set the GAP Characteristics
    GGS_SetParameter( GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, attDeviceName );

    // Setup the GAP Bond Manager
    {
        uint32 passkey = 0; // passkey "000000"
        uint8 pairMode = GAPBOND_PAIRING_MODE_WAIT_FOR_REQ;
        uint8 mitm = FALSE;
        uint8 ioCap = GAPBOND_IO_CAP_DISPLAY_ONLY;
        uint8 bonding = TRUE;
        GAPBondMgr_SetParameter( GAPBOND_DEFAULT_PASSCODE, sizeof ( uint32 ), &passkey );
        GAPBondMgr_SetParameter( GAPBOND_PAIRING_MODE, sizeof ( uint8 ), &pairMode );
        GAPBondMgr_SetParameter( GAPBOND_MITM_PROTECTION, sizeof ( uint8 ), &mitm );
        GAPBondMgr_SetParameter( GAPBOND_IO_CAPABILITIES, sizeof ( uint8 ), &ioCap );
        GAPBondMgr_SetParameter( GAPBOND_BONDING_ENABLED, sizeof ( uint8 ), &bonding );
    }

    // Setup the Thermometer Characteristic Values
    {
        uint8 thermometerSite = THERMOMETER_TYPE_MOUTH;
        Thermometer_SetParameter( THERMOMETER_TYPE, sizeof ( uint8 ), &thermometerSite );

        thermometerIRange_t thermometerIRange= {4,60};
        Thermometer_SetParameter( THERMOMETER_IRANGE, sizeof ( uint16 ), &thermometerIRange );
    }

    // Stop config reads when done
    timeConfigDone = FALSE;

    // Initialize GATT Client
    VOID GATT_InitClient();

    // Register to receive incoming ATT Indications/Notifications
    GATT_RegisterForInd( thermometerTaskId );

    // Initialize GATT attributes
    GGS_AddService( GATT_ALL_SERVICES );         // GAP
    GATTServApp_AddService( GATT_ALL_SERVICES ); // GATT attributes
    Thermometer_AddService( GATT_ALL_SERVICES );
    DevInfo_AddService( );

    // Register for Thermometer service callback
    Thermometer_Register ( thermometerCB );

    // Register for all key events - This app will handle all key events
    RegisterForKeys( thermometerTaskId );

#if defined( CC2540_MINIDK )
    // makes sure LEDs are off
    HalLedSet( (HAL_LED_1 | HAL_LED_2), HAL_LED_MODE_OFF );

    // For keyfob board set GPIO pins into a power-optimized state
    // Note that there is still some leakage current from the buzzer,
    // accelerometer, LEDs, and buttons on the PCB.

    P0SEL = 0; // Configure Port 0 as GPIO
    P1SEL = 0; // Configure Port 1 as GPIO
    P2SEL = 0; // Configure Port 2 as GPIO

    P0DIR = 0xFC; // Port 0 pins P0.0 and P0.1 as input (buttons),
    // all others (P0.2-P0.7) as output
    P1DIR = 0xFF; // All port 1 pins (P1.0-P1.7) as output
    P2DIR = 0x1F; // All port 1 pins (P2.0-P2.4) as output

    P0 = 0x03; // All pins on port 0 to low except for P0.0 and P0.1 (buttons)
    P1 = 0;   // All pins on port 1 to low
    P2 = 0;   // All pins on port 2 to low

#endif // #if defined( CC2540_MINIDK )  

    // Setup a delayed profile startup
    osal_set_event( thermometerTaskId, TH_START_DEVICE_EVT );
}
Exemplo n.º 2
0
/*********************************************************************
 * @fn      Thermometer_init
 *
 * @brief   Initialization function for the Thermometer App Task.
 *          This is called during initialization and should contain
 *          any application specific initialization (ie. hardware
 *          initialization/setup, table initialization, power up
 *          notification ...).
 *
 * @param   None.
 *
 * @return  None.
 */
void Thermometer_init(void)
{
	// ******************************************************************
  // N0 STACK API CALLS CAN OCCUR BEFORE THIS CALL TO ICall_registerApp
  // ******************************************************************
  // Register the current thread as an ICall dispatcher application
  // so that the application can send and receive messages.
  ICall_registerApp(&selfEntity, &sem);

  // Hard code the DB Address till CC2650 board gets its own IEEE address.
  //uint8_t bdAddress[B_ADDR_LEN] = { 0x22, 0x22, 0x22, 0x22, 0x22, 0x22 };
  //HCI_EXT_SetBDADDRCmd(bdAddress);
  
  // Set device's Sleep Clock Accuracy
  //HCI_EXT_SetSCACmd(40);
  
  // Create an RTOS queue for message from profile to be sent to app.
  appMsgQueue = Util_constructQueue(&appMsg);
  
  // Setup clocks.
  Util_constructClock(&startDiscoveryClock, Thermometer_clockHandler, 
                      DEFAULT_DISCOVERY_DELAY, 0, false,
                      THERMOMETER_START_DISC_EVT);
  Util_constructClock(&disconnectClock, Thermometer_clockHandler, 
                      DEFAULT_TERMINATE_DELAY, 0, false,
                      THERMOMETER_DISCONNECT_EVT);
  Util_constructClock(&perMeasClock, Thermometer_clockHandler, 
                      DEFAULT_THERMOMETER_MEAS_DELAY, 0, false,
                      THERMOMETER_PERIODIC_MEAS_EVT);
  Util_constructClock(&perIMeasClock, Thermometer_clockHandler, 
                      DEFAULT_THERMOMETER_IMEAS_DELAY, 0, false,
                      THERMOMETER_PERIODIC_IMEAS_EVT);
  
  // Initialize keys on the SRF06.
  Board_initKeys(Thermometer_keyPressHandler);
  
  // Setup the GAP Peripheral Role Profile.
  {
    // Device doesn't start advertising until button is pressed.
    uint8_t initial_advertising_enable = FALSE;

    // By setting this to zero, the device will go into the waiting state after
    // being discoverable for 30.72 second, and will not being advertising again
    // until the enabler is set back to TRUE.
    uint16_t gapRole_AdvertOffTime = 0;
      
    uint8_t enable_update_request = DEFAULT_ENABLE_UPDATE_REQUEST;
    uint16_t desired_min_interval = DEFAULT_DESIRED_MIN_CONN_INTERVAL;
    uint16_t desired_max_interval = DEFAULT_DESIRED_MAX_CONN_INTERVAL;
    uint16_t desired_slave_latency = DEFAULT_DESIRED_SLAVE_LATENCY;
    uint16_t desired_conn_timeout = DEFAULT_DESIRED_CONN_TIMEOUT;

    // Set the GAP Role Parameters.
    GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), 
                         &initial_advertising_enable);
    GAPRole_SetParameter(GAPROLE_ADVERT_OFF_TIME, sizeof(uint16_t),
                         &gapRole_AdvertOffTime);
    
    GAPRole_SetParameter(GAPROLE_SCAN_RSP_DATA, sizeof (scanResponseData), 
                         scanResponseData);
    GAPRole_SetParameter(GAPROLE_ADVERT_DATA, sizeof(advertData), 
                         advertData);
    
    GAPRole_SetParameter(GAPROLE_PARAM_UPDATE_ENABLE, sizeof(uint8_t), 
                         &enable_update_request);
    GAPRole_SetParameter(GAPROLE_MIN_CONN_INTERVAL, sizeof(uint16_t), 
                         &desired_min_interval);
    GAPRole_SetParameter(GAPROLE_MAX_CONN_INTERVAL, sizeof(uint16_t), 
                         &desired_max_interval);
    GAPRole_SetParameter(GAPROLE_SLAVE_LATENCY, sizeof(uint16_t), 
                         &desired_slave_latency);
    GAPRole_SetParameter(GAPROLE_TIMEOUT_MULTIPLIER, sizeof(uint16_t), 
                         &desired_conn_timeout);
  }
  
  // Set the GAP Characteristics.
  GGS_SetParameter(GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, attDeviceName);

  // Setup the GAP Bond Manager.
  {
    uint32_t passkey = 0; // passkey "000000"
    uint8_t pairMode = GAPBOND_PAIRING_MODE_WAIT_FOR_REQ;
    uint8_t mitm = FALSE;
    uint8_t ioCap = GAPBOND_IO_CAP_DISPLAY_ONLY;
    uint8_t bonding = TRUE;
    
    GAPBondMgr_SetParameter(GAPBOND_DEFAULT_PASSCODE, sizeof (uint32_t), 
                            &passkey);
    GAPBondMgr_SetParameter(GAPBOND_PAIRING_MODE, sizeof(uint8_t), &pairMode);
    GAPBondMgr_SetParameter(GAPBOND_MITM_PROTECTION, sizeof(uint8_t), &mitm);
    GAPBondMgr_SetParameter(GAPBOND_IO_CAPABILITIES, sizeof(uint8_t), &ioCap);
    GAPBondMgr_SetParameter(GAPBOND_BONDING_ENABLED, sizeof(uint8_t), &bonding);
  }  
   
  // Initialize GATT Client.
  VOID GATT_InitClient();

  // Register to receive incoming ATT Indications/Notifications.
  GATT_RegisterForInd(selfEntity);
  
  // Initialize GATT attributes.
  GGS_AddService(GATT_ALL_SERVICES);         // GAP
  GATTServApp_AddService(GATT_ALL_SERVICES); // GATT attributes
  
  // Add Thermometer services.
  Thermometer_AddService(GATT_ALL_SERVICES);
  
  // Add device info services.
  DevInfo_AddService();

  // Register for Thermometer service callback.
  Thermometer_Register (Thermometer_serviceCB);
  
  // Setup the Thermometer Characteristic Values.
  {
    uint8_t thermometerSite = THERMOMETER_TYPE_MOUTH;
    thermometerIRange_t thermometerIRange= {4,60000};
    
    Thermometer_SetParameter(THERMOMETER_TYPE, sizeof(uint8_t), 
                             &thermometerSite);    
    
    Thermometer_SetParameter(THERMOMETER_IRANGE, sizeof(thermometerIRange_t), 
                             &thermometerIRange);
  }
  
  // Initialize measurement storage table
  memset(thStoreMeas, 0, (sizeof(attHandleValueInd_t) * TH_STORE_MAX));
  
  // Start the Device.
  VOID GAPRole_StartDevice(&thermometer_PeripheralCBs);
    
  // Register with bond manager after starting device.
  VOID GAPBondMgr_Register((gapBondCBs_t *)&thermometer_BondMgrCBs);
}