1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
35
36
37
38
39
40
41
42
43
44
45
46
49
50
51
52
56
57
58
59
60
61
62
64
65
66
67
68
69
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
98
99
100
105
106
110
111
112
113
119
120
122
123
124
125
126
127
128
129
131
132
133
134
135
136
137
143
144
145
146
147
148
149
150
151
152
153
154
158
159
160
165
166
167
171
172
173
177
178
179
180
181
182
187
188
189
190
191
195
196
197
198
202
203
204
208
209
210
216
217
218
222
223
224
225
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
390
391
392
393
394
395
396
397
398
399
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
429
430
431
433
434
435
436
437
438
439
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
465
466
467
468
469
470
471
472
473
474
485
486
487
488
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
516
517
518
519
520
521
522
523
524
525
529
530
531
532
536
537
538
539
540
541
542
543
544
545
546
547
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
728
729
730
731
733
737
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
764
765
766
767
768
770
771
772
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
795
796
797
798
799
800
805
806
807
813
819
820
821
822
830
834
835
836
840
841
842
843
844
845
846
847
848
855
856
857
861
866
867
868
869
870
871
872
873
874
875
876
877
878
883
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
919
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
951
952
953
954
955
957
958
959
960
961
962
966
967
968
969
971
972
973
975
976
977
982
986
987
988
989
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1010
1014
1018
1019
1020
1021
1022
1023
1027
1028
1029
1030
1031
1036
1037
1038
1039
1040
1041
1042
1048
1049
1050
1051
1052
1053
1066
1067
1074
1075
1076
1077
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1095
1096
1097
1098
1099
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1129
1130
1131
1132
1133
1134
1135
1138
1139
1140
1141
1151
1152
1153
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1276
1277
1278
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1330
1335
1336
1337
1340
/* ... */
#include <stdlib.h>
/* ... */
#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "timers.h"
#if ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 0 )
#error configUSE_TIMERS must be set to 1 to make the xTimerPendFunctionCall() function available.
#endif
/* ... */
#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE
/* ... */
#if ( configUSE_TIMERS == 1 )
#define tmrNO_DELAY ( ( TickType_t ) 0U )
#define tmrMAX_TIME_BEFORE_OVERFLOW ( ( TickType_t ) -1 )
/* ... */
#ifndef configTIMER_SERVICE_TASK_NAME
#define configTIMER_SERVICE_TASK_NAME "Tmr Svc"
#endif
#if ( ( configNUMBER_OF_CORES > 1 ) && ( configUSE_CORE_AFFINITY == 1 ) )
/* ... */
#ifndef configTIMER_SERVICE_TASK_CORE_AFFINITY
#define configTIMER_SERVICE_TASK_CORE_AFFINITY tskNO_AFFINITY
#endif/* ... */
#endif
#define tmrSTATUS_IS_ACTIVE ( 0x01U )
#define tmrSTATUS_IS_STATICALLY_ALLOCATED ( 0x02U )
#define tmrSTATUS_IS_AUTORELOAD ( 0x04U )
typedef struct tmrTimerControl
{
const char * pcTimerName;
ListItem_t xTimerListItem;
TickType_t xTimerPeriodInTicks;
void * pvTimerID;
portTIMER_CALLBACK_ATTRIBUTE TimerCallbackFunction_t pxCallbackFunction;
#if ( configUSE_TRACE_FACILITY == 1 )
UBaseType_t uxTimerNumber;
#endif
uint8_t ucStatus;
...} xTIMER;
/* ... */
typedef xTIMER Timer_t;
/* ... */
typedef struct tmrTimerParameters
{
TickType_t xMessageValue;
Timer_t * pxTimer;
...} TimerParameter_t;
typedef struct tmrCallbackParameters
{
portTIMER_CALLBACK_ATTRIBUTE
PendedFunction_t pxCallbackFunction;
void * pvParameter1;
uint32_t ulParameter2;
...} CallbackParameters_t;
/* ... */
typedef struct tmrTimerQueueMessage
{
BaseType_t xMessageID;
union
{
TimerParameter_t xTimerParameters;
/* ... */
#if ( INCLUDE_xTimerPendFunctionCall == 1 )
CallbackParameters_t xCallbackParameters;
#endif
...} u;
...} DaemonTaskMessage_t;
/* ... */
PRIVILEGED_DATA static List_t xActiveTimerList1;
PRIVILEGED_DATA static List_t xActiveTimerList2;
PRIVILEGED_DATA static List_t * pxCurrentTimerList;
PRIVILEGED_DATA static List_t * pxOverflowTimerList;
PRIVILEGED_DATA static QueueHandle_t xTimerQueue = NULL;
PRIVILEGED_DATA static TaskHandle_t xTimerTaskHandle = NULL;
/* ... */
static void prvCheckForValidListAndQueue( void ) PRIVILEGED_FUNCTION;
/* ... */
static portTASK_FUNCTION_PROTO( prvTimerTask, pvParameters ) PRIVILEGED_FUNCTION;
/* ... */
static void prvProcessReceivedCommands( void ) PRIVILEGED_FUNCTION;
/* ... */
static BaseType_t prvInsertTimerInActiveList( Timer_t * const pxTimer,
const TickType_t xNextExpiryTime,
const TickType_t xTimeNow,
const TickType_t xCommandTime ) PRIVILEGED_FUNCTION;
/* ... */
static void prvReloadTimer( Timer_t * const pxTimer,
TickType_t xExpiredTime,
const TickType_t xTimeNow ) PRIVILEGED_FUNCTION;
/* ... */
static void prvProcessExpiredTimer( const TickType_t xNextExpireTime,
const TickType_t xTimeNow ) PRIVILEGED_FUNCTION;
/* ... */
static void prvSwitchTimerLists( void ) PRIVILEGED_FUNCTION;
/* ... */
static TickType_t prvSampleTimeNow( BaseType_t * const pxTimerListsWereSwitched ) PRIVILEGED_FUNCTION;
/* ... */
static TickType_t prvGetNextExpireTime( BaseType_t * const pxListWasEmpty ) PRIVILEGED_FUNCTION;
/* ... */
static void prvProcessTimerOrBlockTask( const TickType_t xNextExpireTime,
BaseType_t xListWasEmpty ) PRIVILEGED_FUNCTION;
/* ... */
static void prvInitialiseNewTimer( const char * const pcTimerName,
const TickType_t xTimerPeriodInTicks,
const BaseType_t xAutoReload,
void * const pvTimerID,
TimerCallbackFunction_t pxCallbackFunction,
Timer_t * pxNewTimer ) PRIVILEGED_FUNCTION;
BaseType_t xTimerCreateTimerTask( void )
{
BaseType_t xReturn = pdFAIL;
traceENTER_xTimerCreateTimerTask();
/* ... */
prvCheckForValidListAndQueue();
if( xTimerQueue != NULL )
{
#if ( ( configNUMBER_OF_CORES > 1 ) && ( configUSE_CORE_AFFINITY == 1 ) )
{
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
{
StaticTask_t * pxTimerTaskTCBBuffer = NULL;
StackType_t * pxTimerTaskStackBuffer = NULL;
configSTACK_DEPTH_TYPE uxTimerTaskStackSize;
vApplicationGetTimerTaskMemory( &pxTimerTaskTCBBuffer, &pxTimerTaskStackBuffer, &uxTimerTaskStackSize );
xTimerTaskHandle = xTaskCreateStaticAffinitySet( prvTimerTask,
configTIMER_SERVICE_TASK_NAME,
uxTimerTaskStackSize,
NULL,
( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT,
pxTimerTaskStackBuffer,
pxTimerTaskTCBBuffer,
configTIMER_SERVICE_TASK_CORE_AFFINITY );
if( xTimerTaskHandle != NULL )
{
xReturn = pdPASS;
}if (xTimerTaskHandle != NULL) { ... }
...}/* ... */
#else
{
xReturn = xTaskCreateAffinitySet( prvTimerTask,
configTIMER_SERVICE_TASK_NAME,
configTIMER_TASK_STACK_DEPTH,
NULL,
( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT,
configTIMER_SERVICE_TASK_CORE_AFFINITY,
&xTimerTaskHandle );
...}/* ... */
#endif
...}/* ... */
#else
{
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
{
StaticTask_t * pxTimerTaskTCBBuffer = NULL;
StackType_t * pxTimerTaskStackBuffer = NULL;
configSTACK_DEPTH_TYPE uxTimerTaskStackSize;
vApplicationGetTimerTaskMemory( &pxTimerTaskTCBBuffer, &pxTimerTaskStackBuffer, &uxTimerTaskStackSize );
xTimerTaskHandle = xTaskCreateStatic( prvTimerTask,
configTIMER_SERVICE_TASK_NAME,
uxTimerTaskStackSize,
NULL,
( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT,
pxTimerTaskStackBuffer,
pxTimerTaskTCBBuffer );
if( xTimerTaskHandle != NULL )
{
xReturn = pdPASS;
}if (xTimerTaskHandle != NULL) { ... }
...}/* ... */
#else
{
xReturn = xTaskCreate( prvTimerTask,
configTIMER_SERVICE_TASK_NAME,
configTIMER_TASK_STACK_DEPTH,
NULL,
( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT,
&xTimerTaskHandle );
...}/* ... */
#endif
...}/* ... */
#endif
}if (xTimerQueue != NULL) { ... }
else
{
mtCOVERAGE_TEST_MARKER();
}else { ... }
configASSERT( xReturn );
traceRETURN_xTimerCreateTimerTask( xReturn );
return xReturn;
}xTimerCreateTimerTask (void) { ... }
#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
TimerHandle_t xTimerCreate( const char * const pcTimerName,
const TickType_t xTimerPeriodInTicks,
const BaseType_t xAutoReload,
void * const pvTimerID,
TimerCallbackFunction_t pxCallbackFunction )
{
Timer_t * pxNewTimer;
traceENTER_xTimerCreate( pcTimerName, xTimerPeriodInTicks, xAutoReload, pvTimerID, pxCallbackFunction );
pxNewTimer = ( Timer_t * ) pvPortMalloc( sizeof( Timer_t ) );
if( pxNewTimer != NULL )
{
/* ... */
pxNewTimer->ucStatus = 0x00;
prvInitialiseNewTimer( pcTimerName, xTimerPeriodInTicks, xAutoReload, pvTimerID, pxCallbackFunction, pxNewTimer );
}if (pxNewTimer != NULL) { ... }
traceRETURN_xTimerCreate( pxNewTimer );
return pxNewTimer;
}xTimerCreate (const char * const pcTimerName, const TickType_t xTimerPeriodInTicks, const BaseType_t xAutoReload, void * const pvTimerID, TimerCallbackFunction_t pxCallbackFunction) { ... }
/* ... */
#endif
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
TimerHandle_t xTimerCreateStatic( const char * const pcTimerName,
const TickType_t xTimerPeriodInTicks,
const BaseType_t xAutoReload,
void * const pvTimerID,
TimerCallbackFunction_t pxCallbackFunction,
StaticTimer_t * pxTimerBuffer )
{
Timer_t * pxNewTimer;
traceENTER_xTimerCreateStatic( pcTimerName, xTimerPeriodInTicks, xAutoReload, pvTimerID, pxCallbackFunction, pxTimerBuffer );
#if ( configASSERT_DEFINED == 1 )
{
/* ... */
volatile size_t xSize = sizeof( StaticTimer_t );
configASSERT( xSize == sizeof( Timer_t ) );
( void ) xSize;
...}/* ... */
#endif
configASSERT( pxTimerBuffer );
pxNewTimer = ( Timer_t * ) pxTimerBuffer;
if( pxNewTimer != NULL )
{
/* ... */
pxNewTimer->ucStatus = ( uint8_t ) tmrSTATUS_IS_STATICALLY_ALLOCATED;
prvInitialiseNewTimer( pcTimerName, xTimerPeriodInTicks, xAutoReload, pvTimerID, pxCallbackFunction, pxNewTimer );
}if (pxNewTimer != NULL) { ... }
traceRETURN_xTimerCreateStatic( pxNewTimer );
return pxNewTimer;
}xTimerCreateStatic (const char * const pcTimerName, const TickType_t xTimerPeriodInTicks, const BaseType_t xAutoReload, void * const pvTimerID, TimerCallbackFunction_t pxCallbackFunction, StaticTimer_t * pxTimerBuffer) { ... }
/* ... */
#endif
static void prvInitialiseNewTimer( const char * const pcTimerName,
const TickType_t xTimerPeriodInTicks,
const BaseType_t xAutoReload,
void * const pvTimerID,
TimerCallbackFunction_t pxCallbackFunction,
Timer_t * pxNewTimer )
{
configASSERT( ( xTimerPeriodInTicks > 0 ) );
/* ... */
prvCheckForValidListAndQueue();
/* ... */
pxNewTimer->pcTimerName = pcTimerName;
pxNewTimer->xTimerPeriodInTicks = xTimerPeriodInTicks;
pxNewTimer->pvTimerID = pvTimerID;
pxNewTimer->pxCallbackFunction = pxCallbackFunction;
vListInitialiseItem( &( pxNewTimer->xTimerListItem ) );
if( xAutoReload != pdFALSE )
{
pxNewTimer->ucStatus |= ( uint8_t ) tmrSTATUS_IS_AUTORELOAD;
}if (xAutoReload != pdFALSE) { ... }
traceTIMER_CREATE( pxNewTimer );
}prvInitialiseNewTimer (const char * const pcTimerName, const TickType_t xTimerPeriodInTicks, const BaseType_t xAutoReload, void * const pvTimerID, TimerCallbackFunction_t pxCallbackFunction, Timer_t * pxNewTimer) { ... }
BaseType_t xTimerGenericCommandFromTask( TimerHandle_t xTimer,
const BaseType_t xCommandID,
const TickType_t xOptionalValue,
BaseType_t * const pxHigherPriorityTaskWoken,
const TickType_t xTicksToWait )
{
BaseType_t xReturn = pdFAIL;
DaemonTaskMessage_t xMessage;
( void ) pxHigherPriorityTaskWoken;
traceENTER_xTimerGenericCommandFromTask( xTimer, xCommandID, xOptionalValue, pxHigherPriorityTaskWoken, xTicksToWait );
configASSERT( xTimer );
/* ... */
if( xTimerQueue != NULL )
{
xMessage.xMessageID = xCommandID;
xMessage.u.xTimerParameters.xMessageValue = xOptionalValue;
xMessage.u.xTimerParameters.pxTimer = xTimer;
configASSERT( xCommandID < tmrFIRST_FROM_ISR_COMMAND );
if( xCommandID < tmrFIRST_FROM_ISR_COMMAND )
{
if( xTaskGetSchedulerState() == taskSCHEDULER_RUNNING )
{
xReturn = xQueueSendToBack( xTimerQueue, &xMessage, xTicksToWait );
}if (xTaskGetSchedulerState() == taskSCHEDULER_RUNNING) { ... }
else
{
xReturn = xQueueSendToBack( xTimerQueue, &xMessage, tmrNO_DELAY );
}else { ... }
}if (xCommandID < tmrFIRST_FROM_ISR_COMMAND) { ... }
traceTIMER_COMMAND_SEND( xTimer, xCommandID, xOptionalValue, xReturn );
}if (xTimerQueue != NULL) { ... }
else
{
mtCOVERAGE_TEST_MARKER();
}else { ... }
traceRETURN_xTimerGenericCommandFromTask( xReturn );
return xReturn;
}xTimerGenericCommandFromTask (TimerHandle_t xTimer, const BaseType_t xCommandID, const TickType_t xOptionalValue, BaseType_t * const pxHigherPriorityTaskWoken, const TickType_t xTicksToWait) { ... }
BaseType_t xTimerGenericCommandFromISR( TimerHandle_t xTimer,
const BaseType_t xCommandID,
const TickType_t xOptionalValue,
BaseType_t * const pxHigherPriorityTaskWoken,
const TickType_t xTicksToWait )
{
BaseType_t xReturn = pdFAIL;
DaemonTaskMessage_t xMessage;
( void ) xTicksToWait;
traceENTER_xTimerGenericCommandFromISR( xTimer, xCommandID, xOptionalValue, pxHigherPriorityTaskWoken, xTicksToWait );
configASSERT( xTimer );
/* ... */
if( xTimerQueue != NULL )
{
xMessage.xMessageID = xCommandID;
xMessage.u.xTimerParameters.xMessageValue = xOptionalValue;
xMessage.u.xTimerParameters.pxTimer = xTimer;
configASSERT( xCommandID >= tmrFIRST_FROM_ISR_COMMAND );
if( xCommandID >= tmrFIRST_FROM_ISR_COMMAND )
{
xReturn = xQueueSendToBackFromISR( xTimerQueue, &xMessage, pxHigherPriorityTaskWoken );
}if (xCommandID >= tmrFIRST_FROM_ISR_COMMAND) { ... }
traceTIMER_COMMAND_SEND( xTimer, xCommandID, xOptionalValue, xReturn );
}if (xTimerQueue != NULL) { ... }
else
{
mtCOVERAGE_TEST_MARKER();
}else { ... }
traceRETURN_xTimerGenericCommandFromISR( xReturn );
return xReturn;
}xTimerGenericCommandFromISR (TimerHandle_t xTimer, const BaseType_t xCommandID, const TickType_t xOptionalValue, BaseType_t * const pxHigherPriorityTaskWoken, const TickType_t xTicksToWait) { ... }
TaskHandle_t xTimerGetTimerDaemonTaskHandle( void )
{
traceENTER_xTimerGetTimerDaemonTaskHandle();
/* ... */
configASSERT( ( xTimerTaskHandle != NULL ) );
traceRETURN_xTimerGetTimerDaemonTaskHandle( xTimerTaskHandle );
return xTimerTaskHandle;
}xTimerGetTimerDaemonTaskHandle (void) { ... }
TickType_t xTimerGetPeriod( TimerHandle_t xTimer )
{
Timer_t * pxTimer = xTimer;
traceENTER_xTimerGetPeriod( xTimer );
configASSERT( xTimer );
traceRETURN_xTimerGetPeriod( pxTimer->xTimerPeriodInTicks );
return pxTimer->xTimerPeriodInTicks;
}xTimerGetPeriod (TimerHandle_t xTimer) { ... }
void vTimerSetReloadMode( TimerHandle_t xTimer,
const BaseType_t xAutoReload )
{
Timer_t * pxTimer = xTimer;
traceENTER_vTimerSetReloadMode( xTimer, xAutoReload );
configASSERT( xTimer );
taskENTER_CRITICAL();
{
if( xAutoReload != pdFALSE )
{
pxTimer->ucStatus |= ( uint8_t ) tmrSTATUS_IS_AUTORELOAD;
}if (xAutoReload != pdFALSE) { ... }
else
{
pxTimer->ucStatus &= ( ( uint8_t ) ~tmrSTATUS_IS_AUTORELOAD );
}else { ... }
...}
taskEXIT_CRITICAL();
traceRETURN_vTimerSetReloadMode();
}vTimerSetReloadMode (TimerHandle_t xTimer, const BaseType_t xAutoReload) { ... }
BaseType_t xTimerGetReloadMode( TimerHandle_t xTimer )
{
Timer_t * pxTimer = xTimer;
BaseType_t xReturn;
traceENTER_xTimerGetReloadMode( xTimer );
configASSERT( xTimer );
taskENTER_CRITICAL();
{
if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) == 0U )
{
xReturn = pdFALSE;
}if (( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) == 0U) { ... }
else
{
xReturn = pdTRUE;
}else { ... }
...}
taskEXIT_CRITICAL();
traceRETURN_xTimerGetReloadMode( xReturn );
return xReturn;
}xTimerGetReloadMode (TimerHandle_t xTimer) { ... }
UBaseType_t uxTimerGetReloadMode( TimerHandle_t xTimer )
{
UBaseType_t uxReturn;
traceENTER_uxTimerGetReloadMode( xTimer );
uxReturn = ( UBaseType_t ) xTimerGetReloadMode( xTimer );
traceRETURN_uxTimerGetReloadMode( uxReturn );
return uxReturn;
}uxTimerGetReloadMode (TimerHandle_t xTimer) { ... }
TickType_t xTimerGetExpiryTime( TimerHandle_t xTimer )
{
Timer_t * pxTimer = xTimer;
TickType_t xReturn;
traceENTER_xTimerGetExpiryTime( xTimer );
configASSERT( xTimer );
xReturn = listGET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ) );
traceRETURN_xTimerGetExpiryTime( xReturn );
return xReturn;
}xTimerGetExpiryTime (TimerHandle_t xTimer) { ... }
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
BaseType_t xTimerGetStaticBuffer( TimerHandle_t xTimer,
StaticTimer_t ** ppxTimerBuffer )
{
BaseType_t xReturn;
Timer_t * pxTimer = xTimer;
traceENTER_xTimerGetStaticBuffer( xTimer, ppxTimerBuffer );
configASSERT( ppxTimerBuffer != NULL );
if( ( pxTimer->ucStatus & tmrSTATUS_IS_STATICALLY_ALLOCATED ) != 0U )
{
*ppxTimerBuffer = ( StaticTimer_t * ) pxTimer;
xReturn = pdTRUE;
}if (( pxTimer->ucStatus & tmrSTATUS_IS_STATICALLY_ALLOCATED ) != 0U) { ... }
else
{
xReturn = pdFALSE;
}else { ... }
traceRETURN_xTimerGetStaticBuffer( xReturn );
return xReturn;
}xTimerGetStaticBuffer (TimerHandle_t xTimer, StaticTimer_t ** ppxTimerBuffer) { ... }
/* ... */ #endif
const char * pcTimerGetName( TimerHandle_t xTimer )
{
Timer_t * pxTimer = xTimer;
traceENTER_pcTimerGetName( xTimer );
configASSERT( xTimer );
traceRETURN_pcTimerGetName( pxTimer->pcTimerName );
return pxTimer->pcTimerName;
}pcTimerGetName (TimerHandle_t xTimer) { ... }
static void prvReloadTimer( Timer_t * const pxTimer,
TickType_t xExpiredTime,
const TickType_t xTimeNow )
{
/* ... */
while( prvInsertTimerInActiveList( pxTimer, ( xExpiredTime + pxTimer->xTimerPeriodInTicks ), xTimeNow, xExpiredTime ) != pdFALSE )
{
xExpiredTime += pxTimer->xTimerPeriodInTicks;
traceTIMER_EXPIRED( pxTimer );
pxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer );
}while (prvInsertTimerInActiveList( pxTimer, ( xExpiredTime + pxTimer->xTimerPeriodInTicks ), xTimeNow, xExpiredTime ) != pdFALSE) { ... }
}prvReloadTimer (Timer_t * const pxTimer, TickType_t xExpiredTime, const TickType_t xTimeNow) { ... }
static void prvProcessExpiredTimer( const TickType_t xNextExpireTime,
const TickType_t xTimeNow )
{
Timer_t * const pxTimer = ( Timer_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList );
/* ... */
( void ) uxListRemove( &( pxTimer->xTimerListItem ) );
/* ... */
if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) != 0U )
{
prvReloadTimer( pxTimer, xNextExpireTime, xTimeNow );
}if (( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) != 0U) { ... }
else
{
pxTimer->ucStatus &= ( ( uint8_t ) ~tmrSTATUS_IS_ACTIVE );
}else { ... }
traceTIMER_EXPIRED( pxTimer );
pxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer );
}prvProcessExpiredTimer (const TickType_t xNextExpireTime, const TickType_t xTimeNow) { ... }
static portTASK_FUNCTION( prvTimerTask, pvParameters )
{
TickType_t xNextExpireTime;
BaseType_t xListWasEmpty;
( void ) pvParameters;
#if ( configUSE_DAEMON_TASK_STARTUP_HOOK == 1 )
{
/* ... */
vApplicationDaemonTaskStartupHook();
...}/* ... */
#endif
for( ; configCONTROL_INFINITE_LOOP(); )
{
/* ... */
xNextExpireTime = prvGetNextExpireTime( &xListWasEmpty );
/* ... */
prvProcessTimerOrBlockTask( xNextExpireTime, xListWasEmpty );
prvProcessReceivedCommands();
}for (; configCONTROL_INFINITE_LOOP();) { ... }
}portTASK_FUNCTION (prvTimerTask, pvParameters) { ... }
static void prvProcessTimerOrBlockTask( const TickType_t xNextExpireTime,
BaseType_t xListWasEmpty )
{
TickType_t xTimeNow;
BaseType_t xTimerListsWereSwitched;
vTaskSuspendAll();
{
/* ... */
xTimeNow = prvSampleTimeNow( &xTimerListsWereSwitched );
if( xTimerListsWereSwitched == pdFALSE )
{
if( ( xListWasEmpty == pdFALSE ) && ( xNextExpireTime <= xTimeNow ) )
{
( void ) xTaskResumeAll();
prvProcessExpiredTimer( xNextExpireTime, xTimeNow );
}if (( xListWasEmpty == pdFALSE ) && ( xNextExpireTime <= xTimeNow )) { ... }
else
{
/* ... */
if( xListWasEmpty != pdFALSE )
{
/* ... */
xListWasEmpty = listLIST_IS_EMPTY( pxOverflowTimerList );
}if (xListWasEmpty != pdFALSE) { ... }
vQueueWaitForMessageRestricted( xTimerQueue, ( xNextExpireTime - xTimeNow ), xListWasEmpty );
if( xTaskResumeAll() == pdFALSE )
{
/* ... */
taskYIELD_WITHIN_API();
}if (xTaskResumeAll() == pdFALSE) { ... }
else
{
mtCOVERAGE_TEST_MARKER();
}else { ... }
}else { ... }
}if (xTimerListsWereSwitched == pdFALSE) { ... }
else
{
( void ) xTaskResumeAll();
}else { ... }
...}
}prvProcessTimerOrBlockTask (const TickType_t xNextExpireTime, BaseType_t xListWasEmpty) { ... }
static TickType_t prvGetNextExpireTime( BaseType_t * const pxListWasEmpty )
{
TickType_t xNextExpireTime;
/* ... */
*pxListWasEmpty = listLIST_IS_EMPTY( pxCurrentTimerList );
if( *pxListWasEmpty == pdFALSE )
{
xNextExpireTime = listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxCurrentTimerList );
}if (*pxListWasEmpty == pdFALSE) { ... }
else
{
xNextExpireTime = ( TickType_t ) 0U;
}else { ... }
return xNextExpireTime;
}prvGetNextExpireTime (BaseType_t * const pxListWasEmpty) { ... }
static TickType_t prvSampleTimeNow( BaseType_t * const pxTimerListsWereSwitched )
{
TickType_t xTimeNow;
PRIVILEGED_DATA static TickType_t xLastTime = ( TickType_t ) 0U;
xTimeNow = xTaskGetTickCount();
if( xTimeNow < xLastTime )
{
prvSwitchTimerLists();
*pxTimerListsWereSwitched = pdTRUE;
}if (xTimeNow < xLastTime) { ... }
else
{
*pxTimerListsWereSwitched = pdFALSE;
}else { ... }
xLastTime = xTimeNow;
return xTimeNow;
}prvSampleTimeNow (BaseType_t * const pxTimerListsWereSwitched) { ... }
static BaseType_t prvInsertTimerInActiveList( Timer_t * const pxTimer,
const TickType_t xNextExpiryTime,
const TickType_t xTimeNow,
const TickType_t xCommandTime )
{
BaseType_t xProcessTimerNow = pdFALSE;
listSET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ), xNextExpiryTime );
listSET_LIST_ITEM_OWNER( &( pxTimer->xTimerListItem ), pxTimer );
if( xNextExpiryTime <= xTimeNow )
{
/* ... */
if( ( ( TickType_t ) ( xTimeNow - xCommandTime ) ) >= pxTimer->xTimerPeriodInTicks )
{
/* ... */
xProcessTimerNow = pdTRUE;
}if (( ( TickType_t ) ( xTimeNow - xCommandTime ) ) >= pxTimer->xTimerPeriodInTicks) { ... }
else
{
vListInsert( pxOverflowTimerList, &( pxTimer->xTimerListItem ) );
}else { ... }
}if (xNextExpiryTime <= xTimeNow) { ... }
else
{
if( ( xTimeNow < xCommandTime ) && ( xNextExpiryTime >= xCommandTime ) )
{
/* ... */
xProcessTimerNow = pdTRUE;
}if (( xTimeNow < xCommandTime ) && ( xNextExpiryTime >= xCommandTime )) { ... }
else
{
vListInsert( pxCurrentTimerList, &( pxTimer->xTimerListItem ) );
}else { ... }
}else { ... }
return xProcessTimerNow;
}prvInsertTimerInActiveList (Timer_t * const pxTimer, const TickType_t xNextExpiryTime, const TickType_t xTimeNow, const TickType_t xCommandTime) { ... }
static void prvProcessReceivedCommands( void )
{
DaemonTaskMessage_t xMessage = { 0 };
Timer_t * pxTimer;
BaseType_t xTimerListsWereSwitched;
TickType_t xTimeNow;
while( xQueueReceive( xTimerQueue, &xMessage, tmrNO_DELAY ) != pdFAIL )
{
#if ( INCLUDE_xTimerPendFunctionCall == 1 )
{
/* ... */
if( xMessage.xMessageID < ( BaseType_t ) 0 )
{
const CallbackParameters_t * const pxCallback = &( xMessage.u.xCallbackParameters );
/* ... */
configASSERT( pxCallback );
pxCallback->pxCallbackFunction( pxCallback->pvParameter1, pxCallback->ulParameter2 );
}if (xMessage.xMessageID < ( BaseType_t ) 0) { ... }
else
{
mtCOVERAGE_TEST_MARKER();
}else { ... }
...}/* ... */
#endif
/* ... */
if( xMessage.xMessageID >= ( BaseType_t ) 0 )
{
/* ... */
pxTimer = xMessage.u.xTimerParameters.pxTimer;
if( listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) ) == pdFALSE )
{
( void ) uxListRemove( &( pxTimer->xTimerListItem ) );
}if (listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) ) == pdFALSE) { ... }
else
{
mtCOVERAGE_TEST_MARKER();
}else { ... }
traceTIMER_COMMAND_RECEIVED( pxTimer, xMessage.xMessageID, xMessage.u.xTimerParameters.xMessageValue );
/* ... */
xTimeNow = prvSampleTimeNow( &xTimerListsWereSwitched );
switch( xMessage.xMessageID )
{
case tmrCOMMAND_START:
case tmrCOMMAND_START_FROM_ISR:
case tmrCOMMAND_RESET:
case tmrCOMMAND_RESET_FROM_ISR:
pxTimer->ucStatus |= ( uint8_t ) tmrSTATUS_IS_ACTIVE;
if( prvInsertTimerInActiveList( pxTimer, xMessage.u.xTimerParameters.xMessageValue + pxTimer->xTimerPeriodInTicks, xTimeNow, xMessage.u.xTimerParameters.xMessageValue ) != pdFALSE )
{
/* ... */
if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) != 0U )
{
prvReloadTimer( pxTimer, xMessage.u.xTimerParameters.xMessageValue + pxTimer->xTimerPeriodInTicks, xTimeNow );
}if (( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) != 0U) { ... }
else
{
pxTimer->ucStatus &= ( ( uint8_t ) ~tmrSTATUS_IS_ACTIVE );
}else { ... }
traceTIMER_EXPIRED( pxTimer );
pxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer );
}if (prvInsertTimerInActiveList( pxTimer, xMessage.u.xTimerParameters.xMessageValue + pxTimer->xTimerPeriodInTicks, xTimeNow, xMessage.u.xTimerParameters.xMessageValue ) != pdFALSE) { ... }
else
{
mtCOVERAGE_TEST_MARKER();
}else { ... }
break;
case tmrCOMMAND_RESET_FROM_ISR:
case tmrCOMMAND_STOP:
case tmrCOMMAND_STOP_FROM_ISR:
pxTimer->ucStatus &= ( ( uint8_t ) ~tmrSTATUS_IS_ACTIVE );
break;
case tmrCOMMAND_STOP_FROM_ISR:
case tmrCOMMAND_CHANGE_PERIOD:
case tmrCOMMAND_CHANGE_PERIOD_FROM_ISR:
pxTimer->ucStatus |= ( uint8_t ) tmrSTATUS_IS_ACTIVE;
pxTimer->xTimerPeriodInTicks = xMessage.u.xTimerParameters.xMessageValue;
configASSERT( ( pxTimer->xTimerPeriodInTicks > 0 ) );
/* ... */
( void ) prvInsertTimerInActiveList( pxTimer, ( xTimeNow + pxTimer->xTimerPeriodInTicks ), xTimeNow, xTimeNow );
break;
case tmrCOMMAND_CHANGE_PERIOD_FROM_ISR:
case tmrCOMMAND_DELETE:
#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
{
/* ... */
if( ( pxTimer->ucStatus & tmrSTATUS_IS_STATICALLY_ALLOCATED ) == ( uint8_t ) 0 )
{
vPortFree( pxTimer );
}if (( pxTimer->ucStatus & tmrSTATUS_IS_STATICALLY_ALLOCATED ) == ( uint8_t ) 0) { ... }
else
{
pxTimer->ucStatus &= ( ( uint8_t ) ~tmrSTATUS_IS_ACTIVE );
}else { ... }
...}/* ... */
#else
{
/* ... */
pxTimer->ucStatus &= ( ( uint8_t ) ~tmrSTATUS_IS_ACTIVE );
...}/* ... */
#endif
break;
case tmrCOMMAND_DELETE:
default:
break;default
}switch (xMessage.xMessageID) { ... }
}if (xMessage.xMessageID >= ( BaseType_t ) 0) { ... }
}while (xQueueReceive( xTimerQueue, &xMessage, tmrNO_DELAY ) != pdFAIL) { ... }
}prvProcessReceivedCommands (void) { ... }
static void prvSwitchTimerLists( void )
{
TickType_t xNextExpireTime;
List_t * pxTemp;
/* ... */
while( listLIST_IS_EMPTY( pxCurrentTimerList ) == pdFALSE )
{
xNextExpireTime = listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxCurrentTimerList );
/* ... */
prvProcessExpiredTimer( xNextExpireTime, tmrMAX_TIME_BEFORE_OVERFLOW );
}while (listLIST_IS_EMPTY( pxCurrentTimerList ) == pdFALSE) { ... }
pxTemp = pxCurrentTimerList;
pxCurrentTimerList = pxOverflowTimerList;
pxOverflowTimerList = pxTemp;
}prvSwitchTimerLists (void) { ... }
static void prvCheckForValidListAndQueue( void )
{
/* ... */
taskENTER_CRITICAL();
{
if( xTimerQueue == NULL )
{
vListInitialise( &xActiveTimerList1 );
vListInitialise( &xActiveTimerList2 );
pxCurrentTimerList = &xActiveTimerList1;
pxOverflowTimerList = &xActiveTimerList2;
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
{
/* ... */
PRIVILEGED_DATA static StaticQueue_t xStaticTimerQueue;
PRIVILEGED_DATA static uint8_t ucStaticTimerQueueStorage[ ( size_t ) configTIMER_QUEUE_LENGTH * sizeof( DaemonTaskMessage_t ) ];
xTimerQueue = xQueueCreateStatic( ( UBaseType_t ) configTIMER_QUEUE_LENGTH, ( UBaseType_t ) sizeof( DaemonTaskMessage_t ), &( ucStaticTimerQueueStorage[ 0 ] ), &xStaticTimerQueue );
...}/* ... */
#else
{
xTimerQueue = xQueueCreate( ( UBaseType_t ) configTIMER_QUEUE_LENGTH, ( UBaseType_t ) sizeof( DaemonTaskMessage_t ) );
...}/* ... */
#endif
#if ( configQUEUE_REGISTRY_SIZE > 0 )
{
if( xTimerQueue != NULL )
{
vQueueAddToRegistry( xTimerQueue, "TmrQ" );
}if (xTimerQueue != NULL) { ... }
else
{
mtCOVERAGE_TEST_MARKER();
}else { ... }
...}/* ... */
#endif
}if (xTimerQueue == NULL) { ... }
else
{
mtCOVERAGE_TEST_MARKER();
}else { ... }
...}
taskEXIT_CRITICAL();
}prvCheckForValidListAndQueue (void) { ... }
BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer )
{
BaseType_t xReturn;
Timer_t * pxTimer = xTimer;
traceENTER_xTimerIsTimerActive( xTimer );
configASSERT( xTimer );
taskENTER_CRITICAL();
{
if( ( pxTimer->ucStatus & tmrSTATUS_IS_ACTIVE ) == 0U )
{
xReturn = pdFALSE;
}if (( pxTimer->ucStatus & tmrSTATUS_IS_ACTIVE ) == 0U) { ... }
else
{
xReturn = pdTRUE;
}else { ... }
...}
taskEXIT_CRITICAL();
traceRETURN_xTimerIsTimerActive( xReturn );
return xReturn;
}xTimerIsTimerActive (TimerHandle_t xTimer) { ... }
void * pvTimerGetTimerID( const TimerHandle_t xTimer )
{
Timer_t * const pxTimer = xTimer;
void * pvReturn;
traceENTER_pvTimerGetTimerID( xTimer );
configASSERT( xTimer );
taskENTER_CRITICAL();
{
pvReturn = pxTimer->pvTimerID;
...}
taskEXIT_CRITICAL();
traceRETURN_pvTimerGetTimerID( pvReturn );
return pvReturn;
}pvTimerGetTimerID (const TimerHandle_t xTimer) { ... }
void vTimerSetTimerID( TimerHandle_t xTimer,
void * pvNewID )
{
Timer_t * const pxTimer = xTimer;
traceENTER_vTimerSetTimerID( xTimer, pvNewID );
configASSERT( xTimer );
taskENTER_CRITICAL();
{
pxTimer->pvTimerID = pvNewID;
...}
taskEXIT_CRITICAL();
traceRETURN_vTimerSetTimerID();
}vTimerSetTimerID (TimerHandle_t xTimer, void * pvNewID) { ... }
#if ( INCLUDE_xTimerPendFunctionCall == 1 )
BaseType_t xTimerPendFunctionCallFromISR( PendedFunction_t xFunctionToPend,
void * pvParameter1,
uint32_t ulParameter2,
BaseType_t * pxHigherPriorityTaskWoken )
{
DaemonTaskMessage_t xMessage;
BaseType_t xReturn;
traceENTER_xTimerPendFunctionCallFromISR( xFunctionToPend, pvParameter1, ulParameter2, pxHigherPriorityTaskWoken );
/* ... */
xMessage.xMessageID = tmrCOMMAND_EXECUTE_CALLBACK_FROM_ISR;
xMessage.u.xCallbackParameters.pxCallbackFunction = xFunctionToPend;
xMessage.u.xCallbackParameters.pvParameter1 = pvParameter1;
xMessage.u.xCallbackParameters.ulParameter2 = ulParameter2;
xReturn = xQueueSendFromISR( xTimerQueue, &xMessage, pxHigherPriorityTaskWoken );
tracePEND_FUNC_CALL_FROM_ISR( xFunctionToPend, pvParameter1, ulParameter2, xReturn );
traceRETURN_xTimerPendFunctionCallFromISR( xReturn );
return xReturn;
}xTimerPendFunctionCallFromISR (PendedFunction_t xFunctionToPend, void * pvParameter1, uint32_t ulParameter2, BaseType_t * pxHigherPriorityTaskWoken) { ... }
/* ... */
#endif
#if ( INCLUDE_xTimerPendFunctionCall == 1 )
BaseType_t xTimerPendFunctionCall( PendedFunction_t xFunctionToPend,
void * pvParameter1,
uint32_t ulParameter2,
TickType_t xTicksToWait )
{
DaemonTaskMessage_t xMessage;
BaseType_t xReturn;
traceENTER_xTimerPendFunctionCall( xFunctionToPend, pvParameter1, ulParameter2, xTicksToWait );
/* ... */
configASSERT( xTimerQueue );
/* ... */
xMessage.xMessageID = tmrCOMMAND_EXECUTE_CALLBACK;
xMessage.u.xCallbackParameters.pxCallbackFunction = xFunctionToPend;
xMessage.u.xCallbackParameters.pvParameter1 = pvParameter1;
xMessage.u.xCallbackParameters.ulParameter2 = ulParameter2;
xReturn = xQueueSendToBack( xTimerQueue, &xMessage, xTicksToWait );
tracePEND_FUNC_CALL( xFunctionToPend, pvParameter1, ulParameter2, xReturn );
traceRETURN_xTimerPendFunctionCall( xReturn );
return xReturn;
}xTimerPendFunctionCall (PendedFunction_t xFunctionToPend, void * pvParameter1, uint32_t ulParameter2, TickType_t xTicksToWait) { ... }
/* ... */
#endif
#if ( configUSE_TRACE_FACILITY == 1 )
UBaseType_t uxTimerGetTimerNumber( TimerHandle_t xTimer )
{
traceENTER_uxTimerGetTimerNumber( xTimer );
traceRETURN_uxTimerGetTimerNumber( ( ( Timer_t * ) xTimer )->uxTimerNumber );
return ( ( Timer_t * ) xTimer )->uxTimerNumber;
}uxTimerGetTimerNumber (TimerHandle_t xTimer) { ... }
/* ... */
#endif
#if ( configUSE_TRACE_FACILITY == 1 )
void vTimerSetTimerNumber( TimerHandle_t xTimer,
UBaseType_t uxTimerNumber )
{
traceENTER_vTimerSetTimerNumber( xTimer, uxTimerNumber );
( ( Timer_t * ) xTimer )->uxTimerNumber = uxTimerNumber;
traceRETURN_vTimerSetTimerNumber();
}vTimerSetTimerNumber (TimerHandle_t xTimer, UBaseType_t uxTimerNumber) { ... }
/* ... */
#endif
/* ... */
void vTimerResetState( void )
{
xTimerQueue = NULL;
xTimerTaskHandle = NULL;
}vTimerResetState (void) { ... }
/* ... */
/* ... */#endif