/** * @file main.cpp * @author Jurica Resetar (Jurica@aconno.de) * @brief Template project based on FreeRTOS and Nordic's SDK * @version 0.1 * @date 2019-02-11 * * @copyright Copyright (c) 2019 * */ #include #include #include "nordic_common.h" #include "nrf.h" #include "nrf_sdh_freertos.h" #include "FreeRTOS.h" #include "task.h" #include "nrf_log.h" #include "nrf_log_ctrl.h" #include "nrf_log_default_backends.h" #include "settings.h" #include "basic_config.h" #include "arb_data.h" #include "aconnoConfig.h" #include "aconnoHelpers.h" #include "aconnoTasks.h" #include "aconnoBLE.h" #include "aconnoTasks.h" extern TaskHandle_t initTask; extern TaskHandle_t blinkyTask; extern TaskHandle_t blinkyTask2; extern TaskHandle_t menuStateMachineTask; #if NRF_LOG_ENABLED extern TaskHandle_t m_logger_thread; #endif /** @brief Function for application main entry. */ int main(void) { // Initialize modules. log_init(); clock_init(); NRF_LOG_INFO("\r\n\r\nMain started."); if(pdPASS != xTaskCreate(logTaskFunction, "INIT", 256, NULL, 1, &initTask)) { APP_ERROR_HANDLER(NRF_ERROR_NO_MEM); } xTaskCreate(menuStateMachineTaskFunction, "MenuStateMachine", 256, NULL, 1, &menuStateMachineTask); // Activate deep sleep mode. SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; // Initialize modules. timers_init(); application_timers_start(); // aconno BLE module init AconnoBLE &myBLE = *getAconnoBLEInstance(); myBLE.initBLEStack(); myBLE.GATTInit(); #if 1 myBLE.setTXPower(4); myBLE.startAdvertising(APP_ADV_INTERVAL, APP_ADV_DURATION); #endif // Create a FreeRTOS task for the BLE stack. // The task will run advertising_start() before entering its loop. nrf_sdh_freertos_init(NULL, NULL); NRF_LOG_INFO("HRS FreeRTOS example started."); settingsInit(NULL); basicConfigInit(); arbDataInit(); // Start FreeRTOS scheduler. vTaskStartScheduler(); for (;;) { APP_ERROR_HANDLER(NRF_ERROR_FORBIDDEN); } } #if NRF_LOG_ENABLED /**@brief Thread for handling the logger. * * @details This thread is responsible for processing log entries if * logs are deferred. Thread flushes all log entries and suspends. It is * resumed by idle task hook. * * @param[in] arg Pointer used for passing some arbitrary information * (context) from the osThreadCreate() call to the thread. */ void logger_thread(void * arg) { UNUSED_PARAMETER(arg); while (1) { NRF_LOG_FLUSH(); vTaskSuspend(NULL); // Suspend myself } } #endif //NRF_LOG_ENABLED /**@brief A function which is hooked to idle task. * @note Idle hook must be enabled in FreeRTOS configuration * (configUSE_IDLE_HOOK). */ #ifdef __cplusplus extern "C" { void vApplicationIdleHook( void ) { #if NRF_LOG_ENABLED vTaskResume(m_logger_thread); #endif } } #endif