Skip to content

Commit

Permalink
Fix nasa#60, rework loop in CF_CFDP_CycleTx
Browse files Browse the repository at this point in the history
Modifies the loop inside this function to be more conventional, and
easier to follow. Does not change the logic.
  • Loading branch information
jphickey committed Jan 12, 2022
1 parent c0bf0bd commit decb85b
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions fsw/src/cf_cfdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1101,30 +1101,38 @@ int CF_CFDP_CycleTxFirstActive(CF_CListNode_t *node, void *context)
*-----------------------------------------------------------------*/
void CF_CFDP_CycleTx(CF_Channel_t *c)
{
CF_Transaction_t *t;
CF_CFDP_CycleTx_args_t args;

if (CF_AppData.config_table->chan[(c - CF_AppData.engine.channels)].dequeue_enabled)
{
CF_CFDP_CycleTx_args_t args = {c, 0};
args = (CF_CFDP_CycleTx_args_t) {c, 0};

/* loop through as long as there are pending transactions, and a message buffer to send their pdus on */

/* NOTE: tick processesing is higher priority than sending new filedata pdus, so only send however many
* PDUs that can be sent once we get to here */
if (!c->cur)
{ /* don't enter if cur is set, since we need to pick up where we left off on tick processing next wakeup */
goto entry_jump; /* code reviewers won't like this */
while (!args.ran_one && c->qs[CF_QueueIdx_PEND])

while (true)
{
/* didn't find anything on TXA to run, so pop one off Q_PEND and try again.
* Keep going until CF_QueueIdx_PEND is empty or something is run */
CF_Transaction_t *t = container_of(c->qs[CF_QueueIdx_PEND], CF_Transaction_t, cl_node);
CF_MoveTransaction(t, CF_QueueIdx_TXA);
/* args is ok, still { c, 0 } */
entry_jump:
/* Attempt to run something on TXA */
CF_CList_Traverse(c->qs[CF_QueueIdx_TXA], CF_CFDP_CycleTxFirstActive, &args);

/* Keep going until CF_QueueIdx_PEND is empty or something is run */
if (args.ran_one || c->qs[CF_QueueIdx_PEND] == NULL)
{
break;
}

t = container_of(c->qs[CF_QueueIdx_PEND], CF_Transaction_t, cl_node);
CF_MoveTransaction(t, CF_QueueIdx_TXA);
}
}

c->cur =
NULL; /* in case the loop exited due to no message buffers, clear it and start from the top next time */
/* in case the loop exited due to no message buffers, clear it and start from the top next time */
c->cur = NULL;
}
}

Expand Down

0 comments on commit decb85b

Please sign in to comment.