-
Notifications
You must be signed in to change notification settings - Fork 37
/
sch_lab_app.c
242 lines (205 loc) · 6.91 KB
/
sch_lab_app.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
/************************************************************************
**
** 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: sch_lab_app.c
**
** Purpose:
** This file contains the source code for the SCH lab application
**
** Notes:
**
*************************************************************************/
/*
** Include Files
*/
#include <string.h>
#include "cfe.h"
#include "cfe_sb.h"
#include "osapi.h"
#include "cfe_es.h"
#include "cfe_error.h"
#include "sch_lab_perfids.h"
#include "sch_lab_version.h"
/*
** SCH Lab Schedule table from the platform inc directory
*/
#include "sch_lab_sched_tab.h"
/*
** Global Structure
*/
typedef union
{
CFE_SB_Msg_t MsgHdr;
CFE_SB_CmdHdr_t CommandHeader;
} SCH_LAB_MessageBuffer_t;
typedef struct
{
SCH_LAB_MessageBuffer_t MsgBuf;
uint32 PacketRate;
uint32 Counter;
} SCH_LAB_StateEntry_t;
typedef struct
{
SCH_LAB_StateEntry_t State[SCH_LAB_MAX_SCHEDULE_ENTRIES];
CFE_TBL_Handle_t TblHandle;
CFE_SB_Msg_t * CmdPipePktPtr;
CFE_SB_PipeId_t CmdPipe;
} SCH_LAB_GlobalData_t;
/*
** Global Variables
*/
SCH_LAB_GlobalData_t SCH_LAB_Global;
/*
** Local Function Prototypes
*/
int32 SCH_LAB_AppInit(void);
/*
** AppMain
*/
void SCH_Lab_AppMain(void)
{
int i;
uint32 SCH_OneHzPktsRcvd = 0;
uint32 Status = CFE_SUCCESS;
uint32 RunStatus = CFE_ES_RunStatus_APP_RUN;
SCH_LAB_StateEntry_t *LocalStateEntry;
CFE_ES_PerfLogEntry(SCH_MAIN_TASK_PERF_ID);
CFE_ES_RegisterApp();
Status = SCH_LAB_AppInit();
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("SCH_LAB: Error Initializing RC = 0x%08lX\n", (unsigned long)Status);
}
/* Loop Forever */
while (CFE_ES_RunLoop(&RunStatus) == true)
{
CFE_ES_PerfLogExit(SCH_MAIN_TASK_PERF_ID);
/* Pend on receipt of 1Hz packet */
Status = CFE_SB_RcvMsg(&SCH_LAB_Global.CmdPipePktPtr, SCH_LAB_Global.CmdPipe, CFE_SB_PEND_FOREVER);
CFE_ES_PerfLogEntry(SCH_MAIN_TASK_PERF_ID);
if (Status == CFE_SUCCESS)
{
SCH_OneHzPktsRcvd++;
/*
** Process table every second, sending packets that are ready
*/
LocalStateEntry = SCH_LAB_Global.State;
for (i = 0; i < SCH_LAB_MAX_SCHEDULE_ENTRIES; i++)
{
if (LocalStateEntry->PacketRate != 0)
{
++LocalStateEntry->Counter;
if (LocalStateEntry->Counter >= LocalStateEntry->PacketRate)
{
LocalStateEntry->Counter = 0;
CFE_SB_SendMsg(&LocalStateEntry->MsgBuf.MsgHdr);
}
}
++LocalStateEntry;
}
}
} /* end while */
CFE_ES_ExitApp(Status);
} /* end SCH_Lab_AppMain */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* SCH_LAB_AppInit() -- initialization */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 SCH_LAB_AppInit(void)
{
int i;
int32 Status;
SCH_LAB_ScheduleTable_t * ConfigTable;
SCH_LAB_ScheduleTableEntry_t *ConfigEntry;
SCH_LAB_StateEntry_t * LocalStateEntry;
memset(&SCH_LAB_Global, 0, sizeof(SCH_LAB_Global));
/*
** Register tables with cFE and load default data
*/
Status = CFE_TBL_Register(&SCH_LAB_Global.TblHandle, "SCH_LAB_SchTbl", sizeof(SCH_LAB_ScheduleTable_t),
CFE_TBL_OPT_DEFAULT, NULL);
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("SCH_LAB: Error Registering SCH_LAB_SchTbl, RC = 0x%08lX\n", (unsigned long)Status);
return (Status);
}
else
{
/*
** Loading Table
*/
Status = CFE_TBL_Load(SCH_LAB_Global.TblHandle, CFE_TBL_SRC_FILE, SCH_TBL_DEFAULT_FILE);
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("SCH_LAB: Error Loading Table SCH_LAB_SchTbl, RC = 0x%08lX\n", (unsigned long)Status);
CFE_TBL_ReleaseAddress(SCH_LAB_Global.TblHandle);
return (Status);
}
}
/*
** Get Table Address
*/
Status = CFE_TBL_GetAddress((void **)&ConfigTable, SCH_LAB_Global.TblHandle);
if (Status != CFE_SUCCESS && Status != CFE_TBL_INFO_UPDATED)
{
CFE_ES_WriteToSysLog("SCH_LAB: Error Getting Table's Address SCH_LAB_SchTbl, RC = 0x%08lX\n",
(unsigned long)Status);
return (Status);
}
/*
** Initialize the command headers
*/
ConfigEntry = ConfigTable->Config;
LocalStateEntry = SCH_LAB_Global.State;
for (i = 0; i < SCH_LAB_MAX_SCHEDULE_ENTRIES; i++)
{
if (ConfigEntry->PacketRate != 0)
{
CFE_SB_InitMsg(&LocalStateEntry->MsgBuf.MsgHdr, ConfigEntry->MessageID, sizeof(LocalStateEntry->MsgBuf),
true);
LocalStateEntry->PacketRate = ConfigEntry->PacketRate;
}
++ConfigEntry;
++LocalStateEntry;
}
/*
** Release the table
*/
Status = CFE_TBL_ReleaseAddress(SCH_LAB_Global.TblHandle);
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("SCH_LAB: Error Releasing Table SCH_LAB_SchTbl, RC = 0x%08lX\n", (unsigned long)Status);
}
/* Create pipe and subscribe to the 1Hz pkt */
Status = CFE_SB_CreatePipe(&SCH_LAB_Global.CmdPipe, 8, "SCH_LAB_CMD_PIPE");
if (Status != CFE_SUCCESS)
{
OS_printf("SCH Error creating pipe!\n");
}
Status = CFE_SB_Subscribe(CFE_TIME_1HZ_CMD_MID, SCH_LAB_Global.CmdPipe);
if (Status != CFE_SUCCESS)
{
OS_printf("SCH Error subscribing to 1hz!\n");
}
OS_printf("SCH Lab Initialized. Version %d.%d.%d.%d\n", SCH_LAB_MAJOR_VERSION, SCH_LAB_MINOR_VERSION,
SCH_LAB_REVISION, SCH_LAB_MISSION_REV);
return (CFE_SUCCESS);
} /*End of AppInit*/