Skip to content

Commit e6c2ed4

Browse files
authored
Merge pull request #18 from mysterywolf/master
add English version
2 parents c5a71d9 + 7a78b8c commit e6c2ed4

37 files changed

+1854
-92
lines changed

README.md

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,51 @@
1-
# kernel samples
1+
# kernel samples package
22

3-
## 1、介绍
3+
## 1. Introduction
44

5-
这个软件包包含了内核相关的使用示例代码。
6-
7-
### 1.1 例程说明
5+
This package contains sample code related to the RT-Thread kernel.
86

97
| 文件 | 说明 |
108
| ---- | ---- |
11-
| dynmem_sample.c | 动态堆内存的使用 |
12-
| event_sample.c | 事件的使用 |
13-
| idlehook_sample.c | 空闲任务钩子的使用 |
14-
| interrupt_sample.c | 使用开关中断进行线程间同步 |
15-
| mailbox_sample.c | 邮箱的使用 |
16-
| memp_sample.c | 内存池的使用 |
17-
| msgq_sample.c | 消息队列的使用 |
18-
| mutex_sample.c | 互斥量的使用 |
19-
| priority_inversion.c | 互斥量解决优先级翻转问题 |
20-
| producer_consumer.c | 生产者消费者模型 |
21-
| scheduler_hook.c | 调度器钩子的使用 |
22-
| semaphore_sample.c | 信号量的使用|
23-
| signal_sample.c | 信号的使用 |
24-
| thread_sample.c | 线程的使用 |
25-
| timer_sample.c | 定时器的使用 |
26-
| timeslice_sample.c | 线程时间片 |
27-
28-
### 1.2 许可证
29-
30-
kernel samples package 遵循 Apache license v2.0 许可,详见 `LICENSE` 文件。
9+
| dynmem_sample.c | dynamic memory allocation & management |
10+
| event_sample.c | event |
11+
| idlehook_sample.c | idle thread hook function |
12+
| interrupt_sample.c | disable / enable interrupt |
13+
| mailbox_sample.c | mailbox |
14+
| memp_sample.c | memory pool |
15+
| msgq_sample.c | message queue |
16+
| mutex_sample.c | mutex |
17+
| priority_inversion.c | prevent priority inversions |
18+
| producer_consumer.c | producer & consumer problem |
19+
| scheduler_hook.c | scheduler hook function |
20+
| semaphore_sample.c | semaphore |
21+
| signal_sample.c | signal |
22+
| thread_sample.c | thread |
23+
| timer_sample.c | timer |
24+
| timeslice_sample.c | time-slicing |
3125

32-
### 1.3 依赖
3326

34-
依赖系统内核对应的模块。
3527

36-
## 2、如何打开 kernel samples
28+
## 2. How to use kernel samples package
3729

