From 75dbc59ba95fde9be3351024ced8a7bd6cd397f5 Mon Sep 17 00:00:00 2001 From: Johny Mattsson Date: Tue, 31 May 2016 13:56:47 +1000 Subject: [PATCH] Fixes to task reimplementation to make UART work. --- app/task/task.c | 20 +++++++++++--------- app/user/user_main.c | 6 ++---- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/task/task.c b/app/task/task.c index 3ca057e0..57cb9294 100644 --- a/app/task/task.c +++ b/app/task/task.c @@ -54,12 +54,13 @@ bool task_init_handler(task_prio_t priority, uint8 qlen) { task_handle_t task_get_id(task_callback_t t) { - int p = TASK_PRIORITY_COUNT; - /* Initialise and uninitialised Qs with the default Q len */ - while(p--) + /* Initialise any uninitialised Qs with the default Q len */ + for (task_prio_t p = TASK_PRIORITY_LOW; p != TASK_PRIORITY_COUNT; ++p) + { if (!task_Q[p]) { CHECK(task_init_handler( p, TASK_DEFAULT_QUEUE_LEN ), 0, "Task initialisation failed"); } + } if ( (task_count & (TASK_HANDLE_ALLOCATION_BRICK - 1)) == 0 ) { /* With a brick size of 4 this branch is taken at 0, 4, 8 ... and the new size is +4 */ @@ -71,8 +72,8 @@ task_handle_t task_get_id(task_callback_t t) { memset (task_func+task_count, 0, sizeof(task_callback_t)*TASK_HANDLE_ALLOCATION_BRICK); } - task_func[task_count++] = t; - return TASK_HANDLE_MONIKER + (task_count-1); + task_func[task_count] = t; + return TASK_HANDLE_MONIKER | task_count++; } @@ -80,7 +81,7 @@ bool task_post (task_prio_t priority, task_handle_t handle, task_param_t param) { if (priority >= TASK_PRIORITY_COUNT || !task_Q[priority] || - (handle & TASK_HANDLE_MASK != TASK_HANDLE_MONIKER)) + (handle & TASK_HANDLE_MASK) != TASK_HANDLE_MONIKER) return false; task_event_t ev = { handle, param }; @@ -95,11 +96,12 @@ bool task_post (task_prio_t priority, task_handle_t handle, task_param_t param) static bool next_event (task_event_t *ev, task_prio_t *prio) { - for (task_prio_t p = TASK_PRIORITY_COUNT; p != TASK_PRIORITY_LOW; --p) + for (task_prio_t pr = TASK_PRIORITY_COUNT; pr != TASK_PRIORITY_LOW; --pr) { - if (task_Q[p-1] && xQueueReceive (task_Q[p-1], ev, 0) == pdTRUE) + task_prio_t p = pr -1; + if (task_Q[p] && xQueueReceive (task_Q[p], ev, 0) == pdTRUE) { - *prio = p-1; + *prio = p; return true; } } diff --git a/app/user/user_main.c b/app/user/user_main.c index 2b0b44ad..f98be49b 100644 --- a/app/user/user_main.c +++ b/app/user/user_main.c @@ -54,6 +54,7 @@ void TEXT_SECTION_ATTR user_start_trampoline (void) // +================== New task interface ==================+ static void start_lua(task_param_t param, task_prio_t prio) { + (void)param; (void)prio; char* lua_argv[] = { (char *)"lua", (char *)"-i", NULL }; NODE_DBG("Task task_lua started.\n"); @@ -115,7 +116,7 @@ void nodemcu_init(void) // test_spiffs(); #endif - task_post_low(task_get_id(start_lua),'s'); + task_post_low(task_get_id(start_lua), 0); } @@ -142,13 +143,10 @@ void user_init(void) rtctime_late_startup (); #endif -#if 0 - // TODO: fix uart driver to work with RTOS SDK UartBautRate br = BIT_RATE_DEFAULT; input_sig = task_get_id(handle_input); uart_init (br, br, input_sig); -#endif #ifndef NODE_DEBUG system_set_os_print(0);