38#include "11CXX_rom_driver_CAN.h"
42 const unsigned p_usbd;
43 const unsigned p_clib;
48ROM **rom = (ROM **)0x1fff1ff8;
50static const int RX_MSG_OBJ_NUM = 1;
51static const int TX_MSG_OBJ_NUM = 2;
54typedef struct lpc11crom_can_priv
61static LPC11CRomCanPriv can_private[1] =
69void CAN_IRQHandler (
void){
73static int lpc11crom_can_init(
devtab_t *dev);
74static void ignore_dev_function(
devtab_t *dev);
75static void lpc11crom_can_tx_msg(
devtab_t *dev);
77static void CAN_rx(uint8_t msg_obj_num);
78static void CAN_tx(uint8_t msg_obj_num);
79static void CAN_error(uint32_t error_info);
95const uint32_t ClkInitTable125[2] = {
101static const uint32_t ClkInitTable250[2] = {
110static int lpc11crom_can_init(
devtab_t *dev)
113 (*rom)->pCAND->init_can((uint32_t*) &ClkInitTable250[0], 1);
118 NVIC_EnableIRQ(CAN_IRQn);
122 msg_obj.
msgobj = RX_MSG_OBJ_NUM;
123 msg_obj.
mode_id = 0x000 | CAN_MSGOBJ_EXT;
124 msg_obj.
mask = 0x000;
126 (*rom)->pCAND->config_rxmsgobj(&msg_obj);
128 LPC11CRomCanPriv *priv = (LPC11CRomCanPriv*)dev->
priv;
129 priv->canPriv.enable = ignore_dev_function;
130 priv->canPriv.disable = ignore_dev_function;
131 priv->canPriv.tx_msg = lpc11crom_can_tx_msg;
132 return can_init(dev);
138static void ignore_dev_function(
devtab_t *dev) {}
140static void send_frame(
struct can_frame *can_frame)
143 msg_obj.
msgobj = TX_MSG_OBJ_NUM;
144 msg_obj.
mode_id = can_frame->can_id |
145 (can_frame->can_rtr ? CAN_MSGOBJ_RTR : 0) |
146 (can_frame->can_eff ? CAN_MSGOBJ_EXT : 0);
148 msg_obj.
dlc = can_frame->can_dlc;
149 memcpy(msg_obj.
data, can_frame->data, can_frame->can_dlc);
150 (*rom)->pCAND->can_transmit(&msg_obj);
157static void lpc11crom_can_tx_msg(
devtab_t *dev)
159 LPC11CRomCanPriv *priv = (LPC11CRomCanPriv*)dev->
priv;
160 if (priv->txPending)
return;
162 struct can_frame can_frame;
163 taskENTER_CRITICAL();
169 send_frame(&can_frame);
176void CAN_rx(uint8_t msg_obj_num)
180 msg_obj.
msgobj = msg_obj_num;
183 (*rom)->pCAND->can_receive(&msg_obj);
185 struct can_frame can_frame;
186 can_frame.can_id = msg_obj.
mode_id & ((1<<30) - 1);
187 can_frame.can_rtr = (msg_obj.
mode_id & CAN_MSGOBJ_RTR) ? 1 : 0;
188 can_frame.can_eff = (msg_obj.
mode_id & CAN_MSGOBJ_EXT) ? 1 : 0;
189 can_frame.can_err = 0;
190 can_frame.can_dlc = msg_obj.
dlc;
191 memcpy(can_frame.data, msg_obj.
data, msg_obj.
dlc);
196 can_private[0].canPriv.overrunCount++;
207void CAN_tx(uint8_t msg_obj_num){
209 if (msg_obj_num != TX_MSG_OBJ_NUM)
return;
210 struct can_frame can_frame;
215 can_private[0].txPending = 0;
218 send_frame(&can_frame);
229void CAN_error(uint32_t error_info)
235static CAN_DEVTAB_ENTRY(
can0,
"/dev/can0", lpc11crom_can_init, &can_private[0]);
238#error You need to define TARGET_LPC11Cxx if you want to compiple its rom driver.
MbedCanDriver can0(MbedCanDriver::CAN2, "/dev/can0", config_nmranet_can_bitrate())
The TCH baseboard for the mbed has CAN1 and CAN2 mixed up.
#define OS_MQ_FULL
error code for queue being full
OS_INLINE int os_mq_send_from_isr(os_mq_t queue, const void *data, int *woken)
Send of a message to a queue from ISR context.
OS_INLINE int os_mq_timedreceive(os_mq_t queue, void *data, long long timeout)
Receive a message from a queue.
OS_INLINE int os_mq_receive_from_isr(os_mq_t queue, void *data, int *woken)
Receive a message from a queue from ISR context.
#define OS_MQ_NONE
error code for no error for message queues
All API functions of the ROM can driver.
void(* isr)(void)
Call this from the interrupt service routine.
Specifies the callbacks from the CAN stack to the application.
void * priv
device private data