Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:43

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  * @ingroup can
0006  * @brief Driver API for GRLIB wrapper to OpenCores CAN
0007  */
0008 
0009 /*
0010  *  COPYRIGHT (c) 2007.
0011  *  Cobham Gaisler AB.
0012  *
0013  * Redistribution and use in source and binary forms, with or without
0014  * modification, are permitted provided that the following conditions
0015  * are met:
0016  * 1. Redistributions of source code must retain the above copyright
0017  *    notice, this list of conditions and the following disclaimer.
0018  * 2. Redistributions in binary form must reproduce the above copyright
0019  *    notice, this list of conditions and the following disclaimer in the
0020  *    documentation and/or other materials provided with the distribution.
0021  *
0022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0023  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0025  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0026  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0027  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0028  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0029  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0030  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0031  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0032  * POSSIBILITY OF SUCH DAMAGE.
0033  */
0034 
0035 #ifndef __OCCAN_DRIVER_H__
0036 #define __OCCAN_DRIVER_H__
0037 
0038 #ifdef __cplusplus
0039 extern "C" {
0040 #endif
0041 
0042 /* CAN MESSAGE */
0043 typedef struct {
0044     char extended; /* 1= Extended Frame (29-bit id), 0= STD Frame (11-bit id) */
0045     char rtr; /* RTR - Remote Transmission Request */
0046     char sshot; /* single shot */
0047     unsigned char len;
0048     unsigned char data[8];
0049     unsigned int id;
0050 } CANMsg;
0051 
0052 typedef struct {
0053     /* tx/rx stats */
0054     unsigned int rx_msgs;
0055     unsigned int tx_msgs;
0056 
0057     /* Error Interrupt counters */
0058     unsigned int err_warn;
0059     unsigned int err_dovr;
0060     unsigned int err_errp;
0061     unsigned int err_arb;
0062     unsigned int err_bus;
0063 
0064     /**** BUS ERRORS (err_arb) ****/
0065 
0066     /* ALC 4-0 */
0067     unsigned int err_arb_bitnum[32]; /* At what bit arbitration is lost */
0068 
0069     /******************************/
0070 
0071     /**** BUS ERRORS (err_bus) ****/
0072 
0073     /* ECC 7-6 */
0074     unsigned int err_bus_bit; /* Bit error */
0075     unsigned int err_bus_form; /* Form Error */
0076     unsigned int err_bus_stuff; /* Stuff Error */
0077     unsigned int err_bus_other; /* Other Error */
0078 
0079     /* ECC 5 */
0080     unsigned int err_bus_rx; /* Errors during Reception */
0081     unsigned int err_bus_tx; /* Errors during Transmission */
0082 
0083     /* ECC 4:0 */
0084     unsigned int err_bus_segs[32]; /* Segment (Where in frame error occured)
0085                                     * See OCCAN_SEG_* defines for indexes
0086                                     */
0087 
0088     /******************************/
0089 
0090 
0091     /* total number of interrupts */
0092     unsigned int ints;
0093 
0094     /* software monitoring hw errors */
0095     unsigned int tx_buf_error;
0096 
0097   /* Software fifo overrun */
0098   unsigned int rx_sw_dovr;
0099 
0100 } occan_stats;
0101 
0102 /* indexes into occan_stats.err_bus_segs[index] */
0103 #define OCCAN_SEG_ID28 0x02 /* ID field bit 28:21 */
0104 #define OCCAN_SEG_ID20 0x06 /* ID field bit 20:18 */
0105 #define OCCAN_SEG_ID17 0x07 /* ID field bit 17:13 */
0106 #define OCCAN_SEG_ID12 0x0f /* ID field bit 12:5 */
0107 #define OCCAN_SEG_ID4 0x0e  /* ID field bit 4:0 */
0108 
0109 #define OCCAN_SEG_START 0x03 /* Start of Frame */
0110 #define OCCAN_SEG_SRTR 0x04  /* Bit SRTR */
0111 #define OCCAN_SEG_IDE 0x05   /* Bit IDE */
0112 #define OCCAN_SEG_RTR 0x0c   /* Bit RTR */
0113 #define OCCAN_SEG_RSV0 0x09  /* Reserved bit 0 */
0114 #define OCCAN_SEG_RSV1 0x0d  /* Reserved bit 1 */
0115 
0116 #define OCCAN_SEG_DLEN 0x0b    /* Data Length code */
0117 #define OCCAN_SEG_DFIELD 0x0a  /* Data Field */
0118 
0119 #define OCCAN_SEG_CRC_SEQ 0x08    /* CRC Sequence */
0120 #define OCCAN_SEG_CRC_DELIM 0x18  /* CRC Delimiter */
0121 
0122 #define OCCAN_SEG_ACK_SLOT 0x19   /* Acknowledge slot */
0123 #define OCCAN_SEG_ACK_DELIM 0x1b  /* Acknowledge delimiter */
0124 #define OCCAN_SEG_EOF 0x1a        /* End Of Frame */
0125 #define OCCAN_SEG_INTERMISSION 0x12 /* Intermission */
0126 #define OCCAN_SEG_ACT_ERR 0x11    /* Active error flag */
0127 #define OCCAN_SEG_PASS_ERR 0x16   /* Passive error flag */
0128 #define OCCAN_SEG_DOMINANT 0x13   /* Tolerate dominant bits */
0129 #define OCCAN_SEG_EDELIM 0x17     /* Error delimiter */
0130 #define OCCAN_SEG_OVERLOAD 0x1c   /* overload flag */
0131 
0132 
0133 #define CANMSG_OPT_RTR 0x40             /* RTR Frame */
0134 #define CANMSG_OPT_EXTENDED 0x80  /* Exteneded frame */
0135 #define CANMSG_OPT_SSHOT 0x01     /* Single Shot, no retry */
0136 
0137 #define OCCAN_IOC_START 1
0138 #define OCCAN_IOC_STOP  2
0139 
0140 #define OCCAN_IOC_GET_CONF 3
0141 #define OCCAN_IOC_GET_STATS 4
0142 #define OCCAN_IOC_GET_STATUS 5
0143 
0144 #define OCCAN_IOC_SET_SPEED 6
0145 #define OCCAN_IOC_SPEED_AUTO 7
0146 #define OCCAN_IOC_SET_LINK 8
0147 #define OCCAN_IOC_SET_FILTER 9
0148 #define OCCAN_IOC_SET_BLK_MODE 10
0149 #define OCCAN_IOC_SET_BUFLEN 11
0150 #define OCCAN_IOC_SET_BTRS 12
0151 
0152 
0153 struct occan_afilter {
0154     unsigned char code[4];
0155     unsigned char mask[4];
0156     int single_mode;
0157 };
0158 
0159 #define OCCAN_STATUS_RESET 0x01
0160 #define OCCAN_STATUS_OVERRUN 0x02
0161 #define OCCAN_STATUS_WARN 0x04
0162 #define OCCAN_STATUS_ERR_PASSIVE 0x08
0163 #define OCCAN_STATUS_ERR_BUSOFF 0x10
0164 #define OCCAN_STATUS_QUEUE_ERROR 0x80
0165 
0166 #define OCCAN_BLK_MODE_RX 0x1
0167 #define OCCAN_BLK_MODE_TX 0x2
0168 
0169 void occan_register_drv (void);
0170 
0171 
0172 #define OCCAN_SPEED_500K 500000
0173 #define OCCAN_SPEED_250K 250000
0174 #define OCCAN_SPEED_125K 125000
0175 #define OCCAN_SPEED_75K  75000
0176 #define OCCAN_SPEED_50K  50000
0177 #define OCCAN_SPEED_25K  25000
0178 #define OCCAN_SPEED_10K  10000
0179 
0180 #ifdef __cplusplus
0181 }
0182 #endif
0183 
0184 #endif