diff options
| author | hathach <[email protected]> | 2025-07-04 09:49:28 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2025-07-04 09:49:28 +0700 |
| commit | 1b5f97ff23776279a011e2ab14a85f29e1aa6c10 (patch) | |
| tree | 0328289336a2b135cd8455dab70dd9bd77737590 /src/osal/osal_rtthread.h | |
| parent | cd2b3a53217857930bd8519d074b355ae8933982 (diff) | |
| parent | 9d872d529ffa0aa53e735b24543c26156798fc64 (diff) | |
Merge branch 'refs/heads/master' into fork/verylowfreq/pr-ch32v-usbfs-host
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; |
