![]() |
|
|||
File indexing completed on 2025-05-11 08:23:03
0001 /** 0002 * @file 0003 * 0004 * @ingroup RTEMSBSPsARMLPC176X 0005 * 0006 * @brief CAN controller for the mbed lpc1768 board. 0007 */ 0008 0009 /* 0010 * Copyright (c) 2014 Taller Technologies. 0011 * 0012 * @author Diaz Marcos (marcos.diaz@tallertechnologies.com) 0013 * @author Daniel Chicco (daniel.chicco@tallertechnologies.com) 0014 * 0015 * The license and distribution terms for this file may be 0016 * found in the file LICENSE in this distribution or at 0017 * http://www.rtems.org/license/LICENSE. 0018 */ 0019 0020 #ifndef LPC176X_CAN_H 0021 #define LPC176X_CAN_H 0022 0023 #include <bsp.h> 0024 #include <bsp/io.h> 0025 #include <bsp/lpc176x.h> 0026 0027 #ifdef __cplusplus 0028 extern "C" { 0029 #endif /* __cplusplus */ 0030 0031 /** 0032 * @brief The CAN devices of the board. 0033 */ 0034 typedef enum { 0035 CAN_0, 0036 CAN_1, 0037 CAN_DEVICES_NUMBER 0038 } lpc176x_can_number; 0039 0040 /** 0041 * @brief A CAN message represented for the registers of the device. 0042 */ 0043 typedef struct { 0044 uint32_t info; 0045 uint32_t id; 0046 uint32_t data_a; 0047 uint32_t data_b; 0048 } registers_can_message; 0049 0050 /** 0051 * @brief A CAN message represented with each logical parts 0052 */ 0053 typedef struct { 0054 unsigned int reserved1 : 16; 0055 unsigned int dlc : 4; /* Bits 16..19: DLC - Data Length Counter*/ 0056 unsigned int reserved0 : 10; 0057 unsigned int rtr : 1; /* Bit 30: Set if this is a RTR message*/ 0058 unsigned int type : 1; /* Bit 31: Set if this is a 29-bit ID message*/ 0059 unsigned int id; /* CAN Message ID (11-bit or 29-bit)*/ 0060 unsigned char data[ 8 ]; /* CAN Message Data Bytes 0-7*/ 0061 } low_level_can_message; 0062 0063 /** 0064 * @brief A CAN message represented of both forms. 0065 */ 0066 typedef union { 0067 low_level_can_message low_level; 0068 registers_can_message registers; 0069 } can_message; 0070 0071 /** 0072 * @brief The possible interrupt sources for CAN. 0073 */ 0074 typedef enum { 0075 IRQ_RX = 0, 0076 IRQ_TX, 0077 IRQ_ERROR, 0078 IRQ_OVERRUN, 0079 IRQ_WAKEUP, 0080 IRQ_PASSIVE, 0081 IRQ_ARB, 0082 IRQ_BUS, 0083 IRQ_READY, 0084 CAN_IRQ_NUMBER 0085 } can_irq_type; 0086 0087 /** 0088 * @brief An isr for a CAN interrupt 0089 * 0090 * @param number The CAN which rised the interrupt. 0091 */ 0092 typedef void (*lpc176x_can_isr) ( lpc176x_can_number number ); 0093 0094 /** 0095 * @brief A CAN frequency value 0096 */ 0097 typedef unsigned int can_freq; 0098 0099 /** 0100 * @brief Opens CAN device. 0101 * @details It enables the module and gives it a clock, sets the pins, 0102 * disables the interrupts, sets the frequency and bypasses 0103 * the acceptance filter. 0104 * 0105 * @param minor The device to open. 0106 * @param freq The desired frequency. 0107 * @return RTEMS_SUCCESFUL on success. 0108 */ 0109 rtems_status_code can_open( lpc176x_can_number minor, can_freq freq ); 0110 0111 /** 0112 * @brief Closes the passed CAN device and shut it down. 0113 * 0114 * @param minor The device to close. 0115 * @return RTEMS_SUCCESSFUL if ok, RTEMS_INVALID_NUMBER for a bad parameter. 0116 */ 0117 rtems_status_code can_close( lpc176x_can_number minor ); 0118 0119 /** 0120 * @brief Reads the CAN device. 0121 * 0122 * @param minor The CAN device to read. 0123 * @param message The read message. 0124 * @return RTEMS_SUCCESSFUL if read ok, RTEMS_IO_ERROR otherwise. 0125 */ 0126 rtems_status_code can_read( 0127 const lpc176x_can_number minor, 0128 can_message *message 0129 ); 0130 0131 /** 0132 * @brief Writes the passed CAN message into the selected CAN device. 0133 * 0134 * @param minor The device to write. 0135 * @param message The message to write. 0136 * @return RTEMS_SUCCESFUL if write ok. RTEMS_IO_ERROR otherwise. 0137 */ 0138 rtems_status_code can_write( 0139 const lpc176x_can_number minor, 0140 const can_message *const message 0141 ); 0142 0143 /** 0144 * @brief Registers an isr in the driver vector, and enables the interrupt 0145 * in the device. 0146 * 0147 * @param number The CAN device to set 0148 * @param type The interrupt type. 0149 * @param isr The isr to register. 0150 * @return RTEMS_SUCCESSFUL if ok RTEMS_INVALID_NUMBER otherwise. 0151 */ 0152 rtems_status_code can_register_isr( 0153 const lpc176x_can_number number, 0154 const can_irq_type type, 0155 const lpc176x_can_isr isr 0156 ); 0157 0158 /** 0159 * @brief Creates a CAN message. 0160 * @details [long description] 0161 * 0162 * @param msg The created message. 0163 * @param _id The can id for the message. 0164 * @param _data The data of the message. 0165 * @param _len The length of the message. 0166 * @return RTEMS_SUCCESFUL if created, RTEMS_INVALID_NUMBER otherwise. 0167 */ 0168 rtems_status_code create_can_message( 0169 can_message *const msg, 0170 const int _id, 0171 const char *const _data, 0172 const char _len 0173 ); 0174 0175 #ifdef __cplusplus 0176 } 0177 #endif /* __cplusplus */ 0178 0179 #endif /* ifndef LPC176X_CAN_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |