source: azure_iot_hub_f767zi/trunk/asp_baseplatform/lwip/contrib-2.1.0/ports/freertos/sys_arch.c@ 457

Last change on this file since 457 was 457, checked in by coas-nagasima, 4 years ago

ファイルを追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc;charset=UTF-8
File size: 16.6 KB
Line 
1/*
2 * Copyright (c) 2017 Simon Goldschmidt
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
25 * OF SUCH DAMAGE.
26 *
27 * This file is part of the lwIP TCP/IP stack.
28 *
29 * Author: Simon Goldschmidt <goldsimon@gmx.de>
30 *
31 */
32
33/* lwIP includes. */
34#include "lwip/debug.h"
35#include "lwip/def.h"
36#include "lwip/sys.h"
37#include "lwip/mem.h"
38#include "lwip/stats.h"
39#include "FreeRTOS.h"
40#include "semphr.h"
41#include "task.h"
42
43/** Set this to 1 if you want the stack size passed to sys_thread_new() to be
44 * interpreted as number of stack words (FreeRTOS-like).
45 * Default is that they are interpreted as byte count (lwIP-like).
46 */
47#ifndef LWIP_FREERTOS_THREAD_STACKSIZE_IS_STACKWORDS
48#define LWIP_FREERTOS_THREAD_STACKSIZE_IS_STACKWORDS 0
49#endif
50
51/** Set this to 1 to use a mutex for SYS_ARCH_PROTECT() critical regions.
52 * Default is 0 and locks interrupts/scheduler for SYS_ARCH_PROTECT().
53 */
54#ifndef LWIP_FREERTOS_SYS_ARCH_PROTECT_USES_MUTEX
55#define LWIP_FREERTOS_SYS_ARCH_PROTECT_USES_MUTEX 0
56#endif
57
58/** Set this to 1 to include a sanity check that SYS_ARCH_PROTECT() and
59 * SYS_ARCH_UNPROTECT() are called matching.
60 */
61#ifndef LWIP_FREERTOS_SYS_ARCH_PROTECT_SANITY_CHECK
62#define LWIP_FREERTOS_SYS_ARCH_PROTECT_SANITY_CHECK 0
63#endif
64
65/** Set this to 1 to let sys_mbox_free check that queues are empty when freed */
66#ifndef LWIP_FREERTOS_CHECK_QUEUE_EMPTY_ON_FREE
67#define LWIP_FREERTOS_CHECK_QUEUE_EMPTY_ON_FREE 0
68#endif
69
70/** Set this to 1 to enable core locking check functions in this port.
71 * For this to work, you'll have to define LWIP_ASSERT_CORE_LOCKED()
72 * and LWIP_MARK_TCPIP_THREAD() correctly in your lwipopts.h! */
73#ifndef LWIP_FREERTOS_CHECK_CORE_LOCKING
74#define LWIP_FREERTOS_CHECK_CORE_LOCKING 0
75#endif
76
77/** Set this to 0 to implement sys_now() yourself, e.g. using a hw timer.
78 * Default is 1, where FreeRTOS ticks are used to calculate back to ms.
79 */
80#ifndef LWIP_FREERTOS_SYS_NOW_FROM_FREERTOS
81#define LWIP_FREERTOS_SYS_NOW_FROM_FREERTOS 1
82#endif
83
84#if !configSUPPORT_DYNAMIC_ALLOCATION
85# error "lwIP FreeRTOS port requires configSUPPORT_DYNAMIC_ALLOCATION"
86#endif
87#if !INCLUDE_vTaskDelay
88# error "lwIP FreeRTOS port requires INCLUDE_vTaskDelay"
89#endif
90#if !INCLUDE_vTaskSuspend
91# error "lwIP FreeRTOS port requires INCLUDE_vTaskSuspend"
92#endif
93#if LWIP_FREERTOS_SYS_ARCH_PROTECT_USES_MUTEX || !LWIP_COMPAT_MUTEX
94#if !configUSE_MUTEXES
95# error "lwIP FreeRTOS port requires configUSE_MUTEXES"
96#endif
97#endif
98
99#if SYS_LIGHTWEIGHT_PROT && LWIP_FREERTOS_SYS_ARCH_PROTECT_USES_MUTEX
100static SemaphoreHandle_t sys_arch_protect_mutex;
101#endif
102#if SYS_LIGHTWEIGHT_PROT && LWIP_FREERTOS_SYS_ARCH_PROTECT_SANITY_CHECK
103static sys_prot_t sys_arch_protect_nesting;
104#endif
105
106/* Initialize this module (see description in sys.h) */
107void
108sys_init(void)
109{
110#if SYS_LIGHTWEIGHT_PROT && LWIP_FREERTOS_SYS_ARCH_PROTECT_USES_MUTEX
111 /* initialize sys_arch_protect global mutex */
112 sys_arch_protect_mutex = xSemaphoreCreateRecursiveMutex();
113 LWIP_ASSERT("failed to create sys_arch_protect mutex",
114 sys_arch_protect_mutex != NULL);
115#endif /* SYS_LIGHTWEIGHT_PROT && LWIP_FREERTOS_SYS_ARCH_PROTECT_USES_MUTEX */
116}
117
118#if configUSE_16_BIT_TICKS == 1
119#error This port requires 32 bit ticks or timer overflow will fail
120#endif
121
122#if LWIP_FREERTOS_SYS_NOW_FROM_FREERTOS
123u32_t
124sys_now(void)
125{
126 return xTaskGetTickCount() * portTICK_PERIOD_MS;
127}
128#endif
129
130u32_t
131sys_jiffies(void)
132{
133 return xTaskGetTickCount();
134}
135
136#if SYS_LIGHTWEIGHT_PROT
137
138sys_prot_t
139sys_arch_protect(void)
140{
141#if LWIP_FREERTOS_SYS_ARCH_PROTECT_USES_MUTEX
142 BaseType_t ret;
143 LWIP_ASSERT("sys_arch_protect_mutex != NULL", sys_arch_protect_mutex != NULL);
144
145 ret = xSemaphoreTakeRecursive(sys_arch_protect_mutex, portMAX_DELAY);
146 LWIP_ASSERT("sys_arch_protect failed to take the mutex", ret == pdTRUE);
147#else /* LWIP_FREERTOS_SYS_ARCH_PROTECT_USES_MUTEX */
148 taskENTER_CRITICAL();
149#endif /* LWIP_FREERTOS_SYS_ARCH_PROTECT_USES_MUTEX */
150#if LWIP_FREERTOS_SYS_ARCH_PROTECT_SANITY_CHECK
151 {
152 /* every nested call to sys_arch_protect() returns an increased number */
153 sys_prot_t ret = sys_arch_protect_nesting;
154 sys_arch_protect_nesting++;
155 LWIP_ASSERT("sys_arch_protect overflow", sys_arch_protect_nesting > ret);
156 return ret;
157 }
158#else
159 return 1;
160#endif
161}
162
163void
164sys_arch_unprotect(sys_prot_t pval)
165{
166#if LWIP_FREERTOS_SYS_ARCH_PROTECT_USES_MUTEX
167 BaseType_t ret;
168#endif
169#if LWIP_FREERTOS_SYS_ARCH_PROTECT_SANITY_CHECK
170 LWIP_ASSERT("unexpected sys_arch_protect_nesting", sys_arch_protect_nesting > 0);
171 sys_arch_protect_nesting--;
172 LWIP_ASSERT("unexpected sys_arch_protect_nesting", sys_arch_protect_nesting == pval);
173#endif
174
175#if LWIP_FREERTOS_SYS_ARCH_PROTECT_USES_MUTEX
176 LWIP_ASSERT("sys_arch_protect_mutex != NULL", sys_arch_protect_mutex != NULL);
177
178 ret = xSemaphoreGiveRecursive(sys_arch_protect_mutex);
179 LWIP_ASSERT("sys_arch_unprotect failed to give the mutex", ret == pdTRUE);
180#else /* LWIP_FREERTOS_SYS_ARCH_PROTECT_USES_MUTEX */
181 taskEXIT_CRITICAL();
182#endif /* LWIP_FREERTOS_SYS_ARCH_PROTECT_USES_MUTEX */
183 LWIP_UNUSED_ARG(pval);
184}
185
186#endif /* SYS_LIGHTWEIGHT_PROT */
187
188void
189sys_arch_msleep(u32_t delay_ms)
190{
191 TickType_t delay_ticks = delay_ms / portTICK_RATE_MS;
192 vTaskDelay(delay_ticks);
193}
194
195#if !LWIP_COMPAT_MUTEX
196
197/* Create a new mutex*/
198err_t
199sys_mutex_new(sys_mutex_t *mutex)
200{
201 LWIP_ASSERT("mutex != NULL", mutex != NULL);
202
203 mutex->mut = xSemaphoreCreateRecursiveMutex();
204 if(mutex->mut == NULL) {
205 SYS_STATS_INC(mutex.err);
206 return ERR_MEM;
207 }
208 SYS_STATS_INC_USED(mutex);
209 return ERR_OK;
210}
211
212void
213sys_mutex_lock(sys_mutex_t *mutex)
214{
215 BaseType_t ret;
216 LWIP_ASSERT("mutex != NULL", mutex != NULL);
217 LWIP_ASSERT("mutex->mut != NULL", mutex->mut != NULL);
218
219 ret = xSemaphoreTakeRecursive(mutex->mut, portMAX_DELAY);
220 LWIP_ASSERT("failed to take the mutex", ret == pdTRUE);
221}
222
223void
224sys_mutex_unlock(sys_mutex_t *mutex)
225{
226 BaseType_t ret;
227 LWIP_ASSERT("mutex != NULL", mutex != NULL);
228 LWIP_ASSERT("mutex->mut != NULL", mutex->mut != NULL);
229
230 ret = xSemaphoreGiveRecursive(mutex->mut);
231 LWIP_ASSERT("failed to give the mutex", ret == pdTRUE);
232}
233
234void
235sys_mutex_free(sys_mutex_t *mutex)
236{
237 LWIP_ASSERT("mutex != NULL", mutex != NULL);
238 LWIP_ASSERT("mutex->mut != NULL", mutex->mut != NULL);
239
240 SYS_STATS_DEC(mutex.used);
241 vSemaphoreDelete(mutex->mut);
242 mutex->mut = NULL;
243}
244
245#endif /* !LWIP_COMPAT_MUTEX */
246
247err_t
248sys_sem_new(sys_sem_t *sem, u8_t initial_count)
249{
250 LWIP_ASSERT("sem != NULL", sem != NULL);
251 LWIP_ASSERT("initial_count invalid (not 0 or 1)",
252 (initial_count == 0) || (initial_count == 1));
253
254 sem->sem = xSemaphoreCreateBinary();
255 if(sem->sem == NULL) {
256 SYS_STATS_INC(sem.err);
257 return ERR_MEM;
258 }
259 SYS_STATS_INC_USED(sem);
260
261 if(initial_count == 1) {
262 BaseType_t ret = xSemaphoreGive(sem->sem);
263 LWIP_ASSERT("sys_sem_new: initial give failed", ret == pdTRUE);
264 }
265 return ERR_OK;
266}
267
268void
269sys_sem_signal(sys_sem_t *sem)
270{
271 BaseType_t ret;
272 LWIP_ASSERT("sem != NULL", sem != NULL);
273 LWIP_ASSERT("sem->sem != NULL", sem->sem != NULL);
274
275 ret = xSemaphoreGive(sem->sem);
276 /* queue full is OK, this is a signal only... */
277 LWIP_ASSERT("sys_sem_signal: sane return value",
278 (ret == pdTRUE) || (ret == errQUEUE_FULL));
279}
280
281u32_t
282sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout_ms)
283{
284 BaseType_t ret;
285 LWIP_ASSERT("sem != NULL", sem != NULL);
286 LWIP_ASSERT("sem->sem != NULL", sem->sem != NULL);
287
288 if(!timeout_ms) {
289 /* wait infinite */
290 ret = xSemaphoreTake(sem->sem, portMAX_DELAY);
291 LWIP_ASSERT("taking semaphore failed", ret == pdTRUE);
292 } else {
293 TickType_t timeout_ticks = timeout_ms / portTICK_RATE_MS;
294 ret = xSemaphoreTake(sem->sem, timeout_ticks);
295 if (ret == errQUEUE_EMPTY) {
296 /* timed out */
297 return SYS_ARCH_TIMEOUT;
298 }
299 LWIP_ASSERT("taking semaphore failed", ret == pdTRUE);
300 }
301
302 /* Old versions of lwIP required us to return the time waited.
303 This is not the case any more. Just returning != SYS_ARCH_TIMEOUT
304 here is enough. */
305 return 1;
306}
307
308void
309sys_sem_free(sys_sem_t *sem)
310{
311 LWIP_ASSERT("sem != NULL", sem != NULL);
312 LWIP_ASSERT("sem->sem != NULL", sem->sem != NULL);
313
314 SYS_STATS_DEC(sem.used);
315 vSemaphoreDelete(sem->sem);
316 sem->sem = NULL;
317}
318
319err_t
320sys_mbox_new(sys_mbox_t *mbox, int size)
321{
322 LWIP_ASSERT("mbox != NULL", mbox != NULL);
323 LWIP_ASSERT("size > 0", size > 0);
324
325 mbox->mbx = xQueueCreate((UBaseType_t)size, sizeof(void *));
326 if(mbox->mbx == NULL) {
327 SYS_STATS_INC(mbox.err);
328 return ERR_MEM;
329 }
330 SYS_STATS_INC_USED(mbox);
331 return ERR_OK;
332}
333
334void
335sys_mbox_post(sys_mbox_t *mbox, void *msg)
336{
337 BaseType_t ret;
338 LWIP_ASSERT("mbox != NULL", mbox != NULL);
339 LWIP_ASSERT("mbox->mbx != NULL", mbox->mbx != NULL);
340
341 ret = xQueueSendToBack(mbox->mbx, &msg, portMAX_DELAY);
342 LWIP_ASSERT("mbox post failed", ret == pdTRUE);
343}
344
345err_t
346sys_mbox_trypost(sys_mbox_t *mbox, void *msg)
347{
348 BaseType_t ret;
349 LWIP_ASSERT("mbox != NULL", mbox != NULL);
350 LWIP_ASSERT("mbox->mbx != NULL", mbox->mbx != NULL);
351
352 ret = xQueueSendToBack(mbox->mbx, &msg, 0);
353 if (ret == pdTRUE) {
354 return ERR_OK;
355 } else {
356 LWIP_ASSERT("mbox trypost failed", ret == errQUEUE_FULL);
357 SYS_STATS_INC(mbox.err);
358 return ERR_MEM;
359 }
360}
361
362err_t
363sys_mbox_trypost_fromisr(sys_mbox_t *mbox, void *msg)
364{
365 BaseType_t ret;
366 BaseType_t xHigherPriorityTaskWoken = pdFALSE;
367 LWIP_ASSERT("mbox != NULL", mbox != NULL);
368 LWIP_ASSERT("mbox->mbx != NULL", mbox->mbx != NULL);
369
370 ret = xQueueSendToBackFromISR(mbox->mbx, &msg, &xHigherPriorityTaskWoken);
371 if (ret == pdTRUE) {
372 if (xHigherPriorityTaskWoken == pdTRUE) {
373 return ERR_NEED_SCHED;
374 }
375 return ERR_OK;
376 } else {
377 LWIP_ASSERT("mbox trypost failed", ret == errQUEUE_FULL);
378 SYS_STATS_INC(mbox.err);
379 return ERR_MEM;
380 }
381}
382
383u32_t
384sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout_ms)
385{
386 BaseType_t ret;
387 void *msg_dummy;
388 LWIP_ASSERT("mbox != NULL", mbox != NULL);
389 LWIP_ASSERT("mbox->mbx != NULL", mbox->mbx != NULL);
390
391 if (!msg) {
392 msg = &msg_dummy;
393 }
394
395 if (!timeout_ms) {
396 /* wait infinite */
397 ret = xQueueReceive(mbox->mbx, &(*msg), portMAX_DELAY);
398 LWIP_ASSERT("mbox fetch failed", ret == pdTRUE);
399 } else {
400 TickType_t timeout_ticks = timeout_ms / portTICK_RATE_MS;
401 ret = xQueueReceive(mbox->mbx, &(*msg), timeout_ticks);
402 if (ret == errQUEUE_EMPTY) {
403 /* timed out */
404 *msg = NULL;
405 return SYS_ARCH_TIMEOUT;
406 }
407 LWIP_ASSERT("mbox fetch failed", ret == pdTRUE);
408 }
409
410 /* Old versions of lwIP required us to return the time waited.
411 This is not the case any more. Just returning != SYS_ARCH_TIMEOUT
412 here is enough. */
413 return 1;
414}
415
416u32_t
417sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg)
418{
419 BaseType_t ret;
420 void *msg_dummy;
421 LWIP_ASSERT("mbox != NULL", mbox != NULL);
422 LWIP_ASSERT("mbox->mbx != NULL", mbox->mbx != NULL);
423
424 if (!msg) {
425 msg = &msg_dummy;
426 }
427
428 ret = xQueueReceive(mbox->mbx, &(*msg), 0);
429 if (ret == errQUEUE_EMPTY) {
430 *msg = NULL;
431 return SYS_MBOX_EMPTY;
432 }
433 LWIP_ASSERT("mbox fetch failed", ret == pdTRUE);
434
435 /* Old versions of lwIP required us to return the time waited.
436 This is not the case any more. Just returning != SYS_ARCH_TIMEOUT
437 here is enough. */
438 return 1;
439}
440
441void
442sys_mbox_free(sys_mbox_t *mbox)
443{
444 LWIP_ASSERT("mbox != NULL", mbox != NULL);
445 LWIP_ASSERT("mbox->mbx != NULL", mbox->mbx != NULL);
446
447#if LWIP_FREERTOS_CHECK_QUEUE_EMPTY_ON_FREE
448 {
449 UBaseType_t msgs_waiting = uxQueueMessagesWaiting(mbox->mbx);
450 LWIP_ASSERT("mbox quence not empty", msgs_waiting == 0);
451
452 if (msgs_waiting != 0) {
453 SYS_STATS_INC(mbox.err);
454 }
455 }
456#endif
457
458 vQueueDelete(mbox->mbx);
459
460 SYS_STATS_DEC(mbox.used);
461}
462
463sys_thread_t
464sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stacksize, int prio)
465{
466 TaskHandle_t rtos_task;
467 BaseType_t ret;
468 sys_thread_t lwip_thread;
469 size_t rtos_stacksize;
470
471 LWIP_ASSERT("invalid stacksize", stacksize > 0);
472#if LWIP_FREERTOS_THREAD_STACKSIZE_IS_STACKWORDS
473 rtos_stacksize = (size_t)stacksize;
474#else
475 rtos_stacksize = (size_t)stacksize / sizeof(StackType_t);
476#endif
477
478 /* lwIP's lwip_thread_fn matches FreeRTOS' TaskFunction_t, so we can pass the
479 thread function without adaption here. */
480 ret = xTaskCreate(thread, name, (configSTACK_DEPTH_TYPE)rtos_stacksize, arg, prio, &rtos_task);
481 LWIP_ASSERT("task creation failed", ret == pdTRUE);
482
483 lwip_thread.thread_handle = rtos_task;
484 return lwip_thread;
485}
486
487#if LWIP_NETCONN_SEM_PER_THREAD
488#if configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0
489
490sys_sem_t *
491sys_arch_netconn_sem_get(void)
492{
493 void* ret;
494 TaskHandle_t task = xTaskGetCurrentTaskHandle();
495 LWIP_ASSERT("task != NULL", task != NULL);
496
497 ret = pvTaskGetThreadLocalStoragePointer(task, 0);
498 return ret;
499}
500
501void
502sys_arch_netconn_sem_alloc(void)
503{
504 void *ret;
505 TaskHandle_t task = xTaskGetCurrentTaskHandle();
506 LWIP_ASSERT("task != NULL", task != NULL);
507
508 ret = pvTaskGetThreadLocalStoragePointer(task, 0);
509 if(ret == NULL) {
510 sys_sem_t *sem;
511 err_t err;
512 /* need to allocate the memory for this semaphore */
513 sem = mem_malloc(sizeof(sys_sem_t));
514 LWIP_ASSERT("sem != NULL", sem != NULL);
515 err = sys_sem_new(sem, 0);
516 LWIP_ASSERT("err == ERR_OK", err == ERR_OK);
517 LWIP_ASSERT("sem invalid", sys_sem_valid(sem));
518 vTaskSetThreadLocalStoragePointer(task, 0, sem);
519 }
520}
521
522void sys_arch_netconn_sem_free(void)
523{
524 void* ret;
525 TaskHandle_t task = xTaskGetCurrentTaskHandle();
526 LWIP_ASSERT("task != NULL", task != NULL);
527
528 ret = pvTaskGetThreadLocalStoragePointer(task, 0);
529 if(ret != NULL) {
530 sys_sem_t *sem = ret;
531 sys_sem_free(sem);
532 mem_free(sem);
533 vTaskSetThreadLocalStoragePointer(task, 0, NULL);
534 }
535}
536
537#else /* configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 */
538#error LWIP_NETCONN_SEM_PER_THREAD needs configNUM_THREAD_LOCAL_STORAGE_POINTERS
539#endif /* configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 */
540
541#endif /* LWIP_NETCONN_SEM_PER_THREAD */
542
543#if LWIP_FREERTOS_CHECK_CORE_LOCKING
544#if LWIP_TCPIP_CORE_LOCKING
545
546/** Flag the core lock held. A counter for recursive locks. */
547static u8_t lwip_core_lock_count;
548static TaskHandle_t lwip_core_lock_holder_thread;
549
550void
551sys_lock_tcpip_core(void)
552{
553 sys_mutex_lock(&lock_tcpip_core);
554 if (lwip_core_lock_count == 0) {
555 lwip_core_lock_holder_thread = xTaskGetCurrentTaskHandle();
556 }
557 lwip_core_lock_count++;
558}
559
560void
561sys_unlock_tcpip_core(void)
562{
563 lwip_core_lock_count--;
564 if (lwip_core_lock_count == 0) {
565 lwip_core_lock_holder_thread = 0;
566 }
567 sys_mutex_unlock(&lock_tcpip_core);
568}
569
570#endif /* LWIP_TCPIP_CORE_LOCKING */
571
572#if !NO_SYS
573static TaskHandle_t lwip_tcpip_thread;
574#endif
575
576void
577sys_mark_tcpip_thread(void)
578{
579#if !NO_SYS
580 lwip_tcpip_thread = xTaskGetCurrentTaskHandle();
581#endif
582}
583
584void
585sys_check_core_locking(void)
586{
587 /* Embedded systems should check we are NOT in an interrupt context here */
588 /* E.g. core Cortex-M3/M4 ports:
589 configASSERT( ( portNVIC_INT_CTRL_REG & portVECTACTIVE_MASK ) == 0 );
590
591 Instead, we use more generic FreeRTOS functions here, which should fail from ISR: */
592 taskENTER_CRITICAL();
593 taskEXIT_CRITICAL();
594
595#if !NO_SYS
596 if (lwip_tcpip_thread != 0) {
597 TaskHandle_t current_thread = xTaskGetCurrentTaskHandle();
598
599#if LWIP_TCPIP_CORE_LOCKING
600 LWIP_ASSERT("Function called without core lock",
601 current_thread == lwip_core_lock_holder_thread && lwip_core_lock_count > 0);
602#else /* LWIP_TCPIP_CORE_LOCKING */
603 LWIP_ASSERT("Function called from wrong thread", current_thread == lwip_tcpip_thread);
604#endif /* LWIP_TCPIP_CORE_LOCKING */
605 }
606#endif /* !NO_SYS */
607}
608
609#endif /* LWIP_FREERTOS_CHECK_CORE_LOCKING*/
Note: See TracBrowser for help on using the repository browser.