Zephyr API Documentation 4.2.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
hl78xx_apis.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025 Netfeasa Ltd.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6#ifndef ZEPHYR_INCLUDE_DRIVERS_HL78XX_APIS_H_
7#define ZEPHYR_INCLUDE_DRIVERS_HL78XX_APIS_H_
8
9#include <zephyr/types.h>
10#include <zephyr/device.h>
11#include <errno.h>
12#include <stddef.h>
13#include <zephyr/modem/chat.h>
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20/* Magic constants */
21#define CSQ_RSSI_UNKNOWN (99)
22#define CESQ_RSRP_UNKNOWN (255)
23#define CESQ_RSRQ_UNKNOWN (255)
24/* Magic numbers to units conversions */
25#define CSQ_RSSI_TO_DB(v) (-113 + (2 * (v)))
26#define CESQ_RSRP_TO_DB(v) (-140 + (v))
27#define CESQ_RSRQ_TO_DB(v) (-20 + ((v) / 2))
29#define PAUSED 1
31#define ACTIVE 0
32#define MDM_MANUFACTURER_LENGTH 20
33#define MDM_MODEL_LENGTH 32
34#define MDM_REVISION_LENGTH 64
35#define MDM_IMEI_LENGTH 16
36#define MDM_IMSI_LENGTH 23
37#define MDM_ICCID_LENGTH 22
38#define MDM_APN_MAX_LENGTH 64
39#define MDM_MAX_CERT_LENGTH 4096
40#define MDM_MAX_HOSTNAME_LEN 128
49#define HL78XX_EVT_MONITOR(name, _handler, ...) \
50 static STRUCT_SECTION_ITERABLE(hl78xx_evt_monitor_entry, name) = { \
51 .handler = _handler, \
52 .next = NULL, \
53 .flags.direct = false, \
54 COND_CODE_1(__VA_ARGS__, (.flags.paused = __VA_ARGS__,), ()) }
55
60#ifdef CONFIG_MODEM_HL78XX_12
61 HL78XX_RAT_GSM,
62#ifdef CONFIG_MODEM_HL78XX_12_FW_R6
63 HL78XX_RAT_NBNTN,
64#endif
65#endif
66#ifdef CONFIG_MODEM_HL78XX_AUTORAT
67 HL78XX_RAT_MODE_AUTO,
68#endif
71};
72
79
89
92 /* <APN> Access Point Name */
94 /* <Current RAT> */
96 /* <Network Operator> */
98};
99
112
119
130
131typedef int (*hl78xx_api_configure_networks)(const struct device *dev,
132 const struct hl78xx_network *networks, uint8_t size);
133
135typedef int (*hl78xx_api_get_supported_networks)(const struct device *dev,
136 const struct hl78xx_network **networks,
137 uint8_t *size);
138
140typedef int (*hl78xx_api_get_signal)(const struct device *dev, const enum cellular_signal_type type,
141 int16_t *value);
142
144typedef int (*hl78xx_api_get_modem_info)(const struct device *dev,
145 const enum cellular_modem_info_type type, char *info,
146 size_t size);
147
149typedef int (*hl78xx_api_get_registration_status)(const struct device *dev,
151 enum cellular_registration_status *status);
152
154typedef int (*hl78xx_api_set_apn)(const struct device *dev, const char *apn, uint16_t size);
155
157typedef int (*hl78xx_api_set_phone_functionality)(const struct device *dev,
158 enum hl78xx_phone_functionality functionality,
159 bool reset);
160
162typedef int (*hl78xx_api_get_phone_functionality)(const struct device *dev,
163 enum hl78xx_phone_functionality *functionality);
164
166typedef int (*hl78xx_api_send_at_cmd)(const struct device *dev, const char *cmd, uint16_t cmd_size,
167 const struct modem_chat_match *response_matches,
168 uint16_t matches_size);
169
171struct hl78xx_evt_monitor_entry; /* forward declaration */
172/* Event monitor dispatcher */
173typedef void (*hl78xx_evt_monitor_dispatcher_t)(struct hl78xx_evt *notif);
174/* Event monitor handler */
175typedef void (*hl78xx_evt_monitor_handler_t)(struct hl78xx_evt *notif,
176 struct hl78xx_evt_monitor_entry *mon);
177
181 /* link for runtime list */
183 struct {
184 uint8_t paused: 1; /* Monitor is paused. */
185 uint8_t direct: 1; /* Dispatch in ISR. */
187};
188
196 enum hl78xx_phone_functionality functionality,
197 bool reset);
205 enum hl78xx_phone_functionality *functionality);
213int hl78xx_api_func_get_signal(const struct device *dev, const enum cellular_signal_type type,
214 int16_t *value);
224 enum hl78xx_modem_info_type type, void *info,
225 size_t size);
235int hl78xx_api_func_modem_dynamic_cmd_send(const struct device *dev, const char *cmd,
236 uint16_t cmd_size,
237 const struct modem_chat_match *response_matches,
238 uint16_t matches_size);
252static inline int hl78xx_get_modem_info(const struct device *dev,
253 const enum hl78xx_modem_info_type type, void *info,
254 size_t size)
255{
256 return hl78xx_api_func_get_modem_info_vendor(dev, type, info, size);
257}
258
273static inline int hl78xx_set_phone_functionality(const struct device *dev,
274 enum hl78xx_phone_functionality functionality,
275 bool reset)
276{
277 return hl78xx_api_func_set_phone_functionality(dev, functionality, reset);
278}
279
293static inline int hl78xx_get_phone_functionality(const struct device *dev,
294 enum hl78xx_phone_functionality *functionality)
295{
296 return hl78xx_api_func_get_phone_functionality(dev, functionality);
297}
298
316static inline int hl78xx_modem_cmd_send(const struct device *dev, const char *cmd,
317 uint16_t cmd_size,
318 const struct modem_chat_match *response_matches,
319 uint16_t matches_size)
320{
321
322 return hl78xx_api_func_modem_dynamic_cmd_send(dev, cmd, cmd_size, response_matches,
323 matches_size);
324}
325
337static inline int hl78xx_parse_rssi(uint8_t rssi, int16_t *value)
338{
339 /* AT+CSQ returns a response +CSQ: <rssi>,<ber> where:
340 * - rssi is a integer from 0 to 31 whose values describes a signal strength
341 * between -113 dBm for 0 and -51dbM for 31 or unknown for 99
342 * - ber is an integer from 0 to 7 that describes the error rate, it can also
343 * be 99 for an unknown error rate
344 */
345 if (rssi == CSQ_RSSI_UNKNOWN) {
346 return -EINVAL;
347 }
348
349 *value = (int16_t)CSQ_RSSI_TO_DB(rssi);
350 return 0;
351}
352
365static inline int hl78xx_parse_rsrp(uint8_t rsrp, int16_t *value)
366{
367 /* AT+CESQ returns a response
368 * +CESQ: <rxlev>,<ber>,<rscp>,<ecn0>,<rsrq>,<rsrp> where:
369 * rsrq is a integer from 0 to 34 whose values describes the Reference
370 * Signal Receive Quality between -20 dB for 0 and -3 dB for 34
371 * (0.5 dB steps), or unknown for 255
372 * rsrp is an integer from 0 to 97 that describes the Reference Signal
373 * Receive Power between -140 dBm for 0 and -44 dBm for 97 (1 dBm steps),
374 * or unknown for 255
375 */
376 if (rsrp == CESQ_RSRP_UNKNOWN) {
377 return -EINVAL;
378 }
379
380 *value = (int16_t)CESQ_RSRP_TO_DB(rsrp);
381 return 0;
382}
383
396static inline int hl78xx_parse_rsrq(uint8_t rsrq, int16_t *value)
397{
398 if (rsrq == CESQ_RSRQ_UNKNOWN) {
399 return -EINVAL;
400 }
401
402 *value = (int16_t)CESQ_RSRQ_TO_DB(rsrq);
403 return 0;
404}
405
413{
414 mon->flags.paused = true;
415}
416
424{
425 mon->flags.paused = false;
426}
427
453
454#ifdef __cplusplus
455}
456#endif
457
458#endif /* ZEPHYR_INCLUDE_DRIVERS_HL78XX_APIS_H_ */
Main header file for cellular modem driver API.
System error numbers.
cellular_access_technology
Cellular access technologies (3GPP TS 27.007 AcT)
Definition cellular.h:33
cellular_registration_status
Cellular registration status (3GPP TS 27.007)
Definition cellular.h:109
cellular_signal_type
Cellular signal type.
Definition cellular.h:86
cellular_modem_info_type
Cellular modem info type.
Definition cellular.h:93
static void cmd(uint32_t command)
Execute a display list command by co-processor engine.
Definition ft8xx_reference_api.h:153
#define EINVAL
Invalid argument.
Definition errno.h:60
int(* hl78xx_api_configure_networks)(const struct device *dev, const struct hl78xx_network *networks, uint8_t size)
API for configuring networks.
Definition hl78xx_apis.h:131
#define CESQ_RSRP_UNKNOWN
Definition hl78xx_apis.h:22
static int hl78xx_parse_rsrq(uint8_t rsrq, int16_t *value)
Convert raw RSRQ value from the modem to dB.
Definition hl78xx_apis.h:396
hl78xx_cell_rat_mode
Cellular radio access technologies.
Definition hl78xx_apis.h:57
@ HL78XX_RAT_MODE_NONE
Definition hl78xx_apis.h:69
@ HL78XX_RAT_COUNT
Definition hl78xx_apis.h:70
@ HL78XX_RAT_NB1
Definition hl78xx_apis.h:59
@ HL78XX_RAT_CAT_M1
Definition hl78xx_apis.h:58
#define CESQ_RSRP_TO_DB(v)
Definition hl78xx_apis.h:26
hl78xx_phone_functionality
Phone functionality modes.
Definition hl78xx_apis.h:74
@ HL78XX_SIM_POWER_OFF
Definition hl78xx_apis.h:75
@ HL78XX_AIRPLANE
Definition hl78xx_apis.h:77
@ HL78XX_FULLY_FUNCTIONAL
Definition hl78xx_apis.h:76
#define CESQ_RSRQ_TO_DB(v)
Definition hl78xx_apis.h:27
int(* hl78xx_api_get_registration_status)(const struct device *dev, enum cellular_access_technology tech, enum cellular_registration_status *status)
API for getting registration status.
Definition hl78xx_apis.h:149
int hl78xx_evt_monitor_register(struct hl78xx_evt_monitor_entry *mon)
Register an event monitor to receive HL78xx modem event notifications.
int(* hl78xx_api_get_supported_networks)(const struct device *dev, const struct hl78xx_network **networks, uint8_t *size)
API for getting supported networks.
Definition hl78xx_apis.h:135
#define CSQ_RSSI_TO_DB(v)
Definition hl78xx_apis.h:25
int(* hl78xx_api_get_signal)(const struct device *dev, const enum cellular_signal_type type, int16_t *value)
API for getting network signal strength.
Definition hl78xx_apis.h:140
int(* hl78xx_api_set_phone_functionality)(const struct device *dev, enum hl78xx_phone_functionality functionality, bool reset)
API for set phone functionality.
Definition hl78xx_apis.h:157
int(* hl78xx_api_send_at_cmd)(const struct device *dev, const char *cmd, uint16_t cmd_size, const struct modem_chat_match *response_matches, uint16_t matches_size)
API for get phone functionality.
Definition hl78xx_apis.h:166
int hl78xx_evt_notif_handler_set(hl78xx_evt_monitor_dispatcher_t handler)
Set the event notification handler for HL78xx modem events.
hl78xx_evt_type
Definition hl78xx_apis.h:113
@ HL78XX_LTE_REGISTRATION_STAT_UPDATE
Definition hl78xx_apis.h:115
@ HL78XX_LTE_RAT_UPDATE
Definition hl78xx_apis.h:114
@ HL78XX_LTE_MODEM_STARTUP
Definition hl78xx_apis.h:117
@ HL78XX_LTE_SIM_REGISTRATION
Definition hl78xx_apis.h:116
static int hl78xx_parse_rsrp(uint8_t rsrp, int16_t *value)
Convert raw RSRP value from the modem to dBm.
Definition hl78xx_apis.h:365
#define CSQ_RSSI_UNKNOWN
Definition hl78xx_apis.h:21
#define CESQ_RSRQ_UNKNOWN
Definition hl78xx_apis.h:23
static int hl78xx_parse_rssi(uint8_t rssi, int16_t *value)
Convert raw RSSI value from the modem to dBm.
Definition hl78xx_apis.h:337
void(* hl78xx_evt_monitor_handler_t)(struct hl78xx_evt *notif, struct hl78xx_evt_monitor_entry *mon)
Definition hl78xx_apis.h:175
int(* hl78xx_api_get_modem_info)(const struct device *dev, const enum cellular_modem_info_type type, char *info, size_t size)
API for getting modem information.
Definition hl78xx_apis.h:144
int hl78xx_api_func_set_phone_functionality(const struct device *dev, enum hl78xx_phone_functionality functionality, bool reset)
hl78xx_api_func_set_phone_functionality
int(* hl78xx_api_set_apn)(const struct device *dev, const char *apn, uint16_t size)
API for setting apn.
Definition hl78xx_apis.h:154
hl78xx_modem_info_type
Cellular modem info type.
Definition hl78xx_apis.h:91
@ HL78XX_MODEM_INFO_APN
Definition hl78xx_apis.h:93
@ HL78XX_MODEM_INFO_CURRENT_RAT
Definition hl78xx_apis.h:95
@ HL78XX_MODEM_INFO_NETWORK_OPERATOR
Definition hl78xx_apis.h:97
static void hl78xx_evt_monitor_resume(struct hl78xx_evt_monitor_entry *mon)
Resume monitor.
Definition hl78xx_apis.h:423
int(* hl78xx_api_get_phone_functionality)(const struct device *dev, enum hl78xx_phone_functionality *functionality)
API for get phone functionality.
Definition hl78xx_apis.h:162
hl78xx_module_status
Module status codes.
Definition hl78xx_apis.h:80
@ HL78XX_MODULE_SIM_NOT_PRESENT
Definition hl78xx_apis.h:83
@ HL78XX_MODULE_READY
Definition hl78xx_apis.h:81
@ HL78XX_MODULE_UNRECOVERABLE_ERROR
Definition hl78xx_apis.h:85
@ HL78XX_MODULE_INACTIVE_SIM
Definition hl78xx_apis.h:87
@ HL78XX_MODULE_WAITING_FOR_ACCESS_CODE
Definition hl78xx_apis.h:82
@ HL78XX_MODULE_UNKNOWN_STATE
Definition hl78xx_apis.h:86
@ HL78XX_MODULE_SIMLOCK
Definition hl78xx_apis.h:84
static int hl78xx_get_modem_info(const struct device *dev, const enum hl78xx_modem_info_type type, void *info, size_t size)
Get modem info for the device.
Definition hl78xx_apis.h:252
int hl78xx_api_func_get_phone_functionality(const struct device *dev, enum hl78xx_phone_functionality *functionality)
hl78xx_api_func_get_phone_functionality
int hl78xx_api_func_get_modem_info_vendor(const struct device *dev, enum hl78xx_modem_info_type type, void *info, size_t size)
hl78xx_api_func_get_modem_info_vendor - Brief description of the function.
void(* hl78xx_evt_monitor_dispatcher_t)(struct hl78xx_evt *notif)
Definition hl78xx_apis.h:173
static void hl78xx_evt_monitor_pause(struct hl78xx_evt_monitor_entry *mon)
Pause monitor.
Definition hl78xx_apis.h:412
int hl78xx_api_func_modem_dynamic_cmd_send(const struct device *dev, const char *cmd, uint16_t cmd_size, const struct modem_chat_match *response_matches, uint16_t matches_size)
hl78xx_api_func_modem_dynamic_cmd_send - Brief description of the function.
int hl78xx_api_func_get_signal(const struct device *dev, const enum cellular_signal_type type, int16_t *value)
hl78xx_api_func_get_signal - Brief description of the function.
static int hl78xx_modem_cmd_send(const struct device *dev, const char *cmd, uint16_t cmd_size, const struct modem_chat_match *response_matches, uint16_t matches_size)
Send an AT command to the modem and wait for a matched response.
Definition hl78xx_apis.h:316
static int hl78xx_set_phone_functionality(const struct device *dev, enum hl78xx_phone_functionality functionality, bool reset)
Set the modem phone functionality mode.
Definition hl78xx_apis.h:273
int hl78xx_evt_monitor_unregister(struct hl78xx_evt_monitor_entry *mon)
Unregister an event monitor from receiving HL78xx modem event notifications.
static int hl78xx_get_phone_functionality(const struct device *dev, enum hl78xx_phone_functionality *functionality)
Get the current phone functionality mode of the modem.
Definition hl78xx_apis.h:293
enum cellular_access_technology hl78xx_rat_to_access_tech(enum hl78xx_cell_rat_mode rat_mode)
Convert HL78xx RAT mode to standard cellular API.
flags
Definition parser.h:97
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
__INT16_TYPE__ int16_t
Definition stdint.h:73
Runtime device structure (in ROM) per driver instance.
Definition device.h:510
Definition hl78xx_apis.h:178
uint8_t direct
Definition hl78xx_apis.h:185
uint8_t paused
Definition hl78xx_apis.h:184
struct hl78xx_evt_monitor_entry * next
Definition hl78xx_apis.h:182
struct hl78xx_evt_monitor_entry::@123314375256277045305202074155231060013037303316 flags
const hl78xx_evt_monitor_handler_t handler
Monitor callback.
Definition hl78xx_apis.h:180
Definition hl78xx_apis.h:120
enum hl78xx_evt_type type
Definition hl78xx_apis.h:121
bool status
Definition hl78xx_apis.h:126
union hl78xx_evt::@245116247166211205273371261316135324040054344202 content
int value
Definition hl78xx_apis.h:127
enum hl78xx_cell_rat_mode rat_mode
Definition hl78xx_apis.h:125
enum cellular_registration_status reg_status
Definition hl78xx_apis.h:124
Cellular network structure.
Definition hl78xx_apis.h:101
enum hl78xx_cell_rat_mode technology
Cellular access technology.
Definition hl78xx_apis.h:103
uint16_t * bands
List of bands, as defined by the specified cellular access technology, to enables.
Definition hl78xx_apis.h:108
uint16_t size
Size of bands.
Definition hl78xx_apis.h:110
Modem chat match.
Definition chat.h:47