Skip to content

Commit 66b9eb2

Browse files
[to be squashed] Ensure deprecation period for all net functions
The new functions in module/openthread will be called with `_platform_` to ensure the backward compatibility of functions defined in subsys/net/l2/openthread Signed-off-by: Arkadiusz Balys <[email protected]>
1 parent 06e81bc commit 66b9eb2

File tree

6 files changed

+160
-102
lines changed

6 files changed

+160
-102
lines changed

include/zephyr/net/openthread.h

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,13 @@ struct openthread_context {
6060
struct pkt_list_elem pkt_list[CONFIG_OPENTHREAD_PKT_LIST_SIZE];
6161

6262
/** @deprecated A list for state change callbacks */
63-
sys_slist_t ot_state_change_cbs;
63+
sys_slist_t state_change_cbs;
6464
};
65+
/**
66+
* INTERNAL_HIDDEN @endcond
67+
*/
68+
69+
/** OpenThread state change callback */
6570

6671
/**
6772
* @brief OpenThread state change callback structure
@@ -94,17 +99,11 @@ struct openthread_state_changed_cb {
9499
};
95100

96101
/**
97-
* INTERNAL_HIDDEN @endcond
98-
*/
99-
100-
/** OpenThread state change callback */
101-
102-
/**
103-
* @deprecated use @ref openthread_state_changed_callback_register from modules/openthread
102+
* @deprecated use @ref openthread_platform_state_changed_cb_register from modules/openthread
104103
* instead.
105104
*
106105
* @brief Registers callbacks which will be called when certain configuration
107-
* or state changes occur within OpenThread.`
106+
* or state changes occur within OpenThread.
108107
*
109108
* @param ot_context the OpenThread context to register the callback with.
110109
* @param cb callback struct to register.
@@ -113,7 +112,7 @@ __deprecated int openthread_state_changed_cb_register(struct openthread_context
113112
struct openthread_state_changed_cb *cb);
114113

115114
/**
116-
* @deprecated use @ref openthread_state_changed_callback_unregister from modules/openthread
115+
* @deprecated use @ref openthread_platform_state_changed_cb_unregister from modules/openthread
117116
* instead.
118117
*
119118
* @brief Unregisters OpenThread configuration or state changed callbacks.
@@ -124,6 +123,13 @@ __deprecated int openthread_state_changed_cb_register(struct openthread_context
124123
__deprecated int openthread_state_changed_cb_unregister(struct openthread_context *ot_context,
125124
struct openthread_state_changed_cb *cb);
126125

126+
/**
127+
* @deprecated use @ref openthread_platform_thread_id_get from modules/openthread instead.
128+
*
129+
* @brief Get OpenThread thread identification.
130+
*/
131+
__deprecated k_tid_t openthread_thread_id_get(void);
132+
127133
/**
128134
* @brief Get pointer to default OpenThread context.
129135
*
@@ -133,7 +139,31 @@ __deprecated int openthread_state_changed_cb_unregister(struct openthread_contex
133139
struct openthread_context *openthread_get_default_context(void);
134140

135141
/**
136-
* @deprecated use @ref openthread_mutex_lock from modules/openthread instead.
142+
* @deprecated use @ref openthread_platform_get_default_instance from modules/openthread
143+
* instead.
144+
*
145+
* @brief Get pointer to default OpenThread instance.
146+
*
147+
* @retval !NULL On success.
148+
* @retval NULL On failure.
149+
*/
150+
__deprecated struct otInstance *openthread_get_default_instance(void);
151+
152+
/**
153+
* @deprecated use @ref openthread_platform_start from modules/openthread instead.
154+
*
155+
* @brief Starts the OpenThread network.
156+
*
157+
* @details Depends on active settings: it uses stored network configuration,
158+
* start joining procedure or uses default network configuration. Additionally
159+
* when the device is MTD, it sets the SED mode to properly attach the network.
160+
*
161+
* @param ot_context
162+
*/
163+
__deprecated int openthread_start(struct openthread_context *ot_context);
164+
165+
/**
166+
* @deprecated use @ref openthread_platform_mutex_lock from modules/openthread instead.
137167
*
138168
* @brief Lock internal mutex before accessing OT API.
139169
*
@@ -146,7 +176,7 @@ struct openthread_context *openthread_get_default_context(void);
146176
__deprecated void openthread_api_mutex_lock(struct openthread_context *ot_context);
147177

148178
/**
149-
* @deprecated use @ref openthread_mutex_try_lock from modules/openthread instead.
179+
* @deprecated use @ref openthread_platform_mutex_try_lock from modules/openthread instead.
150180
*
151181
* @brief Try to lock internal mutex before accessing OT API.
152182
*
@@ -161,7 +191,7 @@ __deprecated void openthread_api_mutex_lock(struct openthread_context *ot_contex
161191
__deprecated int openthread_api_mutex_try_lock(struct openthread_context *ot_context);
162192

163193
/**
164-
* @deprecated use @ref openthread_mutex_unlock from modules/openthread instead.
194+
* @deprecated use @ref openthread_platform_mutex_unlock from modules/openthread instead.
165195
*
166196
* @brief Unlock internal mutex after accessing OT API.
167197
*

modules/openthread/platform/openthread.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ LOG_MODULE_REGISTER(module_openthread, CONFIG_OPENTHREAD_PLATFORM_LOG_LEVEL);
1818
#include <zephyr/version.h>
1919
#include <zephyr/sys/check.h>
2020

21-
#include "platform/platform-zephyr.h"
22-
#include "openthread_module.h"
21+
#include "platform-zephyr.h"
22+
#include "openthread.h"
2323

2424
#include <openthread/child_supervision.h>
2525
#include <openthread/cli.h>
@@ -108,7 +108,7 @@ static sys_slist_t openthread_state_change_cbs;
108108

109109
K_KERNEL_STACK_DEFINE(ot_stack_area, OT_STACK_SIZE);
110110

111-
k_tid_t openthread_thread_id_get(void)
111+
k_tid_t openthread_platform_thread_id_get(void)
112112
{
113113
return (k_tid_t)&openthread_work_q.thread;
114114
}
@@ -127,15 +127,15 @@ static int ncp_hdlc_send(const uint8_t *buf, uint16_t len)
127127

128128
static void openthread_process(struct k_work *work)
129129
{
130-
openthread_mutex_lock();
130+
openthread_platform_mutex_lock();
131131

132132
while (otTaskletsArePending(openthread_instance)) {
133133
otTaskletsProcess(openthread_instance);
134134
}
135135

136136
otSysProcessDrivers(openthread_instance);
137137

138-
openthread_mutex_unlock();
138+
openthread_platform_mutex_unlock();
139139
}
140140

141141
static void ot_joiner_start_handler(otError error, void *context)
@@ -172,15 +172,15 @@ static void ot_state_changed_handler(uint32_t flags, void *context)
172172
}
173173
}
174174

175-
int openthread_state_changed_callback_register(struct openthread_state_changed_callback *cb)
175+
int openthread_platform_state_changed_cb_register(struct openthread_state_changed_callback *cb)
176176
{
177177
CHECKIF(cb == NULL || cb->state_changed_cb == NULL) {
178178
return -EINVAL;
179179
}
180180

181-
openthread_mutex_lock();
181+
openthread_platform_mutex_lock();
182182
sys_slist_append(&openthread_state_change_cbs, &cb->node);
183-
openthread_mutex_unlock();
183+
openthread_platform_mutex_unlock();
184184

185185
return 0;
186186
}
@@ -197,17 +197,17 @@ void otSysEventSignalPending(void)
197197
otTaskletsSignalPending(NULL);
198198
}
199199

200-
int openthread_state_changed_callback_unregister(struct openthread_state_changed_callback *cb)
200+
int openthread_platform_state_changed_cb_unregister(struct openthread_state_changed_callback *cb)
201201
{
202202
bool removed;
203203

204204
CHECKIF(cb == NULL) {
205205
return -EINVAL;
206206
}
207207

208-
openthread_mutex_lock();
208+
openthread_platform_mutex_lock();
209209
removed = sys_slist_find_and_remove(&openthread_state_change_cbs, &cb->node);
210-
openthread_mutex_unlock();
210+
openthread_platform_mutex_unlock();
211211

212212
if (!removed) {
213213
return -EALREADY;
@@ -216,13 +216,13 @@ int openthread_state_changed_callback_unregister(struct openthread_state_changed
216216
return 0;
217217
}
218218

219-
struct otInstance *openthread_get_default_instance()
219+
struct otInstance *openthread_platform_get_default_instance()
220220
{
221221
__ASSERT(openthread_instance, "OT instance is not initialized");
222222
return openthread_instance;
223223
}
224224

225-
bool openthread_init(receiveCallback rx_handler, void *context)
225+
bool openthread_platform_init(receiveCallback rx_handler, void *context)
226226
{
227227
struct k_work_queue_config q_cfg = {
228228
.name = "openthread",
@@ -238,7 +238,7 @@ bool openthread_init(receiveCallback rx_handler, void *context)
238238
k_mutex_init(&openthread_lock);
239239
k_work_init(&openthread_work, openthread_process);
240240

241-
openthread_mutex_lock();
241+
openthread_platform_mutex_lock();
242242

243243
otSysInit(0, NULL);
244244
openthread_instance = otInstanceInitSingle();
@@ -290,7 +290,7 @@ bool openthread_init(receiveCallback rx_handler, void *context)
290290
}
291291
}
292292

293-
openthread_mutex_unlock();
293+
openthread_platform_mutex_unlock();
294294

295295
/* Start work queue for the OpenThread module */
296296
k_work_queue_start(&openthread_work_q, ot_stack_area, K_KERNEL_STACK_SIZEOF(ot_stack_area),
@@ -301,9 +301,9 @@ bool openthread_init(receiveCallback rx_handler, void *context)
301301
return true;
302302
}
303303

