tinyusb  0.4
Click here to lend your support to tinyusb donation and make a donation at pledgie.com
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
osal.h
Go to the documentation of this file.
1 /**************************************************************************/
37 /**************************************************************************/
38 
39 #ifndef _TUSB_OSAL_H_
40 #define _TUSB_OSAL_H_
41 
42 #ifdef __cplusplus
43  extern "C" {
44 #endif
45 
52 #define TUSB_OS_NONE 1
53 #define TUSB_OS_FREERTOS 2
54 #define TUSB_OS_CMSIS_RTX 3
55 #define TUSB_OS_UCOS3 4
56 
58 #include "tusb_option.h"
59 
60 #ifndef _TEST_
61 
62 #if TUSB_CFG_OS == TUSB_OS_NONE
63  #include "osal_none.h"
64 
65 #else
66  #if TUSB_CFG_OS == TUSB_OS_FREERTOS
67  #include "osal_freeRTOS.h"
68  #elif TUSB_CFG_OS == TUSB_OS_CMSIS_RTX
69  #include "osal_cmsis_rtx.h"
70  #else
71  #error TUSB_CFG_OS is not defined or OS is not supported yet
72  #endif
73 
74  #define OSAL_TASK_LOOP_BEGIN while(1) {
75  #define OSAL_TASK_LOOP_END }
76 
77  //------------- Sub Task -------------//
78  #define OSAL_SUBTASK_BEGIN // TODO refractor move
79  #define OSAL_SUBTASK_END return TUSB_ERROR_NONE;
80 
81  #define SUBTASK_EXIT(error) return error;
82  #define OSAL_SUBTASK_INVOKED_AND_WAIT(subtask, status) status = subtask
83 
84  //------------- Sub Task Assert -------------//
85  #define SUBTASK_ASSERT_STATUS(sts) ASSERT_STATUS(sts)
86  #define SUBTASK_ASSERT(condition) ASSERT(condition, TUSB_ERROR_OSAL_TASK_FAILED)
87 
88  #define _SUBTASK_ASSERT_ERROR_HANDLER(error, func_call) func_call; return error
89 
90  #define SUBTASK_ASSERT_STATUS_WITH_HANDLER(sts, func_call) \
91  ASSERT_DEFINE_WITH_HANDLER(_SUBTASK_ASSERT_ERROR_HANDLER, func_call, tusb_error_t status = (tusb_error_t)(sts),\
92  TUSB_ERROR_NONE == status, status, "%s", TUSB_ErrorStr[status])
93 
94  #define SUBTASK_ASSERT_WITH_HANDLER(condition, func_call) \
95  ASSERT_DEFINE_WITH_HANDLER(_SUBTASK_ASSERT_ERROR_HANDLER, func_call, ,\
96  condition, TUSB_ERROR_OSAL_TASK_FAILED, "%s", "evaluated to false")
97 #endif
98 
99 //------------- OSAL API for cmock -------------//
100 #else
101 
102 #include "osal_common.h"
103 
104 //------------- Tick -------------//
105 uint32_t osal_tick_get(void);
106 
107 //--------------------------------------------------------------------+
108 // TASK API
109 //--------------------------------------------------------------------+
110 typedef uint32_t osal_task_t;
111 tusb_error_t osal_task_create(osal_task_t *task);
112 
113 #define OSAL_TASK_DEF(code, stack_depth, prio) osal_task_t variable
114 
115 #define OSAL_TASK_REF(name) (&name)
116 
117 #define OSAL_TASK_FUNCTION(task_name) void task_name
118 
119 void osal_task_delay(uint32_t msec);
120 
121 #define OSAL_TASK_LOOP_BEGIN
122 #define OSAL_TASK_LOOP_END
123 
124 #define SUBTASK_EXIT(error) return error;
125 
126 //------------- Sub Task -------------//
127 #define OSAL_SUBTASK_INVOKED_AND_WAIT(subtask, status) status = subtask
128 
129 #define OSAL_SUBTASK_BEGIN
130 #define OSAL_SUBTASK_END return TUSB_ERROR_NONE;
131 
132 //------------- Sub Task Assert -------------//
133 #define _SUBTASK_ASSERT_ERROR_HANDLER(error, func_call) func_call; return error
134 
135 #define SUBTASK_ASSERT_STATUS(sts) ASSERT_STATUS(sts)
136 
137 #define SUBTASK_ASSERT_STATUS_WITH_HANDLER(sts, func_call) \
138  ASSERT_DEFINE_WITH_HANDLER(_SUBTASK_ASSERT_ERROR_HANDLER, func_call, tusb_error_t status = (tusb_error_t)(sts),\
139  TUSB_ERROR_NONE == status, status, "%s", TUSB_ErrorStr[status])
140 
141 #define SUBTASK_ASSERT(condition) ASSERT(condition, TUSB_ERROR_OSAL_TASK_FAILED)
142 
143 #define SUBTASK_ASSERT_WITH_HANDLER(condition, func_call) \
144  ASSERT_DEFINE_WITH_HANDLER(_SUBTASK_ASSERT_ERROR_HANDLER, func_call, ,\
145  condition, TUSB_ERROR_OSAL_TASK_FAILED, "%s", "evaluated to false")
146 
147 //--------------------------------------------------------------------+
148 // Semaphore API
149 //--------------------------------------------------------------------+
150 typedef volatile uint8_t osal_semaphore_t;
151 typedef osal_semaphore_t * osal_semaphore_handle_t;
152 
153 #define OSAL_SEM_DEF(name) osal_semaphore_t name
154 #define OSAL_SEM_REF(name) &name
155 
156 osal_semaphore_handle_t osal_semaphore_create(osal_semaphore_t * p_sem);
157 void osal_semaphore_wait(osal_semaphore_handle_t sem_hdl, uint32_t msec, tusb_error_t *p_error);
158 tusb_error_t osal_semaphore_post(osal_semaphore_handle_t sem_hdl);
159 void osal_semaphore_reset(osal_semaphore_handle_t sem_hdl);
160 
161 //--------------------------------------------------------------------+
162 // MUTEX API (priority inheritance)
163 //--------------------------------------------------------------------+
164 #define OSAL_MUTEX_DEF(name) osal_mutex_t name
165 #define OSAL_MUTEX_REF(name) &name
166 
167 typedef osal_semaphore_t osal_mutex_t;
168 typedef osal_semaphore_handle_t osal_mutex_handle_t;
169 
170 osal_mutex_handle_t osal_mutex_create(osal_mutex_t * p_mutex);
171 void osal_mutex_wait(osal_mutex_handle_t mutex_hdl, uint32_t msec, tusb_error_t *p_error);
172 tusb_error_t osal_mutex_release(osal_mutex_handle_t mutex_hdl);
173 void osal_mutex_reset(osal_mutex_handle_t mutex_hdl);
174 //--------------------------------------------------------------------+
175 // QUEUE API
176 //--------------------------------------------------------------------+
177 typedef struct{
178  uint32_t * const buffer ;
179  uint8_t const depth ;
180  volatile uint8_t count ;
181  volatile uint8_t wr_idx ;
182  volatile uint8_t rd_idx ;
183 } osal_queue_t;
184 
186 
187 #define OSAL_QUEUE_DEF(name, queue_depth, type) osal_queue_t name
188 #define OSAL_QUEUE_REF(name) (&name)
189 
190 osal_queue_handle_t osal_queue_create (osal_queue_t *p_queue);
191 void osal_queue_receive (osal_queue_handle_t const queue_hdl, void *p_data, uint32_t msec, tusb_error_t *p_error);
192 tusb_error_t osal_queue_send (osal_queue_handle_t const queue_hdl, const void * data);
193 void osal_queue_flush(osal_queue_handle_t const queue_hdl);
194 
195 //--------------------------------------------------------------------+
196 // TICK API
197 //--------------------------------------------------------------------+
198 uint32_t osal_tick_get(void);
199 #endif
200 
201 #ifdef __cplusplus
202  }
203 #endif
204 
207 #endif /* _TUSB_OSAL_H_ */
tusb_error_t
Error Code returned.
Definition: tusb_errors.h:100