summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorShell <[email protected]>2024-04-19 10:45:09 +0800
committerMeco Man <[email protected]>2024-04-19 21:30:12 -0400
commit451ac0396512d9fbf2ccad48e08774b8da3cb5ac (patch)
tree7b868b9b060ad71998444e77a7a73cc8547c1d92 /include
parent2aacba2c868176e50ccd522e882ca0b194a9ed14 (diff)
add cpu up
Diffstat (limited to 'include')
-rw-r--r--include/rtthread.h33
-rw-r--r--include/rttypes.h120
2 files changed, 59 insertions, 94 deletions
diff --git a/include/rtthread.h b/include/rtthread.h
index 2329824112..c8993dd7e6 100644
--- a/include/rtthread.h
+++ b/include/rtthread.h
@@ -604,45 +604,12 @@ rt_thread_t rt_thread_defunct_dequeue(void);
* spinlock
*/
struct rt_spinlock;
-#ifdef RT_USING_SMP
void rt_spin_lock_init(struct rt_spinlock *lock);
void rt_spin_lock(struct rt_spinlock *lock);
void rt_spin_unlock(struct rt_spinlock *lock);
rt_base_t rt_spin_lock_irqsave(struct rt_spinlock *lock);
void rt_spin_unlock_irqrestore(struct rt_spinlock *lock, rt_base_t level);
-#else
-
-rt_inline void rt_spin_lock_init(struct rt_spinlock *lock)
-{
- RT_UNUSED(lock);
-}
-rt_inline void rt_spin_lock(struct rt_spinlock *lock)
-{
- RT_UNUSED(lock);
- rt_enter_critical();
-}
-rt_inline void rt_spin_unlock(struct rt_spinlock *lock)
-{
- RT_UNUSED(lock);
- rt_exit_critical();
-}
-rt_inline rt_base_t rt_spin_lock_irqsave(struct rt_spinlock *lock)
-{
- rt_base_t level;
- RT_UNUSED(lock);
- level = rt_hw_interrupt_disable();
- rt_enter_critical();
- return level;
-}
-rt_inline void rt_spin_unlock_irqrestore(struct rt_spinlock *lock, rt_base_t level)
-{
- RT_UNUSED(lock);
- rt_exit_critical();
- rt_hw_interrupt_enable(level);
-}
-
-#endif /* RT_USING_SMP */
/**@}*/
diff --git a/include/rttypes.h b/include/rttypes.h
index f697abf531..bfd6d7975e 100644
--- a/include/rttypes.h
+++ b/include/rttypes.h
@@ -135,62 +135,76 @@ struct rt_spinlock
#endif /* RT_DEBUGING_SPINLOCK */
};
-#ifdef RT_DEBUGING_SPINLOCK
+#ifndef RT_SPINLOCK_INIT
+#define RT_SPINLOCK_INIT {{0}} /* can be overridden by cpuport.h */
+#endif /* RT_SPINLOCK_INIT */
-#define __OWNER_MAGIC ((void *)0xdeadbeaf)
+#else /* !RT_USING_SMP */
-#if defined(__GNUC__)
-#define __GET_RETURN_ADDRESS __builtin_return_address(0)
-#else
-#define __GET_RETURN_ADDRESS RT_NULL
-#endif
+struct rt_spinlock
+{
+#ifdef RT_USING_DEBUG
+ rt_uint32_t critical_level;
+#endif /* RT_USING_DEBUG */
+ rt_ubase_t lock;
+};
+#define RT_SPINLOCK_INIT {0}
+#endif /* RT_USING_SMP */
+#if defined(RT_DEBUGING_SPINLOCK) && defined(RT_USING_SMP)
-#define _SPIN_LOCK_DEBUG_OWNER(lock) \
- do \
- { \
- struct rt_thread *_curthr = rt_thread_self(); \
- if (_curthr != RT_NULL) \
- { \
- (lock)->owner = _curthr; \
- (lock)->pc = __GET_RETURN_ADDRESS; \
- } \
- } while (0)
+ #define __OWNER_MAGIC ((void *)0xdeadbeaf)
-#define _SPIN_UNLOCK_DEBUG_OWNER(lock) \
- do \
- { \
- (lock)->owner = __OWNER_MAGIC; \
- (lock)->pc = RT_NULL; \
- } while (0)
+ #if defined(__GNUC__)
+ #define __GET_RETURN_ADDRESS __builtin_return_address(0)
+ #else /* !__GNUC__ */
+ #define __GET_RETURN_ADDRESS RT_NULL
+ #endif /* __GNUC__ */
-#else
+ #define _SPIN_LOCK_DEBUG_OWNER(lock) \
+ do \
+ { \
+ struct rt_thread *_curthr = rt_thread_self(); \
+ if (_curthr != RT_NULL) \
+ { \
+ (lock)->owner = _curthr; \
+ (lock)->pc = __GET_RETURN_ADDRESS; \
+ } \
+ } while (0)
-#define _SPIN_LOCK_DEBUG_OWNER(lock)
-#define _SPIN_UNLOCK_DEBUG_OWNER(lock)
-#endif
+ #define _SPIN_UNLOCK_DEBUG_OWNER(lock) \
+ do \
+ { \
+ (lock)->owner = __OWNER_MAGIC; \
+ (lock)->pc = RT_NULL; \
+ } while (0)
-#ifdef RT_USING_DEBUG
+#else /* !RT_DEBUGING_SPINLOCK */
-#define _SPIN_LOCK_DEBUG_CRITICAL(lock) \
- do \
- { \
- struct rt_thread *_curthr = rt_thread_self(); \
- if (_curthr != RT_NULL) \
- { \
- (lock)->critical_level = rt_critical_level(); \
- } \
- } while (0)
+ #define _SPIN_LOCK_DEBUG_OWNER(lock)
+ #define _SPIN_UNLOCK_DEBUG_OWNER(lock)
+#endif /* RT_DEBUGING_SPINLOCK */
-#define _SPIN_UNLOCK_DEBUG_CRITICAL(lock, critical) \
- do \
- { \
- (critical) = (lock)->critical_level; \
- } while (0)
+#ifdef RT_USING_DEBUG
+ #define _SPIN_LOCK_DEBUG_CRITICAL(lock) \
+ do \
+ { \
+ struct rt_thread *_curthr = rt_thread_self(); \
+ if (_curthr != RT_NULL) \
+ { \
+ (lock)->critical_level = rt_critical_level(); \
+ } \
+ } while (0)
-#else
+ #define _SPIN_UNLOCK_DEBUG_CRITICAL(lock, critical) \
+ do \
+ { \
+ (critical) = (lock)->critical_level; \
+ } while (0)
+
+#else /* !RT_USING_DEBUG */
+ #define _SPIN_LOCK_DEBUG_CRITICAL(lock)
+ #define _SPIN_UNLOCK_DEBUG_CRITICAL(lock, critical) (critical = 0)
-#define _SPIN_LOCK_DEBUG_CRITICAL(lock)
-#define _SPIN_UNLOCK_DEBUG_CRITICAL(lock, critical) (critical = 0)
#endif /* RT_USING_DEBUG */
#define RT_SPIN_LOCK_DEBUG(lock) \
@@ -207,22 +221,6 @@ struct rt_spinlock
_SPIN_UNLOCK_DEBUG_CRITICAL(lock, critical); \
} while (0)
-#ifndef RT_SPINLOCK_INIT
-#define RT_SPINLOCK_INIT {{0}} /* can be overridden by cpuport.h */
-#endif /* RT_SPINLOCK_INIT */
-
-#else
-
-struct rt_spinlock
-{
-#ifdef RT_USING_DEBUG
- rt_uint32_t critical_level;
-#endif /* RT_USING_DEBUG */
- rt_ubase_t lock;
-};
-#define RT_SPINLOCK_INIT {0}
-#endif /* RT_USING_SMP */
-
typedef struct rt_spinlock rt_spinlock_t;
#define RT_DEFINE_SPINLOCK(x) struct rt_spinlock x = RT_SPINLOCK_INIT