SmartSnippets DA1459x SDK
dgtl_pkt.h
Go to the documentation of this file.
1 
44 #ifndef DGTL_PKT_H_
45 #define DGTL_PKT_H_
46 
47 #include <stdbool.h>
48 #include <stdint.h>
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
57 typedef enum {
58  DGTL_PKT_TYPE_HCI_CMD = 0x01,
59  DGTL_PKT_TYPE_HCI_ACL = 0x02,
60  DGTL_PKT_TYPE_HCI_SCO = 0x03,
61  DGTL_PKT_TYPE_HCI_EVT = 0x04,
62  DGTL_PKT_TYPE_GTL = 0x05,
63  DGTL_PKT_TYPE_APP_CMD = 0x06,
64  DGTL_PKT_TYPE_APP_RSP = 0x07,
65  DGTL_PKT_TYPE_LOG = 0x08,
67 
68 typedef __PACKED_STRUCT {
69  uint8_t pkt_type;
70  uint16_t opcode;
71  uint8_t length;
72  uint8_t parameters[0];
73 } dgtl_pkt_hci_cmd_t;
74 
75 typedef __PACKED_STRUCT {
76  uint8_t pkt_type;
77  uint16_t handle;
78  uint16_t length;
79  uint8_t parameters[0];
80 } dgtl_pkt_hci_acl_t;
81 
82 typedef __PACKED_STRUCT {
83  uint8_t pkt_type;
84  uint16_t handle;
85  uint8_t length;
86  uint8_t parameters[0];
87 } dgtl_pkt_hci_sco_t;
88 
89 typedef __PACKED_STRUCT {
90  uint8_t pkt_type;
91  uint8_t code;
92  uint8_t length;
93  uint8_t parameters[0];
94 } dgtl_pkt_hci_evt_t;
95 
96 typedef __PACKED_STRUCT {
97  uint8_t pkt_type;
98  uint16_t msg_id;
99  uint16_t dst_task_id;
100  uint16_t src_task_id;
101  uint16_t length;
102  uint8_t parameters[0];
103 } dgtl_pkt_gtl_t;
104 
105 typedef __PACKED_STRUCT {
106  uint8_t pkt_type;
107  uint16_t opcode;
108  uint16_t length;
109  uint8_t parameters[0];
110 } dgtl_pkt_app_cmd_t;
111 
112 typedef __PACKED_STRUCT {
113  uint8_t pkt_type;
114  uint8_t code;
115  uint16_t length;
116  uint8_t parameters[0];
117 } dgtl_pkt_app_rsp_t;
118 
119 typedef __PACKED_STRUCT {
120  uint8_t pkt_type;
121  uint8_t length;
122  uint8_t parameters[0];
123 } dgtl_pkt_log_t;
124 
125 typedef __PACKED_UNION {
126  uint8_t pkt_type;
127  dgtl_pkt_hci_cmd_t hci_cmd;
128  dgtl_pkt_hci_acl_t hci_acl;
129  dgtl_pkt_hci_sco_t hci_sco;
130  dgtl_pkt_hci_evt_t hci_evt;
131  dgtl_pkt_gtl_t gtl;
132  dgtl_pkt_app_cmd_t app_cmd;
133  dgtl_pkt_app_rsp_t app_rsp;
134  dgtl_pkt_log_t log;
135 } dgtl_pkt_t;
136 
148 __STATIC_INLINE size_t dgtl_pkt_get_header_length(const dgtl_pkt_t *pkt)
149 {
150  switch (pkt->pkt_type) {
151  case DGTL_PKT_TYPE_HCI_CMD:
152  return sizeof(dgtl_pkt_hci_cmd_t);
153  case DGTL_PKT_TYPE_HCI_ACL:
154  return sizeof(dgtl_pkt_hci_acl_t);
155  case DGTL_PKT_TYPE_HCI_SCO:
156  return sizeof(dgtl_pkt_hci_sco_t);
157  case DGTL_PKT_TYPE_HCI_EVT:
158  return sizeof(dgtl_pkt_hci_evt_t);
159  case DGTL_PKT_TYPE_GTL:
160  return sizeof(dgtl_pkt_gtl_t);
161  case DGTL_PKT_TYPE_APP_CMD:
162  return sizeof(dgtl_pkt_app_cmd_t);
163  case DGTL_PKT_TYPE_APP_RSP:
164  return sizeof(dgtl_pkt_app_rsp_t);
165  case DGTL_PKT_TYPE_LOG:
166  return sizeof(dgtl_pkt_log_t);
167  }
168 
169  /* Unknown packet type, header length is not known */
170  return 0;
171 }
172 
184 __STATIC_INLINE size_t dgtl_pkt_get_param_length(const dgtl_pkt_t *pkt)
185 {
186  switch (pkt->pkt_type) {
187  case DGTL_PKT_TYPE_HCI_CMD:
188  return pkt->hci_cmd.length;
189  case DGTL_PKT_TYPE_HCI_ACL:
190  return pkt->hci_acl.length;
191  case DGTL_PKT_TYPE_HCI_SCO:
192  return pkt->hci_sco.length;
193  case DGTL_PKT_TYPE_HCI_EVT:
194  return pkt->hci_evt.length;
195  case DGTL_PKT_TYPE_GTL:
196  return pkt->gtl.length;
197  case DGTL_PKT_TYPE_APP_CMD:
198  return pkt->app_cmd.length;
199  case DGTL_PKT_TYPE_APP_RSP:
200  return pkt->app_rsp.length;
201  case DGTL_PKT_TYPE_LOG:
202  return pkt->log.length;
203  }
204 
205  /* Unknown packet type, parameters length is not known */
206  return 0;
207 }
208 
220 __STATIC_INLINE size_t dgtl_pkt_get_length(const dgtl_pkt_t *pkt)
221 {
223 }
224 
225 #ifdef __cplusplus
226 }
227 #endif
228 
229 #endif /* DGTL_PKT_H_ */
230 
dgtl_pkt_type_t
dgtl_pkt_type_t
DGTL message packet type indicator.
Definition: dgtl_pkt.h:57
dgtl_pkt_get_header_length
__STATIC_INLINE size_t dgtl_pkt_get_header_length(const dgtl_pkt_t *pkt)
Get header length of packet.
Definition: dgtl_pkt.h:148
__PACKED_UNION
typedef __PACKED_UNION
DGTL message.
Definition: dgtl_msg.h:58
__PACKED_STRUCT
#define __PACKED_STRUCT
Definition: cmsis_gcc.h:67
dgtl_pkt_get_length
__STATIC_INLINE size_t dgtl_pkt_get_length(const dgtl_pkt_t *pkt)
Get length of packet.
Definition: dgtl_pkt.h:220
dgtl_pkt_get_param_length
__STATIC_INLINE size_t dgtl_pkt_get_param_length(const dgtl_pkt_t *pkt)
Get parameters length of packet.
Definition: dgtl_pkt.h:184