LCOV - code coverage report
Current view: top level - message/msg_common.h (source / functions) Coverage Total Hit
Test: coverage-filtered.info Lines: 100.0 % 28 28
Test Date: 2026-03-20 08:45:03 Functions: 100.0 % 11 11
Branches: 81.2 % 16 13
MC/DC: 81.2 % 16 13

             Branch data      MC/DC data    Line data    Source code
       1                 :              :             : #ifndef CANLIB_COMMON_H
       2                 :              :             : #define CANLIB_COMMON_H
       3                 :              :             : 
       4                 :              :             : #include <stdbool.h>
       5                 :              :             : #include <stdint.h>
       6                 :              :             : 
       7                 :              :             : #include "can.h"
       8                 :              :             : #include "message_types.h"
       9                 :              :             : 
      10                 :              :             : #include "common.h"
      11                 :              :             : 
      12                 :              :             : #ifndef CANLIB_DYNAMIC_BOARD_ID
      13                 :              :             : 
      14                 :              :             : #ifndef BOARD_TYPE_UNIQUE_ID
      15                 :              :             : #warning BOARD_TYPE_UNIQUE_ID not defined, please set that up in project
      16                 :              :             : #define BOARD_TYPE_UNIQUE_ID 0
      17                 :              :             : #endif
      18                 :              :             : 
      19                 :              :             : #ifndef BOARD_INST_UNIQUE_ID
      20                 :              :             : #warning BOARD_INST_UNIQUE_ID not defined, please set that up in project
      21                 :              :             : #define BOARD_INST_UNIQUE_ID 0
      22                 :              :             : #endif
      23                 :              :             : 
      24                 :              :          24 : static inline uint32_t build_sid(can_msg_prio_t prio, can_msg_type_t msg_type, uint8_t metadata) {
      25         [ +  - ]:      [ T  f ]:          24 :         w_assert(((uint32_t)prio & 0xfffffffc) == 0);
      26         [ +  - ]:      [ T  f ]:          24 :         w_assert(((uint32_t)msg_type & 0xffffff80) == 0);
      27                 :              :          24 :         w_assert(((uint32_t)BOARD_TYPE_UNIQUE_ID & 0xffffffc0) == 0);
      28                 :              :          24 :         w_assert(((uint32_t)BOARD_INST_UNIQUE_ID & 0xffffffc0) == 0);
      29                 :              :             : 
      30                 :              :          24 :         return (((uint32_t)prio) << 27) | (((uint32_t)msg_type) << 20) |
      31                 :              :          24 :                    (((uint32_t)BOARD_TYPE_UNIQUE_ID) << 14) | (((uint32_t)BOARD_INST_UNIQUE_ID) << 8) |
      32                 :              :           7 :                    metadata;
      33                 :              :             : }
      34                 :              :             : 
      35                 :              :             : #else
      36                 :              :             : 
      37                 :              :             : extern uint8_t board_type_unique_id;
      38                 :              :             : extern uint8_t board_inst_unique_id;
      39                 :              :             : 
      40                 :              :             : static inline uint32_t build_sid(can_msg_prio_t prio, can_msg_type_t msg_type, uint8_t metadata) {
      41                 :              :             :         w_assert(((uint32_t)prio & 0xfffffffc) == 0);
      42                 :              :             :         w_assert(((uint32_t)msg_type & 0xffffff80) == 0);
      43                 :              :             :         w_assert(((uint32_t)board_type_unique_id & 0xffffffc0) == 0);
      44                 :              :             :         w_assert(((uint32_t)board_inst_unique_id & 0xffffffc0) == 0);
      45                 :              :             : 
      46                 :              :             :         return (((uint32_t)prio) << 27) | (((uint32_t)msg_type) << 20) |
      47                 :              :             :                    (((uint32_t)board_type_unique_id) << 14) | (((uint32_t)board_inst_unique_id) << 8) |
      48                 :              :             :                    metadata;
      49                 :              :             : }
      50                 :              :             : 
      51                 :              :             : #endif
      52                 :              :             : 
      53                 :              :             : // SID Handling Functions
      54                 :              :             : 
      55                 :              :          45 : static inline can_msg_type_t get_message_type(const can_msg_t *msg) {
      56         [ +  + ]:      [ T  F ]:          45 :         w_assert(msg);
      57                 :              :             : 
      58                 :              :          44 :         return (can_msg_type_t)((msg->sid >> 20) & 0x7f);
      59                 :              :             : }
      60                 :              :             : 
      61                 :              :           2 : static inline uint8_t get_board_type_unique_id(const can_msg_t *msg) {
      62         [ +  + ]:      [ T  F ]:           2 :         w_assert(msg);
      63                 :              :             : 
      64                 :              :           1 :         return (msg->sid >> 14) & 0x3f;
      65                 :              :             : }
      66                 :              :             : 
      67                 :              :           2 : static inline uint8_t get_board_inst_unique_id(const can_msg_t *msg) {
      68         [ +  + ]:      [ T  F ]:           2 :         w_assert(msg);
      69                 :              :             : 
      70                 :              :           1 :         return (msg->sid >> 8) & 0x3f;
      71                 :              :             : }
      72                 :              :             : 
      73                 :              :           8 : static inline uint8_t get_message_metadata(const can_msg_t *msg) {
      74         [ +  + ]:      [ T  F ]:          11 :         w_assert(msg);
      75                 :              :             : 
      76                 :              :           9 :         return msg->sid & 0xff;
      77                 :              :             : }
      78                 :              :             : 
      79                 :              :             : // Timestamp handle functions
      80                 :              :          18 : static inline void write_timestamp(uint16_t timestamp, can_msg_t *output) {
      81         [ +  - ]:      [ T  f ]:          19 :         w_assert(output);
      82                 :              :             : 
      83                 :              :          18 :         output->data[0] = (timestamp >> 8) & 0xff;
      84                 :              :          18 :         output->data[1] = (timestamp >> 0) & 0xff;
      85                 :              :          18 : }
      86                 :              :             : 
      87                 :              :          16 : static inline uint16_t get_timestamp(const can_msg_t *msg) {
      88         [ +  + ]:      [ T  F ]:          16 :         w_assert(msg);
      89                 :              :             : 
      90                 :              :          15 :         return ((uint16_t)msg->data[0] << 8) | msg->data[1];
      91                 :              :             : }
      92                 :              :             : 
      93                 :              :             : // Dynamic board ID specific function
      94                 :              :             : #ifdef CANLIB_DYNAMIC_BOARD_ID
      95                 :              :             : 
      96                 :              :             : static inline void set_board_id(uint8_t board_type_id, uint8_t board_inst_id) {
      97                 :              :             :         w_assert(((uint32_t)board_type_id & 0xc0) == 0);
      98                 :              :             :         w_assert(((uint32_t)board_inst_id & 0xc0) == 0);
      99                 :              :             : 
     100                 :              :             :         board_type_unique_id = board_type_id;
     101                 :              :             :         board_inst_unique_id = board_inst_id;
     102                 :              :             : }
     103                 :              :             : 
     104                 :              :             : #endif
     105                 :              :             : 
     106                 :              :             : #endif
        

Generated by: LCOV version 2.0-1