PIC24 Support Libraries
pic24_ecan.h
Go to the documentation of this file.
1 /*
2  * "Copyright (c) 2008 Robert B. Reese, Bryan A. Jones, J. W. Bruce ("AUTHORS")"
3  * All rights reserved.
4  * (R. Reese, reese_AT_ece.msstate.edu, Mississippi State University)
5  * (B. A. Jones, bjones_AT_ece.msstate.edu, Mississippi State University)
6  * (J. W. Bruce, jwbruce_AT_ece.msstate.edu, Mississippi State University)
7  *
8  * Permission to use, copy, modify, and distribute this software and its
9  * documentation for any purpose, without fee, and without written agreement is
10  * hereby granted, provided that the above copyright notice, the following
11  * two paragraphs and the authors appear in all copies of this software.
12  *
13  * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR
14  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
15  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS"
16  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17  *
18  * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES,
19  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20  * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21  * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO
22  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
23  *
24  * Please maintain this header in its entirety when copying/modifying
25  * these files.
26  *
27  *
28  */
29 
30 #pragma once
31 
32 #include <stdint.h>
33 #include "pic24_unions.h"
34 #include "pic24_chip.h"
35 #include "pic24_clockfreq.h"
36 
37 // Only include if this ECAN Module exists.
38 #if (NUM_ECAN_MODS >= 1)
39 
40 // Documentation for this file. If the \file tag isn't present,
41 // this file won't be documented.
42 // Note: place this comment below the #if NUM_ECAN_MODS so Doxygen
43 // will only see it once.
44 /** \file
45 * ECAN Header File
46 */
47 
48 #ifndef ECAN_1TIME_HEADER_DEFS
49 
50 #define ECAN_MODE_NORMAL 0
51 #define ECAN_MODE_DISABLED 1
52 #define ECAN_MODE_LOOPBACK 2
53 #define ECAN_MODE_LISTEN_ONLY 3
54 #define ECAN_MODE_CONFIGURE 4
55 #define ECAN_LISTEN_ALL_MESSAGES 7
56 
57 // CANCKS in CiCTRL1 ECAN Register
58 // CANCKS: ECANx Module Clock (FCAN) Source Select Bit
59 //
60 // The CANCKS bit was defined in the CiCTRL1 register when the initial PIC24
61 // library and text was written (2008). The following definitions were used
62 // for the CANCKS bit. In May 2009, datasheet revision history says
63 // Changed bit 11 in the ECAN Control Register 1 (CiCTRL1) to Reserved
64 // (see Register 19-1).
65 // Thus, these definitions are no longer needed in the non-E families of the
66 // PIC24/dsPIC [JWB May 2014]
67 //#define ECAN_FCAN_IS_FCY 1
68 //#define ECAN_FCAN_IS_OSC 0
69 
70 // The CANCKS bit was returned to the "E" family in the same register
71 // (CiCTRL1) and bit location (bit 11). See the revision history entry in
72 // the ECAN chapter of the E-family FRM for March 2011. However, the
73 // meaning of the CANCKS bit is now completely different than original
74 // CANCKS bit used in 2008-2009 [JWB May 2014]
75 //
76 // For certain silicon revisions, the CANCKS bit does not behave in the way
77 // that the datasheet specifies. Based on silicon issue 11 of document
78 // DS80000526E, it functions reverse of its intended operation for a certain
79 // subset of this family. [Ryan Taylor; November 2015]
80 
81 #if defined(__dsPIC33EP512GP806__)
82 
83 #define ECAN_FCAN_IS_2FP 0 // FCAN is equal to 2 * FP
84 #define ECAN_FCAN_IS_FP 1 // FCAN is equal to FP
85 
86 #elif defined(__dsPIC33E__)
87 
88 # define ECAN_FCAN_IS_2FP 1 // FCAN is equal to 2 * FP
89 # define ECAN_FCAN_IS_FP 0 // FCAN is equal to FP
90 
91 #endif
92 
93 //CiCFG2 register (Baud rate config 2 register)
94 #define ECAN_NO_WAKEUP 0x4000
95 #define ECAN_SEG2PH_8TQ (0x0007 << 8)
96 #define ECAN_SEG2PH_7TQ (0x0006 << 8)
97 #define ECAN_SEG2PH_6TQ (0x0005 << 8)
98 #define ECAN_SEG2PH_5TQ (0x0004 << 8)
99 #define ECAN_SEG2PH_4TQ (0x0003 << 8)
100 #define ECAN_SEG2PH_3TQ (0x0002 << 8)
101 #define ECAN_SEG2PH_2TQ (0x0001 << 8)
102 #define ECAN_SEG2PH_1TQ (0x0000 << 8)
103 
104 #define ECAN_SEG2_PROGRAMMABLE 0x0080
105 #define ECAN_SEG2_FIXED 0x0000
106 
107 #define ECAN_SAMPLE_3TIMES 0x0040
108 #define ECAN_SAMPLE_1TIMES 0x0000
109 
110 #define ECAN_SEG1PH_8TQ (0x0007 << 3)
111 #define ECAN_SEG1PH_7TQ (0x0006 << 3)
112 #define ECAN_SEG1PH_6TQ (0x0005 << 3)
113 #define ECAN_SEG1PH_5TQ (0x0004 << 3)
114 #define ECAN_SEG1PH_4TQ (0x0003 << 3)
115 #define ECAN_SEG1PH_3TQ (0x0002 << 3)
116 #define ECAN_SEG1PH_2TQ (0x0001 << 3)
117 #define ECAN_SEG1PH_1TQ (0x0000 << 3)
118 
119 #define ECAN_PRSEG_8TQ 0x0007
120 #define ECAN_PRSEG_7TQ 0x0006
121 #define ECAN_PRSEG_6TQ 0x0005
122 #define ECAN_PRSEG_5TQ 0x0004
123 #define ECAN_PRSEG_4TQ 0x0003
124 #define ECAN_PRSEG_3TQ 0x0002
125 #define ECAN_PRSEG_2TQ 0x0001
126 #define ECAN_PRSEG_1TQ 0x0000
127 
128 //CiCFG1 register (Baud rate config 1 register)
129 #define ECAN_SYNC_JUMP_4 (0x0003 << 6)
130 #define ECAN_SYNC_JUMP_3 (0x0002 << 6)
131 #define ECAN_SYNC_JUMP_2 (0x0001 << 6)
132 #define ECAN_SYNC_JUMP_1 (0x0000 << 6)
133 
134 #define ECAN_PRE_2x64 0x003f
135 #define ECAN_PRE_2x63 0x003e
136 #define ECAN_PRE_2x62 0x003d
137 #define ECAN_PRE_2x61 0x003c
138 #define ECAN_PRE_2x60 0x003b
139 #define ECAN_PRE_2x59 0x003a
140 #define ECAN_PRE_2x58 0x0039
141 #define ECAN_PRE_2x57 0x0038
142 #define ECAN_PRE_2x56 0x0037
143 #define ECAN_PRE_2x55 0x0036
144 #define ECAN_PRE_2x54 0x0035
145 #define ECAN_PRE_2x53 0x0034
146 #define ECAN_PRE_2x52 0x0033
147 #define ECAN_PRE_2x51 0x0032
148 #define ECAN_PRE_2x50 0x0031
149 #define ECAN_PRE_2x49 0x0030
150 #define ECAN_PRE_2x48 0x002f
151 #define ECAN_PRE_2x47 0x002e
152 #define ECAN_PRE_2x46 0x002d
153 #define ECAN_PRE_2x45 0x002c
154 #define ECAN_PRE_2x44 0x002b
155 #define ECAN_PRE_2x43 0x002a
156 #define ECAN_PRE_2x42 0x0029
157 #define ECAN_PRE_2x41 0x0028
158 #define ECAN_PRE_2x40 0x0027
159 #define ECAN_PRE_2x39 0x0026
160 #define ECAN_PRE_2x38 0x0025
161 #define ECAN_PRE_2x37 0x0024
162 #define ECAN_PRE_2x36 0x0023
163 #define ECAN_PRE_2x35 0x0022
164 #define ECAN_PRE_2x34 0x0021
165 #define ECAN_PRE_2x33 0x0020
166 #define ECAN_PRE_2x32 0x001f
167 #define ECAN_PRE_2x31 0x001e
168 #define ECAN_PRE_2x30 0x001d
169 #define ECAN_PRE_2x29 0x001c
170 #define ECAN_PRE_2x28 0x001b
171 #define ECAN_PRE_2x27 0x001a
172 #define ECAN_PRE_2x26 0x0019
173 #define ECAN_PRE_2x25 0x0018
174 #define ECAN_PRE_2x24 0x0017
175 #define ECAN_PRE_2x23 0x0016
176 #define ECAN_PRE_2x22 0x0015
177 #define ECAN_PRE_2x21 0x0014
178 #define ECAN_PRE_2x20 0x0013
179 #define ECAN_PRE_2x19 0x0012
180 #define ECAN_PRE_2x18 0x0011
181 #define ECAN_PRE_2x17 0x0010
182 #define ECAN_PRE_2x16 0x000f
183 #define ECAN_PRE_2x15 0x000e
184 #define ECAN_PRE_2x14 0x000d
185 #define ECAN_PRE_2x13 0x000c
186 #define ECAN_PRE_2x12 0x000b
187 #define ECAN_PRE_2x11 0x000a
188 #define ECAN_PRE_2x10 0x0009
189 #define ECAN_PRE_2x9 0x0008
190 #define ECAN_PRE_2x8 0x0007
191 #define ECAN_PRE_2x7 0x0006
192 #define ECAN_PRE_2x6 0x0005
193 #define ECAN_PRE_2x5 0x0004
194 #define ECAN_PRE_2x4 0x0003
195 #define ECAN_PRE_2x3 0x0002
196 #define ECAN_PRE_2x2 0x0001
197 #define ECAN_PRE_2x1 0x0000
198 
199 //CiFCTRL register (FIFO Control register)
200 #define ECAN_DMA_BUF_SIZE_32 (0x0006 << 13)
201 #define ECAN_DMA_BUF_SIZE_24 (0x0005 << 13)
202 #define ECAN_DMA_BUF_SIZE_16 (0x0004 << 13)
203 #define ECAN_DMA_BUF_SIZE_12 (0x0003 << 13)
204 #define ECAN_DMA_BUF_SIZE_8 (0x0002 << 13)
205 #define ECAN_DMA_BUF_SIZE_6 (0x0001 << 13)
206 #define ECAN_DMA_BUF_SIZE_4 (0x0000 << 13)
207 
208 
209 #define ECAN_FIFO_START_AREA_31 31
210 #define ECAN_FIFO_START_AREA_30 30
211 #define ECAN_FIFO_START_AREA_29 29
212 #define ECAN_FIFO_START_AREA_28 28
213 #define ECAN_FIFO_START_AREA_27 27
214 #define ECAN_FIFO_START_AREA_26 26
215 #define ECAN_FIFO_START_AREA_25 25
216 #define ECAN_FIFO_START_AREA_24 24
217 #define ECAN_FIFO_START_AREA_23 23
218 #define ECAN_FIFO_START_AREA_22 22
219 #define ECAN_FIFO_START_AREA_21 21
220 #define ECAN_FIFO_START_AREA_20 20
221 #define ECAN_FIFO_START_AREA_19 19
222 #define ECAN_FIFO_START_AREA_18 18
223 #define ECAN_FIFO_START_AREA_17 17
224 #define ECAN_FIFO_START_AREA_16 16
225 #define ECAN_FIFO_START_AREA_15 15
226 #define ECAN_FIFO_START_AREA_14 14
227 #define ECAN_FIFO_START_AREA_13 13
228 #define ECAN_FIFO_START_AREA_12 12
229 #define ECAN_FIFO_START_AREA_11 11
230 #define ECAN_FIFO_START_AREA_10 10
231 #define ECAN_FIFO_START_AREA_9 9
232 #define ECAN_FIFO_START_AREA_8 8
233 #define ECAN_FIFO_START_AREA_7 7
234 #define ECAN_FIFO_START_AREA_6 6
235 #define ECAN_FIFO_START_AREA_5 5
236 #define ECAN_FIFO_START_AREA_4 4
237 #define ECAN_FIFO_START_AREA_3 3
238 #define ECAN_FIFO_START_AREA_2 2
239 #define ECAN_FIFO_START_AREA_1 1
240 #define ECAN_FIFO_START_AREA_0 0
241 
242 //CiRXFnSID register
243 #define ECAN_MATCH_EID 0x0008
244 #define ECAN_MATCH_SID 0x0000
245 
246 #define ECAN_USE_FIFO 0xF
247 
248 //CiTRmnCON TXRX buffer control
249 #define ECAN_RX_BUFF 0
250 #define ECAN_TX_BUFF 1
251 
252 
253 //Data structure for ECAN Data Frame
254 typedef struct _ECANW0 {
255  unsigned IDE: 1;
256  unsigned SRR:1;
257  unsigned SID:11;
258 } ECANW0;
259 typedef struct _ECANW1 {
260  unsigned EID17_6: 12;
261 } ECANW1;
262 
263 typedef struct _ECANW2 {
264  unsigned DLC:4;
265  unsigned RB0:1;
266  unsigned :3;
267  unsigned RB1:1;
268  unsigned RTR:1;
269  unsigned EID5_0:6;
270 } ECANW2;
271 
272 typedef struct _ECANW7 {
273  unsigned :8;
274  unsigned FILHIT:5;
275  unsigned :3;
276 } ECANW7;
277 
278 
279 
280 typedef struct _ECANMSG {
281  ECANW0 w0;
282  ECANW1 w1;
283  ECANW2 w2;
284  union64 data;
285  ECANW7 w7;
286 } ECANMSG;
287 
288 // dsPIC33EP512GP806 must be handled differently than the rest of the family
289 // due to errata in the DMA subsystem (see document DS80000526E - silicon issue
290 // 15). DPRAM must be used to ensure that the DMA cannot be held in the "OFF"
291 // state by the system arbiter. [Ryan Taylor; November 2015]
292 #if defined(__dsPIC33EP512GP806__)
293 
294 void formatStandardDataFrameECAN (__eds__ ECANMSG* p_ecanmsg, uint16_t u16_id, uint8_t u8_len);
295 void formatExtendedDataFrameECAN (__eds__ ECANMSG* p_ecanmsg, uint32_t u32_id, uint8_t u8_len);
296 uint32_t getIdExtendedDataFrameECAN (__eds__ ECANMSG* p_ecanmsg);
297 
298 #else
299 
300 void formatStandardDataFrameECAN (ECANMSG* p_ecanmsg, uint16_t u16_id, uint8_t u8_len);
301 void formatExtendedDataFrameECAN (ECANMSG* p_ecanmsg, uint32_t u32_id, uint8_t u8_len);
302 uint32_t getIdExtendedDataFrameECAN (ECANMSG* p_ecanmsg);
303 
304 #endif
305 
306 #define ECAN_1TIME_HEADER_DEFS
307 #endif
308 
309 
310 
311 
312 #ifdef _C1IF
313 /** Waits until all characters placed in the UART have been sent. */
314 inline static void CHANGE_MODE_ECAN1(uint16_t u16_mode) {
315  C1CTRL1bits.REQOP = u16_mode;
316  while(C1CTRL1bits.OPMODE != u16_mode);
317 }
318 
319 /** Return the number (0-31) of the next ECAN FIFO read buffer
320  */
321 #define GET_FIFO_READBUFFER_ECAN1() (C1FIFO & 0x1F)
322 
323 void configBaudECAN1(void);
324 void clrRxFullFlagECAN1(uint8_t u8_bufNum);
326 void clrRxFullOvfFlagsECAN1(void);
327 void configTxRxBufferECAN1(uint8_t u8_bufNum, uint8_t u8_type, uint8_t u8_priority);
328 void configRxFilterECAN1(uint8_t u8_filtNum, uint32_t u32_id, uint8_t u8_idType, uint8_t u8_bufnum, uint8_t u8_maskReg);
329 void configRxMaskECAN1(uint8_t u8_maskNum, uint32_t u32_idMask, uint8_t u8_idType, uint8_t u8_matchType);
330 void startTxECAN1(uint8_t u8_bufNum);
332 
333 #endif
334 
335 
336 #endif // #if (NUM_ECAN_MODS >= 1)
337 
338 
339 
340 
341 
342 
343 
344 /*
345  * "Copyright (c) 2008 Robert B. Reese, Bryan A. Jones, J. W. Bruce ("AUTHORS")"
346  * All rights reserved.
347  * (R. Reese, reese_AT_ece.msstate.edu, Mississippi State University)
348  * (B. A. Jones, bjones_AT_ece.msstate.edu, Mississippi State University)
349  * (J. W. Bruce, jwbruce_AT_ece.msstate.edu, Mississippi State University)
350  *
351  * Permission to use, copy, modify, and distribute this software and its
352  * documentation for any purpose, without fee, and without written agreement is
353  * hereby granted, provided that the above copyright notice, the following
354  * two paragraphs and the authors appear in all copies of this software.
355  *
356  * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR
357  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
358  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS"
359  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
360  *
361  * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES,
362  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
363  * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
364  * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO
365  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
366  *
367  * Please maintain this header in its entirety when copying/modifying
368  * these files.
369  *
370  *
371  */
372 
373 #pragma once
374 
375 #include <stdint.h>
376 #include "pic24_unions.h"
377 #include "pic24_chip.h"
378 #include "pic24_clockfreq.h"
379 
380 // Only include if this ECAN Module exists.
381 #if (NUM_ECAN_MODS >= 2)
382 
383 // Documentation for this file. If the \file tag isn't present,
384 // this file won't be documented.
385 // Note: place this comment below the #if NUM_ECAN_MODS so Doxygen
386 // will only see it once.
387 /** \file
388 * ECAN Header File
389 */
390 
391 #ifndef ECAN_1TIME_HEADER_DEFS
392 
393 #define ECAN_MODE_NORMAL 0
394 #define ECAN_MODE_DISABLED 1
395 #define ECAN_MODE_LOOPBACK 2
396 #define ECAN_MODE_LISTEN_ONLY 3
397 #define ECAN_MODE_CONFIGURE 4
398 #define ECAN_LISTEN_ALL_MESSAGES 7
399 
400 // CANCKS in CiCTRL1 ECAN Register
401 // CANCKS: ECANx Module Clock (FCAN) Source Select Bit
402 //
403 // The CANCKS bit was defined in the CiCTRL1 register when the initial PIC24
404 // library and text was written (2008). The following definitions were used
405 // for the CANCKS bit. In May 2009, datasheet revision history says
406 // Changed bit 11 in the ECAN Control Register 1 (CiCTRL1) to Reserved
407 // (see Register 19-1).
408 // Thus, these definitions are no longer needed in the non-E families of the
409 // PIC24/dsPIC [JWB May 2014]
410 //#define ECAN_FCAN_IS_FCY 1
411 //#define ECAN_FCAN_IS_OSC 0
412 
413 // The CANCKS bit was returned to the "E" family in the same register
414 // (CiCTRL1) and bit location (bit 11). See the revision history entry in
415 // the ECAN chapter of the E-family FRM for March 2011. However, the
416 // meaning of the CANCKS bit is now completely different than original
417 // CANCKS bit used in 2008-2009 [JWB May 2014]
418 //
419 // For certain silicon revisions, the CANCKS bit does not behave in the way
420 // that the datasheet specifies. Based on silicon issue 11 of document
421 // DS80000526E, it functions reverse of its intended operation for a certain
422 // subset of this family. [Ryan Taylor; November 2015]
423 
424 #if defined(__dsPIC33EP512GP806__)
425 
426 #define ECAN_FCAN_IS_2FP 0 // FCAN is equal to 2 * FP
427 #define ECAN_FCAN_IS_FP 1 // FCAN is equal to FP
428 
429 #elif defined(__dsPIC33E__)
430 
431 # define ECAN_FCAN_IS_2FP 1 // FCAN is equal to 2 * FP
432 # define ECAN_FCAN_IS_FP 0 // FCAN is equal to FP
433 
434 #endif
435 
436 //CiCFG2 register (Baud rate config 2 register)
437 #define ECAN_NO_WAKEUP 0x4000
438 #define ECAN_SEG2PH_8TQ (0x0007 << 8)
439 #define ECAN_SEG2PH_7TQ (0x0006 << 8)
440 #define ECAN_SEG2PH_6TQ (0x0005 << 8)
441 #define ECAN_SEG2PH_5TQ (0x0004 << 8)
442 #define ECAN_SEG2PH_4TQ (0x0003 << 8)
443 #define ECAN_SEG2PH_3TQ (0x0002 << 8)
444 #define ECAN_SEG2PH_2TQ (0x0001 << 8)
445 #define ECAN_SEG2PH_1TQ (0x0000 << 8)
446 
447 #define ECAN_SEG2_PROGRAMMABLE 0x0080
448 #define ECAN_SEG2_FIXED 0x0000
449 
450 #define ECAN_SAMPLE_3TIMES 0x0040
451 #define ECAN_SAMPLE_1TIMES 0x0000
452 
453 #define ECAN_SEG1PH_8TQ (0x0007 << 3)
454 #define ECAN_SEG1PH_7TQ (0x0006 << 3)
455 #define ECAN_SEG1PH_6TQ (0x0005 << 3)
456 #define ECAN_SEG1PH_5TQ (0x0004 << 3)
457 #define ECAN_SEG1PH_4TQ (0x0003 << 3)
458 #define ECAN_SEG1PH_3TQ (0x0002 << 3)
459 #define ECAN_SEG1PH_2TQ (0x0001 << 3)
460 #define ECAN_SEG1PH_1TQ (0x0000 << 3)
461 
462 #define ECAN_PRSEG_8TQ 0x0007
463 #define ECAN_PRSEG_7TQ 0x0006
464 #define ECAN_PRSEG_6TQ 0x0005
465 #define ECAN_PRSEG_5TQ 0x0004
466 #define ECAN_PRSEG_4TQ 0x0003
467 #define ECAN_PRSEG_3TQ 0x0002
468 #define ECAN_PRSEG_2TQ 0x0001
469 #define ECAN_PRSEG_1TQ 0x0000
470 
471 //CiCFG1 register (Baud rate config 1 register)
472 #define ECAN_SYNC_JUMP_4 (0x0003 << 6)
473 #define ECAN_SYNC_JUMP_3 (0x0002 << 6)
474 #define ECAN_SYNC_JUMP_2 (0x0001 << 6)
475 #define ECAN_SYNC_JUMP_1 (0x0000 << 6)
476 
477 #define ECAN_PRE_2x64 0x003f
478 #define ECAN_PRE_2x63 0x003e
479 #define ECAN_PRE_2x62 0x003d
480 #define ECAN_PRE_2x61 0x003c
481 #define ECAN_PRE_2x60 0x003b
482 #define ECAN_PRE_2x59 0x003a
483 #define ECAN_PRE_2x58 0x0039
484 #define ECAN_PRE_2x57 0x0038
485 #define ECAN_PRE_2x56 0x0037
486 #define ECAN_PRE_2x55 0x0036
487 #define ECAN_PRE_2x54 0x0035
488 #define ECAN_PRE_2x53 0x0034
489 #define ECAN_PRE_2x52 0x0033
490 #define ECAN_PRE_2x51 0x0032
491 #define ECAN_PRE_2x50 0x0031
492 #define ECAN_PRE_2x49 0x0030
493 #define ECAN_PRE_2x48 0x002f
494 #define ECAN_PRE_2x47 0x002e
495 #define ECAN_PRE_2x46 0x002d
496 #define ECAN_PRE_2x45 0x002c
497 #define ECAN_PRE_2x44 0x002b
498 #define ECAN_PRE_2x43 0x002a
499 #define ECAN_PRE_2x42 0x0029
500 #define ECAN_PRE_2x41 0x0028
501 #define ECAN_PRE_2x40 0x0027
502 #define ECAN_PRE_2x39 0x0026
503 #define ECAN_PRE_2x38 0x0025
504 #define ECAN_PRE_2x37 0x0024
505 #define ECAN_PRE_2x36 0x0023
506 #define ECAN_PRE_2x35 0x0022
507 #define ECAN_PRE_2x34 0x0021
508 #define ECAN_PRE_2x33 0x0020
509 #define ECAN_PRE_2x32 0x001f
510 #define ECAN_PRE_2x31 0x001e
511 #define ECAN_PRE_2x30 0x001d
512 #define ECAN_PRE_2x29 0x001c
513 #define ECAN_PRE_2x28 0x001b
514 #define ECAN_PRE_2x27 0x001a
515 #define ECAN_PRE_2x26 0x0019
516 #define ECAN_PRE_2x25 0x0018
517 #define ECAN_PRE_2x24 0x0017
518 #define ECAN_PRE_2x23 0x0016
519 #define ECAN_PRE_2x22 0x0015
520 #define ECAN_PRE_2x21 0x0014
521 #define ECAN_PRE_2x20 0x0013
522 #define ECAN_PRE_2x19 0x0012
523 #define ECAN_PRE_2x18 0x0011
524 #define ECAN_PRE_2x17 0x0010
525 #define ECAN_PRE_2x16 0x000f
526 #define ECAN_PRE_2x15 0x000e
527 #define ECAN_PRE_2x14 0x000d
528 #define ECAN_PRE_2x13 0x000c
529 #define ECAN_PRE_2x12 0x000b
530 #define ECAN_PRE_2x11 0x000a
531 #define ECAN_PRE_2x10 0x0009
532 #define ECAN_PRE_2x9 0x0008
533 #define ECAN_PRE_2x8 0x0007
534 #define ECAN_PRE_2x7 0x0006
535 #define ECAN_PRE_2x6 0x0005
536 #define ECAN_PRE_2x5 0x0004
537 #define ECAN_PRE_2x4 0x0003
538 #define ECAN_PRE_2x3 0x0002
539 #define ECAN_PRE_2x2 0x0001
540 #define ECAN_PRE_2x1 0x0000
541 
542 //CiFCTRL register (FIFO Control register)
543 #define ECAN_DMA_BUF_SIZE_32 (0x0006 << 13)
544 #define ECAN_DMA_BUF_SIZE_24 (0x0005 << 13)
545 #define ECAN_DMA_BUF_SIZE_16 (0x0004 << 13)
546 #define ECAN_DMA_BUF_SIZE_12 (0x0003 << 13)
547 #define ECAN_DMA_BUF_SIZE_8 (0x0002 << 13)
548 #define ECAN_DMA_BUF_SIZE_6 (0x0001 << 13)
549 #define ECAN_DMA_BUF_SIZE_4 (0x0000 << 13)
550 
551 
552 #define ECAN_FIFO_START_AREA_31 31
553 #define ECAN_FIFO_START_AREA_30 30
554 #define ECAN_FIFO_START_AREA_29 29
555 #define ECAN_FIFO_START_AREA_28 28
556 #define ECAN_FIFO_START_AREA_27 27
557 #define ECAN_FIFO_START_AREA_26 26
558 #define ECAN_FIFO_START_AREA_25 25
559 #define ECAN_FIFO_START_AREA_24 24
560 #define ECAN_FIFO_START_AREA_23 23
561 #define ECAN_FIFO_START_AREA_22 22
562 #define ECAN_FIFO_START_AREA_21 21
563 #define ECAN_FIFO_START_AREA_20 20
564 #define ECAN_FIFO_START_AREA_19 19
565 #define ECAN_FIFO_START_AREA_18 18
566 #define ECAN_FIFO_START_AREA_17 17
567 #define ECAN_FIFO_START_AREA_16 16
568 #define ECAN_FIFO_START_AREA_15 15
569 #define ECAN_FIFO_START_AREA_14 14
570 #define ECAN_FIFO_START_AREA_13 13
571 #define ECAN_FIFO_START_AREA_12 12
572 #define ECAN_FIFO_START_AREA_11 11
573 #define ECAN_FIFO_START_AREA_10 10
574 #define ECAN_FIFO_START_AREA_9 9
575 #define ECAN_FIFO_START_AREA_8 8
576 #define ECAN_FIFO_START_AREA_7 7
577 #define ECAN_FIFO_START_AREA_6 6
578 #define ECAN_FIFO_START_AREA_5 5
579 #define ECAN_FIFO_START_AREA_4 4
580 #define ECAN_FIFO_START_AREA_3 3
581 #define ECAN_FIFO_START_AREA_2 2
582 #define ECAN_FIFO_START_AREA_1 1
583 #define ECAN_FIFO_START_AREA_0 0
584 
585 //CiRXFnSID register
586 #define ECAN_MATCH_EID 0x0008
587 #define ECAN_MATCH_SID 0x0000
588 
589 #define ECAN_USE_FIFO 0xF
590 
591 //CiTRmnCON TXRX buffer control
592 #define ECAN_RX_BUFF 0
593 #define ECAN_TX_BUFF 1
594 
595 
596 //Data structure for ECAN Data Frame
597 typedef struct _ECANW0 {
598  unsigned IDE: 1;
599  unsigned SRR:1;
600  unsigned SID:11;
601 } ECANW0;
602 typedef struct _ECANW1 {
603  unsigned EID17_6: 12;
604 } ECANW1;
605 
606 typedef struct _ECANW2 {
607  unsigned DLC:4;
608  unsigned RB0:1;
609  unsigned :3;
610  unsigned RB1:1;
611  unsigned RTR:1;
612  unsigned EID5_0:6;
613 } ECANW2;
614 
615 typedef struct _ECANW7 {
616  unsigned :8;
617  unsigned FILHIT:5;
618  unsigned :3;
619 } ECANW7;
620 
621 
622 
623 typedef struct _ECANMSG {
624  ECANW0 w0;
625  ECANW1 w1;
626  ECANW2 w2;
627  union64 data;
628  ECANW7 w7;
629 } ECANMSG;
630 
631 // dsPIC33EP512GP806 must be handled differently than the rest of the family
632 // due to errata in the DMA subsystem (see document DS80000526E - silicon issue
633 // 15). DPRAM must be used to ensure that the DMA cannot be held in the "OFF"
634 // state by the system arbiter. [Ryan Taylor; November 2015]
635 #if defined(__dsPIC33EP512GP806__)
636 
637 void formatStandardDataFrameECAN (__eds__ ECANMSG* p_ecanmsg, uint16_t u16_id, uint8_t u8_len);
638 void formatExtendedDataFrameECAN (__eds__ ECANMSG* p_ecanmsg, uint32_t u32_id, uint8_t u8_len);
639 uint32_t getIdExtendedDataFrameECAN (__eds__ ECANMSG* p_ecanmsg);
640 
641 #else
642 
643 void formatStandardDataFrameECAN (ECANMSG* p_ecanmsg, uint16_t u16_id, uint8_t u8_len);
644 void formatExtendedDataFrameECAN (ECANMSG* p_ecanmsg, uint32_t u32_id, uint8_t u8_len);
645 uint32_t getIdExtendedDataFrameECAN (ECANMSG* p_ecanmsg);
646 
647 #endif
648 
649 #define ECAN_1TIME_HEADER_DEFS
650 #endif
651 
652 
653 
654 
655 #ifdef _C2IF
656 /** Waits until all characters placed in the UART have been sent. */
657 inline static void CHANGE_MODE_ECAN2(uint16_t u16_mode) {
658  C2CTRL1bits.REQOP = u16_mode;
659  while(C2CTRL1bits.OPMODE != u16_mode);
660 }
661 
662 /** Return the number (0-31) of the next ECAN FIFO read buffer
663  */
664 #define GET_FIFO_READBUFFER_ECAN2() (C2FIFO & 0x1F)
665 
666 void configBaudECAN2(void);
667 void clrRxFullFlagECAN2(uint8_t u8_bufNum);
668 uint8_t getRxFullFlagECAN2(uint8_t u8_bufNum);
669 void clrRxFullOvfFlagsECAN2(void);
670 void configTxRxBufferECAN2(uint8_t u8_bufNum, uint8_t u8_type, uint8_t u8_priority);
671 void configRxFilterECAN2(uint8_t u8_filtNum, uint32_t u32_id, uint8_t u8_idType, uint8_t u8_bufnum, uint8_t u8_maskReg);
672 void configRxMaskECAN2(uint8_t u8_maskNum, uint32_t u32_idMask, uint8_t u8_idType, uint8_t u8_matchType);
673 void startTxECAN2(uint8_t u8_bufNum);
674 uint8_t getTxInProgressECAN2(uint8_t u8_bufNum);
675 
676 #endif
677 
678 
679 #endif // #if (NUM_ECAN_MODS >= 2)
680 
681 
682 
683 
684 
685 
686 
uint8_t getRxFullFlagECAN1(uint8_t u8_bufNum)
Definition: pic24_ecan.c:258
void formatExtendedDataFrameECAN(ECANMSG *p_ecanmsg, uint32_t u32_id, uint8_t u8_len)
Definition: pic24_ecan.c:121
void clrRxFullOvfFlagsECAN1(void)
Definition: pic24_ecan.c:271
uint8_t getTxInProgressECAN1(uint8_t u8_bufNum)
Definition: pic24_ecan.c:360
void clrRxFullFlagECAN1(uint8_t u8_bufNum)
Definition: pic24_ecan.c:243
void configRxFilterECAN1(uint8_t u8_filtNum, uint32_t u32_id, uint8_t u8_idType, uint8_t u8_bufnum, uint8_t u8_maskReg)
Definition: pic24_ecan.c:393
void configTxRxBufferECAN1(uint8_t u8_bufNum, uint8_t u8_type, uint8_t u8_priority)
Definition: pic24_ecan.c:284
uint32_t getIdExtendedDataFrameECAN(ECANMSG *p_ecanmsg)
Definition: pic24_ecan.c:157
Configures the system clock.
void formatStandardDataFrameECAN(ECANMSG *p_ecanmsg, uint16_t u16_id, uint8_t u8_len)
Definition: pic24_ecan.c:81
A union type for byte, word, or dword access for 64 bit values.
Definition: pic24_unions.h:61
void startTxECAN1(uint8_t u8_bufNum)
Definition: pic24_ecan.c:326
unsigned char uint8_t
An abbreviation for an 8-bit unsigned integer.
Definition: dataXferImpl.h:194
void configBaudECAN1(void)
Definition: pic24_ecan.c:176
void configRxMaskECAN1(uint8_t u8_maskNum, uint32_t u32_idMask, uint8_t u8_idType, uint8_t u8_matchType)
Definition: pic24_ecan.c:451