Skip to content

Commit b2c64b7

Browse files
authored
Merge pull request #5039 from Guozhanxin/kernel_comment
Improve the Kernel comment
2 parents f76a192 + 6cb093a commit b2c64b7

File tree

3 files changed

+85
-19
lines changed

3 files changed

+85
-19
lines changed

src/clock.c

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ static volatile rt_tick_t rt_tick = 0;
3333
/**@{*/
3434

3535
/**
36-
* This function will return current tick from operating system startup
36+
* @brief This function will return current tick from operating system startup
3737
*
38-
* @return current tick
38+
* @return Return current tick
3939
*/
4040
rt_tick_t rt_tick_get(void)
4141
{
@@ -45,7 +45,9 @@ rt_tick_t rt_tick_get(void)
4545
RTM_EXPORT(rt_tick_get);
4646

4747
/**
48-
* This function will set current tick
48+
* @brief This function will set current tick
49+
*
50+
* @param tick is the value that you will set.
4951
*/
5052
void rt_tick_set(rt_tick_t tick)
5153
{
@@ -57,8 +59,8 @@ void rt_tick_set(rt_tick_t tick)
5759
}
5860

5961
/**
60-
* This function will notify kernel there is one tick passed. Normally,
61-
* this function is invoked by clock ISR.
62+
* @brief This function will notify kernel there is one tick passed.
63+
* Normally, this function is invoked by clock ISR.
6264
*/
6365
void rt_tick_increase(void)
6466
{
@@ -97,14 +99,14 @@ void rt_tick_increase(void)
9799
}
98100

99101
/**
100-
* This function will calculate the tick from millisecond.
102+
* @brief This function will calculate the tick from millisecond.
101103
*
102-
* @param ms the specified millisecond
103-
* - Negative Number wait forever
104-
* - Zero not wait
105-
* - Max 0x7fffffff
104+
* @param ms is the specified millisecond
105+
* - Negative Number wait forever
106+
* - Zero not wait
107+
* - Max 0x7fffffff
106108
*
107-
* @return the calculated tick
109+
* @return Return the calculated tick
108110
*/
109111
rt_tick_t rt_tick_from_millisecond(rt_int32_t ms)
110112
{
@@ -126,9 +128,13 @@ rt_tick_t rt_tick_from_millisecond(rt_int32_t ms)
126128
RTM_EXPORT(rt_tick_from_millisecond);
127129

128130
/**
129-
* This function will provide the passed millisecond from boot.
131+
* @brief This function will return the passed millisecond from boot.
132+
*
133+
* @note if the value of RT_TICK_PER_SECOND is lower than 1000 or
134+
* is not an integral multiple of 1000, this function will not
135+
* provide the correct 1ms-based tick.
130136
*
131-
* @return passed millisecond from boot
137+
* @return Return passed millisecond from boot
132138
*/
133139
RT_WEAK rt_tick_t rt_tick_get_millisecond(void)
134140
{

src/components.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ static int rti_end(void)
7878
INIT_EXPORT(rti_end, "6.end");
7979

8080
/**
81-
* RT-Thread Components Initialization for board
81+
* @brief Onboard components initialization. In this function, the board-level
82+
* initialization function will be called to complete the initialization
83+
* of the on-board peripherals.
8284
*/
8385
void rt_components_board_init(void)
8486
{
@@ -102,7 +104,7 @@ void rt_components_board_init(void)
102104
}
103105

104106
/**
105-
* RT-Thread Components Initialization
107+
* @brief RT-Thread Components Initialization.
106108
*/
107109
void rt_components_init(void)
108110
{
@@ -169,7 +171,11 @@ static rt_uint8_t main_stack[RT_MAIN_THREAD_STACK_SIZE];
169171
struct rt_thread main_thread;
170172
#endif /* RT_USING_HEAP */
171173

172-
/* the system main thread */
174+
/**
175+
* @brief The system main thread. In this thread will call the rt_components_init()
176+
* for initialization of RT-Thread Components and call the user's programming
177+
* entry main().
178+
*/
173179
void main_thread_entry(void *parameter)
174180
{
175181
extern int main(void);
@@ -193,6 +199,10 @@ void main_thread_entry(void *parameter)
193199
#endif
194200
}
195201

202+
/**
203+
* @brief This function will create and start the main thread, but this thread
204+
* will not run until the scheduler starts.
205+
*/
196206
void rt_application_init(void)
197207
{
198208
rt_thread_t tid;
@@ -216,6 +226,10 @@ void rt_application_init(void)
216226
rt_thread_startup(tid);
217227
}
218228

229+
/**
230+
* @brief This function will call all levels of initialization functions to complete
231+
* the initialization of the system, and finally start the scheduler.
232+
*/
219233
int rtthread_startup(void)
220234
{
221235
rt_hw_interrupt_disable();

src/cpu.c

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
*/
6873
void rt_spin_lock_init(struct rt_spinlock *lock)
6974
{
7075
rt_hw_spin_lock_init(&lock->lock);
7176
}
7277
RTM_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+
*/
7487
void rt_spin_lock(struct rt_spinlock *lock)
7588
{
7689
_cpu_preempt_disable();
7790
rt_hw_spin_lock(&lock->lock);
7891
}
7992
RTM_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+
*/
8199
void rt_spin_unlock(struct rt_spinlock *lock)
82100
{
83101
rt_hw_spin_unlock(&lock->lock);
84102
_cpu_preempt_enable();
85103
}
86104
RTM_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+
*/
88116
rt_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
}
99127
RTM_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+
*/
101136
void 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)
108143
RTM_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
*/
113150
struct 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+
*/
118160
struct 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
*/
126170
rt_base_t rt_cpus_lock(void)
127171
{
@@ -148,7 +192,9 @@ rt_base_t rt_cpus_lock(void)
148192
RTM_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
*/
153199
void rt_cpus_unlock(rt_base_t level)
154200
{

0 commit comments

Comments
 (0)