Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Mozi
rt-thread
提交
38209e26
R
rt-thread
项目概览
Mozi
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
0
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,发现更多精彩内容 >>
未验证
提交
38209e26
编写于
8月 19, 2019
作者:
B
Bernard Xiong
提交者:
GitHub
8月 19, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2968 from tyustli/driver-can
[bsp] [stm32] fix drv_can.c
上级
e69f4c45
32cffea7
变更
5
展开全部
隐藏空白更改
内联
并排
Showing
5 changed file
with
638 addition
and
585 deletion
+638
-585
bsp/stm32/libraries/HAL_Drivers/drv_can.c
bsp/stm32/libraries/HAL_Drivers/drv_can.c
+526
-492
bsp/stm32/libraries/HAL_Drivers/drv_can.h
bsp/stm32/libraries/HAL_Drivers/drv_can.h
+26
-17
bsp/stm32/libraries/STM32H7xx_HAL/SConscript
bsp/stm32/libraries/STM32H7xx_HAL/SConscript
+4
-4
components/drivers/can/can.c
components/drivers/can/can.c
+79
-69
components/drivers/include/drivers/can.h
components/drivers/include/drivers/can.h
+3
-3
未找到文件。
bsp/stm32/libraries/HAL_Drivers/drv_can.c
浏览文件 @
38209e26
此差异已折叠。
点击以展开。
bsp/stm32/libraries/HAL_Drivers/drv_can.h
浏览文件 @
38209e26
...
...
@@ -11,40 +11,49 @@
* 2019-02-19 YLZ port to BSP [stm32]
* 2019-06-17 YLZ modify struct stm32_drv_can.
*/
#ifndef __DRV_CAN_H__
#define __DRV_CAN_H__
#ifdef __cplusplus
extern
"C"
{
#endif
#include <board.h>
#include <rtdevice.h>
#include <rthw.h>
#include <rtthread.h>
#define BS1SHIFT 16
#define BS2SHIFT 20
#define RRESCLSHIFT 0
#define SJWSHIFT 24
#define BS1MASK
(
(0x0F) << BS1SHIFT )
#define BS2MASK
(
(0x07) << BS2SHIFT )
#define RRESCLMASK
(
0x3FF << RRESCLSHIFT )
#define SJWMASK
(
0x3 << SJWSHIFT )
#define BS1SHIFT
16
#define BS2SHIFT
20
#define RRESCLSHIFT
0
#define SJWSHIFT
24
#define BS1MASK
(
(0x0F) << BS1SHIFT )
#define BS2MASK
(
(0x07) << BS2SHIFT )
#define RRESCLMASK
(
0x3FF << RRESCLSHIFT )
#define SJWMASK
(
0x3 << SJWSHIFT )
struct
stm_baud_rate_tab
struct
stm
32
_baud_rate_tab
{
rt_uint32_t
baud_rate
;
rt_uint32_t
confdata
;
rt_uint32_t
conf
ig_
data
;
};
#define BAUD_DATA(TYPE,NO) ((can_baud_rate_tab[NO].config_data & TYPE##MASK))
/*
STM32 can driver
*/
struct
stm32_
drv_
can
/*
stm32 can device
*/
struct
stm32_can
{
char
*
name
;
CAN_HandleTypeDef
CanHandle
;
CAN_FilterTypeDef
FilterConfig
;
struct
rt_can_device
device
;
/* inherit from can device */
};
#ifdef __cplusplus
extern
"C"
{
#endif
int
rt_hw_can_init
(
void
);
#ifdef __cplusplus
}
}
#endif
#endif
/*__DRV_CAN_H__ */
/************************** end of file ******************/
bsp/stm32/libraries/STM32H7xx_HAL/SConscript
浏览文件 @
38209e26
...
...
@@ -29,9 +29,9 @@ STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_gpio.c
'''
)
if
GetDepend
([
'RT_USING_SERIAL'
]):
src
+=
[
'STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_uart.c'
]
src
+=
[
'STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_usart.c'
]
src
+=
[
'STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_uart_ex.c'
]
src
+=
[
'STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_uart.c'
]
src
+=
[
'STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_usart.c'
]
src
+=
[
'STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_uart_ex.c'
]
if
GetDepend
([
'RT_USING_I2C'
]):
src
+=
[
'STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2c.c'
]
...
...
@@ -49,7 +49,7 @@ if GetDepend(['RT_USING_USB_HOST']) or GetDepend(['RT_USING_USB_DEVICE']):
src
+=
[
'STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_usb.c'
]
if
GetDepend
([
'RT_USING_CAN'
]):
src
+=
[
'STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_can.c'
]
src
+=
[
'STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_
fd
can.c'
]
if
GetDepend
([
'RT_USING_HWTIMER'
])
or
GetDepend
([
'RT_USING_PWM'
]):
src
+=
[
'STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_tim.c'
]
...
...
components/drivers/can/can.c
浏览文件 @
38209e26
...
...
@@ -27,10 +27,15 @@ static rt_err_t rt_can_init(struct rt_device *dev)
/* initialize rx/tx */
can
->
can_rx
=
RT_NULL
;
can
->
can_tx
=
RT_NULL
;
#ifdef RT_CAN_USING_HDR
can
->
hdr
=
RT_NULL
;
#endif
/* apply configuration */
if
(
can
->
ops
->
configure
)
result
=
can
->
ops
->
configure
(
can
,
&
can
->
config
);
else
result
=
-
RT_ENOSYS
;
return
result
;
}
...
...
@@ -293,7 +298,7 @@ static rt_err_t rt_can_open(struct rt_device *dev, rt_uint16_t oflag)
can
->
can_rx
=
rx_fifo
;
dev
->
open_flag
|=
RT_DEVICE_FLAG_INT_RX
;
/*
configure low level device
*/
/*
open can rx interrupt
*/
can
->
ops
->
control
(
can
,
RT_DEVICE_CTRL_SET_INT
,
(
void
*
)
RT_DEVICE_FLAG_INT_RX
);
}
}
...
...
@@ -311,7 +316,7 @@ static rt_err_t rt_can_open(struct rt_device *dev, rt_uint16_t oflag)
tx_fifo
->
buffer
=
(
struct
rt_can_sndbxinx_list
*
)(
tx_fifo
+
1
);
rt_memset
(
tx_fifo
->
buffer
,
0
,
can
->
config
.
sndboxnumber
*
sizeof
(
struct
rt_can_sndbxinx_list
));
can
->
config
.
sndboxnumber
*
sizeof
(
struct
rt_can_sndbxinx_list
));
rt_list_init
(
&
tx_fifo
->
freelist
);
for
(
i
=
0
;
i
<
can
->
config
.
sndboxnumber
;
i
++
)
{
...
...
@@ -325,7 +330,7 @@ static rt_err_t rt_can_open(struct rt_device *dev, rt_uint16_t oflag)
can
->
can_tx
=
tx_fifo
;
dev
->
open_flag
|=
RT_DEVICE_FLAG_INT_TX
;
/*
configure low level device
*/
/*
open can tx interrupt
*/
can
->
ops
->
control
(
can
,
RT_DEVICE_CTRL_SET_INT
,
(
void
*
)
RT_DEVICE_FLAG_INT_TX
);
}
}
...
...
@@ -406,7 +411,7 @@ static rt_err_t rt_can_close(struct rt_device *dev)
rt_free
(
rx_fifo
);
dev
->
open_flag
&=
~
RT_DEVICE_FLAG_INT_RX
;
can
->
can_rx
=
RT_NULL
;
/* c
onfigure low level device
*/
/* c
lear can rx interrupt
*/
can
->
ops
->
control
(
can
,
RT_DEVICE_CTRL_CLR_INT
,
(
void
*
)
RT_DEVICE_FLAG_INT_RX
);
}
...
...
@@ -420,7 +425,7 @@ static rt_err_t rt_can_close(struct rt_device *dev)
rt_free
(
tx_fifo
);
dev
->
open_flag
&=
~
RT_DEVICE_FLAG_INT_TX
;
can
->
can_tx
=
RT_NULL
;
/* c
onfigure low level device
*/
/* c
lear can tx interrupt
*/
can
->
ops
->
control
(
can
,
RT_DEVICE_CTRL_CLR_INT
,
(
void
*
)
RT_DEVICE_FLAG_INT_TX
);
}
...
...
@@ -484,6 +489,7 @@ static rt_err_t rt_can_control(struct rt_device *dev,
struct
rt_can_device
*
can
;
rt_err_t
res
;
res
=
RT_EOK
;
RT_ASSERT
(
dev
!=
RT_NULL
);
can
=
(
struct
rt_can_device
*
)
dev
;
...
...
@@ -501,8 +507,9 @@ static rt_err_t rt_can_control(struct rt_device *dev,
case
RT_DEVICE_CTRL_CONFIG
:
/* configure device */
can
->
ops
->
configure
(
can
,
(
struct
can_configure
*
)
args
);
res
=
can
->
ops
->
configure
(
can
,
(
struct
can_configure
*
)
args
);
break
;
case
RT_CAN_CMD_SET_PRIV
:
/* configure device */
if
((
rt_uint32_t
)
args
!=
can
->
config
.
privmode
)
...
...
@@ -513,7 +520,6 @@ static rt_err_t rt_can_control(struct rt_device *dev,
res
=
can
->
ops
->
control
(
can
,
cmd
,
args
);
if
(
res
!=
RT_EOK
)
return
res
;
tx_fifo
=
(
struct
rt_can_tx_fifo
*
)
can
->
can_tx
;
if
(
can
->
config
.
privmode
)
{
...
...
@@ -522,11 +528,11 @@ static rt_err_t rt_can_control(struct rt_device *dev,
level
=
rt_hw_interrupt_disable
();
if
(
rt_list_isempty
(
&
tx_fifo
->
buffer
[
i
].
list
))
{
rt_sem_release
(
&
(
tx_fifo
->
sem
));
rt_sem_release
(
&
(
tx_fifo
->
sem
));
}
else
{
rt_list_remove
(
&
tx_fifo
->
buffer
[
i
].
list
);
rt_list_remove
(
&
tx_fifo
->
buffer
[
i
].
list
);
}
rt_hw_interrupt_enable
(
level
);
}
...
...
@@ -544,7 +550,6 @@ static rt_err_t rt_can_control(struct rt_device *dev,
rt_hw_interrupt_enable
(
level
);
}
}
return
RT_EOK
;
}
break
;
...
...
@@ -561,74 +566,73 @@ static rt_err_t rt_can_control(struct rt_device *dev,
return
res
;
}
{
struct
rt_can_filter_config
*
pfilter
;
struct
rt_can_filter_item
*
pitem
;
rt_uint32_t
count
;
rt_base_t
level
;
struct
rt_can_filter_config
*
pfilter
;
struct
rt_can_filter_item
*
pitem
;
rt_uint32_t
count
;
rt_base_t
level
;
pfilter
=
(
struct
rt_can_filter_config
*
)
args
;
count
=
pfilter
->
count
;
pitem
=
pfilter
->
items
;
if
(
pfilter
->
actived
)
pfilter
=
(
struct
rt_can_filter_config
*
)
args
;
RT_ASSERT
(
pfilter
);
count
=
pfilter
->
count
;
pitem
=
pfilter
->
items
;
if
(
pfilter
->
actived
)
{
while
(
count
)
{
while
(
count
)
if
(
pitem
->
hdr
>=
can
->
config
.
maxhdr
||
pitem
->
hdr
<
0
)
{
if
(
pitem
->
hdr
>=
can
->
config
.
maxhdr
||
pitem
->
hdr
<
0
)
{
count
--
;
pitem
++
;
continue
;
}
level
=
rt_hw_interrupt_disable
();
if
(
!
can
->
hdr
[
pitem
->
hdr
].
connected
)
{
rt_hw_interrupt_enable
(
level
);
rt_memcpy
(
&
can
->
hdr
[
pitem
->
hdr
].
filter
,
pitem
,
sizeof
(
struct
rt_can_filter_item
));
level
=
rt_hw_interrupt_disable
();
can
->
hdr
[
pitem
->
hdr
].
connected
=
1
;
can
->
hdr
[
pitem
->
hdr
].
msgs
=
0
;
rt_list_init
(
&
can
->
hdr
[
pitem
->
hdr
].
list
);
}
rt_hw_interrupt_enable
(
level
);
count
--
;
pitem
++
;
continue
;
}
level
=
rt_hw_interrupt_disable
();
if
(
!
can
->
hdr
[
pitem
->
hdr
].
connected
)
{
rt_hw_interrupt_enable
(
level
);
rt_memcpy
(
&
can
->
hdr
[
pitem
->
hdr
].
filter
,
pitem
,
sizeof
(
struct
rt_can_filter_item
));
level
=
rt_hw_interrupt_disable
();
can
->
hdr
[
pitem
->
hdr
].
connected
=
1
;
can
->
hdr
[
pitem
->
hdr
].
msgs
=
0
;
rt_list_init
(
&
can
->
hdr
[
pitem
->
hdr
].
list
);
}
rt_hw_interrupt_enable
(
level
);
count
--
;
pitem
++
;
}
else
}
else
{
while
(
count
)
{
while
(
count
)
if
(
pitem
->
hdr
>=
can
->
config
.
maxhdr
||
pitem
->
hdr
<
0
)
{
if
(
pitem
->
hdr
>=
can
->
config
.
maxhdr
||
pitem
->
hdr
<
0
)
{
count
--
;
pitem
++
;
continue
;
}
level
=
rt_hw_interrupt_disable
();
count
--
;
pitem
++
;
continue
;
}
level
=
rt_hw_interrupt_disable
();
if
(
can
->
hdr
[
pitem
->
hdr
].
connected
)
if
(
can
->
hdr
[
pitem
->
hdr
].
connected
)
{
can
->
hdr
[
pitem
->
hdr
].
connected
=
0
;
can
->
hdr
[
pitem
->
hdr
].
msgs
=
0
;
if
(
!
rt_list_isempty
(
&
can
->
hdr
[
pitem
->
hdr
].
list
))
{
can
->
hdr
[
pitem
->
hdr
].
connected
=
0
;
can
->
hdr
[
pitem
->
hdr
].
msgs
=
0
;
if
(
!
rt_list_isempty
(
&
can
->
hdr
[
pitem
->
hdr
].
list
))
{
rt_list_remove
(
can
->
hdr
[
pitem
->
hdr
].
list
.
next
);
}
rt_hw_interrupt_enable
(
level
);
rt_memset
(
&
can
->
hdr
[
pitem
->
hdr
].
filter
,
0
,
sizeof
(
struct
rt_can_filter_item
));
rt_list_remove
(
can
->
hdr
[
pitem
->
hdr
].
list
.
next
);
}
else
{
rt_hw_interrupt_enable
(
level
);
}
count
--
;
pitem
++
;
rt_hw_interrupt_enable
(
level
);
rt_memset
(
&
can
->
hdr
[
pitem
->
hdr
].
filter
,
0
,
sizeof
(
struct
rt_can_filter_item
));
}
else
{
rt_hw_interrupt_enable
(
level
);
}
count
--
;
pitem
++
;
}
}
break
;
...
...
@@ -642,12 +646,16 @@ static rt_err_t rt_can_control(struct rt_device *dev,
/* control device */
if
(
can
->
ops
->
control
!=
RT_NULL
)
{
can
->
ops
->
control
(
can
,
cmd
,
args
);
res
=
can
->
ops
->
control
(
can
,
cmd
,
args
);
}
else
{
res
=
-
RT_ENOSYS
;
}
break
;
}
return
RT_EOK
;
return
res
;
}
/*
...
...
@@ -655,8 +663,10 @@ static rt_err_t rt_can_control(struct rt_device *dev,
*/
static
void
cantimeout
(
void
*
arg
)
{
rt_can_t
can
=
(
rt_can_t
)
arg
;
rt_can_t
can
;
can
=
(
rt_can_t
)
arg
;
RT_ASSERT
(
can
);
rt_device_control
((
rt_device_t
)
can
,
RT_CAN_CMD_GET_STATUS
,
(
void
*
)
&
can
->
status
);
if
(
can
->
status_indicate
.
ind
!=
RT_NULL
)
...
...
@@ -690,7 +700,7 @@ const static struct rt_device_ops can_device_ops =
/*
* can register
*/
rt_err_t
rt_hw_can_register
(
struct
rt_can_device
*
can
,
rt_err_t
rt_hw_can_register
(
struct
rt_can_device
*
can
,
const
char
*
name
,
const
struct
rt_can_ops
*
ops
,
void
*
data
)
...
...
components/drivers/include/drivers/can.h
浏览文件 @
38209e26
...
...
@@ -221,7 +221,7 @@ struct rt_can_msg
rt_uint32_t
rsv
:
1
;
rt_uint32_t
len
:
8
;
rt_uint32_t
priv
:
8
;
rt_
u
int32_t
hdr
:
8
;
rt_int32_t
hdr
:
8
;
rt_uint32_t
reserved
:
8
;
rt_uint8_t
data
[
8
];
};
...
...
@@ -252,7 +252,7 @@ struct rt_can_rx_fifo
#define RT_CAN_EVENT_RX_IND 0x01
/* Rx indication */
#define RT_CAN_EVENT_TX_DONE 0x02
/* Tx complete */
#define RT_CAN_EVENT_TX_FAIL 0x03
/* Tx
complete
*/
#define RT_CAN_EVENT_TX_FAIL 0x03
/* Tx
fail
*/
#define RT_CAN_EVENT_RX_TIMEOUT 0x05
/* Rx timeout */
#define RT_CAN_EVENT_RXOF_IND 0x06
/* Rx overflow */
...
...
@@ -278,7 +278,7 @@ struct rt_can_ops
int
(
*
recvmsg
)(
struct
rt_can_device
*
can
,
void
*
buf
,
rt_uint32_t
boxno
);
};
rt_err_t
rt_hw_can_register
(
struct
rt_can_device
*
can
,
rt_err_t
rt_hw_can_register
(
struct
rt_can_device
*
can
,
const
char
*
name
,
const
struct
rt_can_ops
*
ops
,
void
*
data
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录