304-
int openthread_start()
304+
int openthread_platform_start()
305305
{
306-
openthread_mutex_lock();
306+
openthread_platform_mutex_lock();
307307
otError error = OT_ERROR_NONE;
308308

309309
if (otDatasetIsCommissioned(openthread_instance)) {
@@ -377,42 +377,42 @@ int openthread_start()
377377

378378
exit:
379379

380-
openthread_mutex_unlock();
380+
openthread_platform_mutex_unlock();
381381

382382
return error == OT_ERROR_NONE ? 0 : -EIO;
383383
}
384384

385-
int openthread_stop()
385+
int openthread_platform_stop()
386386
{
387387
otError error;
388388

389389
if (IS_ENABLED(CONFIG_OPENTHREAD_COPROCESSOR)) {
390390
return 0;
391391
}
392392

393-
openthread_mutex_lock();
393+
openthread_platform_mutex_lock();
394394

395395
error = otThreadSetEnabled(openthread_instance, false);
396396
if (error == OT_ERROR_INVALID_STATE) {
397397
LOG_DBG("Openthread interface was not up [%d]", error);
398398
}
399399

400-
openthread_mutex_unlock();
400+
openthread_platform_mutex_unlock();
401401

402402
return 0;
403403
}
404404

405-
void openthread_mutex_lock()
405+
void openthread_platform_mutex_lock()
406406
{
407407
(void)k_mutex_lock(&openthread_lock, K_FOREVER);
408408
}
409409

410-
int openthread_mutex_try_lock()
410+
int openthread_platform_mutex_try_lock()
411411
{
412412
return k_mutex_lock(&openthread_lock, K_NO_WAIT);
413413
}
414414

415-
void openthread_mutex_unlock()
415+
void openthread_platform_mutex_unlock()
416416
{
417417
(void)k_mutex_unlock(&openthread_lock);
418418
}

modules/openthread/platform/openthread.h

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,22 @@ typedef void (*receiveCallback)(otMessage *aMessage, void *aContext);
6969
*
7070
* @param cb callback struct to register.
7171
*/
72-
int openthread_state_changed_callback_register(struct openthread_state_changed_callback *cb);
72+
int openthread_platform_state_changed_cb_register(struct openthread_state_changed_callback *cb);
7373

7474
/**
7575
* @brief Unregisters OpenThread configuration or state changed callbacks.
7676
*
7777
* @param cb callback struct to unregister.
7878
*/
79-
int openthread_state_changed_callback_unregister(struct openthread_state_changed_callback *cb);
79+
int openthread_platform_state_changed_cb_unregister(struct openthread_state_changed_callback *cb);
8080

81-
struct openthread_context *openthread_get_default_context(void);
82-
struct otInstance *openthread_get_default_instance(void);
81+
/**
82+
* @brief Get pointer to default OpenThread instance.
83+
*
84+
* @retval !NULL On success.
85+
* @retval NULL On failure.
86+
*/
87+
struct otInstance *openthread_platform_get_default_context(void);
8388

8489
/**
8590
* @brief Initialize the OpenThread module.
@@ -102,20 +107,20 @@ struct otInstance *openthread_get_default_instance(void);
102107
* @param context The context to pass to the callback.
103108
* @return true if initialization succeeded, false otherwise.
104109
*/
105-
bool openthread_init(receiveCallback rx_handler, void *context);
110+
bool openthread_platform_init(receiveCallback rx_handler, void *context);
106111

107112
/**
108113
* @brief Get OpenThread thread identification.
109114
*/
110-
k_tid_t openthread_thread_id_get(void);
115+
k_tid_t openthread_platform_thread_id_get(void);
111116

112117
/**
113118
* @brief Get pointer to default OpenThread instance.
114119
*
115120
* @retval !NULL On success.
116121
* @retval NULL On failure.
117122
*/
118-
struct otInstance *openthread_get_default_instance(void);
123+
struct otInstance *openthread_platform_get_default_instance(void);
119124

120125
/**
121126
* @brief Starts the OpenThread network.
@@ -124,12 +129,12 @@ struct otInstance *openthread_get_default_instance(void);
124129
* start joining procedure or uses default network configuration. Additionally
125130
* when the device is MTD, it sets the SED mode to properly attach the network.
126131
*/
127-
int openthread_start(void);
132+
int openthread_platform_start(void);
128133

129134
/**
130135
* @brief Stops the OpenThread network.
131136
*/
132-
int openthread_stop(void);
137+
int openthread_platform_stop(void);
133138

134139
/**
135140
* @brief Lock internal mutex before accessing OT API.
@@ -140,7 +145,7 @@ int openthread_stop(void);
140145
*
141146
* @param ot_context Context to lock.
142147
*/
143-
void openthread_mutex_lock(void);
148+
void openthread_platform_mutex_lock(void);
144149

145150
/**
146151
* @brief Try to lock internal mutex before accessing OT API.
@@ -149,14 +154,14 @@ void openthread_mutex_lock(void);
149154
* the internal mutex is unlocked. Otherwise, it exists immediately and returns
150155
* a negative value.
151156
*/
152-
int openthread_mutex_try_lock(void);
157+
int openthread_platform_mutex_try_lock(void);
153158

154159
/**
155160
* @brief Unlock internal mutex after accessing OT API.
156161
*
157162
* @param ot_context Context to unlock.
158163
*/
159-
void openthread_mutex_unlock(void);
164+
void openthread_platform_mutex_unlock(void);
160165

161166
#ifdef __cplusplus
162167
}

modules/openthread/platform/shell.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ static int ot_cmd(const struct shell *sh, size_t argc, char *argv[])
7575

7676
shell_p = sh;
7777

78-
openthread_mutex_lock();
78+
openthread_platform_mutex_lock();
7979
otCliInputLine(rx_buffer);
80-
openthread_mutex_unlock();
80+
openthread_platform_mutex_unlock();
8181

8282
return 0;
8383
}

0 commit comments

Comments
 (0)