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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
|
/***************************************************************************
* Copyright (c) 2024 Microsoft Corporation
* Copyright (c) 2026-present Eclipse ThreadX contributors
*
* This program and the accompanying materials are made available under the
* terms of the MIT License which is available at
* https://opensource.org/licenses/MIT.
*
* SPDX-License-Identifier: MIT
**************************************************************************/
/**************************************************************************/
/**************************************************************************/
/** */
/** ThreadX Component */
/** */
/** ThreadX/GHS Event Log (EL) */
/** */
/**************************************************************************/
/**************************************************************************/
#define TX_SOURCE_CODE
#define TX_EL_SOURCE_CODE
/* Include necessary system files. */
#include "tx_api.h"
#include "tx_el.h"
#include "string.h"
/* Define global variables used to manage the event pool. */
UCHAR *_tx_el_tni_start;
UCHAR **_tx_el_current_event;
UCHAR *_tx_el_event_area_start;
UCHAR *_tx_el_event_area_end;
UINT _tx_el_maximum_events;
ULONG _tx_el_total_events;
UINT _tx_el_event_filter;
ULONG _tx_el_time_base_upper;
ULONG _tx_el_time_base_lower;
extern char __ghsbegin_eventlog[];
extern char __ghsend_eventlog[];
extern TX_THREAD *_tx_thread_current_ptr;
UINT _tx_thread_interrupt_control(UINT new_posture);
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _tx_el_initialize PORTABLE C */
/* 6.1 */
/* AUTHOR */
/* */
/* William E. Lamie, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function creates the Event Log (in the format dictated by the */
/* GHS Event Analyzer) and sets up various information for subsequent */
/* operation. The start and end of the Event Log is determined by the */
/* .eventlog section in the linker control file. */
/* */
/* INPUT */
/* */
/* None */
/* */
/* OUTPUT */
/* */
/* None */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */
/**************************************************************************/
VOID _tx_el_initialize(VOID)
{
UCHAR *work_ptr;
UCHAR *read_ptr;
ULONG event_log_size;
UCHAR *end_ptr;
UINT i;
/* Clear total event counter. */
_tx_el_total_events = 0;
/* Clear event filter. */
_tx_el_event_filter = 0;
/* First, pickup the starting and ending address of the Event Log memory. */
work_ptr = (unsigned char *) __ghsbegin_eventlog;
end_ptr = (unsigned char *) __ghsend_eventlog;
/* Calculate the event log size. */
event_log_size = end_ptr - work_ptr;
/* Subtract off the number of bytes in the header and the TNI area. */
event_log_size = event_log_size - (TX_EL_HEADER_SIZE +
(TX_EL_TNI_ENTRY_SIZE * TX_EL_TNIS));
/* Make sure the event log is evenly divisible by the event size. */
event_log_size = (event_log_size/TX_EL_EVENT_SIZE) * TX_EL_EVENT_SIZE;
/* Build the Event Log header. */
/* Setup the Event Log Version ID. */
*((unsigned short *) work_ptr) = (unsigned short) TX_EL_VERSION_ID;
work_ptr = work_ptr + sizeof(unsigned short);
/* Setup the TNIS (number of thread names) field. */
*((unsigned short *) work_ptr) = (unsigned short) TX_EL_TNIS;
work_ptr = work_ptr + sizeof(unsigned short);
/* Setup the EVPS (event pool size) field. */
*((ULONG *) work_ptr) = event_log_size;
work_ptr = work_ptr + sizeof(ULONG);
/* Remember the maximum number of events. */
_tx_el_maximum_events = event_log_size/TX_EL_EVENT_SIZE;
/* Setup max_events field. */
*((ULONG *) work_ptr) = _tx_el_maximum_events;
work_ptr = work_ptr + sizeof(ULONG);
/* Setup the evploc (location of event pool). */
*((ULONG *) work_ptr) = (ULONG) (((ULONG) __ghsbegin_eventlog) + TX_EL_HEADER_SIZE +
(TX_EL_TNIS * TX_EL_TNI_ENTRY_SIZE));
work_ptr = work_ptr + sizeof(ULONG);
/* Save the current event pointer. */
_tx_el_current_event = (UCHAR **) work_ptr;
/* Setup event_ptr (pointer to oldest event) field to the start
of the event pool. */
*_tx_el_current_event = (UCHAR *) (((ULONG) __ghsbegin_eventlog) + TX_EL_HEADER_SIZE +
(TX_EL_TNIS * TX_EL_TNI_ENTRY_SIZE));
work_ptr = work_ptr + sizeof(ULONG);
/* Setup tbfreq (the number of ticks in a second) field. */
*((ULONG *) work_ptr) = TX_EL_TICKS_PER_SECOND;
work_ptr = work_ptr + sizeof(ULONG);
/* At this point we are pointing at the Thread Name Information (TNI) array. */
/* Remember the start of this for future updates. */
_tx_el_tni_start = work_ptr;
/* Clear the entire TNI array, this is the initial setting. */
end_ptr = work_ptr + (TX_EL_TNIS * TX_EL_TNI_ENTRY_SIZE);
memset((void *)work_ptr, 0, (TX_EL_TNIS * TX_EL_TNI_ENTRY_SIZE));
work_ptr = end_ptr;
/* At this point, we are pointing at the actual Event Entry area. */
/* Remember the start of the actual event log area. */
_tx_el_event_area_start = work_ptr;
/* Clear the entire Event area. */
end_ptr = work_ptr + event_log_size;
memset((void *)work_ptr, 0, event_log_size);
work_ptr = end_ptr;
/* Save the end pointer for later use. */
_tx_el_event_area_end = work_ptr;
/* Setup an entry to resolve all activities from initialization and from
an idle system. */
work_ptr = _tx_el_tni_start;
read_ptr = (UCHAR *) "Initialization/System Idle";
i = 0;
while ((i < TX_EL_TNI_NAME_SIZE) && (*read_ptr))
{
/* Copy a character of thread's name into TNI area of log. */
*work_ptr++ = *read_ptr++;
/* Increment the character count. */
i++;
}
/* Determine if a NULL needs to be inserted. */
if (i < TX_EL_TNI_NAME_SIZE)
{
/* Yes, insert a NULL into the event log string. */
*work_ptr = (unsigned char) 0;
}
/* Setup the thread ID to NULL. */
*((ULONG *) (_tx_el_tni_start + TX_EL_TNI_THREAD_ID_OFFSET)) = (ULONG) TX_NULL;
/* Set the valid field to indicate the entry is complete. */
*((UCHAR *) (_tx_el_tni_start + TX_EL_TNI_VALID_OFFSET)) = (ULONG) TX_EL_VALID_ENTRY;
/* Clear the time base global variables. */
_tx_el_time_base_upper = 0;
_tx_el_time_base_lower = 0;
}
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _tx_el_thread_register PORTABLE C */
/* 6.1 */
/* AUTHOR */
/* */
/* William E. Lamie, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function registers a thread in the event log for future */
/* display purposes. */
/* */
/* INPUT */
/* */
/* thread_ptr Pointer to thread control block */
/* */
/* OUTPUT */
/* */
/* TX_SUCCESS Thread was placed in TNI area */
/* TX_ERROR No more room in the TNI area */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* _tx_thread_create ThreadX thread create function */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */
/* 09-30-2020 William E. Lamie Initial Version 6.1 */
/* */
/**************************************************************************/
UINT _tx_el_thread_register(TX_THREAD *thread_ptr)
{
UCHAR *entry_ptr;
UCHAR *work_ptr;
UCHAR *read_ptr;
UINT i;
/* First of all, search for a free slot in the TNI area. */
entry_ptr = _tx_el_tni_start;
i = 0;
while (i < TX_EL_TNIS)
{
/* Determine if this entry is available. */
if (*(entry_ptr + TX_EL_TNI_VALID_OFFSET) == TX_EL_INVALID_ENTRY)
break;
/* Otherwise, increment the associated pointers and indices. */
i++;
entry_ptr = entry_ptr + TX_EL_TNI_ENTRY_SIZE;
}
/* Check to see if there were no more valid entries. */
if (i >= TX_EL_TNIS)
return(TX_EL_NO_MORE_TNI_ROOM);
/* Otherwise, we have room in the TNI and a valid record. */
/* Setup the thread's name. */
work_ptr = entry_ptr;
read_ptr = (UCHAR *) thread_ptr -> tx_thread_name;
i = 0;
while ((i < TX_EL_TNI_NAME_SIZE) && (*read_ptr))
{
/* Copy a character of thread's name into TNI area of log. */
*work_ptr++ = *read_ptr++;
/* Increment the character count. */
i++;
}
/* Determine if a NULL needs to be inserted. */
if (i < TX_EL_TNI_NAME_SIZE)
{
/* Yes, insert a NULL into the event log string. */
*work_ptr = (unsigned char) 0;
}
/* Setup the thread ID. */
*((ULONG *) (entry_ptr + TX_EL_TNI_THREAD_ID_OFFSET)) = (ULONG) thread_ptr;
/* Setup the thread priority. */
*((ULONG *) (entry_ptr + TX_EL_TNI_THREAD_PRIORITY_OFF)) = (ULONG) thread_ptr -> tx_thread_priority;
/* Set the valid field to indicate the entry is complete. */
*((UCHAR *) (entry_ptr + TX_EL_TNI_VALID_OFFSET)) = (ULONG) TX_EL_VALID_ENTRY;
/* Thread name has been registered. */
return(TX_SUCCESS);
}
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _tx_el_thread_unregister PORTABLE C */
/* 6.1 */
/* AUTHOR */
/* */
/* William E. Lamie, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function unregisters a thread in the event log for future */
/* display purposes. */
/* */
/* INPUT */
/* */
/* thread_ptr Pointer to thread control block */
/* */
/* OUTPUT */
/* */
/* TX_SUCCESS Thread was placed in TNI area */
/* TX_ERROR No more room in the TNI area */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* _tx_thread_create ThreadX thread create function */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */
/* 09-30-2020 William E. Lamie Initial Version 6.1 */
/* */
/**************************************************************************/
UINT _tx_el_thread_unregister(TX_THREAD *thread_ptr)
{
UCHAR *entry_ptr;
UCHAR *work_ptr;
UCHAR *read_ptr;
UINT found;
UINT i, j;
/* First of all, search for a match in the TNI area. */
entry_ptr = _tx_el_tni_start;
i = 0;
while (i < TX_EL_TNIS)
{
/* Determine if this entry is a match. */
work_ptr = entry_ptr;
read_ptr = (UCHAR *) thread_ptr -> tx_thread_name;
found = TX_TRUE;
j = 0;
do
{
/* Determine if this character is the same. */
if (*work_ptr != *read_ptr)
{
/* Set found to false and fall out of the loop. */
found = TX_FALSE;
break;
}
else if (*work_ptr == 0)
{
/* Null terminated, just break the loop. */
break;
}
else
{
/* Copy a character of thread's name into TNI area of log. */
*work_ptr++ = *read_ptr++;
}
/* Increment the character count. */
j++;
} while(j < TX_EL_TNIS);
/* Was a match found? */
if (found)
{
/* Yes, mark the entry as available now. */
*(entry_ptr + TX_EL_TNI_VALID_OFFSET) = TX_EL_INVALID_ENTRY;
/* Get out of the loop! */
break;
}
/* Otherwise, increment the associated pointers and indices. */
i++;
entry_ptr = entry_ptr + TX_EL_TNI_ENTRY_SIZE;
}
/* Determine status to return. */
if (found)
return(TX_SUCCESS);
else
return(TX_EL_NAME_NOT_FOUND);
}
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _tx_el_user_event_insert PORTABLE C */
/* 6.1 */
/* AUTHOR */
/* */
/* William E. Lamie, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function inserts a user event into the event log. */
/* If the event log is full, the oldest event is overwritten. */
/* */
/* INPUT */
/* */
/* sub_type Event subtype for kernel call */
/* info_1 First information field */
/* info_2 Second information field */
/* info_3 Third information field */
/* info_4 Fourth information field */
/* */
/* OUTPUT */
/* */
/* None */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* ThreadX services */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */
/* 09-30-2020 William E. Lamie Initial Version 6.1 */
/* */
/**************************************************************************/
VOID _tx_el_user_event_insert(UINT sub_type, ULONG info_1, ULONG info_2,
ULONG info_3, ULONG info_4)
{
TX_INTERRUPT_SAVE_AREA
UINT upper_tb;
UCHAR *entry_ptr;
/* Disable interrupts. */
TX_DISABLE
/* Increment total event counter. */
_tx_el_total_events++;
/* Setup working entry pointer first. */
entry_ptr = *_tx_el_current_event;
/* Store the event type. */
*((unsigned short *) entry_ptr) = (unsigned short) TX_EL_USER_EVENT;
/* Store the event subtype. */
*((unsigned short *) (entry_ptr + TX_EL_EVENT_SUBTYPE_OFFSET)) =
(unsigned short) sub_type;
/* Get time stamp. */
do
{
/* Pickup the upper tb. */
upper_tb = (ULONG) read_tbu();
/* Store the upper time stamp. */
*((ULONG *) (entry_ptr + TX_EL_EVENT_TIME_UPPER_OFFSET)) =
(ULONG) upper_tb;
/* Store the lower time stamp. */
*((ULONG *) (entry_ptr + TX_EL_EVENT_TIME_LOWER_OFFSET)) =
(ULONG) read_tbl();
} while (upper_tb != (ULONG) read_tbu());
/* Store the current thread. */
*((ULONG *) (entry_ptr + TX_EL_EVENT_THREAD_OFFSET)) =
(ULONG) _tx_thread_current_ptr;
/* Store the first info field. */
*((ULONG *) (entry_ptr + TX_EL_EVENT_INFO_1_OFFSET)) =
(ULONG) info_1;
/* Store the second info field. */
*((ULONG *) (entry_ptr + TX_EL_EVENT_INFO_2_OFFSET)) =
(ULONG) info_2;
/* Store the third info field. */
*((ULONG *) (entry_ptr + TX_EL_EVENT_INFO_3_OFFSET)) =
(ULONG) info_3;
/* Store the fourth info field. */
*((ULONG *) (entry_ptr + TX_EL_EVENT_INFO_4_OFFSET)) =
(ULONG) info_4;
/* Now move the current event log pointer. */
entry_ptr = entry_ptr + TX_EL_EVENT_SIZE;
/* Check for a wraparound condition. */
if (entry_ptr >= _tx_el_event_area_end)
{
/* Yes, we have wrapped around to the end of the event area.
Start back at the top! */
entry_ptr = _tx_el_event_area_start;
}
/* Write the entry pointer back into the header. */
*_tx_el_current_event = entry_ptr;
/* Restore interrupts. */
TX_RESTORE
}
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _tx_el_thread_running PORTABLE C */
/* 6.1 */
/* AUTHOR */
/* */
/* William E. Lamie, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function inserts a thread change event into the event */
/* log, which indicates that a context switch is taking place. */
/* If the event log is full, the oldest event is overwritten. */
/* */
/* INPUT */
/* */
/* thread_ptr Pointer to thread being */
/* scheduled */
/* */
/* OUTPUT */
/* */
/* None */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* _tx_thread_schedule ThreadX scheduler */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */
/* 09-30-2020 William E. Lamie Initial Version 6.1 */
/* */
/**************************************************************************/
VOID _tx_el_thread_running(TX_THREAD *thread_ptr)
{
UINT upper_tb;
UCHAR *entry_ptr;
TX_EL_NO_STATUS_EVENTS
/* Increment total event counter. */
_tx_el_total_events++;
/* Setup working entry pointer first. */
entry_ptr = *_tx_el_current_event;
/* Store the event type. */
*((unsigned short *) entry_ptr) = (unsigned short) TX_EL_THREAD_CHANGE;
/* Store the event subtype. */
*((unsigned short *) (entry_ptr + TX_EL_EVENT_SUBTYPE_OFFSET)) =
(unsigned short) 0;
/* Get time stamp. */
do
{
/* Pickup the upper tb. */
upper_tb = (ULONG) read_tbu();
/* Store the upper time stamp. */
*((ULONG *) (entry_ptr + TX_EL_EVENT_TIME_UPPER_OFFSET)) =
(ULONG) upper_tb;
/* Store the lower time stamp. */
*((ULONG *) (entry_ptr + TX_EL_EVENT_TIME_LOWER_OFFSET)) =
(ULONG) read_tbl();
} while (upper_tb != (ULONG) read_tbu());
/* Store the current thread. */
*((ULONG *) (entry_ptr + TX_EL_EVENT_THREAD_OFFSET)) =
(ULONG) thread_ptr;
/* Now move the current event log pointer. */
entry_ptr = entry_ptr + TX_EL_EVENT_SIZE;
/* Check for a wraparound condition. */
if (entry_ptr >= _tx_el_event_area_end)
{
/* Yes, we have wrapped around to the end of the event area.
Start back at the top! */
entry_ptr = _tx_el_event_area_start;
}
/* Write the entry pointer back into the header. */
*_tx_el_current_event = entry_ptr;
TX_EL_END_FILTER
}
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _tx_el_thread_preempted PORTABLE C */
/* 6.1 */
/* AUTHOR */
/* */
/* William E. Lamie, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function inserts a thread preempted event into the event */
/* log, which indicates that an interrupt occurred that made a higher */
/* priority thread ready for execution. In this case, the previously */
/* executing thread has an event entered to indicate it is no longer */
/* running. */
/* */
/* INPUT */
/* */
/* thread_ptr Pointer to thread being */
/* scheduled */
/* */
/* OUTPUT */
/* */
/* None */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* _tx_thread_context_restore ThreadX context restore */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */
/* 09-30-2020 William E. Lamie Initial Version 6.1 */
/* */
/**************************************************************************/
VOID _tx_el_thread_preempted(TX_THREAD *thread_ptr)
{
UINT upper_tb;
UCHAR *entry_ptr;
TX_EL_NO_STATUS_EVENTS
/* Increment total event counter. */
_tx_el_total_events++;
/* Setup working entry pointer first. */
entry_ptr = *_tx_el_current_event;
/* Store the event type. */
*((unsigned short *) entry_ptr) = (unsigned short) TX_EL_THREAD_STATUS_CHANGE;
/* Store the event subtype. */
*((unsigned short *) (entry_ptr + TX_EL_EVENT_SUBTYPE_OFFSET)) =
(unsigned short) TX_READY;
/* Get time stamp. */
do
{
/* Pickup the upper tb. */
upper_tb = (ULONG) read_tbu();
/* Store the upper time stamp. */
*((ULONG *) (entry_ptr + TX_EL_EVENT_TIME_UPPER_OFFSET)) =
(ULONG) upper_tb;
/* Store the lower time stamp. */
*((ULONG *) (entry_ptr + TX_EL_EVENT_TIME_LOWER_OFFSET)) =
(ULONG) read_tbl();
} while (upper_tb != (ULONG) read_tbu());
/* Store the current thread. */
*((ULONG *) (entry_ptr + TX_EL_EVENT_THREAD_OFFSET)) =
(ULONG) _tx_thread_current_ptr;
/* Now move the current event log pointer. */
entry_ptr = entry_ptr + TX_EL_EVENT_SIZE;
/* Check for a wraparound condition. */
if (entry_ptr >= _tx_el_event_area_end)
{
/* Yes, we have wrapped around to the end of the event area.
Start back at the top! */
entry_ptr = _tx_el_event_area_start;
}
/* Write the entry pointer back into the header. */
*_tx_el_current_event = entry_ptr;
TX_EL_END_FILTER
}
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _tx_el_interrupt PORTABLE C */
/* 6.1 */
/* AUTHOR */
/* */
/* William E. Lamie, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function inserts an interrupt event into the log, which */
/* indicates the start of interrupt processing for the specific */
/* */
/* INPUT */
/* */
/* interrupt_number Interrupt number supplied by */
/* ISR */
/* */
/* OUTPUT */
/* */
/* None */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* ISR processing */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */
/* 09-30-2020 William E. Lamie Initial Version 6.1 */
/* */
/**************************************************************************/
VOID _tx_el_interrupt(UINT interrupt_number)
{
UINT upper_tb;
UCHAR *entry_ptr;
TX_EL_NO_INTERRUPT_EVENTS
/* Increment total event counter. */
_tx_el_total_events++;
/* Setup working entry pointer first. */
entry_ptr = *_tx_el_current_event;
/* Store the event type. */
*((unsigned short *) entry_ptr) = (unsigned short) TX_EL_INTERRUPT;
/* Store the event subtype. */
*((unsigned short *) (entry_ptr + TX_EL_EVENT_SUBTYPE_OFFSET)) =
(unsigned short) TX_EL_INTERRUPT_SUB_TYPE;
/* Get time stamp. */
do
{
/* Pickup the upper tb. */
upper_tb = (ULONG) read_tbu();
/* Store the upper time stamp. */
*((ULONG *) (entry_ptr + TX_EL_EVENT_TIME_UPPER_OFFSET)) =
(ULONG) upper_tb;
/* Store the lower time stamp. */
*((ULONG *) (entry_ptr + TX_EL_EVENT_TIME_LOWER_OFFSET)) =
(ULONG) read_tbl();
} while (upper_tb != (ULONG) read_tbu());
/* Store the current thread. */
*((ULONG *) (entry_ptr + TX_EL_EVENT_THREAD_OFFSET)) =
(ULONG) _tx_thread_current_ptr;
/* Store the first info word. */
*((ULONG *) (entry_ptr + TX_EL_EVENT_INFO_1_OFFSET)) =
(ULONG) interrupt_number;
/* Now move the current event log pointer. */
entry_ptr = entry_ptr + TX_EL_EVENT_SIZE;
/* Check for a wraparound condition. */
if (entry_ptr >= _tx_el_event_area_end)
{
/* Yes, we have wrapped around to the end of the event area.
Start back at the top! */
entry_ptr = _tx_el_event_area_start;
}
/* Write the entry pointer back into the header. */
*_tx_el_current_event = entry_ptr;
TX_EL_END_FILTER
}
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _tx_el_interrupt_end PORTABLE C */
/* 6.1 */
/* AUTHOR */
/* */
/* William E. Lamie, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function inserts an interrupt end event into the log, which */
/* indicates the end of interrupt processing for the specific */
/* */
/* INPUT */
/* */
/* interrupt_number Interrupt number supplied by */
/* ISR */
/* */
/* OUTPUT */
/* */
/* None */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* ISR processing */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */
/* 09-30-2020 William E. Lamie Initial Version 6.1 */
/* */
/**************************************************************************/
VOID _tx_el_interrupt_end(UINT interrupt_number)
{
UINT upper_tb;
UCHAR *entry_ptr;
TX_EL_NO_INTERRUPT_EVENTS
/* Increment total event counter. */
_tx_el_total_events++;
/* Setup working entry pointer first. */
entry_ptr = *_tx_el_current_event;
/* Store the event type. */
*((unsigned short *) entry_ptr) = (unsigned short) TX_EL_INTERRUPT;
/* Store the event subtype. */
*((unsigned short *) (entry_ptr + TX_EL_EVENT_SUBTYPE_OFFSET)) =
(unsigned short) TX_EL_END_OF_INTERRUPT;
/* Get time stamp. */
do
{
/* Pickup the upper tb. */
upper_tb = (ULONG) read_tbu();
/* Store the upper time stamp. */
*((ULONG *) (entry_ptr + TX_EL_EVENT_TIME_UPPER_OFFSET)) =
(ULONG) upper_tb;
/* Store the lower time stamp. */
*((ULONG *) (entry_ptr + TX_EL_EVENT_TIME_LOWER_OFFSET)) =
(ULONG) read_tbl();
} while (upper_tb != (ULONG) read_tbu());
/* Store the current thread. */
*((ULONG *) (entry_ptr + TX_EL_EVENT_THREAD_OFFSET)) =
(ULONG) _tx_thread_current_ptr;
/* Store the first info word. */
*((ULONG *) (entry_ptr + TX_EL_EVENT_INFO_1_OFFSET)) =
(ULONG) interrupt_number;
/* Now move the current event log pointer. */
entry_ptr = entry_ptr + TX_EL_EVENT_SIZE;
/* Check for a wraparound condition. */
if (entry_ptr >= _tx_el_event_area_end)
{
/* Yes, we have wrapped around to the end of the event area.
Start back at the top! */
entry_ptr = _tx_el_event_area_start;
}
/* Write the entry pointer back into the header. */
*_tx_el_current_event = entry_ptr;
TX_EL_END_FILTER
}
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _tx_el_interrupt_control PORTABLE C */
/* 6.1 */
/* AUTHOR */
/* */
/* William E. Lamie, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function remaps the tx_interrupt_control service call so that */
/* it can be tracked in the event log. */
/* */
/* INPUT */
/* */
/* new_posture New interrupt posture */
/* */
/* OUTPUT */
/* */
/* old_posture Old interrupt posture */
/* */
/* CALLS */
/* */
/* _tx_thread_interrupt_control Interrupt control service */
/* */
/* CALLED BY */
/* */
/* ThreadX services */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */
/* 09-30-2020 William E. Lamie Initial Version 6.1 */
/* */
/**************************************************************************/
UINT _tx_el_interrupt_control(UINT new_posture)
{
TX_INTERRUPT_SAVE_AREA
UINT old_posture;
TX_EL_NO_INTERRUPT_EVENTS
TX_DISABLE
TX_EL_KERNEL_CALL_EVENT_INSERT_INFO2(TX_EL_INTERRUPT_CONTROL, _tx_thread_current_ptr, new_posture)
TX_RESTORE
TX_EL_END_FILTER
old_posture = _tx_thread_interrupt_control(new_posture);
return(old_posture);
}
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _tx_el_event_log_on PORTABLE C */
/* 6.1 */
/* AUTHOR */
/* */
/* William E. Lamie, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function disables all event filters. */
/* */
/* INPUT */
/* */
/* None */
/* */
/* OUTPUT */
/* */
/* None */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* Application code */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */
/* 09-30-2020 William E. Lamie Initial Version 6.1 */
/* */
/**************************************************************************/
VOID _tx_el_event_log_on(void)
{
/* Disable all event filters. */
_tx_el_event_filter = TX_EL_ENABLE_ALL_EVENTS;
}
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _tx_el_event_log_off PORTABLE C */
/* 6.1 */
/* AUTHOR */
/* */
/* William E. Lamie, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function sets all event filters, thereby turning event */
/* logging off. */
/* */
/* INPUT */
/* */
/* None */
/* */
/* OUTPUT */
/* */
/* None */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* Application code */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */
/* 09-30-2020 William E. Lamie Initial Version 6.1 */
/* */
/**************************************************************************/
VOID _tx_el_event_log_off(void)
{
/* Set all event filters. */
_tx_el_event_filter = TX_EL_FILTER_ALL_EVENTS;
}
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _tx_el_event_log_set PORTABLE C */
/* 6.1 */
/* AUTHOR */
/* */
/* William E. Lamie, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function sets the events filters specified by the user. */
/* */
/* INPUT */
/* */
/* filter Events to filter */
/* */
/* OUTPUT */
/* */
/* None */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* Application code */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */
/* 09-30-2020 William E. Lamie Initial Version 6.1 */
/* */
/**************************************************************************/
VOID _tx_el_event_filter_set(UINT filter)
{
/* Apply the user event filter. */
_tx_el_event_filter = filter;
}
|