12
12
* from the real FRC2 timer ISR handler and calls former ISR handler.
13
13
* So, timer callbacks are called from the task context rather than an interrupt.
14
14
*
15
+ * Modifications from the original reverese engineered version:
16
+ * - FreeRTOS queue is replaced with Task notifications.
17
+ * - Removed unknown queue lenght monitoring and parameters allocation.
18
+ * - Removed unused debug variables
19
+ * - xTaskGenericCreate is replaced with xTaskCreate
20
+ *
15
21
* This timer should be used with coution together with other tasks. As the
16
22
* timer callback is executed within timer task context, access to data that
17
23
* other tasks accessing should be protected.
@@ -55,25 +61,7 @@ typedef struct ets_timer_st {
55
61
*/
56
62
static ets_timer_t * timer_list = 0 ;
57
63
58
- /**
59
- * Those debug variables are set but never used.
60
- */
61
- static ets_timer_func_t * debug_timerfn ;
62
- static ets_timer_t * debug_timer ;
63
-
64
- /**
65
- * Timer queue
66
- */
67
- static QueueHandle_t queue ;
68
-
69
- /**
70
- * Unknown stuff
71
- * Some counters
72
- */
73
- static uint8_t queue_len = 0 ;
74
- static uint8_t buf_param_index = 0 ;
75
- static uint64_t _unknown_buf [4 ];
76
-
64
+ static TaskHandle_t task_handle = NULL ;
77
65
78
66
void sdk_ets_timer_setfn (ets_timer_t * timer , ets_timer_func_t * func , void * parg )
79
67
{
@@ -87,7 +75,7 @@ void sdk_ets_timer_setfn(ets_timer_t *timer, ets_timer_func_t *func, void *parg)
87
75
/**
88
76
* .Lfunc004
89
77
*/
90
- static void set_alarm_value (uint32_t value )
78
+ static inline void set_alarm_value (uint32_t value )
91
79
{
92
80
TIMER_FRC2 .ALARM = value ;
93
81
}
@@ -247,15 +235,12 @@ void sdk_ets_timer_disarm(ets_timer_t *timer)
247
235
* Check the list of pending timers for expired ones and process them.
248
236
* This function is not called from the interrupt regardless of its name.
249
237
*/
250
- void sdk_ets_timer_handler_isr ()
238
+ void IRAM sdk_ets_timer_handler_isr ()
251
239
{
252
240
vPortEnterCritical ();
253
241
int32_t ticks = TIMER_FRC2 .COUNT ;
254
242
while (timer_list ) {
255
243
if (((int32_t )timer_list -> fire_ticks - ticks ) < 1 ) {
256
- debug_timerfn = timer_list -> callback ;
257
- debug_timer = timer_list ;
258
-
259
244
ets_timer_t * timer = timer_list ;
260
245
timer_list = timer -> next ;
261
246
timer -> next = ETS_TIMER_NOT_ARMED ;
@@ -281,67 +266,19 @@ void sdk_ets_timer_handler_isr()
281
266
vPortExitCritical ();
282
267
}
283
268
284
-
285
- /**
286
- * .Lfunc001
287
- *
288
- * Mysterious function.
289
- * It seems like it keeps track of the queue size and returns 0 if
290
- * the queue gets longer than 5.
291
- * Also it seems like it returns some buffers that are used in the queue.
292
- * But those buffers in the queue are not used at all.
293
- * If anybody knows what is this all about please leave a comment.
294
- */
295
- static void * IRAM func001 ()
296
- {
297
- uint8_t * p = (uint8_t * )_unknown_buf ;
298
-
299
- queue_len ++ ;
300
- if (queue_len < 5 ) {
301
- p += (buf_param_index * 8 );
302
- if (buf_param_index + 1 < 4 ) {
303
- buf_param_index ++ ;
304
- } else {
305
- buf_param_index = 0 ;
306
- }
307
- return p ;
308
- } else {
309
- queue_len -- ;
310
- return 0 ;
311
- }
312
- }
313
-
314
269
/**
315
270
* .Lfunc002
316
271
*/
317
272
static void IRAM frc2_isr ()
318
273
{
319
- void * p = func001 ();
320
-
321
- if (!p ) {
322
- printf ("TIMQ_NUL\n" );
323
- return ;
324
- }
325
-
326
274
BaseType_t task_woken = 0 ;
327
275
328
- BaseType_t result = xQueueGenericSendFromISR ( queue , p , & task_woken , 0 );
276
+ BaseType_t result = xTaskNotifyFromISR ( task_handle , 0 , eNoAction , & task_woken );
329
277
if (result != pdTRUE ) {
330
278
printf ("TIMQ_FL:%d!!" , (uint32_t )result );
331
279
}
332
- if (task_woken ) {
333
- vTaskSwitchContext ();
334
- }
335
- }
336
280
337
- /**
338
- * .Lfunc003
339
- */
340
- static void func003 ()
341
- {
342
- vPortEnterCritical ();
343
- queue_len -- ;
344
- vPortExitCritical ();
281
+ portEND_SWITCHING_ISR (task_woken );
345
282
}
346
283
347
284
/**
@@ -351,11 +288,9 @@ static void func003()
351
288
*/
352
289
static void timer_task (void * param )
353
290
{
354
- uint32_t * local0 ;
355
291
while (true) {
356
- if (xQueueGenericReceive ( queue , & local0 , 0xffffffff , 0 ) == 1 ) {
292
+ if (xTaskNotifyWait ( 0 , 0 , NULL , portMAX_DELAY ) == pdTRUE ) {
357
293
sdk_ets_timer_handler_isr ();
358
- func003 ();
359
294
}
360
295
}
361
296
}
@@ -366,17 +301,12 @@ void sdk_ets_timer_init()
366
301
367
302
_xt_isr_attach (INUM_TIMER_FRC2 , frc2_isr );
368
303
369
- queue = xQueueGenericCreate (/*length=*/ 4 , /*item size=*/ 4 ,
370
- /*queu type: base*/ 0 );
371
-
372
- TaskHandle_t handle = 0 ;
373
-
374
304
/* Original code calls xTaskGenericCreate:
375
- * xTaskGenericCreate(timer_task , "rtc_timer_task", 200, 0, 12, &handle,
305
+ * xTaskGenericCreate(task_handle , "rtc_timer_task", 200, 0, 12, &handle,
376
306
* NULL, NULL);
377
307
*/
378
- xTaskCreate (timer_task , "rtc_timer_task" , 200 , 0 , 12 , & handle );
379
- printf ("frc2_timer_task_hdl:%x , prio:%d, stack:%d\n" , ( uint32_t ) handle , 12 , 200 );
308
+ xTaskCreate (timer_task , "rtc_timer_task" , 200 , 0 , 12 , & task_handle );
309
+ printf ("frc2_timer_task_hdl:%p , prio:%d, stack:%d\n" , task_handle , 12 , 200 );
380
310
381
311
TIMER_FRC2 .ALARM = 0 ;
382
312
TIMER_FRC2 .CTRL = VAL2FIELD (TIMER_CTRL_CLKDIV , TIMER_CLKDIV_16 )
0 commit comments