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 | #define CAN_BASE 0
|
---|
54 | #define CAN_MSG1 0x10
|
---|
55 | #define CAN_MSG2 0x20
|
---|
56 | #define CAN_MSG3 0x30
|
---|
57 | #define CAN_MSG4 0x400
|
---|
58 | #define CAN_MSG5 0x410
|
---|
59 | #define CAN_MSG6 0x420
|
---|
60 | #define CAN_MSG7 0x430
|
---|
61 | #define CAN_MSG8 0x800
|
---|
62 | #define CAN_MSG9 0x810
|
---|
63 | #define CAN_MSG10 0x820
|
---|
64 | #define CAN_MSG11 0x830
|
---|
65 | #define CAN_MSG12 0xC00
|
---|
66 | #define CAN_MSG13 0xC10
|
---|
67 | #define CAN_MSG14 0xC20
|
---|
68 | #define CAN_MSG15 0xC30
|
---|
69 |
|
---|
70 | #define CAN_CTRL CAN_BASE + 0x00
|
---|
71 | #define CAN_STAT CAN_BASE + 0x01
|
---|
72 | #define CAN_CPUIR CAN_BASE + 0x02
|
---|
73 | #define CAN_STDGBLMASK0 CAN_BASE + 0x06
|
---|
74 | #define CAN_STDGBLMASK1 CAN_BASE + 0x07
|
---|
75 | #define CAN_EXTGBLMASK0 CAN_BASE + 0x08
|
---|
76 | #define CAN_EXTGBLMASK1 CAN_BASE + 0x09
|
---|
77 | #define CAN_EXTGBLMASK2 CAN_BASE + 0x0a
|
---|
78 | #define CAN_EXTGBLMASK3 CAN_BASE + 0x0b
|
---|
79 | #define CAN_MSG15MASK0 CAN_BASE + 0x0c
|
---|
80 | #define CAN_MSG15MASK1 CAN_BASE + 0x0d
|
---|
81 | #define CAN_MSG15MASK2 CAN_BASE + 0x0e
|
---|
82 | #define CAN_MSG15MASK3 CAN_BASE + 0x0f
|
---|
83 | #define CAN_BUSCON CAN_MSG2 + 0x0f
|
---|
84 | #define CAN_BTR0 CAN_MSG3 + 0x0f
|
---|
85 | #define CAN_BTR1 CAN_MSG4 + 0x0f
|
---|
86 | #define CAN_IR CAN_MSG5 + 0x0f
|
---|
87 | #define CAN_P2CONF CAN_MSG10 + 0x0f
|
---|
88 | #define CAN_P2IN CAN_MSG12 + 0x0f
|
---|
89 | #define CAN_P2OUT CAN_MSG13 + 0x0f
|
---|
90 |
|
---|
91 |
|
---|
92 | #define CTRL_CCE 0x40
|
---|
93 | #define CTRL_EIE 0x08
|
---|
94 | #define CTRL_SIE 0x04
|
---|
95 | #define CTRL_IE 0x02
|
---|
96 | #define CTRL_INIT 0x1
|
---|
97 |
|
---|
98 | #define STAT_BOFF 0x80
|
---|
99 | #define STAT_WARN 0x40
|
---|
100 | #define STAT_WAKE 0x20
|
---|
101 | #define STAT_RXOK 0x10
|
---|
102 | #define STAT_TXOK 0x08
|
---|
103 |
|
---|
104 | #define CPUIR_RSTST 0X80
|
---|
105 | #define CPUIR_DSC 0X40
|
---|
106 | #define CPUIR_DMC 0X20
|
---|
107 | #define CPUIR_PWD 0X10
|
---|
108 | #define CPUIR_SLEEP 0X08
|
---|
109 | #define CPUIR_MUX 0X04
|
---|
110 | #define CPUIR_CEN 0X01
|
---|
111 |
|
---|
112 | #define BUSCON_COBY 0X40
|
---|
113 | #define BUSCON_POL 0X20
|
---|
114 | #define BUSCON_DCT1 0X08
|
---|
115 | #define BUSCON_DCR1 0X02
|
---|
116 | #define BUSCON_DCR0 0X01
|
---|
117 |
|
---|
118 |
|
---|
119 |
|
---|
120 | /* --- The message objects: */
|
---|
121 | #define CANmsg(addr, n) ((addr) + (((n)&0x03)<<4) + (((n)&0x0c)<<8))
|
---|
122 | #define CANmsg_CTRL0 0
|
---|
123 | #define CANmsg_CTRL1 1
|
---|
124 | #define CANmsg_ARB 2
|
---|
125 | #define CANmsg_CONF 6
|
---|
126 | #define CANmsg_DATA 7
|
---|
127 |
|
---|
128 | /* Bits in the Message Object Controls: */
|
---|
129 | /* Control 0: */
|
---|
130 | #define MsgVal 3
|
---|
131 | #define TxIE 2
|
---|
132 | #define RxIE 1
|
---|
133 | #define IntPnd 0
|
---|
134 | #define CTRL0_MsgVal (1<<(MsgVal*2+1))
|
---|
135 | #define CTRL0_TxIE (1<<(TxIE*2+1))
|
---|
136 | #define CTRL0_RxIE (1<<(RxIE*2+1))
|
---|
137 | #define CTRL0_IntPnd (1<<(IntPnd*2+1))
|
---|
138 |
|
---|
139 | /* Control 1: */
|
---|
140 | #define RmtPnd 3
|
---|
141 | #define TxRqst 2
|
---|
142 | #define MsgLst 1
|
---|
143 | #define CPUUpd 1
|
---|
144 | #define NewDat 0
|
---|
145 | #define CTRL1_RmtPnd (1<<(RmtPnd*2+1))
|
---|
146 | #define CTRL1_TxRqst (1<<(TxRqst*2+1))
|
---|
147 | #define CTRL1_MsgLst (1<<(MsgLst*2+1))
|
---|
148 | #define CTRL1_CPUUpd (1<<(CPUUpd*2+1))
|
---|
149 | #define CTRL1_NewDat (1<<(NewDat*2+1))
|
---|
150 |
|
---|
151 | #define SET(x) (255 ^ (1 << ((x)<<1)))
|
---|
152 | #define CLR(x) (255 ^ (2 << ((x)<<1)))
|
---|
153 | #define TEST(x) (2 << ((x)<<1))
|
---|
154 |
|
---|
155 | /* Use as in
|
---|
156 | * CANmessage(1)[CANmsg_Control0] = SET(MsgVal) & CLR(TxIE);
|
---|
157 | * or
|
---|
158 | * if (CANmessage(1)[CANmsg_Control0] & TEST(IntPnd)) ...
|
---|
159 | */
|
---|
160 |
|
---|
161 | /* Message Configuration Register: */
|
---|
162 | #define CANmsg_DLC(n) ((n)<<4)
|
---|
163 | #define CANmsg_Extended 4
|
---|
164 | #define CANmsg_Standard 0
|
---|
165 | #define CANmsg_Transmit 8
|
---|
166 | #define CANmsg_Receive 0
|
---|