-
Notifications
You must be signed in to change notification settings - Fork 202
/
cfe_time_task.c
1390 lines (1186 loc) · 45.8 KB
/
cfe_time_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_time_task.c
**
** Subsystem: cFE TIME Task
**
** Author: S. Walling (Microtel)
**
** Notes:
**
*/
/*
** Required header files...
*/
#include "cfe_time_module_all.h"
#include "cfe_version.h"
#include "cfe_time_verify.h"
/*
** Time task global data...
*/
CFE_TIME_Global_t CFE_TIME_Global;
/*----------------------------------------------------------------
*
* Function: CFE_TIME_EarlyInit
*
* Implemented per public API
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
int32 CFE_TIME_EarlyInit(void)
{
/*
** Initialize global Time Services nonzero data...
*/
CFE_TIME_InitData();
return (CFE_SUCCESS);
}
/*----------------------------------------------------------------
*
* Function: CFE_TIME_TaskMain
*
* Implemented per public API
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
void CFE_TIME_TaskMain(void)
{
int32 Status;
CFE_SB_Buffer_t *SBBufPtr;
CFE_ES_PerfLogEntry(CFE_MISSION_TIME_MAIN_PERF_ID);
Status = CFE_TIME_TaskInit();
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("%s: Application Init Failed,RC=0x%08X\n", __func__, (unsigned int)Status);
CFE_ES_PerfLogExit(CFE_MISSION_TIME_MAIN_PERF_ID);
/* Note: CFE_ES_ExitApp will not return */
CFE_ES_ExitApp(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 loop */
while (Status == CFE_SUCCESS)
{
/* Increment the Main task Execution Counter */
CFE_ES_IncrementTaskCounter();
CFE_ES_PerfLogExit(CFE_MISSION_TIME_MAIN_PERF_ID);
/* Pend on receipt of packet */
Status = CFE_SB_ReceiveBuffer(&SBBufPtr, CFE_TIME_Global.CmdPipe, CFE_SB_PEND_FOREVER);
CFE_ES_PerfLogEntry(CFE_MISSION_TIME_MAIN_PERF_ID);
if (Status == CFE_SUCCESS)
{
/* Process cmd pipe msg */
CFE_TIME_TaskPipe(SBBufPtr);
}
else
{
CFE_ES_WriteToSysLog("%s: Error reading cmd pipe,RC=0x%08X\n", __func__, (unsigned int)Status);
} /* end if */
} /* end while */
/* while loop exits only if CFE_SB_ReceiveBuffer returns error */
CFE_ES_ExitApp(CFE_ES_RunStatus_CORE_APP_RUNTIME_ERROR);
}
/*----------------------------------------------------------------
*
* Function: CFE_TIME_TaskInit
*
* Application-scope internal function
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
int32 CFE_TIME_TaskInit(void)
{
int32 Status;
int32 OsStatus;
osal_id_t TimeBaseId;
osal_id_t TimerId;
Status = CFE_EVS_Register(NULL, 0, 0);
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("%s: Call to CFE_EVS_Register Failed:RC=0x%08X\n", __func__, (unsigned int)Status);
return Status;
} /* end if */
OsStatus = OS_BinSemCreate(&CFE_TIME_Global.ToneSemaphore, CFE_TIME_SEM_TONE_NAME, CFE_TIME_SEM_VALUE,
CFE_TIME_SEM_OPTIONS);
if (OsStatus != OS_SUCCESS)
{
CFE_ES_WriteToSysLog("%s: Error creating tone semaphore:RC=%ld\n", __func__, (long)OsStatus);
return CFE_STATUS_EXTERNAL_RESOURCE_FAIL;
} /* end if */
OsStatus = OS_BinSemCreate(&CFE_TIME_Global.LocalSemaphore, CFE_TIME_SEM_1HZ_NAME, CFE_TIME_SEM_VALUE,
CFE_TIME_SEM_OPTIONS);
if (OsStatus != OS_SUCCESS)
{
CFE_ES_WriteToSysLog("%s: Error creating local semaphore:RC=%ld\n", __func__, (long)OsStatus);
return CFE_STATUS_EXTERNAL_RESOURCE_FAIL;
} /* end if */
Status = CFE_ES_CreateChildTask(&CFE_TIME_Global.ToneTaskID, CFE_TIME_TASK_TONE_NAME, CFE_TIME_Tone1HzTask,
CFE_TIME_TASK_STACK_PTR, CFE_PLATFORM_TIME_TONE_TASK_STACK_SIZE,
CFE_PLATFORM_TIME_TONE_TASK_PRIORITY, CFE_TIME_TASK_FLAGS);
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("%s: Error creating tone 1Hz child task:RC=0x%08X\n", __func__, (unsigned int)Status);
return Status;
} /* end if */
Status = CFE_ES_CreateChildTask(&CFE_TIME_Global.LocalTaskID, CFE_TIME_TASK_1HZ_NAME, CFE_TIME_Local1HzTask,
CFE_TIME_TASK_STACK_PTR, CFE_PLATFORM_TIME_1HZ_TASK_STACK_SIZE,
CFE_PLATFORM_TIME_1HZ_TASK_PRIORITY, CFE_TIME_TASK_FLAGS);
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("%s: Error creating local 1Hz child task:RC=0x%08X\n", __func__, (unsigned int)Status);
return Status;
} /* end if */
Status = CFE_SB_CreatePipe(&CFE_TIME_Global.CmdPipe, CFE_TIME_TASK_PIPE_DEPTH, CFE_TIME_TASK_PIPE_NAME);
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("%s: Error creating cmd pipe:RC=0x%08X\n", __func__, (unsigned int)Status);
return Status;
} /* end if */
Status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(CFE_TIME_SEND_HK_MID), CFE_TIME_Global.CmdPipe);
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("%s: Error subscribing to HK Request:RC=0x%08X\n", __func__, (unsigned int)Status);
return Status;
} /* end if */
/*
** Subscribe to time at the tone "signal" commands...
*/
#if (CFE_PLATFORM_TIME_CFG_CLIENT == true)
Status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(CFE_TIME_TONE_CMD_MID), CFE_TIME_Global.CmdPipe);
#endif
#if (CFE_PLATFORM_TIME_CFG_SERVER == true)
Status = CFE_SB_SubscribeLocal(CFE_SB_ValueToMsgId(CFE_TIME_TONE_CMD_MID), CFE_TIME_Global.CmdPipe, 4);
#endif
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("%s: Error subscribing to tone cmd:RC=0x%08X\n", __func__, (unsigned int)Status);
return Status;
} /* end if */
/*
** Subscribe to time at the tone "data" commands...
*/
#if (CFE_PLATFORM_TIME_CFG_CLIENT == true)
Status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(CFE_TIME_DATA_CMD_MID), CFE_TIME_Global.CmdPipe);
#endif
#if (CFE_PLATFORM_TIME_CFG_SERVER == true)
Status = CFE_SB_SubscribeLocal(CFE_SB_ValueToMsgId(CFE_TIME_DATA_CMD_MID), CFE_TIME_Global.CmdPipe, 4);
#endif
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("%s: Error subscribing to time data cmd:RC=0x%08X\n", __func__, (unsigned int)Status);
return Status;
} /* end if */
/*
** Subscribe to 1Hz signal commands...
*/
#if (CFE_PLATFORM_TIME_CFG_CLIENT == true)
Status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(CFE_TIME_1HZ_CMD_MID), CFE_TIME_Global.CmdPipe);
#endif
#if (CFE_PLATFORM_TIME_CFG_SERVER == true)
Status = CFE_SB_SubscribeLocal(CFE_SB_ValueToMsgId(CFE_TIME_1HZ_CMD_MID), CFE_TIME_Global.CmdPipe, 4);
#endif
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("%s: Error subscribing to fake tone signal cmds:RC=0x%08X\n", __func__,
(unsigned int)Status);
return Status;
} /* end if */
/*
** Subscribe to time at the tone "request data" commands...
*/
#if (CFE_PLATFORM_TIME_CFG_SERVER == true)
Status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(CFE_TIME_SEND_CMD_MID), CFE_TIME_Global.CmdPipe);
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("%s: Error subscribing to time at the tone request data cmds:RC=0x%08X\n", __func__,
(unsigned int)Status);
return Status;
} /* end if */
#endif
/*
** Subscribe to Time task ground command packets...
*/
Status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(CFE_TIME_CMD_MID), CFE_TIME_Global.CmdPipe);
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("%s: Error subscribing to time task gnd cmds:RC=0x%08X\n", __func__, (unsigned int)Status);
return Status;
} /* end if */
Status = CFE_EVS_SendEvent(CFE_TIME_INIT_EID, CFE_EVS_EventType_INFORMATION, "cFE TIME Initialized: %s",
CFE_VERSION_STRING);
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("%s: Error sending init event:RC=0x%08X\n", __func__, (unsigned int)Status);
return Status;
} /* end if */
/*
** Select primary vs redundant tone interrupt signal...
*/
#if (CFE_PLATFORM_TIME_CFG_SIGNAL == true)
OS_SelectTone(CFE_TIME_Global.ClockSignal);
#endif
/*
* Check to see if the OSAL in use implements the TimeBase API
* and if the PSP has set up a system time base. If so, then create
* a 1Hz callback based on that system time base. This call should
* return OS_ERR_NOT_IMPLEMENTED if the OSAL does not support this,
* or OS_ERR_NAME_NOT_FOUND if the PSP didn't set this up. Either
* way any error here means the PSP must use the "old way" and call
* the 1hz function directly.
*/
OsStatus = OS_TimeBaseGetIdByName(&TimeBaseId, "cFS-Master");
if (OsStatus == OS_SUCCESS)
{
/* Create the 1Hz callback */
OsStatus = OS_TimerAdd(&TimerId, "cFS-1Hz", TimeBaseId, CFE_TIME_Local1HzTimerCallback, NULL);
if (OsStatus == OS_SUCCESS)
{
OsStatus = OS_TimerSet(TimerId, 500000, 1000000);
if (OsStatus != OS_SUCCESS)
{
CFE_ES_WriteToSysLog("%s: 1Hz OS_TimerSet failed:RC=%ld\n", __func__, (long)OsStatus);
}
}
else
{
CFE_ES_WriteToSysLog("%s: 1Hz OS_TimerAdd failed:RC=%ld\n", __func__, (long)OsStatus);
}
}
return CFE_SUCCESS;
}
/*----------------------------------------------------------------
*
* Function: CFE_TIME_VerifyCmdLength
*
* Internal helper routine only, not part of API.
*
* Function to verify the length of incoming TIME command packets
*
*-----------------------------------------------------------------*/
bool CFE_TIME_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength)
{
bool result = true;
CFE_MSG_Size_t ActualLength = 0;
CFE_MSG_FcnCode_t FcnCode = 0;
CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID;
CFE_MSG_GetSize(MsgPtr, &ActualLength);
/*
** Verify the command packet length
*/
if (ExpectedLength != ActualLength)
{
CFE_MSG_GetMsgId(MsgPtr, &MsgId);
CFE_MSG_GetFcnCode(MsgPtr, &FcnCode);
CFE_EVS_SendEvent(CFE_TIME_LEN_ERR_EID, CFE_EVS_EventType_ERROR,
"Invalid msg length: ID = 0x%X, CC = %u, Len = %u, Expected = %u",
(unsigned int)CFE_SB_MsgIdToValue(MsgId), (unsigned int)FcnCode, (unsigned int)ActualLength,
(unsigned int)ExpectedLength);
result = false;
++CFE_TIME_Global.CommandErrorCounter;
}
return (result);
}
/*----------------------------------------------------------------
*
* Function: CFE_TIME_TaskPipe
*
* Application-scope internal function
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
void CFE_TIME_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_TIME_SEND_HK_MID:
CFE_TIME_HousekeepingCmd((CFE_MSG_CommandHeader_t *)SBBufPtr);
break;
/*
** Time at the tone "signal"...
*/
case CFE_TIME_TONE_CMD_MID:
CFE_TIME_ToneSignalCmd((CFE_TIME_ToneSignalCmd_t *)SBBufPtr);
break;
/*
** Time at the tone "data"...
*/
case CFE_TIME_DATA_CMD_MID:
CFE_TIME_ToneDataCmd((CFE_TIME_ToneDataCmd_t *)SBBufPtr);
break;
/*
** Run time state machine at 1Hz...
*/
case CFE_TIME_1HZ_CMD_MID:
CFE_TIME_OneHzCmd((CFE_TIME_1HzCmd_t *)SBBufPtr);
break;
/*
** Request for time at the tone "data"...
*/
#if (CFE_PLATFORM_TIME_CFG_SERVER == true)
case CFE_TIME_SEND_CMD_MID:
CFE_TIME_ToneSendCmd((CFE_TIME_FakeToneCmd_t *)SBBufPtr);
break;
#endif
/*
** Time task ground commands...
*/
case CFE_TIME_CMD_MID:
CFE_MSG_GetFcnCode(&SBBufPtr->Msg, &CommandCode);
switch (CommandCode)
{
case CFE_TIME_NOOP_CC:
if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_NoopCmd_t)))
{
CFE_TIME_NoopCmd((CFE_TIME_NoopCmd_t *)SBBufPtr);
}
break;
case CFE_TIME_RESET_COUNTERS_CC:
if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_ResetCountersCmd_t)))
{
CFE_TIME_ResetCountersCmd((CFE_TIME_ResetCountersCmd_t *)SBBufPtr);
}
break;
case CFE_TIME_SEND_DIAGNOSTIC_TLM_CC:
if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_SendDiagnosticCmd_t)))
{
CFE_TIME_SendDiagnosticTlm((CFE_TIME_SendDiagnosticCmd_t *)SBBufPtr);
}
break;
case CFE_TIME_SET_STATE_CC:
if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_SetStateCmd_t)))
{
CFE_TIME_SetStateCmd((CFE_TIME_SetStateCmd_t *)SBBufPtr);
}
break;
case CFE_TIME_SET_SOURCE_CC:
if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_SetSourceCmd_t)))
{
CFE_TIME_SetSourceCmd((CFE_TIME_SetSourceCmd_t *)SBBufPtr);
}
break;
case CFE_TIME_SET_SIGNAL_CC:
if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_SetSignalCmd_t)))
{
CFE_TIME_SetSignalCmd((CFE_TIME_SetSignalCmd_t *)SBBufPtr);
}
break;
/*
** Time Clients process "tone delay" commands...
*/
case CFE_TIME_ADD_DELAY_CC:
if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_AddDelayCmd_t)))
{
CFE_TIME_AddDelayCmd((CFE_TIME_AddDelayCmd_t *)SBBufPtr);
}
break;
case CFE_TIME_SUB_DELAY_CC:
if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_SubDelayCmd_t)))
{
CFE_TIME_SubDelayCmd((CFE_TIME_SubDelayCmd_t *)SBBufPtr);
}
break;
/*
** Time Servers process "set time" commands...
*/
case CFE_TIME_SET_TIME_CC:
if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_SetTimeCmd_t)))
{
CFE_TIME_SetTimeCmd((CFE_TIME_SetTimeCmd_t *)SBBufPtr);
}
break;
case CFE_TIME_SET_MET_CC:
if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_SetMETCmd_t)))
{
CFE_TIME_SetMETCmd((CFE_TIME_SetMETCmd_t *)SBBufPtr);
}
break;
case CFE_TIME_SET_STCF_CC:
if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_SetSTCFCmd_t)))
{
CFE_TIME_SetSTCFCmd((CFE_TIME_SetSTCFCmd_t *)SBBufPtr);
}
break;
case CFE_TIME_SET_LEAP_SECONDS_CC:
if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_SetLeapSecondsCmd_t)))
{
CFE_TIME_SetLeapSecondsCmd((CFE_TIME_SetLeapSecondsCmd_t *)SBBufPtr);
}
break;
case CFE_TIME_ADD_ADJUST_CC:
if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_AddAdjustCmd_t)))
{
CFE_TIME_AddAdjustCmd((CFE_TIME_AddAdjustCmd_t *)SBBufPtr);
}
break;
case CFE_TIME_SUB_ADJUST_CC:
if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_SubAdjustCmd_t)))
{
CFE_TIME_SubAdjustCmd((CFE_TIME_SubAdjustCmd_t *)SBBufPtr);
}
break;
case CFE_TIME_ADD_1HZ_ADJUSTMENT_CC:
if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_Add1HZAdjustmentCmd_t)))
{
CFE_TIME_Add1HZAdjustmentCmd((CFE_TIME_Add1HZAdjustmentCmd_t *)SBBufPtr);
}
break;
case CFE_TIME_SUB_1HZ_ADJUSTMENT_CC:
if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_Sub1HZAdjustmentCmd_t)))
{
CFE_TIME_Sub1HZAdjustmentCmd((CFE_TIME_Sub1HZAdjustmentCmd_t *)SBBufPtr);
}
break;
default:
CFE_TIME_Global.CommandErrorCounter++;
CFE_EVS_SendEvent(CFE_TIME_CC_ERR_EID, CFE_EVS_EventType_ERROR,
"Invalid command code -- ID = 0x%X, CC = %d",
(unsigned int)CFE_SB_MsgIdToValue(MessageID), (int)CommandCode);
break;
} /* switch (CFE_TIME_CMD_MID -- command code)*/
break;
default:
/*
** Note: we only increment the command error counter when
** processing CFE_TIME_CMD_MID commands...
*/
CFE_EVS_SendEvent(CFE_TIME_ID_ERR_EID, CFE_EVS_EventType_ERROR, "Invalid message ID -- ID = 0x%X",
(unsigned int)CFE_SB_MsgIdToValue(MessageID));
break;
} /* switch (message ID) */
return;
}
/*----------------------------------------------------------------
*
* Function: CFE_TIME_HousekeepingCmd
*
* Application-scope internal function
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
int32 CFE_TIME_HousekeepingCmd(const CFE_MSG_CommandHeader_t *data)
{
CFE_TIME_Reference_t Reference;
/*
** Get reference time values (local time, time at tone, etc.)...
*/
CFE_TIME_GetReference(&Reference);
/*
** Update TIME portion of Critical Data Store...
*/
CFE_TIME_UpdateResetVars(&Reference);
/*
** Collect housekeeping data from Time Services utilities...
*/
CFE_TIME_GetHkData(&Reference);
/*
** Send housekeeping telemetry packet...
*/
CFE_SB_TimeStampMsg(&CFE_TIME_Global.HkPacket.TlmHeader.Msg);
CFE_SB_TransmitMsg(&CFE_TIME_Global.HkPacket.TlmHeader.Msg, true);
/*
** Note: we only increment the command execution counter when
** processing CFE_TIME_CMD_MID commands...
*/
return CFE_SUCCESS;
}
/*----------------------------------------------------------------
*
* Function: CFE_TIME_ToneSignalCmd
*
* Application-scope internal function
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
int32 CFE_TIME_ToneSignalCmd(const CFE_TIME_ToneSignalCmd_t *data)
{
/*
** Indication that tone signal occurred recently...
*/
CFE_TIME_ToneSignal();
/*
** Note: we only increment the command execution counter when
** processing CFE_TIME_CMD_MID commands...
*/
return CFE_SUCCESS;
}
/*----------------------------------------------------------------
*
* Function: CFE_TIME_ToneDataCmd
*
* Application-scope internal function
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
int32 CFE_TIME_ToneDataCmd(const CFE_TIME_ToneDataCmd_t *data)
{
/*
** This command packet contains "time at the tone" data...
*/
CFE_TIME_ToneData(&data->Payload);
/*
** Note: we only increment the command execution counter when
** processing CFE_TIME_CMD_MID commands...
*/
return CFE_SUCCESS;
}
/*----------------------------------------------------------------
*
* Function: CFE_TIME_OneHzCmd
*
* Application-scope internal function
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
int32 CFE_TIME_OneHzCmd(const CFE_TIME_1HzCmd_t *data)
{
/*
* Run the state machine updates required at 1Hz.
*
* This task used to be performed as part of the 1Hz ISR, but this was unsafe on SMP
* as the updates cannot be synchronized with the command handlers in this environment
*/
CFE_TIME_Local1HzStateMachine();
#if (CFE_MISSION_TIME_CFG_FAKE_TONE == true)
/*
** Fake the call-back from the "real" h/w ISR...
*/
CFE_TIME_Tone1HzISR();
#endif /* CFE_MISSION_TIME_CFG_FAKE_TONE */
/*
** Note: we only increment the command execution counter when
** processing CFE_TIME_CMD_MID commands...
*/
return CFE_SUCCESS;
}
/*----------------------------------------------------------------
*
* Function: CFE_TIME_ToneSendCmd
*
* Application-scope internal function
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
#if (CFE_PLATFORM_TIME_CFG_SERVER == true)
int32 CFE_TIME_ToneSendCmd(const CFE_TIME_FakeToneCmd_t *data)
{
/*
** Request for "time at tone" data packet (probably scheduler)...
*/
CFE_TIME_ToneSend();
/*
** Note: we only increment the command execution counter when
** processing CFE_TIME_CMD_MID commands...
*/
return CFE_SUCCESS;
}
#endif /* CFE_PLATFORM_TIME_CFG_SERVER */
/*----------------------------------------------------------------
*
* Function: CFE_TIME_NoopCmd
*
* Application-scope internal function
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
int32 CFE_TIME_NoopCmd(const CFE_TIME_NoopCmd_t *data)
{
CFE_TIME_Global.CommandCounter++;
CFE_EVS_SendEvent(CFE_TIME_NOOP_EID, CFE_EVS_EventType_INFORMATION, "No-op Cmd Rcvd: %s", CFE_VERSION_STRING);
return CFE_SUCCESS;
}
/*----------------------------------------------------------------
*
* Function: CFE_TIME_ResetCountersCmd
*
* Application-scope internal function
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
int32 CFE_TIME_ResetCountersCmd(const CFE_TIME_ResetCountersCmd_t *data)
{
CFE_TIME_Global.CommandCounter = 0;
CFE_TIME_Global.CommandErrorCounter = 0;
CFE_TIME_Global.ToneMatchCounter = 0;
CFE_TIME_Global.ToneMatchErrorCounter = 0;
CFE_TIME_Global.ToneSignalCounter = 0;
CFE_TIME_Global.ToneDataCounter = 0;
CFE_TIME_Global.ToneIntCounter = 0;
CFE_TIME_Global.ToneIntErrorCounter = 0;
CFE_TIME_Global.ToneTaskCounter = 0;
/*
* Note: Not resetting "LastVersion" counter here, that might
* disturb access to the time reference data by other tasks
*/
CFE_TIME_Global.ResetVersionCounter = CFE_TIME_Global.LastVersionCounter;
CFE_TIME_Global.LocalIntCounter = 0;
CFE_TIME_Global.LocalTaskCounter = 0;
CFE_TIME_Global.InternalCount = 0;
CFE_TIME_Global.ExternalCount = 0;
CFE_EVS_SendEvent(CFE_TIME_RESET_EID, CFE_EVS_EventType_DEBUG, "Reset Counters command");
return CFE_SUCCESS;
}
/*----------------------------------------------------------------
*
* Function: CFE_TIME_SendDiagnosticTlm
*
* Application-scope internal function
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
int32 CFE_TIME_SendDiagnosticTlm(const CFE_TIME_SendDiagnosticCmd_t *data)
{
CFE_TIME_Global.CommandCounter++;
/*
** Collect diagnostics data from Time Services utilities...
*/
CFE_TIME_GetDiagData();
/*
** Send diagnostics telemetry packet...
*/
CFE_SB_TimeStampMsg(&CFE_TIME_Global.DiagPacket.TlmHeader.Msg);
CFE_SB_TransmitMsg(&CFE_TIME_Global.DiagPacket.TlmHeader.Msg, true);
CFE_EVS_SendEvent(CFE_TIME_DIAG_EID, CFE_EVS_EventType_DEBUG, "Request diagnostics command");
return CFE_SUCCESS;
}
/*----------------------------------------------------------------
*
* Function: CFE_TIME_SetStateCmd
*
* Application-scope internal function
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
int32 CFE_TIME_SetStateCmd(const CFE_TIME_SetStateCmd_t *data)
{
const CFE_TIME_StateCmd_Payload_t *CommandPtr = &data->Payload;
const char * ClockStateText;
/*
** Verify command argument value (clock state)...
*/
if ((CommandPtr->ClockState == CFE_TIME_ClockState_INVALID) ||
(CommandPtr->ClockState == CFE_TIME_ClockState_VALID) ||
(CommandPtr->ClockState == CFE_TIME_ClockState_FLYWHEEL))
{
CFE_TIME_SetState(CommandPtr->ClockState);
/*
** Select appropriate text for event message...
*/
if (CommandPtr->ClockState == CFE_TIME_ClockState_INVALID)
{
ClockStateText = "INVALID";
}
else if (CommandPtr->ClockState == CFE_TIME_ClockState_VALID)
{
ClockStateText = "VALID";
}
else
{
ClockStateText = "FLYWHEEL";
}
CFE_TIME_Global.CommandCounter++;
CFE_EVS_SendEvent(CFE_TIME_STATE_EID, CFE_EVS_EventType_INFORMATION, "Set Clock State = %s", ClockStateText);
}
else
{
CFE_TIME_Global.CommandErrorCounter++;
CFE_EVS_SendEvent(CFE_TIME_STATE_ERR_EID, CFE_EVS_EventType_ERROR, "Invalid Clock State = 0x%X",
(unsigned int)CommandPtr->ClockState);
}
return CFE_SUCCESS;
}
/*----------------------------------------------------------------
*
* Function: CFE_TIME_SetSourceCmd
*
* Application-scope internal function
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
int32 CFE_TIME_SetSourceCmd(const CFE_TIME_SetSourceCmd_t *data)
{
const CFE_TIME_SourceCmd_Payload_t *CommandPtr = &data->Payload;
#if (CFE_PLATFORM_TIME_CFG_SOURCE == true)
const char *TimeSourceText;
#endif
/*
** Verify command argument value (time data source)...
*/
if ((CommandPtr->TimeSource == CFE_TIME_SourceSelect_INTERNAL) ||
(CommandPtr->TimeSource == CFE_TIME_SourceSelect_EXTERNAL))
{
#if (CFE_PLATFORM_TIME_CFG_SOURCE == true)
/*
** Only systems configured to select source of time data...
*/
CFE_TIME_Global.CommandCounter++;
CFE_TIME_SetSource(CommandPtr->TimeSource);
/*
** Select appropriate text for event message...
*/
if (CommandPtr->TimeSource == CFE_TIME_SourceSelect_INTERNAL)
{
TimeSourceText = "INTERNAL";
}
else
{
TimeSourceText = "EXTERNAL";
}
CFE_EVS_SendEvent(CFE_TIME_SOURCE_EID, CFE_EVS_EventType_INFORMATION, "Set Time Source = %s", TimeSourceText);
#else /* not CFE_PLATFORM_TIME_CFG_SOURCE */
/*
** We want to know if disabled commands are being sent...
*/
CFE_TIME_Global.CommandErrorCounter++;
CFE_EVS_SendEvent(CFE_TIME_SOURCE_CFG_EID, CFE_EVS_EventType_ERROR,
"Set Source commands invalid without CFE_PLATFORM_TIME_CFG_SOURCE set to TRUE");
#endif /* CFE_PLATFORM_TIME_CFG_SOURCE */
}
else
{
/*
** Ground system database will prevent most of these errors...
*/
CFE_TIME_Global.CommandErrorCounter++;
CFE_EVS_SendEvent(CFE_TIME_SOURCE_ERR_EID, CFE_EVS_EventType_ERROR, "Invalid Time Source = 0x%X",
(unsigned int)CommandPtr->TimeSource);
}
return CFE_SUCCESS;
}
/*----------------------------------------------------------------
*
* Function: CFE_TIME_SetSignalCmd
*
* Application-scope internal function
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
int32 CFE_TIME_SetSignalCmd(const CFE_TIME_SetSignalCmd_t *data)
{
const CFE_TIME_SignalCmd_Payload_t *CommandPtr = &data->Payload;
#if (CFE_PLATFORM_TIME_CFG_SIGNAL == true)
const char *ToneSourceText;
#endif
/*
** Verify command argument value (tone source)...
*/
if ((CommandPtr->ToneSource == CFE_TIME_ToneSignalSelect_PRIMARY) ||
(CommandPtr->ToneSource == CFE_TIME_ToneSignalSelect_REDUNDANT))
{
#if (CFE_PLATFORM_TIME_CFG_SIGNAL == true)
/*
** Only systems configured to select tone signal...
*/
CFE_TIME_Global.CommandCounter++;
CFE_TIME_SetSignal(CommandPtr->ToneSource);
/*
** Select appropriate text for event message...
*/
if (CommandPtr->ToneSource == CFE_TIME_ToneSignalSelect_PRIMARY)
{
ToneSourceText = "PRIMARY";
}
else
{
ToneSourceText = "REDUNDANT";
}
CFE_EVS_SendEvent(CFE_TIME_SIGNAL_EID, CFE_EVS_EventType_INFORMATION, "Set Tone Source = %s", ToneSourceText);
#else /* not CFE_PLATFORM_TIME_CFG_SIGNAL */
/*
** We want to know if disabled commands are being sent...
*/
CFE_TIME_Global.CommandErrorCounter++;
CFE_EVS_SendEvent(CFE_TIME_SIGNAL_CFG_EID, CFE_EVS_EventType_ERROR,
"Set Signal commands invalid without CFE_PLATFORM_TIME_CFG_SIGNAL set to TRUE");
#endif /* CFE_PLATFORM_TIME_CFG_SIGNAL */
}
else
{
/*
** Ground system database will prevent most of these errors...
*/
CFE_TIME_Global.CommandErrorCounter++;
CFE_EVS_SendEvent(CFE_TIME_SIGNAL_ERR_EID, CFE_EVS_EventType_ERROR, "Invalid Tone Source = 0x%X",
(unsigned int)CommandPtr->ToneSource);
}
return CFE_SUCCESS;
}
/*----------------------------------------------------------------
*
* Function: CFE_TIME_SetDelayImpl
*
* Application-scope internal function
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
void CFE_TIME_SetDelayImpl(const CFE_TIME_TimeCmd_Payload_t *CommandPtr, CFE_TIME_AdjustDirection_Enum_t Direction)
{
/*
** Verify "micro-seconds" command argument...
*/
if (CommandPtr->MicroSeconds < 1000000)
{
#if (CFE_PLATFORM_TIME_CFG_CLIENT == true)
CFE_TIME_SysTime_t Delay;
Delay.Seconds = CommandPtr->Seconds;
Delay.Subseconds = CFE_TIME_Micro2SubSecs(CommandPtr->MicroSeconds);
CFE_TIME_SetDelay(Delay, Direction);
CFE_TIME_Global.CommandCounter++;
CFE_EVS_SendEvent(CFE_TIME_DELAY_EID, CFE_EVS_EventType_INFORMATION,
"Set Tone Delay -- secs = %u, usecs = %u, ssecs = 0x%X, dir = %d",
(unsigned int)CommandPtr->Seconds, (unsigned int)CommandPtr->MicroSeconds,
(unsigned int)CFE_TIME_Micro2SubSecs(CommandPtr->MicroSeconds), (int)Direction);