[97] | 1 | /*
|
---|
| 2 | ** Copyright 2012 by Kvaser AB, Mölndal, Sweden
|
---|
| 3 | ** http://www.kvaser.com
|
---|
| 4 | **
|
---|
| 5 | ** This software is dual licensed under the following two licenses:
|
---|
| 6 | ** BSD-new and GPLv2. You may use either one. See the included
|
---|
| 7 | ** COPYING file for details.
|
---|
| 8 | **
|
---|
| 9 | ** License: BSD-new
|
---|
| 10 | ** ===============================================================================
|
---|
| 11 | ** Redistribution and use in source and binary forms, with or without
|
---|
| 12 | ** modification, are permitted provided that the following conditions are met:
|
---|
| 13 | ** * Redistributions of source code must retain the above copyright
|
---|
| 14 | ** notice, this list of conditions and the following disclaimer.
|
---|
| 15 | ** * Redistributions in binary form must reproduce the above copyright
|
---|
| 16 | ** notice, this list of conditions and the following disclaimer in the
|
---|
| 17 | ** documentation and/or other materials provided with the distribution.
|
---|
| 18 | ** * Neither the name of the <organization> nor the
|
---|
| 19 | ** names of its contributors may be used to endorse or promote products
|
---|
| 20 | ** derived from this software without specific prior written permission.
|
---|
| 21 | **
|
---|
| 22 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
---|
| 23 | ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
---|
| 24 | ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
| 25 | ** DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
---|
| 26 | ** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
---|
| 27 | ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
---|
| 28 | ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
---|
| 29 | ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 30 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
---|
| 31 | ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 32 | **
|
---|
| 33 | **
|
---|
| 34 | ** License: GPLv2
|
---|
| 35 | ** ===============================================================================
|
---|
| 36 | ** This program is free software; you can redistribute it and/or
|
---|
| 37 | ** modify it under the terms of the GNU General Public License
|
---|
| 38 | ** as published by the Free Software Foundation; either version 2
|
---|
| 39 | ** of the License, or (at your option) any later version.
|
---|
| 40 | **
|
---|
| 41 | ** This program is distributed in the hope that it will be useful,
|
---|
| 42 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 43 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 44 | ** GNU General Public License for more details.
|
---|
| 45 | **
|
---|
| 46 | ** You should have received a copy of the GNU General Public License
|
---|
| 47 | ** along with this program; if not, write to the Free Software
|
---|
| 48 | ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
---|
| 49 | **
|
---|
| 50 | ** ---------------------------------------------------------------------------
|
---|
| 51 | **/
|
---|
| 52 |
|
---|
| 53 | #ifndef _SJA1000_H_
|
---|
| 54 | #define _SJA1000_H_
|
---|
| 55 |
|
---|
| 56 | /* Mode Register */
|
---|
| 57 | #define PCAN_MOD 0
|
---|
| 58 | #define PCAN_SM 0x10
|
---|
| 59 | #define PCAN_AFM 0x08
|
---|
| 60 | #define PCAN_STM 0x04
|
---|
| 61 | #define PCAN_LOM 0x02
|
---|
| 62 | #define PCAN_RM 0x01
|
---|
| 63 |
|
---|
| 64 | /* Command Register */
|
---|
| 65 | #define PCAN_CMR 1
|
---|
| 66 | #define PCAN_SRR 0x10
|
---|
| 67 | #define PCAN_CDO 0x08
|
---|
| 68 | #define PCAN_RRB 0x04
|
---|
| 69 | #define PCAN_AT 0x02
|
---|
| 70 | #define PCAN_TR 0x01
|
---|
| 71 |
|
---|
| 72 | #define PCAN_CMD_SINGLESHOT (PCAN_AT|PCAN_TR)
|
---|
| 73 | #define PCAN_CMD_SINGLESHOT_SELF (PCAN_SRR|PCAN_AT)
|
---|
| 74 |
|
---|
| 75 | /* Status Register */
|
---|
| 76 | #define PCAN_SR 2
|
---|
| 77 | #define PCAN_BS 0x80
|
---|
| 78 | #define PCAN_ES 0x40
|
---|
| 79 | #define PCAN_TS 0x20
|
---|
| 80 | #define PCAN_RS 0x10
|
---|
| 81 | #define PCAN_TCS 0x08
|
---|
| 82 | #define PCAN_TBS 0x04
|
---|
| 83 | #define PCAN_DOS 0x02
|
---|
| 84 | #define PCAN_RBS 0x01
|
---|
| 85 |
|
---|
| 86 | /* Interrupt Register */
|
---|
| 87 | #define PCAN_IR 3
|
---|
| 88 | #define PCAN_BEI 0x80
|
---|
| 89 | #define PCAN_ALI 0x40
|
---|
| 90 | #define PCAN_EPI 0x20
|
---|
| 91 | #define PCAN_WUI 0x10
|
---|
| 92 | #define PCAN_DOI 0x08
|
---|
| 93 | #define PCAN_EI 0x04
|
---|
| 94 | #define PCAN_TI 0x02
|
---|
| 95 | #define PCAN_RI 0x01
|
---|
| 96 |
|
---|
| 97 | /* Interrupt Enable Register */
|
---|
| 98 | #define PCAN_IER 4
|
---|
| 99 | #define PCAN_BEIE 0x80
|
---|
| 100 | #define PCAN_ALIE 0x40
|
---|
| 101 | #define PCAN_EPIE 0x20
|
---|
| 102 | #define PCAN_WUIE 0x10
|
---|
| 103 | #define PCAN_DOIE 0x08
|
---|
| 104 | #define PCAN_EIE 0x04
|
---|
| 105 | #define PCAN_TIE 0x02
|
---|
| 106 | #define PCAN_RIE 0x01
|
---|
| 107 |
|
---|
| 108 |
|
---|
| 109 | /* Bus Timing Register 0 */
|
---|
| 110 | #define PCAN_BTR0 6
|
---|
| 111 |
|
---|
| 112 | /* Bus Timing Register 1 */
|
---|
| 113 | #define PCAN_BTR1 7
|
---|
| 114 |
|
---|
| 115 | /* Output Control Register */
|
---|
| 116 | #define PCAN_OCR 8
|
---|
| 117 | #define PCAN_OCTP1 0x80
|
---|
| 118 | #define PCAN_OCTN1 0x40
|
---|
| 119 | #define PCAN_OCPOL1 0x20
|
---|
| 120 | #define PCAN_OCTP0 0x10
|
---|
| 121 | #define PCAN_OCTN0 0x08
|
---|
| 122 | #define PCAN_OCPOL0 0x04
|
---|
| 123 | #define PCAN_OCM1 0x02
|
---|
| 124 | #define PCAN_OCM0 0x01
|
---|
| 125 |
|
---|
| 126 | #define PCAN_ALC 11
|
---|
| 127 |
|
---|
| 128 | #define PCAN_ECC 12
|
---|
| 129 | #define PCAN_ECC_ERROR_MASK 0xC0
|
---|
| 130 | #define PCAN_ECC_BIT_ERROR 0x00
|
---|
| 131 | #define PCAN_ECC_FORM_ERROR 0x40
|
---|
| 132 | #define PCAN_ECC_STUFF_ERROR 0x80
|
---|
| 133 | #define PCAN_ECC_OTHER_ERROR 0xc0
|
---|
| 134 | #define PCAN_ECC_DIR_MASK 0x20
|
---|
| 135 | #define PCAN_ECC_DIR_TX 0x00
|
---|
| 136 | #define PCAN_ECC_DIR_RX 0x20
|
---|
| 137 | #define PCAN_ECC_SEGMENT_MASK 0x1F
|
---|
| 138 |
|
---|
| 139 | #define PCAN_EWLR 13
|
---|
| 140 | #define PCAN_RXERR 14
|
---|
| 141 | #define PCAN_TXERR 15
|
---|
| 142 |
|
---|
| 143 | #define PCAN_ACR0 16
|
---|
| 144 | #define PCAN_ACR1 17
|
---|
| 145 | #define PCAN_ACR2 18
|
---|
| 146 | #define PCAN_ACR3 19
|
---|
| 147 | #define PCAN_AMR0 20
|
---|
| 148 | #define PCAN_AMR1 21
|
---|
| 149 | #define PCAN_AMR2 22
|
---|
| 150 | #define PCAN_AMR3 23
|
---|
| 151 |
|
---|
| 152 | #define PCAN_RMC 29
|
---|
| 153 | #define PCAN_RBSA 30
|
---|
| 154 | #define PCAN_CDR 31
|
---|
| 155 | #define PCAN_PELICAN 0x80
|
---|
| 156 | #define PCAN_CBP 0x40
|
---|
| 157 | #define PCAN_RXINTEN 0x20
|
---|
| 158 | #define PCAN_CLOCKOFF 0x08
|
---|
| 159 |
|
---|
| 160 | #define PCAN_FF_EXTENDED 0x80
|
---|
| 161 | #define PCAN_FF_REMOTE 0x40
|
---|
| 162 |
|
---|
| 163 | #define PCAN_MSGBUF 16
|
---|
| 164 | #define PCAN_SID0 17
|
---|
| 165 | #define PCAN_SID1 18
|
---|
| 166 | #define PCAN_XID0 17
|
---|
| 167 | #define PCAN_XID1 18
|
---|
| 168 | #define PCAN_XID2 19
|
---|
| 169 | #define PCAN_XID3 20
|
---|
| 170 | #define PCAN_SDATA 19
|
---|
| 171 | #define PCAN_XDATA 21
|
---|
| 172 |
|
---|
| 173 | #define PCAN_RXFIFO 32
|
---|
| 174 | #define PCAN_RXFIFO_SIZE 64
|
---|
| 175 |
|
---|
| 176 | typedef struct {
|
---|
| 177 | unsigned char mode;
|
---|
| 178 | unsigned char command;
|
---|
| 179 | unsigned char status;
|
---|
| 180 | unsigned char intr;
|
---|
| 181 | unsigned char intrEnable;
|
---|
| 182 | unsigned char _reserved0;
|
---|
| 183 | unsigned char btr0;
|
---|
| 184 | unsigned char btr1;
|
---|
| 185 | unsigned char outputCtrl;
|
---|
| 186 | unsigned char test;
|
---|
| 187 | unsigned char _reserved1;
|
---|
| 188 | unsigned char arbLost;
|
---|
| 189 | unsigned char errorCode;
|
---|
| 190 | unsigned char errorWarningLimit;
|
---|
| 191 | unsigned char rxError;
|
---|
| 192 | unsigned char txError;
|
---|
| 193 | unsigned char frameFormat;
|
---|
| 194 | union {
|
---|
| 195 | struct {
|
---|
| 196 | unsigned char id0;
|
---|
| 197 | unsigned char id1;
|
---|
| 198 | unsigned char data[8];
|
---|
| 199 | } std;
|
---|
| 200 | struct {
|
---|
| 201 | unsigned char id0;
|
---|
| 202 | unsigned char id1;
|
---|
| 203 | unsigned char id2;
|
---|
| 204 | unsigned char id3;
|
---|
| 205 | unsigned char data[8];
|
---|
| 206 | } ext;
|
---|
| 207 | } msg;
|
---|
| 208 | unsigned char _reserved3;
|
---|
| 209 | unsigned char rxBufStart;
|
---|
| 210 | unsigned char clockDivider;
|
---|
| 211 | } sja1000;
|
---|
| 212 |
|
---|
| 213 | #define PCAN_EPOS_START_OF_FRAME 0x03
|
---|
| 214 | #define PCAN_EPOS_ID28_ID21 0x02
|
---|
| 215 | #define PCAN_EPOS_ID20_ID18 0x06
|
---|
| 216 | #define PCAN_EPOS_SRTR 0x04
|
---|
| 217 | #define PCAN_EPOS_IDE 0x05
|
---|
| 218 | #define PCAN_EPOS_ID17_ID13 0x07
|
---|
| 219 | #define PCAN_EPOS_ID12_ID5 0x0F
|
---|
| 220 | #define PCAN_EPOS_ID4_ID0 0x0E
|
---|
| 221 | #define PCAN_EPOS_RTR 0x0C
|
---|
| 222 | #define PCAN_EPOS_RESVD_1 0x0D
|
---|
| 223 | #define PCAN_EPOS_RESVD_2 0x09
|
---|
| 224 | #define PCAN_EPOS_DLC 0x0B
|
---|
| 225 | #define PCAN_EPOS_DATA 0x0A
|
---|
| 226 | #define PCAN_EPOS_CRC 0x08
|
---|
| 227 | #define PCAN_EPOS_CRC_DELIM 0x18
|
---|
| 228 | #define PCAN_EPOS_ACK 0x19
|
---|
| 229 | #define PCAN_EPOS_ACK_DELIM 0x1B
|
---|
| 230 | #define PCAN_EPOS_EOF 0x1A
|
---|
| 231 | #define PCAN_EPOS_INTERMISSION 0x12
|
---|
| 232 | #define PCAN_EPOS_ACTIVE_ERROR 0x11
|
---|
| 233 | #define PCAN_EPOS_PASSIVE_ERROR 0x16
|
---|
| 234 | #define PCAN_EPOS_TOLERATE_DOM 0x13
|
---|
| 235 | #define PCAN_EPOS_ERROR_DELIM 0x17
|
---|
| 236 | #define PCAN_EPOS_OVERLOAD 0x1C
|
---|
| 237 |
|
---|
| 238 |
|
---|
| 239 | #endif
|
---|