Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
11CXX_rom_driver_CAN.h
1/****************************************************************************
2 * $Id:: rom_driver_CAN.h 5034 2010-09-24 23:48:37Z nxp12832 $
3 * Project: NXP LPC11xx CAN example
4 *
5 * Description:
6 * This file is part of the CAN and CANopen on-chip driver examples.
7 *
8 ****************************************************************************
9 * Software that is described herein is for illustrative purposes only
10 * which provides customers with programming information regarding the
11 * products. This software is supplied "AS IS" without any warranties.
12 * NXP Semiconductors assumes no responsibility or liability for the
13 * use of the software, conveys no license or title under any patent,
14 * copyright, or mask work right to the product. NXP Semiconductors
15 * reserves the right to make changes in the software without
16 * notification. NXP Semiconductors also make no representation or
17 * warranty that such application will be suitable for the specified
18 * use without further testing or modification.
19****************************************************************************/
20#ifndef _FREERTOS_DRIVERS_NXP_11CXX_ROM_DRIVER_CAN_H_
21#define _FREERTOS_DRIVERS_NXP_11CXX_ROM_DRIVER_CAN_H_
22
23#include "LPC11xx.h"
24
25// error status bits
26#define CAN_ERROR_NONE 0x00000000UL
27#define CAN_ERROR_PASS 0x00000001UL
28#define CAN_ERROR_WARN 0x00000002UL
29#define CAN_ERROR_BOFF 0x00000004UL
30#define CAN_ERROR_STUF 0x00000008UL
31#define CAN_ERROR_FORM 0x00000010UL
32#define CAN_ERROR_ACK 0x00000020UL
33#define CAN_ERROR_BIT1 0x00000040UL
34#define CAN_ERROR_BIT0 0x00000080UL
35#define CAN_ERROR_CRC 0x00000100UL
36
37// control bits for CAN_MSG_OBJ.mode_id
38#define CAN_MSGOBJ_STD 0x00000000UL // CAN 2.0a 11-bit ID
39#define CAN_MSGOBJ_EXT 0x20000000UL // CAN 2.0b 29-bit ID
40#define CAN_MSGOBJ_DAT 0x00000000UL // data frame
41#define CAN_MSGOBJ_RTR 0x40000000UL // rtr frame
42
44typedef struct _CAN_MSG_OBJ {
45 uint32_t mode_id;
47 uint32_t mask;
49 uint8_t data[8];
51 uint8_t dlc;
53 uint8_t msgobj;
56
57/**************************************************************************
58SDO Abort Codes
59**************************************************************************/
60#define SDO_ABORT_TOGGLE 0x05030000UL // Toggle bit not alternated
61#define SDO_ABORT_SDOTIMEOUT 0x05040000UL // SDO protocol timed out
62#define SDO_ABORT_UNKNOWN_COMMAND 0x05040001UL // Client/server command specifier not valid or unknown
63#define SDO_ABORT_UNSUPPORTED 0x06010000UL // Unsupported access to an object
64#define SDO_ABORT_WRITEONLY 0x06010001UL // Attempt to read a write only object
65#define SDO_ABORT_READONLY 0x06010002UL // Attempt to write a read only object
66#define SDO_ABORT_NOT_EXISTS 0x06020000UL // Object does not exist in the object dictionary
67#define SDO_ABORT_PARAINCOMP 0x06040043UL // General parameter incompatibility reason
68#define SDO_ABORT_ACCINCOMP 0x06040047UL // General internal incompatibility in the device
69#define SDO_ABORT_TYPEMISMATCH 0x06070010UL // Data type does not match, length of service parameter does not match
70#define SDO_ABORT_UNKNOWNSUB 0x06090011UL // Sub-index does not exist
71#define SDO_ABORT_VALUE_RANGE 0x06090030UL // Value range of parameter exceeded (only for write access)
72#define SDO_ABORT_TRANSFER 0x08000020UL // Data cannot be transferred or stored to the application
73#define SDO_ABORT_LOCAL 0x08000021UL // Data cannot be transferred or stored to the application because of local control
74#define SDO_ABORT_DEVSTAT 0x08000022UL // Data cannot be transferred or stored to the application because of the present device state
75
77typedef struct _CAN_ODCONSTENTRY {
78 uint16_t index;
80 uint8_t subindex;
82 uint8_t len;
84 uint32_t val;
87
88// upper-nibble values for CAN_ODENTRY.entrytype_len
89#define OD_NONE 0x00
90#define OD_EXP_RO 0x10
91#define OD_EXP_WO 0x20
92#define OD_EXP_RW 0x30
93#define OD_SEG_RO 0x40
94#define OD_SEG_WO 0x50
95#define OD_SEG_RW 0x60
96
98typedef struct _CAN_ODENTRY {
99 uint16_t index;
101 uint8_t subindex;
103 uint8_t entrytype_len;
105 uint8_t *val;
108
110typedef struct _CAN_CANOPENCFG {
111 uint8_t node_id;
113 uint8_t msgobj_rx;
115 uint8_t msgobj_tx;
117 uint8_t isr_handled;
119 uint32_t od_const_num;
123 uint32_t od_num;
128
129// Return values for CANOPEN_sdo_req() callback
130#define CAN_SDOREQ_NOTHANDLED 0
131#define CAN_SDOREQ_HANDLED_SEND 1
132#define CAN_SDOREQ_HANDLED_NOSEND 2
133
134// Values for CANOPEN_sdo_seg_read/write() callback 'openclose' parameter
135#define CAN_SDOSEG_SEGMENT 0
136#define CAN_SDOSEG_OPEN 1
137#define CAN_SDOSEG_CLOSE 2
138
140typedef struct _CAN_CALLBACKS {
142 void (*CAN_rx)(uint8_t msg_obj_num);
144 void (*CAN_tx)(uint8_t msg_obj_num);
146 void (*CAN_error)(uint32_t error_info);
148 uint32_t (*CANOPEN_sdo_read)(uint16_t index, uint8_t subindex);
150 uint32_t (*CANOPEN_sdo_write)(uint16_t index, uint8_t subindex, uint8_t *dat_ptr);
152 uint32_t (*CANOPEN_sdo_seg_read)(uint16_t index, uint8_t subindex, uint8_t openclose, uint8_t *length, uint8_t *data, uint8_t *last);
154 uint32_t (*CANOPEN_sdo_seg_write)(uint16_t index, uint8_t subindex, uint8_t openclose, uint8_t length, uint8_t *data, uint8_t *fast_resp);
156 uint8_t (*CANOPEN_sdo_req)(uint8_t length_req, uint8_t *req_ptr, uint8_t *length_resp, uint8_t *resp_ptr);
158
159// API function prototypes
160extern void init_can(uint32_t * can_cfg, uint8_t isr_ena);
161extern void isr(void);
162extern void config_rxmsgobj(CAN_MSG_OBJ * msg_obj);
163extern uint8_t can_receive(CAN_MSG_OBJ * msg_obj);
164extern void can_transmit(CAN_MSG_OBJ * msg_obj);
165extern void config_canopen(CAN_CANOPENCFG * canopen_cfg);
166extern void canopen_handler(void);
167extern void config_calb(CAN_CALLBACKS * callback_cfg);
168
170typedef struct _CAND {
172 void (*init_can)(uint32_t * can_cfg, uint8_t isr_ena);
174 void (*isr)(void);
176 void (*config_rxmsgobj)(CAN_MSG_OBJ * msg_obj);
178 uint8_t (*can_receive)(CAN_MSG_OBJ * msg_obj);
180 void (*can_transmit)(CAN_MSG_OBJ * msg_obj);
182 void (*config_canopen)(CAN_CANOPENCFG * canopen_cfg);
184 void (*canopen_handler)(void);
186 void (*config_calb)(CAN_CALLBACKS * callback_cfg);
187}CAND;
188
189void CANInit(void);
190
191#endif /* __ROM_DRIVER_CAN_H__ */
All API functions of the ROM can driver.
Specifies the callbacks from the CAN stack to the application.
Helper struct for CANOpen configuration.
CAN_ODCONSTENTRY * od_const_table
?
CAN_ODENTRY * od_table
?
CAN message object.
CanOpen message entry.
helper struct to specify a hardware CAN buffer entry.