Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
天中雨水
rt-thread
提交
6fad73c9
R
rt-thread
项目概览
天中雨水
/
rt-thread
该项目与 Fork 源项目分叉
Fork自
RT-Thread / rt-thread
通知
2
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6fad73c9
编写于
7月 07, 2015
作者:
A
Aubr.Cool
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[BSP] stm32f10x can code format
上级
b750e11e
变更
2
展开全部
隐藏空白更改
内联
并排
Showing
2 changed file
with
1231 addition
and
1023 deletion
+1231
-1023
bsp/stm32f10x/applications/canapp.c
bsp/stm32f10x/applications/canapp.c
+142
-120
bsp/stm32f10x/drivers/bxcan.c
bsp/stm32f10x/drivers/bxcan.c
+1089
-903
未找到文件。
bsp/stm32f10x/applications/canapp.c
浏览文件 @
6fad73c9
...
@@ -8,8 +8,8 @@
...
@@ -8,8 +8,8 @@
* http://www.rt-thread.org/license/LICENSE
* http://www.rt-thread.org/license/LICENSE
*
*
* Change Logs:
* Change Logs:
* Date Author
Notes
* Date Author
Notes
* 2015-05-14 aubrcool@qq.com
first version
* 2015-05-14 aubrcool@qq.com
first version
*/
*/
#include <board.h>
#include <board.h>
...
@@ -22,69 +22,80 @@
...
@@ -22,69 +22,80 @@
#define CANERR2 38
#define CANERR2 38
static
struct
canledtype
static
struct
canledtype
{
{
struct
stm32_hw_pin_userdata
rtd
;
struct
stm32_hw_pin_userdata
rtd
;
struct
stm32_hw_pin_userdata
err
;
struct
stm32_hw_pin_userdata
err
;
}
canled
[]
=
}
canled
[]
=
{
{
#ifdef USING_BXCAN1
#ifdef USING_BXCAN1
{
{
{
CANRT1
,
PIN_MODE_OUTPUT_OD
,},
{
CANRT1
,
PIN_MODE_OUTPUT_OD
,},
{
CANERR1
,
PIN_MODE_OUTPUT_OD
,},
{
CANERR1
,
PIN_MODE_OUTPUT_OD
,},
},
},
#endif
/*USING_BXCAN1*/
#endif
/*USING_BXCAN1*/
#ifdef USING_BXCAN2
#ifdef USING_BXCAN2
{
{
{
CANRT2
,
PIN_MODE_OUTPUT_OD
,},
{
CANRT2
,
PIN_MODE_OUTPUT_OD
,},
{
CANERR2
,
PIN_MODE_OUTPUT_OD
,},
{
CANERR2
,
PIN_MODE_OUTPUT_OD
,},
},
},
#endif
/*USING_BXCAN2*/
#endif
/*USING_BXCAN2*/
};
};
void
can_bus_hook
(
struct
rt_can_device
*
can
,
struct
canledtype
*
led
)
void
can_bus_hook
(
struct
rt_can_device
*
can
,
struct
canledtype
*
led
)
{
{
if
(
can
->
timerinitflag
==
1
)
{
if
(
can
->
timerinitflag
==
1
)
rt_pin_write
(
led
->
rtd
.
pin
,
0
);
{
}
else
{
rt_pin_write
(
led
->
rtd
.
pin
,
0
);
if
(
can
->
status
.
rcvchange
==
1
||
can
->
status
.
sndchange
==
1
)
}
else
{
if
(
can
->
status
.
rcvchange
==
1
||
can
->
status
.
sndchange
==
1
)
{
{
can
->
status
.
rcvchange
=
0
;
can
->
status
.
rcvchange
=
0
;
can
->
status
.
sndchange
=
0
;
can
->
status
.
sndchange
=
0
;
rt_pin_write
(
led
->
rtd
.
pin
,
rt_pin_read
(
led
->
rtd
.
pin
)
?
0
:
1
);
rt_pin_write
(
led
->
rtd
.
pin
,
rt_pin_read
(
led
->
rtd
.
pin
)
?
0
:
1
);
}
else
{
}
rt_pin_write
(
led
->
rtd
.
pin
,
1
);
else
{
rt_pin_write
(
led
->
rtd
.
pin
,
1
);
}
}
if
(
can
->
timerinitflag
==
1
)
{
rt_pin_write
(
led
->
err
.
pin
,
0
);
}
else
{
if
(
can
->
status
.
errcode
)
{
rt_pin_write
(
led
->
err
.
pin
,
0
);
}
else
{
rt_pin_write
(
led
->
err
.
pin
,
1
);
}
}
}
}
if
(
can
->
timerinitflag
==
1
)
{
rt_pin_write
(
led
->
err
.
pin
,
0
);
}
else
{
if
(
can
->
status
.
errcode
)
{
rt_pin_write
(
led
->
err
.
pin
,
0
);
}
else
{
rt_pin_write
(
led
->
err
.
pin
,
1
);
}
}
}
}
#ifdef USING_BXCAN1
#ifdef USING_BXCAN1
void
can1_bus_hook
(
struct
rt_can_device
*
can
)
void
can1_bus_hook
(
struct
rt_can_device
*
can
)
{
{
static
rt_int32_t
inited
=
0
;
static
rt_int32_t
inited
=
0
;
if
(
!
inited
)
if
(
!
inited
)
{
{
inited
=
1
;
inited
=
1
;
rt_pin_mode
(
canled
[
0
].
rtd
.
pin
,
canled
[
0
].
rtd
.
mode
);
rt_pin_mode
(
canled
[
0
].
rtd
.
pin
,
canled
[
0
].
rtd
.
mode
);
rt_pin_mode
(
canled
[
0
].
err
.
pin
,
canled
[
0
].
err
.
mode
);
rt_pin_mode
(
canled
[
0
].
err
.
pin
,
canled
[
0
].
err
.
mode
);
}
}
can_bus_hook
(
can
,
&
canled
[
0
]);
can_bus_hook
(
can
,
&
canled
[
0
]);
}
}
#endif
/*USING_BXCAN1*/
#endif
/*USING_BXCAN1*/
#ifdef USING_BXCAN2
#ifdef USING_BXCAN2
void
can2_bus_hook
(
struct
rt_can_device
*
can
)
void
can2_bus_hook
(
struct
rt_can_device
*
can
)
{
{
static
rt_int32_t
inited
=
0
;
static
rt_int32_t
inited
=
0
;
if
(
!
inited
)
if
(
!
inited
)
{
{
inited
=
1
;
inited
=
1
;
rt_pin_mode
(
canled
[
1
].
rtd
.
pin
,
canled
[
1
].
rtd
.
mode
);
rt_pin_mode
(
canled
[
1
].
rtd
.
pin
,
canled
[
1
].
rtd
.
mode
);
rt_pin_mode
(
canled
[
1
].
err
.
pin
,
canled
[
1
].
err
.
mode
);
rt_pin_mode
(
canled
[
1
].
err
.
pin
,
canled
[
1
].
err
.
mode
);
}
}
can_bus_hook
(
can
,
&
canled
[
1
]);
can_bus_hook
(
can
,
&
canled
[
1
]);
}
}
...
@@ -95,31 +106,31 @@ int can_bus_hook_init(void)
...
@@ -95,31 +106,31 @@ int can_bus_hook_init(void)
#ifdef USING_BXCAN1
#ifdef USING_BXCAN1
candev
=
rt_device_find
(
"bxcan1"
);
candev
=
rt_device_find
(
"bxcan1"
);
RT_ASSERT
(
candev
);
RT_ASSERT
(
candev
);
rt_device_control
(
candev
,
RT_CAN_CMD_SET_BUS_HOOK
,(
void
*
)
can1_bus_hook
);
rt_device_control
(
candev
,
RT_CAN_CMD_SET_BUS_HOOK
,
(
void
*
)
can1_bus_hook
);
#endif
/*USING_BXCAN1*/
#endif
/*USING_BXCAN1*/
#ifdef USING_BXCAN2
#ifdef USING_BXCAN2
candev
=
rt_device_find
(
"bxcan2"
);
candev
=
rt_device_find
(
"bxcan2"
);
RT_ASSERT
(
candev
);
RT_ASSERT
(
candev
);
rt_device_control
(
candev
,
RT_CAN_CMD_SET_BUS_HOOK
,(
void
*
)
can2_bus_hook
);
rt_device_control
(
candev
,
RT_CAN_CMD_SET_BUS_HOOK
,
(
void
*
)
can2_bus_hook
);
#endif
/*USING_BXCAN2*/
#endif
/*USING_BXCAN2*/
return
RT_EOK
;
return
RT_EOK
;
}
}
INIT_DEVICE_EXPORT
(
can_bus_hook_init
);
INIT_DEVICE_EXPORT
(
can_bus_hook_init
);
struct
can_app_struct
struct
can_app_struct
{
{
const
char
*
name
;
const
char
*
name
;
struct
rt_event
event
;
struct
rt_event
event
;
struct
rt_can_filter_config
*
filter
;
struct
rt_can_filter_config
*
filter
;
rt_uint8_t
eventopt
;
rt_uint8_t
eventopt
;
};
};
static
struct
can_app_struct
can_data
[
2
];
static
struct
can_app_struct
can_data
[
2
];
static
rt_err_t
can1ind
(
rt_device_t
dev
,
void
*
args
,
rt_int32_t
hdr
,
rt_size_t
size
)
static
rt_err_t
can1ind
(
rt_device_t
dev
,
void
*
args
,
rt_int32_t
hdr
,
rt_size_t
size
)
{
{
rt_event_t
pevent
=
(
rt_event_t
)
args
;
rt_event_t
pevent
=
(
rt_event_t
)
args
;
rt_event_send
(
pevent
,
1
<<
(
hdr
));
rt_event_send
(
pevent
,
1
<<
(
hdr
));
return
RT_EOK
;
return
RT_EOK
;
}
}
static
rt_err_t
can2ind
(
rt_device_t
dev
,
void
*
args
,
rt_int32_t
hdr
,
rt_size_t
size
)
static
rt_err_t
can2ind
(
rt_device_t
dev
,
void
*
args
,
rt_int32_t
hdr
,
rt_size_t
size
)
{
{
rt_event_t
pevent
=
(
rt_event_t
)
args
;
rt_event_t
pevent
=
(
rt_event_t
)
args
;
rt_event_send
(
pevent
,
1
<<
(
hdr
));
rt_event_send
(
pevent
,
1
<<
(
hdr
));
...
@@ -127,106 +138,117 @@ static rt_err_t can2ind(rt_device_t dev, void* args, rt_int32_t hdr, rt_size_t
...
@@ -127,106 +138,117 @@ static rt_err_t can2ind(rt_device_t dev, void* args, rt_int32_t hdr, rt_size_t
}
}
struct
rt_can_filter_item
filter1item
[
4
]
=
struct
rt_can_filter_item
filter1item
[
4
]
=
{
{
RT_CAN_FILTER_STD_INIT
(
1
,
can1ind
,
&
can_data
[
0
].
event
),
RT_CAN_FILTER_STD_INIT
(
1
,
can1ind
,
&
can_data
[
0
].
event
),
RT_CAN_FILTER_STD_INIT
(
2
,
can1ind
,
&
can_data
[
0
].
event
),
RT_CAN_FILTER_STD_INIT
(
2
,
can1ind
,
&
can_data
[
0
].
event
),
RT_CAN_STD_RMT_FILTER_INIT
(
3
,
can1ind
,
&
can_data
[
0
].
event
),
RT_CAN_STD_RMT_FILTER_INIT
(
3
,
can1ind
,
&
can_data
[
0
].
event
),
RT_CAN_STD_RMT_DATA_FILTER_INIT
(
4
,
can1ind
,
&
can_data
[
0
].
event
),
RT_CAN_STD_RMT_DATA_FILTER_INIT
(
4
,
can1ind
,
&
can_data
[
0
].
event
),
};
};
struct
rt_can_filter_item
filter2item
[
4
]
=
struct
rt_can_filter_item
filter2item
[
4
]
=
{
{
RT_CAN_FILTER_STD_INIT
(
1
,
can2ind
,
&
can_data
[
1
].
event
),
RT_CAN_FILTER_STD_INIT
(
1
,
can2ind
,
&
can_data
[
1
].
event
),
RT_CAN_FILTER_STD_INIT
(
2
,
can2ind
,
&
can_data
[
1
].
event
),
RT_CAN_FILTER_STD_INIT
(
2
,
can2ind
,
&
can_data
[
1
].
event
),
RT_CAN_STD_RMT_FILTER_INIT
(
3
,
can2ind
,
&
can_data
[
1
].
event
),
RT_CAN_STD_RMT_FILTER_INIT
(
3
,
can2ind
,
&
can_data
[
1
].
event
),
RT_CAN_STD_RMT_DATA_FILTER_INIT
(
4
,
can2ind
,
&
can_data
[
1
].
event
),
RT_CAN_STD_RMT_DATA_FILTER_INIT
(
4
,
can2ind
,
&
can_data
[
1
].
event
),
};
};
struct
rt_can_filter_config
filter1
=
struct
rt_can_filter_config
filter1
=
{
{
.
count
=
4
,
.
count
=
4
,
.
actived
=
1
,
.
actived
=
1
,
.
items
=
filter1item
,
.
items
=
filter1item
,
};
};
struct
rt_can_filter_config
filter2
=
struct
rt_can_filter_config
filter2
=
{
{
.
count
=
4
,
.
count
=
4
,
.
actived
=
1
,
.
actived
=
1
,
.
items
=
filter2item
,
.
items
=
filter2item
,
};
};
static
struct
can_app_struct
can_data
[
2
]
=
{
static
struct
can_app_struct
can_data
[
2
]
=
{
{
{
.
name
=
"bxcan1"
,
.
name
=
"bxcan1"
,
.
filter
=
&
filter1
,
.
filter
=
&
filter1
,
.
eventopt
=
RT_EVENT_FLAG_OR
|
RT_EVENT_FLAG_CLEAR
,
.
eventopt
=
RT_EVENT_FLAG_OR
|
RT_EVENT_FLAG_CLEAR
,
},
},
{
{
.
name
=
"bxcan2"
,
.
name
=
"bxcan2"
,
.
filter
=
&
filter2
,
.
filter
=
&
filter2
,
.
eventopt
=
RT_EVENT_FLAG_AND
|
RT_EVENT_FLAG_CLEAR
,
.
eventopt
=
RT_EVENT_FLAG_AND
|
RT_EVENT_FLAG_CLEAR
,
},
},
};
};
void
rt_can_thread_entry
(
void
*
parameter
)
void
rt_can_thread_entry
(
void
*
parameter
)
{
{
struct
rt_can_msg
msg
;
struct
rt_can_msg
msg
;
struct
can_app_struct
*
canpara
=
(
struct
can_app_struct
*
)
parameter
;
struct
can_app_struct
*
canpara
=
(
struct
can_app_struct
*
)
parameter
;
rt_device_t
candev
;
rt_device_t
candev
;
rt_uint32_t
e
;
rt_uint32_t
e
;
candev
=
rt_device_find
(
canpara
->
name
);
candev
=
rt_device_find
(
canpara
->
name
);
RT_ASSERT
(
candev
);
RT_ASSERT
(
candev
);
rt_event_init
(
&
canpara
->
event
,
canpara
->
name
,
RT_IPC_FLAG_FIFO
);
rt_event_init
(
&
canpara
->
event
,
canpara
->
name
,
RT_IPC_FLAG_FIFO
);
rt_device_open
(
candev
,
(
RT_DEVICE_OFLAG_RDWR
|
RT_DEVICE_FLAG_INT_RX
|
RT_DEVICE_FLAG_INT_TX
));
rt_device_open
(
candev
,
(
RT_DEVICE_OFLAG_RDWR
|
RT_DEVICE_FLAG_INT_RX
|
RT_DEVICE_FLAG_INT_TX
));
rt_device_control
(
candev
,
RT_CAN_CMD_SET_FILTER
,
canpara
->
filter
);
rt_device_control
(
candev
,
RT_CAN_CMD_SET_FILTER
,
canpara
->
filter
);
while
(
1
)
{
while
(
1
)
if
(
{
rt_event_recv
(
&
canpara
->
event
,
if
(
((
1
<<
canpara
->
filter
->
items
[
0
].
hdr
)
|
rt_event_recv
(
&
canpara
->
event
,
(
1
<<
canpara
->
filter
->
items
[
1
].
hdr
)
|
((
1
<<
canpara
->
filter
->
items
[
0
].
hdr
)
|
(
1
<<
canpara
->
filter
->
items
[
2
].
hdr
)
|
(
1
<<
canpara
->
filter
->
items
[
1
].
hdr
)
|
(
1
<<
canpara
->
filter
->
items
[
3
].
hdr
)),
(
1
<<
canpara
->
filter
->
items
[
2
].
hdr
)
|
canpara
->
eventopt
,
(
1
<<
canpara
->
filter
->
items
[
3
].
hdr
)),
RT_WAITING_FOREVER
,
&
e
)
!=
RT_EOK
canpara
->
eventopt
,
)
{
RT_WAITING_FOREVER
,
&
e
)
!=
RT_EOK
continue
;
)
}
{
if
(
e
&
(
1
<<
canpara
->
filter
->
items
[
0
].
hdr
))
{
continue
;
msg
.
hdr
=
canpara
->
filter
->
items
[
0
].
hdr
;
}
while
(
rt_device_read
(
candev
,
0
,
&
msg
,
sizeof
(
msg
))
==
sizeof
(
msg
))
{
if
(
e
&
(
1
<<
canpara
->
filter
->
items
[
0
].
hdr
))
rt_device_write
(
candev
,
0
,
&
msg
,
sizeof
(
msg
));
{
}
msg
.
hdr
=
canpara
->
filter
->
items
[
0
].
hdr
;
}
while
(
rt_device_read
(
candev
,
0
,
&
msg
,
sizeof
(
msg
))
==
sizeof
(
msg
))
if
(
e
&
(
1
<<
canpara
->
filter
->
items
[
1
].
hdr
))
{
{
msg
.
hdr
=
canpara
->
filter
->
items
[
1
].
hdr
;
rt_device_write
(
candev
,
0
,
&
msg
,
sizeof
(
msg
));
while
(
rt_device_read
(
candev
,
0
,
&
msg
,
sizeof
(
msg
))
==
sizeof
(
msg
))
{
}
rt_device_write
(
candev
,
0
,
&
msg
,
sizeof
(
msg
));
}
}
if
(
e
&
(
1
<<
canpara
->
filter
->
items
[
1
].
hdr
))
}
{
if
(
e
&
(
1
<<
canpara
->
filter
->
items
[
2
].
hdr
))
{
msg
.
hdr
=
canpara
->
filter
->
items
[
1
].
hdr
;
msg
.
hdr
=
canpara
->
filter
->
items
[
2
].
hdr
;
while
(
rt_device_read
(
candev
,
0
,
&
msg
,
sizeof
(
msg
))
==
sizeof
(
msg
))
while
(
rt_device_read
(
candev
,
0
,
&
msg
,
sizeof
(
msg
))
==
sizeof
(
msg
))
{
{
rt_device_write
(
candev
,
0
,
&
msg
,
sizeof
(
msg
));
rt_device_write
(
candev
,
0
,
&
msg
,
sizeof
(
msg
));
}
}
}
}
if
(
e
&
(
1
<<
canpara
->
filter
->
items
[
3
].
hdr
))
{
if
(
e
&
(
1
<<
canpara
->
filter
->
items
[
2
].
hdr
))
msg
.
hdr
=
canpara
->
filter
->
items
[
3
].
hdr
;
{
while
(
rt_device_read
(
candev
,
0
,
&
msg
,
sizeof
(
msg
))
==
sizeof
(
msg
))
{
msg
.
hdr
=
canpara
->
filter
->
items
[
2
].
hdr
;
rt_device_write
(
candev
,
0
,
&
msg
,
sizeof
(
msg
));
while
(
rt_device_read
(
candev
,
0
,
&
msg
,
sizeof
(
msg
))
==
sizeof
(
msg
))
}
{
}
rt_device_write
(
candev
,
0
,
&
msg
,
sizeof
(
msg
));
}
}
}
if
(
e
&
(
1
<<
canpara
->
filter
->
items
[
3
].
hdr
))
{
msg
.
hdr
=
canpara
->
filter
->
items
[
3
].
hdr
;
while
(
rt_device_read
(
candev
,
0
,
&
msg
,
sizeof
(
msg
))
==
sizeof
(
msg
))
{
rt_device_write
(
candev
,
0
,
&
msg
,
sizeof
(
msg
));
}
}
}
}
}
int
rt_can_app_init
(
void
)
int
rt_can_app_init
(
void
)
{
{
rt_thread_t
tid
;
rt_thread_t
tid
;
tid
=
rt_thread_create
(
"canapp1"
,
tid
=
rt_thread_create
(
"canapp1"
,
rt_can_thread_entry
,
&
can_data
[
0
],
rt_can_thread_entry
,
&
can_data
[
0
],
512
,
RT_THREAD_PRIORITY_MAX
/
3
-
1
,
20
);
512
,
RT_THREAD_PRIORITY_MAX
/
3
-
1
,
20
);
if
(
tid
!=
RT_NULL
)
rt_thread_startup
(
tid
);
if
(
tid
!=
RT_NULL
)
rt_thread_startup
(
tid
);
tid
=
rt_thread_create
(
"canapp2"
,
tid
=
rt_thread_create
(
"canapp2"
,
rt_can_thread_entry
,
&
can_data
[
1
],
rt_can_thread_entry
,
&
can_data
[
1
],
512
,
RT_THREAD_PRIORITY_MAX
/
3
-
1
,
20
);
512
,
RT_THREAD_PRIORITY_MAX
/
3
-
1
,
20
);
if
(
tid
!=
RT_NULL
)
rt_thread_startup
(
tid
);
if
(
tid
!=
RT_NULL
)
rt_thread_startup
(
tid
);
return
0
;
return
0
;
}
}
...
...
bsp/stm32f10x/drivers/bxcan.c
浏览文件 @
6fad73c9
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录