diff --git a/Qorvo/Qorvo_Apple_Nearby_Interaction_beta/Projects/nRF52840DK/config/FreeRTOSConfig.h b/Qorvo/Qorvo_Apple_Nearby_Interaction_beta/Projects/nRF52840DK/config/FreeRTOSConfig.h index d03aede..029cf60 100644 --- a/Qorvo/Qorvo_Apple_Nearby_Interaction_beta/Projects/nRF52840DK/config/FreeRTOSConfig.h +++ b/Qorvo/Qorvo_Apple_Nearby_Interaction_beta/Projects/nRF52840DK/config/FreeRTOSConfig.h @@ -62,8 +62,8 @@ #define configCPU_CLOCK_HZ ( SystemCoreClock ) #define configTICK_RATE_HZ 1000 #define configMAX_PRIORITIES ( 7 ) -#define configMINIMAL_STACK_SIZE ( 128 ) -#define configTOTAL_HEAP_SIZE (32*1024) +#define configMINIMAL_STACK_SIZE ( 512 ) +#define configTOTAL_HEAP_SIZE (64*1024) #define configMAX_TASK_NAME_LEN ( 12 ) #define configUSE_16_BIT_TICKS 0 #define configIDLE_SHOULD_YIELD 1 @@ -80,7 +80,7 @@ /* Hook function related definitions. */ #define configUSE_IDLE_HOOK 1 #define configUSE_TICK_HOOK 0 -#define configCHECK_FOR_STACK_OVERFLOW 0 +#define configCHECK_FOR_STACK_OVERFLOW 1 #define configUSE_MALLOC_FAILED_HOOK 0 /* Run time and task stats gathering related definitions. */ @@ -103,7 +103,7 @@ /* Tickless idle/low power functionality. */ - +#define DEBUG_NRF 1 /* Define to trap errors during development. */ #if defined(DEBUG_NRF) || defined(DEBUG_NRF_USER) #define configASSERT( x ) ASSERT(x) @@ -118,7 +118,7 @@ #define INCLUDE_vTaskDelete 1 #define INCLUDE_vTaskSuspend 1 #define INCLUDE_xResumeFromISR 1 -#define INCLUDE_vTaskDelayUntil 0 +#define INCLUDE_vTaskDelayUntil 1 #define INCLUDE_vTaskDelay 1 #define INCLUDE_xTaskGetSchedulerState 1 #define INCLUDE_xTaskGetCurrentTaskHandle 1 diff --git a/Qorvo/Qorvo_Apple_Nearby_Interaction_beta/Projects/nRF52840DK/config/default_config.h b/Qorvo/Qorvo_Apple_Nearby_Interaction_beta/Projects/nRF52840DK/config/default_config.h index 6596144..53a849a 100644 --- a/Qorvo/Qorvo_Apple_Nearby_Interaction_beta/Projects/nRF52840DK/config/default_config.h +++ b/Qorvo/Qorvo_Apple_Nearby_Interaction_beta/Projects/nRF52840DK/config/default_config.h @@ -69,7 +69,7 @@ .s.mode = 0,\ \ .s.txConfig.PGdly = 0x34, \ - .s.txConfig.power = 0xfefefefeUL, \ + .s.txConfig.power = 0xffffffffUL, \ .s.txConfig.PGcount = 0, \ \ .s.rngOffset_mm = DEFAULT_RNGOFF_MM, \ diff --git a/Qorvo/Qorvo_Apple_Nearby_Interaction_beta/Projects/nRF52840DK/config/project_name.c b/Qorvo/Qorvo_Apple_Nearby_Interaction_beta/Projects/nRF52840DK/config/project_name.c index f5b65eb..b9a23c9 100644 --- a/Qorvo/Qorvo_Apple_Nearby_Interaction_beta/Projects/nRF52840DK/config/project_name.c +++ b/Qorvo/Qorvo_Apple_Nearby_Interaction_beta/Projects/nRF52840DK/config/project_name.c @@ -10,6 +10,6 @@ * */ -const char BoardName[] = "1 DWM3000EVB + nRF52840DK"; +const char BoardName[] = "Tagx"; const char OsName[] = "FreeRTOS"; const char ApplicationName[] = "Nearby Interaction Beta"; diff --git a/Qorvo/Qorvo_Apple_Nearby_Interaction_beta/Src/Apps/fira/fira_app.c b/Qorvo/Qorvo_Apple_Nearby_Interaction_beta/Src/Apps/fira/fira_app.c index 4c39a8a..53b4085 100644 --- a/Qorvo/Qorvo_Apple_Nearby_Interaction_beta/Src/Apps/fira/fira_app.c +++ b/Qorvo/Qorvo_Apple_Nearby_Interaction_beta/Src/Apps/fira/fira_app.c @@ -48,6 +48,7 @@ static void report_cb(void *user_data, struct sk_buff *skb) if (osSignalSet(reportTask.Handle, SIGNAL_REPORT_READY) != osOK) { error_handler(1, _ERR_Signal_Bad); } + // port_tx_msg("signal\n", strlen("signal\n")); } @@ -175,7 +176,10 @@ static void _reportTask(void const *arg) error_e ret; uint16_t head, tail; float r_m; - char result[256]; + // char result[256]; + char result[20]; + + static int timeout_protection=20; const int Signal = SIGNAL_REPORT_READY; @@ -186,15 +190,36 @@ static void _reportTask(void const *arg) for (int i = 0; i < results->n_measurements; i++) { - snprintf(result, sizeof(result), + /*snprintf(result, sizeof(result), "{\"TWR\": {\"R\":%d,\"a16\":\"0x%04x\",\"S\":\"%s\",\"D cm\":%d}}\r\n", results->block_index, results->measurements[i].short_addr, (results->measurements[i].status == 0)?("OK"):("ERR"), (int)results->measurements[i].distance_mm/10 + );*/ + snprintf(result, sizeof(result), + "S: %s, D cm :%d \n", + (results->measurements[i].status == 0)?("OK"):("ERR"), + (int)results->measurements[i].distance_mm/10 ); + if(results->measurements[i].status == 0) + { + timeout_protection=20; + } + else + { + timeout_protection--; + } + if(timeout_protection==0) + { + timeout_protection=20; + niq_stop_uwb(); + + port_tx_msg("rinit\n", strlen("rinit\n")); + } } - port_tx_msg(result, strlen(result)); + port_tx_msg(result, strlen(result)); + } while (1); } @@ -203,7 +228,7 @@ static void _reportTask(void const *arg) * */ static void fira_setup_tasks(void) { - osThreadDef(repTask, _reportTask, PRIO_TagRxTask, 0, 256); + osThreadDef(repTask, _reportTask, PRIO_TagRxTask, 0, 1024); osMutexDef(repMutex); reportTask.MutexId = osMutexCreate(osMutex(repMutex)); diff --git a/Qorvo/Qorvo_Apple_Nearby_Interaction_beta/Src/Comm/ble/ble.c b/Qorvo/Qorvo_Apple_Nearby_Interaction_beta/Src/Comm/ble/ble.c index 16b12d6..2ce583c 100644 --- a/Qorvo/Qorvo_Apple_Nearby_Interaction_beta/Src/Comm/ble/ble.c +++ b/Qorvo/Qorvo_Apple_Nearby_Interaction_beta/Src/Comm/ble/ble.c @@ -78,18 +78,18 @@ #define APP_BLE_OBSERVER_PRIO 3 /**< Application's BLE observer priority. You shouldn't need to modify this value. */ #define APP_BLE_CONN_CFG_TAG 1 /**< A tag identifying the SoftDevice BLE configuration. */ -#define APP_ADV_INTERVAL 300 /**< The advertising interval (in units of 0.625 ms. This value corresponds to 187.5 ms). */ -#define APP_ADV_DURATION 18000 /**< The advertising duration (180 seconds) in units of 10 milliseconds. */ +#define APP_ADV_INTERVAL 1600 /**< The advertising interval (in units of 0.625 ms. This value corresponds to 187.5 ms). */ +#define APP_ADV_DURATION 0 /**< The advertising duration (180 seconds) in units of 10 milliseconds. */ -#define MIN_CONN_INTERVAL MSEC_TO_UNITS(100, UNIT_1_25_MS) /**< Minimum acceptable connection interval (0.4 seconds). */ +#define MIN_CONN_INTERVAL MSEC_TO_UNITS(25, UNIT_1_25_MS) /**< Minimum acceptable connection interval (0.4 seconds). */ #define MAX_CONN_INTERVAL MSEC_TO_UNITS(250, UNIT_1_25_MS) /**< Maximum acceptable connection interval (0.65 second). */ #define SLAVE_LATENCY 6 /**< Slave latency. */ #define CONN_SUP_TIMEOUT MSEC_TO_UNITS(16000, UNIT_10_MS) /**< Connection supervisory time-out (4 seconds). */ #define FIRST_CONN_PARAMS_UPDATE_DELAY 5000 /**< Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (5 seconds). */ #define NEXT_CONN_PARAMS_UPDATE_DELAY 30000 /**< Time between each call to sd_ble_gap_conn_param_update after the first call (30 seconds). */ -#define MAX_CONN_PARAMS_UPDATE_COUNT 3 /**< Number of attempts before giving up the connection parameter negotiation. */ +#define MAX_CONN_PARAMS_UPDATE_COUNT 2 /**< Number of attempts before giving up the connection parameter negotiation. */ BLE_NUS_DEF(m_nus, NRF_SDH_BLE_TOTAL_LINK_COUNT); NRF_BLE_GATT_DEF(m_gatt); /**< GATT module instance. */ diff --git a/Qorvo/Qorvo_Apple_Nearby_Interaction_beta/Src/UWB/dw3000/dw3000_mcps_mcu.c b/Qorvo/Qorvo_Apple_Nearby_Interaction_beta/Src/UWB/dw3000/dw3000_mcps_mcu.c index ed454a2..7c5b108 100644 --- a/Qorvo/Qorvo_Apple_Nearby_Interaction_beta/Src/UWB/dw3000/dw3000_mcps_mcu.c +++ b/Qorvo/Qorvo_Apple_Nearby_Interaction_beta/Src/UWB/dw3000/dw3000_mcps_mcu.c @@ -1244,7 +1244,7 @@ int dw3000_mcps_register(struct dwchip_s *dw) osMutexDef(mcpsMutex); mcpsTask.MutexId = osMutexCreate(osMutex(mcpsMutex)); #ifndef __ZEPHYR__ - osThreadDef(mcpsTask, McpsTask, osPriorityRealtime, 0, 1024); + osThreadDef(mcpsTask, McpsTask, osPriorityRealtime, 0, 2048); mcpsTask.Handle = osThreadCreate(osThread(mcpsTask), dw->llhw); #else osThreadDef(McpsTask, osPriorityRealtime, 0, 512); diff --git a/Qorvo/Qorvo_Apple_Nearby_Interaction_beta/Src/UWB/main_uwb.c b/Qorvo/Qorvo_Apple_Nearby_Interaction_beta/Src/UWB/main_uwb.c index c780ca3..37f986a 100644 --- a/Qorvo/Qorvo_Apple_Nearby_Interaction_beta/Src/UWB/main_uwb.c +++ b/Qorvo/Qorvo_Apple_Nearby_Interaction_beta/Src/UWB/main_uwb.c @@ -152,7 +152,6 @@ static void _defaultTask(const void *arg) case SIGNAL_STOP_ALL: //through default: - /* niq_reinit() must be called every time Session is Stopped. * If not, then next session would not start */ diff --git a/Qorvo/Qorvo_Apple_Nearby_Interaction_beta/Src/main.c b/Qorvo/Qorvo_Apple_Nearby_Interaction_beta/Src/main.c index 21d4461..86eb4fe 100644 --- a/Qorvo/Qorvo_Apple_Nearby_Interaction_beta/Src/main.c +++ b/Qorvo/Qorvo_Apple_Nearby_Interaction_beta/Src/main.c @@ -52,7 +52,7 @@ extern const char BoardName[]; #if NRF_LOG_ENABLED static TaskHandle_t m_logger_thread; /**< Definition of Logger thread. */ #endif - +static TaskHandle_t m_heartbeat_thread; /**< Definition of Logger thread. */ /**@brief Callback function for asserts in the SoftDevice. * * @details This function will be called in case of an assert in the SoftDevice. @@ -103,6 +103,27 @@ static void logger_thread(void * arg) } #endif //NRF_LOG_ENABLED + + + + +static void heartbeat_thread(void * arg) +{ + TickType_t xLastWakeTime; + const TickType_t xFrequency = 1000; + + // Initialise the xLastWakeTime variable with the current time. + xLastWakeTime = xTaskGetTickCount(); + + for( ;; ) + { + // Wait for the next cycle. + vTaskDelayUntil( &xLastWakeTime, xFrequency/portTICK_PERIOD_MS ); + port_tx_msg("Here\n",6); + // Perform action here. + } +} + /**@brief A function which is hooked to idle task. * @note Idle hook must be enabled in FreeRTOS configuration (configUSE_IDLE_HOOK). */ @@ -138,11 +159,15 @@ int main(void) #if NRF_LOG_ENABLED // Logging task is only required if NRF_LOG module is in use - if (pdPASS != xTaskCreate(logger_thread, "LOGGER", 256, NULL, 1, &m_logger_thread)) + if (pdPASS != xTaskCreate(logger_thread, "LOGGER", 2048, NULL, 1, &m_logger_thread)) { APP_ERROR_HANDLER(NRF_ERROR_NO_MEM); } #endif + if (pdPASS != xTaskCreate(heartbeat_thread, "Heartbeat", 256, NULL, 1, &m_heartbeat_thread)) + { + APP_ERROR_HANDLER(NRF_ERROR_NO_MEM); + } // Accessory Nearby Interaction Initialization niq_init(ResumeUwbTasks, StopUwbTask, (const void *)nrf_crypto_init, diff --git a/SDK/external/freertos/source/include/FreeRTOS.h b/SDK/external/freertos/source/include/FreeRTOS.h index 04b2204..5a00460 100644 --- a/SDK/external/freertos/source/include/FreeRTOS.h +++ b/SDK/external/freertos/source/include/FreeRTOS.h @@ -236,6 +236,7 @@ extern "C" { #define configASSERT_DEFINED 0 #else #define configASSERT_DEFINED 1 + #warning here #endif /* The timers module relies on xTaskGetSchedulerState(). */