|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include <os.h> |
| 4 | +#include <stddef.h> |
| 5 | +#include <stdint.h> |
| 6 | +#include <stdbool.h> |
| 7 | +#include "buffer.h" |
| 8 | + |
| 9 | +// ───────────────────────────────────────────────────────────────────────────── |
| 10 | +// TLV X macros |
| 11 | +// Not intended for library users |
| 12 | +// ───────────────────────────────────────────────────────────────────────────── |
| 13 | + |
| 14 | +/** |
| 15 | + * @brief Internal macro — assigns the tag's enum value. |
| 16 | + * @note Do not use directly. |
| 17 | + */ |
| 18 | +#define __X_DEFINE_TLV__TAG_ASSIGN(value, name, callback, unicity) name = value, |
| 19 | + |
| 20 | +/** |
| 21 | + * @brief Internal macro — creates an index enum for mapping tags to their order in the list. |
| 22 | + * @note Do not use directly. |
| 23 | + */ |
| 24 | +#define __X_DEFINE_TLV__TAG_INDEX(value, name, callback, unicity) name##_INDEX, |
| 25 | + |
| 26 | +/** |
| 27 | + * @brief Internal macro — creates a flag enum for mapping tags to their reception flag. |
| 28 | + * @note Do not use directly. |
| 29 | + */ |
| 30 | +#define __X_DEFINE_TLV__TAG_FLAG(value, name, callback, unicity) name##_FLAG = (1U << name##_INDEX), |
| 31 | + |
| 32 | +/** |
| 33 | + * @brief Internal macro — expands to a switch case that maps a tag to its flag. |
| 34 | + * @note Do not use directly. |
| 35 | + */ |
| 36 | +#define __X_DEFINE_TLV__TAG_TO_FLAG_CASE(value, name, callback, unicity) \ |
| 37 | + case name: \ |
| 38 | + return name##_FLAG; |
| 39 | + |
| 40 | +/** |
| 41 | + * @brief Internal macro — expands each tag into an _internal_tlv_handler_t array element |
| 42 | + * @note Do not use directly. |
| 43 | + */ |
| 44 | +#define __X_DEFINE_TLV__TAG_CALLBACKS(value, name, callback, unicity) \ |
| 45 | + {.tag = name, \ |
| 46 | + .func = (tlv_handler_cb_t *) callback, \ |
| 47 | + .is_unique = (unicity == ENFORCE_UNIQUE_TAG)}, |
| 48 | + |
| 49 | +// The generated TLV library will give the user a tag_to_flag function of the following type for |
| 50 | +// his TLV use case |
| 51 | +typedef uint32_t TLV_tag_t; |
| 52 | +typedef uint64_t TLV_flag_t; |
| 53 | +typedef TLV_flag_t(tag_to_flag_function_t)(TLV_tag_t tag); |
| 54 | + |
| 55 | +// This structure is returned to the TLV parser caller and can be used in conjunction with the |
| 56 | +// associated helper functions to get the status of received tags. |
| 57 | +typedef struct { |
| 58 | + TLV_flag_t flags; |
| 59 | + tag_to_flag_function_t *tag_to_flag_function; |
| 60 | +} TLV_reception_internal_t; |
0 commit comments