Skip to content

Commit 4f99bc3

Browse files
committed
remove unused constant
Simplify task.c to use handles as callbacks
1 parent 189fe96 commit 4f99bc3

File tree

2 files changed

+8
-50
lines changed

2 files changed

+8
-50
lines changed

components/task/include/task/task.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ typedef enum {
1313
TASK_PRIORITY_COUNT
1414
} task_prio_t;
1515

16-
typedef uint32_t task_handle_t;
1716
typedef intptr_t task_param_t;
18-
17+
typedef void (*task_callback_t)(task_param_t param, task_prio_t prio);
18+
typedef task_callback_t task_handle_t;
1919
/*
2020
* Signals are a 32-bit number of the form header:14; count:18. The header
2121
* is just a fixed fingerprint and the count is allocated serially by the
@@ -27,9 +27,9 @@ bool task_post(task_prio_t priority, task_handle_t handle, task_param_t param);
2727
#define task_post_medium(handle,param) task_post(TASK_PRIORITY_MEDIUM, handle, param)
2828
#define task_post_high(handle,param) task_post(TASK_PRIORITY_HIGH, handle, param)
2929

30-
typedef void (*task_callback_t)(task_param_t param, task_prio_t prio);
31-
32-
task_handle_t task_get_id(task_callback_t t);
30+
inline task_handle_t task_get_id(task_callback_t t) {
31+
return (task_handle_t)t;
32+
}
3333

3434
/* Init, must be called before any posting happens */
3535
void task_init (void);

components/task/task.c

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,9 @@
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-
2312
typedef 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 */
3625
static 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-
5827
bool 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

8856
static 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

Comments
 (0)