Skip to content

Commit 20dcc15

Browse files
openthread: Move OpenThread implementation from net to modules
Move OpenThread-related code from zephyr/subsys/net/l2/openthread/openthread.c to zephyr/modules/openthread/openthread_module.c. The primary goal of this refactor is to enable the use of OpenThread as an independent module, without the necessity of Zephyr's networking layer. This change is particularly beneficial for simple applications that have their own implementation of the IEEE802.15.4 driver and do not require a networking layer. These applications can now disable Zephyr's L2 and IEEE802.15.4 shim layers and directly use the OpenThread module, saving valuable kilobytes of memory. In this approach if the CONFIG_NET_L2_OPENTHREAD Kconfig option is set, Zephyr's L2 and IEEE802.15.4 layer will be used, and everything will function as before. The main difference is the Zephyr's L2 layer now uses the OpenThread module, no longer implementing it. If the CONFIG_NET_L2_OPENTHREAD Kconfig option is not set, the opentherad_init function will be called at system boot in the POST_KERNEL phase. While most of the functions in include/net/openthread.h have been deprecated, they are still available for use to maintain backwards compatibility. These functions now act as an interface to the new ones defined in modules/openthread. Signed-off-by: Arkadiusz Balys <[email protected]>
1 parent 63c239c commit 20dcc15

File tree

7 files changed

+692
-488
lines changed

7 files changed

+692
-488
lines changed

include/zephyr/net/openthread.h

Lines changed: 22 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ struct pkt_list_elem {
4444
* @brief OpenThread l2 private data.
4545
*/
4646
struct openthread_context {
47-
/** Pointer to OpenThread stack instance */
48-
otInstance *instance;
49-
5047
/** Pointer to OpenThread network interface */
5148
struct net_if *iface;
5249

@@ -62,23 +59,10 @@ struct openthread_context {
6259
/** Array for storing net_pkt for OpenThread internal usage */
6360
struct pkt_list_elem pkt_list[CONFIG_OPENTHREAD_PKT_LIST_SIZE];
6461

65-
/** A mutex to protect API calls from being preempted. */
66-
struct k_mutex api_lock;
67-
68-
/** A work queue for all OpenThread activity */
69-
struct k_work_q work_q;
70-
71-
/** Work object for OpenThread internal usage */
72-
struct k_work api_work;
73-
74-
/** A list for state change callbacks */
75-
sys_slist_t state_change_cbs;
62+
/** @deprecated A list for state change callbacks */
63+
sys_slist_t ot_state_change_cbs;
7664
};
77-
/**
78-
* INTERNAL_HIDDEN @endcond
79-
*/
8065

81-
/** OpenThread state change callback */
8266

8367
/**
8468
* @brief OpenThread state change callback structure
@@ -111,29 +95,34 @@ struct openthread_state_changed_cb {
11195
};
11296

11397
/**
98+
* INTERNAL_HIDDEN @endcond
99+
*/
100+
101+
/** OpenThread state change callback */
102+
103+
/**
104+
* @deprecated use @ref openthread_state_changed_callback_register from modules/openthread instead.
105+
*
114106
* @brief Registers callbacks which will be called when certain configuration
115107
* or state changes occur within OpenThread.
116108
*
117109
* @param ot_context the OpenThread context to register the callback with.
118110
* @param cb callback struct to register.
119111
*/
120-
int openthread_state_changed_cb_register(struct openthread_context *ot_context,
112+
__deprecated int openthread_state_changed_cb_register(struct openthread_context *ot_context,
121113
struct openthread_state_changed_cb *cb);
122114

123115
/**
116+
* @deprecated use @ref openthread_state_changed_callback_unregister from modules/openthread instead.
117+
*
124118
* @brief Unregisters OpenThread configuration or state changed callbacks.
125119
*
126120
* @param ot_context the OpenThread context to unregister the callback from.
127121
* @param cb callback struct to unregister.
128122
*/
129-
int openthread_state_changed_cb_unregister(struct openthread_context *ot_context,
123+
__deprecated int openthread_state_changed_cb_unregister(struct openthread_context *ot_context,
130124
struct openthread_state_changed_cb *cb);
131125

132-
/**
133-
* @brief Get OpenThread thread identification.
134-
*/
135-
k_tid_t openthread_thread_id_get(void);
136-
137126
/**
138127
* @brief Get pointer to default OpenThread context.
139128
*
@@ -143,25 +132,8 @@ k_tid_t openthread_thread_id_get(void);
143132
struct openthread_context *openthread_get_default_context(void);
144133

145134
/**
146-
* @brief Get pointer to default OpenThread instance.
135+
* @deprecated use @ref openthread_mutex_lock from modules/openthread instead.
147136
*
148-
* @retval !NULL On success.
149-
* @retval NULL On failure.
150-
*/
151-
struct otInstance *openthread_get_default_instance(void);
152-
153-
/**
154-
* @brief Starts the OpenThread network.
155-
*
156-
* @details Depends on active settings: it uses stored network configuration,
157-
* start joining procedure or uses default network configuration. Additionally
158-
* when the device is MTD, it sets the SED mode to properly attach the network.
159-
*
160-
* @param ot_context
161-
*/
162-
int openthread_start(struct openthread_context *ot_context);
163-
164-
/**
165137
* @brief Lock internal mutex before accessing OT API.
166138
*
167139
* @details OpenThread API is not thread-safe, therefore before accessing any
@@ -170,9 +142,11 @@ int openthread_start(struct openthread_context *ot_context);
170142
*
171143
* @param ot_context Context to lock.
172144
*/
173-
void openthread_api_mutex_lock(struct openthread_context *ot_context);
145+
__deprecated void openthread_api_mutex_lock(struct openthread_context *ot_context);
174146

175147
/**
148+
* @deprecated use @ref openthread_mutex_try_lock from modules/openthread instead.
149+
*
176150
* @brief Try to lock internal mutex before accessing OT API.
177151
*
178152
* @details This function behaves like openthread_api_mutex_lock() provided that
@@ -183,14 +157,16 @@ void openthread_api_mutex_lock(struct openthread_context *ot_context);
183157
* @retval 0 On success.
184158
* @retval <0 On failure.
185159
*/
186-
int openthread_api_mutex_try_lock(struct openthread_context *ot_context);
160+
__deprecated int openthread_api_mutex_try_lock(struct openthread_context *ot_context);
187161

188162
/**
163+
* @deprecated use @ref openthread_mutex_unlock from modules/openthread instead.
164+
*
189165
* @brief Unlock internal mutex after accessing OT API.
190166
*
191167
* @param ot_context Context to unlock.
192168
*/
193-
void openthread_api_mutex_unlock(struct openthread_context *ot_context);
169+
__deprecated void openthread_api_mutex_unlock(struct openthread_context *ot_context);
194170

195171
/** @cond INTERNAL_HIDDEN */
196172

modules/openthread/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ config OPENTHREAD
88

99
if OPENTHREAD
1010

11+
config OPENTHREAD_AUTO_INITIALIZE
12+
bool "Automatically initialize OpenThread"
13+
default y
14+
depends on !NET_L2_OPENTHREAD
15+
help
16+
This option automatically initializes OpenThread when the the
17+
Zephyr's networking layer is not enabled.
18+
1119
menu "OpenThread stack features"
1220
rsource "Kconfig.features"
1321
endmenu

0 commit comments

Comments
 (0)