-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscheduler.c
1567 lines (1355 loc) · 54.2 KB
/
scheduler.c
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
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
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
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
674
675
676
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
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
ESFree V1.0 - Copyright (C) 2016 Robin Kase
All rights reserved
This file is part of ESFree.
ESFree is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public licence (version 2) as published by the
Free Software Foundation AND MODIFIED BY one exception.
***************************************************************************
>>! NOTE: The modification to the GPL is included to allow you to !<<
>>! distribute a combined work that includes ESFree without being !<<
>>! obliged to provide the source code for proprietary components !<<
>>! outside of ESFree. !<<
***************************************************************************
ESFree is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. Full license text can be found on license.txt.
*/
#include "scheduler.h"
#if( schedSCHEDULING_POLICY == schedSCHEDULING_POLICY_EDF )
#include "list.h"
#endif /* schedSCHEDULING_POLICY_EDF */
#define schedTHREAD_LOCAL_STORAGE_POINTER_INDEX 0
#if( schedSCHEDULING_POLICY == schedSCHEDULING_POLICY_EDF )
#define schedUSE_TCB_SORTED_LIST 1
#if( schedEDF_EFFICIENT == 1 )
#define schedPRIORITY_RUNNING ( schedSCHEDULER_PRIORITY - 1 )
#define schedPRIORITY_NOT_RUNNING 0
#endif /* schedEDF_EFFICIENT */
#else
#define schedUSE_TCB_ARRAY 1
#endif /* schedSCHEDULING_POLICY_EDF */
/* Extended Task control block for managing periodic tasks within this library. */
typedef struct xExtended_TCB
{
TaskFunction_t pvTaskCode; /* Function pointer to the code that will be run periodically. */
const char *pcName; /* Name of the task. */
UBaseType_t uxStackDepth; /* Stack size of the task. */
void *pvParameters; /* Parameters to the task function. */
UBaseType_t uxPriority; /* Priority of the task. */
TaskHandle_t *pxTaskHandle; /* Task handle for the task. */
TickType_t xReleaseTime; /* Release time of the task. */
TickType_t xRelativeDeadline; /* Relative deadline of the task. */
TickType_t xAbsoluteDeadline; /* Absolute deadline of the task. */
TickType_t xPeriod; /* Task period. */
TickType_t xLastWakeTime; /* Last time stamp when the task was running. */
TickType_t xMaxExecTime; /* Worst-case execution time of the task. */
TickType_t xExecTime; /* Current execution time of the task. */
BaseType_t xWorkIsDone; /* pdFALSE if the job is not finished, pdTRUE if the job is finished. */
#if( schedUSE_TCB_ARRAY == 1 )
BaseType_t xPriorityIsSet; /* pdTRUE if the priority is assigned. */
BaseType_t xInUse; /* pdFALSE if this extended TCB is empty. */
#elif( schedUSE_TCB_SORTED_LIST == 1 )
ListItem_t xTCBListItem; /* Used to reference TCB from the TCB list. */
#if( schedEDF_EFFICIENT == 1 )
ListItem_t xTCBAllListItem; /* Extra list item for xTCBAllList. */
#endif /* schedEDF_EFFICIENT */
#endif /* schedUSE_TCB_SORTED_LIST */
#if( schedUSE_TIMING_ERROR_DETECTION_DEADLINE == 1 )
BaseType_t xExecutedOnce; /* pdTRUE if the task has executed once. */
#endif /* schedUSE_TIMING_ERROR_DETECTION_DEADLINE */
#if( schedUSE_TIMING_ERROR_DETECTION_EXECUTION_TIME == 1 || schedUSE_TIMING_ERROR_DETECTION_DEADLINE == 1 )
TickType_t xAbsoluteUnblockTime; /* The task will be unblocked at this time if it is blocked by the scheduler task. */
#endif /* schedUSE_TIMING_ERROR_DETECTION_EXECUTION_TIME || schedUSE_TIMING_ERROR_DETECTION_DEADLINE */
#if( schedUSE_TIMING_ERROR_DETECTION_EXECUTION_TIME == 1 )
BaseType_t xSuspended; /* pdTRUE if the task is suspended. */
BaseType_t xMaxExecTimeExceeded; /* pdTRUE when execTime exceeds maxExecTime. */
#endif /* schedUSE_TIMING_ERROR_DETECTION_EXECUTION_TIME */
#if( schedUSE_POLLING_SERVER == 1 )
BaseType_t xIsPeriodicServer; /* pdTRUE if the task is a polling server. */
#endif /* schedUSE_POLLING_SERVER */
} SchedTCB_t;
#if( schedUSE_APERIODIC_JOBS == 1 )
/* Control block for managing Aperiodic jobs. */
typedef struct xAperiodicJobControlBlock
{
TaskFunction_t pvTaskCode; /* Function pointer to the code of the aperiodic job. */
const char *pcName; /* Name of the aperiodic job. */
void *pvParameters; /* Parameters to the job function. */
TickType_t xMaxExecTime; /* Worst-case execution time of the aperiodic job. */
TickType_t xExecTime; /* Current execution time of the aperiodic job. */
} AJCB_t;
#endif /* schedUSE_APERIODIC_JOBS */
#if( schedUSE_SPORADIC_JOBS == 1 )
/* Control block for managing sporadic jobs. */
typedef struct xSporadicJobControlBlock
{
TaskFunction_t pvTaskCode; /* Function pointer to the code of the sporadic job. */
const char *pcName; /* Name of the job. */
void *pvParameters; /* Pararmeters to the job function. */
TickType_t xRelativeDeadline; /* Relative deadline of the sporadic job. */
TickType_t xMaxExecTime; /* Worst-case execution time of the sporadic job. */
TickType_t xExecTime; /* Current execution time of the sporadic job. */
#if( schedUSE_TIMING_ERROR_DETECTION_DEADLINE == 1 )
TickType_t xAbsoluteDeadline; /* Absolute deadline of the sporadic job. */
#endif /* schedUSE_TIMING_ERROR_DETECTION_DEADLINE */
} SJCB_t;
#endif /* schedUSE_SPORADIC_JOBS */
#if( schedUSE_TCB_ARRAY == 1 )
static BaseType_t prvGetTCBIndexFromHandle( TaskHandle_t xTaskHandle );
static void prvInitTCBArray( void );
/* Find index for an empty entry in xTCBArray. Return -1 if there is no empty entry. */
static BaseType_t prvFindEmptyElementIndexTCB( void );
/* Remove a pointer to extended TCB from xTCBArray. */
static void prvDeleteTCBFromArray( BaseType_t xIndex );
#elif( schedUSE_TCB_SORTED_LIST == 1 )
static void prvAddTCBToList( SchedTCB_t *pxTCB );
static void prvDeleteTCBFromList( SchedTCB_t *pxTCB );
#endif /* schedUSE_TCB_ARRAY */
static TickType_t xSystemStartTime = 0;
static void prvPeriodicTaskCode( void *pvParameters );
static void prvCreateAllTasks( void );
#if( schedSCHEDULING_POLICY == schedSCHEDULING_POLICY_RMS || schedSCHEDULING_POLICY == schedSCHEDULING_POLICY_DMS )
static void prvSetFixedPriorities( void );
#elif( schedSCHEDULING_POLICY == schedSCHEDULING_POLICY_EDF )
static void prvInitEDF( void );
#if( schedEDF_NAIVE == 1 )
static void prvUpdatePrioritiesEDF( void );
#elif( schedEDF_EFFICIENT == 1 )
static void prvInsertTCBToReadyList( SchedTCB_t *pxTCB );
#endif /* schedEDF_NAIVE */
#if( schedUSE_TCB_SORTED_LIST == 1 )
static void prvSwapList( List_t **ppxList1, List_t **ppxList2 );
#endif /* schedUSE_TCB_SORTED_LIST */
#endif /* schedSCHEDULING_POLICY_EDF */
#if( schedUSE_SCHEDULER_TASK == 1 )
static void prvSchedulerCheckTimingError( TickType_t xTickCount, SchedTCB_t *pxTCB );
static void prvSchedulerFunction( void );
static void prvCreateSchedulerTask( void );
static void prvWakeScheduler( void );
#if( schedUSE_TIMING_ERROR_DETECTION_DEADLINE == 1 )
static void prvPeriodicTaskRecreate( SchedTCB_t *pxTCB );
static void prvDeadlineMissedHook( SchedTCB_t *pxTCB, TickType_t xTickCount );
static void prvCheckDeadline( SchedTCB_t *pxTCB, TickType_t xTickCount );
#if( schedUSE_SPORADIC_JOBS == 1 )
static void prvDeadlineMissedHookSporadicJob( BaseType_t xIndex );
static void prvCheckSporadicJobDeadline( TickType_t xTickCount );
#endif /* schedUSE_SPORADIC_JOBS */
#endif /* schedUSE_TIMING_ERROR_DETECTION_DEADLINE */
#if( schedUSE_TIMING_ERROR_DETECTION_EXECUTION_TIME == 1 )
static void prvExecTimeExceedHook( TickType_t xTickCount, SchedTCB_t *pxCurrentTask );
#endif /* schedUSE_TIMING_ERROR_DETECTION_EXECUTION_TIME */
#endif /* schedUSE_SCHEDULER_TASK */
#if( schedUSE_POLLING_SERVER == 1 )
static void prvPollingServerFunction( void );
void prvPollingServerCreate( void );
#endif /* schedUSE_POLLING_SERVER */
#if( schedUSE_APERIODIC_JOBS == 1 )
static AJCB_t *prvGetNextAperiodicJob( void );
static BaseType_t prvFindEmptyElementIndexAJCB( void );
#endif /* schedUSE_APERIODIC_JOBS */
#if( schedUSE_SPORADIC_JOBS == 1 )
static SJCB_t *prvGetNextSporadicJob( void );
static BaseType_t prvFindEmptyElementIndexSJCB( void );
static BaseType_t prvAnalyzeSporadicJobSchedulability( SJCB_t *pxSporadicJob, TickType_t xTickCount );
#endif /* schedUSE_SPORADIC_JOBS */
#if( schedUSE_TCB_ARRAY == 1 )
/* Array for extended TCBs. */
static SchedTCB_t xTCBArray[ schedMAX_NUMBER_OF_PERIODIC_TASKS ] = { 0 };
/* Counter for number of periodic tasks. */
static BaseType_t xTaskCounter = 0;
#elif( schedUSE_TCB_SORTED_LIST == 1 )
#if( schedEDF_NAIVE == 1 )
static List_t xTCBList; /* Sorted linked list for all periodic tasks. */
static List_t xTCBTempList; /* A temporary list used for switching lists. */
static List_t xTCBOverflowedList; /* Sorted linked list for periodic tasks that have overflowed deadline. */
static List_t *pxTCBList = NULL; /* Pointer to xTCBList. */
static List_t *pxTCBTempList = NULL; /* Pointer to xTCBTempList. */
static List_t *pxTCBOverflowedList = NULL; /* Pointer to xTCBOverflowedList. */
#elif( schedEDF_EFFICIENT == 1 )
static List_t xTCBListAll; /* Sorted linked list for all periodic tasks. */
static List_t xTCBBlockedList; /* Linked list for blocked periodic tasks. */
static List_t xTCBReadyList; /* Sorted linked list for all ready periodic tasks. */
static List_t xTCBOverflowedReadyList; /* Sorted linked list for all ready periodic tasks with overflowed deadline. */
static List_t *pxTCBListAll; /* Pointer to xTCBListAll. */
static List_t *pxTCBBlockedList = NULL; /* Pointer to xTCBBlockedList. */
static List_t *pxTCBReadyList = NULL; /* Pointer to xTCBReadyList. */
static List_t *pxTCBOverflowedReadyList = NULL; /* Pointer to xTCBOverflowedReadyList. */
static SchedTCB_t *pxCurrentTCB = NULL; /* Pointer to current executing periodic task. */
static SchedTCB_t *pxPreviousTCB = NULL; /* Pointer to previous executing periodic task. */
static BaseType_t xSwitchToSchedulerOnSuspend = pdFALSE; /* pdTRUE if context switch to scheduler task occur since a task is suspended. */
static BaseType_t xSwitchToSchedulerOnBlock = pdFALSE; /* pdTRUE if context switch to scheduler task occur since a task is blocked. */
static BaseType_t xSwitchToSchedulerOnReady = pdFALSE; /* pdTRUE if context switch to scheduler task occur since a task becomes ready. */
#endif /* schedEDF_NAIVE */
#endif /* schedUSE_TCB_ARRAY */
#if( schedUSE_SCHEDULER_TASK )
static TickType_t xSchedulerWakeCounter = 0;
static TaskHandle_t xSchedulerHandle = NULL;
#endif /* schedUSE_SCHEDULER_TASK */
#if( schedUSE_APERIODIC_JOBS == 1 )
/* Array for extended AJCBs (Aperiodic Job Control Block). */
static AJCB_t xAJCBFifo[ schedMAX_NUMBER_OF_APERIODIC_JOBS ] = { 0 };
static BaseType_t xAJCBFifoHead = 0;
static BaseType_t xAJCBFifoTail = 0;
static UBaseType_t uxAperiodicJobCounter = 0;
#endif /* schedUSE_APERIODIC_JOBS */
#if( schedUSE_SPORADIC_JOBS == 1 )
/* Array for extended SJCBs (Sporadic Job Control Block). */
static SJCB_t xSJCBFifo[ schedMAX_NUMBER_OF_SPORADIC_JOBS ] = { 0 };
static BaseType_t xSJCBFifoHead = 0;
static BaseType_t xSJCBFifoTail = 0;
static UBaseType_t uxSporadicJobCounter = 0;
static TickType_t xAbsolutePreviousMaxResponseTime = 0;
#endif /* schedUSE_SPORADIC_JOBS */
#if( schedUSE_POLLING_SERVER == 1 )
static TaskHandle_t xPollingServerHandle = NULL;
#if( schedUSE_APERIODIC_JOBS == 1 )
static AJCB_t *pxCurrentAperiodicJob;
#endif /* schedUSE_APERIODIC_JOBS */
#if( schedUSE_SPORADIC_JOBS == 1 )
static SJCB_t *pxCurrentSporadicJob;
#endif /* schedUSE_SPORADIC_JOBS */
#endif /* schedUSE_POLLING_SERVER */
#if( schedUSE_TCB_ARRAY == 1 )
/* Returns index position in xTCBArray of TCB with same task handle as parameter. */
static BaseType_t prvGetTCBIndexFromHandle( TaskHandle_t xTaskHandle )
{
static BaseType_t xIndex = 0;
BaseType_t xIterator;
for( xIterator = 0; xIterator < schedMAX_NUMBER_OF_PERIODIC_TASKS; xIterator++ )
{
if( pdTRUE == xTCBArray[ xIndex ].xInUse && *xTCBArray[ xIndex ].pxTaskHandle == xTaskHandle )
{
return xIndex;
}
xIndex++;
if( schedMAX_NUMBER_OF_PERIODIC_TASKS == xIndex )
{
xIndex = 0;
}
}
return -1;
}
/* Initializes xTCBArray. */
static void prvInitTCBArray( void )
{
UBaseType_t uxIndex;
for( uxIndex = 0; uxIndex < schedMAX_NUMBER_OF_PERIODIC_TASKS; uxIndex++)
{
xTCBArray[ uxIndex ].xInUse = pdFALSE;
}
}
/* Find index for an empty entry in xTCBArray. Returns -1 if there is no empty entry. */
static BaseType_t prvFindEmptyElementIndexTCB( void )
{
BaseType_t xIndex;
for( xIndex = 0; xIndex < schedMAX_NUMBER_OF_PERIODIC_TASKS; xIndex++ )
{
if( pdFALSE == xTCBArray[ xIndex ].xInUse )
{
return xIndex;
}
}
return -1;
}
/* Remove a pointer to extended TCB from xTCBArray. */
static void prvDeleteTCBFromArray( BaseType_t xIndex )
{
configASSERT( xIndex >= 0 && xIndex < schedMAX_NUMBER_OF_PERIODIC_TASKS );
configASSERT( pdTRUE == xTCBArray[ xIndex ].xInUse );
if( xTCBArray[ pdTRUE == xIndex].xInUse )
{
xTCBArray[ xIndex ].xInUse = pdFALSE;
xTaskCounter--;
}
}
#elif( schedUSE_TCB_SORTED_LIST == 1 )
/* Add an extended TCB to sorted linked list. */
static void prvAddTCBToList( SchedTCB_t *pxTCB )
{
/* Initialise TCB list item. */
vListInitialiseItem( &pxTCB->xTCBListItem );
/* Set owner of list item to the TCB. */
listSET_LIST_ITEM_OWNER( &pxTCB->xTCBListItem, pxTCB );
/* List is sorted by absolute deadline value. */
listSET_LIST_ITEM_VALUE( &pxTCB->xTCBListItem, pxTCB->xAbsoluteDeadline );
#if( schedEDF_EFFICIENT == 1 )
/* Initialise list item for xTCBListAll. */
vListInitialiseItem( &pxTCB->xTCBAllListItem );
/* Set owner of list item to the TCB. */
listSET_LIST_ITEM_OWNER( &pxTCB->xTCBAllListItem, pxTCB );
/* There is no need to sort the list. */
#endif /* schedEDF_EFFICIENT */
#if( schedEDF_NAIVE == 1 )
/* Insert TCB into list. */
vListInsert( pxTCBList, &pxTCB->xTCBListItem );
#elif( schedEDF_EFFICIENT == 1 )
/* Insert TCB into ready list. */
vListInsert( pxTCBReadyList, &pxTCB->xTCBListItem );
/* Insert TCB into list containing tasks in any state. */
vListInsert( pxTCBListAll, &pxTCB->xTCBAllListItem );
#endif /* schedEDF_EFFICIENT */
}
/* Delete an extended TCB from sorted linked list. */
static void prvDeleteTCBFromList( SchedTCB_t *pxTCB )
{
#if( schedEDF_EFFICIENT == 1 )
uxListRemove( &pxTCB->xTCBAllListItem );
#endif /* schedEDF_EFFICIENT */
uxListRemove( &pxTCB->xTCBListItem );
vPortFree( pxTCB );
}
#endif /* schedUSE_TCB_ARRAY */
#if( schedSCHEDULING_POLICY == schedSCHEDULING_POLICY_EDF )
#if( schedUSE_TCB_SORTED_LIST == 1 )
/* Swap content of two lists. */
static void prvSwapList( List_t **ppxList1, List_t **ppxList2 )
{
List_t *pxTemp;
pxTemp = *ppxList1;
*ppxList1 = *ppxList2;
*ppxList2 = pxTemp;
}
#endif /* schedUSE_TCB_SORTED_LIST */
#if( schedEDF_NAIVE == 1 )
/* Update priorities of all periodic tasks with respect to EDF policy. */
static void prvUpdatePrioritiesEDF( void )
{
SchedTCB_t *pxTCB;
#if( schedUSE_TCB_SORTED_LIST == 1 )
ListItem_t *pxTCBListItem;
ListItem_t *pxTCBListItemTemp;
if( listLIST_IS_EMPTY( pxTCBList ) && !listLIST_IS_EMPTY( pxTCBOverflowedList ) )
{
prvSwapList( &pxTCBList, &pxTCBOverflowedList );
}
const ListItem_t *pxTCBListEndMarker = listGET_END_MARKER( pxTCBList );
pxTCBListItem = listGET_HEAD_ENTRY( pxTCBList );
while( pxTCBListItem != pxTCBListEndMarker )
{
pxTCB = listGET_LIST_ITEM_OWNER( pxTCBListItem );
/* Update priority in the SchedTCB list. */
listSET_LIST_ITEM_VALUE( pxTCBListItem, pxTCB->xAbsoluteDeadline );
pxTCBListItemTemp = pxTCBListItem;
pxTCBListItem = listGET_NEXT( pxTCBListItem );
uxListRemove( pxTCBListItem->pxPrevious );
/* If absolute deadline overflowed, insert TCB to overflowed list. */
if( pxTCB->xAbsoluteDeadline < pxTCB->xLastWakeTime )
{
vListInsert( pxTCBOverflowedList, pxTCBListItemTemp );
}
else /* Insert TCB into temp list in usual case. */
{
vListInsert( pxTCBTempList, pxTCBListItemTemp );
}
}
/* Swap list with temp list. */
prvSwapList( &pxTCBList, &pxTCBTempList );
#if( schedUSE_SCHEDULER_TASK == 1 )
BaseType_t xHighestPriority = schedSCHEDULER_PRIORITY - 1;
#else
BaseType_t xHighestPriority = configMAX_PRIORITIES - 1;
#endif /* schedUSE_SCHEDULER_TASK */
const ListItem_t *pxTCBListEndMarkerAfterSwap = listGET_END_MARKER( pxTCBList );
pxTCBListItem = listGET_HEAD_ENTRY( pxTCBList );
while( pxTCBListItem != pxTCBListEndMarkerAfterSwap )
{
pxTCB = listGET_LIST_ITEM_OWNER( pxTCBListItem );
configASSERT( -1 <= xHighestPriority );
pxTCB->uxPriority = xHighestPriority;
vTaskPrioritySet( *pxTCB->pxTaskHandle, pxTCB->uxPriority );
xHighestPriority--;
pxTCBListItem = listGET_NEXT( pxTCBListItem );
}
#endif /* schedUSE_TCB_SORTED_LIST */
}
#elif( schedEDF_EFFICIENT == 1 )
/* Removes given SchedTCB from blocked list and inserts it to ready list. */
static void prvInsertTCBToReadyList( SchedTCB_t *pxTCB )
{
/* Remove ready task from blocked list. */
uxListRemove( &pxTCB->xTCBListItem );
/* Check whether absolute deadline has overflowed or not. */
if( pxTCB->xAbsoluteDeadline < pxTCB->xLastWakeTime )
{
/* Absolute deadline has overflowed. */
vListInsert( pxTCBOverflowedReadyList, &pxTCB->xTCBListItem );
}
else
{
vListInsert( pxTCBReadyList, &pxTCB->xTCBListItem );
}
/* If ready list is empty and overflowed ready list is not, swap those. */
if( listLIST_IS_EMPTY( pxTCBReadyList ) && !listLIST_IS_EMPTY( pxTCBOverflowedReadyList ) )
{
prvSwapList( &pxTCBReadyList, &pxTCBOverflowedReadyList );
}
/*
ListItem_t *pxListItem = listGET_HEAD_ENTRY( pxTCBReadyList );
SchedTCB_t *pxHighestPriorityTCB = listGET_LIST_ITEM_OWNER( pxListItem );
SchedTCB_t *pxNextTCB = listGET_LIST_ITEM_OWNER( pxListItem->pxNext );
if( pxCurrentTCB != pxHighestPriorityTCB )
{
if( NULL != pxCurrentTCB )
{
pxPreviousTCB = pxCurrentTCB;
}
pxCurrentTCB = pxHighestPriorityTCB;
xSwitchToSchedulerOnReady = pdTRUE;
prvWakeScheduler();
}
*/
if( NULL == pxCurrentTCB || ( signed ) ( pxCurrentTCB->xAbsoluteDeadline - pxTCB->xAbsoluteDeadline ) > 0 )
{
if( NULL != pxCurrentTCB )
{
pxPreviousTCB = pxCurrentTCB;
}
pxCurrentTCB = pxTCB;
xSwitchToSchedulerOnReady = pdTRUE;
prvWakeScheduler();
}
}
/* Called when a task is blocked. */
void vSchedulerBlockTrace( void )
{
if( NULL != pxCurrentTCB && xTaskGetCurrentTaskHandle() == *pxCurrentTCB->pxTaskHandle )
{
/* Remove current task from ready list. */
uxListRemove( &pxCurrentTCB->xTCBListItem );
/* Insert current task to blocked list. */
vListInsert( pxTCBBlockedList, &pxCurrentTCB->xTCBListItem );
pxPreviousTCB = pxCurrentTCB;
pxCurrentTCB = NULL;
xSwitchToSchedulerOnBlock = pdTRUE;
prvWakeScheduler();
}
}
/* Called when a task is suspended. */
void vSchedulerSuspendTrace( TaskHandle_t xTaskHandle )
{
SchedTCB_t *pxTCBToSuspend = ( SchedTCB_t * ) pvTaskGetThreadLocalStoragePointer( xTaskHandle, schedTHREAD_LOCAL_STORAGE_POINTER_INDEX );
if( NULL != pxTCBToSuspend )
{
/* Remove suspended task from ready list. */
uxListRemove( &pxTCBToSuspend->xTCBListItem );
/* Insert suspended task to blocked list. */
vListInsert( pxTCBBlockedList, &pxTCBToSuspend->xTCBListItem );
if( *pxCurrentTCB->pxTaskHandle == *pxTCBToSuspend->pxTaskHandle )
{
pxPreviousTCB = pxCurrentTCB;
pxCurrentTCB = NULL;
xSwitchToSchedulerOnSuspend = pdTRUE;
prvWakeScheduler();
}
}
}
/* Called when a task becomes ready. */
void vSchedulerReadyTrace( TaskHandle_t xTaskHandle )
{
if( xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED || xTaskHandle == xSchedulerHandle )
{
return;
}
#if( configUSE_TIMERS == 1 )
/* Check if the unblocked task was the timer task. */
if( xTimerGetTimerDaemonTaskHandle() == xTaskHandle )
{
return;
}
#endif /* configUSE_TIMERS */
SchedTCB_t *pxTCBReady = ( SchedTCB_t * ) pvTaskGetThreadLocalStoragePointer( xTaskHandle, schedTHREAD_LOCAL_STORAGE_POINTER_INDEX );
if( NULL != pxTCBReady )
{
prvInsertTCBToReadyList( pxTCBReady );
}
}
#endif /* schedEDF_EFFICIENT */
#endif /* schedSCHEDULING_POLICY_EDF */
/* The whole function code that is executed by every periodic task.
* This function wraps the task code specified by the user. */
static void prvPeriodicTaskCode( void *pvParameters )
{
SchedTCB_t *pxThisTask = ( SchedTCB_t * ) pvTaskGetThreadLocalStoragePointer( xTaskGetCurrentTaskHandle(), schedTHREAD_LOCAL_STORAGE_POINTER_INDEX );
configASSERT( NULL != pxThisTask );
if( 0 != pxThisTask->xReleaseTime )
{
vTaskDelayUntil( &pxThisTask->xLastWakeTime, pxThisTask->xReleaseTime );
}
#if( schedUSE_TIMING_ERROR_DETECTION_DEADLINE == 1 )
pxThisTask->xExecutedOnce = pdTRUE;
#endif /* schedUSE_TIMING_ERROR_DETECTION_DEADLINE */
if( 0 == pxThisTask->xReleaseTime )
{
pxThisTask->xLastWakeTime = xSystemStartTime;
}
for( ; ; )
{
#if( schedSCHEDULING_POLICY == schedSCHEDULING_POLICY_EDF )
#if( schedEDF_NAIVE == 1 )
/* Wake up the scheduler task to update priorities of all periodic tasks. */
prvWakeScheduler();
#endif /* schedEDF_NAIVE */
#endif /* schedSCHEDULING_POLICY_EDF */
pxThisTask->xWorkIsDone = pdFALSE;
taskENTER_CRITICAL();
//printf( "TICK %d: Task in %s [Abs deadline:%d, lastWakeTime:%d, priority:%d]\n\r", (int) xTaskGetTickCount(), pxThisTask->pcName, (int)pxThisTask->xAbsoluteDeadline, (int) pxThisTask->xLastWakeTime, (int) uxTaskPriorityGet( NULL ));
printf( "TICK %d: Task in %s [Abs deadline:%d ms, lastWakeTime:%d ms]\n\r", (int) xTaskGetTickCount(), pxThisTask->pcName, (int)pxThisTask->xAbsoluteDeadline, (int) pxThisTask->xLastWakeTime);
taskEXIT_CRITICAL();
/* Execute the task function specified by the user. */
pxThisTask->pvTaskCode( pvParameters );
pxThisTask->xWorkIsDone = pdTRUE;
taskENTER_CRITICAL();
printf( "TICK %d: Task out %s execution time [%d ms]\n\r", (int) xTaskGetTickCount(), pxThisTask->pcName, (int) pxThisTask->xExecTime );
taskEXIT_CRITICAL();
pxThisTask->xExecTime = 0;
#if( schedSCHEDULING_POLICY == schedSCHEDULING_POLICY_EDF )
pxThisTask->xAbsoluteDeadline = pxThisTask->xLastWakeTime + pxThisTask->xPeriod + pxThisTask->xRelativeDeadline;
#if( schedEDF_EFFICIENT == 1 )
listSET_LIST_ITEM_VALUE( &pxThisTask->xTCBListItem, pxThisTask->xAbsoluteDeadline );
#endif /* schedEDF_EFFICIENT */
#if( schedEDF_NAIVE == 1 )
/* Wake up the scheduler task to update priorities of all periodic tasks. */
prvWakeScheduler();
#endif /* schedEDF_NAIVE */
#endif /* schedSCHEDULING_POLICY_EDF */
vTaskDelayUntil( &pxThisTask->xLastWakeTime, pxThisTask->xPeriod );
}
}
/* Creates a periodic task. */
void vSchedulerPeriodicTaskCreate( TaskFunction_t pvTaskCode, const char *pcName, UBaseType_t uxStackDepth, void *pvParameters, UBaseType_t uxPriority,
TaskHandle_t *pxCreatedTask, TickType_t xPhaseTick, TickType_t xPeriodTick, TickType_t xMaxExecTimeTick, TickType_t xDeadlineTick )
{
taskENTER_CRITICAL();
SchedTCB_t *pxNewTCB;
#if( schedUSE_TCB_ARRAY == 1 )
BaseType_t xIndex = prvFindEmptyElementIndexTCB();
configASSERT( xTaskCounter < schedMAX_NUMBER_OF_PERIODIC_TASKS );
configASSERT( xIndex != -1 );
pxNewTCB = &xTCBArray[ xIndex ];
#else
pxNewTCB = pvPortMalloc( sizeof( SchedTCB_t ) );
#endif /* schedUSE_TCB_ARRAY */
/* Intialize item. */
*pxNewTCB = ( SchedTCB_t ) { .pvTaskCode = pvTaskCode, .pcName = pcName, .uxStackDepth = uxStackDepth, .pvParameters = pvParameters,
.uxPriority = uxPriority, .pxTaskHandle = pxCreatedTask, .xReleaseTime = xPhaseTick, .xPeriod = xPeriodTick, .xMaxExecTime = xMaxExecTimeTick,
.xRelativeDeadline = xDeadlineTick, .xWorkIsDone = pdTRUE, .xExecTime = 0 };
#if( schedUSE_TCB_ARRAY == 1 )
pxNewTCB->xInUse = pdTRUE;
#endif /* schedUSE_TCB_ARRAY */
#if( schedSCHEDULING_POLICY == schedSCHEDULING_POLICY_RMS || schedSCHEDULING_POLICY == schedSCHEDULING_POLICY_DMS )
pxNewTCB->xPriorityIsSet = pdFALSE;
#elif( schedSCHEDULING_POLICY == schedSCHEDULING_POLICY_MANUAL )
pxNewTCB->xPriorityIsSet = pdTRUE;
#elif( schedSCHEDULING_POLICY == schedSCHEDULING_POLICY_EDF )
pxNewTCB->xAbsoluteDeadline = pxNewTCB->xRelativeDeadline + pxNewTCB->xReleaseTime + xSystemStartTime;
pxNewTCB->uxPriority = -1;
#endif /* schedSCHEDULING_POLICY */
#if( schedUSE_TIMING_ERROR_DETECTION_DEADLINE == 1 )
pxNewTCB->xExecutedOnce = pdFALSE;
#endif /* schedUSE_TIMING_ERROR_DETECTION_DEADLINE */
#if( schedUSE_TIMING_ERROR_DETECTION_EXECUTION_TIME == 1 )
pxNewTCB->xSuspended = pdFALSE;
pxNewTCB->xMaxExecTimeExceeded = pdFALSE;
#endif /* schedUSE_TIMING_ERROR_DETECTION_EXECUTION_TIME */
#if( schedUSE_POLLING_SERVER == 1)
pxNewTCB->xIsPeriodicServer = pdFALSE;
#endif /* schedUSE_POLLING_SERVER */
#if( schedUSE_TCB_ARRAY == 1 )
xTaskCounter++;
#elif( schedUSE_TCB_SORTED_LIST == 1 )
#if( schedEDF_EFFICIENT == 1 )
pxNewTCB->uxPriority = schedPRIORITY_NOT_RUNNING;
#endif /* schedEDF_EFFICIENT */
prvAddTCBToList( pxNewTCB );
#endif /* schedUSE_TCB_SORTED_LIST */
taskEXIT_CRITICAL();
}
/* Deletes a periodic task. */
void vSchedulerPeriodicTaskDelete( TaskHandle_t xTaskHandle )
{
if( xTaskHandle != NULL )
{
#if( schedUSE_TCB_ARRAY == 1 )
prvDeleteTCBFromArray( prvGetTCBIndexFromHandle( xTaskHandle ) );
#elif( schedUSE_TCB_SORTED_LIST == 1 )
prvDeleteTCBFromList( ( SchedTCB_t * ) pvTaskGetThreadLocalStoragePointer( xTaskHandle, schedTHREAD_LOCAL_STORAGE_POINTER_INDEX ) );
#endif /* schedUSE_TCB_ARRAY */
}
else
{
#if( schedUSE_TCB_ARRAY == 1 )
prvDeleteTCBFromArray( prvGetTCBIndexFromHandle( xTaskGetCurrentTaskHandle() ) );
#elif( schedUSE_TCB_SORTED_LIST == 1 )
prvDeleteTCBFromList( ( SchedTCB_t * ) pvTaskGetThreadLocalStoragePointer( xTaskGetCurrentTaskHandle(), schedTHREAD_LOCAL_STORAGE_POINTER_INDEX ) );
#endif /* schedUSE_TCB_ARRAY */
}
vTaskDelete( xTaskHandle );
}
/* Creates all periodic tasks stored in TCB array, or TCB list. */
static void prvCreateAllTasks( void )
{
SchedTCB_t *pxTCB;
#if( schedUSE_TCB_ARRAY == 1 )
BaseType_t xIndex;
for( xIndex = 0; xIndex < xTaskCounter; xIndex++ )
{
configASSERT( pdTRUE == xTCBArray[ xIndex ].xInUse );
pxTCB = &xTCBArray[ xIndex ];
BaseType_t xReturnValue = xTaskCreate( prvPeriodicTaskCode, pxTCB->pcName, pxTCB->uxStackDepth, pxTCB->pvParameters, pxTCB->uxPriority, pxTCB->pxTaskHandle );
if( pdPASS == xReturnValue )
{
vTaskSetThreadLocalStoragePointer( *pxTCB->pxTaskHandle, schedTHREAD_LOCAL_STORAGE_POINTER_INDEX, pxTCB );
}
else
{
/* if task creation failed */
}
}
#elif( schedUSE_TCB_SORTED_LIST == 1 )
#if( schedEDF_NAIVE ==1 )
const ListItem_t *pxTCBListEndMarker = listGET_END_MARKER( pxTCBList );
ListItem_t *pxTCBListItem = listGET_HEAD_ENTRY( pxTCBList );
#elif( schedEDF_EFFICIENT == 1 )
const ListItem_t *pxTCBListEndMarker = listGET_END_MARKER( pxTCBListAll );
ListItem_t *pxTCBListItem = listGET_HEAD_ENTRY( pxTCBListAll );
#endif /* schedEDF_EFFICIENT */
while( pxTCBListItem != pxTCBListEndMarker )
{
pxTCB = listGET_LIST_ITEM_OWNER( pxTCBListItem );
configASSERT( NULL != pxTCB );
BaseType_t xReturnValue = xTaskCreate( prvPeriodicTaskCode, pxTCB->pcName, pxTCB->uxStackDepth, pxTCB->pvParameters, pxTCB->uxPriority, pxTCB->pxTaskHandle );
if( pdPASS == xReturnValue )
{
}
else
{
/* if task creation failed */
}
vTaskSetThreadLocalStoragePointer( *pxTCB->pxTaskHandle, schedTHREAD_LOCAL_STORAGE_POINTER_INDEX, pxTCB );
pxTCBListItem = listGET_NEXT( pxTCBListItem );
}
#endif /* schedUSE_TCB_ARRAY */
}
#if( schedSCHEDULING_POLICY == schedSCHEDULING_POLICY_RMS || schedSCHEDULING_POLICY == schedSCHEDULING_POLICY_DMS )
/* Initiazes fixed priorities of all periodic tasks with respect to RMS or
* DMS policy. */
static void prvSetFixedPriorities( void )
{
BaseType_t xIter, xIndex;
TickType_t xShortest, xPreviousShortest=0;
SchedTCB_t *pxShortestTaskPointer, *pxTCB;
#if( schedUSE_SCHEDULER_TASK == 1 )
BaseType_t xHighestPriority = schedSCHEDULER_PRIORITY;
#else
BaseType_t xHighestPriority = configMAX_PRIORITIES;
#endif /* schedUSE_SCHEDULER_TASK */
for( xIter = 0; xIter < xTaskCounter; xIter++ )
{
xShortest = portMAX_DELAY;
/* search for shortest period/deadline */
for( xIndex = 0; xIndex < xTaskCounter; xIndex++ )
{
pxTCB = &xTCBArray[ xIndex ];
configASSERT( pdTRUE == pxTCB->xInUse );
if(pdTRUE == pxTCB->xPriorityIsSet)
{
continue;
}
#if( schedSCHEDULING_POLICY == schedSCHEDULING_POLICY_RMS )
if( pxTCB->xPeriod <= xShortest )
{
xShortest = pxTCB->xPeriod;
pxShortestTaskPointer = pxTCB;
}
#elif( schedSCHEDULING_POLICY == schedSCHEDULING_POLICY_DMS )
if( pxTCB->xRelativeDeadline <= xShortest )
{
xShortest = pxTCB->xRelativeDeadline;
pxShortestTaskPointer = pxTCB;
}
#endif /* schedSCHEDULING_POLICY */
}
configASSERT( -1 <= xHighestPriority );
if( xPreviousShortest != xShortest )
{
xHighestPriority--;
}
/* set highest priority to task with xShortest period (the highest priority is configMAX_PRIORITIES-1) */
pxShortestTaskPointer->uxPriority = xHighestPriority;
pxShortestTaskPointer->xPriorityIsSet = pdTRUE;
xPreviousShortest = xShortest;
}
}
#elif( schedSCHEDULING_POLICY == schedSCHEDULING_POLICY_EDF )
/* Initializes priorities of all periodic tasks with respect to EDF policy. */
static void prvInitEDF( void )
{
#if( schedEDF_NAIVE == 1 )
SchedTCB_t *pxTCB;
#if( schedUSE_SCHEDULER_TASK == 1 )
UBaseType_t uxHighestPriority = schedSCHEDULER_PRIORITY - 1;
#else
UBaseType_t uxHighestPriority = configMAX_PRIORITIES - 1;
#endif /* schedUSE_SCHEDULER_TASK */
const ListItem_t *pxTCBListEndMarker = listGET_END_MARKER( pxTCBList );
ListItem_t *pxTCBListItem = listGET_HEAD_ENTRY( pxTCBList );
while( pxTCBListItem != pxTCBListEndMarker )
{
pxTCB = listGET_LIST_ITEM_OWNER( pxTCBListItem );
pxTCB->uxPriority = uxHighestPriority;
uxHighestPriority--;
pxTCBListItem = listGET_NEXT( pxTCBListItem );
}
#elif( schedEDF_EFFICIENT == 1 )
ListItem_t *pxTCBListItem = listGET_HEAD_ENTRY( pxTCBReadyList );
pxCurrentTCB = listGET_LIST_ITEM_OWNER( pxTCBListItem );
pxCurrentTCB->uxPriority = schedPRIORITY_RUNNING;
#endif /* schedEDF_EFFICIENT */
}
#endif /* schedSCHEDULING_POLICY */
#if( schedUSE_TIMING_ERROR_DETECTION_DEADLINE == 1 )
/* Recreates a deleted task that still has its information left in the task array (or list). */
static void prvPeriodicTaskRecreate( SchedTCB_t *pxTCB )
{
BaseType_t xReturnValue = xTaskCreate( prvPeriodicTaskCode, pxTCB->pcName, pxTCB->uxStackDepth, pxTCB->pvParameters, pxTCB->uxPriority, pxTCB->pxTaskHandle );
if( pdPASS == xReturnValue )
{
vTaskSetThreadLocalStoragePointer( *pxTCB->pxTaskHandle, schedTHREAD_LOCAL_STORAGE_POINTER_INDEX, ( SchedTCB_t * ) pxTCB );
/* This must be set to false so that the task does not miss the deadline immediately when it is created. */
pxTCB->xExecutedOnce = pdFALSE;
#if( schedUSE_TIMING_ERROR_DETECTION_EXECUTION_TIME == 1 )
pxTCB->xSuspended = pdFALSE;
pxTCB->xMaxExecTimeExceeded = pdFALSE;
#endif /* schedUSE_TIMING_ERROR_DETECTION_EXECUTION_TIME */
#if( schedEDF_EFFICIENT == 1)
prvInsertTCBToReadyList( pxTCB );
#endif/* schedEDF_EFFICIENT */
}
else
{
/* if task creation failed */
}
}
/* Called when a deadline of a periodic task is missed.
* Deletes the periodic task that has missed it's deadline and recreate it.
* The periodic task is released during next period. */
static void prvDeadlineMissedHook( SchedTCB_t *pxTCB, TickType_t xTickCount )
{
taskENTER_CRITICAL();
printf( "TICK %d: deadline missed task %s!\n\r", (int)xTickCount, pxTCB->pcName );
taskEXIT_CRITICAL();
/* Delete the pxTask and recreate it. */
vTaskDelete( *pxTCB->pxTaskHandle );
pxTCB->xExecTime = 0;
prvPeriodicTaskRecreate( pxTCB );
pxTCB->xReleaseTime = pxTCB->xLastWakeTime + pxTCB->xPeriod;
/* Need to reset lastWakeTime for correct release. */
pxTCB->xLastWakeTime = 0;
pxTCB->xAbsoluteDeadline = pxTCB->xRelativeDeadline + pxTCB->xReleaseTime;
#if( schedEDF_EFFICIENT == 1 )
listSET_LIST_ITEM_VALUE( &pxTCB->xTCBListItem, pxTCB->xAbsoluteDeadline );
#endif /* schedEDF_EFFICIENT */
}
/* Checks whether given task has missed deadline or not. */
static void prvCheckDeadline( SchedTCB_t *pxTCB, TickType_t xTickCount )
{
if( ( NULL != pxTCB ) && ( pdFALSE == pxTCB->xWorkIsDone ) && ( pdTRUE == pxTCB->xExecutedOnce ) )
{
/* Need to update absolute deadline if the scheduling policy is not EDF. */
#if( schedSCHEDULING_POLICY != schedSCHEDULING_POLICY_EDF )
pxTCB->xAbsoluteDeadline = pxTCB->xLastWakeTime + pxTCB->xRelativeDeadline;
#endif /* schedSCHEDULING_POLICY */
/* Using ICTOH method proposed by Carlini and Buttazzo, to check whether deadline is missed. */
if( ( signed ) ( pxTCB->xAbsoluteDeadline - xTickCount ) < 0 )
{
/* Deadline is missed. */
prvDeadlineMissedHook( pxTCB, xTickCount );
}
}
}
#if( schedUSE_SPORADIC_JOBS == 1 )
/* Called when a deadline of a sporadic job is missed. */
static void prvDeadlineMissedHookSporadicJob( BaseType_t xIndex )
{
printf( "Task %s: Deadline missed sporadic job! \n\r", xSJCBFifo[ xIndex ].pcName );
}
/* Checks if any sporadic job has missed it's deadline. */
static void prvCheckSporadicJobDeadline( TickType_t xTickCount )
{
if( uxSporadicJobCounter > 0 )
{
BaseType_t xIndex;
for( xIndex = xSJCBFifoHead-1; xIndex < uxSporadicJobCounter; xIndex++ )
{
if( -1 == xIndex )
{
xIndex = schedMAX_NUMBER_OF_SPORADIC_JOBS - 1;
}
if( schedMAX_NUMBER_OF_SPORADIC_JOBS == xIndex )
{
xIndex = 0;
}
/* Using ICTOH method proposed by Carlini and Buttazzo, to check whether deadline is missed. */
if( ( signed ) ( xSJCBFifo[ xIndex ].xAbsoluteDeadline - xTickCount ) < 0 )
{
prvDeadlineMissedHookSporadicJob( xIndex );
}
}
}
}
#endif /* schedUSE_SPORADIC_JOBS */
#endif /* schedUSE_TIMING_ERROR_DETECTION_DEADLINE */
#if( schedUSE_TIMING_ERROR_DETECTION_EXECUTION_TIME == 1 )
/* Called if a periodic task has exceeded it's worst-case execution time.
* The periodic task is blocked until next period. A context switch to
* the scheduler task occur to block the periodic task. */
static void prvExecTimeExceedHook( TickType_t xTickCount, SchedTCB_t *pxCurrentTask )
{
printf( "TICK %d: Worst case execution time exceeded! Task %s [%d]\r\n", (int)xTickCount, pxCurrentTask->pcName, (int)pxCurrentTask->xExecTime );
pxCurrentTask->xMaxExecTimeExceeded = pdTRUE;
/* Is not suspended yet, but will be suspended by the scheduler later. */
pxCurrentTask->xSuspended = pdTRUE;
pxCurrentTask->xAbsoluteUnblockTime = pxCurrentTask->xLastWakeTime + pxCurrentTask->xPeriod;
pxCurrentTask->xExecTime = 0;
#if( schedUSE_POLLING_SERVER == 1)
if( pdTRUE == pxCurrentTask->xIsPeriodicServer )
{
pxCurrentTask->xAbsoluteDeadline = pxCurrentTask->xAbsoluteUnblockTime + pxCurrentTask->xRelativeDeadline;
#if( schedEDF_EFFICIENT == 1 )
listSET_LIST_ITEM_VALUE( &pxCurrentTask->xTCBListItem, pxCurrentTask->xAbsoluteDeadline );
#endif /* schedEDF_EFFICIENT */
}
#endif /* schedUSE_POLLING_SERVER */
BaseType_t xHigherPriorityTaskWoken;
vTaskNotifyGiveFromISR( xSchedulerHandle, &xHigherPriorityTaskWoken );
schedYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}
#endif /* schedUSE_TIMING_ERROR_DETECTION_EXECUTION_TIME */
#if( schedUSE_SCHEDULER_TASK == 1 )
/* Called by the scheduler task. Checks all tasks for any enabled
* Timing Error Detection feature. */
static void prvSchedulerCheckTimingError( TickType_t xTickCount, SchedTCB_t *pxTCB )
{
#if( schedUSE_TCB_ARRAY == 1 )
if( pdFALSE == pxTCB->xInUse )
{
return;
}
#endif
#if( schedUSE_TIMING_ERROR_DETECTION_DEADLINE == 1 )
#if( schedUSE_POLLING_SERVER == 1 )
/* If the task is periodic server, do not check deadline. */
if( pdTRUE == pxTCB->xIsPeriodicServer )
{
#if( schedUSE_SPORADIC_JOBS == 1 )
prvCheckSporadicJobDeadline( xTickCount );
#endif /* schedUSE_SPORADIC_JOBS */
}
else
{
/* Since lastWakeTime is updated to next wake time when the task is delayed, tickCount > lastWakeTime implies that
* the task has not finished it's job this period. */
/* Using ICTOH method proposed by Carlini and Buttazzo, to check the condition unaffected by counter overflows. */
if( ( signed ) ( xTickCount - pxTCB->xLastWakeTime ) > 0 )
{