Control a robot over the internet using UDP and a Ethernet interface.

Dependencies:   EthernetInterface Motor TextLCD mbed-rtos mbed Socket lwip-eth lwip-sys lwip

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 #if NO_SYS == 0
00024 #include "cmsis_os.h"
00025 
00026 // === SEMAPHORE ===
00027 typedef struct {
00028     osSemaphoreId    id;
00029     osSemaphoreDef_t def;
00030 #ifdef CMSIS_OS_RTX
00031     uint32_t         data[2];
00032 #endif
00033 } sys_sem_t;
00034 
00035 #define sys_sem_valid(x)        (((*x).id == NULL) ? 0 : 1)
00036 #define sys_sem_set_invalid(x)  ( (*x).id = NULL)
00037 
00038 // === MUTEX ===
00039 typedef struct {
00040     osMutexId    id;
00041     osMutexDef_t def;
00042 #ifdef CMSIS_OS_RTX
00043     int32_t      data[3];
00044 #endif
00045 } sys_mutex_t;
00046 
00047 // === MAIL BOX ===
00048 #define MB_SIZE      8
00049 
00050 typedef struct {
00051     osMessageQId    id;
00052     osMessageQDef_t def;
00053 #ifdef CMSIS_OS_RTX
00054     uint32_t        queue[4+MB_SIZE]; /* The +4 is required for RTX OS_MCB overhead. */
00055 #endif
00056 } sys_mbox_t;
00057 
00058 #define SYS_MBOX_NULL               ((uint32_t) NULL)
00059 #define sys_mbox_valid(x)           (((*x).id == NULL) ? 0 : 1 )
00060 #define sys_mbox_set_invalid(x)     ( (*x).id = NULL )
00061 
00062 #if ((DEFAULT_RAW_RECVMBOX_SIZE) > (MB_SIZE)) || \
00063     ((DEFAULT_UDP_RECVMBOX_SIZE) > (MB_SIZE)) || \
00064     ((DEFAULT_TCP_RECVMBOX_SIZE) > (MB_SIZE)) || \
00065     ((DEFAULT_ACCEPTMBOX_SIZE)   > (MB_SIZE)) || \
00066     ((TCPIP_MBOX_SIZE)           > (MB_SIZE))
00067 #   error Mailbox size not supported
00068 #endif
00069 
00070 // === THREAD ===
00071 typedef struct {
00072     osThreadId    id;
00073     osThreadDef_t def;
00074 } sys_thread_data_t;
00075 typedef sys_thread_data_t* sys_thread_t;
00076 
00077 #define SYS_THREAD_POOL_N                   6
00078 #define SYS_DEFAULT_THREAD_STACK_DEPTH      DEFAULT_STACK_SIZE
00079 
00080 // === PROTECTION ===
00081 typedef int sys_prot_t;
00082 
00083 #else
00084 #ifdef  __cplusplus
00085 extern "C" {
00086 #endif
00087 
00088 /** \brief  Init systick to 1ms rate
00089  *
00090  *  This init the systick to 1ms rate. This function is only used in standalone
00091  *  systems.
00092  */
00093 void SysTick_Init(void);
00094 
00095 
00096 /** \brief  Get the current systick time in milliSeconds
00097  *
00098  *  Returns the current systick time in milliSeconds. This function is only
00099  *  used in standalone systems.
00100  *
00101  *  /returns current systick time in milliSeconds
00102  */
00103 uint32_t SysTick_GetMS(void);
00104 
00105 /** \brief  Delay for the specified number of milliSeconds
00106  *
00107  *  For standalone systems. This function will block for the specified
00108  *  number of milliSconds. For RTOS based systems, this function will delay
00109  *  the task by the specified number of milliSeconds.
00110  *
00111  *  \param[in]  ms Time in milliSeconds to delay
00112  */
00113 void osDelay(uint32_t ms);
00114 
00115 #ifdef  __cplusplus
00116 }
00117 #endif
00118 #endif
00119 
00120 #endif /* __ARCH_SYS_ARCH_H__ */