@@ -135,13 +135,14 @@ typedef int16_t device_handle_t;
135
135
#endif
136
136
137
137
/**
138
- * @brief Create a device object and set it up for boot time initialization.
138
+ * @brief Create a device object and set it up for boot time initialization,
139
+ * with de-init capabilities.
139
140
*
140
141
* This macro defines a @ref device that is automatically configured by the
141
142
* kernel during system initialization. This macro should only be used when the
142
143
* device is not being allocated from a devicetree node. If you are allocating a
143
- * device from a devicetree node, use DEVICE_DT_DEFINE () or
144
- * DEVICE_DT_INST_DEFINE () instead.
144
+ * device from a devicetree node, use DEVICE_DT_DEINIT_DEFINE () or
145
+ * DEVICE_DT_INST_DEINIT_DEFINE () instead.
145
146
*
146
147
* @param dev_id A unique token which is used in the name of the global device
147
148
* structure as a C identifier.
@@ -151,6 +152,9 @@ typedef int16_t device_handle_t;
151
152
* (including terminating `NULL`) in order to be looked up from user mode.
152
153
* @param init_fn Pointer to the device's initialization function, which will be
153
154
* run by the kernel during system initialization. Can be `NULL`.
155
+ * @param deinit_fn Pointer to the device's de-initialization function. Can be
156
+ * `NULL`. It must release any acquired resources (e.g. pins, bus, clock...) and
157
+ * leave the device in its reset state.
154
158
* @param pm Pointer to the device's power management resources, a
155
159
* @ref pm_device, which will be stored in @ref device.pm field. Use `NULL` if
156
160
* the device does not use PM.
@@ -164,13 +168,23 @@ typedef int16_t device_handle_t;
164
168
* SYS_INIT() for details.
165
169
* @param api Pointer to the device's API structure. Can be `NULL`.
166
170
*/
167
- #define DEVICE_DEFINE (dev_id , name , init_fn , pm , data , config , level , prio , \
168
- api ) \
171
+ #define DEVICE_DEINIT_DEFINE (dev_id , name , init_fn , deinit_fn , pm , data , \
172
+ config , level , prio , api ) \
169
173
Z_DEVICE_STATE_DEFINE(dev_id); \
170
- Z_DEVICE_DEFINE(DT_INVALID_NODE, dev_id, name, init_fn, NULL , 0U, pm, \
171
- data, config, level, prio, api, \
174
+ Z_DEVICE_DEFINE(DT_INVALID_NODE, dev_id, name, init_fn, deinit_fn , 0U, \
175
+ pm, data, config, level, prio, api, \
172
176
&Z_DEVICE_STATE_NAME(dev_id))
173
177
178
+ /**
179
+ * @brief Create a device object and set it up for boot time initialization.
180
+ *
181
+ * @see DEVICE_DEINIT_DEFINE()
182
+ */
183
+ #define DEVICE_DEFINE (dev_id , name , init_fn , pm , data , config , level , prio , \
184
+ api ) \
185
+ DEVICE_DEINIT_DEFINE(dev_id, name, init_fn, NULL, pm, data, config, \
186
+ level, prio, api)
187
+
174
188
/**
175
189
* @brief Return a string name for a devicetree node.
176
190
*
@@ -213,6 +227,9 @@ typedef int16_t device_handle_t;
213
227
* @param node_id The devicetree node identifier.
214
228
* @param init_fn Pointer to the device's initialization function, which will be
215
229
* run by the kernel during system initialization. Can be `NULL`.
230
+ * @param deinit_fn Pointer to the device's de-initialization function. Can be
231
+ * `NULL`. It must release any acquired resources (e.g. pins, bus, clock...) and
232
+ * leave the device in its reset state.
216
233
* @param pm Pointer to the device's power management resources, a
217
234
* @ref pm_device, which will be stored in @ref device.pm. Use `NULL` if the
218
235
* device does not use PM.
@@ -226,16 +243,38 @@ typedef int16_t device_handle_t;
226
243
* SYS_INIT() for details.
227
244
* @param api Pointer to the device's API structure. Can be `NULL`.
228
245
*/
229
- #define DEVICE_DT_DEFINE (node_id , init_fn , pm , data , config , level , prio , api , \
230
- ...) \
246
+ #define DEVICE_DT_DEINIT_DEFINE (node_id , init_fn , deinit_fn , pm , data , config , \
247
+ level , prio , api , ...) \
231
248
Z_DEVICE_STATE_DEFINE(Z_DEVICE_DT_DEV_ID(node_id)); \
232
249
Z_DEVICE_DEFINE(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
233
- DEVICE_DT_NAME(node_id), init_fn, NULL, \
250
+ DEVICE_DT_NAME(node_id), init_fn, deinit_fn, \
234
251
Z_DEVICE_DT_FLAGS(node_id), pm, data, config, level, \
235
252
prio, api, \
236
253
&Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_ID(node_id)), \
237
254
__VA_ARGS__)
238
255
256
+ /**
257
+ * @brief Create a device object from a devicetree node identifier and set it up
258
+ * for boot time initialization.
259
+ *
260
+ * @see DEVICE_DT_DEINIT_DEFINE()
261
+ */
262
+ #define DEVICE_DT_DEFINE (node_id , init_fn , pm , data , config , level , prio , api , \
263
+ ...) \
264
+ DEVICE_DT_DEINIT_DEFINE(node_id, init_fn, NULL, pm, data, config, \
265
+ level, prio, api, __VA_ARGS__)
266
+
267
+ /**
268
+ * @brief Like DEVICE_DT_DEINIT_DEFINE(), but uses an instance of a
269
+ * `DT_DRV_COMPAT` compatible instead of a node identifier.
270
+ *
271
+ * @param inst Instance number. The `node_id` argument to DEVICE_DT_DEFINE() is
272
+ * set to `DT_DRV_INST(inst)`.
273
+ * @param ... Other parameters as expected by DEVICE_DT_DEFINE().
274
+ */
275
+ #define DEVICE_DT_INST_DEINIT_DEFINE (inst , ...) \
276
+ DEVICE_DT_DEINIT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
277
+
239
278
/**
240
279
* @brief Like DEVICE_DT_DEFINE(), but uses an instance of a `DT_DRV_COMPAT`
241
280
* compatible instead of a node identifier.
0 commit comments