/** * Interrupt handler of UART0 peripherial. */ void UARTE0_UART0_IRQHandler(void) { // Check if any error has been detected. if (nrf_uart_event_check(UART_INSTANCE, NRF_UART_EVENT_ERROR)) { // Clear error event and ignore erronous byte in RXD register. nrf_uart_event_clear(UART_INSTANCE, NRF_UART_EVENT_ERROR); nrf_uart_event_clear(UART_INSTANCE, NRF_UART_EVENT_RXDRDY); } else if (nrf_uart_event_check(UART_INSTANCE, NRF_UART_EVENT_RXDRDY)) { // Clear RXDRDY event. nrf_uart_event_clear(UART_INSTANCE, NRF_UART_EVENT_RXDRDY); // Read byte from the UART buffer. uint8_t byte = nrf_uart_rxd_get(UART_INSTANCE); if (!isRxBufferFull()) { sReceiveBuffer[sReceiveHead] = byte; sReceiveHead = (sReceiveHead + 1) % UART_RX_BUFFER_SIZE; otSysEventSignalPending(); } } if (nrf_uart_event_check(UART_INSTANCE, NRF_UART_EVENT_TXDRDY)) { // Clear TXDRDY event. nrf_uart_event_clear(UART_INSTANCE, NRF_UART_EVENT_TXDRDY); // Send any more bytes if available or call application about TX done. if (sTransmitLength) { nrf_uart_txd_set(UART_INSTANCE, *sTransmitBuffer++); sTransmitLength--; } else { sTransmitDone = true; nrf_uart_task_trigger(UART_INSTANCE, NRF_UART_TASK_STOPTX); otSysEventSignalPending(); } } }
static void setPendingEvent(RadioPendingEvents aEvent) { volatile uint32_t pendingEvents; uint32_t bitToSet = 1UL << aEvent; do { pendingEvents = __LDREXW((unsigned long volatile *)&sPendingEvents); pendingEvents |= bitToSet; } while (__STREXW(pendingEvents, (unsigned long volatile *)&sPendingEvents)); otSysEventSignalPending(); }
void nrf_802154_received_raw(uint8_t *p_data, int8_t power, uint8_t lqi) #endif { otRadioFrame *receivedFrame = NULL; for (uint32_t i = 0; i < NRF_802154_RX_BUFFERS; i++) { if (sReceivedFrames[i].mPsdu == NULL) { receivedFrame = &sReceivedFrames[i]; memset(receivedFrame, 0, sizeof(*receivedFrame)); #if OPENTHREAD_CONFIG_HEADER_IE_SUPPORT receivedFrame->mIeInfo = &sReceivedIeInfos[i]; #endif break; } } assert(receivedFrame != NULL); receivedFrame->mPsdu = &p_data[1]; receivedFrame->mLength = p_data[0]; receivedFrame->mInfo.mRxInfo.mRssi = power; receivedFrame->mInfo.mRxInfo.mLqi = lqi; receivedFrame->mChannel = nrf_802154_channel_get(); if (otPlatRadioGetPromiscuous(sInstance)) { uint64_t timestamp = nrf5AlarmGetCurrentTime(); receivedFrame->mInfo.mRxInfo.mMsec = timestamp / US_PER_MS; receivedFrame->mInfo.mRxInfo.mUsec = timestamp - receivedFrame->mInfo.mRxInfo.mMsec * US_PER_MS; } #if OPENTHREAD_CONFIG_ENABLE_TIME_SYNC // Get the timestamp when the SFD was received. uint32_t offset = (int32_t)otPlatAlarmMicroGetNow() - (int32_t)nrf_802154_first_symbol_timestamp_get(time, p_data[0]); receivedFrame->mIeInfo->mTimestamp = otPlatTimeGet() - offset; #endif otSysEventSignalPending(); }