Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Mr_Pangza
rt-thread
提交
a8106442
R
rt-thread
项目概览
Mr_Pangza
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
2
Star
1
Fork
1
代码
文件
提交
分支
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,发现更多精彩内容 >>
提交
a8106442
编写于
9月 21, 2014
作者:
wuyangyong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update uart driver.
上级
9da1668c
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
73 addition
and
27 deletion
+73
-27
bsp/CME_M7/drivers/uart.c
bsp/CME_M7/drivers/uart.c
+73
-27
未找到文件。
bsp/CME_M7/drivers/uart.c
浏览文件 @
a8106442
...
...
@@ -29,7 +29,7 @@ struct CME_M7_uart uart2 =
static
struct
rt_serial_device
serial2
;
#endif
/* RT_USING_UART2 */
static
rt_err_t
nuc400
_configure
(
struct
rt_serial_device
*
serial
,
struct
serial_configure
*
cfg
)
static
rt_err_t
CME_M7
_configure
(
struct
rt_serial_device
*
serial
,
struct
serial_configure
*
cfg
)
{
struct
CME_M7_uart
*
uart
;
UART_InitTypeDef
init
;
...
...
@@ -43,18 +43,21 @@ static rt_err_t nuc400_configure(struct rt_serial_device *serial, struct serial_
init
.
UART_StopBits
=
UART_StopBits_1
;
init
.
UART_Parity
=
UART_Parity_None
;
init
.
UART_LoopBack
=
FALSE
;
init
.
UART_RxEn
=
FALS
E
;
init
.
UART_RxEn
=
TRU
E
;
init
.
UART_CtsEn
=
FALSE
;
UART_Init
(
uart
->
uart_device
,
&
init
);
uart
->
uart_device
->
RX_RESET
=
1
;
UART_Enable
(
uart
->
uart_device
,
TRUE
);
uart
->
uart_device
->
RX_RESET
=
0
;
return
RT_EOK
;
}
static
rt_err_t
nuc400
_control
(
struct
rt_serial_device
*
serial
,
int
cmd
,
void
*
arg
)
static
rt_err_t
CME_M7
_control
(
struct
rt_serial_device
*
serial
,
int
cmd
,
void
*
arg
)
{
struct
CME_M7_uart
*
uart
;
NVIC_InitTypeDef
NVIC_InitStructure
;
RT_ASSERT
(
serial
!=
RT_NULL
);
uart
=
(
struct
CME_M7_uart
*
)
serial
->
parent
.
user_data
;
...
...
@@ -63,36 +66,45 @@ static rt_err_t nuc400_control(struct rt_serial_device *serial, int cmd, void *a
{
case
RT_DEVICE_CTRL_CLR_INT
:
/* disable rx irq */
// UART_DisableInt(uart->uart_device, UART_INTEN_RDAIEN_Msk);
// NVIC_DisableIRQ(uart->irq);
NVIC_InitStructure
.
NVIC_IRQChannel
=
uart
->
irq
;
NVIC_InitStructure
.
NVIC_IRQChannelPreemptionPriority
=
0
;
NVIC_InitStructure
.
NVIC_IRQChannelSubPriority
=
0
;
NVIC_InitStructure
.
NVIC_IRQChannelCmd
=
FALSE
;
NVIC_Init
(
&
NVIC_InitStructure
);
UART_EnableInt
(
uart
->
uart_device
,
UART_Int_RxNotEmpty
,
FALSE
);
break
;
case
RT_DEVICE_CTRL_SET_INT
:
/* enable rx irq */
// UART_EnableInt(uart->uart_device, UART_INTEN_RDAIEN_Msk);
// NVIC_EnableIRQ(uart->irq);
NVIC_InitStructure
.
NVIC_IRQChannel
=
uart
->
irq
;
NVIC_InitStructure
.
NVIC_IRQChannelPreemptionPriority
=
0
;
NVIC_InitStructure
.
NVIC_IRQChannelSubPriority
=
0
;
NVIC_InitStructure
.
NVIC_IRQChannelCmd
=
TRUE
;
NVIC_Init
(
&
NVIC_InitStructure
);
UART_ClearInt
(
uart
->
uart_device
,
UART_Int_RxNotEmpty
);
UART_EnableInt
(
uart
->
uart_device
,
UART_Int_RxNotEmpty
,
TRUE
);
break
;
}
return
RT_EOK
;
}
static
int
nuc400
_putc
(
struct
rt_serial_device
*
serial
,
char
ch
)
static
int
CME_M7
_putc
(
struct
rt_serial_device
*
serial
,
char
ch
)
{
struct
CME_M7_uart
*
uart
;
RT_ASSERT
(
serial
!=
RT_NULL
);
uart
=
(
struct
CME_M7_uart
*
)
serial
->
parent
.
user_data
;
while
(
0
==
UART_Write
(
uart
->
uart_device
,
1
,
&
ch
))
;
// while(UART_GET_TX_FULL(uart->uart_device)); //waits for TXFULL bit is clear
// uart->uart_device->DAT = ch;
while
(
uart
->
uart_device
->
STATUS_b
.
TF
);
//waits for transmitter FIFO not full.
uart
->
uart_device
->
TX_BUF
=
ch
;
return
1
;
}
static
int
nuc400
_getc
(
struct
rt_serial_device
*
serial
)
static
int
CME_M7
_getc
(
struct
rt_serial_device
*
serial
)
{
int
ch
;
struct
CME_M7_uart
*
uart
;
...
...
@@ -102,20 +114,20 @@ static int nuc400_getc(struct rt_serial_device *serial)
ch
=
-
1
;
// if(!UART_GET_RX_EMPTY(uart->uart_device)
)
//
{
// ch = uart->uart_device->DAT
; /* Get Data from UART RX */
//
}
if
(
uart
->
uart_device
->
STATUS_b
.
RNE
)
{
ch
=
uart
->
uart_device
->
RX_BUF
&
0x00FF
;
/* Get Data from UART RX */
}
return
ch
;
}
static
const
struct
rt_uart_ops
CME_M7_uart_ops
=
{
nuc400
_configure
,
nuc400
_control
,
nuc400
_putc
,
nuc400
_getc
,
CME_M7
_configure
,
CME_M7
_control
,
CME_M7
_putc
,
CME_M7
_getc
,
};
int
rt_hw_uart_init
(
void
)
...
...
@@ -125,14 +137,14 @@ int rt_hw_uart_init(void)
struct
serial_configure
config
=
RT_SERIAL_CONFIG_DEFAULT
;
#ifdef RT_USING_UART0
CLK
->
APBCLK0
|=
CLK_APBCLK0_UART0CKEN_Msk
;
// UART0 Clock Enable
uart
=
&
uart0
;
serial
=
&
serial0
;
serial
0
.
ops
=
&
CME_M7_uart_ops
;
serial
0
.
config
=
config
;
serial
->
ops
=
&
CME_M7_uart_ops
;
serial
->
config
=
config
;
/* register UART device */
rt_hw_serial_register
(
&
serial0
,
rt_hw_serial_register
(
serial
,
"uart0"
,
RT_DEVICE_FLAG_RDWR
|
RT_DEVICE_FLAG_INT_RX
,
uart
);
...
...
@@ -156,16 +168,50 @@ int rt_hw_uart_init(void)
}
INIT_BOARD_EXPORT
(
rt_hw_uart_init
);
static
void
CME_UART_IRQHandler
(
struct
rt_serial_device
*
serial
)
{
struct
CME_M7_uart
*
uart
;
RT_ASSERT
(
serial
!=
RT_NULL
);
uart
=
(
struct
CME_M7_uart
*
)
serial
->
parent
.
user_data
;
if
(
UART_GetIntStatus
(
uart
->
uart_device
,
UART_Int_RxNotEmpty
))
{
UART_ClearInt
(
uart
->
uart_device
,
UART_Int_RxNotEmpty
);
rt_hw_serial_isr
(
&
serial2
,
RT_SERIAL_EVENT_RX_IND
);
}
if
(
UART_GetIntStatus
(
uart
->
uart_device
,
UART_Int_RxThresholdReach
))
{
UART_ClearInt
(
uart
->
uart_device
,
UART_Int_RxThresholdReach
);
}
if
(
UART_GetIntStatus
(
uart
->
uart_device
,
UART_Int_OverrunError
))
{
UART_ClearInt
(
uart
->
uart_device
,
UART_Int_OverrunError
);
}
if
(
UART_GetIntStatus
(
uart
->
uart_device
,
UART_Int_FrameError
))
{
UART_ClearInt
(
uart
->
uart_device
,
UART_Int_FrameError
);
}
if
(
UART_GetIntStatus
(
uart
->
uart_device
,
UART_Int_ParityError
))
{
UART_ClearInt
(
uart
->
uart_device
,
UART_Int_ParityError
);
}
}
#ifdef RT_USING_UART0
void
UART0_IRQHandler
(
void
)
{
rt_hw_serial_isr
(
&
serial0
,
RT_SERIAL_EVENT_RX_IND
);
CME_UART_IRQHandler
(
&
serial0
);
}
#endif
/* RT_USING_UART0 */
#ifdef RT_USING_UART2
void
UART2_IRQHandler
(
void
)
{
//rt_hw_serial_isr(&serial0, RT_SERIAL_EVENT_RX_IND
);
CME_UART_IRQHandler
(
&
serial2
);
}
#endif
/* RT_USING_UART2 */
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录