LCOV - code coverage report
Current view: top level - util/can_tx_buffer.c (source / functions) Coverage Total Hit
Test: coverage-filtered.info Lines: 100.0 % 19 19
Test Date: 2026-03-20 08:45:03 Functions: 100.0 % 3 3
Branches: 92.9 % 14 13
MC/DC: 92.9 % 14 13

             Branch data      MC/DC data    Line data    Source code
       1                 :              :             : #include <stddef.h>
       2                 :              :             : 
       3                 :              :             : #include "common.h"
       4                 :              :             : 
       5                 :              :             : #include "can.h"
       6                 :              :             : #include "can_tx_buffer.h"
       7                 :              :             : #include "safe_ring_buffer.h"
       8                 :              :             : 
       9                 :              :             : typedef struct {
      10                 :              :             :         void (*can_send_fp)(const can_msg_t *);
      11                 :              :             :         bool (*can_tx_ready_fp)(void);
      12                 :              :             : } cbl_ctx_t;
      13                 :              :             : 
      14                 :              :             : // context to store info for the safe ring buffer
      15                 :              :             : static srb_ctx_t buf;
      16                 :              :             : 
      17                 :              :             : // context to store pointers to can_send_fp and can_tx_ready
      18                 :              :             : static cbl_ctx_t ctx;
      19                 :              :             : 
      20                 :              :           5 : void txb_init(void *pool, size_t pool_size, void (*can_send)(const can_msg_t *),
      21                 :              :             :                           bool (*can_tx_ready)(void)) {
      22         [ +  + ]:      [ T  F ]:           5 :         w_assert(pool);
      23         [ +  + ]:      [ T  F ]:           3 :         w_assert(can_send);
      24         [ +  + ]:      [ T  F ]:           2 :         w_assert(can_tx_ready);
      25                 :              :             : 
      26                 :              :           1 :         ctx.can_send_fp = can_send;
      27                 :              :           1 :         ctx.can_tx_ready_fp = can_tx_ready;
      28                 :              :           1 :         srb_init(&buf, pool, pool_size, sizeof(can_msg_t));
      29                 :              :           1 : }
      30                 :              :             : 
      31                 :              :         108 : bool txb_enqueue(const can_msg_t *msg) {
      32         [ +  + ]:      [ T  F ]:         108 :         w_assert(msg);
      33                 :              :             : 
      34         [ +  - ]:      [ t  F ]:         107 :         if (srb_is_full(&buf)) {
      35                 :              :             :                 return false;
      36                 :              :             :         }
      37                 :              :         107 :         srb_push(&buf, msg);
      38                 :              :         107 :         return true;
      39                 :              :             : }
      40                 :              :             : 
      41                 :              :        1000 : void txb_heartbeat(void) {
      42         [ +  + ]:      [ T  F ]:        1000 :         if (!srb_is_empty(&buf)) {
      43         [ +  + ]:      [ T  F ]:         450 :                 if ((*(ctx.can_tx_ready_fp))()) {
      44                 :              :             :                         can_msg_t msg_sent;
      45                 :              :         104 :                         srb_pop(&buf, &msg_sent);
      46                 :              :         104 :                         (*(ctx.can_send_fp))(&msg_sent);
      47                 :              :             :                 }
      48                 :              :             :         }
      49                 :              :        1000 : }
        

Generated by: LCOV version 2.0-1