Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
rt-thread
提交
738871fd
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看板
提交
738871fd
编写于
3月 03, 2014
作者:
B
Bernard Xiong
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #243 from grissiom/serial-rollback
Revert "Merge pull request #241 from bright-pan/master"
上级
54b693b3
f615c1e9
变更
4
展开全部
隐藏空白更改
内联
并排
Showing
4 changed file
with
178 addition
and
493 deletion
+178
-493
bsp/stm32f10x/drivers/board.h
bsp/stm32f10x/drivers/board.h
+0
-2
bsp/stm32f10x/drivers/usart.c
bsp/stm32f10x/drivers/usart.c
+129
-455
components/drivers/include/drivers/serial.h
components/drivers/include/drivers/serial.h
+12
-21
components/drivers/serial/serial.c
components/drivers/serial/serial.c
+37
-15
未找到文件。
bsp/stm32f10x/drivers/board.h
浏览文件 @
738871fd
...
...
@@ -41,8 +41,6 @@
#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
浏览文件 @
738871fd
此差异已折叠。
点击以展开。
components/drivers/include/drivers/serial.h
浏览文件 @
738871fd
...
...
@@ -29,7 +29,6 @@
#define __SERIAL_H__
#include <rtthread.h>
#include <rtdevice.h>
#define BAUD_RATE_4800 4800
#define BAUD_RATE_9600 9600
...
...
@@ -56,11 +55,6 @@
#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
...
...
@@ -81,23 +75,21 @@
#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 */
\
HW_CONTROL_NONE,
/* Hardware control */
\
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 */
\
0 \
}
struct
serial_ringbuffer
{
struct
rt_ringbuffer
rb
;
rt_uint8_t
*
pool
;
rt_uint16_t
size
;
rt_uint8_t
buffer
[
RT_SERIAL_RB_BUFSZ
];
rt_uint16_t
put_index
,
get_index
;
};
struct
serial_configure
...
...
@@ -108,8 +100,7 @@ struct serial_configure
rt_uint32_t
parity
:
2
;
rt_uint32_t
bit_order
:
1
;
rt_uint32_t
invert
:
1
;
rt_uint32_t
hw_control
:
2
;
rt_uint32_t
reserved
:
18
;
rt_uint32_t
reserved
:
20
;
};
struct
rt_serial_device
...
...
components/drivers/serial/serial.c
浏览文件 @
738871fd
...
...
@@ -25,9 +25,6 @@
* 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>
...
...
@@ -36,7 +33,9 @@
rt_inline
void
serial_ringbuffer_init
(
struct
serial_ringbuffer
*
rbuffer
)
{
rt_ringbuffer_init
(
&
rbuffer
->
rb
,
rbuffer
->
pool
,
rbuffer
->
size
);
rt_memset
(
rbuffer
->
buffer
,
0
,
sizeof
(
rbuffer
->
buffer
));
rbuffer
->
put_index
=
0
;
rbuffer
->
get_index
=
0
;
}
rt_inline
void
serial_ringbuffer_putc
(
struct
serial_ringbuffer
*
rbuffer
,
...
...
@@ -46,8 +45,17 @@ rt_inline void serial_ringbuffer_putc(struct serial_ringbuffer *rbuffer,
/* disable interrupt */
level
=
rt_hw_interrupt_disable
();
rt_ringbuffer_putchar
(
&
rbuffer
->
rb
,
ch
);
// enable interrupt
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_hw_interrupt_enable
(
level
);
}
...
...
@@ -55,11 +63,25 @@ 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
();
rt_ringbuffer_putchar
(
&
rbuffer
->
rb
,
ch
);
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
;
}
/* enable interrupt */
rt_hw_interrupt_enable
(
level
);
...
...
@@ -68,14 +90,17 @@ rt_inline int serial_ringbuffer_putchar(struct serial_ringbuffer *rbuffer,
rt_inline
int
serial_ringbuffer_getc
(
struct
serial_ringbuffer
*
rbuffer
)
{
int
ch
=
0
;
int
ch
;
rt_base_t
level
;
ch
=
-
1
;
/* disable interrupt */
level
=
rt_hw_interrupt_disable
();
/* get char */
if
(
!
rt_ringbuffer_getchar
(
&
rbuffer
->
rb
,
(
rt_uint8_t
*
)
&
ch
))
ch
=
-
1
;
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
);
}
/* enable interrupt */
rt_hw_interrupt_enable
(
level
);
...
...
@@ -88,10 +113,7 @@ 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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录