Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers lwip_sys.c Source File

lwip_sys.c

Go to the documentation of this file.
00001 /**
00002  * @file
00003  * lwIP Operating System abstraction
00004  *
00005  */
00006 
00007 /*
00008  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
00009  * All rights reserved.
00010  *
00011  * Redistribution and use in source and binary forms, with or without modification,
00012  * are permitted provided that the following conditions are met:
00013  *
00014  * 1. Redistributions of source code must retain the above copyright notice,
00015  *    this list of conditions and the following disclaimer.
00016  * 2. Redistributions in binary form must reproduce the above copyright notice,
00017  *    this list of conditions and the following disclaimer in the documentation
00018  *    and/or other materials provided with the distribution.
00019  * 3. The name of the author may not be used to endorse or promote products
00020  *    derived from this software without specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
00023  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00024  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
00025  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00026  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00027  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00028  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00029  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
00030  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
00031  * OF SUCH DAMAGE.
00032  *
00033  * This file is part of the lwIP TCP/IP stack.
00034  *
00035  * Author: Adam Dunkels <adam@sics.se>
00036  *
00037  */
00038 
00039 /**
00040  * @defgroup sys_layer Porting (system abstraction layer)
00041  * @ingroup lwip
00042  *
00043  * @defgroup sys_os OS abstraction layer
00044  * @ingroup sys_layer
00045  * No need to implement functions in this section in NO_SYS mode.
00046  * The OS-specific code should be implemented in arch/sys_arch.h
00047  * and sys_arch.c of your port.
00048  * 
00049  * The operating system emulation layer provides a common interface
00050  * between the lwIP code and the underlying operating system kernel. The
00051  * general idea is that porting lwIP to new architectures requires only
00052  * small changes to a few header files and a new sys_arch
00053  * implementation. It is also possible to do a sys_arch implementation
00054  * that does not rely on any underlying operating system.
00055  * 
00056  * The sys_arch provides semaphores, mailboxes and mutexes to lwIP. For the full
00057  * lwIP functionality, multiple threads support can be implemented in the
00058  * sys_arch, but this is not required for the basic lwIP
00059  * functionality. Timer scheduling is implemented in lwIP, but can be implemented
00060  * by the sys_arch port (LWIP_TIMERS_CUSTOM==1).
00061  * 
00062  * In addition to the source file providing the functionality of sys_arch,
00063  * the OS emulation layer must provide several header files defining
00064  * macros used throughout lwip.  The files required and the macros they
00065  * must define are listed below the sys_arch description.
00066  * 
00067  * Since lwIP 1.4.0, semaphore, mutexes and mailbox functions are prototyped in a way that
00068  * allows both using pointers or actual OS structures to be used. This way, memory
00069  * required for such types can be either allocated in place (globally or on the
00070  * stack) or on the heap (allocated internally in the "*_new()" functions).
00071  * 
00072  * Note:
00073  * -----
00074  * Be careful with using mem_malloc() in sys_arch. When malloc() refers to
00075  * mem_malloc() you can run into a circular function call problem. In mem.c
00076  * mem_init() tries to allocate a semaphore using mem_malloc, which of course
00077  * can't be performed when sys_arch uses mem_malloc.
00078  *
00079  * @defgroup sys_sem Semaphores
00080  * @ingroup sys_os
00081  * Semaphores can be either counting or binary - lwIP works with both
00082  * kinds.
00083  * Semaphores are represented by the type "sys_sem_t" which is typedef'd
00084  * in the sys_arch.h file. Mailboxes are equivalently represented by the
00085  * type "sys_mbox_t". Mutexes are represented by the type "sys_mutex_t".
00086  * lwIP does not place any restrictions on how these types are represented
00087  * internally.
00088  *
00089  * @defgroup sys_mutex Mutexes
00090  * @ingroup sys_os
00091  * Mutexes are recommended to correctly handle priority inversion,
00092  * especially if you use LWIP_CORE_LOCKING .
00093  *
00094  * @defgroup sys_mbox Mailboxes
00095  * @ingroup sys_os
00096  * Mailboxes should be implemented as a queue which allows multiple messages
00097  * to be posted (implementing as a rendez-vous point where only one message can be
00098  * posted at a time can have a highly negative impact on performance). A message
00099  * in a mailbox is just a pointer, nothing more. 
00100  *
00101  * @defgroup sys_time Time
00102  * @ingroup sys_layer
00103  *
00104  * @defgroup sys_prot Critical sections
00105  * @ingroup sys_layer
00106  * Used to protect short regions of code against concurrent access.
00107  * - Your system is a bare-metal system (probably with an RTOS)
00108  *   and interrupts are under your control:
00109  *   Implement this as LockInterrupts() / UnlockInterrupts()
00110  * - Your system uses an RTOS with deferred interrupt handling from a
00111  *   worker thread: Implement as a global mutex or lock/unlock scheduler
00112  * - Your system uses a high-level OS with e.g. POSIX signals:
00113  *   Implement as a global mutex
00114  *
00115  * @defgroup sys_misc Misc
00116  * @ingroup sys_os
00117  */
00118 
00119 #include "lwip/opt.h"
00120 
00121 #include "lwip/sys.h"
00122 
00123 /* Most of the functions defined in sys.h must be implemented in the
00124  * architecture-dependent file sys_arch.c */
00125 
00126 #if !NO_SYS
00127 
00128 #ifndef sys_msleep
00129 /**
00130  * Sleep for some ms. Timeouts are NOT processed while sleeping.
00131  *
00132  * @param ms number of milliseconds to sleep
00133  */
00134 void
00135 sys_msleep(u32_t ms)
00136 {
00137   if (ms > 0) {
00138     sys_sem_t delaysem;
00139     err_t err = sys_sem_new(&delaysem, 0);
00140     if (err == ERR_OK) {
00141       sys_arch_sem_wait(&delaysem, ms);
00142       sys_sem_free(&delaysem);
00143     }
00144   }
00145 }
00146 #endif /* sys_msleep */
00147 
00148 #endif /* !NO_SYS */