📄 can.lst
字号:
C166 COMPILER V6.04, CAN 09/02/2008 15:32:01 PAGE 1
C166 COMPILER V6.04, COMPILATION OF MODULE CAN
OBJECT MODULE PLACED IN CAN.OBJ
COMPILER INVOKED BY: C:\Keil\C166\BIN\C166.EXE CAN.C MODV2 BROWSE MODV2 DEFINE(TargetA) DEBUG
stmt lvl source
1 #ifdef TargetA
2 #define ID0 0x100
3 #define ID1 0x101
4 #else
#define ID0 0x101
#define ID1 0x100
#endif
8
9 #include "MAIN.H"
10
11 // Structure for a single TwinCAN object
12 // A total of 31 such object structures exists
13
14 struct stCanObj
15 {
16 ubyte ubData[8]; // Message Data 0..7
17 ulong ulCANAR; // Arbitration Register
18 ulong ulCANAMR; // Acceptance Mask Register
19 uword uwMSGCTR; // Message Control Register
20 uword uwCounter; // Frame Counter
21 uword uwMSGCFG; // Message Configuration Register
22 uword uwINP; // Interrupt Node Pointer
23 uword uwCANFCR; // FIFO / Gateway Control Register
24 uword uwCANPTR; // FIFO Pointer
25 ulong ulReserved; // Reserved
26 };
27
28 #define CAN_HWOBJ ((struct stCanObj volatile far *) 0x200300)
29
30
31 static ubyte aubFIFOWritePtr[16];
32 static ubyte aubFIFOReadPtr[16];
33
34
35 void CAN_vInit(void)
36 {
37 1 ubyte i;
38 1
39 1 /// -----------------------------------------------------------------------
40 1 /// Configuration of CAN Node A:
41 1 /// -----------------------------------------------------------------------
42 1
43 1 /// General Configuration of the Node A:
44 1 /// - set INIT and CCE
45 1
46 1 CAN_ACR = 0x0041; // load global control register
47 1 CAN_AGINP = 0x0000; // load global interrupt node pointer
48 1 // register
49 1
50 1 /// Configuration of the Node A Error Counter:
51 1 /// - the error warning threshold value (warning level) is 96
52 1
53 1 CAN_AECNTH = 0x0060; // load error counter register high
54 1
55 1 /// Configuration of the used CAN Port Pins:
C166 COMPILER V6.04, CAN 09/02/2008 15:32:01 PAGE 2
56 1 /// - P4.5 is used for CAN Interface Input (RXDCA)
57 1 /// - P4.6 is used for CAN Interface Output (TXDCA)
58 1
59 1 ALTSEL0P4 |= 0x0040; // select alternate output function
60 1 DP4 = (DP4 & ~(uword)0x0040) | 0x0040; //set direction register
61 1
62 1 /// Configuration of the Node A Baud Rate:
63 1 /// - required baud rate = 100,000 kbaud
64 1 /// - real baud rate = 100,000 kbaud
65 1 /// - sample point = 60,00 %
66 1 /// - there are 5 time quanta before sample point
67 1 /// - there are 4 time quanta after sample point
68 1 /// - the (re)synchronization jump width is 2 time quanta
69 1
70 1 CAN_ABTRL = 0x3453; // load bit timing register low
71 1
72 1 CAN_ABTRH = 0x0000; // load bit timing register high
73 1
74 1 CAN_AFCRL = 0x0000; // load frame counter timing register low
75 1
76 1 CAN_AFCRH = 0x0000; // load frame counter timing register high
77 1
78 1 /// -----------------------------------------------------------------------
79 1 /// Configuration of CAN Node B:
80 1 /// -----------------------------------------------------------------------
81 1
82 1 /// General Configuration of the Node B:
83 1 /// - set INIT and CCE
84 1
85 1 CAN_BCR = 0x0041; // load global control register
86 1
87 1 /// -----------------------------------------------------------------------
88 1 /// Configuration of the CAN Message Objects 0 - 31:
89 1 /// -----------------------------------------------------------------------
90 1
91 1 /// -----------------------------------------------------------------------
92 1 /// Configuration of Message Object 0:
93 1 /// -----------------------------------------------------------------------
94 1 /// - message object 0 is valid
95 1
96 1 CAN_MSGCTRL0 = 0x5595; // load message control register low
97 1
98 1 CAN_MSGCTRH0 = 0x0000; // load message control register high
99 1
100 1 /// - message object is used as transmit object
101 1 /// - extended 29-bit identifier
102 1 /// - 1 valid data bytes
103 1 /// - this message object works with CAN node A
104 1 /// - remote monitoring is disabled
105 1
106 1 CAN_MSGCFGL0 = 0x001C; // load message configuration register low
107 1
108 1
109 1 CAN_MSGCFGH0 = 0x0000; // load message configuration register high
110 1
111 1 /// - acceptance mask 29-bit: 0xFFFF
112 1 /// - identifier 29-bit: 0x0100
113 1
114 1 CAN_MSGAMRL0 = 0xFFFF; // load acceptance mask register low
115 1
116 1 CAN_MSGAMRH0 = 0x1FFF; // load acceptance mask register high
117 1 CAN_MSGARL0 = ID1; // load arbitration register low
C166 COMPILER V6.04, CAN 09/02/2008 15:32:01 PAGE 3
118 1
119 1 CAN_MSGARH0 = 0x0000; // load arbitration register high
120 1
121 1 CAN_MSGDRL00 = 0x0000; // load data register 0 low
122 1 CAN_MSGDRH00 = 0x0000; // load data register 0 high
123 1 CAN_MSGDRL04 = 0x0000; // load data register 4 low
124 1
125 1 CAN_MSGDRH04 = 0x0000; // load data register 4 high
126 1
127 1 /// - functionality of standard message object
128 1
129 1 CAN_MSGFGCRL0 = 0x0000; // load FIFO/gateway control register low
130 1
131 1
132 1 CAN_MSGFGCRH0 = 0x0000; // load FIFO/gateway control register high
133 1
134 1 /// -----------------------------------------------------------------------
135 1 /// Configuration of Message Object 1:
136 1 /// -----------------------------------------------------------------------
137 1 /// - message object 1 is valid
138 1
139 1 CAN_MSGCTRL1 = 0x5595; // load message control register low
140 1
141 1 CAN_MSGCTRH1 = 0x0000; // load message control register high
142 1
143 1 /// - message object is used as receive object
144 1 /// - extended 29-bit identifier
145 1 /// - 1 valid data bytes
146 1 /// - this message object works with CAN node A
147 1 /// - remote monitoring is disabled
148 1
149 1 CAN_MSGCFGL1 = 0x0014; // load message configuration register low
150 1
151 1
152 1 CAN_MSGCFGH1 = 0x0000; // load message configuration register high
153 1
154 1 /// - acceptance mask 29-bit: 0xFFFF
155 1 /// - identifier 29-bit: 0x0101
156 1
157 1 CAN_MSGAMRL1 = 0xFFFF; // load acceptance mask register low
158 1
159 1 CAN_MSGAMRH1 = 0x1FFF; // load acceptance mask register high
160 1 CAN_MSGARL1 = ID0; // load arbitration register low
161 1
162 1 CAN_MSGARH1 = 0x0000; // load arbitration register high
163 1
164 1 CAN_MSGDRL10 = 0x0000; // load data register 0 low
165 1 CAN_MSGDRH10 = 0x0000; // load data register 0 high
166 1 CAN_MSGDRL14 = 0x0000; // load data register 4 low
167 1
168 1 CAN_MSGDRH14 = 0x0000; // load data register 4 high
169 1
170 1 /// - functionality of standard message object
171 1
172 1 CAN_MSGFGCRL1 = 0x0000; // load FIFO/gateway control register low
173 1
174 1
175 1 CAN_MSGFGCRH1 = 0x0001; // load FIFO/gateway control register high
176 1
177 1
178 1 /// -----------------------------------------------------------------------
179 1 /// Configuration of Service Request Nodes 0 - 7:
C166 COMPILER V6.04, CAN 09/02/2008 15:32:01 PAGE 4
180 1 /// -----------------------------------------------------------------------
181 1
182 1 /// -----------------------------------------------------------------------
183 1 /// Initialization of the FIFO Pointer:
184 1 /// -----------------------------------------------------------------------
185 1
186 1 for (i = 0; i < 16; i++)
187 1 {
188 2 aubFIFOWritePtr[i] = i * 2;
*** WARNING C192 IN LINE 188 OF CAN.C: '=': value truncated
189 2 aubFIFOReadPtr[i] = i * 2;
*** WARNING C192 IN LINE 189 OF CAN.C: '=': value truncated
190 2 }
191 1
192 1
193 1 CAN_PISEL = 0x0000; // load port input select register
194 1
195 1 // -----------------------------------------------------------------------
196 1 // Start the CAN Nodes:
197 1 // -----------------------------------------------------------------------
198 1
199 1 CAN_ACR &= ~(uword)0x0041; // reset INIT and CCE
200 1
201 1 }
202
203 void CAN_vGetMsgObj(ubyte ubObjNr, TCAN_SWObj *pstObj)
204 {
205 1 ubyte i;
206 1
207 1 for(i = 0; i < (CAN_HWOBJ[ubObjNr].uwMSGCFG & 0x00f0) >> 4; i++)
208 1 {
209 2 pstObj->ubData[i] = CAN_HWOBJ[ubObjNr].ubData[i];
210 2 }
211 1
212 1 if(CAN_HWOBJ[ubObjNr].uwMSGCFG & 0x04) // extended identifier
213 1 {
214 2 pstObj->ulID = CAN_HWOBJ[ubObjNr].ulCANAR;
215 2 pstObj->ulMask = CAN_HWOBJ[ubObjNr].ulCANAMR;
216 2 }
217 1 else // standard identifier
218 1 {
219 2 pstObj->ulID = CAN_HWOBJ[ubObjNr].ulCANAR >> 18;
220 2 pstObj->ulMask = CAN_HWOBJ[ubObjNr].ulCANAMR >> 18;
221 2 }
222 1
223 1 pstObj->uwCounter = CAN_HWOBJ[ubObjNr].uwCounter;
224 1 pstObj->uwMsgCfg = CAN_HWOBJ[ubObjNr].uwMSGCFG;
225 1
226 1 }
227
228 ubyte CAN_ubRequestMsgObj(ubyte ubObjNr)
229 {
230 1 ubyte ubReturn;
231 1
232 1 ubReturn = 0;
233 1 if((CAN_HWOBJ[ubObjNr].uwMSGCTR & 0x3000) == 0x1000) // if reset TXRQ
234 1 {
235 2 CAN_HWOBJ[ubObjNr].uwMSGCTR = 0xfbff; // set CPUUPD
236 2 ubReturn = 1;
237 2 }
238 1 return(ubReturn);
239 1
C166 COMPILER V6.04, CAN 09/02/2008 15:32:01 PAGE 5
240 1 }
241
242 ubyte CAN_ubNewData(ubyte ubObjNr)
243 {
244 1 ubyte ubReturn;
245 1
246 1 ubReturn = 0;
247 1 if((CAN_HWOBJ[ubObjNr].uwMSGCTR & 0x0300) == 0x0200) // if NEWDAT
248 1 {
249 2 ubReturn = 1;
250 2 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -