@@ -65,26 +65,55 @@ static void _cpu_preempt_enable(void)
6565 rt_hw_local_irq_enable (level );
6666}
6767
68+ /**
69+ * @brief Initialize a static spinlock object.
70+ *
71+ * @param lock is a pointer to the spinlock to initialize.
72+ * It is assumed that storage for the spinlock will be allocated in your application.
73+ */
6874void rt_spin_lock_init (struct rt_spinlock * lock )
6975{
7076 rt_hw_spin_lock_init (& lock -> lock );
7177}
7278RTM_EXPORT (rt_spin_lock_init )
7379
80+ /**
81+ * @brief This function will lock the spinlock.
82+ *
83+ * @note If the spinlock is locked, the current CPU will keep polling the spinlock state
84+ * until the spinlock is unlocked.
85+ *
86+ * @param lock is a pointer to the spinlock.
87+ */
7488void rt_spin_lock (struct rt_spinlock * lock )
7589{
7690 _cpu_preempt_disable ();
7791 rt_hw_spin_lock (& lock -> lock );
7892}
7993RTM_EXPORT (rt_spin_lock )
8094
95+ /**
96+ * @brief This function will unlock the spinlock.
97+ *
98+ * @param lock is a pointer to the spinlock.
99+ */
81100void rt_spin_unlock (struct rt_spinlock * lock )
82101{
83102 rt_hw_spin_unlock (& lock -> lock );
84103 _cpu_preempt_enable ();
85104}
86105RTM_EXPORT (rt_spin_unlock )
87106
107+ /**
108+ * @brief This function will disable the local interrupt and then lock the spinlock.
109+ *
110+ * @note If the spinlock is locked, the current CPU will keep polling the spinlock state
111+ * until the spinlock is unlocked.
112+ *
113+ * @param lock is a pointer to the spinlock.
114+ *
115+ * @return Return current cpu interrupt status.
116+ */
88117rt_base_t rt_spin_lock_irqsave (struct rt_spinlock * lock )
89118{
90119 unsigned long level ;
@@ -98,6 +127,13 @@ rt_base_t rt_spin_lock_irqsave(struct rt_spinlock *lock)
98127}
99128RTM_EXPORT (rt_spin_lock_irqsave )
100129
130+ /**
131+ * @brief This function will unlock the spinlock and then restore current cpu interrupt status.
132+ *
133+ * @param lock is a pointer to the spinlock.
134+ *
135+ * @param level is interrupt status returned by rt_spin_lock_irqsave().
136+ */
101137void rt_spin_unlock_irqrestore (struct rt_spinlock * lock , rt_base_t level )
102138{
103139 rt_hw_spin_unlock (& lock -> lock );
@@ -108,20 +144,29 @@ void rt_spin_unlock_irqrestore(struct rt_spinlock *lock, rt_base_t level)
108144RTM_EXPORT (rt_spin_unlock_irqrestore )
109145
110146/**
111- * This fucntion will return current cpu.
147+ * @brief This fucntion will return current cpu object.
148+ *
149+ * @return Return a pointer to the current cpu object.
112150 */
113151struct rt_cpu * rt_cpu_self (void )
114152{
115153 return & _cpus [rt_hw_cpu_id ()];
116154}
117155
156+ /**
157+ * @brief This fucntion will return the cpu object corresponding to index.
158+ *
159+ * @return Return a pointer to the cpu object corresponding to index.
160+ */
118161struct rt_cpu * rt_cpu_index (int index )
119162{
120163 return & _cpus [index ];
121164}
122165
123166/**
124- * This function will lock all cpus's scheduler and disable local irq.
167+ * @brief This function will lock all cpus's scheduler and disable local irq.
168+ *
169+ * @return Return current cpu interrupt status.
125170 */
126171rt_base_t rt_cpus_lock (void )
127172{
@@ -148,7 +193,9 @@ rt_base_t rt_cpus_lock(void)
148193RTM_EXPORT (rt_cpus_lock );
149194
150195/**
151- * This function will restore all cpus's scheduler and restore local irq.
196+ * @brief This function will restore all cpus's scheduler and restore local irq.
197+ *
198+ * @param level is interrupt status returned by rt_cpus_lock().
152199 */
153200void rt_cpus_unlock (rt_base_t level )
154201{
0 commit comments