www.linuxidc.com
第一章:范例
.......................................................................................................................... 1
1.00
安装
µ
C/OS-II
................................................................................................................. 1
1.01 INCLUDES.H
..................................................................................................... 2
1.02
不依赖于编译的数据类型
................................................................................ 2
1.03
全局变量
........................................................................................................... 3
1.04 OS_ENTER_CRITICAL()
和
OS_EXIT_CRITICAL()
....................................... 5
1.05
基于
PC
的服务
................................................................................................ 6
1.05.01
字符显示
...................................................................................................................... 6
1.05.02
花费时间的测量
.......................................................................................................... 6
1.05.03
其他½数
...................................................................................................................... 7
1.06
应用
µ
C/OS-II
的范例
...................................................................................... 7
1.07
例
1
.................................................................................................................... 8
1.07.01 main() ........................................................................................................................... 9
1.07.02 TaskStart() .................................................................................................................. 11
1.07.03 TaskN
()
.................................................................................................................. 13
1.08
例
2
................................................................................................................................... 14
1.08.01 main() ......................................................................................................................... 15
1.08.02TaskStart() ................................................................................................................... 16
1.08.03 TaskN() ....................................................................................................................... 17
1.09
例
3
................................................................................................................................... 21
1.09.01 main() ......................................................................................................................... 21
1.09.02
任务
............................................................................................................................ 22
1.09.03
注意
............................................................................................................................ 25
第二章实时系统概念
......................................................................................................... 28
2.0
前后台系统(
F
OREGROUND
/B
ACKGROUND
S
YSTEM
)
...................................... 28
2.1
代码的临界段
................................................................................................... 29
2.2
资源
................................................................................................................... 29
2.3
共享资源
........................................................................................................... 29
2.4
多任务
............................................................................................................... 29
2.5
任务
................................................................................................................... 30
2.6
任务切换
(C
ONTEXT
S
WITCH OR
T
ASK
S
WITCH
)
.................................................... 31
2.7
内核(
K
ERNEL
)
............................................................................................... 31
2.8
调度(
S
CHEDULER
)
......................................................................................... 31
2.9
不可剥夺型内核(
N
ON
-P
REEMPTIVE
K
ERNEL
)
.............................................. 32
2.10
可剥夺型内核
................................................................................................. 33
2.11
可重入性(
R
EENTRANCY
)
.............................................................................. 33
2.12
时间片½番调度法
......................................................................................... 35
2.13
任务优先级
..................................................................................................... 35
2.14
静态优先级
..................................................................................................... 35
2.15
动态优先级
..................................................................................................... 36
Linux公社(LinuxIDC.com)
是包括Ubuntu,Fedora,SUSE技术,最新IT资讯等Linux专业类½站。
www.linuxidc.com
2.16
优先级反½
..................................................................................................... 36
2.17
任务优先级分配
............................................................................................. 38
2.18
互斥条件
......................................................................................................... 39
2.18.1
关中断和开中断
.......................................................................................................... 39
2.18.2
测试并½½
.................................................................................................................. 40
2.18.3
禁止
,
然后允许任务切换
............................................................................................. 41
2.18.4
信号量
(Semaphores).................................................................................................... 42
2.19
2.20
2.21
2.22
2.23
2.24
2.25
2.26
2.27
2.28
2.29
2.30
2.31
2.32
2.33
2.34
2.35
死锁
(
或抱死
)
(
D
EADLOCK
(
OR
D
EADLY
E
MBRACE
)
)
..................................... 46
同步
................................................................................................................. 46
事件标志
(E
VENT
F
LAGS
)
.................................................................................. 48
任务间的通讯
(I
NTERTASK
C
OMMUNICATION
)
................................................... 49
消息邮箱
(M
ESSAGE
M
AIL BOXES
)
..................................................................... 49
消息队列
(M
ESSAGE
Q
UEUE
)
............................................................................ 50
中断
................................................................................................................. 51
中断延迟
......................................................................................................... 51
中断响应
......................................................................................................... 52
中断恢复时间
(I
NTERRUPT
R
ECOVERY
)
............................................................. 53
中断延迟、响应和恢复
................................................................................. 53
中断处理时间
................................................................................................. 53
非屏½中断
(NMI)
........................................................................................... 54
时钟节拍
(C
LOCK
T
ICK
)....................................................................................
56
对存储器的需求
............................................................................................. 58
½用实时内核的优缺点
................................................................................. 59
实时系统小结
................................................................................................. 60
第三章内核结构
................................................................................................................... 61
3.0
临界段
(C
RITICAL
S
ECTIONS
)
............................................................................... 61
3.1
任务
................................................................................................................... 61
3.2
任务状态
........................................................................................................... 63
3.3
任务控制块(
T
ASK
C
ONTROL
B
LOCKS
, OS_TCB
S
)
.......................................... 64
3.4
就绪表(
R
EADY
L
IST
)
...................................................................................... 67
3.5
任务调度(
T
ASK
S
CHEDULING
)
....................................................................... 70
3.6
给调度器上锁和开锁
(L
OCKING AND
U
N
L
OCKING THE
S
CHEDULER
)
................. 71
3.7
空闲任务
(I
DLE
T
ASK
)
......................................................................................... 73
3.8
统计任务
........................................................................................................... 73
3.9
Μ
C/OS
中的中断处理
........................................................................................ 77
3.10
时钟节拍
......................................................................................................... 81
3.11
Μ
C/OS-
Ⅱ初始化
.............................................................................................. 85
3.12
Μ
C/OS-
Ⅱ的启动
.............................................................................................. 85
3.13
获取½前
Μ
C/OS-
Ⅱ的版本号
........................................................................ 88
3.14 OSE
VENT
???()
½数
.......................................................................................... 89
第四章任务管理
................................................................................................................... 90
Linux公社(LinuxIDC.com)
是包括Ubuntu,Fedora,SUSE技术,最新IT资讯等Linux专业类½站。
www.linuxidc.com
4.0
4.1
4.2
4.3
4.4
4.5
4.6
4.7
4.8
4.9
建立任务,
OST
ASK
C
REATE
()
............................................................................ 91
建立任务,
OST
ASK
C
REATE
E
XT
()
...................................................................... 95
任务堆栈
........................................................................................................... 98
堆栈检验,
OST
ASK
S
TK
C
HK
()
......................................................................... 100
删除任务,
OST
ASK
D
EL
()
................................................................................ 103
请求删除任务,
OST
ASK
D
EL
R
EQ
()
................................................................. 106
改变任务的优先级,
OST
ASK
C
HANGE
P
RIO
()
................................................. 109
挂起任务,
OST
ASK
S
USPEND
()
........................................................................ 112
恢复任务,
OST
ASK
R
ESUME
()
......................................................................... 113
获得有关任务的信息,
OST
ASK
Q
UERY
()........................................................
115
第五章时间管理
................................................................................................................. 117
5.0
5.1
5.2
5.3
任务延时½数,
OST
IME
D
LY
()
........................................................................ 117
按时分秒延时½数
OST
IME
D
LY
HMSM().......................................................
118
让处在延时期的任务结束延时,
OST
IME
D
LY
R
ESUME
()
............................... 120
系统时间,
OST
IME
G
ET
()
和
OST
IME
S
ET
()
..................................................... 122
第六章任务之间的通讯与同步
................................................................................. 123
6.0
6.1
6.2
6.3
6.4
6.5
事件控制块
ECB
............................................................................................. 124
初始化一个事件控制块,
OSE
VENT
W
AIT
L
IST
I
NIT
()
....................................... 127
½一个任务进入就绪态,
OSE
VENT
T
ASK
R
DY
()
.............................................. 128
½一个任务进入等待某事件发生状态
, OSE
VENT
T
ASK
W
AIT
().......................
130
由于等待超时而将任务½为就绪态
, OSE
VENT
TO()
..................................... 131
信号量
............................................................................................................. 131
6.5.1
建立一个信号量
, OSSemCreate() ............................................................................... 132
6.5.2
等待一个信号量
, OSSemPend() ................................................................................. 133
6.5.3
发送一个信号量
, OSSemPost() .................................................................................. 135
6.5.4
无等待地请求一个信号量
, OSSemAccept() ............................................................... 136
6.5.5
查询一个信号量的½前状态
, OSSemQuery() ............................................................ 137
6.6
邮箱
.................................................................................................................................. 138
6.6.1
建立一个邮箱,
OSMboxCreate() .............................................................................. 139
6.6.2
等待一个邮箱中的消息,
OSMboxPend() ................................................................. 139
6.6.3
发送一个消息到邮箱中,
OSMboxPost() .................................................................. 141
6.6.4
无等待地从邮箱中得到一个消息
, OSMboxAccept() ................................................ 143
6.6.5
查询一个邮箱的状态
, OSMboxQuery() ..................................................................... 143
6.6.6
用邮箱½二值信号量
.................................................................................................. 144
6.6.7
用邮箱实现延时,而不½用
OSTimeDly() ................................................................ 145
6.7
消息队列
......................................................................................................................... 146
6.7.1
建立一个消息队列,
OSQCreate() ............................................................................. 149
6.7.2
等待一个消息队列中的消息,
OSQPend() ............................................................... 151
6.7.3
向消息队列发送一个消息(
FIFO
)
OSQPost() ..................................................... 153
,
6.7.4
向消息队列发送一个消息(后进先出
LIFO
)
OSQPostFront() ............................ 155
,
6.7.5
无等待地从一个消息队列中取得消息
, OSQAccept() ............................................... 156
Linux公社(LinuxIDC.com)
是包括Ubuntu,Fedora,SUSE技术,最新IT资讯等Linux专业类½站。
www.linuxidc.com
6.7.6
清空一个消息队列
, OSQFlush() ................................................................................ 157
6.7.7
查询一个消息队列的状态,
OSQQuery() ................................................................. 158
6.7.8
½用消息队列读取模拟量的值
.................................................................................. 159
6.7.9
½用一个消息队列½为计数信号量
.......................................................................... 160
第七章 内存管理
............................................................................................................... 162
7.0
内存控制块
..................................................................................................... 163
7.1
建立一个内存分区,
OSM
EM
C
REATE
()
.......................................................... 164
7.2
分配一个内存块,
OSM
EM
G
ET
()
................................................................... 166
7.3
释放一个内存块,
OSM
EM
P
UT
()
................................................................... 168
7.4
查询一个内存分区的状态,
OSM
EM
Q
UERY
()
............................................... 169
7.5 U
SING
M
EMORY
P
ARTITIONS
............................................................................... 169
7.6
等待一个内存块
............................................................................................. 171
第八章 移植
µ
C/OS-Ⅱ
................................................................................................. 174
8.0
开发工具
......................................................................................................... 175
8.1
目½和文件
..................................................................................................... 175
8.2 INCLUDES.H
................................................................................................... 176
8.3 OS_CPU.H
....................................................................................................... 176
8.3.1
8.3.2
8.3.3
8.3.4
8.4.1
8.4.2
8.4.3
8.4.4
8.5.1
8.5.2
8.5.3
8.5.4
8.5.5
8.5.6
与编译器相关的数据类型
................................................................................... 177
OS_ENTER_CRITICAL()
和
OS_EXIT_CRITICAL()............................................ 178
OS_STK_GROWTH .............................................................................................. 179
OS_TASK_SW() ..................................................................................................... 179
OSStartHighRdy() ................................................................................................. 180
OSCtxSw() ............................................................................................................. 181
OSIntCtxSw() ........................................................................................................ 182
OSTickISR() ........................................................................................................... 184
OSTaskStkInt()....................................................................................................... 185
OSTaskCreateHook()............................................................................................. 187
OSTaskDelHook().................................................................................................. 188
OSTaskSwHook()................................................................................................... 188
OSTaskStatHook() ................................................................................................. 188
OSTimeTickHook() ................................................................................................ 188
8.4 OS_CPU_A.ASM
............................................................................................................ 180
8.5 OS_CPU_C.C
................................................................................................................. 185
第九章
µ
C/OS-II
在
80X86
上的移植
................................................................... 193
9.0
开发工具
......................................................................................................... 195
9.1
目½和文件
..................................................................................................... 195
9.2 INCLUDES.H
文件
.......................................................................................... 195
9.3 OS_CPU.H
文件
.............................................................................................. 196
9.3.1
数据类型
..................................................................................................................... 199
Linux公社(LinuxIDC.com)
是包括Ubuntu,Fedora,SUSE技术,最新IT资讯等Linux专业类½站。
www.linuxidc.com
9.3.2
代码临界区
................................................................................................................. 199
9.3.3
堆栈增长方向
............................................................................................................. 200
9.3.4 OS_TASK_SW() ............................................................................................................ 200
9.3.5
时钟节拍的发生频率
................................................................................................. 200
9.4 OS_CPU_A.ASM
............................................................................................................ 200
9.4.1 OSStartHighRdy() ........................................................................................................ 200
9.4.2 OSCtxSw() .................................................................................................................... 202
9.4.3 OSIntCtxSw() ............................................................................................................... 203
9.4.4 OSTickISR().................................................................................................................. 207
9.5 OS_CPU_C.C
................................................................................................................. 211
9.5.1 OSTaskStkInit() ............................................................................................................ 212
9.6
内存占用
......................................................................................................... 214
9.7
运行时间
......................................................................................................... 214
第十章从
µ
C/OS
升级到
µ
C/OS-II
.................................................................... 226
10.0
目½和文件
................................................................................................... 226
10.1 INCLUDES.H
................................................................................................. 227
10.2 OS_CPU.H
..................................................................................................... 227
10.2.1
与编译有关的数据类型
s ........................................................................................ 227
10.2.2 OS_ENTER_CRITICAL()
和
OS_EXIT_CRITICAL()................................................. 229
10.2.3 OS_STK_GROWTH ................................................................................................... 229
10.2.4 OS_TASK_SW() .......................................................................................................... 229
10.2.5 OS_FAR ...................................................................................................................... 229
10.3 OS_CPU_A.ASM
.......................................................................................................... 230
10.3.1 OSStartHighRdy() ...................................................................................................... 230
10.3.2 OSCtxSw() .................................................................................................................. 231
10.3.3 OSIntCtxSw() ............................................................................................................. 231
10.3.4 OSTickISR()................................................................................................................ 232
10.4 OS_CPU_C.C
............................................................................................................... 232
10.4.1 OSTaskStkInit() .......................................................................................................... 232
10.4.2 OSTaskCreateHook().................................................................................................. 234
10.4.3 OSTaskDelHook()....................................................................................................... 235
10.4.4 OSTaskSwHook()........................................................................................................ 235
10.4.5 OSTaskStatHook() ...................................................................................................... 236
10.4.6 OSTimeTickHook() ..................................................................................................... 236
10.5
总结
................................................................................................................................ 236
第
11
章参考手册
............................................................................................................... 238
第
12
章配½手册
............................................................................................................... 289
Linux公社(LinuxIDC.com)
是包括Ubuntu,Fedora,SUSE技术,最新IT资讯等Linux专业类½站。
评论