Skip to content

Commit 7a12058

Browse files
committed
Fix nasa#32 nasa#33, Refactor hs_custom.c to support full coverage
- Replace direct use of config value in conditional w/ global - Replace redundant condition in search for empty diag slot
1 parent 70ebc47 commit 7a12058

File tree

2 files changed

+23
-28
lines changed

2 files changed

+23
-28
lines changed

fsw/src/hs_custom.c

+21-28
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ int32 HS_CustomInit(void)
9191
{
9292
int32 Status;
9393

94+
memset(&HS_CustomData, 0, sizeof(HS_CustomData));
95+
9496
/*
9597
** Spawn the Idle Task
9698
*/
@@ -118,16 +120,13 @@ int32 HS_CustomInit(void)
118120
(unsigned int)Status);
119121
}
120122

121-
HS_CustomData.UtilMult1 = HS_UTIL_CONV_MULT1;
122-
HS_CustomData.UtilMult2 = HS_UTIL_CONV_MULT2;
123-
HS_CustomData.UtilDiv = HS_UTIL_CONV_DIV;
124-
HS_CustomData.UtilMask = HS_UTIL_DIAG_MASK;
125-
HS_CustomData.UtilCycleCounter = 0;
126-
HS_CustomData.UtilArrayIndex = 0;
127-
HS_CustomData.UtilArrayMask = HS_UTIL_TIME_DIAG_ARRAY_MASK;
128-
HS_CustomData.ThisIdleTaskExec = 0;
129-
HS_CustomData.LastIdleTaskExec = 0;
130-
HS_CustomData.LastIdleTaskInterval = 0;
123+
/* Non-zero initialization */
124+
HS_CustomData.UtilMult1 = HS_UTIL_CONV_MULT1;
125+
HS_CustomData.UtilMult2 = HS_UTIL_CONV_MULT2;
126+
HS_CustomData.UtilDiv = HS_UTIL_CONV_DIV;
127+
HS_CustomData.UtilMask = HS_UTIL_DIAG_MASK;
128+
HS_CustomData.UtilArrayMask = HS_UTIL_TIME_DIAG_ARRAY_MASK;
129+
HS_CustomData.UtilCallsPerMark = HS_UTIL_CALLS_PER_MARK;
131130

132131
return (Status);
133132

@@ -183,7 +182,7 @@ void HS_UtilizationMark(void)
183182

184183
CycleCount++;
185184

186-
if (CycleCount >= HS_UTIL_CALLS_PER_MARK)
185+
if (CycleCount >= HS_CustomData.UtilCallsPerMark)
187186
{
188187
HS_CustomData.LastIdleTaskInterval = HS_CustomData.ThisIdleTaskExec - HS_CustomData.LastIdleTaskExec;
189188
HS_CustomData.LastIdleTaskExec = HS_CustomData.ThisIdleTaskExec;
@@ -278,10 +277,9 @@ void HS_UtilDiagReport(void)
278277
{
279278
uint32 DiagValue[HS_UTIL_TIME_DIAG_ARRAY_LENGTH];
280279
uint32 DiagCount[HS_UTIL_TIME_DIAG_ARRAY_LENGTH];
281-
uint32 i = 0;
282-
uint32 j = 0;
283-
uint32 ThisValue = 0;
284-
bool MatchFound = false;
280+
uint32 i = 0;
281+
uint32 j = 0;
282+
uint32 ThisValue = 0;
285283

286284
uint32 Ordinal = 0;
287285
uint32 NewOrdinalIndex = 0;
@@ -314,24 +312,19 @@ void HS_UtilDiagReport(void)
314312
ThisValue = HS_CustomData.UtilArray[i] - HS_CustomData.UtilArray[i - 1];
315313
}
316314

317-
j = 0;
318-
MatchFound = false;
319-
while ((MatchFound == false) && (j < HS_UTIL_TIME_DIAG_ARRAY_LENGTH))
315+
for (j = 0; j < HS_UTIL_TIME_DIAG_ARRAY_LENGTH; j++)
320316
{
321-
if (ThisValue == DiagValue[j])
322-
{
323-
DiagCount[j]++;
324-
MatchFound = true;
325-
}
326-
else if (DiagValue[j] == 0xFFFFFFFF)
317+
if (DiagValue[j] == 0xFFFFFFFF)
327318
{
319+
/* Acquire a slot if empty */
328320
DiagValue[j] = ThisValue;
329-
DiagCount[j]++;
330-
MatchFound = true;
331321
}
332-
else
322+
323+
if (ThisValue == DiagValue[j])
333324
{
334-
j++;
325+
/* Increment count and cause loop to exit on match */
326+
DiagCount[j]++;
327+
j = HS_UTIL_TIME_DIAG_ARRAY_LENGTH;
335328
}
336329
}
337330
}

fsw/src/hs_custom.h

+2
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ typedef struct
266266
uint32 LastIdleTaskInterval; /**< \brief Idle Task Increments during Previous Interval */
267267
uint32 UtilCycleCounter; /**< \brief Counter to determine when to monitor utilization */
268268

269+
int32 UtilCallsPerMark; /**< \brief CPU Utilization Calls per mark */
270+
269271
int32 IdleTaskRunStatus; /**< \brief HS Idle Task Run Status */
270272
CFE_ES_TaskId_t IdleTaskID; /**< \brief HS Idle Task Task ID */
271273

0 commit comments

Comments
 (0)