Infuse-IoT SDK API 0.0.1
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
modem.h
Go to the documentation of this file.
1
9#ifndef INFUSE_SDK_DRIVERS_GNSS_UBX_MODEM_H_
10#define INFUSE_SDK_DRIVERS_GNSS_UBX_MODEM_H_
11
12#include <stdint.h>
13
14#include <zephyr/kernel.h>
15#include <zephyr/net_buf.h>
16#include <zephyr/modem/pipe.h>
17#include <zephyr/sys/ring_buffer.h>
18
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
39typedef int (*ubx_message_handler_t)(uint8_t message_class, uint8_t message_id, const void *payload,
40 size_t payload_len, void *user_data);
41
42#define UBX_MSG_CLASS_WILDCARD 0x00
43#define UBX_MSG_ID_WILDCARD 0x00
44
46 /* Message results in an ACK/NAK only */
48 /* Message results in a direct response only */
50 /* Message results in a response AND an ACK/NAK */
52};
53
59 sys_snode_t _node;
61 struct k_poll_signal *signal;
65 void *user_data;
69 uint8_t message_id;
71 uint8_t flags;
72};
73
78 /* Pipe for communications with underlying modem */
79 struct modem_pipe *pipe;
80 /* Worker to read data */
81 struct k_work fifo_read_worker;
82 /* Notification that TX has completed */
83 struct k_poll_signal tx_done;
84 /* List of message handlers */
85 sys_slist_t handlers;
86 /* Thread protection for handlers list */
87 struct k_sem handlers_sem;
88 /* Data buffer to read bytes into */
89 uint8_t rx_buffer[CONFIG_GNSS_U_BLOX_MAX_MSG_SIZE];
90 /* Bytes pending in rx_buffer */
92};
93
101struct ubx_modem_data *ubx_modem_data_get(const struct device *dev);
102
109void ubx_modem_init(struct ubx_modem_data *modem, struct modem_pipe *pipe);
110
121int ubx_modem_comms_reset(const struct device *dev);
122
129
137 struct ubx_message_handler_ctx *handler_ctx);
138
146 struct ubx_message_handler_ctx *handler_ctx);
147
160int ubx_modem_ack_handler(uint8_t message_class, uint8_t message_id, const void *payload,
161 size_t payload_len, void *user_data);
162
177int ubx_modem_send_async(struct ubx_modem_data *modem, struct net_buf_simple *buf,
178 struct ubx_message_handler_ctx *handler_ctx, bool wait_tx);
179
197int ubx_modem_send_sync(struct ubx_modem_data *modem, struct net_buf_simple *buf, uint8_t flags,
198 ubx_message_handler_t handler, void *user_data, k_timeout_t timeout);
199
212int ubx_modem_send_sync_acked(struct ubx_modem_data *modem, struct net_buf_simple *buf,
213 k_timeout_t timeout);
214
229int ubx_modem_send_sync_poll(struct ubx_modem_data *modem, uint8_t message_class,
230 uint8_t message_id, ubx_message_handler_t handler, void *user_data,
231 k_timeout_t timeout);
232
249int ubx_modem_send_async_poll(struct ubx_modem_data *modem, uint8_t message_class,
250 uint8_t message_id, uint8_t buf[8],
251 struct ubx_message_handler_ctx *handler_ctx);
252
253#ifdef CONFIG_GNSS_UBX_RAW_FRAME_HANDLER
254
264void ubx_modem_raw_frame_handler(struct ubx_frame *frame, uint16_t total_len);
265
266#endif
267
272#ifdef __cplusplus
273}
274#endif
275
276#endif /* INFUSE_SDK_DRIVERS_GNSS_UBX_MODEM_H_ */
int ubx_modem_send_sync_acked(struct ubx_modem_data *modem, struct net_buf_simple *buf, k_timeout_t timeout)
Send a message to the modem and wait for the UBX_MSG_CLASS_ACK response.
int ubx_modem_send_async(struct ubx_modem_data *modem, struct net_buf_simple *buf, struct ubx_message_handler_ctx *handler_ctx, bool wait_tx)
Send a message to the modem without waiting for a response.
int ubx_modem_comms_reset(const struct device *dev)
Reset communications with the UBX modem.
struct ubx_modem_data * ubx_modem_data_get(const struct device *dev)
Get modem data structure from device.
void ubx_modem_msg_subscribe(struct ubx_modem_data *modem, struct ubx_message_handler_ctx *handler_ctx)
Subscribe to messages from the UBX modem.
int ubx_modem_send_async_poll(struct ubx_modem_data *modem, uint8_t message_class, uint8_t message_id, uint8_t buf[8], struct ubx_message_handler_ctx *handler_ctx)
Request a poll response from the modem.
void ubx_modem_msg_unsubscribe(struct ubx_modem_data *modem, struct ubx_message_handler_ctx *handler_ctx)
Unsubscribe from messages from the UBX modem.
int(* ubx_message_handler_t)(uint8_t message_class, uint8_t message_id, const void *payload, size_t payload_len, void *user_data)
UBX Message handler callback.
Definition modem.h:39
int ubx_modem_ack_handler(uint8_t message_class, uint8_t message_id, const void *payload, size_t payload_len, void *user_data)
Common ACK handler for messages.
int ubx_modem_send_sync(struct ubx_modem_data *modem, struct net_buf_simple *buf, uint8_t flags, ubx_message_handler_t handler, void *user_data, k_timeout_t timeout)
Send a message to the modem and wait for the response.
void ubx_modem_software_standby(struct ubx_modem_data *modem)
Notify UBX modem that hardware is in standby.
ubx_message_handler_flags
Definition modem.h:45
void ubx_modem_init(struct ubx_modem_data *modem, struct modem_pipe *pipe)
Initialise UBX modem handler.
int ubx_modem_send_sync_poll(struct ubx_modem_data *modem, uint8_t message_class, uint8_t message_id, ubx_message_handler_t handler, void *user_data, k_timeout_t timeout)
Request a poll response from the modem and wait for the response.
@ UBX_HANDLING_ACK
Definition modem.h:47
@ UBX_HANDLING_RSP_ACK
Definition modem.h:51
@ UBX_HANDLING_RSP
Definition modem.h:49
UBX Message Frame.
Definition protocol.h:32
Context around a ubx_message_handler_t.
Definition modem.h:57
struct k_poll_signal * signal
Signal raise after callback run.
Definition modem.h:61
ubx_message_handler_t message_cb
Callback to run.
Definition modem.h:63
uint8_t message_id
Message ID callback should be run on (or UBX_MSG_ID_WILDCARD)
Definition modem.h:69
void * user_data
Arbitrary user data, provided to message_cb.
Definition modem.h:65
uint8_t flags
Flags for callback (ubx_message_handler_flags)
Definition modem.h:71
uint8_t message_class
Message class callback should be run on (or UBX_MSG_CLASS_WILDCARD)
Definition modem.h:67
UBX modem state.
Definition modem.h:77
sys_slist_t handlers
Definition modem.h:85
struct modem_pipe * pipe
Definition modem.h:79
uint8_t rx_buffer[CONFIG_GNSS_U_BLOX_MAX_MSG_SIZE]
Definition modem.h:89
uint16_t rx_buffer_pending
Definition modem.h:91
struct k_work fifo_read_worker
Definition modem.h:81
struct k_poll_signal tx_done
Definition modem.h:83
struct k_sem handlers_sem
Definition modem.h:87