diff options
| author | Ha Thach <[email protected]> | 2025-05-21 15:15:43 +0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-05-21 15:15:43 +0700 |
| commit | 3a042b37da28d0ba1e5593eb1068ca5645d77b56 (patch) | |
| tree | 4a8d00b8d34c7c2e390b7b8f5ed53afc316c7121 /src/osal/osal_rtthread.h | |
| parent | 5428b87948f6c5740660e6e3e29dfd6fde3be37c (diff) | |
| parent | 58dfc126ac96d151bc6a9e9ee8bda564b52c350f (diff) | |
Merge pull request #3127 from hathach/fix/dcd_race_condition
add osal spinlock API, Fix/dcd dwc2 race condition
Diffstat (limited to 'src/osal/osal_rtthread.h')
| -rw-r--r-- | src/osal/osal_rtthread.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/osal/osal_rtthread.h b/src/osal/osal_rtthread.h index c27814835..a778f5425 100644 --- a/src/osal/osal_rtthread.h +++ b/src/osal/osal_rtthread.h @@ -43,6 +43,32 @@ TU_ATTR_ALWAYS_INLINE static inline void osal_task_delay(uint32_t msec) { } //--------------------------------------------------------------------+ +// Spinlock API +//--------------------------------------------------------------------+ +typedef struct rt_spinlock osal_spinlock_t; + +#define OSAL_SPINLOCK_DEF(_name, _int_set) \ + osal_spinlock_t _name + +TU_ATTR_ALWAYS_INLINE static inline void osal_spin_init(osal_spinlock_t *ctx) { + rt_spin_lock_init(ctx); +} + +TU_ATTR_ALWAYS_INLINE static inline void osal_spin_lock(osal_spinlock_t *ctx, bool in_isr) { + if (!TUP_MCU_MULTIPLE_CORE && in_isr) { + return; // single core MCU does not need to lock in ISR + } + rt_spin_lock(ctx); +} + +TU_ATTR_ALWAYS_INLINE static inline void osal_spin_unlock(osal_spinlock_t *ctx, bool in_isr) { + if (!TUP_MCU_MULTIPLE_CORE && in_isr) { + return; // single core MCU does not need to lock in ISR + } + rt_spin_unlock(ctx); +} + +//--------------------------------------------------------------------+ // Semaphore API //--------------------------------------------------------------------+ typedef struct rt_semaphore osal_semaphore_def_t; |
