Skip to content

Commit

Permalink
Partial nasa#42, naming convention pass though cf_chunk.h
Browse files Browse the repository at this point in the history
Updates names of all identifiers in cf_chunk.h to follow naming
conventions from CFE.
  • Loading branch information
jphickey committed Dec 8, 2021
1 parent 17e413c commit d66ed3e
Show file tree
Hide file tree
Showing 12 changed files with 713 additions and 709 deletions.
2 changes: 1 addition & 1 deletion fsw/src/cf_cfdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,7 @@ int32 CF_CFDP_InitEngine(void)
for (k = 0; k < CF_Direction_NUM; ++k, ++c)
{
CF_Assert((chunk_mem_offset + CF_max_chunks[k][i]) <= CF_NUM_CHUNKS_ALL_CHANNELS);
CF_Chunks_Init(&c->chunks, CF_max_chunks[k][i], &CF_AppData.engine.chunk_mem[chunk_mem_offset]);
CF_ChunkListInit(&c->chunks, CF_max_chunks[k][i], &CF_AppData.engine.chunk_mem[chunk_mem_offset]);
chunk_mem_offset += CF_max_chunks[k][i];
CF_CList_InitNode(&c->cl_node);
CF_CList_InsertBack(&CF_AppData.engine.channels[i].cs[k], &c->cl_node);
Expand Down
6 changes: 3 additions & 3 deletions fsw/src/cf_cfdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ typedef struct

typedef struct
{
chunks_t chunks;
clist_node_t cl_node;
CF_ChunkList_t chunks;
clist_node_t cl_node;
} CF_ChunkWrapper_t;

typedef struct
Expand Down Expand Up @@ -337,7 +337,7 @@ typedef struct
CF_Channel_t channels[CF_NUM_CHANNELS];

CF_ChunkWrapper_t chunks[CF_NUM_TRANSACTIONS * CF_Direction_NUM];
chunk_t chunk_mem[CF_NUM_CHUNKS_ALL_CHANNELS];
CF_Chunk_t chunk_mem[CF_NUM_CHUNKS_ALL_CHANNELS];

uint32 outgoing_counter;
uint8 enabled;
Expand Down
16 changes: 8 additions & 8 deletions fsw/src/cf_cfdp_r.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ static void CF_CFDP_R2_Complete(CF_Transaction_t *t, int ok_to_send_nak)
else
{
/* only look for 1 gap, since the goal here is just to know that there are gaps */
uint32 ret = CF_Chunks_ComputeGaps(&t->chunks->chunks, 1, t->fsize, 0, NULL, NULL);
uint32 ret = CF_ChunkList_ComputeGaps(&t->chunks->chunks, 1, t->fsize, 0, NULL, NULL);

if (ret)
{
Expand Down Expand Up @@ -481,7 +481,7 @@ static void CF_CFDP_R2_SubstateRecvFileData(CF_Transaction_t *t, const CF_CFDP_P

cfdp_ldst_uint32(offset, STATIC_CAST(ph, CF_CFDP_PduFd_t)->fdh.offset);
/* class 2 does crc at FIN, but track gaps */
CF_Chunks_Add(&t->chunks->chunks, offset, (uint32)bytes_received);
CF_ChunkListAdd(&t->chunks->chunks, offset, (uint32)bytes_received);

if (t->flags.rx.fd_nak_sent)
{
Expand Down Expand Up @@ -515,7 +515,7 @@ static void CF_CFDP_R2_SubstateRecvFileData(CF_Transaction_t *t, const CF_CFDP_P
** \endreturns
**
*************************************************************************/
static void CF_CFDP_R2_GapCompute(const chunks_t *chunks, const chunk_t *c, void *opaque)
static void CF_CFDP_R2_GapCompute(const CF_ChunkList_t *chunks, const CF_Chunk_t *c, void *opaque)
{
gap_compute_args_t *args = (gap_compute_args_t *)opaque;
CF_CFDP_PduNak_t *nak = STATIC_CAST(args->ph, CF_CFDP_PduNak_t);
Expand Down Expand Up @@ -567,11 +567,11 @@ static int CF_CFDP_R_SubstateSendNak(CF_Transaction_t *t)
uint32 cret;

cfdp_ldst_uint32(nak->scope_start, 0);
cret = CF_Chunks_ComputeGaps(&t->chunks->chunks,
(t->chunks->chunks.count < t->chunks->chunks.CF_max_chunks)
? t->chunks->chunks.CF_max_chunks
: (t->chunks->chunks.CF_max_chunks - 1),
t->fsize, 0, CF_CFDP_R2_GapCompute, &args);
cret = CF_ChunkList_ComputeGaps(&t->chunks->chunks,
(t->chunks->chunks.count < t->chunks->chunks.CF_max_chunks)
? t->chunks->chunks.CF_max_chunks
: (t->chunks->chunks.CF_max_chunks - 1),
t->fsize, 0, CF_CFDP_R2_GapCompute, &args);

if (!cret)
{
Expand Down
10 changes: 5 additions & 5 deletions fsw/src/cf_cfdp_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ static void CF_CFDP_S_SubstateSendFileData(CF_Transaction_t *t)
*************************************************************************/
static int CF_CFDP_S_CheckAndRespondNak(CF_Transaction_t *t)
{
const chunk_t *c;
int ret = 0;
const CF_Chunk_t *c;
int ret = 0;

if (t->flags.tx.md_need_send)
{
Expand All @@ -290,12 +290,12 @@ static int CF_CFDP_S_CheckAndRespondNak(CF_Transaction_t *t)
/* unless CF_SendRet_ERROR, return 1 to keep caller from sending file data */
ret = 1; /* 1 means nak processed, so don't send filedata */
}
else if ((c = CF_Chunks_GetFirstChunk(&t->chunks->chunks)))
else if ((c = CF_ChunkList_GetFirstChunk(&t->chunks->chunks)))
{
ret = CF_CFDP_S_SendFileData(t, c->offset, c->size, 0);
if (ret > 0)
{
CF_Chunks_RemoveFromFirst(&t->chunks->chunks, ret);
CF_ChunkList_RemoveFromFirst(&t->chunks->chunks, ret);
ret = 1; /* processed nak, so caller doesn't send file data */
}
else if (ret < 0)
Expand Down Expand Up @@ -535,7 +535,7 @@ static void CF_CFDP_S2_Nak(CF_Transaction_t *t, const CF_CFDP_PduHeader_t *ph)
if ((start + size) <= t->fsize)
{
/* insert gap data in chunks */
CF_Chunks_Add(&t->chunks->chunks, start, size);
CF_ChunkListAdd(&t->chunks->chunks, start, size);
}
else
{
Expand Down
86 changes: 43 additions & 43 deletions fsw/src/cf_chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
** chunks must not be NULL.
**
*************************************************************************/
static void CF_Chunks_EraseRange(chunks_t *chunks, index_t start, index_t end)
static void CF_Chunks_EraseRange(CF_ChunkList_t *chunks, CF_ChunkIdx_t start, CF_ChunkIdx_t end)
{
CF_Assert(end >= start);
if (start < chunks->count)
Expand All @@ -70,7 +70,7 @@ static void CF_Chunks_EraseRange(chunks_t *chunks, index_t start, index_t end)
** chunks must not be NULL.
**
*************************************************************************/
static void CF_Chunks_EraseChunk(chunks_t *chunks, index_t erase_index)
static void CF_Chunks_EraseChunk(CF_ChunkList_t *chunks, CF_ChunkIdx_t erase_index)
{
CF_Assert(chunks->count > 0);
CF_Assert(erase_index < chunks->count);
Expand All @@ -88,7 +88,7 @@ static void CF_Chunks_EraseChunk(chunks_t *chunks, index_t erase_index)
** chunks must not be NULL. chunk must not be NULL.
**
*************************************************************************/
static void CF_Chunks_InsertChunk(chunks_t *chunks, index_t index_before, const chunk_t *chunk)
static void CF_Chunks_InsertChunk(CF_ChunkList_t *chunks, CF_ChunkIdx_t index_before, const CF_Chunk_t *chunk)
{
CF_Assert(chunks->count < chunks->CF_max_chunks);
CF_Assert(index_before <= chunks->count);
Expand Down Expand Up @@ -117,12 +117,12 @@ static void CF_Chunks_InsertChunk(chunks_t *chunks, index_t index_before, const
** \endreturns
**
*************************************************************************/
static index_t CF_Chunks_FindInsertPosition(chunks_t *chunks, const chunk_t *chunk)
static CF_ChunkIdx_t CF_Chunks_FindInsertPosition(CF_ChunkList_t *chunks, const CF_Chunk_t *chunk)
{
index_t first = 0;
index_t i;
index_t count = chunks->count;
index_t step;
CF_ChunkIdx_t first = 0;
CF_ChunkIdx_t i;
CF_ChunkIdx_t count = chunks->count;
CF_ChunkIdx_t step;

while (count > 0)
{
Expand Down Expand Up @@ -154,17 +154,17 @@ static index_t CF_Chunks_FindInsertPosition(chunks_t *chunks, const chunk_t *chu
** \endreturns
**
*************************************************************************/
static int CF_Chunks_CombinePrevious(chunks_t *chunks, index_t i, const chunk_t *chunk)
static int CF_Chunks_CombinePrevious(CF_ChunkList_t *chunks, CF_ChunkIdx_t i, const CF_Chunk_t *chunk)
{
int ret = 0;
CF_Assert(i <= chunks->CF_max_chunks);

chunk_offset_t chunk_end = chunk->offset + chunk->size;
CF_ChunkOffset_t chunk_end = chunk->offset + chunk->size;

if ((i && chunks->count))
{
chunk_t *prev = &chunks->chunks[i - 1];
chunk_offset_t prev_end = prev->offset + prev->size;
CF_Chunk_t *prev = &chunks->chunks[i - 1];
CF_ChunkOffset_t prev_end = prev->offset + prev->size;
if (chunk->offset <= prev_end)
{
if (prev_end < chunk_end)
Expand All @@ -189,25 +189,25 @@ static int CF_Chunks_CombinePrevious(chunks_t *chunks, index_t i, const chunk_t
** \endreturns
**
*************************************************************************/
static int CF_Chunks_CombineNext(chunks_t *chunks, index_t i, const chunk_t *chunk)
static int CF_Chunks_CombineNext(CF_ChunkList_t *chunks, CF_ChunkIdx_t i, const CF_Chunk_t *chunk)
{
/* check if not at the end */
int ret = 0;
if (i != chunks->count)
{
chunk_offset_t chunk_end = chunk->offset + chunk->size;
CF_ChunkOffset_t chunk_end = chunk->offset + chunk->size;
CF_Assert(chunk_end >= chunk->offset);

/* check if anything can be combined */
if (chunks->chunks[i].offset <= chunk_end)
{
/* figure out how many chunks can be combined */
index_t combined_i = i;
chunk_offset_t new_end; /* initialized below */
CF_ChunkIdx_t combined_i = i;
CF_ChunkOffset_t new_end; /* initialized below */

for (; combined_i < chunks->count; ++combined_i)
{
chunk_offset_t existing_end = chunks->chunks[combined_i].offset + chunks->chunks[combined_i].size;
CF_ChunkOffset_t existing_end = chunks->chunks[combined_i].offset + chunks->chunks[combined_i].size;
if (chunk_end < existing_end)
{
break;
Expand Down Expand Up @@ -251,10 +251,10 @@ static int CF_Chunks_CombineNext(chunks_t *chunks, index_t i, const chunk_t *chu
** \endreturns
**
*************************************************************************/
static index_t CF_Chunks_FindSmallestSize(const chunks_t *chunks)
static CF_ChunkIdx_t CF_Chunks_FindSmallestSize(const CF_ChunkList_t *chunks)
{
index_t i;
index_t smallest = 0;
CF_ChunkIdx_t i;
CF_ChunkIdx_t smallest = 0;

for (i = 1; i < chunks->count; ++i)
{
Expand All @@ -278,7 +278,7 @@ static index_t CF_Chunks_FindSmallestSize(const chunks_t *chunks)
** chunks must not be NULL. chunk must not be NULL.
**
*************************************************************************/
static void CF_Chunks_Insert(chunks_t *chunks, index_t i, const chunk_t *chunk)
static void CF_Chunks_Insert(CF_ChunkList_t *chunks, CF_ChunkIdx_t i, const CF_Chunk_t *chunk)
{
int n = CF_Chunks_CombineNext(chunks, i, chunk);
if (n)
Expand All @@ -300,8 +300,8 @@ static void CF_Chunks_Insert(chunks_t *chunks, index_t i, const chunk_t *chunk)
}
else
{
index_t smallest_i = CF_Chunks_FindSmallestSize(chunks);
chunk_t *smallest_c = &chunks->chunks[smallest_i];
CF_ChunkIdx_t smallest_i = CF_Chunks_FindSmallestSize(chunks);
CF_Chunk_t *smallest_c = &chunks->chunks[smallest_i];
if (smallest_c->size < chunk->size)
{
CF_Chunks_EraseChunk(chunks, smallest_i);
Expand All @@ -319,10 +319,10 @@ static void CF_Chunks_Insert(chunks_t *chunks, index_t i, const chunk_t *chunk)
** chunks must not be NULL.
**
*************************************************************************/
void CF_Chunks_Add(chunks_t *chunks, chunk_offset_t offset, chunk_size_t size)
void CF_ChunkListAdd(CF_ChunkList_t *chunks, CF_ChunkOffset_t offset, CF_ChunkSize_t size)
{
const chunk_t chunk = {offset, size};
const index_t i = CF_Chunks_FindInsertPosition(chunks, &chunk);
const CF_Chunk_t chunk = {offset, size};
const CF_ChunkIdx_t i = CF_Chunks_FindInsertPosition(chunks, &chunk);

/* PTFO: files won't be so big we need to gracefully handle overflow,
* and in that case the user should change everything in chunks
Expand Down Expand Up @@ -353,9 +353,9 @@ void CF_Chunks_Add(chunks_t *chunks, chunk_offset_t offset, chunk_size_t size)
** chunks must not be NULL.
**
*************************************************************************/
void CF_Chunks_RemoveFromFirst(chunks_t *chunks, chunk_size_t size)
void CF_ChunkList_RemoveFromFirst(CF_ChunkList_t *chunks, CF_ChunkSize_t size)
{
chunk_t *c = &chunks->chunks[0]; /* front is always 0 */
CF_Chunk_t *c = &chunks->chunks[0]; /* front is always 0 */

if (size > c->size)
{
Expand Down Expand Up @@ -385,7 +385,7 @@ void CF_Chunks_RemoveFromFirst(chunks_t *chunks, chunk_size_t size)
** chunks must not be NULL.
**
*************************************************************************/
const chunk_t *CF_Chunks_GetFirstChunk(const chunks_t *chunks)
const CF_Chunk_t *CF_ChunkList_GetFirstChunk(const CF_ChunkList_t *chunks)
{
return chunks->count ? &chunks->chunks[0] : NULL;
}
Expand All @@ -397,12 +397,12 @@ const chunk_t *CF_Chunks_GetFirstChunk(const chunks_t *chunks)
** chunks must not be NULL. chunks_mem must not be NULL.
**
*************************************************************************/
void CF_Chunks_Init(chunks_t *chunks, index_t CF_max_chunks, chunk_t *chunks_mem)
void CF_ChunkListInit(CF_ChunkList_t *chunks, CF_ChunkIdx_t CF_max_chunks, CF_Chunk_t *chunks_mem)
{
CF_Assert(CF_max_chunks > 0);
chunks->CF_max_chunks = CF_max_chunks;
chunks->chunks = chunks_mem;
CF_ChunksReset(chunks);
CF_ChunkListReset(chunks);
}

/************************************************************************/
Expand All @@ -412,7 +412,7 @@ void CF_Chunks_Init(chunks_t *chunks, index_t CF_max_chunks, chunk_t *chunks_mem
** chunks must not be NULL.
**
*************************************************************************/
void CF_ChunksReset(chunks_t *chunks)
void CF_ChunkListReset(CF_ChunkList_t *chunks)
{
chunks->count = 0;
memset(chunks->chunks, 0, sizeof(*chunks->chunks) * chunks->CF_max_chunks);
Expand All @@ -434,19 +434,19 @@ void CF_ChunksReset(chunks_t *chunks)
** \endreturns
**
*************************************************************************/
uint32 CF_Chunks_ComputeGaps(const chunks_t *chunks, index_t max_gaps, chunk_size_t total, chunk_offset_t start,
compute_gap_fn_t compute_gap_fn, void *opaque)
uint32 CF_ChunkList_ComputeGaps(const CF_ChunkList_t *chunks, CF_ChunkIdx_t max_gaps, CF_ChunkSize_t total,
CF_ChunkOffset_t start, CF_ChunkList_ComputeGapFn_t compute_gap_fn, void *opaque)
{
uint32 ret = 0;
index_t i = 0;
int started = 0;
uint32 ret = 0;
CF_ChunkIdx_t i = 0;
int started = 0;
CF_Assert(total); /* does it make sense to have a 0 byte file? */
CF_Assert(start < total);

/* simple case: there is no chunk data, which means there is a single gap of the entire size */
if (!chunks->count)
{
chunk_t c = {0, total};
CF_Chunk_t c = {0, total};
if (compute_gap_fn)
{
compute_gap_fn(chunks, &c, opaque);
Expand All @@ -457,10 +457,10 @@ uint32 CF_Chunks_ComputeGaps(const chunks_t *chunks, index_t max_gaps, chunk_siz

while ((ret < max_gaps) && (i < chunks->count))
{
chunk_offset_t next_off = (i == (chunks->count - 1)) ? total : chunks->chunks[i + 1].offset;
chunk_offset_t gap_start = (chunks->chunks[i].offset + chunks->chunks[i].size);
chunk_size_t gap_size = (next_off - gap_start);
chunk_t c = {gap_start, gap_size};
CF_ChunkOffset_t next_off = (i == (chunks->count - 1)) ? total : chunks->chunks[i + 1].offset;
CF_ChunkOffset_t gap_start = (chunks->chunks[i].offset + chunks->chunks[i].size);
CF_ChunkSize_t gap_size = (next_off - gap_start);
CF_Chunk_t c = {gap_start, gap_size};

if (gap_start >= total)
{
Expand All @@ -470,7 +470,7 @@ uint32 CF_Chunks_ComputeGaps(const chunks_t *chunks, index_t max_gaps, chunk_siz
/* check if start has been passed */
if (!started && ((c.offset + c.size) >= start))
{
chunk_size_t start_diff = (start - c.offset);
CF_ChunkSize_t start_diff = (start - c.offset);
if (start_diff < c.offset)
{
c.offset += start_diff;
Expand Down
Loading

0 comments on commit d66ed3e

Please sign in to comment.