otError utilsFlashStatusWait(uint32_t aTimeout) { otError error = OT_ERROR_BUSY; if (aTimeout == 0) { if (!nrf5FlashIsBusy()) { error = OT_ERROR_NONE; } } else { uint32_t startTime = otPlatAlarmMilliGetNow(); do { if (!nrf5FlashIsBusy()) { error = OT_ERROR_NONE; break; } } while (otPlatAlarmMilliGetNow() - startTime < aTimeout); } return error; }
void ExampleProcess(otInstance *aInstance) { static int aliveLEDcounter = 0; otDeviceRole devRole; static int thrValue; devRole = otThreadGetDeviceRole(aInstance); if (sBlink == false && otPlatAlarmMilliGetNow() != 0) { sMsCounterInit = otPlatAlarmMilliGetNow(); sBlink = true; } sMsCounter = otPlatAlarmMilliGetNow() - sMsCounterInit; switch (devRole) { case OT_DEVICE_ROLE_LEADER: thrValue = LEADER_BLINK_TIME; break; case OT_DEVICE_ROLE_ROUTER: thrValue = ROUTER_BLINK_TIME; break; case OT_DEVICE_ROLE_CHILD: thrValue = CHILD_BLINK_TIME; break; default: thrValue = 0x00; } if ((thrValue != 0x00) && (sMsCounter >= thrValue)) { hw_gpio_toggle(HW_GPIO_PORT_1, HW_GPIO_PIN_5); sMsCounterInit = otPlatAlarmMilliGetNow(); } if (thrValue == 0) { // No specific role, let's generate 'alive blink' // to inform that we are running. // Loop counter is used to run even if timers // are not initialized yet. aliveLEDcounter++; if (aliveLEDcounter > ALIVE_LED_PERIOD) { aliveLEDcounter = 0; hw_gpio_set_active(HW_GPIO_PORT_1, HW_GPIO_PIN_5); } if (aliveLEDcounter > ALIVE_LED_DUTY) { hw_gpio_set_inactive(HW_GPIO_PORT_1, HW_GPIO_PIN_5); } } }
static void waitInState(SdFlashState state) { uint32_t startTime = otPlatAlarmMilliGetNow(); do { nrf_sdh_evts_poll(); if (sState != state) { break; } } while (otPlatAlarmMilliGetNow() - startTime < FLASH_TIMEOUT); }
/** * Function documented in platform-cc2650.h */ void cc2650AlarmProcess(otInstance *aInstance) { uint32_t offsetTime; if (sIsRunning) { /* unsinged subtraction will result in the absolute offset */ offsetTime = otPlatAlarmMilliGetNow() - sTime0; if (sAlarmTime <= offsetTime) { sIsRunning = false; #if OPENTHREAD_ENABLE_DIAG if (otPlatDiagModeGet()) { otPlatDiagAlarmFired(aInstance); } else #endif /* OPENTHREAD_ENABLE_DIAG */ { otPlatAlarmMilliFired(aInstance); } } } }
static void cdcAcmUserEventHandler(app_usbd_class_inst_t const *aCdcAcmInstance, app_usbd_cdc_acm_user_event_t aEvent) { app_usbd_cdc_acm_t const *cdcAcmClass = app_usbd_cdc_acm_class_get(aCdcAcmInstance); switch (aEvent) { case APP_USBD_CDC_ACM_USER_EVT_PORT_OPEN: // Setup first transfer. (void)app_usbd_cdc_acm_read_any(&sAppCdcAcm, sRxBuffer, sizeof(sRxBuffer)); sUsbState.mOpenTimestamp = otPlatAlarmMilliGetNow(); break; case APP_USBD_CDC_ACM_USER_EVT_PORT_CLOSE: break; case APP_USBD_CDC_ACM_USER_EVT_TX_DONE: sUsbState.mTransferDone = true; break; case APP_USBD_CDC_ACM_USER_EVT_RX_DONE: sUsbState.mReceiveDone = true; // Get amount of data received. sUsbState.mReceivedDataSize = app_usbd_cdc_acm_rx_size(cdcAcmClass); break; default: break; } }
otError utilsFlashStatusWait(uint32_t aTimeout) { otError error = OT_ERROR_BUSY; uint32_t start = otPlatAlarmMilliGetNow(); do { if (FTFA->FSTAT & FTFA_FSTAT_CCIF_MASK) { error = OT_ERROR_NONE; break; } } while (aTimeout && ((otPlatAlarmMilliGetNow() - start) < aTimeout)); return error; }
static void handleRx(void) { if (sRxDone) { sRxDone = false; if (otPlatRadioGetPromiscuous(sInstance)) { // Timestamp sReceiveFrame.mInfo.mRxInfo.mMsec = otPlatAlarmMilliGetNow(); sReceiveFrame.mInfo.mRxInfo.mUsec = 0; // Don't support microsecond timer for now. } #if OPENTHREAD_ENABLE_DIAG if (otPlatDiagModeGet()) { otPlatDiagRadioReceiveDone(sInstance, &sReceiveFrame, OT_ERROR_NONE); } else #endif { // signal MAC layer for each received frame if promiscous is enabled // otherwise only signal MAC layer for non-ACK frame if (sPromiscuous || sReceiveFrame.mLength > IEEE802154_ACK_LENGTH) { otLogDebgPlat(sInstance, "Radio receive done, rssi: %d", sReceiveFrame.mInfo.mRxInfo.mRssi); otPlatRadioReceiveDone(sInstance, &sReceiveFrame, OT_ERROR_NONE); } } } }
otError utilsFlashStatusWait(uint32_t aTimeout) { otError error = OT_ERROR_BUSY; uint32_t start = otPlatAlarmMilliGetNow(); do { if (MSC->STATUS & MSC_STATUS_WDATAREADY) { error = OT_ERROR_NONE; break; } } while (aTimeout && ((otPlatAlarmMilliGetNow() - start) < aTimeout)); return error; }
otError utilsFlashStatusWait(uint32_t aTimeout) { otError error = OT_ERROR_BUSY; uint32_t start = otPlatAlarmMilliGetNow(); do { if (nvm_is_ready()) { error = OT_ERROR_NONE; break; } } while (aTimeout && ((otPlatAlarmMilliGetNow() - start) < aTimeout)); return error; }
otError otPlatRadioEnergyScan(otInstance *aInstance, uint8_t aScanChannel, uint16_t aScanDuration) { (void)aInstance; sScanStartTime = otPlatAlarmMilliGetNow(); sScanDuration = aScanDuration; sMaxRssi = PHY_EdReq(); sStartScan = true; return OT_ERROR_NONE; }
/* this should not be a WEAK function */ void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...) { OT_UNUSED_VARIABLE(aLogLevel); OT_UNUSED_VARIABLE(aLogRegion); va_list ap; uint32_t now; now = otPlatAlarmMilliGetNow(); otPlatDebugUart_printf("%3d.%03d | ", (int)(now / 1000), (int)(now % 1000)); va_start(ap, aFormat); otPlatDebugUart_vprintf(aFormat, ap); va_end(ap); otPlatDebugUart_putchar('\n'); }
void platformAlarmProcess(otInstance *aInstance) { int32_t remaining; if (sIsMsRunning) { remaining = (int32_t)(sMsAlarm - otPlatAlarmMilliGetNow()); if (remaining <= 0) { sIsMsRunning = false; #if OPENTHREAD_ENABLE_DIAG if (otPlatDiagModeGet()) { otPlatDiagAlarmFired(aInstance); } else #endif { otPlatAlarmMilliFired(aInstance); } } } #if OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER if (sIsUsRunning) { remaining = (int32_t)(sUsAlarm - otPlatAlarmMicroGetNow()); if (remaining <= 0) { sIsUsRunning = false; otPlatAlarmMicroFired(aInstance); } } #endif // OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER }
void efr32AlarmProcess(otInstance *aInstance) { uint32_t now = otPlatAlarmMilliGetNow(); uint32_t expires; bool fire = false; otEXPECT(sIsRunning); expires = sAlarmT0 + sAlarmDt; if (sAlarmT0 <= now) { fire = (expires >= sAlarmT0 && expires <= now); } else { fire = (expires >= sAlarmT0 || expires <= now); } if (fire) { sIsRunning = false; #if OPENTHREAD_ENABLE_DIAG if (otPlatDiagModeGet()) { otPlatDiagAlarmFired(aInstance); } else #endif { otPlatAlarmMilliFired(aInstance); } } exit: return; }
static void handleEnergyScan() { if (sStartScan) { if ((otPlatAlarmMilliGetNow() - sScanStartTime) < sScanDuration) { int8_t curRssi = PHY_EdReq(); if (curRssi > sMaxRssi) { sMaxRssi = curRssi; } } else { sStartScan = false; otPlatRadioEnergyScanDone(sInstance, sMaxRssi); radioRestore(); } } }
static bool hasPortOpenDelayPassed(void) { int32_t timeDiff = otPlatAlarmMilliGetNow() - sUsbState.mOpenTimestamp; return (timeDiff < 0) || (timeDiff > USB_HOST_UART_CONFIG_DELAY_MS); }