Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
在你之后
rt-thread
提交
914244f3
R
rt-thread
项目概览
在你之后
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
914244f3
编写于
7月 29, 2013
作者:
B
bernard
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of
https://github.com/RT-Thread/rt-thread
上级
d74dee0d
a431a256
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
56 addition
and
13 deletion
+56
-13
bsp/K60Fxxxx/drivers/drv_uart.c
bsp/K60Fxxxx/drivers/drv_uart.c
+49
-13
components/drivers/serial/serial.c
components/drivers/serial/serial.c
+7
-0
未找到文件。
bsp/K60Fxxxx/drivers/drv_uart.c
浏览文件 @
914244f3
...
...
@@ -39,46 +39,83 @@ static struct k60_serial_device _k60_node =
static
rt_err_t
_configure
(
struct
rt_serial_device
*
serial
,
struct
serial_configure
*
cfg
)
{
unsigned
int
reg_C1
=
0
,
reg_
BDH
=
0
,
reg_BDL
=
0
,
reg_S2
;
unsigned
int
reg_C1
=
0
,
reg_
C3
=
0
,
reg_C4
=
0
,
reg_BDH
=
0
,
reg_BDL
=
0
,
reg_S2
,
reg_BRFA
=
0
;
unsigned
int
cal_SBR
=
0
;
UART_Type
*
uart_reg
;
/* ref : drivers\system_MK60F12.c Line 64 ,BusClock = 60MHz
* calculate baud_rate
*/
uart_reg
=
((
struct
k60_serial_device
*
)
serial
->
parent
.
user_data
)
->
baseAddress
;
/* calc SBR */
cal_SBR
=
60000000
/
(
16
*
cfg
->
baud_rate
);
reg_BDH
=
(
cal_SBR
&
0x1FFF
)
>>
8
&
0x00FF
;
reg_BDL
=
cal_SBR
&
0x00FF
;
/
/calc baud_rate
/
* calc baud_rate */
reg_BDH
=
(
cal_SBR
&
0x1FFF
)
>>
8
&
0x00FF
;
reg_BDL
=
cal_SBR
&
0x00FF
;
//calc bit_order
/* fractional divider */
reg_BRFA
=
((
60000
*
32000
)
/
(
cfg
->
baud_rate
*
16
))
-
(
cal_SBR
*
32
);
reg_C4
=
(
unsigned
char
)(
reg_BRFA
&
0x001F
);
/*
* set bit order
*/
if
(
cfg
->
bit_order
==
BIT_ORDER_LSB
)
reg_S2
&=
~
(
UART_S2_MSBF_MASK
<<
UART_S2_MSBF_SHIFT
);
else
if
(
cfg
->
bit_order
==
BIT_ORDER_MSB
)
reg_S2
|=
UART_S2_MSBF_MASK
<<
UART_S2_MSBF_SHIFT
;
//calc data_bits
/*
* set data_bits
*/
if
(
cfg
->
data_bits
==
DATA_BITS_8
)
reg_C1
&=
~
(
UART_C1_M_MASK
<<
UART_C1_M_SHIFT
);
else
if
(
cfg
->
data_bits
==
DATA_BITS_9
)
reg_C1
|=
UART_C1_M_MASK
<<
UART_C1_M_SHIFT
;
//clac parity
/*
* set parity
*/
if
(
cfg
->
parity
==
PARITY_NONE
)
reg_C1
&=
~
(
UART_C1_PE_MASK
<<
UART_C1_PE_SHIFT
);
{
reg_C1
&=
~
(
UART_C1_PE_MASK
);
}
else
{
reg_C1
&=
~
(
UART_C1_PE_MASK
<<
UART_C1_PE_SHIFT
);
/* first ,set parity enable bit */
reg_C1
|=
(
UART_C1_PE_MASK
);
/* second ,determine parity odd or even*/
if
(
cfg
->
parity
==
PARITY_ODD
)
reg_C1
|=
UART_C1_PT_MASK
<<
UART_C1_PT_SHIFT
;
reg_C1
|=
UART_C1_PT_MASK
;
if
(
cfg
->
parity
==
PARITY_EVEN
)
reg_C1
&=
~
(
UART_C1_PT_MASK
<<
UART_C1_PT_SHIFT
);
reg_C1
&=
~
(
UART_C1_PT_MASK
);
}
/*
* set stop bit
* not supported on Tower? need ur help!
*/
/*
* set NZR mode
* not tested
*/
if
(
cfg
->
invert
!=
NRZ_NORMAL
)
{
/* not in normal mode ,set inverted polarity */
reg_C3
|=
UART_C3_TXINV_MASK
;
}
switch
(
(
int
)
uart_reg
)
{
/* Tower board use UART5 for communication
* if you're using other board
* set clock and pin map for UARTx
*/
case
UART5_BASE
:
//set UART5 clock
...
...
@@ -96,6 +133,7 @@ static rt_err_t _configure(struct rt_serial_device *serial, struct serial_config
uart_reg
->
BDH
=
reg_BDH
;
uart_reg
->
BDL
=
reg_BDL
;
uart_reg
->
C1
=
reg_C1
;
uart_reg
->
C4
=
reg_C4
;
uart_reg
->
S2
=
reg_S2
;
uart_reg
->
S2
=
0
;
...
...
@@ -203,8 +241,6 @@ void rt_hw_uart_init(void)
rt_hw_serial_register
(
&
_k60_serial
,
"uart5"
,
RT_DEVICE_FLAG_RDWR
|
RT_DEVICE_FLAG_INT_RX
|
RT_DEVICE_FLAG_STREAM
,
(
void
*
)
&
_k60_node
);
rt_device_control
(
&
_k60_serial
.
parent
,
RT_DEVICE_CTRL_SET_INT
,
0
);
}
void
rt_hw_console_output
(
const
char
*
str
)
...
...
components/drivers/serial/serial.c
浏览文件 @
914244f3
...
...
@@ -145,7 +145,14 @@ static rt_err_t rt_serial_init(struct rt_device *dev)
serial_ringbuffer_init
(
serial
->
int_rx
);
if
(
dev
->
flag
&
RT_DEVICE_FLAG_INT_TX
)
{
/* not supported yet */
/*
serial->ops->control(serial, RT_DEVICE_CTRL_SET_INT, (void *)RT_NULL);
serial_ringbuffer_init(serial->int_tx);
serial->int_sending_flag = RT_FALSE;
*/
}
if
(
dev
->
flag
&
RT_DEVICE_FLAG_DMA_TX
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录