1 /* 2 * @brief LPC15xx CAN ROM API declarations and functions 3 * 4 * @note 5 * Copyright(C) NXP Semiconductors, 2014 6 * All rights reserved. 7 * 8 * @par 9 * Software that is described herein is for illustrative purposes only 10 * which provides customers with programming information regarding the 11 * LPC products. This software is supplied "AS IS" without any warranties of 12 * any kind, and NXP Semiconductors and its licensor disclaim any and 13 * all warranties, express or implied, including all implied warranties of 14 * merchantability, fitness for a particular purpose and non-infringement of 15 * intellectual property rights. NXP Semiconductors assumes no responsibility 16 * or liability for the use of the software, conveys no license or rights under any 17 * patent, copyright, mask work right, or any other intellectual property rights in 18 * or to any products. NXP Semiconductors reserves the right to make changes 19 * in the software without notification. NXP Semiconductors also makes no 20 * representation or warranty that such application will be suitable for the 21 * specified use without further testing or modification. 22 * 23 * @par 24 * Permission to use, copy, modify, and distribute this software and its 25 * documentation is hereby granted, under NXP Semiconductors' and its 26 * licensor's relevant copyrights in the software, without fee, provided that it 27 * is used in conjunction with NXP Semiconductors microcontrollers. This 28 * copyright, permission, and disclaimer notice must appear in all copies of 29 * this code. 30 */ 31 32 #ifndef __ROM_CAN_15XX_H_ 33 #define __ROM_CAN_15XX_H_ 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 /** @defgroup CANROM_15XX CHIP: LPC15xx CAN ROM API declarations and functions 40 * @ingroup ROMAPI_15XX 41 * @{ 42 */ 43 44 /* error status bits */ 45 #define CAN_ERROR_NONE 0x00000000UL 46 #define CAN_ERROR_PASS 0x00000001UL 47 #define CAN_ERROR_WARN 0x00000002UL 48 #define CAN_ERROR_BOFF 0x00000004UL 49 #define CAN_ERROR_STUF 0x00000008UL 50 #define CAN_ERROR_FORM 0x00000010UL 51 #define CAN_ERROR_ACK 0x00000020UL 52 #define CAN_ERROR_BIT1 0x00000040UL 53 #define CAN_ERROR_BIT0 0x00000080UL 54 #define CAN_ERROR_CRC 0x00000100UL 55 56 typedef void *CAN_HANDLE_T; /* define TYPE for CAN handle pointer */ 57 58 typedef struct _CAN_MSG_OBJ { 59 uint32_t mode_id; 60 uint32_t mask; 61 uint8_t data[8]; 62 uint8_t dlc; 63 uint8_t msgobj; 64 } CAN_MSG_OBJ; 65 66 typedef struct _CAN_CALLBACKS { 67 void (*CAN_rx)(uint8_t msg_obj); 68 void (*CAN_tx)(uint8_t msg_obj); 69 void (*CAN_error)(uint32_t error_info); 70 } CAN_CALLBACKS; 71 72 typedef struct _CAN_CFG { 73 uint32_t clkdiv; 74 uint32_t btr; 75 uint32_t isr_ena; 76 } CAN_CFG; 77 78 typedef struct _CAN_ODCONSTENTRY { 79 uint16_t index; 80 uint8_t subindex; 81 uint8_t len; 82 uint32_t val; 83 } CAN_ODCONSTENTRY; 84 85 typedef struct _CAN_ODENTRY { 86 uint16_t index; 87 uint8_t subindex; 88 uint8_t entrytype_len; 89 uint8_t *val; 90 } CAN_ODENTRY; 91 92 typedef struct _CAN_CANOPENCFG { 93 uint8_t node_id; 94 uint8_t msgobj_rx; 95 uint8_t msgobj_tx; 96 uint8_t isr_handled; 97 uint32_t od_const_num; 98 CAN_ODCONSTENTRY *od_const_table; 99 uint32_t od_num; 100 CAN_ODENTRY *od_table; 101 } CAN_CANOPENCFG; 102 103 typedef struct _CANOPEN_CALLBACKS { 104 uint32_t (*CANOPEN_sdo_read)(uint16_t index, uint8_t subindex); 105 uint32_t (*CANOPEN_sdo_write)(uint16_t index, uint8_t subindex, uint8_t *dat_ptr); 106 uint32_t (*CANOPEN_sdo_seg_read)(uint16_t index, uint8_t subindex, uint8_t 107 openclose, uint8_t *length, uint8_t *data, uint8_t *last); 108 uint32_t (*CANOPEN_sdo_seg_write)(uint16_t index, uint8_t subindex, uint8_t 109 openclose, uint8_t length, uint8_t *data, uint8_t *fast_resp); 110 uint8_t (*CANOPEN_sdo_req)(uint8_t length_req, uint8_t *req_ptr, uint8_t 111 *length_resp, uint8_t *resp_ptr); 112 } CANOPEN_CALLBACKS; 113 114 typedef struct _CAN_API_INIT_PARAM_T { 115 uint32_t mem_base; /* Address of user-space memory area to use */ 116 uint32_t can_reg_base; /* Address of start of CAN controller register area */ 117 CAN_CFG *can_cfg; 118 CAN_CALLBACKS *callbacks; 119 CAN_CANOPENCFG *canopen_cfg; 120 CANOPEN_CALLBACKS *co_callbacks; 121 } CAN_API_INIT_PARAM_T; 122 123 /** 124 * @brief LPC15XX CAN ROM API structure 125 * The CAN profile API provides functions to configure and manage the CAN sub-system. 126 */ 127 typedef struct _CAND_API_T { 128 uint32_t (*hwCAN_GetMemSize)(CAN_API_INIT_PARAM_T *param); 129 ErrorCode_t (*hwCAN_Init)(CAN_HANDLE_T *phCan, CAN_API_INIT_PARAM_T *param); 130 void (*hwCAN_Isr)(CAN_HANDLE_T hCan); 131 void (*hwCAN_ConfigRxmsgobj)(CAN_HANDLE_T hCan, CAN_MSG_OBJ *msg_obj); 132 uint8_t (*hwCAN_MsgReceive)(CAN_HANDLE_T hCan, CAN_MSG_OBJ *msg_obj); 133 void (*hwCAN_MsgTransmit)(CAN_HANDLE_T hCan, CAN_MSG_OBJ *msg_obj); 134 void (*hwCAN_CANopenHandler)(CAN_HANDLE_T hCan); 135 } CAND_API_T; 136 137 uint32_t hwCAN_GetMemSize(CAN_API_INIT_PARAM_T *param); 138 139 ErrorCode_t hwCAN_Init(CAN_HANDLE_T *phCan, CAN_API_INIT_PARAM_T *param); 140 141 void hwCAN_Isr(CAN_HANDLE_T hCan); 142 143 void hwCAN_ConfigRxmsgobj(CAN_HANDLE_T hCan, CAN_MSG_OBJ *msg_obj); 144 145 uint8_t hwCAN_MsgReceive(CAN_HANDLE_T hCan, CAN_MSG_OBJ *msg_obj); 146 147 void hwCAN_MsgTransmit(CAN_HANDLE_T hCan, CAN_MSG_OBJ *msg_obj); 148 149 void hwCAN_CANopenHandler(CAN_HANDLE_T hCan); 150 151 /** 152 * @} 153 */ 154 155 #ifdef __cplusplus 156 } 157 #endif 158 159 #endif /* __ROM_CAN_15XX_H_ */ 160