2018-08-01 22:01:00 +02:00
|
|
|
/** @file
|
|
|
|
* @brief Modem receiver header file.
|
|
|
|
*
|
|
|
|
* A modem receiver driver allowing application to handle all
|
|
|
|
* aspects of received protocol data.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 Foundries.io
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2018-09-14 19:43:44 +02:00
|
|
|
#ifndef ZEPHYR_INCLUDE_DRIVERS_MODEM_MODEM_RECEIVER_H_
|
|
|
|
#define ZEPHYR_INCLUDE_DRIVERS_MODEM_MODEM_RECEIVER_H_
|
2018-08-01 22:01:00 +02:00
|
|
|
|
|
|
|
#include <kernel.h>
|
2019-06-25 21:57:18 +02:00
|
|
|
#include <sys/ring_buffer.h>
|
2018-08-01 22:01:00 +02:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct mdm_receiver_context {
|
|
|
|
struct device *uart_dev;
|
|
|
|
|
|
|
|
/* rx data */
|
2019-02-13 22:48:46 +01:00
|
|
|
struct ring_buf rx_rb;
|
2018-08-01 22:01:00 +02:00
|
|
|
struct k_sem rx_sem;
|
|
|
|
|
|
|
|
/* modem data */
|
|
|
|
char *data_manufacturer;
|
|
|
|
char *data_model;
|
|
|
|
char *data_revision;
|
|
|
|
char *data_imei;
|
|
|
|
int data_rssi;
|
|
|
|
};
|
|
|
|
|
2019-02-13 22:59:17 +01:00
|
|
|
/**
|
|
|
|
* @brief Gets receiver context by id.
|
|
|
|
*
|
|
|
|
* @param id: receiver context id.
|
|
|
|
*
|
|
|
|
* @retval Receiver context or NULL.
|
|
|
|
*/
|
2018-08-01 22:01:00 +02:00
|
|
|
struct mdm_receiver_context *mdm_receiver_context_from_id(int id);
|
|
|
|
|
2019-02-13 22:59:17 +01:00
|
|
|
/**
|
|
|
|
* @brief Get received data.
|
|
|
|
*
|
|
|
|
* @param *ctx: receiver context.
|
|
|
|
* @param *buf: buffer to copy the received data to.
|
|
|
|
* @param size: buffer size.
|
|
|
|
* @param *bytes_read: amount of received bytes
|
|
|
|
*
|
|
|
|
* @retval 0 if ok, < 0 if error.
|
|
|
|
*/
|
2018-08-01 22:01:00 +02:00
|
|
|
int mdm_receiver_recv(struct mdm_receiver_context *ctx,
|
|
|
|
u8_t *buf, size_t size, size_t *bytes_read);
|
2019-02-13 22:59:17 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Sends the data over specified receiver context.
|
|
|
|
*
|
|
|
|
* @param *ctx: receiver context.
|
|
|
|
* @param *buf: buffer with the data to send.
|
|
|
|
* @param size: the amount of data to send.
|
|
|
|
*
|
|
|
|
* @retval 0 if ok, < 0 if error.
|
|
|
|
*/
|
2018-08-01 22:01:00 +02:00
|
|
|
int mdm_receiver_send(struct mdm_receiver_context *ctx,
|
|
|
|
const u8_t *buf, size_t size);
|
2019-02-13 22:59:17 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Registers receiver context.
|
|
|
|
*
|
2019-03-27 16:43:42 +01:00
|
|
|
* @note Acquires receivers device, and prepares the context to be used.
|
2019-02-13 22:59:17 +01:00
|
|
|
*
|
|
|
|
* @param *ctx: receiver context to register.
|
|
|
|
* @param *uart_dev_name: communication device for the receiver context.
|
|
|
|
* @param *buf: rx buffer to use for received data.
|
|
|
|
* @param size: rx buffer size.
|
|
|
|
*
|
|
|
|
* @retval 0 if ok, < 0 if error.
|
|
|
|
*/
|
2018-08-01 22:01:00 +02:00
|
|
|
int mdm_receiver_register(struct mdm_receiver_context *ctx,
|
|
|
|
const char *uart_dev_name,
|
|
|
|
u8_t *buf, size_t size);
|
|
|
|
|
2019-06-07 17:51:30 +02:00
|
|
|
int mdm_receiver_sleep(struct mdm_receiver_context *ctx);
|
|
|
|
|
|
|
|
int mdm_receiver_wake(struct mdm_receiver_context *ctx);
|
|
|
|
|
2018-08-01 22:01:00 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-09-14 19:43:44 +02:00
|
|
|
#endif /* ZEPHYR_INCLUDE_DRIVERS_MODEM_MODEM_RECEIVER_H_ */
|