From 509d55f9a5e22a3828dd57bbaa8f7343037ef507 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 15 Sep 2017 16:40:14 +0700 Subject: [PATCH] Add Adacallback as part of the repo and initial task --- cores/nRF5/Arduino.h | 1 + cores/nRF5/main.cpp | 3 +++ cores/nRF5/utility/AdaCallback.c | 5 ++--- cores/nRF5/utility/AdaCallback.h | 6 +++--- libraries/Bluefruit52Lib/src/bluefruit.cpp | 2 -- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/cores/nRF5/Arduino.h b/cores/nRF5/Arduino.h index bb02fa9c..d871a8c4 100644 --- a/cores/nRF5/Arduino.h +++ b/cores/nRF5/Arduino.h @@ -63,6 +63,7 @@ uint32_t setLoopStacksize(void); #include "debug.h" #include "common_inc.h" #include "utility/utilities.h" +#include "utility/AdaCallback.h" #ifdef __cplusplus #include "Uart.h" diff --git a/cores/nRF5/main.cpp b/cores/nRF5/main.cpp index 56c53046..b3e865ca 100644 --- a/cores/nRF5/main.cpp +++ b/cores/nRF5/main.cpp @@ -95,6 +95,9 @@ int main( void ) TaskHandle_t _loopHandle; xTaskCreate( loop_task, "loop", _loopStacksize, NULL, TASK_PRIO_NORMAL, &_loopHandle); + // Initialize callback task + ada_callback_init(); + // Start FreeRTOS scheduler. vTaskStartScheduler(); diff --git a/cores/nRF5/utility/AdaCallback.c b/cores/nRF5/utility/AdaCallback.c index e2d87cba..7cff83e5 100644 --- a/cores/nRF5/utility/AdaCallback.c +++ b/cores/nRF5/utility/AdaCallback.c @@ -34,7 +34,7 @@ */ /**************************************************************************/ -#include "AdaCallback.h" +#include "Arduino.h" static QueueHandle_t _cb_queue = NULL; @@ -48,7 +48,6 @@ void adafruit_callback_task(void* arg) if ( xQueueReceive(_cb_queue, (void*) &cb_data, portMAX_DELAY) ) { // PRINT_HEX(cb_data); -// PRINT_INT(cb_data->callback_type); // PRINT_HEX(cb_data->malloced_data); void* func = cb_data->callback_func; @@ -75,7 +74,7 @@ void adafruit_callback_task(void* arg) void ada_callback_queue(ada_callback_t* cb_data) { - xQueueSend(_cb_queue, (void*) &cb_data, BLE_GENERIC_TIMEOUT); + xQueueSend(_cb_queue, (void*) &cb_data, CFG_CALLBACK_TIMEOUT); } void ada_callback_init(void) diff --git a/cores/nRF5/utility/AdaCallback.h b/cores/nRF5/utility/AdaCallback.h index e5f329a9..7e12fd2e 100644 --- a/cores/nRF5/utility/AdaCallback.h +++ b/cores/nRF5/utility/AdaCallback.h @@ -36,11 +36,11 @@ #ifndef ADACALLBACK_H_ #define ADACALLBACK_H_ -#include -#include "bluefruit.h" +#include "common_inc.h" #define CFG_CALLBACK_TASK_STACKSIZE (512*2) #define CFG_CALLBACK_QUEUE_LENGTH 20 +#define CFG_CALLBACK_TIMEOUT 100 #ifdef __cplusplus extern "C"{ @@ -58,7 +58,7 @@ typedef struct uint32_t arguments[1]; // flexible array holder }ada_callback_t; -static_assert(sizeof(ada_callback_t) == 16, "Incorrect Size"); +VERIFY_STATIC( sizeof(ada_callback_t) == 16 ); /*------------- Defer callback type, determined by number of arguments -------------*/ typedef void (*adacb_0arg_t) (void); diff --git a/libraries/Bluefruit52Lib/src/bluefruit.cpp b/libraries/Bluefruit52Lib/src/bluefruit.cpp index 2c7d9c39..53bc16e0 100644 --- a/libraries/Bluefruit52Lib/src/bluefruit.cpp +++ b/libraries/Bluefruit52Lib/src/bluefruit.cpp @@ -214,8 +214,6 @@ err_t AdafruitBluefruit::begin(bool prph_enable, bool central_enable) TaskHandle_t soc_task_hdl; xTaskCreate( adafruit_soc_task, "SD SOC", CFG_SOC_TASK_STACKSIZE, NULL, TASK_PRIO_HIGH, &soc_task_hdl); - ada_callback_init(); - NVIC_SetPriority(SD_EVT_IRQn, 6); NVIC_EnableIRQ(SD_EVT_IRQn);