§ Coverage
1/*2 * sc_ringbuf.c -- implementation. Blocks are tagged with the low-level3 * requirement they satisfy; see requirements/sc_ringbuf.md.4 */5#include "sc_ringbuf.h"6711sc_status_t sc_ringbuf_init(sc_ringbuf_t *rb, uint8_t *storage, uint32_t capacity)8{9 sc_status_t status;101111 if ((rb == NULL) || (storage == NULL))condition outcomes covered 4/412 {132 status = SC_ERR_NULL; /* LLR-RB-9 */14 }159 else if (capacity == 0u)condition outcomes covered 2/216 {171 status = SC_ERR_PARAM; /* LLR-RB-10 */18 }19 else20 {218 rb->buffer = storage; /* LLR-RB-1 */228 rb->capacity = capacity;238 rb->head = 0u;248 rb->tail = 0u;258 rb->count = 0u;268 status = SC_OK;27 }282911 return status;30}31325bool sc_ringbuf_is_empty(const sc_ringbuf_t *rb)33{34 bool result;35365 if (rb == NULL)condition outcomes covered 2/237 {381 result = true; /* LLR-RB-11 */39 }40 else41 {424 result = (rb->count == 0u); /* LLR-RB-2 */43 }44455 return result;46}47484bool sc_ringbuf_is_full(const sc_ringbuf_t *rb)49{50 bool result;51524 if (rb == NULL)condition outcomes covered 2/253 {541 result = false; /* LLR-RB-11 */55 }56 else57 {583 result = (rb->count == rb->capacity); /* LLR-RB-3 */59 }60614 return result;62}63645uint32_t sc_ringbuf_count(const sc_ringbuf_t *rb)65{66 uint32_t result;67685 if (rb == NULL)condition outcomes covered 2/269 {701 result = 0u; /* LLR-RB-11 */71 }72 else73 {744 result = rb->count; /* LLR-RB-4 */75 }76775 return result;78}798019sc_status_t sc_ringbuf_push(sc_ringbuf_t *rb, uint8_t value)81{82 sc_status_t status;838419 if (rb == NULL)condition outcomes covered 2/285 {861 status = SC_ERR_NULL; /* LLR-RB-9 */87 }8818 else if (rb->count == rb->capacity)condition outcomes covered 2/289 {902 status = SC_ERR_FULL; /* LLR-RB-6 */91 }92 else93 {9416 rb->buffer[rb->head] = value; /* LLR-RB-5 */9516 rb->head++;9616 if (rb->head == rb->capacity) /* LLR-RB-7: wrap */condition outcomes covered 2/297 {983 rb->head = 0u;99 }10016 rb->count++;10116 status = SC_OK;102 }10310419 return status;105}10610715sc_status_t sc_ringbuf_pop(sc_ringbuf_t *rb, uint8_t *out)108{109 sc_status_t status;11011115 if ((rb == NULL) || (out == NULL))condition outcomes covered 4/4112 {1132 status = SC_ERR_NULL; /* LLR-RB-9 */114 }11513 else if (rb->count == 0u)condition outcomes covered 2/2116 {1171 status = SC_ERR_EMPTY; /* LLR-RB-8 */118 }119 else120 {12112 *out = rb->buffer[rb->tail]; /* LLR-RB-5 */12212 rb->tail++;12312 if (rb->tail == rb->capacity) /* LLR-RB-7: wrap */condition outcomes covered 2/2124 {1252 rb->tail = 0u;126 }12712 rb->count--;12812 status = SC_OK;129 }13013115 return status;132}1331342sc_status_t sc_ringbuf_reset(sc_ringbuf_t *rb)135{136 sc_status_t status;1371382 if (rb == NULL)condition outcomes covered 2/2139 {1401 status = SC_ERR_NULL; /* LLR-RB-9 */141 }142 else143 {1441 rb->head = 0u; /* LLR-RB-12 */1451 rb->tail = 0u;1461 rb->count = 0u;1471 status = SC_OK;148 }1491502 return status;151}