Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

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 #include "mbed_rtos_storage.h"
00023 
00024 #include <stdbool.h>
00025 
00026 extern u8_t lwip_ram_heap[];
00027 
00028 #if NO_SYS == 0
00029 #include "cmsis_os2.h"
00030 
00031 // === SEMAPHORE ===
00032 typedef struct {
00033     osSemaphoreId_t               id;
00034     osSemaphoreAttr_t             attr;
00035     mbed_rtos_storage_semaphore_t data;
00036 } sys_sem_t;
00037 
00038 #define sys_sem_valid(x)        (((*x).id == NULL) ? 0 : 1)
00039 #define sys_sem_set_invalid(x)  ( (*x).id = NULL)
00040 
00041 // === MUTEX ===
00042 typedef struct {
00043     osMutexId_t               id;
00044     osMutexAttr_t             attr;
00045     mbed_rtos_storage_mutex_t data;
00046 } sys_mutex_t;
00047 
00048 // === MAIL BOX ===
00049 #define MB_SIZE      MBED_CONF_LWIP_MBOX_SIZE
00050 
00051 typedef struct {
00052     osEventFlagsId_t                id;
00053     osEventFlagsAttr_t              attr;
00054     mbed_rtos_storage_event_flags_t data;
00055 
00056     uint8_t     post_idx;
00057     uint8_t     fetch_idx;
00058     void*       queue[MB_SIZE];
00059 } sys_mbox_t;
00060 
00061 #define SYS_MBOX_FETCH_EVENT 0x1
00062 #define SYS_MBOX_POST_EVENT  0x2
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_t               id;
00079     osThreadAttr_t             attr;
00080     mbed_rtos_storage_thread_t data;
00081 } sys_thread_data_t;
00082 typedef sys_thread_data_t* sys_thread_t;
00083 
00084 #define SYS_THREAD_POOL_N                   6
00085 #define SYS_DEFAULT_THREAD_STACK_DEPTH      OS_STACK_SIZE
00086 
00087 // === PROTECTION ===
00088 typedef int sys_prot_t;
00089 
00090 void sys_tcpip_thread_set(void);
00091 bool sys_tcpip_thread_check(void);
00092 
00093 #else
00094 #ifdef  __cplusplus
00095 extern "C" {
00096 #endif
00097 
00098 /** \brief  Init systick to 1ms rate
00099  *
00100  *  This init the systick to 1ms rate. This function is only used in standalone
00101  *  systems.
00102  */
00103 void SysTick_Init(void);
00104 
00105 
00106 /** \brief  Get the current systick time in milliSeconds
00107  *
00108  *  Returns the current systick time in milliSeconds. This function is only
00109  *  used in standalone systems.
00110  *
00111  *  /returns current systick time in milliSeconds
00112  */
00113 uint32_t SysTick_GetMS(void);
00114 
00115 /** \brief  Delay for the specified number of milliSeconds
00116  *
00117  *  For standalone systems. This function will block for the specified
00118  *  number of milliSconds. For RTOS based systems, this function will delay
00119  *  the task by the specified number of milliSeconds.
00120  *
00121  *  \param[in]  ms Time in milliSeconds to delay
00122  */
00123 void osDelay(uint32_t ms);
00124 
00125 #ifdef  __cplusplus
00126 }
00127 #endif
00128 #endif
00129 
00130 #endif /* __ARCH_SYS_ARCH_H__ */