@@ -65,26 +65,54 @@ 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+ */
6873void rt_spin_lock_init (struct rt_spinlock * lock )
6974{
7075 rt_hw_spin_lock_init (& lock -> lock );
7176}
7277RTM_EXPORT (rt_spin_lock_init )
7378
79+ /**
80+ * @brief This function will lock the spinlock.
81+ *
82+ * @note If the spinlock is locked, the current CPU will keep polling the spinlock state
83+ * until the spinlock is unlocked.
84+ *
85+ * @param lock is a pointer to the spinlock.
86+ */
7487void rt_spin_lock (struct rt_spinlock * lock )
7588{
7689 _cpu_preempt_disable ();
7790 rt_hw_spin_lock (& lock -> lock );
7891}
7992RTM_EXPORT (rt_spin_lock )
8093
94+ /**
95+ * @brief This function will unlock the spinlock.
96+ *
97+ * @param lock is a pointer to the spinlock.
98+ */
8199void rt_spin_unlock (struct rt_spinlock * lock )
82100{
83101 rt_hw_spin_unlock (& lock -> lock );
84102 _cpu_preempt_enable ();
85103}
86104RTM_EXPORT (rt_spin_unlock )
87105
106+ /**
107+ * @brief This function will disable the local interrupt and then lock the spinlock.
108+ *
109+ * @note If the spinlock is locked, the current CPU will keep polling the spinlock state
110+ * until the spinlock is unlocked.
111+ *
112+ * @param lock is a pointer to the spinlock.
113+ *
114+ * @return Return current cpu interrupt status.
115+ */
88116rt_base_t rt_spin_lock_irqsave (struct rt_spinlock * lock )
89117{
90118 unsigned long level ;
@@ -98,6 +126,13 @@ rt_base_t rt_spin_lock_irqsave(struct rt_spinlock *lock)
98126}
99127RTM_EXPORT (rt_spin_lock_irqsave )
100128
129+ /**
130+ * @brief This function will unlock the spinlock and then restore current cpu interrupt status.
131+ *
132+ * @param lock is a pointer to the spinlock.
133+ *
134+ * @param level is interrupt status returned by rt_spin_lock_irqsave().
135+ */
101136void rt_spin_unlock_irqrestore (struct rt_spinlock * lock , rt_base_t level )
102137{
103138 rt_hw_spin_unlock (& lock -> lock );
@@ -108,20 +143,29 @@ void rt_spin_unlock_irqrestore(struct rt_spinlock *lock, rt_base_t level)
108143RTM_EXPORT (rt_spin_unlock_irqrestore )
109144
110145/**
111- * This fucntion will return current cpu.
146+ * @brief This fucntion will return current cpu object.
147+ *
148+ * @return Return a pointer to the current cpu object.
112149 */
113150struct rt_cpu * rt_cpu_self (void )
114151{
115152 return & _cpus [rt_hw_cpu_id ()];
116153}
117154
155+ /**
156+ * @brief This fucntion will return the cpu object corresponding to index.
157+ *
158+ * @return Return a pointer to the cpu object corresponding to index.
159+ */
118160struct rt_cpu * rt_cpu_index (int index )
119161{
120162 return & _cpus [index ];
121163}
122164
123165/**
124- * This function will lock all cpus's scheduler and disable local irq.
166+ * @brief This function will lock all cpus's scheduler and disable local irq.
167+ *
168+ * @return Return current cpu interrupt status.
125169 */
126170rt_base_t rt_cpus_lock (void )
127171{
@@ -148,7 +192,9 @@ rt_base_t rt_cpus_lock(void)
148192RTM_EXPORT (rt_cpus_lock );
149193
150194/**
151- * This function will restore all cpus's scheduler and restore local irq.
195+ * @brief This function will restore all cpus's scheduler and restore local irq.
196+ *
197+ * @param level is interrupt status returned by rt_cpus_lock().
152198 */
153199void rt_cpus_unlock (rt_base_t level )
154200{
0 commit comments