99#include "freertos/queue.h"
1010#include "freertos/semphr.h"
1111
12- #define TASK_HANDLE_MONIKER 0x68680000
13- #define TASK_HANDLE_MASK 0xFFF80000
14- #define TASK_HANDLE_UNMASK (~TASK_HANDLE_MASK)
15- #define TASK_HANDLE_ALLOCATION_BRICK 4 // must be a power of 2
16-
17- #define CHECK (p ,v ,msg ) if (!(p)) { NODE_DBG ( msg ); return (v); }
18-
19- #ifndef NODE_DBG
20- # define NODE_DBG (...) do{}while(0)
21- #endif
22-
2312typedef struct
2413{
25- task_handle_t sig ;
14+ task_handle_t handle ;
2615 task_param_t par ;
2716} task_event_t ;
2817
@@ -35,30 +24,9 @@ static xQueueHandle task_Q[TASK_PRIORITY_COUNT];
3524 * we use a binary semaphore to unblock the pump whenever something is posted */
3625static xSemaphoreHandle pending ;
3726
38- static task_callback_t * task_func ;
39- static int task_count ;
40-
41-
42- task_handle_t task_get_id (task_callback_t t ) {
43- if ( (task_count & (TASK_HANDLE_ALLOCATION_BRICK - 1 )) == 0 ) {
44- /* With a brick size of 4 this branch is taken at 0, 4, 8 ... and the new size is +4 */
45- task_func = (task_callback_t * )realloc (
46- task_func ,
47- sizeof (task_callback_t )* (task_count + TASK_HANDLE_ALLOCATION_BRICK ));
48-
49- CHECK (task_func , 0 , "Malloc failure in task_get_id" );
50- memset (task_func + task_count , 0 , sizeof (task_callback_t )* TASK_HANDLE_ALLOCATION_BRICK );
51- }
52-
53- task_func [task_count ] = t ;
54- return TASK_HANDLE_MONIKER | task_count ++ ;
55- }
56-
57-
5827bool IRAM_ATTR task_post (task_prio_t priority , task_handle_t handle , task_param_t param )
5928{
60- if (priority >= TASK_PRIORITY_COUNT ||
61- (handle & TASK_HANDLE_MASK ) != TASK_HANDLE_MONIKER )
29+ if (priority >= TASK_PRIORITY_COUNT )
6230 return false;
6331
6432 task_event_t ev = { handle , param };
@@ -86,17 +54,7 @@ static bool next_event (task_event_t *ev, task_prio_t *prio)
8654
8755
8856static void dispatch (task_event_t * e , uint8_t prio ) {
89- task_handle_t handle = e -> sig ;
90- if ( (handle & TASK_HANDLE_MASK ) == TASK_HANDLE_MONIKER ) {
91- uint16_t entry = (handle & TASK_HANDLE_UNMASK );
92- if ( task_func && entry < task_count ){
93- /* call the registered task handler with the specified parameter and priority */
94- task_func [entry ](e -> par , prio );
95- return ;
96- }
97- }
98- /* Invalid signals are ignored */
99- NODE_DBG ( "Invalid signal issued: %08x" , handle );
57+ ((task_callback_t )e -> handle )(e -> par , prio );
10058}
10159
10260
0 commit comments