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
8
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
30
40typedef int (*ubx_message_handler_t)(uint8_t message_class, uint8_t message_id, const void *payload,
41 size_t payload_len, void *user_data);
42
44#define UBX_MSG_CLASS_WILDCARD 0x00
46#define UBX_MSG_ID_WILDCARD 0x00
47
59
65 sys_snode_t _node;
67 struct k_poll_signal *signal;
71 void *user_data;
75 uint8_t message_id;
77 uint8_t flags;
78};
79
85 struct modem_pipe *pipe;
87 struct k_work fifo_read_worker;
89 struct k_poll_signal tx_done;
91 sys_slist_t handlers;
93 struct k_sem handlers_sem;
95 uint8_t rx_buffer[CONFIG_GNSS_U_BLOX_MAX_MSG_SIZE];
98};
99
107struct ubx_modem_data *ubx_modem_data_get(const struct device *dev);
108
116void ubx_modem_fifo_poll(const struct device *dev);
117
124void ubx_modem_extint_control(const struct device *dev, bool high);
125
131void ubx_modem_extint_wake(const struct device *dev);
132
139void ubx_modem_init(struct ubx_modem_data *modem, struct modem_pipe *pipe);
140
151int ubx_modem_comms_reset(const struct device *dev);
152
159
167 struct ubx_message_handler_ctx *handler_ctx);
168
176 struct ubx_message_handler_ctx *handler_ctx);
177
190int ubx_modem_ack_handler(uint8_t message_class, uint8_t message_id, const void *payload,
191 size_t payload_len, void *user_data);
192
207int ubx_modem_send_async(struct ubx_modem_data *modem, struct net_buf_simple *buf,
208 struct ubx_message_handler_ctx *handler_ctx, bool wait_tx);
209
227int ubx_modem_send_sync(struct ubx_modem_data *modem, struct net_buf_simple *buf, uint8_t flags,
228 ubx_message_handler_t handler, void *user_data, k_timeout_t timeout);
229
242int ubx_modem_send_sync_acked(struct ubx_modem_data *modem, struct net_buf_simple *buf,
243 k_timeout_t timeout);
244
259int ubx_modem_send_sync_poll(struct ubx_modem_data *modem, uint8_t message_class,
260 uint8_t message_id, ubx_message_handler_t handler, void *user_data,
261 k_timeout_t timeout);
262
280int ubx_modem_send_sync_raw_poll(struct ubx_modem_data *modem, uint8_t message_class,
281 uint8_t message_id, ubx_message_handler_t handler, void *user_data,
282 k_timeout_t timeout);
283
300int ubx_modem_send_async_poll(struct ubx_modem_data *modem, uint8_t message_class,
301 uint8_t message_id, uint8_t buf[8],
302 struct ubx_message_handler_ctx *handler_ctx);
303
304#ifdef CONFIG_GNSS_UBX_RAW_FRAME_HANDLER
305
315void ubx_modem_raw_frame_handler(struct ubx_frame *frame, uint16_t total_len);
316
317#endif
318
322
323#ifdef __cplusplus
324}
325#endif
326
327#endif /* INFUSE_SDK_DRIVERS_GNSS_UBX_MODEM_H_ */
void ubx_modem_fifo_poll(const struct device *dev)
Explicitly trigger a poll of the modem data FIFO.
void ubx_modem_extint_wake(const struct device *dev)
Trigger a wakeup of the UBX modem via EXTINT pin.
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.
void ubx_modem_raw_frame_handler(struct ubx_frame *frame, uint16_t total_len)
Function prototype for raw UBX frame handler.
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_extint_control(const struct device *dev, bool high)
Control the EXTINT pin state.
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:40
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.
int ubx_modem_send_sync_raw_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 (raw) poll response from 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
Message handling flags for ubx_message_handler_ctx::flags.
Definition modem.h:49
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
Message results in an ACK/NAK only.
Definition modem.h:51
@ UBX_HANDLING_RSP_ACK
Message results in a response AND an ACK/NAK.
Definition modem.h:55
@ UBX_HANDLING_RAW_FRAME_CB
Response callback wants the raw frame.
Definition modem.h:57
@ UBX_HANDLING_RSP
Message results in a direct response only.
Definition modem.h:53
UBX Message Frame.
Definition protocol.h:35
Context around a ubx_message_handler_t.
Definition modem.h:63
struct k_poll_signal * signal
Signal raise after callback run.
Definition modem.h:67
ubx_message_handler_t message_cb
Callback to run.
Definition modem.h:69
uint8_t message_id
Message ID callback should be run on (or UBX_MSG_ID_WILDCARD)
Definition modem.h:75
void * user_data
Arbitrary user data, provided to message_cb.
Definition modem.h:71
uint8_t flags
Flags for callback (ubx_message_handler_flags)
Definition modem.h:77
uint8_t message_class
Message class callback should be run on (or UBX_MSG_CLASS_WILDCARD)
Definition modem.h:73
UBX modem state.
Definition modem.h:83
sys_slist_t handlers
List of message handlers.
Definition modem.h:91
struct modem_pipe * pipe
Pipe for communications with underlying modem.
Definition modem.h:85
uint8_t rx_buffer[CONFIG_GNSS_U_BLOX_MAX_MSG_SIZE]
Data buffer to read bytes into.
Definition modem.h:95
uint16_t rx_buffer_pending
Bytes pending in rx_buffer.
Definition modem.h:97
struct k_work fifo_read_worker
Worker to read data.
Definition modem.h:87
struct k_poll_signal tx_done
Notification that TX has completed.
Definition modem.h:89
struct k_sem handlers_sem
Thread protection for handlers list.
Definition modem.h:93