NRFLOGDEBUG(“Idle task”); delayms(1000); } ~~~ ~~~ /* Create task for senddata blinking with priority set to 2 */ UNUSED_VARIABLE(xTaskCreate(send_data, “send_data”, configMINIMAL_STACK_SIZE + 200, NULL, 2, &send_data_handle)); ~~~ Code in task.c ~~~ // RTC timer APPTIMERDEF(mledatimerid); /** * @brief RTC instance number * */
define PERIODIC_RTC 2
/** * @brief RTC compare channel used * */define PERIODICRTCCC 0
/** * @brief Number of RTC ticks between interrupts */define PERIODICTIMERUS 5000000ULL
define PERIODICRTCTICKS (RTCUSTOTICKS(PERIODICTIMERUS, RTCDEFAULTCONFIGFREQUENCY))
/** * @brief Semaphore set in RTC event */ static SemaphoreHandle_t send_data_semaphore = NULL; /** * @brief RTC configuration */ static nrf_drv_rtc_config_t const m_rtc_config = NRF_DRV_RTC_DEFAULT_CONFIG; /** * @brief RTC instance * * Instance of the RTC used for led blinking */ static nrf_drv_rtc_t const m_rtc = NRF_DRV_RTC_INSTANCE(PERIODIC_RTC); static void periodicrtchandler(nrfdrvrtcinttypet inttype) { NRFLOGDEBUG(“Send data RTC handler”); BaseTypet yieldreq = pdFALSE; BaseTypet retval; retcodet errcode; errcode = nrfdrvrtcccset( &mrtc, PERIODICRTCCC, (nrfrtcccget(mrtc.preg, PERIODICRTCCC) + PERIODICRTCTICKS) & RTCCOUNTERCOUNTERMsk, true); APPERRORCHECK(errcode); /* The returned value may be safely ignored, if error is returned it only means that * the semaphore is already given (raised). */ UNUSED_VARIABLE(xSemaphoreGiveFromISR(send_data_semaphore, &yield_req)); // Request a context switch (switch to other task). Interrupt safe verison of taskYIELD() portYIELD_FROM_ISR(yield_req); } ~~~ ~~~ /** * @brief send_data task entry function. * * @param[in] pvParameter Pointer that will be used as the parameter for the task. */ void send_data(void * pvParameter) {NRF_LOG_INFO(“———- SEND DATA TASK ———-“);
// Create rtc instance and compare channel
NRF_LOG_DEBUG("Init RTC");
ret_code_t err_code;
err_code = nrf_drv_rtc_init(&m_rtc, &m_rtc_config, periodic_rtc_handler);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_rtc_cc_set(&m_rtc, PERIODIC_RTC_CC, PERIODIC_RTC_TICKS, true);
APP_ERROR_CHECK(err_code);
// Enable RTC instance
nrf_drv_rtc_enable(&m_rtc);
// Create semaphore
send_data_semaphore = xSemaphoreCreateBinary();
UNUSED_PARAMETER(pvParameter);
// Begin task loop
while(1)
{
NRF_LOG_DEBUG("Waiting for semaphore to begin task");
UNUSED_VARIABLE(xSemaphoreTake(send_data_semaphore, portMAX_DELAY));
NRF_LOG_INFO("++++++++++++++++task begin++++++++++++++++rn");
~~~