本文整理汇总了C++中osal_start_timerEx函数的典型用法代码示例。如果您正苦于以下问题:C++ osal_start_timerEx函数的具体用法?C++ osal_start_timerEx怎么用?C++ osal_start_timerEx使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了osal_start_timerEx函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: timeAppGapStateCB
/*********************************************************************
* @fn timeAppGapStateCB
*
* @brief Notification from the profile of a state change.
*
* @param newState - new state
*
* @return none
*/
static void timeAppGapStateCB( gaprole_States_t newState )
{
// if connected
if ( newState == GAPROLE_CONNECTED )
{
linkDBItem_t *pItem;
// Get connection handle
GAPRole_GetParameter( GAPROLE_CONNHANDLE, &timeAppConnHandle );
// Get peer bd address
if ( (pItem = linkDB_Find( timeAppConnHandle )) != NULL)
{
// If connected to device without bond do service discovery
if ( !osal_memcmp( pItem->addr, timeAppBondedAddr, B_ADDR_LEN ) )
{
timeAppDiscoveryCmpl = FALSE;
}
// Initiate service discovery if necessary
if ( timeAppDiscoveryCmpl == FALSE )
{
osal_start_timerEx( timeAppTaskId, START_DISCOVERY_EVT, DEFAULT_DISCOVERY_DELAY );
}
}
LCD_WRITE_STRING( "Connected", HAL_LCD_LINE_1 );
LCD_WRITE_STRING( "", HAL_LCD_LINE_2 );
}
// if disconnected
else if ( timeAppGapState == GAPROLE_CONNECTED &&
newState != GAPROLE_CONNECTED )
{
uint8 advState = TRUE;
timeAppDisconnected();
if ( newState == GAPROLE_WAITING_AFTER_TIMEOUT )
{
// link loss timeout-- use fast advertising
GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MIN, DEFAULT_FAST_ADV_INTERVAL );
GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MAX, DEFAULT_FAST_ADV_INTERVAL );
GAP_SetParamValue( TGAP_GEN_DISC_ADV_MIN, DEFAULT_FAST_ADV_DURATION );
}
else
{
// Else use slow advertising
GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MIN, DEFAULT_SLOW_ADV_INTERVAL );
GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MAX, DEFAULT_SLOW_ADV_INTERVAL );
GAP_SetParamValue( TGAP_GEN_DISC_ADV_MIN, DEFAULT_SLOW_ADV_DURATION );
}
// Enable advertising
GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &advState );
LCD_WRITE_STRING( "Disconnected", HAL_LCD_LINE_1 );
LCD_WRITE_STRING( "", HAL_LCD_LINE_2 );
}
// if advertising stopped
else if ( timeAppGapState == GAPROLE_ADVERTISING &&
newState == GAPROLE_WAITING )
{
// if advertising stopped by user
if ( timeAppAdvCancelled )
{
timeAppAdvCancelled = FALSE;
}
// if fast advertising switch to slow
else if ( GAP_GetParamValue( TGAP_GEN_DISC_ADV_INT_MIN ) == DEFAULT_FAST_ADV_INTERVAL )
{
uint8 advState = TRUE;
GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MIN, DEFAULT_SLOW_ADV_INTERVAL );
GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MAX, DEFAULT_SLOW_ADV_INTERVAL );
GAP_SetParamValue( TGAP_GEN_DISC_ADV_MIN, DEFAULT_SLOW_ADV_DURATION );
GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &advState );
}
}
// if started
else if ( newState == GAPROLE_STARTED )
{
#ifndef CC2540_MINIDK
uint8 bdAddr[B_ADDR_LEN];
GAPRole_GetParameter( GAPROLE_BD_ADDR, &bdAddr );
LCD_WRITE_STRING( "Time App", HAL_LCD_LINE_1 );
LCD_WRITE_STRING( bdAddr2Str( bdAddr ), HAL_LCD_LINE_2 );
#endif
// Initialize time clock after writing first two lines of LCD
//.........这里部分代码省略.........
示例2: MT_AfDataRequest
//.........这里部分代码省略.........
if (dstAddr.addrMode == afAddr64Bit)
{
(void)osal_memcpy(dstAddr.addr.extAddr, pBuf, Z_EXTADDR_LEN);
}
else
{
dstAddr.addr.shortAddr = BUILD_UINT16(pBuf[0], pBuf[1]);
}
pBuf += Z_EXTADDR_LEN;
dstAddr.endPoint = *pBuf++;
dstAddr.panId = BUILD_UINT16(pBuf[0], pBuf[1]);
pBuf += 2;
}
else
{
/* Destination address */
dstAddr.addrMode = afAddr16Bit;
dstAddr.addr.shortAddr = BUILD_UINT16(pBuf[0], pBuf[1]);
pBuf += 2;
/* Destination endpoint */
dstAddr.endPoint = *pBuf++;
dstAddr.panId = 0;
}
/* Source endpoint */
epDesc = afFindEndPointDesc(*pBuf++);
/* ClusterId */
cId = BUILD_UINT16(pBuf[0], pBuf[1]);
pBuf +=2;
/* TransId */
transId = *pBuf++;
/* TxOption */
txOpts = *pBuf++;
/* Radius */
radius = *pBuf++;
/* Length */
if (cmd1 == MT_AF_DATA_REQUEST_EXT)
{
dataLen = BUILD_UINT16(pBuf[0], pBuf[1]);
tempLen = dataLen + MT_AF_REQ_MSG_LEN + MT_AF_REQ_MSG_EXT;
pBuf += 2;
}
else
{
dataLen = *pBuf++;
tempLen = dataLen + MT_AF_REQ_MSG_LEN;
}
if ( epDesc == NULL )
{
retValue = afStatus_INVALID_PARAMETER;
}
else if (tempLen > (uint16)MT_RPC_DATA_MAX)
{
if (pMtAfDataReq != NULL)
{
retValue = afStatus_INVALID_PARAMETER;
}
else if ((pMtAfDataReq = osal_mem_alloc(sizeof(mtAfDataReq_t) + dataLen)) == NULL)
{
retValue = afStatus_MEM_FAIL;
}
else
{
retValue = afStatus_SUCCESS;
pMtAfDataReq->data = (uint8 *)(pMtAfDataReq+1);
(void)osal_memcpy(&(pMtAfDataReq->dstAddr), &dstAddr, sizeof(afAddrType_t));
pMtAfDataReq->epDesc = epDesc;
pMtAfDataReq->cId = cId;
pMtAfDataReq->dataLen = dataLen;
pMtAfDataReq->transId = transId;
pMtAfDataReq->txOpts = txOpts;
pMtAfDataReq->radius = radius;
// Setup to time-out the huge outgoing item if host does not MT_AF_DATA_STORE it.
pMtAfDataReq->tick = MT_AF_EXEC_CNT;
if (ZSuccess != osal_start_timerEx(MT_TaskID, MT_AF_EXEC_EVT, MT_AF_EXEC_DLY))
{
(void)osal_set_event(MT_TaskID, MT_AF_EXEC_EVT);
}
}
}
else
{
retValue = AF_DataRequest(&dstAddr, epDesc, cId, dataLen, pBuf, &transId, txOpts, radius);
}
if (MT_RPC_CMD_SREQ == (cmd0 & MT_RPC_CMD_TYPE_MASK))
{
MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP|(uint8)MT_RPC_SYS_AF), cmd1, 1, &retValue);
}
}
示例3: simpleBLECentralEventCB
/*********************************************************************************************
* @fn simpleBLECentralEventCB
*
* @brief Central event callback function.
*
* @param pEvent - pointer to event structure
*
* @return none
**********************************************************************************************/
static void simpleBLECentralEventCB( gapCentralRoleEvent_t *pEvent ){
switch ( pEvent->gap.opcode ){
case GAP_DEVICE_INIT_DONE_EVENT:{
//LCDPrintText("Central Initialized",0,PRINT_STRING);
osal_memcpy(mac_buffer[0],pEvent->initDone.devAddr, MAC_LEN);
HalLcdWriteString(bdAddr2Str( mac_buffer[0]), HAL_LCD_LINE_1);
uint32 random_scan_duration =500;//to avoid normal scan be discarded by the timer,so its lasting-time should be short
GAP_SetParamValue( TGAP_GEN_DISC_SCAN, random_scan_duration ); //random scan duration
//LCDPrintText("discovering",0,PRINT_STRING);
uint32 timeout_value = 200; // timeout_value - in milliseconds.
osal_start_timerEx(MasterSlaveSwitchTaskID, PERIOD_DETECH_EVT, timeout_value);
uint8 return_status;
if(return_status = GAPCentralRole_StartDiscovery(DISCOVERY_MODE, ACTIVE_SCAN, DISCOVERY_WHITE_LIST ))
LCDPrintText("discovery error:",return_status,PRINT_VALUE);
break;
}
case GAP_DEVICE_INFO_EVENT:{ //find a new device
// filtering device discovery results based on service UUID
//LCDPrintText("find new device",0,PRINT_STRING);
if(simpleBLEScanRes >= MAX_SCAN_RES){
GAPCentralRole_CancelDiscovery();
break;
}
if ( simpleBLEFindSvcUuid(WANTED_SERVICE_UUID, pEvent->deviceInfo.pEvtData, pEvent->deviceInfo.dataLen) ){
simpleBLEAddDeviceInfo( pEvent->deviceInfo.addr, pEvent->deviceInfo.addrType );
//GAPCentralRole_CancelDiscovery(); //stop discoverying
}
break;
}
case GAP_DEVICE_DISCOVERY_EVENT:{ //discaovery has completed
osal_stop_timerEx(MasterSlaveSwitchTaskID,PERIOD_DETECH_EVT);
//LCDPrintText("disca completed ",0,PRINT_STRING);
if ( simpleBLEScanRes > 0 ){
// connect to current device in scan result
uint8 random_select = random_num%simpleBLEScanRes;
//LCDPrintText("random_select ",random_select,PRINT_STRING);
CurrentConnectionInfo.MacType= simpleBLEDevList[random_select].addrType;
CurrentConnectionInfo.MacAddr= simpleBLEDevList[random_select].addr;
uint8 return_status;
if(return_status = GAPCentralRole_EstablishLink( LINK_HIGH_DUTY_CYCLE, LINK_WHITE_LIST, CurrentConnectionInfo.MacType, CurrentConnectionInfo.MacAddr)){
LCDPrintText("Link Error",return_status,PRINT_VALUE);
osal_set_event(MasterSlaveSwitchTaskID, MSS_CHANGE_ROLE_EVT);
}
}
else{
//LCDPrintText("no device found",0,PRINT_STRING);
osal_set_event(MasterSlaveSwitchTaskID, MSS_CHANGE_ROLE_EVT); //switch to periperal
}
break;
}
case GAP_LINK_ESTABLISHED_EVENT:{
if ( pEvent->gap.hdr.status == SUCCESS ){
//LCDPrintText("Connected",0,PRINT_STRING);
CurrentConnectionInfo.Handle= pEvent->linkCmpl.connectionHandle;
if(CharHandleSearchFlag == 1)
simpleBLECentralStartDiscovery();
else{
ClientWriteValue();
CharSendingFlag =1;
//LCDPrintText("NO NEED TO",0,PRINT_STRING);
}
}
else{
LCDPrintText("Connect Failed ",pEvent->gap.hdr.status,PRINT_VALUE);
osal_set_event(MasterSlaveSwitchTaskID, MSS_CHANGE_ROLE_EVT);
}
break;
}
case GAP_LINK_TERMINATED_EVENT:{
osal_set_event(MasterSlaveSwitchTaskID, MSS_CHANGE_ROLE_EVT);
break;
//.........这里部分代码省略.........
示例4: Hal_ProcessEvent
/**************************************************************************************************
* @fn Hal_ProcessEvent
*
* @brief Hal Process Event
*
* @param task_id - Hal TaskId
* events - events
*
* @return None
**************************************************************************************************/
uint16 Hal_ProcessEvent( uint8 task_id, uint16 events )
{
uint8 *msgPtr;
(void)task_id; // Intentionally unreferenced parameter
if ( events & SYS_EVENT_MSG )
{
msgPtr = osal_msg_receive(Hal_TaskID);
while (msgPtr)
{
/* Do something here - for now, just deallocate the msg and move on */
/* De-allocate */
osal_msg_deallocate( msgPtr );
/* Next */
msgPtr = osal_msg_receive( Hal_TaskID );
}
return events ^ SYS_EVENT_MSG;
}
#if (defined HAL_BUZZER) && (HAL_BUZZER == TRUE)
if (events & HAL_BUZZER_EVENT)
{
HalBuzzerStop();
return events ^ HAL_BUZZER_EVENT;
}
#endif
#ifdef CC2591_COMPRESSION_WORKAROUND
if ( events & PERIOD_RSSI_RESET_EVT )
{
macRxResetRssi();
return (events ^ PERIOD_RSSI_RESET_EVT);
}
#endif
if ( events & HAL_LED_BLINK_EVENT )
{
#if (defined (BLINK_LEDS)) && (HAL_LED == TRUE)
HalLedUpdate();
#endif /* BLINK_LEDS && HAL_LED */
return events ^ HAL_LED_BLINK_EVENT;
}
if (events & HAL_KEY_EVENT)
{
#if (defined HAL_KEY) && (HAL_KEY == TRUE)
/* Check for keys */
HalKeyPoll();
/* if interrupt disabled, do next polling */
if (!Hal_KeyIntEnable)
{
osal_start_timerEx( Hal_TaskID, HAL_KEY_EVENT, 100);
}
#endif
return events ^ HAL_KEY_EVENT;
}
#if defined POWER_SAVING
if ( events & HAL_SLEEP_TIMER_EVENT )
{
halRestoreSleepLevel();
return events ^ HAL_SLEEP_TIMER_EVENT;
}
if ( events & HAL_PWRMGR_HOLD_EVENT )
{
(void)osal_pwrmgr_task_state(Hal_TaskID, PWRMGR_HOLD);
(void)osal_stop_timerEx(Hal_TaskID, HAL_PWRMGR_CONSERVE_EVENT);
(void)osal_clear_event(Hal_TaskID, HAL_PWRMGR_CONSERVE_EVENT);
return (events & ~(HAL_PWRMGR_HOLD_EVENT | HAL_PWRMGR_CONSERVE_EVENT));
}
if ( events & HAL_PWRMGR_CONSERVE_EVENT )
{
(void)osal_pwrmgr_task_state(Hal_TaskID, PWRMGR_CONSERVE);
return events ^ HAL_PWRMGR_CONSERVE_EVENT;
}
#endif
return 0;
}
示例5: SimpleBLEPeripheral_ProcessEvent
/*********************************************************************
* @fn SimpleBLEPeripheral_ProcessEvent
*
* @brief Simple BLE Peripheral Application Task event processor. This function
* is called to process all events for the task. Events
* include timers, messages and any other user defined events.
*
* @param task_id - The OSAL assigned task ID.
* @param events - events to process. This is a bit map and can
* contain more than one event.
*
* @return events not processed
*/
uint16 SimpleBLEPeripheral_ProcessEvent( uint8 task_id, uint16 events )
{
VOID task_id; // OSAL required parameter that isn't used in this function
if ( events & SYS_EVENT_MSG )
{
uint8 *pMsg;
if ( (pMsg = osal_msg_receive( simpleBLEPeripheral_TaskID )) != NULL )
{
simpleBLEPeripheral_ProcessOSALMsg( (osal_event_hdr_t *)pMsg );
// Release the OSAL message
VOID osal_msg_deallocate( pMsg );
}
// return unprocessed events
return (events ^ SYS_EVENT_MSG);
}
if ( events & SBP_START_DEVICE_EVT )
{
// Start the Device
VOID GAPRole_StartDevice( &simpleBLEPeripheral_PeripheralCBs );
// Start Bond Manager
VOID GAPBondMgr_Register( &simpleBLEPeripheral_BondMgrCBs );
// Set timer for first periodic event
osal_start_timerEx( simpleBLEPeripheral_TaskID, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD );
return ( events ^ SBP_START_DEVICE_EVT );
}
if ( events & SBP_PERIODIC_EVT )
{
// Restart timer
if ( SBP_PERIODIC_EVT_PERIOD )
{
osal_start_timerEx( simpleBLEPeripheral_TaskID, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD );
}
// Perform periodic application task
performPeriodicTask();
return (events ^ SBP_PERIODIC_EVT);
}
if ( events & SBP_LED_TOGGLE_EVT )
{
// Assuming that the LED is on P0_4 in the circuit.
if(led_toggle_flag == 0)
{
P0_4 = 1;
led_toggle_flag = 1;
}
else
{
P0_4 = 0;
led_toggle_flag = 0;
}
VOID osal_start_timerEx( simpleBLEPeripheral_TaskID, SBP_LED_TOGGLE_EVT, 1000 );
return ( events ^ SBP_LED_TOGGLE_EVT );
}
// Discard unknown events
return 0;
}
示例6: zapSBL_RxExt
/**************************************************************************************************
* @fn zapSBL_RxExt
*
* @brief This function is the registered callback for the UART to the external application
* that is driving the serial boot load to the ZNP.
*
* input parameters
*
* @param port - Don't care.
* @param event - Don't care.
*
* output parameters
*
* None.
*
* @return None.
**************************************************************************************************
*/
static void zapSBL_RxExt(uint8 port, uint8 event)
{
uint8 ch;
(void)port;
(void)event;
// Use external UART Rx as the trigger to start an SBL session.
if (!zapSBL_Active)
{
if ((zapSBL_Buf = osal_mem_alloc(SB_BUF_SIZE)) == NULL)
{
return;
}
zapSBL_Active = TRUE;
zapSBL_ResetZNP();
// Stop other tasks access (e.g. zapMonitor()) to SPI when in SBL mode.
(void)osal_memset(tasksEvents+1, 0, ((tasksCnt-1) * sizeof(uint16)));
for (ch = 1; ch < tasksCnt; ch++)
{
uint16 evt;
for (evt = 0x0001; evt < 0x8000; evt <<= 1)
{
(void)osal_stop_timerEx(ch, evt);
}
}
if (ZSuccess != osal_start_timerEx(zapSBL_TaskId, ZAP_SBL_EVT_EXIT, ZAP_SBL_DLY_EXIT))
{
(void)osal_set_event(zapSBL_TaskId, ZAP_SBL_EVT_EXIT);
}
#if HAL_LCD
HalLcdWriteString( "TexasInstruments", 1 );
HalLcdWriteString( "ZAP Proxy to ZNP", 2 );
HalLcdWriteString( " BootLoader ", 3 );
#endif
}
while (HalUARTRead(ZAP_SBL_EXT_PORT, &ch, 1))
{
sbBuf[sbSte + sbIdx] = ch;
switch (sbSte)
{
case SB_SOF_STATE:
if (SB_SOF == ch)
{
sbSte = SB_LEN_STATE;
}
break;
case SB_LEN_STATE:
sbFcs = 0;
sbSte = ((sbLen = ch) >= SB_BUF_SIZE) ? SB_SOF_STATE : SB_CMD1_STATE;
break;
case SB_CMD1_STATE:
sbSte = SB_CMD2_STATE;
break;
case SB_CMD2_STATE:
sbSte = (sbLen) ? SB_DATA_STATE : SB_FCS_STATE;
break;
case SB_DATA_STATE:
if (++sbIdx == sbLen)
{
sbSte = SB_FCS_STATE;
}
break;
case SB_FCS_STATE:
if (sbFcs == ch)
{
sbBuf[SB_DATA_STATE + sbIdx] = ch;
zapSBL_Tx();
}
else
{
//.........这里部分代码省略.........
示例7: pulseDataCalc
/**************************************************************************************************
* @fn pulseDataCalc
*
* @brief This function is called by MHMSAppEvt() to calculate the data for a MHMS report.
* The function will called on a 2ms interval and detect whether a pulse is being measured.
* If a pulse is determined it will invoke the MHMSdataReq interrupt timer (20ms intervals)
*
* input parameters
*
* None.
*
* output parameters
*
* None.
*
* @return None.
**************************************************************************************************
*/
static void pulseDataCalc(void)
{
MHMSEvtDat_sync = TRUE; //Pulse Data collection has been synced, no need to respond to annc commands to set EVT
static int Pulse_sketch_count = 0;
if (INVALID_NODE_ADDR == MHMSAddr)
{
return;
}
if (ZSuccess != osal_start_timerEx(MHMSTaskId, MHMS_EVT_DAT, MHMS_DLY_DAT)) //If the timer can't be started set event flag again for it to be service again
{
(void)osal_set_event(MHMSTaskId, MHMS_EVT_DAT);
}
pulseBPM(MHMSDat); //Function to collect/calculate Pulse
#if TVSA_DATA_CNF
MHMSDat[MHMS_RTG_IDX] = MHMSCnfErrCnt;
#else
MHMSDat[MHMS_RTG_IDX] = 0;
#endif
if(QS == TRUE && MHMSEvtReq_sync == FALSE) { //If pulse is being measured synchronize MHMSdatareq event
osal_set_event(MHMSTaskId, MHMS_EVT_REQ);
MHMSEvtReq_sync = TRUE;
}
else if(QS == FALSE && MHMSEvtCheckin_sync == FALSE)
{
osal_set_event(MHMSTaskId, MHMS_EVT_CHECKIN); //Since no pulse data is being collected, just send check in data to gateway
MHMSEvtCheckin_sync = TRUE;
}
Pulse_sketch_count++;
//MHMS USB communication with Pulse sensor Processor application
if(EnableUSBPulseSketchTxFlag == TRUE && Pulse_sketch_count >= 10) {
uint8 BPMBuf[7] = {'B',0,0,0,10,13};
uint8 IBIBuf[7] = {'Q',0,0,0,10,13};
uint8 SignalBuf[7] = {'S',0,0,0,10,13};
Pulse_sketch_count = 0; //reset count
//conversion Signal Dec to ASCII
uint16 temp = (BUILD_UINT16(MHMSDat[15], MHMSDat[16])) - 400;
if(temp > 999) {
SignalBuf[1] = '9';
SignalBuf[2] = '9';
SignalBuf[3] = '9';
}
else {
SignalBuf[1] = (uint8)((temp/100)+ 48);
SignalBuf[2] = (uint8)((((temp%100) - (temp % 100)%10)/10) + 48);
SignalBuf[3] = (uint8)(((temp % 100)%10)+ 48);
}
//conversion BPM Dec to ASCII
temp = (uint16)MHMSDat[13];
BPMBuf[1] = (uint8)((temp/100)+ 48);
BPMBuf[2] = (uint8)((((temp%100) - (temp % 100)%10)/10) + 48);
BPMBuf[3] = (uint8)(((temp % 100)%10)+ 48);
//conversion IBI Dec to ASCII
temp = (uint16)MHMSDat[18];
IBIBuf[1] = (uint8)((temp/100)+ 48);
IBIBuf[2] = (uint8)((((temp%100) - (temp % 100)%10)/10) + 48);
IBIBuf[3] = (uint8)(((temp % 100)%10)+ 48);
HalUARTWrite(0, SignalBuf, 6);
HalUARTWrite(0, BPMBuf, 6);
HalUARTWrite(0, IBIBuf, 6);
}
}
示例8: CyclingSensor_ProcessEvent
/*********************************************************************
* @fn CyclingSensor_ProcessEvent
*
* @brief Cycling Application Task event processor. This function
* is called to process all events for the task. Events
* include timers, messages and any other user defined events.
*
* @param task_id - The OSAL assigned task ID.
* @param events - events to process. This is a bit map and can
* contain more than one event.
*
* @return events not processed
*/
uint16 CyclingSensor_ProcessEvent( uint8 task_id, uint16 events )
{
VOID task_id; // OSAL required parameter that isn't used in this function
if ( events & SYS_EVENT_MSG )
{
uint8 *pMsg;
if ( (pMsg = osal_msg_receive( sensor_TaskID )) != NULL )
{
sensor_ProcessOSALMsg( (osal_event_hdr_t *)pMsg );
// Release the OSAL message
VOID osal_msg_deallocate( pMsg );
}
// return unprocessed events
return (events ^ SYS_EVENT_MSG);
}
if ( events & START_DEVICE_EVT )
{
// Start the Device
VOID GAPRole_StartDevice( &cyclingPeripheralCB );
// Register with bond manager after starting device
GAPBondMgr_Register( (gapBondCBs_t *) &cyclingBondCB );
return ( events ^ START_DEVICE_EVT );
}
if ( events & CSC_PERIODIC_EVT )
{
// Perform sensor's periodic task
sensorPeriodicTask();
return (events ^ CSC_PERIODIC_EVT);
}
if ( events & CSC_CONN_PARAM_UPDATE_EVT )
{
// Send param update. If it fails, retry until successful.
GAPRole_SendUpdateParam( DEFAULT_DESIRED_MIN_CONN_INTERVAL, DEFAULT_DESIRED_MAX_CONN_INTERVAL,
DEFAULT_DESIRED_SLAVE_LATENCY, DEFAULT_DESIRED_CONN_TIMEOUT,
GAPROLE_RESEND_PARAM_UPDATE );
// Assuming service discovery complete, start neglect timer
if ( USING_NEGLECT_TIMEOUT )
{
osal_start_timerEx( sensor_TaskID, CSC_NEGLECT_TIMEOUT_EVT, NEGLECT_TIMEOUT_DELAY );
}
return (events ^ CSC_CONN_PARAM_UPDATE_EVT);
}
if ( events & CSC_NEGLECT_TIMEOUT_EVT )
{
// No user input, terminate connection.
GAPRole_TerminateConnection();
return ( events ^ CSC_NEGLECT_TIMEOUT_EVT );
}
if ( events & CSC_RESET_EVT )
{
// Soft reset in action
if ( gapProfileState == GAPROLE_CONNECTED )
{
// Exit the connection
GAPRole_TerminateConnection();
// There is no callback for manual termination of the link. change state variable here.
gapProfileState = GAPROLE_WAITING;
// Set timer to give the end advertising event time to finish
osal_start_timerEx( sensor_TaskID, CSC_RESET_EVT, 500 );
}
else if ( gapProfileState == GAPROLE_ADVERTISING )
{
uint8 value = FALSE;
// Turn off advertising
GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &value );
// Set timer to give the end advertising event time to finish
osal_start_timerEx( sensor_TaskID, CSC_RESET_EVT, 500 );
//.........这里部分代码省略.........
示例9: sensor_HandleKeys
/*********************************************************************
* @fn sensor_HandleKeys
*
* @brief Handles all key events for this device.
*
* @param shift - true if in shift/alt.
* @param keys - bit field for key events. Valid entries:
* HAL_KEY_SW_2
* HAL_KEY_SW_1
*
* @return none
*/
static void sensor_HandleKeys( uint8 shift, uint8 keys )
{
if ( keys == ( HAL_KEY_SW_1 | HAL_KEY_SW_2 ) )
{
// Reset in progress has started
resetInProgress = TRUE;
// Set OSAL timer for reset
osal_start_timerEx( sensor_TaskID, CSC_RESET_EVT, CSC_RESET_DELAY );
}
else if ( keys & HAL_KEY_SW_1 )
{
if ( resetInProgress == TRUE )
{
// Cancel the reset
resetInProgress = FALSE;
osal_stop_timerEx ( sensor_TaskID, CSC_RESET_EVT );
}
// set simulated measurement flag index
if (++sensorFlagsIdx == FLAGS_IDX_MAX)
{
sensorFlagsIdx = 0;
}
}
else if ( keys & HAL_KEY_SW_2 )
{
if ( resetInProgress == TRUE )
{
// Cancel the reset
resetInProgress = FALSE;
osal_stop_timerEx ( sensor_TaskID, CSC_RESET_EVT );
}
// if not in a connection, toggle advertising on and off
if ( gapProfileState != GAPROLE_CONNECTED )
{
uint8 status;
// Set fast advertising interval for user-initiated connections
GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MIN, DEFAULT_FAST_ADV_INTERVAL );
GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MAX, DEFAULT_FAST_ADV_INTERVAL );
GAP_SetParamValue( TGAP_GEN_DISC_ADV_MIN, DEFAULT_WHITE_LIST_ADV_DURATION );
// toggle GAP advertisement status
GAPRole_GetParameter( GAPROLE_ADVERT_ENABLED, &status );
status = !status;
// If not already using white list, begin to do so.
// Only do so if about to begin advertising
if ( USING_WHITE_LIST && status == TRUE )
{
uint8 bondCount = 0;
GAPBondMgr_GetParameter( GAPBOND_BOND_COUNT, &bondCount );
if ((sensorUsingWhiteList == FALSE) && (bondCount > 0) )
{
uint8 value = GAP_FILTER_POLICY_WHITE;
GAPRole_SetParameter(GAPROLE_ADV_FILTER_POLICY, sizeof( uint8 ), &value);
sensorUsingWhiteList = TRUE;
}
}
GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &status );
// Set state variable
if (status == FALSE)
{
sensorAdvCancelled = TRUE;
}
}
}
// End of key press
else if ( keys == 0x00 )
{
if ( resetInProgress == TRUE )
{
resetInProgress = FALSE;
osal_stop_timerEx( sensor_TaskID, CSC_RESET_EVT );
}
}
}
示例10: HalKeyConfig
/**************************************************************************************************
* @fn HalKeyConfig
*
* @brief Configure the Key serivce
*
* @param interruptEnable - TRUE/FALSE, enable/disable interrupt
* cback - pointer to the CallBack function
*
* @return None
**************************************************************************************************/
void HalKeyConfig (bool interruptEnable, halKeyCBack_t cback)
{
/* Enable/Disable Interrupt or */
Hal_KeyIntEnable = interruptEnable;
/* Register the callback fucntion */
pHalKeyProcessFunction = cback;
/* Determine if interrupt is enable or not */
if (Hal_KeyIntEnable)
{
/* Rising/Falling edge configuratinn */
PICTL &= ~(HAL_KEY_SW_6_EDGEBIT); /* Clear the edge bit */
/* For falling edge, the bit must be set. */
#if (HAL_KEY_SW_6_EDGE == HAL_KEY_FALLING_EDGE)
PICTL |= HAL_KEY_SW_6_EDGEBIT;
#endif
/* Interrupt configuration:
* - Enable interrupt generation at the port
* - Enable CPU interrupt
* - Clear any pending interrupt
*/
HAL_KEY_SW_6_ICTL |= HAL_KEY_SW_6_ICTLBIT;
HAL_KEY_SW_6_IEN |= HAL_KEY_SW_6_IENBIT;
HAL_KEY_SW_6_PXIFG = ~(HAL_KEY_SW_6_BIT);
/* Rising/Falling edge configuratinn */
HAL_KEY_JOY_MOVE_ICTL &= ~(HAL_KEY_JOY_MOVE_EDGEBIT); /* Clear the edge bit */
/* For falling edge, the bit must be set. */
#if (HAL_KEY_JOY_MOVE_EDGE == HAL_KEY_FALLING_EDGE)
HAL_KEY_JOY_MOVE_ICTL |= HAL_KEY_JOY_MOVE_EDGEBIT;
#endif
/* Interrupt configuration:
* - Enable interrupt generation at the port
* - Enable CPU interrupt
* - Clear any pending interrupt
*/
HAL_KEY_JOY_MOVE_ICTL |= HAL_KEY_JOY_MOVE_ICTLBIT;
HAL_KEY_JOY_MOVE_IEN |= HAL_KEY_JOY_MOVE_IENBIT;
HAL_KEY_JOY_MOVE_PXIFG = ~(HAL_KEY_JOY_MOVE_BIT);
/* Do this only after the hal_key is configured - to work with sleep stuff */
if (HalKeyConfigured == TRUE)
{
osal_stop_timerEx( Hal_TaskID, HAL_KEY_EVENT); /* Cancel polling if active */
}
}
else /* Interrupts NOT enabled */
{
HAL_KEY_SW_6_ICTL &= ~(HAL_KEY_SW_6_ICTLBIT); /* don't generate interrupt */
HAL_KEY_SW_6_IEN &= ~(HAL_KEY_SW_6_IENBIT); /* Clear interrupt enable bit */
osal_start_timerEx (Hal_TaskID, HAL_KEY_EVENT, HAL_KEY_POLLING_VALUE); /* Kick off polling */
}
/* Key now is configured */
HalKeyConfigured = TRUE;
}
示例11: SampleApp_ProcessEvent
/*********************************************************************
* @fn SampleApp_ProcessEvent
*
* @brief Generic Application Task event processor. This function
* is called to process all events for the task. Events
* include timers, messages and any other user defined events.
*
* @param task_id - The OSAL assigned task ID.
* @param events - events to process. This is a bit map and can
* contain more than one event.
*
* @return none
*/
uint16 SampleApp_ProcessEvent( uint8 task_id, uint16 events )
{
afIncomingMSGPacket_t *MSGpkt;
(void)task_id; // Intentionally unreferenced parameter
if ( events & SYS_EVENT_MSG )
{
MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( SampleApp_TaskID );
while ( MSGpkt )
{
switch ( MSGpkt->hdr.event )
{
// Received when a key is pressed
case KEY_CHANGE:
SampleApp_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys );
break;
// Received when a messages is received (OTA) for this endpoint
case AF_INCOMING_MSG_CMD:
SampleApp_MessageMSGCB( MSGpkt );
break;
// Received whenever the device changes state in the network
case ZDO_STATE_CHANGE:
SampleApp_NwkState = (devStates_t)(MSGpkt->hdr.status);
if ( (SampleApp_NwkState == DEV_ZB_COORD)
|| (SampleApp_NwkState == DEV_ROUTER)
|| (SampleApp_NwkState == DEV_END_DEVICE) )
{
// Start sending the periodic message in a regular interval.
osal_start_timerEx( SampleApp_TaskID,
SAMPLEAPP_SEND_PERIODIC_MSG_EVT,
SAMPLEAPP_SEND_PERIODIC_MSG_TIMEOUT );
}
else
{
// Device is no longer in the network
}
break;
default:
break;
}
// Release the memory
osal_msg_deallocate( (uint8 *)MSGpkt );
// Next - if one is available
MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( SampleApp_TaskID );
}
// return unprocessed events
return (events ^ SYS_EVENT_MSG);
}
// Send a message out - This event is generated by a timer
// (setup in SampleApp_Init()).
if ( events & SAMPLEAPP_SEND_PERIODIC_MSG_EVT )
{
// Send the periodic message
SampleApp_SendPeriodicMessage();
// Setup to send message again in normal period (+ a little jitter)
osal_start_timerEx( SampleApp_TaskID, SAMPLEAPP_SEND_PERIODIC_MSG_EVT,
(/*SAMPLEAPP_SEND_PERIODIC_MSG_TIMEOUT*/ 1000 + (osal_rand() & 0x00FF)) );
// return unprocessed events
return (events ^ SAMPLEAPP_SEND_PERIODIC_MSG_EVT);
}
// Discard unknown events
return 0;
}
示例12: SimpleBLEPeripheral_ProcessEvent
/*********************************************************************
* @fn SimpleBLEPeripheral_ProcessEvent
*
* @brief Simple BLE Peripheral Application Task event processor. This function
* is called to process all events for the task. Events
* include timers, messages and any other user defined events.
*
* @param task_id - The OSAL assigned task ID.
* @param events - events to process. This is a bit map and can
* contain more than one event.
*
* @return events not processed
*/
uint16 SimpleBLEPeripheral_ProcessEvent(uint8 task_id, uint16 events) {
VOID task_id; // OSAL required parameter that isn't used in this function
if (events & SYS_EVENT_MSG) {
uint8 *pMsg;
if ((pMsg = osal_msg_receive(simpleBLEPeripheral_TaskID)) != NULL) {
simpleBLEPeripheral_ProcessOSALMsg((osal_event_hdr_t *) pMsg);
// Release the OSAL message
VOID osal_msg_deallocate(pMsg);
}
// return unprocessed events
return (events ^ SYS_EVENT_MSG);
}
if (events & SBP_START_DEVICE_EVT) {
// Start the Device
GAPRole_StartDevice(&simpleBLEPeripheral_PeripheralCBs);
// Start Bond Manager
GAPBondMgr_Register(&simpleBLEPeripheral_BondMgrCBs);
// Set timer for first periodic event
osal_start_timerEx(simpleBLEPeripheral_TaskID, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD);
return (events ^ SBP_START_DEVICE_EVT);
}
if (events & SBP_PERIODIC_EVT) {
// Restart timer
if (SBP_PERIODIC_EVT_PERIOD) {
osal_start_timerEx(simpleBLEPeripheral_TaskID, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD);
}
// Perform periodic application task
performPeriodicTask();
return (events ^ SBP_PERIODIC_EVT);
}
if (events & SBP_ZEKEZANG_EVT) {
uint8 initial_advertising_enable = FALSE;
GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8), &initial_advertising_enable);
return (events ^ SBP_ZEKEZANG_EVT);
}
if (events & SBP_SEND_IRDATA_EVT) {
HalLcdWriteString("send plan complete...", HAL_LCD_LINE_4);
return (events ^ SBP_SEND_IRDATA_EVT);
}
if (events & SBP_ADV_IN_CONNECTION_EVT) {
uint8 turnOnAdv = TRUE;
// Turn on advertising while in a connection
GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8), &turnOnAdv);
return (events ^ SBP_ADV_IN_CONNECTION_EVT);
}
return 0;
}
示例13: sensorTag_HandleKeys
/*********************************************************************
* @fn sensorTag_HandleKeys
*
* @brief Handles all key events for this device.
*
* @param shift - true if in shift/alt.
* @param keys - bit field for key events. Valid entries:
* HAL_KEY_SW_2
* HAL_KEY_SW_1
*
* @return none
*/
static void sensorTag_HandleKeys( uint8 shift, uint8 keys )
{
uint8 SK_Keys = 0;
VOID shift; // Intentionally unreferenced parameter
if (keys & HAL_KEY_SW_1)
{
// Reset the system if side key is pressed for more than 3 seconds
sysResetRequest = TRUE;
osal_start_timerEx( sensorTag_TaskID, ST_SYS_RESET_EVT, ST_SYS_RESET_DELAY );
if (!testMode ) // Side key
{
// If device is not in a connection, pressing the side key should toggle
// advertising on and off
if ( gapProfileState != GAPROLE_CONNECTED )
{
uint8 current_adv_enabled_status;
uint8 new_adv_enabled_status;
// Find the current GAP advertising status
GAPRole_GetParameter( GAPROLE_ADVERT_ENABLED, ¤t_adv_enabled_status );
if( current_adv_enabled_status == FALSE )
{
new_adv_enabled_status = TRUE;
}
else
{
new_adv_enabled_status = FALSE;
}
// Change the GAP advertisement status to opposite of current status
GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &new_adv_enabled_status );
}
if ( gapProfileState == GAPROLE_CONNECTED )
{
uint8 adv_enabled = TRUE;
// Disconnect
GAPRole_TerminateConnection();
// Start advertising
GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &adv_enabled );
}
}
else
{
// Test mode
if ( keys & HAL_KEY_SW_1 ) // Side key
{
SK_Keys |= SK_KEY_SIDE;
}
}
}
if ( keys & HAL_KEY_SW_2 ) // Carbon S2
{
SK_Keys |= SK_KEY_LEFT;
}
if ( keys & HAL_KEY_SW_3 ) // Carbon S3
{
SK_Keys |= SK_KEY_RIGHT;
}
if (!(keys & HAL_KEY_SW_1))
{
// Cancel system reset request
sysResetRequest = FALSE;
}
// Set the value of the keys state to the Simple Keys Profile;
// This will send out a notification of the keys state if enabled
SK_SetParameter( SK_KEY_ATTR, sizeof ( uint8 ), &SK_Keys );
}
示例14: SensorTag_ProcessEvent
/*********************************************************************
* @fn SensorTag_ProcessEvent
*
* @brief Simple BLE Peripheral Application Task event processor. This function
* is called to process all events for the task. Events
* include timers, messages and any other user defined events.
*
* @param task_id - The OSAL assigned task ID.
* @param events - events to process. This is a bit map and can
* contain more than one event.
*
* @return events not processed
*/
uint16 SensorTag_ProcessEvent( uint8 task_id, uint16 events )
{
VOID task_id; // OSAL required parameter that isn't used in this function
if ( events & SYS_EVENT_MSG )
{
uint8 *pMsg;
if ( (pMsg = osal_msg_receive( sensorTag_TaskID )) != NULL )
{
sensorTag_ProcessOSALMsg( (osal_event_hdr_t *)pMsg );
// Release the OSAL message
VOID osal_msg_deallocate( pMsg );
}
// return unprocessed events
return (events ^ SYS_EVENT_MSG);
}
// Handle system reset (long press on side key)
if ( events & ST_SYS_RESET_EVT )
{
if (sysResetRequest)
{
HAL_SYSTEM_RESET();
}
return ( events ^ ST_SYS_RESET_EVT );
}
if ( events & ST_START_DEVICE_EVT )
{
// Start the Device
VOID GAPRole_StartDevice( &sensorTag_PeripheralCBs );
// Start Bond Manager
VOID GAPBondMgr_Register( &sensorTag_BondMgrCBs );
return ( events ^ ST_START_DEVICE_EVT );
}
//////////////////////////
// IR TEMPERATURE //
//////////////////////////
if ( events & ST_IRTEMPERATURE_READ_EVT )
{
if ( irTempEnabled )
{
if (HalIRTempStatus() == TMP006_DATA_READY)
{
readIrTempData();
osal_start_timerEx( sensorTag_TaskID, ST_IRTEMPERATURE_READ_EVT, TEMP_DEFAULT_PERIOD-TEMP_MEAS_DELAY );
}
else if (HalIRTempStatus() == TMP006_OFF)
{
HalIRTempTurnOn();
osal_start_timerEx( sensorTag_TaskID, ST_IRTEMPERATURE_READ_EVT, TEMP_MEAS_DELAY );
}
}
else
{
//Turn off Temperatur sensor
VOID HalIRTempTurnOff();
VOID resetCharacteristicValue(IRTEMPERATURE_SERV_UUID,IRTEMPERATURE_DATA,0,IRTEMPERATURE_DATA_LEN);
VOID resetCharacteristicValue(IRTEMPERATURE_SERV_UUID,IRTEMPERATURE_CONF,ST_CFG_SENSOR_DISABLE,sizeof ( uint8 ));
}
return (events ^ ST_IRTEMPERATURE_READ_EVT);
}
//////////////////////////
// Accelerometer //
//////////////////////////
if ( events & ST_ACCELEROMETER_SENSOR_EVT )
{
if(accEnabled)
{
readAccData();
osal_start_timerEx( sensorTag_TaskID, ST_ACCELEROMETER_SENSOR_EVT, sensorAccPeriod );
}
else
{
VOID resetCharacteristicValue( ACCELEROMETER_SERV_UUID, ACCELEROMETER_DATA, 0, ACCELEROMETER_DATA_LEN );
VOID resetCharacteristicValue( ACCELEROMETER_SERV_UUID, ACCELEROMETER_CONF, ST_CFG_SENSOR_DISABLE, sizeof ( uint8 ));
VOID resetCharacteristicValue( ACCELEROMETER_SERV_UUID, ACCELEROMETER_PERI, ACC_DEFAULT_PERIOD/ACCELEROMETER_TIME_UNIT, sizeof ( uint8 ));
}
//.........这里部分代码省略.........
示例15: gapRole_ProcessOSALMsg
/*********************************************************************
* @fn gapRole_ProcessOSALMsg
*
* @brief Process an incoming task message.
*
* @param pMsg - message to process
*
* @return none
*/
static void gapRole_ProcessOSALMsg( osal_event_hdr_t *pMsg )
{
switch ( pMsg->event )
{
case HCI_GAP_EVENT_EVENT:
if ( pMsg->status == HCI_COMMAND_COMPLETE_EVENT_CODE )
{
hciEvt_CmdComplete_t *pPkt = (hciEvt_CmdComplete_t *)pMsg;
if ( pPkt->cmdOpcode == HCI_READ_RSSI )
{
int8 rssi = (int8)pPkt->pReturnParam[3];
if ( (gapRole_state == GAPROLE_CONNECTED) && (rssi != RSSI_NOT_AVAILABLE) )
{
// Report RSSI to app
if ( pGapRoles_AppCGs && pGapRoles_AppCGs->pfnRssiRead )
{
pGapRoles_AppCGs->pfnRssiRead( rssi );
}
}
}
}
break;
case GAP_MSG_EVENT:
gapRole_ProcessGAPMsg( (gapEventHdr_t *)pMsg );
break;
case L2CAP_SIGNAL_EVENT:
{
l2capSignalEvent_t *pPkt = (l2capSignalEvent_t *)pMsg;
// Process the Parameter Update Response
if ( pPkt->opcode == L2CAP_PARAM_UPDATE_RSP )
{
l2capParamUpdateRsp_t *pRsp = (l2capParamUpdateRsp_t *)&(pPkt->cmd.updateRsp);
if ( ( pRsp->result == L2CAP_CONN_PARAMS_REJECTED ) &&
( paramUpdateNoSuccessOption == GAPROLE_TERMINATE_LINK ) )
{
// Cancel connection param update timeout timer
VOID osal_stop_timerEx( gapRole_TaskID, CONN_PARAM_TIMEOUT_EVT );
// Terminate connection immediately
GAPRole_TerminateConnection();
}
else
{
uint16 timeout = GAP_GetParamValue( TGAP_CONN_PARAM_TIMEOUT );
// Let's wait for Controller to update connection parameters if they're
// accepted. Otherwise, decide what to do based on no success option.
VOID osal_start_timerEx( gapRole_TaskID, CONN_PARAM_TIMEOUT_EVT, timeout );
}
}
}
break;
default:
break;
}
}