1 /** @file
2  * @brief Modem receiver header file.
3  *
4  * A modem receiver driver allowing application to handle all
5  * aspects of received protocol data.
6  */
7 
8 /*
9  * Copyright (c) 2018 Foundries.io
10  *
11  * SPDX-License-Identifier: Apache-2.0
12  */
13 
14 #ifndef ZEPHYR_INCLUDE_DRIVERS_MODEM_MODEM_RECEIVER_H_
15 #define ZEPHYR_INCLUDE_DRIVERS_MODEM_MODEM_RECEIVER_H_
16 
17 #include <zephyr/kernel.h>
18 #include <zephyr/sys/ring_buffer.h>
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 struct mdm_receiver_context {
25 	const struct device *uart_dev;
26 
27 	/* rx data */
28 	struct ring_buf rx_rb;
29 	struct k_sem rx_sem;
30 
31 	/* modem data */
32 	char *data_manufacturer;
33 	char *data_model;
34 	char *data_revision;
35 #if defined(CONFIG_MODEM_SIM_NUMBERS)
36 	char *data_imei;
37 	char *data_imsi;
38 #endif
39 	char *data_iccid;
40 	int  *data_rssi;
41 };
42 
43 /**
44  * @brief  Gets receiver context by id.
45  *
46  * @param  id: receiver context id.
47  *
48  * @retval Receiver context or NULL.
49  */
50 struct mdm_receiver_context *mdm_receiver_context_from_id(int id);
51 
52 /**
53  * @brief  Get received data.
54  *
55  * @param  ctx: receiver context.
56  * @param  buf: buffer to copy the received data to.
57  * @param  size: buffer size.
58  * @param  bytes_read: amount of received bytes
59  *
60  * @retval 0 if ok, < 0 if error.
61  */
62 int mdm_receiver_recv(struct mdm_receiver_context *ctx,
63 		      uint8_t *buf, size_t size, size_t *bytes_read);
64 
65 /**
66  * @brief  Sends the data over specified receiver context.
67  *
68  * @param  ctx: receiver context.
69  * @param  buf: buffer with the data to send.
70  * @param  size: the amount of data to send.
71  *
72  * @retval 0 if ok, < 0 if error.
73  */
74 int mdm_receiver_send(struct mdm_receiver_context *ctx,
75 		      const uint8_t *buf, size_t size);
76 
77 /**
78  * @brief  Registers receiver context.
79  *
80  * @note   Acquires receivers device, and prepares the context to be used.
81  *
82  * @param  ctx: receiver context to register.
83  * @param  uart_dev: communication device for the receiver context.
84  * @param  buf: rx buffer to use for received data.
85  * @param  size: rx buffer size.
86  *
87  * @retval 0 if ok, < 0 if error.
88  */
89 int mdm_receiver_register(struct mdm_receiver_context *ctx,
90 			  const struct device *uart_dev,
91 			  uint8_t *buf, size_t size);
92 
93 int mdm_receiver_sleep(struct mdm_receiver_context *ctx);
94 
95 int mdm_receiver_wake(struct mdm_receiver_context *ctx);
96 
97 #ifdef __cplusplus
98 }
99 #endif
100 
101 #endif /* ZEPHYR_INCLUDE_DRIVERS_MODEM_MODEM_RECEIVER_H_ */
102