NimBLE-Arduino 2.1.3
Loading...
Searching...
No Matches
nimble_npl_os.h
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#ifndef _NIMBLE_NPL_OS_H_
21#define _NIMBLE_NPL_OS_H_
22#include "nimble/porting/nimble/include/syscfg/syscfg.h"
23
24#if CONFIG_NIMBLE_STACK_USE_MEM_POOLS
25
26#include <assert.h>
27#include <stdint.h>
28#include <string.h>
29#include "freertos/FreeRTOS.h"
30#include "freertos/queue.h"
31#include "freertos/semphr.h"
32#include "freertos/task.h"
33#include "freertos/timers.h"
34#include "esp_timer.h"
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40#ifndef ARRAY_SIZE
41#define ARRAY_SIZE(array) \
42 (sizeof(array) / sizeof((array)[0]))
43#endif
44
45#ifdef ESP_PLATFORM
46extern int ets_printf(const char *fmt, ...);
47#else
48#define ets_printf printf
49#define IRAM_ATTR
50#define NIMBLE_CFG_CONTROLLER 1
51#endif
52
53#define PLATFORM_BLE_LL_ASSERT(con) \
54 do{ \
55 if(!(con)) { \
56 ets_printf("assertion:%s\n",#con); \
57 ets_printf("line:%d,function:%s\n", __LINE__, __func__);\
58 assert(0); \
59 } \
60 }while(0)
61
62#define BLE_NPL_OS_ALIGNMENT (4)/*ble_npl_get_os_alignment()*/
63
64#define BLE_NPL_TIME_FOREVER ble_npl_get_time_forever()
65
66/* This should be compatible with TickType_t */
67typedef uint32_t ble_npl_time_t;
68typedef int32_t ble_npl_stime_t;
69
70struct ble_npl_event;
71typedef void ble_npl_event_fn(struct ble_npl_event *ev);
72
73struct ble_npl_event {
74 void *event;
75};
76
77struct ble_npl_eventq {
78 void *eventq;
79};
80
81struct ble_npl_callout {
82 void *co;
83};
84
85struct ble_npl_mutex {
86 void *mutex;
87};
88
89struct ble_npl_sem {
90 void *sem;
91};
92
93/*
94 * Simple APIs are just defined as static inline below, but some are a bit more
95 * complex or require some global state variables and thus are defined in .c
96 * file instead and static inline wrapper just calls proper implementation.
97 * We need declarations of these functions and they are defined in header below.
98 */
99#include "npl_freertos.h"
100
101struct npl_funcs_t {
102 bool (*p_ble_npl_os_started)(void);
103 void *(*p_ble_npl_get_current_task_id)(void);
104 void (*p_ble_npl_eventq_init)(struct ble_npl_eventq *);
105 void (*p_ble_npl_eventq_deinit)(struct ble_npl_eventq *);
106 struct ble_npl_event * (*p_ble_npl_eventq_get)(struct ble_npl_eventq *, ble_npl_time_t);
107 void (*p_ble_npl_eventq_put)(struct ble_npl_eventq *, struct ble_npl_event *);
108 void (*p_ble_npl_eventq_remove)(struct ble_npl_eventq *, struct ble_npl_event *);
109 void (*p_ble_npl_event_run)(struct ble_npl_event *);
110 bool (*p_ble_npl_eventq_is_empty)(struct ble_npl_eventq *);
111 void (*p_ble_npl_event_init)(struct ble_npl_event *, ble_npl_event_fn *, void *);
112 void (*p_ble_npl_event_deinit)(struct ble_npl_event *);
113 void (*p_ble_npl_event_reset)(struct ble_npl_event *);
114 bool (*p_ble_npl_event_is_queued)(struct ble_npl_event *);
115 void * (*p_ble_npl_event_get_arg)(struct ble_npl_event *);
116 void (*p_ble_npl_event_set_arg)(struct ble_npl_event *, void *);
117 ble_npl_error_t (*p_ble_npl_mutex_init)(struct ble_npl_mutex *);
118 ble_npl_error_t (*p_ble_npl_mutex_deinit)(struct ble_npl_mutex *);
119 ble_npl_error_t (*p_ble_npl_mutex_pend)(struct ble_npl_mutex *, ble_npl_time_t);
120 ble_npl_error_t (*p_ble_npl_mutex_release)(struct ble_npl_mutex *);
121 ble_npl_error_t (*p_ble_npl_sem_init)(struct ble_npl_sem *, uint16_t);
122 ble_npl_error_t (*p_ble_npl_sem_deinit)(struct ble_npl_sem *);
123 ble_npl_error_t (*p_ble_npl_sem_pend)(struct ble_npl_sem *, ble_npl_time_t);
124 ble_npl_error_t (*p_ble_npl_sem_release)(struct ble_npl_sem *);
125 uint16_t (*p_ble_npl_sem_get_count)(struct ble_npl_sem *);
126 int (*p_ble_npl_callout_init)(struct ble_npl_callout *, struct ble_npl_eventq *, ble_npl_event_fn *, void *);
127 ble_npl_error_t (*p_ble_npl_callout_reset)(struct ble_npl_callout *, ble_npl_time_t);
128 void (*p_ble_npl_callout_stop)(struct ble_npl_callout *);
129 void (*p_ble_npl_callout_deinit)(struct ble_npl_callout *);
130 void (*p_ble_npl_callout_mem_reset)(struct ble_npl_callout *);
131 bool (*p_ble_npl_callout_is_active)(struct ble_npl_callout *);
132 ble_npl_time_t (*p_ble_npl_callout_get_ticks)(struct ble_npl_callout *);
133 uint32_t (*p_ble_npl_callout_remaining_ticks)(struct ble_npl_callout *, ble_npl_time_t);
134 void (*p_ble_npl_callout_set_arg)(struct ble_npl_callout *, void *);
135 uint32_t (*p_ble_npl_time_get)(void);
136 ble_npl_error_t (*p_ble_npl_time_ms_to_ticks)(uint32_t ms, ble_npl_time_t *);
137 ble_npl_error_t (*p_ble_npl_time_ticks_to_ms)(ble_npl_time_t, uint32_t *);
138 ble_npl_time_t (*p_ble_npl_time_ms_to_ticks32)(uint32_t);
139 uint32_t (*p_ble_npl_time_ticks_to_ms32)(ble_npl_time_t);
140 void (*p_ble_npl_time_delay)(ble_npl_time_t);
141#ifdef ESP_PLATFORM
142 void (*p_ble_npl_hw_set_isr)(int, uint32_t);
143#else
144 void (*p_ble_npl_hw_set_isr)(int, void (*addr)(void));
145#endif
146 uint32_t (*p_ble_npl_hw_enter_critical)(void);
147 void (*p_ble_npl_hw_exit_critical)(uint32_t);
148 uint32_t (*p_ble_npl_get_time_forever)(void);
149 uint8_t (*p_ble_npl_hw_is_in_critical)(void);
150};
151
152extern struct npl_funcs_t *npl_funcs;
153
154static inline bool
155ble_npl_os_started(void)
156{
157 return npl_funcs->p_ble_npl_os_started();
158}
159
160static inline void *
161ble_npl_get_current_task_id(void)
162{
163 return npl_funcs->p_ble_npl_get_current_task_id();
164}
165
166static inline void
167ble_npl_eventq_init(struct ble_npl_eventq *evq)
168{
169 return npl_funcs->p_ble_npl_eventq_init(evq);
170}
171
172static inline void
173ble_npl_eventq_deinit(struct ble_npl_eventq *evq)
174{
175 return npl_funcs->p_ble_npl_eventq_deinit(evq);
176}
177
178static inline struct ble_npl_event *
179ble_npl_eventq_get(struct ble_npl_eventq *evq, ble_npl_time_t tmo)
180{
181 return npl_funcs->p_ble_npl_eventq_get(evq, tmo);
182}
183
184static inline void
185ble_npl_eventq_put(struct ble_npl_eventq *evq, struct ble_npl_event *ev)
186{
187 return npl_funcs->p_ble_npl_eventq_put(evq, ev);
188}
189
190static inline void
191ble_npl_eventq_remove(struct ble_npl_eventq *evq, struct ble_npl_event *ev)
192{
193 return npl_funcs->p_ble_npl_eventq_remove(evq, ev);
194}
195
196static inline void
197ble_npl_event_run(struct ble_npl_event *ev)
198{
199 return npl_funcs->p_ble_npl_event_run(ev);
200}
201
202static inline bool
203ble_npl_eventq_is_empty(struct ble_npl_eventq *evq)
204{
205 return npl_funcs->p_ble_npl_eventq_is_empty(evq);
206}
207
208static inline void
209ble_npl_event_init(struct ble_npl_event *ev, ble_npl_event_fn *fn,
210 void *arg)
211{
212 return npl_funcs->p_ble_npl_event_init(ev, fn, arg);
213}
214
215static inline bool
216ble_npl_event_is_queued(struct ble_npl_event *ev)
217{
218 return npl_funcs->p_ble_npl_event_is_queued(ev);
219}
220
221static inline void *
222ble_npl_event_get_arg(struct ble_npl_event *ev)
223{
224 return npl_funcs->p_ble_npl_event_get_arg(ev);
225}
226
227static inline void
228ble_npl_event_set_arg(struct ble_npl_event *ev, void *arg)
229{
230 return npl_funcs->p_ble_npl_event_set_arg(ev, arg);
231}
232
233static inline ble_npl_error_t
234ble_npl_mutex_init(struct ble_npl_mutex *mu)
235{
236 return npl_funcs->p_ble_npl_mutex_init(mu);
237}
238
239static inline ble_npl_error_t
240ble_npl_mutex_deinit(struct ble_npl_mutex *mu)
241{
242 return npl_funcs->p_ble_npl_mutex_deinit(mu);
243}
244
245static inline ble_npl_error_t
246ble_npl_mutex_pend(struct ble_npl_mutex *mu, ble_npl_time_t timeout)
247{
248 return npl_funcs->p_ble_npl_mutex_pend(mu, timeout);
249}
250
251static inline ble_npl_error_t
252ble_npl_mutex_release(struct ble_npl_mutex *mu)
253{
254 return npl_funcs->p_ble_npl_mutex_release(mu);
255}
256
257static inline ble_npl_error_t
258ble_npl_sem_init(struct ble_npl_sem *sem, uint16_t tokens)
259{
260 return npl_funcs->p_ble_npl_sem_init(sem, tokens);
261}
262
263static inline ble_npl_error_t
264ble_npl_sem_deinit(struct ble_npl_sem *sem)
265{
266 return npl_funcs->p_ble_npl_sem_deinit(sem);
267}
268
269static inline ble_npl_error_t
270ble_npl_sem_pend(struct ble_npl_sem *sem, ble_npl_time_t timeout)
271{
272 return npl_funcs->p_ble_npl_sem_pend(sem, timeout);
273}
274
275static inline ble_npl_error_t
276ble_npl_sem_release(struct ble_npl_sem *sem)
277{
278 return npl_funcs->p_ble_npl_sem_release(sem);
279}
280
281static inline uint16_t
282ble_npl_sem_get_count(struct ble_npl_sem *sem)
283{
284 return npl_funcs->p_ble_npl_sem_get_count(sem);
285}
286
287static inline int
288ble_npl_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq,
289 ble_npl_event_fn *ev_cb, void *ev_arg)
290{
291 return npl_funcs->p_ble_npl_callout_init(co, evq, ev_cb, ev_arg);
292}
293static inline void
294ble_npl_callout_deinit(struct ble_npl_callout *co)
295{
296 return npl_funcs->p_ble_npl_callout_deinit(co);
297}
298
299static inline ble_npl_error_t
300ble_npl_callout_reset(struct ble_npl_callout *co, ble_npl_time_t ticks)
301{
302 return npl_funcs->p_ble_npl_callout_reset(co, ticks);
303}
304
305static inline void
306ble_npl_callout_stop(struct ble_npl_callout *co)
307{
308 return npl_funcs->p_ble_npl_callout_stop(co);
309}
310
311static inline bool
312ble_npl_callout_is_active(struct ble_npl_callout *co)
313{
314 return npl_funcs->p_ble_npl_callout_is_active(co);
315}
316
317static inline ble_npl_time_t
318ble_npl_callout_get_ticks(struct ble_npl_callout *co)
319{
320 return npl_funcs->p_ble_npl_callout_get_ticks(co);
321}
322
323static inline ble_npl_time_t
324ble_npl_callout_remaining_ticks(struct ble_npl_callout *co,
325 ble_npl_time_t time)
326{
327 return npl_funcs->p_ble_npl_callout_remaining_ticks(co, time);
328}
329
330static inline void
331ble_npl_callout_set_arg(struct ble_npl_callout *co, void *arg)
332{
333 return npl_funcs->p_ble_npl_callout_set_arg(co, arg);
334}
335
336static inline ble_npl_time_t
337ble_npl_time_get(void)
338{
339 return npl_funcs->p_ble_npl_time_get();
340}
341
342static inline ble_npl_error_t
343ble_npl_time_ms_to_ticks(uint32_t ms, ble_npl_time_t *out_ticks)
344{
345 return npl_funcs->p_ble_npl_time_ms_to_ticks(ms, out_ticks);
346}
347
348static inline ble_npl_error_t
349ble_npl_time_ticks_to_ms(ble_npl_time_t ticks, uint32_t *out_ms)
350{
351 return npl_funcs->p_ble_npl_time_ticks_to_ms(ticks, out_ms);
352}
353
354static inline ble_npl_time_t
355ble_npl_time_ms_to_ticks32(uint32_t ms)
356{
357 return npl_funcs->p_ble_npl_time_ms_to_ticks32(ms);
358}
359
360static inline uint32_t
361ble_npl_time_ticks_to_ms32(ble_npl_time_t ticks)
362{
363 return npl_funcs->p_ble_npl_time_ticks_to_ms32(ticks);
364}
365
366static inline void
367ble_npl_time_delay(ble_npl_time_t ticks)
368{
369 return npl_funcs->p_ble_npl_time_delay(ticks);
370}
371
372#if NIMBLE_CFG_CONTROLLER
373#ifdef ESP_PLATFORM
374static inline void
375ble_npl_hw_set_isr(int irqn, uint32_t addr)
376{
377 return npl_funcs->p_ble_npl_hw_set_isr(irqn, addr);
378}
379#else
380static inline void
381IRAM_ATTR ble_npl_hw_set_isr(int irqn, void (*addr)(void))
382{
383 return npl_funcs->p_ble_npl_hw_set_isr(irqn, addr);
384}
385#endif
386#endif
387
388//critical section
389static inline uint32_t
390ble_npl_hw_enter_critical(void)
391{
392 return npl_funcs->p_ble_npl_hw_enter_critical();
393}
394
395static inline void
396ble_npl_hw_exit_critical(uint32_t ctx)
397{
398 return npl_funcs->p_ble_npl_hw_exit_critical(ctx);
399}
400
401static inline bool ble_npl_hw_is_in_critical(void)
402{
403 return npl_funcs->p_ble_npl_hw_is_in_critical();
404}
405
406#define ble_npl_get_time_forever (*npl_funcs->p_ble_npl_get_time_forever)
407#define ble_npl_callout_mem_reset (*npl_funcs->p_ble_npl_callout_mem_reset)
408#define ble_npl_event_deinit (*npl_funcs->p_ble_npl_event_deinit)
409#define ble_npl_event_reset (*npl_funcs->p_ble_npl_event_reset)
410
411#ifdef __cplusplus
412}
413#endif
414
415#else // Not using MEM Pools
416
417#include <assert.h>
418#include <stdint.h>
419#include <string.h>
420#include "freertos/FreeRTOS.h"
421#include "freertos/queue.h"
422#include "freertos/semphr.h"
423#include "freertos/task.h"
424#include "freertos/timers.h"
425
426#ifdef __cplusplus
427extern "C" {
428#endif
429
430#define BLE_NPL_OS_ALIGNMENT 4
431
432#define BLE_NPL_TIME_FOREVER portMAX_DELAY
433
434#ifndef ESP_PLATFORM
435#define IRAM_ATTR
436#define NIMBLE_CFG_CONTROLLER 1
437#define NIMBLE_EVT_QUEUE_SIZE 4
438#else
439#define NIMBLE_EVT_QUEUE_SIZE 32
440#endif
441
442/* This should be compatible with TickType_t */
443typedef uint32_t ble_npl_time_t;
444typedef int32_t ble_npl_stime_t;
445
446struct ble_npl_event {
447 bool queued;
448 ble_npl_event_fn *fn;
449 void *arg;
450};
451
452struct ble_npl_eventq {
453 QueueHandle_t q;
454};
455
456struct ble_npl_callout {
457#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
458 esp_timer_handle_t handle;
459#else
460 TimerHandle_t handle;
461#endif
462 struct ble_npl_eventq *evq;
463 struct ble_npl_event ev;
464};
465
466struct ble_npl_mutex {
467 SemaphoreHandle_t handle;
468};
469
470struct ble_npl_sem {
471 SemaphoreHandle_t handle;
472};
473
474/*
475 * Simple APIs are just defined as static inline below, but some are a bit more
476 * complex or require some global state variables and thus are defined in .c
477 * file instead and static inline wrapper just calls proper implementation.
478 * We need declarations of these functions and they are defined in header below.
479 */
480#include "npl_freertos.h"
481
482static inline bool
483ble_npl_os_started(void)
484{
485 return xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED;
486}
487
488static inline void *
489ble_npl_get_current_task_id(void)
490{
491 return xTaskGetCurrentTaskHandle();
492}
493
494static inline void
495ble_npl_eventq_init(struct ble_npl_eventq *evq)
496{
497 evq->q = xQueueCreate(NIMBLE_EVT_QUEUE_SIZE, sizeof(struct ble_npl_eventq *));
498}
499
500static inline void
501ble_npl_eventq_deinit(struct ble_npl_eventq *evq)
502{
503 vQueueDelete(evq->q);
504}
505
506static inline struct ble_npl_event *
507ble_npl_eventq_get(struct ble_npl_eventq *evq, ble_npl_time_t tmo)
508{
509 return npl_freertos_eventq_get(evq, tmo);
510}
511
512static inline void
513ble_npl_eventq_put(struct ble_npl_eventq *evq, struct ble_npl_event *ev)
514{
515 npl_freertos_eventq_put(evq, ev);
516}
517
518static inline void
519ble_npl_eventq_remove(struct ble_npl_eventq *evq, struct ble_npl_event *ev)
520{
521 npl_freertos_eventq_remove(evq, ev);
522}
523
524static inline void
525ble_npl_event_run(struct ble_npl_event *ev)
526{
527 ev->fn(ev);
528}
529
530static inline bool
531ble_npl_eventq_is_empty(struct ble_npl_eventq *evq)
532{
533 return xQueueIsQueueEmptyFromISR(evq->q);
534}
535
536static inline void
537ble_npl_event_init(struct ble_npl_event *ev, ble_npl_event_fn *fn,
538 void *arg)
539{
540 memset(ev, 0, sizeof(*ev));
541 ev->fn = fn;
542 ev->arg = arg;
543}
544
545static inline void
546ble_npl_event_deinit(struct ble_npl_event *ev)
547{
548
549}
550
551static inline bool
552ble_npl_event_is_queued(struct ble_npl_event *ev)
553{
554 return ev->queued;
555}
556
557static inline void *
558ble_npl_event_get_arg(struct ble_npl_event *ev)
559{
560 return ev->arg;
561}
562
563static inline void
564ble_npl_event_set_arg(struct ble_npl_event *ev, void *arg)
565{
566 ev->arg = arg;
567}
568
569static inline ble_npl_error_t
570ble_npl_mutex_init(struct ble_npl_mutex *mu)
571{
572 return npl_freertos_mutex_init(mu);
573}
574
575static inline ble_npl_error_t
576ble_npl_mutex_deinit(struct ble_npl_mutex *mu)
577{
578 return npl_freertos_mutex_deinit(mu);
579}
580
581static inline ble_npl_error_t
582ble_npl_mutex_pend(struct ble_npl_mutex *mu, ble_npl_time_t timeout)
583{
584 return npl_freertos_mutex_pend(mu, timeout);
585}
586
587static inline ble_npl_error_t
588ble_npl_mutex_release(struct ble_npl_mutex *mu)
589{
590 return npl_freertos_mutex_release(mu);
591}
592
593static inline ble_npl_error_t
594ble_npl_sem_init(struct ble_npl_sem *sem, uint16_t tokens)
595{
596 return npl_freertos_sem_init(sem, tokens);
597}
598
599static inline ble_npl_error_t
600ble_npl_sem_deinit(struct ble_npl_sem *sem)
601{
602 return npl_freertos_sem_deinit(sem);
603}
604
605static inline ble_npl_error_t
606ble_npl_sem_pend(struct ble_npl_sem *sem, ble_npl_time_t timeout)
607{
608 return npl_freertos_sem_pend(sem, timeout);
609}
610
611static inline ble_npl_error_t
612ble_npl_sem_release(struct ble_npl_sem *sem)
613{
614 return npl_freertos_sem_release(sem);
615}
616
617static inline uint16_t
618ble_npl_sem_get_count(struct ble_npl_sem *sem)
619{
620 return uxSemaphoreGetCount(sem->handle);
621}
622
623static inline int
624ble_npl_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq,
625 ble_npl_event_fn *ev_cb, void *ev_arg)
626{
627 return npl_freertos_callout_init(co, evq, ev_cb, ev_arg);
628}
629
630static inline void
631ble_npl_callout_deinit(struct ble_npl_callout *co)
632{
633 npl_freertos_callout_deinit(co);
634}
635
636static inline ble_npl_error_t
637ble_npl_callout_reset(struct ble_npl_callout *co, ble_npl_time_t ticks)
638{
639 return npl_freertos_callout_reset(co, ticks);
640}
641
642static inline void
643ble_npl_callout_stop(struct ble_npl_callout *co)
644{
645 npl_freertos_callout_stop(co);
646}
647
648static inline bool
649ble_npl_callout_is_active(struct ble_npl_callout *co)
650{
651 return npl_freertos_callout_is_active(co);
652}
653
654static inline ble_npl_time_t
655ble_npl_callout_get_ticks(struct ble_npl_callout *co)
656{
657 return npl_freertos_callout_get_ticks(co);
658}
659
660static inline uint32_t
661ble_npl_callout_remaining_ticks(struct ble_npl_callout *co,
662 ble_npl_time_t time)
663{
664 return npl_freertos_callout_remaining_ticks(co, time);
665}
666
667static inline void
668ble_npl_callout_set_arg(struct ble_npl_callout *co, void *arg)
669{
670 co->ev.arg = arg;
671}
672
673static inline uint32_t
674ble_npl_time_get(void)
675{
676 return xTaskGetTickCountFromISR();
677}
678
679static inline ble_npl_error_t
680ble_npl_time_ms_to_ticks(uint32_t ms, ble_npl_time_t *out_ticks)
681{
682 return npl_freertos_time_ms_to_ticks(ms, out_ticks);
683}
684
685static inline ble_npl_error_t
686ble_npl_time_ticks_to_ms(ble_npl_time_t ticks, uint32_t *out_ms)
687{
688 return ble_npl_time_ticks_to_ms(ticks, out_ms);
689}
690
691static inline ble_npl_time_t
692ble_npl_time_ms_to_ticks32(uint32_t ms)
693{
694 return ms * configTICK_RATE_HZ / 1000;
695}
696
697static inline uint32_t
698ble_npl_time_ticks_to_ms32(ble_npl_time_t ticks)
699{
700 return ticks * 1000 / configTICK_RATE_HZ;
701}
702
703static inline void
704ble_npl_time_delay(ble_npl_time_t ticks)
705{
706 vTaskDelay(ticks);
707}
708
709#if NIMBLE_CFG_CONTROLLER
710static inline void
711ble_npl_hw_set_isr(int irqn, void (*addr)(void))
712{
713 npl_freertos_hw_set_isr(irqn, addr);
714}
715
716static inline bool
717ble_npl_hw_is_in_critical(void)
718{
719 return (uxGetCriticalNestingDepth() > 0);
720}
721#endif
722
723#ifdef ESP_PLATFORM
724extern portMUX_TYPE ble_port_mutex;
725//critical section
726static inline uint32_t
727ble_npl_hw_enter_critical(void)
728{
729 portENTER_CRITICAL(&ble_port_mutex);
730 return 0;
731}
732
733static inline void
734ble_npl_hw_exit_critical(uint32_t ctx)
735{
736 portEXIT_CRITICAL(&ble_port_mutex);
737}
738
739#else
740static inline uint32_t
741ble_npl_hw_enter_critical(void)
742{
743 vPortEnterCritical();
744 return 0;
745}
746
747static inline void
748ble_npl_hw_exit_critical(uint32_t ctx)
749{
750 (void)ctx;
751 vPortExitCritical();
752}
753#endif
754
755#ifdef __cplusplus
756}
757#endif
758
759#endif // CONFIG_NIMBLE_STACK_USE_MEM_POOLS
760
761#endif /* _NPL_H_ */