2424 * This file is part of the TinyUSB stack.
2525 */
2626
27- #ifndef _TUSB_OSAL_NONE_H_
28- #define _TUSB_OSAL_NONE_H_
27+ #ifndef TUSB_OSAL_NONE_H_
28+ #define TUSB_OSAL_NONE_H_
2929
3030#ifdef __cplusplus
31- extern "C" {
31+ extern "C" {
3232#endif
3333
3434//--------------------------------------------------------------------+
@@ -43,39 +43,34 @@ TU_ATTR_WEAK void osal_task_delay(uint32_t msec);
4343//--------------------------------------------------------------------+
4444// Binary Semaphore API
4545//--------------------------------------------------------------------+
46- typedef struct
47- {
46+ typedef struct {
4847 volatile uint16_t count ;
49- }osal_semaphore_def_t ;
48+ } osal_semaphore_def_t ;
5049
5150typedef osal_semaphore_def_t * osal_semaphore_t ;
5251
53- TU_ATTR_ALWAYS_INLINE static inline osal_semaphore_t osal_semaphore_create (osal_semaphore_def_t * semdef )
54- {
52+ TU_ATTR_ALWAYS_INLINE static inline osal_semaphore_t osal_semaphore_create (osal_semaphore_def_t * semdef ) {
5553 semdef -> count = 0 ;
5654 return semdef ;
5755}
5856
59- TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_post (osal_semaphore_t sem_hdl , bool in_isr )
60- {
57+ TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_post (osal_semaphore_t sem_hdl , bool in_isr ) {
6158 (void ) in_isr ;
6259 sem_hdl -> count ++ ;
6360 return true;
6461}
6562
6663// TODO blocking for now
67- TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_wait (osal_semaphore_t sem_hdl , uint32_t msec )
68- {
64+ TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_wait (osal_semaphore_t sem_hdl , uint32_t msec ) {
6965 (void ) msec ;
7066
71- while (sem_hdl -> count == 0 ) { }
67+ while (sem_hdl -> count == 0 ) {}
7268 sem_hdl -> count -- ;
7369
7470 return true;
7571}
7672
77- TU_ATTR_ALWAYS_INLINE static inline void osal_semaphore_reset (osal_semaphore_t sem_hdl )
78- {
73+ TU_ATTR_ALWAYS_INLINE static inline void osal_semaphore_reset (osal_semaphore_t sem_hdl ) {
7974 sem_hdl -> count = 0 ;
8075}
8176
@@ -90,19 +85,16 @@ typedef osal_semaphore_t osal_mutex_t;
9085// Note: multiple cores MCUs usually do provide IPC API for mutex
9186// or we can use std atomic function
9287
93- TU_ATTR_ALWAYS_INLINE static inline osal_mutex_t osal_mutex_create (osal_mutex_def_t * mdef )
94- {
88+ TU_ATTR_ALWAYS_INLINE static inline osal_mutex_t osal_mutex_create (osal_mutex_def_t * mdef ) {
9589 mdef -> count = 1 ;
9690 return mdef ;
9791}
9892
99- TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_lock (osal_mutex_t mutex_hdl , uint32_t msec )
100- {
93+ TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_lock (osal_mutex_t mutex_hdl , uint32_t msec ) {
10194 return osal_semaphore_wait (mutex_hdl , msec );
10295}
10396
104- TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_unlock (osal_mutex_t mutex_hdl )
105- {
97+ TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_unlock (osal_mutex_t mutex_hdl ) {
10698 return osal_semaphore_post (mutex_hdl , false);
10799}
108100
@@ -119,11 +111,10 @@ TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_unlock(osal_mutex_t mutex_hd
119111//--------------------------------------------------------------------+
120112#include "common/tusb_fifo.h"
121113
122- typedef struct
123- {
124- void (* interrupt_set )(bool );
114+ typedef struct {
115+ void (* interrupt_set )(bool );
125116 tu_fifo_t ff ;
126- }osal_queue_def_t ;
117+ } osal_queue_def_t ;
127118
128119typedef osal_queue_def_t * osal_queue_t ;
129120
@@ -136,27 +127,23 @@ typedef osal_queue_def_t* osal_queue_t;
136127 }
137128
138129// lock queue by disable USB interrupt
139- TU_ATTR_ALWAYS_INLINE static inline void _osal_q_lock (osal_queue_t qhdl )
140- {
130+ TU_ATTR_ALWAYS_INLINE static inline void _osal_q_lock (osal_queue_t qhdl ) {
141131 // disable dcd/hcd interrupt
142132 qhdl -> interrupt_set (false);
143133}
144134
145135// unlock queue
146- TU_ATTR_ALWAYS_INLINE static inline void _osal_q_unlock (osal_queue_t qhdl )
147- {
136+ TU_ATTR_ALWAYS_INLINE static inline void _osal_q_unlock (osal_queue_t qhdl ) {
148137 // enable dcd/hcd interrupt
149138 qhdl -> interrupt_set (true);
150139}
151140
152- TU_ATTR_ALWAYS_INLINE static inline osal_queue_t osal_queue_create (osal_queue_def_t * qdef )
153- {
141+ TU_ATTR_ALWAYS_INLINE static inline osal_queue_t osal_queue_create (osal_queue_def_t * qdef ) {
154142 tu_fifo_clear (& qdef -> ff );
155143 return (osal_queue_t ) qdef ;
156144}
157145
158- TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_receive (osal_queue_t qhdl , void * data , uint32_t msec )
159- {
146+ TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_receive (osal_queue_t qhdl , void * data , uint32_t msec ) {
160147 (void ) msec ; // not used, always behave as msec = 0
161148
162149 _osal_q_lock (qhdl );
@@ -166,8 +153,7 @@ TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_receive(osal_queue_t qhdl, v
166153 return success ;
167154}
168155
169- TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_send (osal_queue_t qhdl , void const * data , bool in_isr )
170- {
156+ TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_send (osal_queue_t qhdl , void const * data , bool in_isr ) {
171157 if (!in_isr ) {
172158 _osal_q_lock (qhdl );
173159 }
@@ -179,19 +165,17 @@ TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_send(osal_queue_t qhdl, void
179165 }
180166
181167 TU_ASSERT (success );
182-
183168 return success ;
184169}
185170
186- TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_empty (osal_queue_t qhdl )
187- {
171+ TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_empty (osal_queue_t qhdl ) {
188172 // Skip queue lock/unlock since this function is primarily called
189173 // with interrupt disabled before going into low power mode
190174 return tu_fifo_empty (& qhdl -> ff );
191175}
192176
193177#ifdef __cplusplus
194- }
178+ }
195179#endif
196180
197- #endif /* _TUSB_OSAL_NONE_H_ */
181+ #endif
0 commit comments