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
34
35
36
37
38
39
40
41
42
43
44
45
49
50
51
52
56
57
58
59
60
61
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
88
89
90
95
96
100
101
102
103
108
109
111
112
113
114
115
116
117
118
120
121
122
123
124
125
126
128
129
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
156
157
158
162
163
164
169
170
171
175
176
177
181
182
183
187
188
189
193
194
195
199
200
201
207
208
209
213
214
215
219
220
221
222
223
224
225
226
227
228
229
230
231
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
258
259
260
261
262
263
264
265
266
267
268
269
270
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
327
328
329
330
331
332
333
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
363
364
365
367
368
369
370
371
372
376
377
378
379
380
381
382
383
384
385
386
387
388
390
391
392
393
394
395
396
397
408
412
413
414
415
419
420
421
422
423
424
431
432
433
440
441
442
443
444
445
446
447
448
458
459
460
461
462
463
464
465
466
467
468
469
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
505
506
507
508
509
510
511
512
514
515
516
517
519
537
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
566
567
568
569
570
572
573
574
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
596
597
598
599
600
605
606
607
613
619
620
621
622
630
634
635
636
640
641
642
643
644
645
646
647
648
655
656
660
665
666
667
668
669
670
671
672
673
674
675
676
677
682
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
715
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
747
748
749
750
751
753
754
755
756
757
758
762
763
764
765
767
768
769
771
772
773
774
778
782
783
784
785
791
792
793
794
795
796
797
798
799
800
801
802
803
804
806
807
808
809
815
819
820
824
825
826
827
832
833
834
835
836
837
838
844
845
846
847
848
849
862
863
870
871
872
873
876
877
878
879
880
881
882
883
884
885
886
887
888
889
893
894
895
896
897
898
899
900
901
902
905
906
907
929
933
934
935
936
937
938
939
940
941
942
943
946
947
948
949
950
951
952
953
954
955
956
964
965
968
969
970
971
981
982
983
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1082
1083
1084
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1108
1109
1110
1111
1112
1118
1119
1120
1121
1124
1125
1126
1127
/* ... */
#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
/* ... */
#ifndef configTIMER_SERVICE_TASK_NAME
#define configTIMER_SERVICE_TASK_NAME "Tmr Svc"
#endif
#define tmrSTATUS_IS_ACTIVE ( ( uint8_t ) 0x01 )
#define tmrSTATUS_IS_STATICALLY_ALLOCATED ( ( uint8_t ) 0x02 )
#define tmrSTATUS_IS_AUTORELOAD ( ( uint8_t ) 0x04 )
typedef struct tmrTimerControl
{
const char *pcTimerName;
ListItem_t xTimerListItem;
TickType_t xTimerPeriodInTicks;
void *pvTimerID;
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
{
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;
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
/* ... */
extern void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize );
/* ... */
#endif
/* ... */
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 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 UBaseType_t uxAutoReload,
void * const pvTimerID,
TimerCallbackFunction_t pxCallbackFunction,
Timer_t *pxNewTimer ) PRIVILEGED_FUNCTION;
BaseType_t xTimerCreateTimerTask( void )
{
BaseType_t xReturn = pdFAIL;
/* ... */
prvCheckForValidListAndQueue();
if( xTimerQueue != NULL )
{
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
{
StaticTask_t *pxTimerTaskTCBBuffer = NULL;
StackType_t *pxTimerTaskStackBuffer = NULL;
uint32_t ulTimerTaskStackSize;
vApplicationGetTimerTaskMemory( &pxTimerTaskTCBBuffer, &pxTimerTaskStackBuffer, &ulTimerTaskStackSize );
xTimerTaskHandle = xTaskCreateStatic( prvTimerTask,
configTIMER_SERVICE_TASK_NAME,
ulTimerTaskStackSize,
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
}if (xTimerQueue != NULL) { ... }
else
{
mtCOVERAGE_TEST_MARKER();
}else { ... }
configASSERT( xReturn );
return xReturn;
}xTimerCreateTimerTask (void) { ... }
#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
TimerHandle_t xTimerCreate( const char * const pcTimerName,
const TickType_t xTimerPeriodInTicks,
const UBaseType_t uxAutoReload,
void * const pvTimerID,
TimerCallbackFunction_t pxCallbackFunction )
{
Timer_t *pxNewTimer;
pxNewTimer = ( Timer_t * ) pvPortMalloc( sizeof( Timer_t ) );
if( pxNewTimer != NULL )
{
/* ... */
pxNewTimer->ucStatus = 0x00;
prvInitialiseNewTimer( pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, pxCallbackFunction, pxNewTimer );
}if (pxNewTimer != NULL) { ... }
return pxNewTimer;
}xTimerCreate (const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ const TickType_t xTimerPeriodInTicks, const UBaseType_t uxAutoReload, void * const pvTimerID, TimerCallbackFunction_t pxCallbackFunction) { ... }
/* ... */
#endif
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
TimerHandle_t xTimerCreateStatic( const char * const pcTimerName,
const TickType_t xTimerPeriodInTicks,
const UBaseType_t uxAutoReload,
void * const pvTimerID,
TimerCallbackFunction_t pxCallbackFunction,
StaticTimer_t *pxTimerBuffer )
{
Timer_t *pxNewTimer;
#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 = tmrSTATUS_IS_STATICALLY_ALLOCATED;
prvInitialiseNewTimer( pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, pxCallbackFunction, pxNewTimer );
}if (pxNewTimer != NULL) { ... }
return pxNewTimer;
}xTimerCreateStatic (const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ const TickType_t xTimerPeriodInTicks, const UBaseType_t uxAutoReload, void * const pvTimerID, TimerCallbackFunction_t pxCallbackFunction, StaticTimer_t *pxTimerBuffer) { ... }
/* ... */
#endif
static void prvInitialiseNewTimer( const char * const pcTimerName,
const TickType_t xTimerPeriodInTicks,
const UBaseType_t uxAutoReload,
void * const pvTimerID,
TimerCallbackFunction_t pxCallbackFunction,
Timer_t *pxNewTimer )
{
configASSERT( ( xTimerPeriodInTicks > 0 ) );
if( pxNewTimer != NULL )
{
/* ... */
prvCheckForValidListAndQueue();
/* ... */
pxNewTimer->pcTimerName = pcTimerName;
pxNewTimer->xTimerPeriodInTicks = xTimerPeriodInTicks;
pxNewTimer->pvTimerID = pvTimerID;
pxNewTimer->pxCallbackFunction = pxCallbackFunction;
vListInitialiseItem( &( pxNewTimer->xTimerListItem ) );
if( uxAutoReload != pdFALSE )
{
pxNewTimer->ucStatus |= tmrSTATUS_IS_AUTORELOAD;
}if (uxAutoReload != pdFALSE) { ... }
traceTIMER_CREATE( pxNewTimer );
}if (pxNewTimer != NULL) { ... }
}prvInitialiseNewTimer (const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ const TickType_t xTimerPeriodInTicks, const UBaseType_t uxAutoReload, void * const pvTimerID, TimerCallbackFunction_t pxCallbackFunction, Timer_t *pxNewTimer) { ... }
BaseType_t xTimerGenericCommand( 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;
configASSERT( xTimer );
/* ... */
if( xTimerQueue != NULL )
{
xMessage.xMessageID = xCommandID;
xMessage.u.xTimerParameters.xMessageValue = xOptionalValue;
xMessage.u.xTimerParameters.pxTimer = xTimer;
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) { ... }
else
{
xReturn = xQueueSendToBackFromISR( xTimerQueue, &xMessage, pxHigherPriorityTaskWoken );
}else { ... }
traceTIMER_COMMAND_SEND( xTimer, xCommandID, xOptionalValue, xReturn );
}if (xTimerQueue != NULL) { ... }
else
{
mtCOVERAGE_TEST_MARKER();
}else { ... }
return xReturn;
}xTimerGenericCommand (TimerHandle_t xTimer, const BaseType_t xCommandID, const TickType_t xOptionalValue, BaseType_t * const pxHigherPriorityTaskWoken, const TickType_t xTicksToWait) { ... }
TaskHandle_t xTimerGetTimerDaemonTaskHandle( void )
{
/* ... */
configASSERT( ( xTimerTaskHandle != NULL ) );
return xTimerTaskHandle;
}xTimerGetTimerDaemonTaskHandle (void) { ... }
TickType_t xTimerGetPeriod( TimerHandle_t xTimer )
{
Timer_t *pxTimer = xTimer;
configASSERT( xTimer );
return pxTimer->xTimerPeriodInTicks;
}xTimerGetPeriod (TimerHandle_t xTimer) { ... }
void vTimerSetReloadMode( TimerHandle_t xTimer, const UBaseType_t uxAutoReload )
{
Timer_t * pxTimer = xTimer;
configASSERT( xTimer );
taskENTER_CRITICAL();
{
if( uxAutoReload != pdFALSE )
{
pxTimer->ucStatus |= tmrSTATUS_IS_AUTORELOAD;
}if (uxAutoReload != pdFALSE) { ... }
else
{
pxTimer->ucStatus &= ~tmrSTATUS_IS_AUTORELOAD;
}else { ... }
...}
taskEXIT_CRITICAL();
}vTimerSetReloadMode (TimerHandle_t xTimer, const UBaseType_t uxAutoReload) { ... }
UBaseType_t uxTimerGetReloadMode( TimerHandle_t xTimer )
{
Timer_t * pxTimer = xTimer;
UBaseType_t uxReturn;
configASSERT( xTimer );
taskENTER_CRITICAL();
{
if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) == 0 )
{
uxReturn = ( UBaseType_t ) pdFALSE;
}if (( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) == 0) { ... }
else
{
uxReturn = ( UBaseType_t ) pdTRUE;
}else { ... }
...}
taskEXIT_CRITICAL();
return uxReturn;
}uxTimerGetReloadMode (TimerHandle_t xTimer) { ... }
TickType_t xTimerGetExpiryTime( TimerHandle_t xTimer )
{
Timer_t * pxTimer = xTimer;
TickType_t xReturn;
configASSERT( xTimer );
xReturn = listGET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ) );
return xReturn;
}xTimerGetExpiryTime (TimerHandle_t xTimer) { ... }
const char * pcTimerGetName( TimerHandle_t xTimer )
{
Timer_t *pxTimer = xTimer;
configASSERT( xTimer );
return pxTimer->pcTimerName;
...}
static void prvProcessExpiredTimer( const TickType_t xNextExpireTime, const TickType_t xTimeNow )
{
BaseType_t xResult;
Timer_t * const pxTimer = ( Timer_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList );
/* ... */
( void ) uxListRemove( &( pxTimer->xTimerListItem ) );
traceTIMER_EXPIRED( pxTimer );
/* ... */
if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) != 0 )
{
/* ... */
if( prvInsertTimerInActiveList( pxTimer, ( xNextExpireTime + pxTimer->xTimerPeriodInTicks ), xTimeNow, xNextExpireTime ) != pdFALSE )
{
/* ... */
xResult = xTimerGenericCommand( pxTimer, tmrCOMMAND_START_DONT_TRACE, xNextExpireTime, NULL, tmrNO_DELAY );
configASSERT( xResult );
( void ) xResult;
}if (prvInsertTimerInActiveList( pxTimer, ( xNextExpireTime + pxTimer->xTimerPeriodInTicks ), xTimeNow, xNextExpireTime ) != pdFALSE) { ... }
else
{
mtCOVERAGE_TEST_MARKER();
}else { ... }
}if (( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) != 0) { ... }
else
{
pxTimer->ucStatus &= ~tmrSTATUS_IS_ACTIVE;
mtCOVERAGE_TEST_MARKER();
}else { ... }
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 )
{
extern void vApplicationDaemonTaskStartupHook( void );
/* ... */
vApplicationDaemonTaskStartupHook();
...}/* ... */
#endif
for( ;; )
{
/* ... */
xNextExpireTime = prvGetNextExpireTime( &xListWasEmpty );
/* ... */
prvProcessTimerOrBlockTask( xNextExpireTime, xListWasEmpty );
prvProcessReceivedCommands();
}for (;;) { ... }
}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 )
{
/* ... */
portYIELD_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;
...}
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;
Timer_t *pxTimer;
BaseType_t xTimerListsWereSwitched, xResult;
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 ) );
...}
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 :
case tmrCOMMAND_START_DONT_TRACE :
pxTimer->ucStatus |= tmrSTATUS_IS_ACTIVE;
if( prvInsertTimerInActiveList( pxTimer, xMessage.u.xTimerParameters.xMessageValue + pxTimer->xTimerPeriodInTicks, xTimeNow, xMessage.u.xTimerParameters.xMessageValue ) != pdFALSE )
{
/* ... */
pxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer );
traceTIMER_EXPIRED( pxTimer );
if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) != 0 )
{
xResult = xTimerGenericCommand( pxTimer, tmrCOMMAND_START_DONT_TRACE, xMessage.u.xTimerParameters.xMessageValue + pxTimer->xTimerPeriodInTicks, NULL, tmrNO_DELAY );
configASSERT( xResult );
( void ) xResult;
}if (( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) != 0) { ... }
else
{
mtCOVERAGE_TEST_MARKER();
}else { ... }
}if (prvInsertTimerInActiveList( pxTimer, xMessage.u.xTimerParameters.xMessageValue + pxTimer->xTimerPeriodInTicks, xTimeNow, xMessage.u.xTimerParameters.xMessageValue ) != pdFALSE) { ... }
else
{
mtCOVERAGE_TEST_MARKER();
}else { ... }
break;
case tmrCOMMAND_START_DONT_TRACE :
case tmrCOMMAND_STOP :
case tmrCOMMAND_STOP_FROM_ISR :
pxTimer->ucStatus &= ~tmrSTATUS_IS_ACTIVE;
break;
case tmrCOMMAND_STOP_FROM_ISR :
case tmrCOMMAND_CHANGE_PERIOD :
case tmrCOMMAND_CHANGE_PERIOD_FROM_ISR :
pxTimer->ucStatus |= 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 &= ~tmrSTATUS_IS_ACTIVE;
}else { ... }
...}/* ... */
#else
{
/* ... */
pxTimer->ucStatus &= ~tmrSTATUS_IS_ACTIVE;
...}/* ... */
#endif
break;
case tmrCOMMAND_DELETE :
default :
break;default
}switch (xMessage.xMessageID) { ... }
}if (xMessage.xMessageID >= ( BaseType_t ) 0) { ... }
...}
}prvProcessReceivedCommands (void) { ... }
static void prvSwitchTimerLists( void )
{
TickType_t xNextExpireTime, xReloadTime;
List_t *pxTemp;
Timer_t *pxTimer;
BaseType_t xResult;
/* ... */
while( listLIST_IS_EMPTY( pxCurrentTimerList ) == pdFALSE )
{
xNextExpireTime = listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxCurrentTimerList );
pxTimer = ( Timer_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList );
( void ) uxListRemove( &( pxTimer->xTimerListItem ) );
traceTIMER_EXPIRED( pxTimer );
/* ... */
pxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer );
if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) != 0 )
{
/* ... */
xReloadTime = ( xNextExpireTime + pxTimer->xTimerPeriodInTicks );
if( xReloadTime > xNextExpireTime )
{
listSET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ), xReloadTime );
listSET_LIST_ITEM_OWNER( &( pxTimer->xTimerListItem ), pxTimer );
vListInsert( pxCurrentTimerList, &( pxTimer->xTimerListItem ) );
}if (xReloadTime > xNextExpireTime) { ... }
else
{
xResult = xTimerGenericCommand( pxTimer, tmrCOMMAND_START_DONT_TRACE, xNextExpireTime, NULL, tmrNO_DELAY );
configASSERT( xResult );
( void ) xResult;
}else { ... }
}if (( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) != 0) { ... }
else
{
mtCOVERAGE_TEST_MARKER();
}else { ... }
}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 )
{
/* ... */
static StaticQueue_t xStaticTimerQueue;
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, 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;
configASSERT( xTimer );
taskENTER_CRITICAL();
{
if( ( pxTimer->ucStatus & tmrSTATUS_IS_ACTIVE ) == 0 )
{
xReturn = pdFALSE;
}if (( pxTimer->ucStatus & tmrSTATUS_IS_ACTIVE ) == 0) { ... }
else
{
xReturn = pdTRUE;
}else { ... }
...}
taskEXIT_CRITICAL();
return xReturn;
}xTimerIsTimerActive (TimerHandle_t xTimer) { ... }
void *pvTimerGetTimerID( const TimerHandle_t xTimer )
{
Timer_t * const pxTimer = xTimer;
void *pvReturn;
configASSERT( xTimer );
taskENTER_CRITICAL();
{
pvReturn = pxTimer->pvTimerID;
...}
taskEXIT_CRITICAL();
return pvReturn;
}pvTimerGetTimerID (const TimerHandle_t xTimer) { ... }
void vTimerSetTimerID( TimerHandle_t xTimer, void *pvNewID )
{
Timer_t * const pxTimer = xTimer;
configASSERT( xTimer );
taskENTER_CRITICAL();
{
pxTimer->pvTimerID = pvNewID;
...}
taskEXIT_CRITICAL();
}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;
/* ... */
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 );
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;
/* ... */
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 );
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 )
{
return ( ( Timer_t * ) xTimer )->uxTimerNumber;
}uxTimerGetTimerNumber (TimerHandle_t xTimer) { ... }
/* ... */
#endif
#if ( configUSE_TRACE_FACILITY == 1 )
void vTimerSetTimerNumber( TimerHandle_t xTimer, UBaseType_t uxTimerNumber )
{
( ( Timer_t * ) xTimer )->uxTimerNumber = uxTimerNumber;
}vTimerSetTimerNumber (TimerHandle_t xTimer, UBaseType_t uxTimerNumber) { ... }
/* ... */
#endif
/* ... */
/* ... */#endif