lwip-sys with changes
Fork of lwip-sys by
arch/sys_arch.h@1:a7366e261ca3, 2012-06-22 (annotated)
- Committer:
- emilmont
- Date:
- Fri Jun 22 11:12:52 2012 +0000
- Revision:
- 1:a7366e261ca3
- Parent:
- 0:762278923909
- Child:
- 8:742ae4a0ca3f
First lwip operating system implementation based on CMIS-RTOS
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 1:a7366e261ca3 | 1 | /* Copyright (C) 2012 mbed.org, MIT License |
emilmont | 1:a7366e261ca3 | 2 | * |
emilmont | 1:a7366e261ca3 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
emilmont | 1:a7366e261ca3 | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
emilmont | 1:a7366e261ca3 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
emilmont | 1:a7366e261ca3 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
emilmont | 1:a7366e261ca3 | 7 | * furnished to do so, subject to the following conditions: |
emilmont | 1:a7366e261ca3 | 8 | * |
emilmont | 1:a7366e261ca3 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
emilmont | 1:a7366e261ca3 | 10 | * substantial portions of the Software. |
emilmont | 1:a7366e261ca3 | 11 | * |
emilmont | 1:a7366e261ca3 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
emilmont | 1:a7366e261ca3 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
emilmont | 1:a7366e261ca3 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
emilmont | 1:a7366e261ca3 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
emilmont | 1:a7366e261ca3 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
emilmont | 1:a7366e261ca3 | 17 | */ |
emilmont | 1:a7366e261ca3 | 18 | #ifndef __ARCH_SYS_ARCH_H__ |
emilmont | 1:a7366e261ca3 | 19 | #define __ARCH_SYS_ARCH_H__ |
emilmont | 1:a7366e261ca3 | 20 | |
emilmont | 1:a7366e261ca3 | 21 | #include "lwip/opt.h" |
emilmont | 1:a7366e261ca3 | 22 | |
emilmont | 1:a7366e261ca3 | 23 | #if NO_SYS == 0 |
emilmont | 1:a7366e261ca3 | 24 | #include "cmsis_os.h" |
emilmont | 1:a7366e261ca3 | 25 | |
emilmont | 1:a7366e261ca3 | 26 | // === SEMAPHORE === |
emilmont | 1:a7366e261ca3 | 27 | typedef struct { |
emilmont | 1:a7366e261ca3 | 28 | osSemaphoreId id; |
emilmont | 1:a7366e261ca3 | 29 | osSemaphoreDef_t def; |
emilmont | 1:a7366e261ca3 | 30 | #ifdef CMSIS_OS_RTX |
emilmont | 1:a7366e261ca3 | 31 | uint32_t data[2]; |
emilmont | 1:a7366e261ca3 | 32 | #endif |
emilmont | 1:a7366e261ca3 | 33 | } sys_sem_t; |
emilmont | 1:a7366e261ca3 | 34 | |
emilmont | 1:a7366e261ca3 | 35 | #define sys_sem_valid(x) (((*x).id == NULL) ? 0 : 1) |
emilmont | 1:a7366e261ca3 | 36 | #define sys_sem_set_invalid(x) ( (*x).id = NULL) |
emilmont | 1:a7366e261ca3 | 37 | |
emilmont | 1:a7366e261ca3 | 38 | // === MUTEX === |
emilmont | 1:a7366e261ca3 | 39 | typedef struct { |
emilmont | 1:a7366e261ca3 | 40 | osMutexId id; |
emilmont | 1:a7366e261ca3 | 41 | osMutexDef_t def; |
emilmont | 1:a7366e261ca3 | 42 | #ifdef CMSIS_OS_RTX |
emilmont | 1:a7366e261ca3 | 43 | int32_t data[3]; |
emilmont | 1:a7366e261ca3 | 44 | #endif |
emilmont | 1:a7366e261ca3 | 45 | } sys_mutex_t; |
emilmont | 1:a7366e261ca3 | 46 | |
emilmont | 1:a7366e261ca3 | 47 | // === MAIL BOX === |
emilmont | 1:a7366e261ca3 | 48 | #define MB_SIZE 8 |
emilmont | 1:a7366e261ca3 | 49 | |
emilmont | 1:a7366e261ca3 | 50 | typedef struct { |
emilmont | 1:a7366e261ca3 | 51 | osMessageQId id; |
emilmont | 1:a7366e261ca3 | 52 | osMessageQDef_t def; |
emilmont | 1:a7366e261ca3 | 53 | #ifdef CMSIS_OS_RTX |
emilmont | 1:a7366e261ca3 | 54 | uint32_t queue[MB_SIZE]; |
emilmont | 1:a7366e261ca3 | 55 | #endif |
emilmont | 1:a7366e261ca3 | 56 | } sys_mbox_t; |
emilmont | 1:a7366e261ca3 | 57 | |
emilmont | 1:a7366e261ca3 | 58 | #define SYS_MBOX_NULL ((uint32_t) NULL) |
emilmont | 1:a7366e261ca3 | 59 | #define sys_mbox_valid(x) (((*x).id == NULL) ? 0 : 1 ) |
emilmont | 1:a7366e261ca3 | 60 | #define sys_mbox_set_invalid(x) ( (*x).id = NULL ) |
emilmont | 1:a7366e261ca3 | 61 | |
emilmont | 1:a7366e261ca3 | 62 | #if ((DEFAULT_RAW_RECVMBOX_SIZE) > (MB_SIZE)) || \ |
emilmont | 1:a7366e261ca3 | 63 | ((DEFAULT_UDP_RECVMBOX_SIZE) > (MB_SIZE)) || \ |
emilmont | 1:a7366e261ca3 | 64 | ((DEFAULT_TCP_RECVMBOX_SIZE) > (MB_SIZE)) || \ |
emilmont | 1:a7366e261ca3 | 65 | ((DEFAULT_ACCEPTMBOX_SIZE) > (MB_SIZE)) || \ |
emilmont | 1:a7366e261ca3 | 66 | ((TCPIP_MBOX_SIZE) > (MB_SIZE)) |
emilmont | 1:a7366e261ca3 | 67 | # error Mailbox size not supported |
emilmont | 1:a7366e261ca3 | 68 | #endif |
emilmont | 1:a7366e261ca3 | 69 | |
emilmont | 1:a7366e261ca3 | 70 | // === THREAD === |
emilmont | 1:a7366e261ca3 | 71 | typedef struct { |
emilmont | 1:a7366e261ca3 | 72 | osThreadId id; |
emilmont | 1:a7366e261ca3 | 73 | osThreadDef_t def; |
emilmont | 1:a7366e261ca3 | 74 | } sys_thread_data_t; |
emilmont | 1:a7366e261ca3 | 75 | typedef sys_thread_data_t* sys_thread_t; |
emilmont | 1:a7366e261ca3 | 76 | |
emilmont | 1:a7366e261ca3 | 77 | #define SYS_THREAD_POOL_N 6 |
emilmont | 1:a7366e261ca3 | 78 | #define SYS_DEFAULT_THREAD_STACK_DEPTH DEFAULT_STACK_SIZE |
emilmont | 1:a7366e261ca3 | 79 | |
emilmont | 1:a7366e261ca3 | 80 | // === PROTECTION === |
emilmont | 1:a7366e261ca3 | 81 | typedef int sys_prot_t; |
emilmont | 1:a7366e261ca3 | 82 | |
emilmont | 1:a7366e261ca3 | 83 | #else |
emilmont | 1:a7366e261ca3 | 84 | #ifdef __cplusplus |
emilmont | 1:a7366e261ca3 | 85 | extern "C" { |
emilmont | 1:a7366e261ca3 | 86 | #endif |
emilmont | 1:a7366e261ca3 | 87 | |
emilmont | 1:a7366e261ca3 | 88 | /** \brief Init systick to 1ms rate |
emilmont | 1:a7366e261ca3 | 89 | * |
emilmont | 1:a7366e261ca3 | 90 | * This init the systick to 1ms rate. This function is only used in standalone |
emilmont | 1:a7366e261ca3 | 91 | * systems. |
emilmont | 1:a7366e261ca3 | 92 | */ |
emilmont | 1:a7366e261ca3 | 93 | void SysTick_Init(void); |
emilmont | 1:a7366e261ca3 | 94 | |
emilmont | 1:a7366e261ca3 | 95 | |
emilmont | 1:a7366e261ca3 | 96 | /** \brief Get the current systick time in milliSeconds |
emilmont | 1:a7366e261ca3 | 97 | * |
emilmont | 1:a7366e261ca3 | 98 | * Returns the current systick time in milliSeconds. This function is only |
emilmont | 1:a7366e261ca3 | 99 | * used in standalone systems. |
emilmont | 1:a7366e261ca3 | 100 | * |
emilmont | 1:a7366e261ca3 | 101 | * /returns current systick time in milliSeconds |
emilmont | 1:a7366e261ca3 | 102 | */ |
emilmont | 1:a7366e261ca3 | 103 | uint32_t SysTick_GetMS(void); |
emilmont | 1:a7366e261ca3 | 104 | |
emilmont | 1:a7366e261ca3 | 105 | /** \brief Delay for the specified number of milliSeconds |
emilmont | 1:a7366e261ca3 | 106 | * |
emilmont | 1:a7366e261ca3 | 107 | * For standalone systems. This function will block for the specified |
emilmont | 1:a7366e261ca3 | 108 | * number of milliSconds. For RTOS based systems, this function will delay |
emilmont | 1:a7366e261ca3 | 109 | * the task by the specified number of milliSeconds. |
emilmont | 1:a7366e261ca3 | 110 | * |
emilmont | 1:a7366e261ca3 | 111 | * \param[in] ms Time in milliSeconds to delay |
emilmont | 1:a7366e261ca3 | 112 | */ |
emilmont | 1:a7366e261ca3 | 113 | void osDelay(uint32_t ms); |
emilmont | 1:a7366e261ca3 | 114 | |
emilmont | 1:a7366e261ca3 | 115 | #ifdef __cplusplus |
emilmont | 1:a7366e261ca3 | 116 | } |
emilmont | 1:a7366e261ca3 | 117 | #endif |
emilmont | 1:a7366e261ca3 | 118 | #endif |
emilmont | 1:a7366e261ca3 | 119 | |
emilmont | 1:a7366e261ca3 | 120 | #endif /* __ARCH_SYS_ARCH_H__ */ |