Simon Cooksey / mbed-os
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers sys_arch.h Source File

sys_arch.h

00001 /* Copyright (C) 2012 mbed.org, MIT License
00002  *
00003  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
00004  * and associated documentation files (the "Software"), to deal in the Software without restriction,
00005  * including without limitation the rights to use, copy, modify, merge, publish, distribute,
00006  * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
00007  * furnished to do so, subject to the following conditions:
00008  *
00009  * The above copyright notice and this permission notice shall be included in all copies or
00010  * substantial portions of the Software.
00011  *
00012  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
00013  * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00014  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
00015  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00016  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00017  */
00018 #ifndef __ARCH_SYS_ARCH_H__
00019 #define __ARCH_SYS_ARCH_H__
00020 
00021 #include "lwip/opt.h"
00022 
00023 extern u8_t lwip_ram_heap[];
00024 
00025 #if NO_SYS == 0
00026 #include "cmsis_os.h"
00027 
00028 // === SEMAPHORE ===
00029 typedef struct {
00030     osSemaphoreId    id;
00031     osSemaphoreDef_t def;
00032 #ifdef CMSIS_OS_RTX
00033     uint32_t         data[2];
00034 #endif
00035 } sys_sem_t;
00036 
00037 #define sys_sem_valid(x)        (((*x).id == NULL) ? 0 : 1)
00038 #define sys_sem_set_invalid(x)  ( (*x).id = NULL)
00039 
00040 // === MUTEX ===
00041 typedef struct {
00042     osMutexId    id;
00043     osMutexDef_t def;
00044 #ifdef CMSIS_OS_RTX
00045 #if defined(__MBED_CMSIS_RTOS_CA9) || defined(__MBED_CMSIS_RTOS_CM)
00046     int32_t      data[4];
00047 #else
00048     int32_t      data[3];
00049 #endif
00050 #endif
00051 } sys_mutex_t;
00052 
00053 // === MAIL BOX ===
00054 #define MB_SIZE      8
00055 
00056 typedef struct {
00057     osMessageQId    id;
00058     osMessageQDef_t def;
00059 #ifdef CMSIS_OS_RTX
00060     uint32_t        queue[4+MB_SIZE]; /* The +4 is required for RTX OS_MCB overhead. */
00061 #endif
00062 } sys_mbox_t;
00063 
00064 #define SYS_MBOX_NULL               ((uint32_t) NULL)
00065 #define sys_mbox_valid(x)           (((*x).id == NULL) ? 0 : 1 )
00066 #define sys_mbox_set_invalid(x)     ( (*x).id = NULL )
00067 
00068 #if ((DEFAULT_RAW_RECVMBOX_SIZE) > (MB_SIZE)) || \
00069     ((DEFAULT_UDP_RECVMBOX_SIZE) > (MB_SIZE)) || \
00070     ((DEFAULT_TCP_RECVMBOX_SIZE) > (MB_SIZE)) || \
00071     ((DEFAULT_ACCEPTMBOX_SIZE)   > (MB_SIZE)) || \
00072     ((TCPIP_MBOX_SIZE)           > (MB_SIZE))
00073 #   error Mailbox size not supported
00074 #endif
00075 
00076 // === THREAD ===
00077 typedef struct {
00078     osThreadId    id;
00079     osThreadDef_t def;
00080 } sys_thread_data_t;
00081 typedef sys_thread_data_t* sys_thread_t;
00082 
00083 #define SYS_THREAD_POOL_N                   6
00084 #define SYS_DEFAULT_THREAD_STACK_DEPTH      DEFAULT_STACK_SIZE
00085 
00086 // === PROTECTION ===
00087 typedef int sys_prot_t;
00088 
00089 #else
00090 #ifdef  __cplusplus
00091 extern "C" {
00092 #endif
00093 
00094 /** \brief  Init systick to 1ms rate
00095  *
00096  *  This init the systick to 1ms rate. This function is only used in standalone
00097  *  systems.
00098  */
00099 void SysTick_Init(void);
00100 
00101 
00102 /** \brief  Get the current systick time in milliSeconds
00103  *
00104  *  Returns the current systick time in milliSeconds. This function is only
00105  *  used in standalone systems.
00106  *
00107  *  /returns current systick time in milliSeconds
00108  */
00109 uint32_t SysTick_GetMS(void);
00110 
00111 /** \brief  Delay for the specified number of milliSeconds
00112  *
00113  *  For standalone systems. This function will block for the specified
00114  *  number of milliSconds. For RTOS based systems, this function will delay
00115  *  the task by the specified number of milliSeconds.
00116  *
00117  *  \param[in]  ms Time in milliSeconds to delay
00118  */
00119 void osDelay(uint32_t ms);
00120 
00121 #ifdef  __cplusplus
00122 }
00123 #endif
00124 #endif
00125 
00126 #endif /* __ARCH_SYS_ARCH_H__ */