LCOV - code coverage report
Current view: top level - util - can_tx_buffer.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 15 0
Test Date: 2026-02-15 13:08:52 Functions: 0.0 % 3 0
Branches: 0.0 % 6 0

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

Generated by: LCOV version 2.0-1