-
Notifications
You must be signed in to change notification settings - Fork 207
/
cfe_es_task.c
2077 lines (1777 loc) · 79.9 KB
/
cfe_es_task.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
/*
** GSC-18128-1, "Core Flight Executive Version 6.7"
**
** Copyright (c) 2006-2019 United States Government as represented by
** the Administrator of the National Aeronautics and Space Administration.
** All Rights Reserved.
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
/*
** File: cfe_es_task.c
**
** Purpose:
** cFE Executive Services (ES) task
**
** References:
** Flight Software Branch C Coding Standard Version 1.0a
** cFE Flight Software Application Developers Guide
**
** Notes:
**
*/
/*
** Includes
*/
#include "cfe_es_module_all.h"
#include "cfe_version.h"
#include "target_config.h"
#include <string.h>
/*
** Defines
*/
#define CFE_ES_PERF_TRIGGERMASK_INT_SIZE \
(sizeof(CFE_ES_Global.ResetDataPtr->Perf.MetaData.TriggerMask) / sizeof(uint32))
#define CFE_ES_PERF_TRIGGERMASK_EXT_SIZE \
(sizeof(CFE_ES_Global.TaskData.HkPacket.Payload.PerfTriggerMask) / sizeof(uint32))
#define CFE_ES_PERF_FILTERMASK_INT_SIZE (sizeof(CFE_ES_Global.ResetDataPtr->Perf.MetaData.FilterMask) / sizeof(uint32))
#define CFE_ES_PERF_FILTERMASK_EXT_SIZE \
(sizeof(CFE_ES_Global.TaskData.HkPacket.Payload.PerfFilterMask) / sizeof(uint32))
/*
** This define should be put in the OS API headers -- Right now it matches what the OS API uses
*/
#define OS_MAX_PRIORITY 255
/*
** Executive Services (ES) task global data.
*/
CFE_ES_TaskData_t CFE_ES_TaskData;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* CFE_ES_TaskMain() -- Task entry point and main process loop */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void CFE_ES_TaskMain(void)
{
int32 Status;
uint32 AppRunStatus = CFE_ES_RunStatus_APP_RUN;
CFE_SB_Buffer_t *SBBufPtr;
/*
** Performance Time Stamp Entry
*/
CFE_ES_PerfLogEntry(CFE_MISSION_ES_MAIN_PERF_ID);
/*
** Perform task specific initialization.
*/
Status = CFE_ES_TaskInit();
if (Status != CFE_SUCCESS)
{
/*
** Create a syslog entry
*/
CFE_ES_WriteToSysLog("ES:Application Init Failed,RC=0x%08X\n", (unsigned int)Status);
/*
** Allow Core App to Exit
*/
AppRunStatus = CFE_ES_RunStatus_CORE_APP_INIT_ERROR;
} /* end if */
/*
* Wait for other apps to start.
* It is important that the core apps are present before this starts receiving
* messages from the command pipe, as some of those handlers might depend on
* the other core apps.
*/
CFE_ES_WaitForSystemState(CFE_ES_SystemState_CORE_READY, CFE_PLATFORM_CORE_MAX_STARTUP_MSEC);
/*
** Main process loop
*/
while (AppRunStatus == CFE_ES_RunStatus_APP_RUN)
{
/*
** Increment the main task execution counter
** This is normally done in the CFE_ES_RunLoop call, but
** currently CFE Child tasks and the cFE core tasks do not
** use the RunLoop call.
*/
CFE_ES_IncrementTaskCounter();
/*
** Performance Time Stamp Exit
*/
CFE_ES_PerfLogExit(CFE_MISSION_ES_MAIN_PERF_ID);
/*
** Wait for the next Software Bus message.
*/
Status = CFE_SB_ReceiveBuffer(&SBBufPtr, CFE_ES_Global.TaskData.CmdPipe, CFE_SB_PEND_FOREVER);
/*
** Performance Time Stamp Entry
*/
CFE_ES_PerfLogEntry(CFE_MISSION_ES_MAIN_PERF_ID);
if (Status == CFE_SUCCESS)
{
/*
** Process message.
*/
CFE_ES_TaskPipe(SBBufPtr);
/*
* Wake up the background task, which includes the
* scanning of the ES app table for entries that may need cleanup
*/
CFE_ES_BackgroundWakeup();
}
else
{
/*
** SB Error: Write a SysLog Message
*/
CFE_ES_WriteToSysLog("ES:Error reading cmd pipe,RC=0x%08X\n", (unsigned int)Status);
/*
** Allow Core App to Exit
*/
AppRunStatus = CFE_ES_RunStatus_CORE_APP_RUNTIME_ERROR;
} /* end if */
} /* end while */
/*
** Performance Time Stamp Exit
*/
CFE_ES_PerfLogExit(CFE_MISSION_ES_MAIN_PERF_ID);
/*
** Exit the application, CFE_ES_ExitApp will not return.
*/
CFE_ES_ExitApp(AppRunStatus);
} /* End of CFE_ES_TaskMain() */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* CFE_ES_FindConfigKeyValue() -- Find value for given config key */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
const char *CFE_ES_FindConfigKeyValue(const CFE_ConfigKeyValue_t *ConfigList, const char *KeyName)
{
const char *ValuePtr;
ValuePtr = NULL;
if (KeyName != NULL && ConfigList != NULL)
{
while (ConfigList->Key != NULL)
{
if (strcmp(KeyName, ConfigList->Key) == 0)
{
ValuePtr = ConfigList->Value;
break;
}
++ConfigList;
}
}
return ValuePtr;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* CFE_ES_GenerateSingleVersionEvent() -- Send CFE_ES_VERSION_INF_EID */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 CFE_ES_GenerateSingleVersionEvent(const char *ModuleType, const char *ModuleName)
{
int32 Status;
const char *VersionString;
/* The mission version which should appear in the version list under the mission name */
VersionString = CFE_ES_FindConfigKeyValue(GLOBAL_CONFIGDATA.ModuleVersionList, ModuleName);
/* If NULL that means the source code was either uncontrolled or there was no way to determine its version */
if (VersionString == NULL)
{
VersionString = "[unknown]";
}
/*
* Advertise the mission version information
*/
Status = CFE_EVS_SendEvent(CFE_ES_VERSION_INF_EID, CFE_EVS_EventType_INFORMATION, "Version Info: %s %s, version %s",
ModuleType, ModuleName, VersionString);
return Status;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* CFE_ES_GenerateVersionEvents() -- Send CFE_ES_VERSION_INF_EID's */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void CFE_ES_GenerateVersionEvents(void)
{
int32 Status;
CFE_ConfigName_t * ModuleNamePtr;
CFE_StaticModuleLoadEntry_t *StaticModulePtr;
/*
* Advertise the mission version information
*/
Status = CFE_ES_GenerateSingleVersionEvent("Mission", GLOBAL_CONFIGDATA.MissionName);
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("ES:Error sending mission version event:RC=0x%08X\n", (unsigned int)Status);
}
/*
* Also Advertise the version information for all statically-linked core modules.
* Send a separate CFE_ES_VERSION_INF_EID for every component.
*/
ModuleNamePtr = GLOBAL_CONFIGDATA.CoreModuleList;
if (ModuleNamePtr != NULL)
{
while (Status == CFE_SUCCESS && ModuleNamePtr->Name != NULL)
{
Status = CFE_ES_GenerateSingleVersionEvent("Core Module", ModuleNamePtr->Name);
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("ES:Error sending core module version event:RC=0x%08X\n", (unsigned int)Status);
}
++ModuleNamePtr;
}
}
/*
* Advertise PSP module versions
*/
StaticModulePtr = GLOBAL_CONFIGDATA.PspModuleList;
if (StaticModulePtr != NULL)
{
while (Status == CFE_SUCCESS && StaticModulePtr->Name != NULL)
{
Status = CFE_ES_GenerateSingleVersionEvent("PSP Module", StaticModulePtr->Name);
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("ES:Error sending PSP module version event:RC=0x%08X\n", (unsigned int)Status);
}
++StaticModulePtr;
}
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* CFE_ES_GenerateBuildInfoEvents() -- Send CFE_ES_BUILD_INF_EID */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void CFE_ES_GenerateBuildInfoEvents(void)
{
int32 Status;
const char *BuildDate;
const char *BuildUser;
const char *BuildHost;
BuildDate = CFE_ES_FindConfigKeyValue(GLOBAL_CONFIGDATA.BuildEnvironment, "BUILDDATE");
BuildUser = CFE_ES_FindConfigKeyValue(GLOBAL_CONFIGDATA.BuildEnvironment, "BUILDUSER");
BuildHost = CFE_ES_FindConfigKeyValue(GLOBAL_CONFIGDATA.BuildEnvironment, "BUILDHOST");
/* Ensure all strings are set to something non-NULL */
if (BuildDate == NULL)
{
BuildDate = "[unknown]";
}
if (BuildUser == NULL)
{
BuildUser = "[unknown]";
}
if (BuildHost == NULL)
{
BuildHost = "[unknown]";
}
Status = CFE_EVS_SendEvent(CFE_ES_BUILD_INF_EID, CFE_EVS_EventType_INFORMATION, "Build %s by %s@%s, config %s",
BuildDate, BuildUser, BuildHost, GLOBAL_CONFIGDATA.Config);
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("ES:Error sending build info event:RC=0x%08X\n", (unsigned int)Status);
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* CFE_ES_TaskInit() -- ES task initialization */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 CFE_ES_TaskInit(void)
{
int32 Status;
uint32 SizeofCfeSegment;
cpuaddr CfeSegmentAddr;
uint8 VersionNumber[4];
/*
** Initialize task command execution counters
*/
CFE_ES_Global.TaskData.CommandCounter = 0;
CFE_ES_Global.TaskData.CommandErrorCounter = 0;
/*
** Initialize systemlog to default Power On or Processor Reset mode
*/
if (CFE_ES_GetResetType(NULL) == CFE_PSP_RST_TYPE_POWERON)
{
CFE_ES_Global.ResetDataPtr->SystemLogMode = CFE_PLATFORM_ES_DEFAULT_POR_SYSLOG_MODE;
}
else
{
CFE_ES_Global.ResetDataPtr->SystemLogMode = CFE_PLATFORM_ES_DEFAULT_PR_SYSLOG_MODE;
}
/*
** Register event filter table.
*/
Status = CFE_EVS_Register(NULL, 0, CFE_EVS_EventFilter_BINARY);
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("ES:Call to CFE_EVS_Register Failed, RC = 0x%08X\n", (unsigned int)Status);
return (Status);
}
/*
** Initialize housekeeping packet (clear user data area)
*/
CFE_MSG_Init(&CFE_ES_Global.TaskData.HkPacket.TlmHeader.Msg, CFE_SB_ValueToMsgId(CFE_ES_HK_TLM_MID),
sizeof(CFE_ES_Global.TaskData.HkPacket));
/*
** Initialize single application telemetry packet
*/
CFE_MSG_Init(&CFE_ES_Global.TaskData.OneAppPacket.TlmHeader.Msg, CFE_SB_ValueToMsgId(CFE_ES_APP_TLM_MID),
sizeof(CFE_ES_Global.TaskData.OneAppPacket));
/*
** Initialize memory pool statistics telemetry packet
*/
CFE_MSG_Init(&CFE_ES_Global.TaskData.MemStatsPacket.TlmHeader.Msg, CFE_SB_ValueToMsgId(CFE_ES_MEMSTATS_TLM_MID),
sizeof(CFE_ES_Global.TaskData.MemStatsPacket));
/*
** Create Software Bus message pipe
*/
Status = CFE_SB_CreatePipe(&CFE_ES_Global.TaskData.CmdPipe, CFE_ES_PIPE_DEPTH, CFE_ES_PIPE_NAME);
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("ES:Cannot Create SB Pipe, RC = 0x%08X\n", (unsigned int)Status);
return (Status);
}
/*
** Subscribe to Housekeeping request commands
*/
Status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(CFE_ES_SEND_HK_MID), CFE_ES_Global.TaskData.CmdPipe);
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("ES:Cannot Subscribe to HK packet, RC = 0x%08X\n", (unsigned int)Status);
return (Status);
}
/*
** Subscribe to ES task ground command packets
*/
Status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(CFE_ES_CMD_MID), CFE_ES_Global.TaskData.CmdPipe);
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("ES:Cannot Subscribe to ES ground commands, RC = 0x%08X\n", (unsigned int)Status);
return (Status);
}
/*
** Compute the CRC for the cfe core code segment and place
** in ES Housekeeping pkt.
*/
Status = CFE_PSP_GetCFETextSegmentInfo(&CfeSegmentAddr, &SizeofCfeSegment);
if (Status == CFE_PSP_SUCCESS)
{
CFE_ES_Global.TaskData.HkPacket.Payload.CFECoreChecksum =
CFE_ES_CalculateCRC((void *)(CfeSegmentAddr), SizeofCfeSegment, 0, CFE_MISSION_ES_DEFAULT_CRC);
}
else
{
CFE_ES_Global.TaskData.HkPacket.Payload.CFECoreChecksum = 0xFFFF;
}
/*
** Initialize the version numbers in the ES Housekeeping pkt
*/
CFE_ES_Global.TaskData.HkPacket.Payload.CFEMajorVersion = CFE_MAJOR_VERSION;
CFE_ES_Global.TaskData.HkPacket.Payload.CFEMinorVersion = CFE_MINOR_VERSION;
CFE_ES_Global.TaskData.HkPacket.Payload.CFERevision = CFE_REVISION;
CFE_ES_Global.TaskData.HkPacket.Payload.CFEMissionRevision = CFE_MISSION_REV;
OS_GetVersionNumber(VersionNumber);
CFE_ES_Global.TaskData.HkPacket.Payload.OSALMajorVersion = VersionNumber[0];
CFE_ES_Global.TaskData.HkPacket.Payload.OSALMinorVersion = VersionNumber[1];
CFE_ES_Global.TaskData.HkPacket.Payload.OSALRevision = VersionNumber[2];
CFE_ES_Global.TaskData.HkPacket.Payload.OSALMissionRevision = VersionNumber[3];
CFE_PSP_GetVersionNumber(VersionNumber);
CFE_ES_Global.TaskData.HkPacket.Payload.PSPMajorVersion = VersionNumber[0];
CFE_ES_Global.TaskData.HkPacket.Payload.PSPMinorVersion = VersionNumber[1];
CFE_ES_Global.TaskData.HkPacket.Payload.PSPRevision = VersionNumber[2];
CFE_ES_Global.TaskData.HkPacket.Payload.PSPMissionRevision = VersionNumber[3];
/*
** Task startup event message.
*/
Status = CFE_EVS_SendEvent(CFE_ES_INIT_INF_EID, CFE_EVS_EventType_INFORMATION, "cFE ES Initialized");
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("ES:Error sending init event:RC=0x%08X\n", (unsigned int)Status);
return (Status);
}
Status =
CFE_EVS_SendEvent(CFE_ES_INITSTATS_INF_EID, CFE_EVS_EventType_INFORMATION,
"cFS Versions: cfe %s, osal %s, psp %s. cFE chksm %d", CFE_SRC_VERSION, OS_GetVersionString(),
CFE_PSP_GetVersionString(), (int)CFE_ES_Global.TaskData.HkPacket.Payload.CFECoreChecksum);
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("ES:Error sending init stats event:RC=0x%08X\n", (unsigned int)Status);
return (Status);
}
/*
* Generate all module version and build info events.
*/
CFE_ES_GenerateVersionEvents();
CFE_ES_GenerateBuildInfoEvents();
/*
* Initialize the "background task" which is a low priority child task
* devoted to maintence duties that do not need to execute on a
* strict/precise schedule.
*/
Status = CFE_ES_BackgroundInit();
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("ES:Error initializing background task:RC=0x%08X\n", (unsigned int)Status);
return (Status);
}
return (CFE_SUCCESS);
} /* End of CFE_ES_TaskInit() */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* CFE_ES_TaskPipe() -- Process command pipe message */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void CFE_ES_TaskPipe(CFE_SB_Buffer_t *SBBufPtr)
{
CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID;
CFE_MSG_FcnCode_t CommandCode = 0;
CFE_MSG_GetMsgId(&SBBufPtr->Msg, &MessageID);
switch (CFE_SB_MsgIdToValue(MessageID))
{
/*
** Housekeeping telemetry request
*/
case CFE_ES_SEND_HK_MID:
CFE_ES_HousekeepingCmd((CFE_MSG_CommandHeader_t *)SBBufPtr);
break;
/*
** ES task ground commands
*/
case CFE_ES_CMD_MID:
CFE_MSG_GetFcnCode(&SBBufPtr->Msg, &CommandCode);
switch (CommandCode)
{
case CFE_ES_NOOP_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_NoopCmd_t)))
{
CFE_ES_NoopCmd((CFE_ES_NoopCmd_t *)SBBufPtr);
}
break;
case CFE_ES_RESET_COUNTERS_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_ResetCountersCmd_t)))
{
CFE_ES_ResetCountersCmd((CFE_ES_ResetCountersCmd_t *)SBBufPtr);
}
break;
case CFE_ES_RESTART_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_RestartCmd_t)))
{
CFE_ES_RestartCmd((CFE_ES_RestartCmd_t *)SBBufPtr);
}
break;
case CFE_ES_START_APP_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_StartAppCmd_t)))
{
CFE_ES_StartAppCmd((CFE_ES_StartAppCmd_t *)SBBufPtr);
}
break;
case CFE_ES_STOP_APP_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_StopAppCmd_t)))
{
CFE_ES_StopAppCmd((CFE_ES_StopAppCmd_t *)SBBufPtr);
}
break;
case CFE_ES_RESTART_APP_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_RestartAppCmd_t)))
{
CFE_ES_RestartAppCmd((CFE_ES_RestartAppCmd_t *)SBBufPtr);
}
break;
case CFE_ES_RELOAD_APP_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_ReloadAppCmd_t)))
{
CFE_ES_ReloadAppCmd((CFE_ES_ReloadAppCmd_t *)SBBufPtr);
}
break;
case CFE_ES_QUERY_ONE_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_QueryOneCmd_t)))
{
CFE_ES_QueryOneCmd((CFE_ES_QueryOneCmd_t *)SBBufPtr);
}
break;
case CFE_ES_QUERY_ALL_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_QueryAllCmd_t)))
{
CFE_ES_QueryAllCmd((CFE_ES_QueryAllCmd_t *)SBBufPtr);
}
break;
case CFE_ES_QUERY_ALL_TASKS_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_QueryAllTasksCmd_t)))
{
CFE_ES_QueryAllTasksCmd((CFE_ES_QueryAllTasksCmd_t *)SBBufPtr);
}
break;
case CFE_ES_CLEAR_SYSLOG_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_ClearSysLogCmd_t)))
{
CFE_ES_ClearSysLogCmd((CFE_ES_ClearSysLogCmd_t *)SBBufPtr);
}
break;
case CFE_ES_WRITE_SYSLOG_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_WriteSysLogCmd_t)))
{
CFE_ES_WriteSysLogCmd((CFE_ES_WriteSysLogCmd_t *)SBBufPtr);
}
break;
case CFE_ES_OVER_WRITE_SYSLOG_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_OverWriteSysLogCmd_t)))
{
CFE_ES_OverWriteSysLogCmd((CFE_ES_OverWriteSysLogCmd_t *)SBBufPtr);
}
break;
case CFE_ES_CLEAR_ER_LOG_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_ClearERLogCmd_t)))
{
CFE_ES_ClearERLogCmd((CFE_ES_ClearERLogCmd_t *)SBBufPtr);
}
break;
case CFE_ES_WRITE_ER_LOG_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_WriteERLogCmd_t)))
{
CFE_ES_WriteERLogCmd((CFE_ES_WriteERLogCmd_t *)SBBufPtr);
}
break;
case CFE_ES_START_PERF_DATA_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_StartPerfDataCmd_t)))
{
CFE_ES_StartPerfDataCmd((CFE_ES_StartPerfDataCmd_t *)SBBufPtr);
}
break;
case CFE_ES_STOP_PERF_DATA_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_StopPerfDataCmd_t)))
{
CFE_ES_StopPerfDataCmd((CFE_ES_StopPerfDataCmd_t *)SBBufPtr);
}
break;
case CFE_ES_SET_PERF_FILTER_MASK_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_SetPerfFilterMaskCmd_t)))
{
CFE_ES_SetPerfFilterMaskCmd((CFE_ES_SetPerfFilterMaskCmd_t *)SBBufPtr);
}
break;
case CFE_ES_SET_PERF_TRIGGER_MASK_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_SetPerfTriggerMaskCmd_t)))
{
CFE_ES_SetPerfTriggerMaskCmd((CFE_ES_SetPerfTriggerMaskCmd_t *)SBBufPtr);
}
break;
case CFE_ES_RESET_PR_COUNT_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_ResetPRCountCmd_t)))
{
CFE_ES_ResetPRCountCmd((CFE_ES_ResetPRCountCmd_t *)SBBufPtr);
}
break;
case CFE_ES_SET_MAX_PR_COUNT_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_SetMaxPRCountCmd_t)))
{
CFE_ES_SetMaxPRCountCmd((CFE_ES_SetMaxPRCountCmd_t *)SBBufPtr);
}
break;
case CFE_ES_DELETE_CDS_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_DeleteCDSCmd_t)))
{
CFE_ES_DeleteCDSCmd((CFE_ES_DeleteCDSCmd_t *)SBBufPtr);
}
break;
case CFE_ES_SEND_MEM_POOL_STATS_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_SendMemPoolStatsCmd_t)))
{
CFE_ES_SendMemPoolStatsCmd((CFE_ES_SendMemPoolStatsCmd_t *)SBBufPtr);
}
break;
case CFE_ES_DUMP_CDS_REGISTRY_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_DumpCDSRegistryCmd_t)))
{
CFE_ES_DumpCDSRegistryCmd((CFE_ES_DumpCDSRegistryCmd_t *)SBBufPtr);
}
break;
default:
CFE_EVS_SendEvent(CFE_ES_CC1_ERR_EID, CFE_EVS_EventType_ERROR,
"Invalid ground command code: ID = 0x%X, CC = %d",
(unsigned int)CFE_SB_MsgIdToValue(MessageID), (int)CommandCode);
CFE_ES_Global.TaskData.CommandErrorCounter++;
break;
}
break;
default:
CFE_EVS_SendEvent(CFE_ES_MID_ERR_EID, CFE_EVS_EventType_ERROR, "Invalid command pipe message ID: 0x%X",
(unsigned int)CFE_SB_MsgIdToValue(MessageID));
CFE_ES_Global.TaskData.CommandErrorCounter++;
break;
}
} /* End of CFE_ES_TaskPipe() */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* CFE_ES_HousekeepingCmd() -- On-board command (HK request) */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 CFE_ES_HousekeepingCmd(const CFE_MSG_CommandHeader_t *data)
{
OS_heap_prop_t HeapProp;
int32 stat;
uint32 PerfIdx;
/*
** Get command execution counters, system log entry count & bytes used.
*/
CFE_ES_Global.TaskData.HkPacket.Payload.CommandCounter = CFE_ES_Global.TaskData.CommandCounter;
CFE_ES_Global.TaskData.HkPacket.Payload.CommandErrorCounter = CFE_ES_Global.TaskData.CommandErrorCounter;
CFE_ES_Global.TaskData.HkPacket.Payload.SysLogBytesUsed =
CFE_ES_MEMOFFSET_C(CFE_ES_Global.ResetDataPtr->SystemLogEndIdx);
CFE_ES_Global.TaskData.HkPacket.Payload.SysLogSize = CFE_ES_MEMOFFSET_C(CFE_PLATFORM_ES_SYSTEM_LOG_SIZE);
CFE_ES_Global.TaskData.HkPacket.Payload.SysLogEntries = CFE_ES_Global.ResetDataPtr->SystemLogEntryNum;
CFE_ES_Global.TaskData.HkPacket.Payload.SysLogMode = CFE_ES_Global.ResetDataPtr->SystemLogMode;
CFE_ES_Global.TaskData.HkPacket.Payload.ERLogIndex = CFE_ES_Global.ResetDataPtr->ERLogIndex;
CFE_ES_Global.TaskData.HkPacket.Payload.ERLogEntries = CFE_ES_Global.ResetDataPtr->ERLogEntries;
CFE_ES_Global.TaskData.HkPacket.Payload.RegisteredCoreApps = CFE_ES_Global.RegisteredCoreApps;
CFE_ES_Global.TaskData.HkPacket.Payload.RegisteredExternalApps = CFE_ES_Global.RegisteredExternalApps;
CFE_ES_Global.TaskData.HkPacket.Payload.RegisteredTasks = CFE_ES_Global.RegisteredTasks;
CFE_ES_Global.TaskData.HkPacket.Payload.RegisteredLibs = CFE_ES_Global.RegisteredLibs;
CFE_ES_Global.TaskData.HkPacket.Payload.ResetType = CFE_ES_Global.ResetDataPtr->ResetVars.ResetType;
CFE_ES_Global.TaskData.HkPacket.Payload.ResetSubtype = CFE_ES_Global.ResetDataPtr->ResetVars.ResetSubtype;
CFE_ES_Global.TaskData.HkPacket.Payload.ProcessorResets = CFE_ES_Global.ResetDataPtr->ResetVars.ProcessorResetCount;
CFE_ES_Global.TaskData.HkPacket.Payload.MaxProcessorResets =
CFE_ES_Global.ResetDataPtr->ResetVars.MaxProcessorResetCount;
CFE_ES_Global.TaskData.HkPacket.Payload.BootSource = CFE_ES_Global.ResetDataPtr->ResetVars.BootSource;
CFE_ES_Global.TaskData.HkPacket.Payload.PerfState = CFE_ES_Global.ResetDataPtr->Perf.MetaData.State;
CFE_ES_Global.TaskData.HkPacket.Payload.PerfMode = CFE_ES_Global.ResetDataPtr->Perf.MetaData.Mode;
CFE_ES_Global.TaskData.HkPacket.Payload.PerfTriggerCount = CFE_ES_Global.ResetDataPtr->Perf.MetaData.TriggerCount;
CFE_ES_Global.TaskData.HkPacket.Payload.PerfDataStart = CFE_ES_Global.ResetDataPtr->Perf.MetaData.DataStart;
CFE_ES_Global.TaskData.HkPacket.Payload.PerfDataEnd = CFE_ES_Global.ResetDataPtr->Perf.MetaData.DataEnd;
CFE_ES_Global.TaskData.HkPacket.Payload.PerfDataCount = CFE_ES_Global.ResetDataPtr->Perf.MetaData.DataCount;
CFE_ES_Global.TaskData.HkPacket.Payload.PerfDataToWrite = CFE_ES_GetPerfLogDumpRemaining();
/*
* Fill out the perf trigger/filter mask objects
* The entire array in the HK payload object (external size) must be filled,
* to avoid sending garbage data.
*
* If it is larger than what the platform supports (internal size), it will
* be padded with 0's
*
* If it is smaller than what the platform supports, then truncate.
*/
for (PerfIdx = 0; PerfIdx < CFE_ES_PERF_TRIGGERMASK_EXT_SIZE; ++PerfIdx)
{
if (PerfIdx < CFE_ES_PERF_TRIGGERMASK_INT_SIZE)
{
CFE_ES_Global.TaskData.HkPacket.Payload.PerfTriggerMask[PerfIdx] =
CFE_ES_Global.ResetDataPtr->Perf.MetaData.TriggerMask[PerfIdx];
}
else
{
CFE_ES_Global.TaskData.HkPacket.Payload.PerfTriggerMask[PerfIdx] = 0;
}
}
for (PerfIdx = 0; PerfIdx < CFE_ES_PERF_FILTERMASK_EXT_SIZE; ++PerfIdx)
{
if (PerfIdx < CFE_ES_PERF_FILTERMASK_INT_SIZE)
{
CFE_ES_Global.TaskData.HkPacket.Payload.PerfFilterMask[PerfIdx] =
CFE_ES_Global.ResetDataPtr->Perf.MetaData.FilterMask[PerfIdx];
}
else
{
CFE_ES_Global.TaskData.HkPacket.Payload.PerfFilterMask[PerfIdx] = 0;
}
}
stat = OS_HeapGetInfo(&HeapProp);
/*
* If retrieving info from OSAL was not successful,
* zero out the property struct, so all sizes will
* in turn be reported in telemetry as 0.
*/
if (stat != OS_SUCCESS)
{
memset(&HeapProp, 0, sizeof(HeapProp));
}
CFE_ES_Global.TaskData.HkPacket.Payload.HeapBytesFree = CFE_ES_MEMOFFSET_C(HeapProp.free_bytes);
CFE_ES_Global.TaskData.HkPacket.Payload.HeapBlocksFree = CFE_ES_MEMOFFSET_C(HeapProp.free_blocks);
CFE_ES_Global.TaskData.HkPacket.Payload.HeapMaxBlockSize = CFE_ES_MEMOFFSET_C(HeapProp.largest_free_block);
/*
** Send housekeeping telemetry packet.
*/
CFE_SB_TimeStampMsg(&CFE_ES_Global.TaskData.HkPacket.TlmHeader.Msg);
CFE_SB_TransmitMsg(&CFE_ES_Global.TaskData.HkPacket.TlmHeader.Msg, true);
/*
** This command does not affect the command execution counter.
*/
return CFE_SUCCESS;
} /* End of CFE_ES_HousekeepingCmd() */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* CFE_ES_NoopCmd() -- ES task ground command (NO-OP) */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 CFE_ES_NoopCmd(const CFE_ES_NoopCmd_t *Cmd)
{
/*
** Advertise the build and version information with the no-op command
** For unit testing purposes, it helps to put this first - the UT
** is checking for the last event sent to be NOOP_INF_EID.
*/
CFE_ES_GenerateBuildInfoEvents();
/*
** This command will always succeed.
*/
CFE_ES_Global.TaskData.CommandCounter++;
CFE_EVS_SendEvent(CFE_ES_NOOP_INF_EID, CFE_EVS_EventType_INFORMATION,
"No-op command:\n cFS Versions: cfe %s, osal %s, psp %s", CFE_SRC_VERSION, OS_GetVersionString(),
CFE_PSP_GetVersionString());
return CFE_SUCCESS;
} /* End of CFE_ES_NoopCmd() */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* CFE_ES_ResetCountersCmd() -- ES task ground command (reset counters) */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 CFE_ES_ResetCountersCmd(const CFE_ES_ResetCountersCmd_t *data)
{
CFE_ES_Global.TaskData.CommandCounter = 0;
CFE_ES_Global.TaskData.CommandErrorCounter = 0;
/*
** This command will always succeed.
*/
CFE_EVS_SendEvent(CFE_ES_RESET_INF_EID, CFE_EVS_EventType_INFORMATION, "Reset Counters command");
return CFE_SUCCESS;
} /* End of CFE_ES_ResetCountersCmd() */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* CFE_ES_RestartCmd() -- Restart cFE (may reset processor) */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 CFE_ES_RestartCmd(const CFE_ES_RestartCmd_t *data)
{
const CFE_ES_RestartCmd_Payload_t *cmd = &data->Payload;
if ((cmd->RestartType != CFE_PSP_RST_TYPE_PROCESSOR) && (cmd->RestartType != CFE_PSP_RST_TYPE_POWERON))
{
CFE_ES_Global.TaskData.CommandErrorCounter++;
CFE_EVS_SendEvent(CFE_ES_BOOT_ERR_EID, CFE_EVS_EventType_ERROR, "Invalid cFE restart type: %d",
(int)cmd->RestartType);
}
else
{
/*
** This function will not return.
*/
CFE_ES_ResetCFE(cmd->RestartType);
}
return CFE_SUCCESS;
} /* End of CFE_ES_RestartCmd() */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* CFE_ES_StartAppCmd() -- Load (and start) single application */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 CFE_ES_StartAppCmd(const CFE_ES_StartAppCmd_t *data)
{
const CFE_ES_StartAppCmd_Payload_t *cmd = &data->Payload;
CFE_ES_AppId_t AppID;
int32 Result;
int32 AppEntryLen;
int32 AppNameLen;
char LocalAppName[OS_MAX_API_NAME];
CFE_ES_AppStartParams_t StartParams;
/* Create local copies of all input strings and ensure null termination */
Result = CFE_FS_ParseInputFileNameEx(StartParams.BasicInfo.FileName, cmd->AppFileName,
sizeof(StartParams.BasicInfo.FileName), sizeof(cmd->AppFileName), NULL,
CFE_FS_GetDefaultMountPoint(CFE_FS_FileCategory_DYNAMIC_MODULE),
CFE_FS_GetDefaultExtension(CFE_FS_FileCategory_DYNAMIC_MODULE));
AppEntryLen = CFE_SB_MessageStringGet(StartParams.BasicInfo.InitSymbolName, cmd->AppEntryPoint, NULL,
sizeof(StartParams.BasicInfo.InitSymbolName), sizeof(cmd->AppEntryPoint));
AppNameLen =
CFE_SB_MessageStringGet(LocalAppName, cmd->Application, NULL, sizeof(LocalAppName), sizeof(cmd->Application));
/*
** Verify command parameters
*/
if (Result != CFE_SUCCESS)
{
CFE_ES_Global.TaskData.CommandErrorCounter++;
CFE_EVS_SendEvent(CFE_ES_START_INVALID_FILENAME_ERR_EID, CFE_EVS_EventType_ERROR,
"CFE_ES_StartAppCmd: invalid filename, status=%lx", (unsigned long)Result);
}
else if (AppEntryLen <= 0)
{
CFE_ES_Global.TaskData.CommandErrorCounter++;
CFE_EVS_SendEvent(CFE_ES_START_INVALID_ENTRY_POINT_ERR_EID, CFE_EVS_EventType_ERROR,
"CFE_ES_StartAppCmd: App Entry Point is empty.");
}
else if (AppNameLen <= 0)
{
CFE_ES_Global.TaskData.CommandErrorCounter++;
CFE_EVS_SendEvent(CFE_ES_START_NULL_APP_NAME_ERR_EID, CFE_EVS_EventType_ERROR,
"CFE_ES_StartAppCmd: App Name is empty.");
}
else if (cmd->Priority > OS_MAX_PRIORITY)
{
CFE_ES_Global.TaskData.CommandErrorCounter++;
CFE_EVS_SendEvent(CFE_ES_START_PRIORITY_ERR_EID, CFE_EVS_EventType_ERROR,
"CFE_ES_StartAppCmd: Priority is too large: %d.", (int)cmd->Priority);
}
else if ((cmd->ExceptionAction != CFE_ES_ExceptionAction_RESTART_APP) &&
(cmd->ExceptionAction != CFE_ES_ExceptionAction_PROC_RESTART))
{
CFE_ES_Global.TaskData.CommandErrorCounter++;
CFE_EVS_SendEvent(CFE_ES_START_EXC_ACTION_ERR_EID, CFE_EVS_EventType_ERROR,
"CFE_ES_StartAppCmd: Invalid Exception Action: %d.", (int)cmd->ExceptionAction);
}
else
{
/* If stack size was provided, use it, otherwise use default. */
if (cmd->StackSize == 0)
{
StartParams.MainTaskInfo.StackSize = CFE_PLATFORM_ES_DEFAULT_STACK_SIZE;
}
else
{
StartParams.MainTaskInfo.StackSize = cmd->StackSize;
}
StartParams.MainTaskInfo.Priority = cmd->Priority;
StartParams.ExceptionAction = cmd->ExceptionAction;
/*
** Invoke application loader/startup function.
*/
Result = CFE_ES_AppCreate(&AppID, LocalAppName, &StartParams);
/*
** Send appropriate event message
*/
if (Result == CFE_SUCCESS)
{
CFE_ES_Global.TaskData.CommandCounter++;
CFE_EVS_SendEvent(CFE_ES_START_INF_EID, CFE_EVS_EventType_INFORMATION, "Started %s from %s, AppID = %lu",
LocalAppName, StartParams.BasicInfo.FileName, CFE_RESOURCEID_TO_ULONG(AppID));
}
else
{
CFE_ES_Global.TaskData.CommandErrorCounter++;
CFE_EVS_SendEvent(CFE_ES_START_ERR_EID, CFE_EVS_EventType_ERROR, "Failed to start %s from %s, RC = 0x%08X",
LocalAppName, StartParams.BasicInfo.FileName, (unsigned int)Result);
}
} /* End if -- command parameter validation */