37
37
extern "C" {
38
38
#endif
39
39
40
+ TU_ATTR_ALWAYS_INLINE static inline uint32_t _osal_ms2tick (uint32_t msec )
41
+ {
42
+ if (msec == OSAL_TIMEOUT_WAIT_FOREVER ) return portMAX_DELAY ;
43
+ if (msec == 0 ) return 0 ;
44
+
45
+ uint32_t ticks = pdMS_TO_TICKS (msec );
46
+
47
+ // configTICK_RATE_HZ is less than 1000 and 1 tick > 1 ms
48
+ // we still need to delay at least 1 tick
49
+ if (ticks == 0 ) ticks = 1 ;
50
+
51
+ return ticks ;
52
+ }
53
+
40
54
//--------------------------------------------------------------------+
41
55
// TASK API
42
56
//--------------------------------------------------------------------+
43
- static inline void osal_task_delay (uint32_t msec )
57
+ TU_ATTR_ALWAYS_INLINE static inline void osal_task_delay (uint32_t msec )
44
58
{
45
59
vTaskDelay ( pdMS_TO_TICKS (msec ) );
46
60
}
@@ -51,12 +65,12 @@ static inline void osal_task_delay(uint32_t msec)
51
65
typedef StaticSemaphore_t osal_semaphore_def_t ;
52
66
typedef SemaphoreHandle_t osal_semaphore_t ;
53
67
54
- static inline osal_semaphore_t osal_semaphore_create (osal_semaphore_def_t * semdef )
68
+ TU_ATTR_ALWAYS_INLINE static inline osal_semaphore_t osal_semaphore_create (osal_semaphore_def_t * semdef )
55
69
{
56
70
return xSemaphoreCreateBinaryStatic (semdef );
57
71
}
58
72
59
- static inline bool osal_semaphore_post (osal_semaphore_t sem_hdl , bool in_isr )
73
+ TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_post (osal_semaphore_t sem_hdl , bool in_isr )
60
74
{
61
75
if ( !in_isr )
62
76
{
@@ -78,13 +92,12 @@ static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr)
78
92
}
79
93
}
80
94
81
- static inline bool osal_semaphore_wait (osal_semaphore_t sem_hdl , uint32_t msec )
95
+ TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_wait (osal_semaphore_t sem_hdl , uint32_t msec )
82
96
{
83
- uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER ) ? portMAX_DELAY : pdMS_TO_TICKS (msec );
84
- return xSemaphoreTake (sem_hdl , ticks );
97
+ return xSemaphoreTake (sem_hdl , _osal_ms2tick (msec ));
85
98
}
86
99
87
- static inline void osal_semaphore_reset (osal_semaphore_t const sem_hdl )
100
+ TU_ATTR_ALWAYS_INLINE static inline void osal_semaphore_reset (osal_semaphore_t const sem_hdl )
88
101
{
89
102
xQueueReset (sem_hdl );
90
103
}
@@ -95,17 +108,17 @@ static inline void osal_semaphore_reset(osal_semaphore_t const sem_hdl)
95
108
typedef StaticSemaphore_t osal_mutex_def_t ;
96
109
typedef SemaphoreHandle_t osal_mutex_t ;
97
110
98
- static inline osal_mutex_t osal_mutex_create (osal_mutex_def_t * mdef )
111
+ TU_ATTR_ALWAYS_INLINE static inline osal_mutex_t osal_mutex_create (osal_mutex_def_t * mdef )
99
112
{
100
113
return xSemaphoreCreateMutexStatic (mdef );
101
114
}
102
115
103
- static inline bool osal_mutex_lock (osal_mutex_t mutex_hdl , uint32_t msec )
116
+ TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_lock (osal_mutex_t mutex_hdl , uint32_t msec )
104
117
{
105
118
return osal_semaphore_wait (mutex_hdl , msec );
106
119
}
107
120
108
- static inline bool osal_mutex_unlock (osal_mutex_t mutex_hdl )
121
+ TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_unlock (osal_mutex_t mutex_hdl )
109
122
{
110
123
return xSemaphoreGive (mutex_hdl );
111
124
}
@@ -114,7 +127,7 @@ static inline bool osal_mutex_unlock(osal_mutex_t mutex_hdl)
114
127
// QUEUE API
115
128
//--------------------------------------------------------------------+
116
129
117
- // role device/host is used by OS NONE for mutex (disable usb isr) only
130
+ // _int_set is not used with an RTOS
118
131
#define OSAL_QUEUE_DEF (_int_set , _name , _depth , _type ) \
119
132
static _type _name##_##buf[_depth];\
120
133
osal_queue_def_t _name = { .depth = _depth, .item_sz = sizeof(_type), .buf = _name##_##buf };
@@ -130,17 +143,17 @@ typedef struct
130
143
131
144
typedef QueueHandle_t osal_queue_t ;
132
145
133
- static inline osal_queue_t osal_queue_create (osal_queue_def_t * qdef )
146
+ TU_ATTR_ALWAYS_INLINE static inline osal_queue_t osal_queue_create (osal_queue_def_t * qdef )
134
147
{
135
148
return xQueueCreateStatic (qdef -> depth , qdef -> item_sz , (uint8_t * ) qdef -> buf , & qdef -> sq );
136
149
}
137
150
138
- static inline bool osal_queue_receive (osal_queue_t qhdl , void * data )
151
+ TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_receive (osal_queue_t qhdl , void * data , uint32_t msec )
139
152
{
140
- return xQueueReceive (qhdl , data , portMAX_DELAY );
153
+ return xQueueReceive (qhdl , data , _osal_ms2tick ( msec ) );
141
154
}
142
155
143
- static inline bool osal_queue_send (osal_queue_t qhdl , void const * data , bool in_isr )
156
+ TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_send (osal_queue_t qhdl , void const * data , bool in_isr )
144
157
{
145
158
if ( !in_isr )
146
159
{
@@ -162,7 +175,7 @@ static inline bool osal_queue_send(osal_queue_t qhdl, void const * data, bool in
162
175
}
163
176
}
164
177
165
- static inline bool osal_queue_empty (osal_queue_t qhdl )
178
+ TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_empty (osal_queue_t qhdl )
166
179
{
167
180
return uxQueueMessagesWaiting (qhdl ) == 0 ;
168
181
}
0 commit comments