From 9c85db086c07f467e18c609224f703e40658e284 Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Thu, 27 Apr 2023 23:53:48 +0000 Subject: [PATCH] Fix #380, Support polling with no delay --- fsw/inc/cf_tbldefs.h | 6 +----- fsw/src/cf_cfdp.c | 7 ++++--- unit-test/cf_cfdp_tests.c | 16 +++++++++------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/fsw/inc/cf_tbldefs.h b/fsw/inc/cf_tbldefs.h index f66743c3..c2a55a03 100644 --- a/fsw/inc/cf_tbldefs.h +++ b/fsw/inc/cf_tbldefs.h @@ -33,11 +33,7 @@ */ typedef struct CF_PollDir { - uint32 interval_sec; /**< - * \brief number of seconds to wait before trying a new directory. - * - * Must be >0 or slot is inactive. - */ + uint32 interval_sec; /**< \brief number of seconds to wait before trying a new directory */ uint8 priority; /**< \brief priority to use when placing transactions on the pending queue */ CF_CFDP_Class_t cfdp_class; /**< \brief the CFDP class to send */ diff --git a/fsw/src/cf_cfdp.c b/fsw/src/cf_cfdp.c index 4c8e9a0c..a8170aca 100644 --- a/fsw/src/cf_cfdp.c +++ b/fsw/src/cf_cfdp.c @@ -1510,12 +1510,11 @@ void CF_CFDP_ProcessPollingDirectories(CF_Channel_t *c) pd = &cc->polldir[i]; count_check = 0; - if (pd->enabled && pd->interval_sec) + if (pd->enabled) { - /* only handle polling for polldirs configured with a non-zero interval */ if (!p->pb.busy && !p->pb.num_ts) { - if (!p->timer_set) + if (!p->timer_set && pd->interval_sec) { /* timer was not set, so set it now */ CF_Timer_InitRelSec(&p->interval_timer, pd->interval_sec); @@ -1539,7 +1538,9 @@ void CF_CFDP_ProcessPollingDirectories(CF_Channel_t *c) } } else + { CF_Timer_Tick(&p->interval_timer); + } } else { diff --git a/unit-test/cf_cfdp_tests.c b/unit-test/cf_cfdp_tests.c index d380706f..d17d8c16 100644 --- a/unit-test/cf_cfdp_tests.c +++ b/unit-test/cf_cfdp_tests.c @@ -1137,27 +1137,29 @@ void Test_CF_CFDP_ProcessPollingDirectories(void) pdcfg = &config->chan[UT_CFDP_CHANNEL].polldir[0]; poll = &c->poll[0]; - /* nominal call, w/engine disabled (noop) */ + /* nominal call, polldir disabled (noop) */ UtAssert_VOIDCALL(CF_CFDP_ProcessPollingDirectories(c)); UtAssert_UINT32_EQ(CF_AppData.hk.channel_hk[UT_CFDP_CHANNEL].poll_counter, 0); - /* nominal call, w/engine enabled, polldir enabled but interval_sec == 0 */ - CF_AppData.engine.enabled = 1; - pdcfg->enabled = 1; + /* nominal call, polldir enabled but interval_sec == 0 */ + /* Will tick because CF_Timer_Expired stub returns 0 by default (not expired) */ + pdcfg->enabled = 1; UtAssert_VOIDCALL(CF_CFDP_ProcessPollingDirectories(c)); - UtAssert_UINT32_EQ(CF_AppData.hk.channel_hk[UT_CFDP_CHANNEL].poll_counter, 0); + UtAssert_BOOL_FALSE(poll->timer_set); + UtAssert_UINT32_EQ(CF_AppData.hk.channel_hk[UT_CFDP_CHANNEL].poll_counter, 1); + UtAssert_STUB_COUNT(CF_Timer_Tick, 1); /* with interval_sec nonzero the timer should get set, but not tick */ pdcfg->interval_sec = 1; UtAssert_VOIDCALL(CF_CFDP_ProcessPollingDirectories(c)); UtAssert_BOOL_TRUE(poll->timer_set); - UtAssert_STUB_COUNT(CF_Timer_Tick, 0); + UtAssert_STUB_COUNT(CF_Timer_Tick, 1); UtAssert_UINT32_EQ(CF_AppData.hk.channel_hk[UT_CFDP_CHANNEL].poll_counter, 1); /* call again should tick */ UtAssert_VOIDCALL(CF_CFDP_ProcessPollingDirectories(c)); UtAssert_BOOL_TRUE(poll->timer_set); - UtAssert_STUB_COUNT(CF_Timer_Tick, 1); + UtAssert_STUB_COUNT(CF_Timer_Tick, 2); /* call again timer should expire and start a playback */ UT_SetDeferredRetcode(UT_KEY(CF_Timer_Expired), 1, true);