38-
使用 kernel samples package 需要在 RT-Thread 的 menuconfig 配置菜单中选择它,具体路径如下:
30+
You can use [ENV tool](https://www.rt-thread.io/download.html?download=Env) or [RT-Studio IDE](https://www.rt-thread.io/studio.html) to activate this package:
3931

4032
```
4133
RT-Thread online packages
4234
miscellaneous packages --->
4335
samples: kernel and components samples --->
4436
a kernel_samples package for rt-thread --->
45-
4637
```
4738

48-
然后让 RT-Thread 的包管理器自动更新,或者使用 `pkgs --update` 命令更新包到 BSP 中。
4939

50-
## 3、使用 kernel samples
5140

52-
在打开 kernel samples package 后,当进行 BSP 编译时,选择的软件包相关源代码会被加入到 BSP 工程中进行编译。
41+
## 3. License
42+
43+
This package is an open source software and has been licensed under Apache License Version 2.0.
5344

54-
## 4、注意事项
5545

56-
暂无。
5746

58-
## 5、联系方式 & 感谢
47+
## 4. Maintained by
5948

60-
* 维护:yangjie11
61-
* 主页:https://github.com/RT-Thread-packages/kernel-sample.git
49+
* Yang Jie: https://github.com/yangjie11
50+
* Meco Man: https://github.com/mysterywolf
51+
* https://github.com/RT-Thread-packages/kernel-sample

README_zh.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# kernel samples
2+
3+
## 1、介绍
4+
5+
这个软件包包含了内核相关的使用示例代码。
6+
7+
### 1.1 例程说明
8+
9+
| 文件 | 说明 |
10+
| ---- | ---- |
11+
| dynmem_sample.c | 动态堆内存的使用 |
12+
| event_sample.c | 事件的使用 |
13+
| idlehook_sample.c | 空闲任务钩子的使用 |
14+
| interrupt_sample.c | 使用开关中断进行线程间同步 |
15+
| mailbox_sample.c | 邮箱的使用 |
16+
| memp_sample.c | 内存池的使用 |
17+
| msgq_sample.c | 消息队列的使用 |
18+
| mutex_sample.c | 互斥量的使用 |
19+
| priority_inversion.c | 互斥量解决优先级翻转问题 |
20+
| producer_consumer.c | 生产者消费者模型 |
21+
| scheduler_hook.c | 调度器钩子的使用 |
22+
| semaphore_sample.c | 信号量的使用|
23+
| signal_sample.c | 信号的使用 |
24+
| thread_sample.c | 线程的使用 |
25+
| timer_sample.c | 定时器的使用 |
26+
| timeslice_sample.c | 线程时间片 |
27+
28+
### 1.2 许可证
29+
30+
kernel samples package 遵循 Apache license v2.0 许可,详见 `LICENSE` 文件。
31+
32+
### 1.3 依赖
33+
34+
依赖系统内核对应的模块。
35+
36+
## 2、如何打开 kernel samples
37+
38+
使用 kernel samples package 需要在 RT-Thread 的 menuconfig 配置菜单中选择它,具体路径如下:
39+
40+
```
41+
RT-Thread online packages
42+
miscellaneous packages --->
43+
samples: kernel and components samples --->
44+
a kernel_samples package for rt-thread --->
45+
46+
```
47+
48+
然后让 RT-Thread 的包管理器自动更新,或者使用 `pkgs --update` 命令更新包到 BSP 中。
49+
50+
## 3、使用 kernel samples
51+
52+
在打开 kernel samples package 后,当进行 BSP 编译时,选择的软件包相关源代码会被加入到 BSP 工程中进行编译。
53+
54+
## 4、注意事项
55+
56+
暂无。
57+
58+
## 5、联系方式 & 感谢
59+
60+
* 维护:yangjie11
61+
* 主页:https://github.com/RT-Thread-packages/kernel-sample.git

SConscript

Lines changed: 11 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,15 @@
1+
import os
12
from building import *
23

3-
src = []
4-
cwd = GetCurrentDir()
5-
include_path = [cwd]
4+
# get current dir path
5+
cwd = GetCurrentDir()
66

7-
# add kernel samples.
8-
if GetDepend('KERNEL_SAMPLES_USING_THREAD'):
9-
src += ['thread_sample.c']
7+
# traversal subscript
8+
objs = []
9+
list = os.listdir(cwd)
10+
for d in list:
11+
path = os.path.join(cwd, d)
12+
if os.path.isfile(os.path.join(path, 'SConscript')):
13+
objs = objs + SConscript(os.path.join(d, 'SConscript'))
1014

11-
if GetDepend('KERNEL_SAMPLES_USING_SEMAPHORE'):
12-
src += ['semaphore_sample.c']
13-
14-
if GetDepend('KERNEL_SAMPLES_USING_MUTEX'):
15-
src += ['mutex_sample.c']
16-
17-
if GetDepend('KERNEL_SAMPLES_USING_MAILBOX'):
18-
src += ['mailbox_sample.c']
19-
20-
if GetDepend('KERNEL_SAMPLES_USING_EVENT'):
21-
src += ['event_sample.c']
22-
23-
if GetDepend('KERNEL_SAMPLES_USING_MESSAGEQUEUE'):
24-
src += ['msgq_sample.c']
25-
26-
if GetDepend('KERNEL_SAMPLES_USING_TIMER'):
27-
src += ['timer_sample.c']
28-
29-
if GetDepend('KERNEL_SAMPLES_USING_HEAP'):
30-
src += ['dynmem_sample.c']
31-
32-
if GetDepend('KERNEL_SAMPLES_USING_MEMPOOL'):
33-
src += ['memp_sample.c']
34-
35-
if GetDepend('KERNEL_SAMPLES_USING_IDLEHOOK'):
36-
src += ['idlehook_sample.c']
37-
38-
if GetDepend('KERNEL_SAMPLES_USING_SIGNAL'):
39-
src += ['signal_sample.c']
40-
41-
if GetDepend('KERNEL_SAMPLES_USING_INTERRUPT'):
42-
src += ['interrupt_sample.c']
43-
44-
if GetDepend('KERNEL_SAMPLES_USING_PRI_INVERSION'):
45-
src += ['priority_inversion.c']
46-
47-
if GetDepend('KERNEL_SAMPLES_USING_TIME_SLICE'):
48-
src += ['timeslice_sample.c']
49-
50-
if GetDepend('KERNEL_SAMPLES_USING_SCHEDULER_HOOK'):
51-
src += ['scheduler_hook.c']
52-
53-
if GetDepend('KERNEL_SAMPLES_USING_PRODUCER_CONSUMER'):
54-
src += ['producer_consumer.c']
55-
56-
group = DefineGroup('kernel-samples', src, depend = ['PKG_USING_KERNEL_SAMPLES'], CPPPATH = include_path)
57-
58-
Return('group')
15+
Return('objs')

en/SConscript

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from building import *
2+
3+
src = []
4+
cwd = GetCurrentDir()
5+
include_path = [cwd]
6+
7+
# add kernel samples.
8+
if GetDepend('KERNEL_SAMPLES_USING_THREAD'):
9+
src += ['thread_sample.c']
10+
11+
if GetDepend('KERNEL_SAMPLES_USING_SEMAPHORE'):
12+
src += ['semaphore_sample.c']
13+
14+
if GetDepend('KERNEL_SAMPLES_USING_MUTEX'):
15+
src += ['mutex_sample.c']
16+
17+
if GetDepend('KERNEL_SAMPLES_USING_MAILBOX'):
18+
src += ['mailbox_sample.c']
19+
20+
if GetDepend('KERNEL_SAMPLES_USING_EVENT'):
21+
src += ['event_sample.c']
22+
23+
if GetDepend('KERNEL_SAMPLES_USING_MESSAGEQUEUE'):
24+
src += ['msgq_sample.c']
25+
26+
if GetDepend('KERNEL_SAMPLES_USING_TIMER'):
27+
src += ['timer_sample.c']
28+
29+
if GetDepend('KERNEL_SAMPLES_USING_HEAP'):
30+
src += ['dynmem_sample.c']
31+
32+
if GetDepend('KERNEL_SAMPLES_USING_MEMPOOL'):
33+
src += ['memp_sample.c']
34+
35+
if GetDepend('KERNEL_SAMPLES_USING_IDLEHOOK'):
36+
src += ['idlehook_sample.c']
37+
38+
if GetDepend('KERNEL_SAMPLES_USING_SIGNAL'):
39+
src += ['signal_sample.c']
40+
41+
if GetDepend('KERNEL_SAMPLES_USING_INTERRUPT'):
42+
src += ['interrupt_sample.c']
43+
44+
if GetDepend('KERNEL_SAMPLES_USING_PRI_INVERSION'):
45+
src += ['priority_inversion.c']
46+
47+
if GetDepend('KERNEL_SAMPLES_USING_TIME_SLICE'):
48+
src += ['timeslice_sample.c']
49+
50+
if GetDepend('KERNEL_SAMPLES_USING_SCHEDULER_HOOK'):
51+
src += ['scheduler_hook.c']
52+
53+
if GetDepend('KERNEL_SAMPLES_USING_PRODUCER_CONSUMER'):
54+
src += ['producer_consumer.c']
55+
56+
group = DefineGroup('kernel-samples', src, depend = ['PKG_USING_KERNEL_SAMPLES_EN'], CPPPATH = include_path)
57+
58+
Return('group')

en/dynmem_sample.c

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (c) 2006-2018, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2018-08-24 yangjie the first version
9+
* 2020-10-17 Meco Man translate to English comment
10+
*/
11+
12+
/*
13+
* Demo: dynamic memory management
14+
*
15+
* This demo creates a dynamic thread to allocate and free memory.
16+
* Each time it allocates more memory, and it will end when it can't allocate any memory.
17+
*
18+
* read more:
19+
* https://www.rt-thread.io/document/site/memory/memory/#memory-management
20+
*/
21+
22+
#include <rtthread.h>
23+
24+
#define THREAD_PRIORITY 25
25+
#define THREAD_STACK_SIZE 512
26+
#define THREAD_TIMESLICE 5
27+
28+
/* thread #1 entry function*/
29+
void thread1_entry(void *parameter)
30+
{
31+
int i;
32+
char *ptr = RT_NULL; /* memory's pointer */
33+
34+
for (i = 0; ; i++)
35+
{
36+
/* allocate memory of (1 << i) bytes */
37+
ptr = rt_malloc(1 << i);
38+
39+
if (ptr != RT_NULL)
40+
{
41+
/* if memory allocated successfully */
42+
rt_kprintf("get memory :%d byte\n", (1 << i));
43+
rt_free(ptr); /* free memory */
44+
rt_kprintf("free memory :%d byte\n", (1 << i));
45+
ptr = RT_NULL;
46+
}
47+
else
48+
{
49+
rt_kprintf("try to get %d byte memory failed!\n", (1 << i));
50+
return;
51+
}
52+
}
53+
}
54+
55+
int dynmem_sample(void)
56+
{
57+
rt_thread_t tid = RT_NULL;
58+
59+
/* create thread #1 */
60+
tid = rt_thread_create("thread1",
61+
thread1_entry, RT_NULL,
62+
THREAD_STACK_SIZE,
63+
THREAD_PRIORITY,
64+
THREAD_TIMESLICE);
65+
/*start thread #1 */
66+
if (tid != RT_NULL)
67+
rt_thread_startup(tid);
68+
69+
return 0;
70+
}
71+
72+
/* export the msh command */
73+
MSH_CMD_EXPORT(dynmem_sample, dynmem sample);

0 commit comments

Comments
 (0)