Skip to content

Commit 64612ec

Browse files
committed
Merge pull request #104 from jphickey/fix-103-faster-wakeup
Fix #103, add option to configure base tick rate
2 parents af1f6c3 + 0396089 commit 64612ec

File tree

3 files changed

+79
-7
lines changed

3 files changed

+79
-7
lines changed

fsw/platform_inc/sch_lab_table.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,13 @@
4848
typedef struct
4949
{
5050
CFE_SB_MsgId_t MessageID; /* Message ID for the table entry */
51-
uint32 PacketRate; /* Rate: Send packet every N seconds */
51+
uint32 PacketRate; /* Rate: Send packet every N ticks */
5252
CFE_MSG_FcnCode_t FcnCode; /* Command/Function code to set */
5353
} SCH_LAB_ScheduleTableEntry_t;
5454

5555
typedef struct
5656
{
57+
uint32 TickRate; /* Ticks per second to configure for timer (0=default) */
5758
SCH_LAB_ScheduleTableEntry_t Config[SCH_LAB_MAX_SCHEDULE_ENTRIES];
5859
} SCH_LAB_ScheduleTable_t;
5960

fsw/src/sch_lab_app.c

Lines changed: 75 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ typedef struct
5959
typedef struct
6060
{
6161
SCH_LAB_StateEntry_t State[SCH_LAB_MAX_SCHEDULE_ENTRIES];
62+
osal_id_t TimerId;
63+
osal_id_t TimingSem;
6264
CFE_TBL_Handle_t TblHandle;
6365
CFE_SB_PipeId_t CmdPipe;
6466
} SCH_LAB_GlobalData_t;
@@ -80,8 +82,9 @@ void SCH_Lab_AppMain(void)
8082
{
8183
int i;
8284
uint32 SCH_OneHzPktsRcvd = 0;
83-
uint32 Status = CFE_SUCCESS;
84-
uint32 RunStatus = CFE_ES_RunStatus_APP_RUN;
85+
int32 OsStatus;
86+
CFE_Status_t Status;
87+
uint32 RunStatus = CFE_ES_RunStatus_APP_RUN;
8588
SCH_LAB_StateEntry_t *LocalStateEntry;
8689
CFE_SB_Buffer_t * SBBufPtr;
8790

@@ -99,16 +102,29 @@ void SCH_Lab_AppMain(void)
99102
{
100103
CFE_ES_PerfLogExit(SCH_MAIN_TASK_PERF_ID);
101104

102-
/* Pend on receipt of 1Hz packet */
103-
Status = CFE_SB_ReceiveBuffer(&SBBufPtr, SCH_LAB_Global.CmdPipe, CFE_SB_PEND_FOREVER);
105+
/* Pend on timing sem */
106+
OsStatus = OS_CountSemTake(SCH_LAB_Global.TimingSem);
107+
if (OsStatus == OS_SUCCESS)
108+
{
109+
/* check for arrival of the 1Hz - this should sync counts (TBD) */
110+
Status = CFE_SB_ReceiveBuffer(&SBBufPtr, SCH_LAB_Global.CmdPipe, CFE_SB_POLL);
111+
}
112+
else
113+
{
114+
Status = CFE_STATUS_EXTERNAL_RESOURCE_FAIL;
115+
}
104116

105117
CFE_ES_PerfLogEntry(SCH_MAIN_TASK_PERF_ID);
106118

107119
if (Status == CFE_SUCCESS)
108120
{
109121
SCH_OneHzPktsRcvd++;
122+
}
123+
124+
if (OsStatus == OS_SUCCESS && SCH_OneHzPktsRcvd > 0)
125+
{
110126
/*
111-
** Process table every second, sending packets that are ready
127+
** Process table every tick, sending packets that are ready
112128
*/
113129
LocalStateEntry = SCH_LAB_Global.State;
114130
for (i = 0; i < SCH_LAB_MAX_SCHEDULE_ENTRIES; i++)
@@ -132,6 +148,11 @@ void SCH_Lab_AppMain(void)
132148

133149
} /* end SCH_Lab_AppMain */
134150

151+
void SCH_LAB_LocalTimerCallback(osal_id_t object_id, void *arg)
152+
{
153+
OS_CountSemGive(SCH_LAB_Global.TimingSem);
154+
}
155+
135156
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
136157
/* */
137158
/* SCH_LAB_AppInit() -- initialization */
@@ -141,13 +162,39 @@ int32 SCH_LAB_AppInit(void)
141162
{
142163
int i;
143164
int32 Status;
165+
int32 OsStatus;
166+
uint32 TimerPeriod;
167+
osal_id_t TimeBaseId;
144168
SCH_LAB_ScheduleTable_t * ConfigTable;
145169
SCH_LAB_ScheduleTableEntry_t *ConfigEntry;
146170
SCH_LAB_StateEntry_t * LocalStateEntry;
147171
void * TableAddr;
148172

149173
memset(&SCH_LAB_Global, 0, sizeof(SCH_LAB_Global));
150174

175+
OsStatus = OS_CountSemCreate(&SCH_LAB_Global.TimingSem, "SCH_LAB", 0, 0);
176+
if (OsStatus != OS_SUCCESS)
177+
{
178+
CFE_ES_WriteToSysLog("%s: OS_CountSemCreate failed:RC=%ld\n", __func__, (long)OsStatus);
179+
return CFE_STATUS_EXTERNAL_RESOURCE_FAIL;
180+
}
181+
182+
/* The underlying timebase object should have been created by the PSP */
183+
OsStatus = OS_TimeBaseGetIdByName(&TimeBaseId, "cFS-Master");
184+
if (OsStatus != OS_SUCCESS)
185+
{
186+
CFE_ES_WriteToSysLog("%s: OS_TimeBaseGetIdByName failed:RC=%ld\n", __func__, (long)OsStatus);
187+
return CFE_STATUS_EXTERNAL_RESOURCE_FAIL;
188+
}
189+
190+
/* Create the timer callback (but not set yet, as that requires the config table) */
191+
OsStatus = OS_TimerAdd(&SCH_LAB_Global.TimerId, "SCH_LAB", TimeBaseId, SCH_LAB_LocalTimerCallback, NULL);
192+
if (OsStatus != OS_SUCCESS)
193+
{
194+
CFE_ES_WriteToSysLog("%s: OS_TimerAdd failed:RC=%ld\n", __func__, (long)OsStatus);
195+
return CFE_STATUS_EXTERNAL_RESOURCE_FAIL;
196+
}
197+
151198
/*
152199
** Register tables with cFE and load default data
153200
*/
@@ -206,6 +253,22 @@ int32 SCH_LAB_AppInit(void)
206253
++LocalStateEntry;
207254
}
208255

256+
if (ConfigTable->TickRate == 0)
257+
{
258+
/* use default of 1 second */
259+
CFE_ES_WriteToSysLog("%s: Using default tick rate of 1 second\n", __func__);
260+
TimerPeriod = 1000000;
261+
}
262+
else
263+
{
264+
TimerPeriod = 1000000 / ConfigTable->TickRate;
265+
if ((TimerPeriod * ConfigTable->TickRate) != 1000000)
266+
{
267+
CFE_ES_WriteToSysLog("%s: WARNING: tick rate of %lu is not an integer number of microseconds\n", __func__,
268+
(unsigned long)ConfigTable->TickRate);
269+
}
270+
}
271+
209272
/*
210273
** Release the table
211274
*/
@@ -228,6 +291,13 @@ int32 SCH_LAB_AppInit(void)
228291
OS_printf("SCH Error subscribing to 1hz!\n");
229292
}
230293

294+
/* Set timer period */
295+
OsStatus = OS_TimerSet(SCH_LAB_Global.TimerId, 1000000, TimerPeriod);
296+
if (OsStatus != OS_SUCCESS)
297+
{
298+
CFE_ES_WriteToSysLog("%s: OS_TimerSet failed:RC=%ld\n", __func__, (long)OsStatus);
299+
}
300+
231301
OS_printf("SCH Lab Initialized.%s\n", SCH_LAB_VERSION_STRING);
232302

233303
return (CFE_SUCCESS);

fsw/tables/sch_lab_table.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
** 3. If the table grows too big, increase SCH_LAB_MAX_SCHEDULE_ENTRIES
5050
*/
5151

52-
SCH_LAB_ScheduleTable_t SCH_TBL_Structure = {.Config = {
52+
SCH_LAB_ScheduleTable_t SCH_TBL_Structure = {.TickRate = 1,
53+
.Config = {
5354
{CFE_SB_MSGID_WRAP_VALUE(CFE_ES_SEND_HK_MID), 4, 0},
5455
{CFE_SB_MSGID_WRAP_VALUE(CFE_EVS_SEND_HK_MID), 4, 0},
5556
{CFE_SB_MSGID_WRAP_VALUE(CFE_TIME_SEND_HK_MID), 4, 0},

0 commit comments

Comments
 (0)