-
Notifications
You must be signed in to change notification settings - Fork 57
/
cfe_psp_start.c
710 lines (635 loc) · 22.2 KB
/
cfe_psp_start.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
/*
** 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:https://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_psp_start.c
**
** Purpose:
** cFE BSP main entry point.
**
** History:
** 2005/07/26 A. Cudmore | Initial version for OS X/Linux
**
******************************************************************************/
/*
** Include Files
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <unistd.h>
#include <signal.h>
#include <sys/time.h>
#include <getopt.h>
#include <string.h>
#include <limits.h>
#include <pthread.h>
#include <sched.h>
#include <errno.h>
/*
** cFE includes
*/
#include "common_types.h"
#include "osapi.h"
#include "cfe_psp.h"
#include "cfe_psp_memory.h"
/*
* The preferred way to obtain the CFE tunable values at runtime is via
* the dynamically generated configuration object. This allows a single build
* of the PSP to be completely CFE-independent.
*/
#include "target_config.h"
#include "cfe_psp_module.h"
#define CFE_PSP_MAIN_FUNCTION (*GLOBAL_CONFIGDATA.CfeConfig->SystemMain)
#define CFE_PSP_1HZ_FUNCTION (*GLOBAL_CONFIGDATA.CfeConfig->System1HzISR)
#define CFE_PSP_NONVOL_STARTUP_FILE (GLOBAL_CONFIGDATA.CfeConfig->NonvolStartupFile)
#define CFE_PSP_CPU_ID (GLOBAL_CONFIGDATA.Default_CpuId)
#define CFE_PSP_CPU_NAME (GLOBAL_CONFIGDATA.Default_CpuName)
#define CFE_PSP_SPACECRAFT_ID (GLOBAL_CONFIGDATA.Default_SpacecraftId)
/*
** Defines
*/
#define CFE_PSP_CPU_NAME_LENGTH 32
#define CFE_PSP_RESET_NAME_LENGTH 10
/*
* Limits for task name length in kernel (fixed by Linux/glibc)
* For reference see manpage for "pthread_setname_np".
*/
#define CFE_PSP_KERNEL_NAME_LENGTH_MAX 16
/*
** Typedefs for this module
*/
/*
** Structure for the Command line parameters
*/
typedef struct
{
char ResetType[CFE_PSP_RESET_NAME_LENGTH]; /* Reset type can be "PO" for Power on or "PR" for Processor Reset */
uint32 GotResetType; /* did we get the ResetType parameter ? */
uint32 SubType; /* Reset Sub Type ( 1 - 5 ) */
uint32 GotSubType; /* did we get the ResetSubType parameter ? */
char CpuName[CFE_PSP_CPU_NAME_LENGTH]; /* CPU Name */
uint32 GotCpuName; /* Did we get a CPU Name ? */
uint32 CpuId; /* CPU ID */
uint32 GotCpuId; /* Did we get a CPU Id ?*/
uint32 SpacecraftId; /* Spacecraft ID */
uint32 GotSpacecraftId; /* Did we get a Spacecraft ID */
} CFE_PSP_CommandData_t;
/*
** Prototypes for this module
*/
void CFE_PSP_TimerHandler(int signum);
void CFE_PSP_DisplayUsage(char *Name);
void CFE_PSP_ProcessArgumentDefaults(CFE_PSP_CommandData_t *CommandDataDefault);
void CFE_PSP_SetupLocal1Hz(void);
/*
** Global variables
*/
uint32 TimerCounter;
CFE_PSP_CommandData_t CommandData;
uint32 CFE_PSP_SpacecraftId;
uint32 CFE_PSP_CpuId;
char CFE_PSP_CpuName[CFE_PSP_CPU_NAME_LENGTH];
CFE_PSP_IdleTaskState_t CFE_PSP_IdleTaskState;
/*
** getopts parameter passing options string
*/
static const char *optString = "R:S:C:I:N:h";
/*
** getopts_long long form argument table
*/
static const struct option longOpts[] = {{"reset", required_argument, NULL, 'R'},
{"subtype", required_argument, NULL, 'S'},
{"cpuid", required_argument, NULL, 'C'},
{"scid", required_argument, NULL, 'I'},
{"cpuname", required_argument, NULL, 'N'},
{"help", no_argument, NULL, 'h'},
{NULL, no_argument, NULL, 0}};
/******************************************************************************
** Function: CFE_PSP_OS_EventHandler()
**
** Purpose:
** Linux Task creation event handler.
** Sets the kernel task name using a glibc-specific (non-posix) function.
**
*/
int32 CFE_PSP_OS_EventHandler(OS_Event_t event, osal_id_t object_id, void *data)
{
char taskname[OS_MAX_API_NAME];
switch (event)
{
case OS_EVENT_RESOURCE_ALLOCATED:
/* resource/id is newly allocated but not yet created. Invoked within locked region. */
break;
case OS_EVENT_RESOURCE_CREATED:
/* resource/id has been fully created/finalized. Invoked outside locked region. */
break;
case OS_EVENT_RESOURCE_DELETED:
/* resource/id has been deleted. Invoked outside locked region. */
break;
case OS_EVENT_TASK_STARTUP:
{
/* New task is starting. Invoked from within the task context. */
/* Get the name from OSAL and propagate to the pthread/system layer */
if (OS_GetResourceName(object_id, taskname, sizeof(taskname)) == OS_SUCCESS)
{
/*
* glibc/kernel has an internal limit for this name.
* If the OSAL name is longer, just truncate it.
* Otherwise the name isn't set at all - this assumes the first
* chars of the name is better for debug than none of it.
*/
if (strlen(taskname) >= CFE_PSP_KERNEL_NAME_LENGTH_MAX)
{
taskname[CFE_PSP_KERNEL_NAME_LENGTH_MAX - 1] = 0;
}
pthread_setname_np(pthread_self(), taskname);
}
break;
}
default:
break;
}
return OS_SUCCESS;
}
/******************************************************************************
** Function: main()
**
** Purpose:
** BSP Application entry point.
**
** Arguments:
** (none)
**
** Return:
** (none)
*/
void OS_Application_Startup(void)
{
uint32 reset_type;
uint32 reset_subtype;
int32 time_status;
osal_id_t sys_timebase_id;
osal_id_t fs_id;
int opt = 0;
int longIndex = 0;
int32 Status;
char *const *argv;
int argc;
/*
** Initialize the CommandData struct
*/
memset(&(CommandData), 0, sizeof(CFE_PSP_CommandData_t));
/*
** Process the arguments with getopt_long(), then
** start the cFE
*/
argc = OS_BSP_GetArgC();
argv = OS_BSP_GetArgV();
opt = getopt_long(argc, argv, optString, longOpts, &longIndex);
while (opt != -1)
{
switch (opt)
{
case 'R':
strncpy(CommandData.ResetType, optarg, CFE_PSP_RESET_NAME_LENGTH - 1);
CommandData.ResetType[CFE_PSP_RESET_NAME_LENGTH - 1] = 0;
if ((strncmp(CommandData.ResetType, "PO", CFE_PSP_RESET_NAME_LENGTH) != 0) &&
(strncmp(CommandData.ResetType, "PR", CFE_PSP_RESET_NAME_LENGTH) != 0))
{
printf("\nERROR: Invalid Reset Type: %s\n\n", CommandData.ResetType);
CommandData.GotResetType = 0;
CFE_PSP_DisplayUsage(argv[0]);
break;
}
printf("CFE_PSP: Reset Type: %s\n", (char *)optarg);
CommandData.GotResetType = 1;
break;
case 'S':
CommandData.SubType = strtol(optarg, NULL, 0);
if (CommandData.SubType < 1 || CommandData.SubType > 5)
{
printf("\nERROR: Invalid Reset SubType: %s\n\n", optarg);
CommandData.SubType = 0;
CommandData.GotSubType = 0;
CFE_PSP_DisplayUsage(argv[0]);
break;
}
printf("CFE_PSP: Reset SubType: %d\n", (int)CommandData.SubType);
CommandData.GotSubType = 1;
break;
case 'N':
strncpy(CommandData.CpuName, optarg, CFE_PSP_CPU_NAME_LENGTH - 1);
CommandData.CpuName[CFE_PSP_CPU_NAME_LENGTH - 1] = 0;
printf("CFE_PSP: CPU Name: %s\n", CommandData.CpuName);
CommandData.GotCpuName = 1;
break;
case 'C':
CommandData.CpuId = strtol(optarg, NULL, 0);
printf("CFE_PSP: CPU ID: %d\n", (int)CommandData.CpuId);
CommandData.GotCpuId = 1;
break;
case 'I':
CommandData.SpacecraftId = strtol(optarg, NULL, 0);
printf("CFE_PSP: Spacecraft ID: %d\n", (int)CommandData.SpacecraftId);
CommandData.GotSpacecraftId = 1;
break;
case 'h':
CFE_PSP_DisplayUsage(argv[0]);
break;
default:
CFE_PSP_DisplayUsage(argv[0]);
break;
}
opt = getopt_long(argc, argv, optString, longOpts, &longIndex);
} /* end while */
/*
** Set the defaults for values that were not given for the
** optional arguments, and check for arguments that are required.
*/
CFE_PSP_ProcessArgumentDefaults(&CommandData);
/*
** Assign the Spacecraft ID, CPU ID, and CPU Name
*/
CFE_PSP_SpacecraftId = CommandData.SpacecraftId;
CFE_PSP_CpuId = CommandData.CpuId;
strncpy(CFE_PSP_CpuName, CommandData.CpuName, sizeof(CFE_PSP_CpuName) - 1);
CFE_PSP_CpuName[sizeof(CFE_PSP_CpuName) - 1] = 0;
/*
** Set the reset subtype
*/
reset_subtype = CommandData.SubType;
/*
** Initialize the OS API data structures
*/
Status = OS_API_Init();
if (Status != OS_SUCCESS)
{
/* irrecoverable error if OS_API_Init() fails. */
/* note: use printf here, as OS_printf may not work */
printf("CFE_PSP: OS_API_Init() failure\n");
CFE_PSP_Panic(Status);
}
OS_RegisterEventHandler(CFE_PSP_OS_EventHandler);
/*
* Map the PSP shared memory segments
*/
CFE_PSP_SetupReservedMemoryMap();
/*
* Prepare for exception handling in the idle task
*/
memset(&CFE_PSP_IdleTaskState, 0, sizeof(CFE_PSP_IdleTaskState));
CFE_PSP_IdleTaskState.ThreadID = pthread_self();
/*
** Set up the timebase, if OSAL supports it
** Done here so that the modules can also use it, if desired
**
** This is a clock named "cFS-Master" that will serve to drive
** all time-related CFE functions including the 1Hz signal.
**
** Note the timebase is only prepared here; the application is
** not ready to receive a callback yet, as it hasn't been started.
** CFE TIME registers its own callback when it is ready to do so.
*/
time_status = OS_TimeBaseCreate(&sys_timebase_id, "cFS-Master", NULL);
if (time_status == OS_SUCCESS)
{
/*
* Set the clock to trigger with 50ms resolution - slow enough that
* it will not hog CPU resources but fast enough to have sufficient resolution
* for most general timing purposes.
* (It may be better to move this to the mission config file)
*/
time_status = OS_TimeBaseSet(sys_timebase_id, 50000, 50000);
}
else
{
/*
* Cannot create a timebase in OSAL.
*
* Note: Most likely this is due to building with
* the old/classic POSIX OSAL which does not support this.
*
* See below for workaround.
*/
sys_timebase_id = OS_OBJECT_ID_UNDEFINED;
}
/*
** Set up the virtual FS mapping for the "/cf" directory
** On this platform it is just a local/relative dir of the same name.
*/
Status = OS_FileSysAddFixedMap(&fs_id, "./cf", "/cf");
if (Status != OS_SUCCESS)
{
/* Print for informational purposes --
* startup can continue, but loads may fail later, depending on config. */
OS_printf("CFE_PSP: OS_FileSysAddFixedMap() failure: %d\n", (int)Status);
}
/*
** Initialize the statically linked modules (if any)
** This is only applicable to CMake build - classic build
** does not have the logic to selectively include/exclude modules
*/
CFE_PSP_ModuleInit();
sleep(1);
/*
* For informational purposes, show the state of the last exit
*/
if (CFE_PSP_ReservedMemoryMap.BootPtr->ValidityFlag == CFE_PSP_BOOTRECORD_VALID)
{
OS_printf("CFE_PSP: Normal exit from previous cFE instance\n");
}
else if (CFE_PSP_ReservedMemoryMap.BootPtr->ValidityFlag == CFE_PSP_BOOTRECORD_INVALID)
{
OS_printf("CFE_PSP: Abnormal exit from previous cFE instance\n");
}
/*
* determine reset type...
* If not specified at the command line, then check the "boot record"
*/
reset_type = 0;
if (!CommandData.GotResetType)
{
if (CFE_PSP_ReservedMemoryMap.BootPtr->ValidityFlag == CFE_PSP_BOOTRECORD_VALID ||
CFE_PSP_ReservedMemoryMap.BootPtr->ValidityFlag == CFE_PSP_BOOTRECORD_INVALID)
{
reset_type = CFE_PSP_ReservedMemoryMap.BootPtr->NextResetType;
}
}
else if (strncmp("PR", CommandData.ResetType, 2) == 0)
{
reset_type = CFE_PSP_RST_TYPE_PROCESSOR;
}
if (reset_type == CFE_PSP_RST_TYPE_PROCESSOR)
{
OS_printf("CFE_PSP: Starting the cFE with a PROCESSOR reset.\n");
}
else
{
/* catch-all for anything else */
reset_type = CFE_PSP_RST_TYPE_POWERON;
OS_printf("CFE_PSP: Starting the cFE with a POWER ON reset.\n");
}
/*
** Initialize the reserved memory
*/
Status = CFE_PSP_InitProcessorReservedMemory(reset_type);
if (Status != CFE_PSP_SUCCESS)
{
OS_printf("CFE_PSP: CFE_PSP_InitProcessorReservedMemory() Failure");
CFE_PSP_Panic(Status);
}
/*
** Call cFE entry point.
*/
CFE_PSP_MAIN_FUNCTION(reset_type, reset_subtype, 1, CFE_PSP_NONVOL_STARTUP_FILE);
/*
* Backward compatibility for old OSAL.
*/
if (!OS_ObjectIdDefined(sys_timebase_id) || time_status != OS_SUCCESS)
{
OS_printf("CFE_PSP: WARNING - Compatibility mode - using local 1Hz Interrupt\n");
CFE_PSP_SetupLocal1Hz();
}
}
void OS_Application_Run(void)
{
int sig;
int ret;
sigset_t sigset;
/*
* Now that all main tasks are created,
* this original thread will exist just to service signals
* that aren't directed to a specific task.
*
* OSAL sets a very conservative signal mask that
* blocks most signals. Start by unblocking the
* ones that should be handled.
*
* Unblock SIGQUIT so the user can force exit the CFE
* by pressing CTRL+\ (default handler). Also allow
* SIGTERM for which a handler was installed in CFE_PSP_AttachExceptions()
*/
sigemptyset(&sigset);
sigaddset(&sigset, SIGQUIT);
sigaddset(&sigset, SIGTERM);
pthread_sigmask(SIG_UNBLOCK, &sigset, NULL);
/*
* Reset to the signal for background events (SIGUSR1)
*/
sigemptyset(&sigset);
sigaddset(&sigset, CFE_PSP_EXCEPTION_EVENT_SIGNAL);
/*
** just wait for events to occur and notify CFE
**
** "shutdownreq" will become true if CFE calls CFE_PSP_Restart(),
** indicating a request to gracefully exit and restart CFE.
*/
while (!CFE_PSP_IdleTaskState.ShutdownReq)
{
/* go idle and wait for an event */
ret = sigwait(&sigset, &sig);
if (ret == 0 && !CFE_PSP_IdleTaskState.ShutdownReq && sig == CFE_PSP_EXCEPTION_EVENT_SIGNAL &&
GLOBAL_CFE_CONFIGDATA.SystemNotify != NULL)
{
/* notify the CFE of the event */
GLOBAL_CFE_CONFIGDATA.SystemNotify();
}
}
/*
* This happens if an unhandled exception occurs, or if the user presses CTRL+C
*/
OS_printf("\nCFE_PSP: Shutdown initiated - Exiting cFE\n");
OS_TaskDelay(100);
OS_DeleteAllObjects();
}
/******************************************************************************
** Function: CFE_PSP_TimerHandler()
**
** Purpose:
** 1hz "isr" routine for linux/OSX
** This timer handler will execute 4 times a second.
**
** Arguments:
** (none)
**
** Return:
** (none)
*/
void CFE_PSP_TimerHandler(int signum)
{
/*
** call the CFE_TIME 1hz ISR
*/
if ((TimerCounter % 4) == 0)
CFE_PSP_1HZ_FUNCTION();
/* update timer counter */
TimerCounter++;
}
/******************************************************************************
** Function: CFE_PSP_DisplayUsage
**
** Purpose:
** Display program usage, and exit.
**
** Arguments:
** Name -- the name of the binary.
**
** Return:
** (none)
*/
void CFE_PSP_DisplayUsage(char *Name)
{
printf("usage : %s [-R <value>] [-S <value>] [-C <value] [-N <value] [-I <value] [-h] \n", Name);
printf("\n");
printf(" All parameters are optional and can be used in any order\n");
printf("\n");
printf(" Parameters include:\n");
printf(" -R [ --reset ] Reset Type is one of:\n");
printf(" PO for Power On reset ( default )\n");
printf(" PR for Processor Reset\n");
printf(" -S [ --subtype ] Reset Sub Type is one of\n");
printf(" 1 for Power on ( default )\n");
printf(" 2 for Push Button Reset\n");
printf(" 3 for Hardware Special Command Reset\n");
printf(" 4 for Watchdog Reset\n");
printf(" 5 for Reset Command\n");
printf(" -C [ --cpuid ] CPU ID is an integer CPU identifier.\n");
printf(" The default CPU ID is from the platform configuration file: %d\n", CFE_PSP_CPU_ID);
printf(" -N [ --cpuname ] CPU Name is a string to identify the CPU.\n");
printf(" The default CPU Name is from the platform configuration file: %s\n", CFE_PSP_CPU_NAME);
printf(" -I [ --scid ] Spacecraft ID is an integer Spacecraft identifier.\n");
printf(" The default Spacecraft ID is from the mission configuration file: %d\n",
CFE_PSP_SPACECRAFT_ID);
printf(" -h [ --help ] This message.\n");
printf("\n");
printf(" Example invocation:\n");
printf(" \n");
printf(" Short form:\n");
printf(" %s -R PO -S 1 -C 1 -N CPU1 -I 32\n", Name);
printf(" Long form:\n");
printf(" %s --reset PO --subtype 1 --cpuid 1 --cpuname CPU1 --scid 32\n", Name);
printf(" \n");
exit(1);
}
/******************************************************************************
** Function: CFE_PSP_ProcessArgumentDefaults
**
** Purpose:
** This function assigns defaults to parameters and checks to make sure
** the user entered required parameters
**
** Arguments:
** CFE_PSP_CommandData_t *CommandDataDefault -- A pointer to the command parameters.
**
** Return:
** (none)
*/
void CFE_PSP_ProcessArgumentDefaults(CFE_PSP_CommandData_t *CommandDataDefault)
{
if (CommandDataDefault->GotSubType == 0)
{
CommandDataDefault->SubType = 1;
printf("CFE_PSP: Default Reset SubType = 1\n");
CommandDataDefault->GotSubType = 1;
}
if (CommandDataDefault->GotCpuId == 0)
{
CommandDataDefault->CpuId = CFE_PSP_CPU_ID;
printf("CFE_PSP: Default CPU ID = %d\n", CFE_PSP_CPU_ID);
CommandDataDefault->GotCpuId = 1;
}
if (CommandDataDefault->GotSpacecraftId == 0)
{
CommandDataDefault->SpacecraftId = CFE_PSP_SPACECRAFT_ID;
printf("CFE_PSP: Default Spacecraft ID = %d\n", CFE_PSP_SPACECRAFT_ID);
CommandDataDefault->GotSpacecraftId = 1;
}
if (CommandDataDefault->GotCpuName == 0)
{
strncpy(CommandDataDefault->CpuName, CFE_PSP_CPU_NAME, CFE_PSP_CPU_NAME_LENGTH - 1);
CommandDataDefault->CpuName[CFE_PSP_CPU_NAME_LENGTH - 1] = 0;
printf("CFE_PSP: Default CPU Name: %s\n", CFE_PSP_CPU_NAME);
CommandDataDefault->GotCpuName = 1;
}
}
/******************************************************************************
** Function: CFE_PSP_SetupLocal1Hz
**
** Purpose:
** This is a backward-compatible timer setup that is invoked when
** there is a failure to set up the timebase in OSAL. It is basically
** the old way of doing things.
**
** IMPORTANT: Note this is technically incorrect as it gives the
** callback directly in the context of the signal handler. It is
** against spec to use most OSAL functions within a signal.
**
** This is included merely to mimic the previous system behavior. It
** should be removed in a future version of the PSP.
**
**
** Arguments:
** (none)
**
** Return:
** (none)
**
*/
void CFE_PSP_SetupLocal1Hz(void)
{
struct sigaction sa;
struct itimerval timer;
int ret;
/*
** Init timer counter
*/
TimerCounter = 0;
/*
** Install timer_handler as the signal handler for SIGALRM.
*/
memset(&sa, 0, sizeof(sa));
sa.sa_handler = &CFE_PSP_TimerHandler;
/*
** Configure the timer to expire after 250ms
**
** (this is historical; the actual callback is invoked
** only on every 4th timer tick. previous versions of the
** PSP did it this way, so this is preserved here).
*/
timer.it_value.tv_sec = 0;
timer.it_value.tv_usec = 250000;
timer.it_interval.tv_sec = 0;
timer.it_interval.tv_usec = 250000;
ret = sigaction(SIGALRM, &sa, NULL);
if (ret < 0)
{
OS_printf("CFE_PSP: sigaction() error %d: %s \n", ret, strerror(errno));
}
else
{
ret = setitimer(ITIMER_REAL, &timer, NULL);
if (ret < 0)
{
OS_printf("CFE_PSP: setitimer() error %d: %s \n", ret, strerror(errno));
}
}
}