mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-06-21 05:42:29 +08:00
Merge pull request #511 from AubrCool/fix-lpc4088candriver
Fix lpc4088candriver
This commit is contained in:
@@ -64,5 +64,5 @@ void rt_hw_board_init()
|
||||
lpc_sdram_hw_init();
|
||||
rt_kprintf("done!\n");
|
||||
#endif
|
||||
|
||||
rt_components_board_init();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* File : canapp.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2015-05-14 aubrcool@qq.com first version
|
||||
*/
|
||||
|
||||
#include <board.h>
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
#ifdef RT_USING_CAN
|
||||
#include "drv_lpccan.h"
|
||||
struct can_app_struct
|
||||
{
|
||||
const char* name;
|
||||
struct rt_can_filter_config * filter;
|
||||
rt_uint8_t eventopt;
|
||||
struct rt_semaphore sem;
|
||||
};
|
||||
static struct can_app_struct can_data[1];
|
||||
struct rt_can_filter_item filter1item[4] =
|
||||
{
|
||||
LPC_CAN_AF_STD_INIT(1),
|
||||
LPC_CAN_AF_STD_GRP_INIT(3,5),
|
||||
LPC_CAN_AF_EXT_INIT(2),
|
||||
LPC_CAN_AF_EXT_GRP_INIT(4,6),
|
||||
};
|
||||
struct rt_can_filter_config filter1 =
|
||||
{
|
||||
.count = 4,
|
||||
.actived = 1,
|
||||
.items = filter1item,
|
||||
};
|
||||
static struct can_app_struct can_data[1] = {
|
||||
{
|
||||
.name = "lpccan1",
|
||||
.filter = &filter1,
|
||||
.eventopt = RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR,
|
||||
},
|
||||
};
|
||||
static rt_err_t lpccanind(rt_device_t dev, rt_size_t size)
|
||||
{
|
||||
rt_sem_release(&can_data[0].sem);
|
||||
}
|
||||
void rt_can_thread_entry(void* parameter)
|
||||
{
|
||||
struct rt_can_msg msg;
|
||||
struct can_app_struct* canpara = (struct can_app_struct*) parameter;
|
||||
rt_device_t candev;
|
||||
|
||||
candev = rt_device_find(canpara->name);
|
||||
RT_ASSERT(candev);
|
||||
rt_sem_init(&canpara->sem, canpara->name, 0, RT_IPC_FLAG_FIFO);
|
||||
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_set_rx_indicate(candev, lpccanind);
|
||||
while(1) {
|
||||
rt_sem_take(&canpara->sem, RT_WAITING_FOREVER);
|
||||
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)
|
||||
{
|
||||
rt_thread_t tid;
|
||||
|
||||
tid = rt_thread_create("canapp1",
|
||||
rt_can_thread_entry, &can_data[0],
|
||||
512, RT_THREAD_PRIORITY_MAX /3 - 1, 20);
|
||||
if (tid != RT_NULL) rt_thread_startup(tid);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
INIT_APP_EXPORT(rt_can_app_init);
|
||||
#endif /*RT_USING_CAN*/
|
||||
@@ -39,7 +39,6 @@ void rtthread_startup(void)
|
||||
rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* initialize scheduler system */
|
||||
rt_system_scheduler_init();
|
||||
/* initialize system timer*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* File : drv_lpccan.h
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2015, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2015-06-30 aubrcool@qq.com first version
|
||||
*/
|
||||
|
||||
#ifndef DRV_LPCCAN_H_
|
||||
#define DRV_LPCCAN_H_
|
||||
#include <rthw.h>
|
||||
#include <rtdevice.h>
|
||||
|
||||
#define LPC_CAN_AF_STD_INIT(id) \
|
||||
RT_CAN_FILTER_ITEM_INIT(id,0,0,0,0xFFFFFFFF)
|
||||
#define LPC_CAN_AF_EXT_INIT(id) \
|
||||
RT_CAN_FILTER_ITEM_INIT(id,1,0,0,0xFFFFFFFF)
|
||||
#define LPC_CAN_AF_STD_GRP_INIT(id1,id2) \
|
||||
RT_CAN_FILTER_ITEM_INIT(id1,0,0,1,id2)
|
||||
#define LPC_CAN_AF_EXT_GRP_INIT(id1,id2) \
|
||||
RT_CAN_FILTER_ITEM_INIT(id1,1,0,1,id2)
|
||||
|
||||
#endif /*DRV_LPCCAN_H_*/
|
||||
File diff suppressed because it is too large
Load Diff
@@ -72,6 +72,7 @@
|
||||
#define RT_USING_DEVICE_IPC
|
||||
// <bool name="RT_USING_SERIAL" description="Using Serial Device Driver Framework" default="true" />
|
||||
#define RT_USING_SERIAL
|
||||
#define RT_USING_CAN
|
||||
// <integer name="RT_UART_RX_BUFFER_SIZE" description="The buffer size for UART reception" default="64" />
|
||||
#define RT_UART_RX_BUFFER_SIZE 64
|
||||
// </section>
|
||||
@@ -95,6 +96,7 @@
|
||||
#define RT_USING_COMPONENTS_INIT
|
||||
// <section name="RT_USING_FINSH" description="Using finsh as shell, which is a C-Express shell" default="true" >
|
||||
#define RT_USING_FINSH
|
||||
#define FINSH_USING_MSH
|
||||
// <bool name="FINSH_USING_SYMTAB" description="Using symbol table in finsh shell" default="true" />
|
||||
#define FINSH_USING_SYMTAB
|
||||
// <bool name="FINSH_USING_DESCRIPTION" description="Keeping description in symbol table" default="true" />
|
||||
@@ -236,5 +238,6 @@
|
||||
// </section>
|
||||
|
||||
// </RDTConfigurator>
|
||||
|
||||
#define RT_USING_LPCCAN1
|
||||
#define RT_USING_CPU_FFS
|
||||
#endif
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include <board.h>
|
||||
#include <bxcan.h>
|
||||
#ifdef RT_USING_COMPONENTS_INIT
|
||||
#include <init/components.h>
|
||||
#include <components.h>
|
||||
#endif
|
||||
#ifdef RT_USING_CAN
|
||||
|
||||
|
||||
@@ -607,11 +607,15 @@ static rt_err_t rt_can_control(struct rt_device *dev,
|
||||
*/
|
||||
static void cantimeout(void* arg)
|
||||
{
|
||||
#ifdef RT_CAN_USING_LED
|
||||
rt_uint32_t ledonflag = 0;
|
||||
#endif /*RT_CAN_USING_LED*/
|
||||
rt_can_t can = (rt_can_t)arg;
|
||||
rt_device_control((rt_device_t)can,RT_CAN_CMD_GET_STATUS,(void* )&can->status);
|
||||
if(can->timerinitflag == 1) {
|
||||
ledonflag = 1;
|
||||
#ifdef RT_CAN_USING_LED
|
||||
ledonflag = 1;
|
||||
#endif /*RT_CAN_USING_LED*/
|
||||
can->timerinitflag = 0xFF;
|
||||
}
|
||||
#ifdef RT_CAN_USING_LED
|
||||
@@ -713,17 +717,12 @@ rt_err_t rt_hw_can_register(struct rt_can_device *can,
|
||||
|
||||
device->user_data = data;
|
||||
can->timerinitflag = 0;
|
||||
if(can->config.rcvled != RT_NULL ||
|
||||
can->config.sndled != RT_NULL ||
|
||||
can->config.errled != RT_NULL)
|
||||
{
|
||||
rt_timer_init(&can->timer,
|
||||
name,
|
||||
cantimeout,
|
||||
(void*)can,
|
||||
can->config.ticks,
|
||||
RT_TIMER_FLAG_PERIODIC);
|
||||
}
|
||||
rt_timer_init(&can->timer,
|
||||
name,
|
||||
cantimeout,
|
||||
(void*)can,
|
||||
can->config.ticks,
|
||||
RT_TIMER_FLAG_PERIODIC);
|
||||
/* register a character device */
|
||||
return rt_device_register(device, name, RT_DEVICE_FLAG_RDWR);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#ifndef CAN_H_
|
||||
#define CAN_H_
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
#ifndef RT_CANMSG_BOX_SZ
|
||||
#define RT_CANMSG_BOX_SZ 16
|
||||
#endif
|
||||
@@ -58,8 +60,10 @@ struct rt_can_filter_item
|
||||
rt_uint32_t mode :1;
|
||||
rt_uint32_t mask;
|
||||
rt_int32_t hdr;
|
||||
#ifdef RT_CAN_USING_HDR
|
||||
rt_err_t (*ind)(rt_device_t dev, void* args ,rt_int32_t hdr, rt_size_t size);
|
||||
void* args;
|
||||
void* args;
|
||||
#endif /*RT_CAN_USING_HDR*/
|
||||
};
|
||||
#ifdef RT_CAN_USING_HDR
|
||||
#define RT_CAN_FILTER_ITEM_INIT(id,ide,rtr,mode,mask,ind,args) \
|
||||
@@ -86,7 +90,7 @@ struct rt_can_filter_item
|
||||
#define RT_CAN_EXT_RMT_DATA_FILTER_INIT(id,ind,args) \
|
||||
RT_CAN_FILTER_ITEM_INIT(id,1,0,1,0xFFFFFFFF,ind,args)
|
||||
#else
|
||||
#define RT_CAN_FILTER_ITEM_INIT(id,ide,rtr,mode,mask,args) \
|
||||
#define RT_CAN_FILTER_ITEM_INIT(id,ide,rtr,mode,mask) \
|
||||
{\
|
||||
id,\
|
||||
ide,\
|
||||
@@ -94,20 +98,19 @@ struct rt_can_filter_item
|
||||
mode,\
|
||||
mask,\
|
||||
-1,\
|
||||
args,\
|
||||
}
|
||||
#define RT_CAN_FILTER_STD_INIT(id,args) \
|
||||
RT_CAN_FILTER_ITEM_INIT(id,0,0,0,0xFFFFFFFF,args)
|
||||
#define RT_CAN_FILTER_EXT_INIT(id,args) \
|
||||
RT_CAN_FILTER_ITEM_INIT(id,1,0,0,0xFFFFFFFF,args)
|
||||
#define RT_CAN_STD_RMT_FILTER_INIT(id,args) \
|
||||
RT_CAN_FILTER_ITEM_INIT(id,0,1,0,0xFFFFFFFF,args)
|
||||
#define RT_CAN_EXT_RMT_FILTER_INIT(id,args) \
|
||||
RT_CAN_FILTER_ITEM_INIT(id,1,1,0,0xFFFFFFFF,args)
|
||||
#define RT_CAN_STD_RMT_DATA_FILTER_INIT(id,args) \
|
||||
RT_CAN_FILTER_ITEM_INIT(id,0,0,1,0xFFFFFFFF,args)
|
||||
#define RT_CAN_EXT_RMT_DATA_FILTER_INIT(id,args) \
|
||||
RT_CAN_FILTER_ITEM_INIT(id,1,0,1,0xFFFFFFFF,args)
|
||||
#define RT_CAN_FILTER_STD_INIT(id) \
|
||||
RT_CAN_FILTER_ITEM_INIT(id,0,0,0,0xFFFFFFFF)
|
||||
#define RT_CAN_FILTER_EXT_INIT(id) \
|
||||
RT_CAN_FILTER_ITEM_INIT(id,1,0,0,0xFFFFFFFF)
|
||||
#define RT_CAN_STD_RMT_FILTER_INIT(id) \
|
||||
RT_CAN_FILTER_ITEM_INIT(id,0,1,0,0xFFFFFFFF)
|
||||
#define RT_CAN_EXT_RMT_FILTER_INIT(id) \
|
||||
RT_CAN_FILTER_ITEM_INIT(id,1,1,0,0xFFFFFFFF)
|
||||
#define RT_CAN_STD_RMT_DATA_FILTER_INIT(id) \
|
||||
RT_CAN_FILTER_ITEM_INIT(id,0,0,1,0xFFFFFFFF)
|
||||
#define RT_CAN_EXT_RMT_DATA_FILTER_INIT(id) \
|
||||
RT_CAN_FILTER_ITEM_INIT(id,1,0,1,0xFFFFFFFF)
|
||||
#endif
|
||||
|
||||
struct rt_can_filter_config
|
||||
|
||||
Reference in New Issue
Block a user