@@ -85,6 +85,35 @@ enum cellular_registration_status {
85
85
CELLULAR_REGISTRATION_REGISTERED_ROAMING ,
86
86
};
87
87
88
+ /** Events emitted asynchronously by a cellular driver */
89
+ enum cellular_event {
90
+ /** One or more modem-info field changed (e.g. IMSI became available). */
91
+ CELLULAR_EVENT_MODEM_INFO_CHANGED = BIT (0 ),
92
+ };
93
+
94
+ /* Opaque bit-mask large enough for all current & future events */
95
+ typedef uint32_t cellular_event_mask_t ;
96
+
97
+ /** Payload for @ref CELLULAR_EVENT_MODEM_INFO_CHANGED. */
98
+ struct cellular_evt_modem_info {
99
+ enum cellular_modem_info_type field ; /**< Which field changed */
100
+ };
101
+
102
+ /**
103
+ * @brief Prototype for cellular event callbacks.
104
+ *
105
+ * @param dev Cellular device that generated the event
106
+ * @param event Which @ref cellular_event occurred
107
+ * @param payload Pointer to the kind-specific payload
108
+ * (`NULL` if the kind defines no payload).
109
+ * @param user_data Pointer supplied when the callback was registered
110
+ *
111
+ * @note The driver calls the callback directly from its own context.
112
+ * Off-load heavy processing to a work-queue if required.
113
+ */
114
+ typedef void (* cellular_event_cb_t )(const struct device * dev , enum cellular_event event ,
115
+ const void * payload , void * user_data );
116
+
88
117
/** API for configuring networks */
89
118
typedef int (* cellular_api_configure_networks )(const struct device * dev ,
90
119
const struct cellular_network * networks ,
@@ -101,8 +130,8 @@ typedef int (*cellular_api_get_signal)(const struct device *dev,
101
130
102
131
/** API for getting modem information */
103
132
typedef int (* cellular_api_get_modem_info )(const struct device * dev ,
104
- const enum cellular_modem_info_type type ,
105
- char * info , size_t size );
133
+ const enum cellular_modem_info_type type , char * info ,
134
+ size_t size );
106
135
107
136
/** API for getting registration status */
108
137
typedef int (* cellular_api_get_registration_status )(const struct device * dev ,
@@ -112,6 +141,10 @@ typedef int (*cellular_api_get_registration_status)(const struct device *dev,
112
141
/** API for programming APN */
113
142
typedef int (* cellular_api_set_apn )(const struct device * dev , const char * apn );
114
143
144
+ /** API for registering an asynchronous callback */
145
+ typedef int (* cellular_api_set_callback )(const struct device * dev , cellular_event_mask_t mask ,
146
+ cellular_event_cb_t cb , void * user_data );
147
+
115
148
/** Cellular driver API */
116
149
__subsystem struct cellular_driver_api {
117
150
cellular_api_configure_networks configure_networks ;
@@ -120,6 +153,7 @@ __subsystem struct cellular_driver_api {
120
153
cellular_api_get_modem_info get_modem_info ;
121
154
cellular_api_get_registration_status get_registration_status ;
122
155
cellular_api_set_apn set_apn ;
156
+ cellular_api_set_callback set_callback ;
123
157
};
124
158
125
159
/**
@@ -281,6 +315,32 @@ static inline int cellular_set_apn(const struct device *dev, const char *apn)
281
315
return api -> set_apn (dev , apn );
282
316
}
283
317
318
+ /**
319
+ * @brief Subscribe to asynchronous cellular events.
320
+ *
321
+ * @param dev Cellular device
322
+ * @param mask Event mask to subscribe to
323
+ * @param cb Callback to call when the event occurs, or NULL to unsubscribe
324
+ * @param user_data Pointer to user data that will be passed to the callback
325
+ *
326
+ * @retval 0 Success
327
+ * @retval -ENOSYS Driver does not support event callbacks
328
+ * @retval -EINVAL Bad parameters
329
+ * @retval -ENOMEM No space left for another subscriber
330
+ * @retval <0 Driver-specific error
331
+ */
332
+ static inline int cellular_set_callback (const struct device * dev , cellular_event_mask_t mask ,
333
+ cellular_event_cb_t cb , void * user_data )
334
+ {
335
+ const struct cellular_driver_api * api = (const struct cellular_driver_api * )dev -> api ;
336
+
337
+ if (api -> set_callback == NULL ) {
338
+ return - ENOSYS ;
339
+ }
340
+
341
+ return api -> set_callback (dev , mask , cb , user_data );
342
+ }
343
+
284
344
#ifdef __cplusplus
285
345
}
286
346
#endif
0 commit comments