Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
rt-thread
提交
5aeedc4f
R
rt-thread
项目概览
BaiXuePrincess
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
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,发现更多精彩内容 >>
提交
5aeedc4f
编写于
2月 27, 2014
作者:
B
Bernard Xiong
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #241 from bright-pan/master
Add RTS/CTS option in the serial framework.
上级
3d80e414
a4cd9495
变更
4
展开全部
隐藏空白更改
内联
并排
Showing
4 changed file
with
493 addition
and
178 deletion
+493
-178
bsp/stm32f10x/drivers/board.h
bsp/stm32f10x/drivers/board.h
+2
-0
bsp/stm32f10x/drivers/usart.c
bsp/stm32f10x/drivers/usart.c
+455
-129
components/drivers/include/drivers/serial.h
components/drivers/include/drivers/serial.h
+21
-12
components/drivers/serial/serial.c
components/drivers/serial/serial.c
+15
-37
未找到文件。
bsp/stm32f10x/drivers/board.h
浏览文件 @
5aeedc4f
...
...
@@ -41,6 +41,8 @@
#define RT_USING_UART1
#define RT_USING_UART2
#define RT_USING_UART3
//#define RT_USING_UART4
//#define RT_USING_UART5
#endif
/* __BOARD_H__ */
...
...
bsp/stm32f10x/drivers/usart.c
浏览文件 @
5aeedc4f
此差异已折叠。
点击以展开。
components/drivers/include/drivers/serial.h
浏览文件 @
5aeedc4f
...
...
@@ -29,6 +29,7 @@
#define __SERIAL_H__
#include <rtthread.h>
#include <rtdevice.h>
#define BAUD_RATE_4800 4800
#define BAUD_RATE_9600 9600
...
...
@@ -55,6 +56,11 @@
#define NRZ_NORMAL 0
/* Non Return to Zero : normal mode */
#define NRZ_INVERTED 1
/* Non Return to Zero : inverted mode */
#define HW_CONTROL_NONE 0
#define HW_CONTROL_RTS 1
#define HW_CONTROL_CTS 2
#define HW_CONTROL_RTS_CTS 3
#ifndef RT_SERIAL_RB_BUFSZ
#define RT_SERIAL_RB_BUFSZ 64
#endif
...
...
@@ -75,21 +81,23 @@
#define RT_SERIAL_TX_DATAQUEUE_LWM 30
/* Default config for serial_configure structure */
#define RT_SERIAL_CONFIG_DEFAULT \
{ \
BAUD_RATE_115200,
/* 115200 bits/s */
\
DATA_BITS_8,
/* 8 databits */
\
STOP_BITS_1,
/* 1 stopbit */
\
PARITY_NONE,
/* No parity */
\
BIT_ORDER_LSB,
/* LSB first sent */
\
NRZ_NORMAL,
/* Normal mode */
\
0 \
#define RT_SERIAL_CONFIG_DEFAULT \
{ \
BAUD_RATE_115200,
/* 115200 bits/s */
\
DATA_BITS_8,
/* 8 databits */
\
STOP_BITS_1,
/* 1 stopbit */
\
PARITY_NONE,
/* No parity */
\
BIT_ORDER_LSB,
/* LSB first sent */
\
NRZ_NORMAL,
/* Normal mode */
\
HW_CONTROL_NONE,
/* Hardware control */
\
0 \
}
struct
serial_ringbuffer
{
rt_uint8_t
buffer
[
RT_SERIAL_RB_BUFSZ
];
rt_uint16_t
put_index
,
get_index
;
struct
rt_ringbuffer
rb
;
rt_uint8_t
*
pool
;
rt_uint16_t
size
;
};
struct
serial_configure
...
...
@@ -100,7 +108,8 @@ struct serial_configure
rt_uint32_t
parity
:
2
;
rt_uint32_t
bit_order
:
1
;
rt_uint32_t
invert
:
1
;
rt_uint32_t
reserved
:
20
;
rt_uint32_t
hw_control
:
2
;
rt_uint32_t
reserved
:
18
;
};
struct
rt_serial_device
...
...
components/drivers/serial/serial.c
浏览文件 @
5aeedc4f
...
...
@@ -25,6 +25,9 @@
* 2012-11-23 bernard fix compiler warning.
* 2013-02-20 bernard use RT_SERIAL_RB_BUFSZ to define
* the size of ring buffer.
* 2014-02-26 bright use DeviceDriver ringbuffer.
* add hardware flow support.
* use new struct serial_ringbuffer.
*/
#include <rthw.h>
...
...
@@ -33,9 +36,7 @@
rt_inline
void
serial_ringbuffer_init
(
struct
serial_ringbuffer
*
rbuffer
)
{
rt_memset
(
rbuffer
->
buffer
,
0
,
sizeof
(
rbuffer
->
buffer
));
rbuffer
->
put_index
=
0
;
rbuffer
->
get_index
=
0
;
rt_ringbuffer_init
(
&
rbuffer
->
rb
,
rbuffer
->
pool
,
rbuffer
->
size
);
}
rt_inline
void
serial_ringbuffer_putc
(
struct
serial_ringbuffer
*
rbuffer
,
...
...
@@ -45,17 +46,8 @@ rt_inline void serial_ringbuffer_putc(struct serial_ringbuffer *rbuffer,
/* disable interrupt */
level
=
rt_hw_interrupt_disable
();
rbuffer
->
buffer
[
rbuffer
->
put_index
]
=
ch
;
rbuffer
->
put_index
=
(
rbuffer
->
put_index
+
1
)
&
(
RT_SERIAL_RB_BUFSZ
-
1
);
/* if the next position is read index, discard this 'read char' */
if
(
rbuffer
->
put_index
==
rbuffer
->
get_index
)
{
rbuffer
->
get_index
=
(
rbuffer
->
get_index
+
1
)
&
(
RT_SERIAL_RB_BUFSZ
-
1
);
}
/* enable interrupt */
rt_ringbuffer_putchar
(
&
rbuffer
->
rb
,
ch
);
// enable interrupt
rt_hw_interrupt_enable
(
level
);
}
...
...
@@ -63,25 +55,11 @@ rt_inline int serial_ringbuffer_putchar(struct serial_ringbuffer *rbuffer,
char
ch
)
{
rt_base_t
level
;
rt_uint16_t
next_index
;
//
rt_uint16_t next_index;
/* disable interrupt */
level
=
rt_hw_interrupt_disable
();
next_index
=
(
rbuffer
->
put_index
+
1
)
&
(
RT_SERIAL_RB_BUFSZ
-
1
);
if
(
next_index
!=
rbuffer
->
get_index
)
{
rbuffer
->
buffer
[
rbuffer
->
put_index
]
=
ch
;
rbuffer
->
put_index
=
next_index
;
}
else
{
/* enable interrupt */
rt_hw_interrupt_enable
(
level
);
return
-
1
;
}
rt_ringbuffer_putchar
(
&
rbuffer
->
rb
,
ch
);
/* enable interrupt */
rt_hw_interrupt_enable
(
level
);
...
...
@@ -90,17 +68,14 @@ rt_inline int serial_ringbuffer_putchar(struct serial_ringbuffer *rbuffer,
rt_inline
int
serial_ringbuffer_getc
(
struct
serial_ringbuffer
*
rbuffer
)
{
int
ch
;
int
ch
=
0
;
rt_base_t
level
;
ch
=
-
1
;
/* disable interrupt */
level
=
rt_hw_interrupt_disable
();
if
(
rbuffer
->
get_index
!=
rbuffer
->
put_index
)
{
ch
=
rbuffer
->
buffer
[
rbuffer
->
get_index
];
rbuffer
->
get_index
=
(
rbuffer
->
get_index
+
1
)
&
(
RT_SERIAL_RB_BUFSZ
-
1
);
}
/* get char */
if
(
!
rt_ringbuffer_getchar
(
&
rbuffer
->
rb
,
(
rt_uint8_t
*
)
&
ch
))
ch
=
-
1
;
/* enable interrupt */
rt_hw_interrupt_enable
(
level
);
...
...
@@ -113,7 +88,10 @@ rt_inline rt_uint32_t serial_ringbuffer_size(struct serial_ringbuffer *rbuffer)
rt_base_t
level
;
level
=
rt_hw_interrupt_disable
();
size
=
rt_ringbuffer_space_len
(
&
rbuffer
->
rb
);
/*
size = (rbuffer->put_index - rbuffer->get_index) & (RT_SERIAL_RB_BUFSZ - 1);
*/
rt_hw_interrupt_enable
(
level
);
return
size
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录