ECAN.h 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714
  1. /*********************************************************************
  2. *
  3. * ECAN C Library Source Code
  4. *
  5. *********************************************************************
  6. * FileName: ECAN.h
  7. * Dependencies: ECAN.def
  8. * Processor: Any PIC18 with ECAN module
  9. * Complier: Microchip C 2.10.06 or higher
  10. * Company: Microchip Technology, Inc.
  11. *
  12. *
  13. * Software License Agreement
  14. *
  15. * The software supplied herewith by Microchip Technology Incorporated
  16. * (the “Company”) for its PICmicro® Microcontroller is intended and
  17. * supplied to you, the Company’s customer, for use solely and
  18. * exclusively on Microchip PICmicro Microcontroller products. The
  19. * software is owned by the Company and/or its supplier, and is
  20. * protected under applicable copyright laws. All rights are reserved.
  21. * Any use in violation of the foregoing restrictions may subject the
  22. * user to criminal sanctions under applicable laws, as well as to
  23. * civil liability for the breach of the terms and conditions of this
  24. * license.
  25. *
  26. * THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES,
  27. * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
  28. * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  29. * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
  30. * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
  31. * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
  32. *
  33. * Author Date Comment
  34. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  35. * Caio Gubel 5/5/03 Version 1.0 - Initial Release
  36. * Nilesh R. 7/22/03 Improved
  37. *********************************************************************/
  38. #ifndef ECAN_H // To avoid duplicate inclusion
  39. #define ECAN_H
  40. #include "ecan.def"
  41. #if defined(HI_TECH_C)
  42. #define HITECH_C18
  43. #else
  44. #define MCHP_C18
  45. #endif
  46. #if defined(MCHP_C18) && defined(HITECH_C18)
  47. #error "Invalid Compiler selection."
  48. #endif
  49. #if !defined(MCHP_C18) && !defined(HITECH_C18)
  50. #error "Compiler not supported."
  51. #endif
  52. #if defined(MCHP_C18)
  53. #include <p18cxxx.h> // p18cxxx.h must have current processor
  54. // defined.
  55. #endif
  56. #if defined(HITECH_C18)
  57. #include <pic18.h>
  58. #endif
  59. /*********************************************************************
  60. *
  61. * General purpose typedef's
  62. *
  63. * Remove these definations if they are already defined in one of your
  64. * application files.
  65. ********************************************************************/
  66. typedef enum _BOOL { FALSE = 0, TRUE } BOOL;
  67. typedef unsigned char BYTE;
  68. typedef union _BYTE_VAL
  69. {
  70. struct
  71. {
  72. unsigned int b0:1;
  73. unsigned int b1:1;
  74. unsigned int b2:1;
  75. unsigned int b3:1;
  76. unsigned int b4:1;
  77. unsigned int b5:1;
  78. unsigned int b6:1;
  79. unsigned int b7:1;
  80. } bits;
  81. BYTE Val;
  82. } BYTE_VAL;
  83. #define ECAN_LIB_MODE_FIXED 1
  84. #define ECAN_LIB_MODE_RUN_TIME 0
  85. #define ECAN_TX2_MODE_DISABLE 0
  86. #define ECAN_TX2_MODE_ENABLE 1
  87. #define ECAN_INIT_NORMAL 0x00
  88. #define ECAN_INIT_LOOPBACK 0x40
  89. #define ECAN_INIT_CONFIGURATION 0x80
  90. #define ECAN_INIT_DISABLE 0x20
  91. #define ECAN_INIT_LISTEN_ONLY 0X60
  92. #define ECAN_RXFn_ENABLE 1
  93. #define ECAN_RXFn_DISABLE 0
  94. // Enable auto RTR code when at least one buffer is configured in
  95. // auto RTR mode.
  96. #if (ECAN_FUNC_MODE_VAL != MODE_0 )
  97. #if ( (ECAN_B0_AUTORTR_MODE == ECAN_AUTORTR_MODE_ENABLE) || \
  98. (ECAN_B1_AUTORTR_MODE == ECAN_AUTORTR_MODE_ENABLE) || \
  99. (ECAN_B2_AUTORTR_MODE == ECAN_AUTORTR_MODE_ENABLE) || \
  100. (ECAN_B3_AUTORTR_MODE == ECAN_AUTORTR_MODE_ENABLE) || \
  101. (ECAN_B4_AUTORTR_MODE == ECAN_AUTORTR_MODE_ENABLE) || \
  102. (ECAN_B5_AUTORTR_MODE == ECAN_AUTORTR_MODE_ENABLE) )
  103. #define ECAN_ENABLE_AUTO_RTR
  104. #endif
  105. #endif
  106. /*********************************************************************
  107. * Function: void ECANInitialize(void)
  108. *
  109. * Overview: Use this function to initialize ECAN module with
  110. * options defined in ECAN.def file.
  111. * You may manually edit ECAN.def file as per your
  112. * requirements, or use Microchip Application
  113. * Maestro tool.
  114. *
  115. * PreCondition: None
  116. *
  117. * Input: None
  118. *
  119. * Output: None
  120. *
  121. * Side Effects: All pending transmissions are aborted.
  122. ********************************************************************/
  123. void ECANInitialize(void);
  124. /*********************************************************************
  125. *
  126. * ECAN_TX_MSG_FLAGS
  127. *
  128. * This enumeration values define flags related to transmission of a
  129. * CAN message. There could be more than one this flag
  130. * ORed together to form multiple flags.
  131. *
  132. *********************************************************************/
  133. typedef enum _ECAN_TX_MSG_FLAGS
  134. {
  135. ECAN_TX_PRIORITY_BITS = 0b00000011,
  136. ECAN_TX_PRIORITY_0 = 0b00000000,
  137. ECAN_TX_PRIORITY_1 = 0b00000001,
  138. ECAN_TX_PRIORITY_2 = 0b00000010,
  139. ECAN_TX_PRIORITY_3 = 0b00000011,
  140. ECAN_TX_FRAME_BIT = 0b00100000,
  141. ECAN_TX_STD_FRAME = 0b00000000,
  142. ECAN_TX_XTD_FRAME = 0b00100000,
  143. ECAN_TX_RTR_BIT = 0b01000000,
  144. ECAN_TX_NO_RTR_FRAME = 0b00000000,
  145. ECAN_TX_RTR_FRAME = 0b01000000
  146. } ECAN_TX_MSG_FLAGS;
  147. /*********************************************************************
  148. * Function: BOOL ECANSendMessage(unsigned long id,
  149. * BYTE *data,
  150. * BYTE dataLen,
  151. * ECAN_TX_MSG_FLAGS msgFlags)
  152. *
  153. * Overview: Use this function to transmit a CAN message.
  154. * This function searches for empty transmit buffer
  155. * and loads it with given messages. Buffer is then
  156. * marked for ready to transmit.
  157. *
  158. * PreCondition: None
  159. *
  160. * Input: id - CAN message identifier.
  161. * Only 11 or 29 bits may be used
  162. * depending on standard or extended
  163. * message type as specified in
  164. * msgFlags parameter.
  165. * data - Data bytes of upto 8 bytes in length
  166. * dataLen - Data length from 0 thru 8.
  167. * If 0, data may be NULL.
  168. * msgFlags - One or ECAN_TX_MSG_FLAGS values ORed
  169. * together
  170. *
  171. * Output: TRUE, if an empty buffer was found and loaded with
  172. * given data
  173. * FALSE, if otherwise.
  174. *
  175. * Side Effects: None
  176. *
  177. ********************************************************************/
  178. BOOL ECANSendMessage( unsigned long id,
  179. BYTE *data,
  180. BYTE dataLen,
  181. ECAN_TX_MSG_FLAGS msgFlags);
  182. /*********************************************************************
  183. * Function: BOOL ECANLoadRTRBuffer(BYTE buffer,
  184. * unsigned long id,
  185. * BYTE *data,
  186. * BYTE dataLen,
  187. * BYTE type)
  188. *
  189. * Overview: Use this function to update automatic RTR buffer.
  190. *
  191. *
  192. * PreCondition: None
  193. *
  194. * Input: buffer - Buffer number that is to be loaded
  195. * id - CAN message identifier.
  196. * Only 11 or 29 bits may be used
  197. * depending on standard or extended
  198. * message type as specified in
  199. * type parameter.
  200. * data - Data bytes of upto 8 bytes in length
  201. * dataLen - Data length from 0 thru 8.
  202. * If 0, data may be NULL.
  203. * type - Buffer type
  204. * Must be ECAN_MSG_STD for Standard
  205. * ECAN_MSG_XTD for Extended
  206. *
  207. * Output: TRUE, if given data was successfully loaded
  208. * FALSE, if RTR buffer was in process of transmitting
  209. * automated response.
  210. *
  211. * Side Effects: None
  212. *
  213. ********************************************************************/
  214. #if ( defined(ECAN_ENABLE_AUTO_RTR) )
  215. BOOL ECANLoadRTRBuffer(BYTE buffer,
  216. unsigned long id,
  217. BYTE *data,
  218. BYTE dataLen,
  219. BYTE type);
  220. #endif
  221. /*********************************************************************
  222. *
  223. * ECAN_RX_MSG_FLAGS
  224. *
  225. * This enumeration values define flags related to reception of a ECAN
  226. * message. There could be more than one this flag
  227. * ORed together to form multiple flags.
  228. * If a particular bit is set, corresponding meaning is TRUE or else
  229. * it will be FALSE.
  230. *
  231. * e.g.
  232. * if (msgFlag & ECAN_RX_OVERFLOW)
  233. * {
  234. * // Receiver overflow has occured.
  235. * ...
  236. * }
  237. *
  238. ********************************************************************/
  239. typedef enum _ECAN_RX_MSG_FLAGS
  240. {
  241. ECAN_RX_OVERFLOW = 0b00001000,
  242. ECAN_RX_INVALID_MSG = 0b00010000,
  243. ECAN_RX_XTD_FRAME = 0b00100000,
  244. ECAN_RX_RTR_FRAME = 0b01000000,
  245. ECAN_RX_DBL_BUFFERED = 0b10000000
  246. } ECAN_RX_MSG_FLAGS;
  247. /*********************************************************************
  248. * Function: BOOL ECANReceiveMessage(unsigned long *id,
  249. * BYTE *data,
  250. * BYTE *dataLen,
  251. * ECAN_RX_MSG_FLAGS *msgFlags)
  252. *
  253. * Overview: Use this function to check for full receive buffer
  254. * and extract received data into local buffers.
  255. *
  256. * PreCondition: None
  257. *
  258. * Input: id - Pointer to buffer that will be
  259. * populated with receive ID.
  260. * data - Pointer to buffer that will be
  261. * populated with data if there is any
  262. * dataLen - Pointer to buffer that will be
  263. * populated with count of bytes
  264. * copied in data buffer.
  265. * msgFlags - Pointer to buffer that will be
  266. * copied with information about
  267. * received message. More than
  268. * one information is ORed together.
  269. *
  270. * Output: TRUE, if a full receive buffer was found and
  271. * given parameters were populated.
  272. * FALSE, if otherwise.
  273. *
  274. * Side Effects: None
  275. *
  276. * Note: If you need to know the filter number that caused
  277. * this message to get accepted, call
  278. * ECANGetFilterHitInfo().
  279. *
  280. ********************************************************************/
  281. BOOL ECANReceiveMessage( unsigned long* id,
  282. BYTE *Data,
  283. BYTE *DataLen,
  284. ECAN_RX_MSG_FLAGS *MsgFlags);
  285. /*********************************************************************
  286. * Macro: BYTE ECANGetFilterHitInfo(void)
  287. *
  288. * Overview: Use this macro to extract filter number that
  289. * caused a message to get accepted.
  290. * You must call this macro immediately after calling
  291. * ECANReceiveMessage function.
  292. *
  293. * PreCondition: ECANReceiveMessage is called and returned TRUE
  294. *
  295. * Input: None
  296. *
  297. * Output: Number of filter that caused acceptance.
  298. * 0 means RXF0, 1 means RXF1 and so on.
  299. *
  300. * Side Effects: None
  301. *
  302. * Note: This macro will return filter hit information
  303. * for previously received message only.
  304. *
  305. ********************************************************************/
  306. #define ECANGetFilterHitInfo() (_ECANRxFilterHitInfo.Val)
  307. extern BYTE_VAL _ECANRxFilterHitInfo;
  308. /*********************************************************************
  309. *
  310. * ECAN_OP_MODE
  311. *
  312. * This enumeration values define codes related to ECAN module
  313. * operation mode. ECANSetOperationMode() routine requires this code.
  314. * These values must be used by itself
  315. * i.e. it cannot be ORed to form * multiple values.
  316. *
  317. ********************************************************************/
  318. typedef enum _ECAN_OP_MODE
  319. {
  320. ECAN_OP_MODE_BITS = 0xe0, // Use this to access opmode bits
  321. ECAN_OP_MODE_NORMAL = 0x00,
  322. ECAN_OP_MODE_SLEEP = 0x20,
  323. ECAN_OP_MODE_LOOP = 0x40,
  324. ECAN_OP_MODE_LISTEN = 0x60,
  325. ECAN_OP_MODE_CONFIG = 0x80
  326. } ECAN_OP_MODE;
  327. /*********************************************************************
  328. * Function: void ECANSetOperationMode(ECAN_OP_MODE mode)
  329. *
  330. * Overview: Use this function to switch ECAN module into
  331. * given operational mode.
  332. * You may not need to call this function if
  333. * your application does not require run-time
  334. * changes in ECAN mode.
  335. *
  336. * PreCondition: None
  337. *
  338. * Input: mode - Operation mode code
  339. * must be of type ECAN_OP_MODES
  340. *
  341. * Output: MCU is set to requested mode
  342. *
  343. * Side Effects: None
  344. *
  345. * Note: This is a blocking call. It will not return until
  346. * requested mode is set.
  347. ********************************************************************/
  348. void ECANSetOperationMode(ECAN_OP_MODE mode);
  349. /*********************************************************************
  350. * Macro: void ECANSetOperationModeNoWait(ECAN_OP_MODE mode)
  351. *
  352. * Overview: Use this macro to request operation mode but
  353. * do not want macro to wait for it get accepted.
  354. * You must use ECANGetOperationMode() to esnure
  355. * requested operation mode is accepted before
  356. * performing operation critical steps.
  357. * You may not need to call this macro if your
  358. * application does not require run-time changes
  359. * in ECAN mode.
  360. *
  361. * PreCondition: None
  362. *
  363. * Input: mode - Operation mode code
  364. * must be of type enum ECAN_OP_MODES
  365. *
  366. * Output: MCU is set to requested mode
  367. *
  368. * Side Effects: None
  369. *
  370. * Note: This is a non-blocking call.
  371. * It does not verify that
  372. * ECAN module is switched to requested mode or not.
  373. * Caller must use ECANGetOperationMode() to verify
  374. * correct operation mode before performing mode
  375. * specific operation.
  376. *
  377. ********************************************************************/
  378. #define ECANSetOperationModeNoWait(mode) CANCON = mode
  379. /*********************************************************************
  380. * Macro: ECAN_OP_MODE ECANGetOperationMode()
  381. *
  382. * Overview: Use this macro to obtain current operation mode
  383. * ECAN module.
  384. * You may not need to call this macro if your
  385. * application does not require run-time changes.
  386. * PreCondition:
  387. *
  388. * Input:
  389. *
  390. * Output: Current operational mode of ECAN module is returned
  391. *
  392. * Side Effects: None
  393. *
  394. ********************************************************************/
  395. #define ECANGetOperationMode() (CANCON & ECAN_OP_MODE_BITS)
  396. /*********************************************************************
  397. * Macro: ECANSetFunctionalMode(mode)
  398. *
  399. * Overview: Use this macro to set functional mode of ECAN.
  400. * You may not need to call this macro if
  401. * your application will not change mode at run-time.
  402. *
  403. * PreCondition: ECAN must be in configuration mode
  404. * and ECAN_LIB_MODE_VAL = ECAN_LIB_MODE_RUN_TIME
  405. *
  406. * Input: mode - New mode
  407. * Allowable values are
  408. * ECAN_MODE_0 for Mode 0
  409. * ECAN_MODE_1 for Mode 1
  410. * ECAN_MODE_2 for Mode 2
  411. *
  412. * Output: None
  413. *
  414. * Side Effects:
  415. *
  416. ********************************************************************/
  417. //if ( ECAN_LIB_MODE_VAL == ECAN_LIB_MODE_RUN_TIME )
  418. #define ECANSetFunctionalMode(mode) \
  419. ECANCON_MDSEL1 = mode >> 7; \
  420. ECANCON_MDSEL0 = mode >> 6;
  421. //#endif
  422. #define ECAN_MODE_0 0x00
  423. #define ECAN_MODE_1 0x40
  424. #define ECAN_MODE_2 0x80
  425. /*********************************************************************
  426. * Macro: BYTE ECANGetFunctionalMode()
  427. *
  428. * Overview: Use this macro to get functional mode of ECAN.
  429. * You may not need to call this macro if
  430. * your application will not change mode at run-time.
  431. *
  432. * PreCondition: None
  433. *
  434. * Input: None
  435. *
  436. * Output: mode - ECAN_MODE_0
  437. * ECAN_MODE_1
  438. * ECAN_MODE_2
  439. *
  440. * Side Effects:
  441. *
  442. ********************************************************************/
  443. #define ECANGetFunctionalMode() (ECANCON & 0b11000000)
  444. /*********************************************************************
  445. * Macro: ECANSetBusSampleMode(mode)
  446. *
  447. * Overview: Use this macro to set CAN bus sample mode.
  448. * You may not need to call this macro if your
  449. * application does not require run-time change
  450. * to sampling mode.
  451. *
  452. * PreCondition: ECAN must be in configuration mode
  453. *
  454. * Input: mode - Bus sample mode
  455. * Allowable values are
  456. * ECAN_BUS_SAMPLE_MODE_ONCE to sample once
  457. * ECAN_BUS_SAMPLE_THRICE to sample thrice.
  458. *
  459. * Output: None
  460. *
  461. * Side Effects:
  462. *
  463. ********************************************************************/
  464. #define ECANSetBusSampleMode(mode) BRGCON2_SAM = mode
  465. #define ECAN_BUS_SAMPLE_MODE_ONCE 0
  466. #define ECAN_BUS_SAMPLE_MODE_THRICE 1
  467. /*********************************************************************
  468. * Macro: ECANSetWakeupMode(mode)
  469. *
  470. * Overview: Use this macro to set CAN bus activity bus mode.
  471. * You may not need to call this macro if your
  472. * application does not require run-time changes.
  473. *
  474. * PreCondition: ECAN must be in configuration mode
  475. *
  476. * Input: mode - CAN Bus activity wakeup mode
  477. * Allowable values are
  478. * ECAN_WAKEUP_MODE_ENABLE to enable bus wakeup
  479. * ECAN_WAKEUP_MODE_DISABLE to disable bus wakeup
  480. *
  481. * Output: None
  482. *
  483. * Side Effects:
  484. *
  485. ********************************************************************/
  486. #define ECANSetWakeupMode(mode) BRGCON3_WAKDIS = mode
  487. #define ECAN_WAKEUP_MODE_ENABLE 0
  488. #define ECAN_WAKEUP_MODE_DISABLE 1
  489. /*********************************************************************
  490. * Macro: ECANSetFilterMode(mode)
  491. *
  492. * Overview: Use this macro to CAN wakeup low pass filter mode.
  493. * You may not need to call this macro if your application
  494. * does not require run-time changes.
  495. *
  496. * PreCondition: ECAN must be in configuration mode
  497. *
  498. * Input: mode - CAN wakeup filter mode
  499. * Allowable values are
  500. * ECAN_FILTER_MODE_DISABLE to not use wakeup filter
  501. * ECAN_FILTER_MODE_ENABLE to use wakeup filter
  502. *
  503. * Output: None
  504. *
  505. * Side Effects:
  506. *
  507. ********************************************************************/
  508. #define ECANSetFilterMode(mode) BRGCON3_WAKFIL = mode
  509. #define ECAN_FILTER_MODE_DISABLE 0
  510. #define ECAN_FILTER_MODE_ENABLE 1
  511. /*********************************************************************
  512. * Macro: ECANSetTxDriveMode(mode)
  513. *
  514. * Overview: Use this macro to set CANTX pin drive options.
  515. * You may not need to call this macro if your
  516. * application does not require run-time change.
  517. *
  518. * PreCondition: None
  519. *
  520. * Input: mode - CANTX drive mode when trnasmitting
  521. * recessive bit.
  522. * Allowable values are
  523. * ECAN_TXDRIVE_MODE_TRISTATE to drive tri-state
  524. * ECAN_TXDRIVE_MODE_VDD to drive to Vdd
  525. *
  526. * Output: None
  527. *
  528. * Side Effects:
  529. *
  530. ********************************************************************/
  531. #define ECANSetTxDriveMode(mode) CIOCON_ENDRHI = mode
  532. #define ECAN_TXDRIVE_MODE_TRISTATE 0
  533. #define ECAN_TXDRIVE_MODE_VDD 1
  534. /*********************************************************************
  535. * Macro: ECANSetCANTX2Source(source)
  536. *
  537. * Overview: Use this macro to set CANTX2 pin source.
  538. * This macro automatically enables CANTX2 pin.
  539. * You may not need to call this macro if your
  540. * application does not require run-time change.
  541. *
  542. * PreCondition: None
  543. *
  544. * Input: source - CANTX2 source
  545. * Allowable values are
  546. * ECAN_TX2_CAN_CLOCK to output CAN clock on TX2
  547. * ECAN_TX2_CAN_DATA to output complete CAN
  548. *
  549. * Output: None
  550. *
  551. * Side Effects:
  552. *
  553. ********************************************************************/
  554. #define ECANSetCANTX2Mode(mode) CIOCON_TX2SRC = mode << 7; \
  555. CIOCON_TX2EN = 1
  556. #define ECAN_TX2_SOURCE_COMP 0
  557. #define ECAN_TX2_SOURCE_CLOCK 1
  558. /*********************************************************************
  559. * Macro: ECANDisableCANTX2()
  560. *
  561. * Overview: Use this macro to disable CANTX2 pin.
  562. * You may not need to call this macro if your
  563. * application does not require run-time change.
  564. *
  565. * PreCondition: None
  566. *
  567. * Input: None
  568. *
  569. * Output: None
  570. *
  571. * Side Effects:
  572. *
  573. ********************************************************************/
  574. #define ECANDisableCANTX2() CIOCON_TX2EN = 0
  575. /*********************************************************************
  576. * Macro: ECANSetCaptureMode(mode)
  577. *
  578. * Overview: Use this macro to set CAN CAPTURE mode. This is
  579. * mainly used to timestamp incoming CAN messages.
  580. * You would also need to setup and enable CCP module
  581. * to obtain timeestamp information.
  582. * You may not need to call this macro if your
  583. * application does not require run-time change.
  584. *
  585. * PreCondition: None
  586. *
  587. * Input: mode - Capture mode
  588. * Allowable values are
  589. * ECAN_CAPTURE_MODE_DISABLE
  590. * ECAN_CAPTURE_MODE_ENABLE
  591. *
  592. * Output: None
  593. *
  594. * Side Effects:
  595. *
  596. ********************************************************************/
  597. #define ECANSetCaptureMode(mode) CIOCON_CANCAP = mode
  598. #define ECAN_CAPTURE_MODE_DISABLE 0
  599. #define ECAN_CAPTURE_MODE_ENABLE 1
  600. /*********************************************************************
  601. * Macro: ECANSetPHSEG2Mode(mode)
  602. *
  603. * Overview: Use this macro to set PHSEG2 mode.
  604. * You may not need to call this macro if your
  605. * application does not require run-time change.
  606. *
  607. * PreCondition: None
  608. *
  609. * Input: mode - PHSEG2 Mode
  610. * Allowable values are
  611. * ECAN_PHSEG2_MODE_AUTOMATIC
  612. * - Max. of PHSEG1 of IPT, whichever is greater
  613. * ECAN_PHSEG2_MODE_PROGRAMMABLE
  614. * - Freely programmable
  615. *
  616. * Output: None
  617. *
  618. * Side Effects:
  619. *
  620. ********************************************************************/
  621. #define ECANSetPHSEG2Mode(mode) BRGCON2_SEG2PHTS = mode
  622. #define ECAN_PHSEG2_MODE_AUTOMATIC 0
  623. #define ECAN_PHSEG2_MODE_PROGRAMMABLE 1
  624. /*********************************************************************
  625. * Macro: ECANSetB0AutoRTRMode(mode)
  626. * ECANSetB1AutoRTRMode(mode)
  627. * ECANSetB2AutoRTRMode(mode)
  628. * ECANSetB3AutoRTRMode(mode)
  629. * ECANSetB4AutoRTRMode(mode)
  630. * ECANSetB5AutoRTRMode(mode)
  631. *
  632. * Overview: Use these macros to set automatic RTR handling
  633. * mode for given programmable buffer.
  634. * You may not need to call this macro if your
  635. * application does not require run-time change.
  636. *
  637. * PreCondition: ECAN_LIB_MODE_VAL = ECAN_LIB_MODE_RUN_TIME
  638. * ECAN_FUNC_MODE_VAL != ECAN_MODE_0
  639. *
  640. * Input: mode - AutoRTR mode
  641. * Allowable values are
  642. * ECAN_AUTORTR_MODE_DISABLE
  643. * - To disable automatic RTR handling
  644. * ECAN_AUTORTR_MODE_ENABLE
  645. * - To enable automatic RTR handling
  646. *
  647. * Output: None
  648. *
  649. * Side Effects:
  650. *
  651. ********************************************************************/
  652. #if ( (ECAN_LIB_MODE_VAL == ECAN_LIB_MODE_RUN_TIME) || \
  653. (ECAN_FUNC_MODE_VAL != ECAN_MODE_0) )
  654. #define ECANSetB0AutoRTRMode(mode) B0CON_RTREN = mode; \
  655. BSEL0_B0TXEN = 1
  656. #define ECANSetB1AutoRTRMode(mode) B1CON_RTREN = mode; \
  657. BSEL0_B1TXEN = 1
  658. #define ECANSetB2AutoRTRMode(mode) B2CON_RTREN = mode; \
  659. BSEL0_B2TXEN = 1
  660. #define ECANSetB3AutoRTRMode(mode) B3CON_RTREN = mode; \
  661. BSEL0_B3TXEN = 1
  662. #define ECANSetB4AutoRTRMode(mode) B4CON_RTREN = mode; \
  663. BSEL0_B4TXEN = 1
  664. #define ECANSetB5AutoRTRMode(mode) B5CON_RTREN = mode; \
  665. BSEL0_B5TXEN = 1
  666. #endif
  667. #define ECAN_AUTORTR_MODE_DISABLE 0
  668. #define ECAN_AUTORTR_MODE_ENABLE 1
  669. /*********************************************************************
  670. * Macro: ECANSetRXMnValue(val, type)
  671. *
  672. * Overview: Use these macros to set specific mask value.
  673. * You may not need to call this macro if your
  674. * application does not require run-time change.
  675. *
  676. * PreCondition: ECAN must be in Configuration mode
  677. *
  678. * Input: val - Value to be set
  679. * Actual value would depend on type.
  680. * If type is Standard, value will be 11-bit long
  681. * If type is Extended, value will be 29-bit long
  682. * type - Mask type
  683. * Allowable values are
  684. * ECAN_MSG_STD for Standard type
  685. * ECAN_MSG_XTD for Extended type
  686. *
  687. * Output: None
  688. *
  689. * Side Effects: None
  690. *
  691. *
  692. * Overview: This function sets mask value for given mask number.
  693. * Type of mask, whether standard or extended is defined
  694. * by type parameter.
  695. *
  696. * Note: The MASK_RXF15 is only available in enhanced and
  697. * FIFO modes
  698. ********************************************************************/
  699. #define ECANSetRXM0Value(val, type) \
  700. _CANIDToRegs((BYTE*)&RXM0SIDH, val, type)
  701. #define ECANSetRXM1Value(val, type) \
  702. _CANIDToRegs((BYTE*)&RXM1SIDH, val, type)
  703. /*********************************************************************
  704. * Macro: ECANSetRXFnValue(val, type)
  705. *
  706. * Overview: Use these macros to set receive filter values.
  707. * You may not need to call this macro if your
  708. * application does not require run-time change.
  709. *
  710. * PreCondition: ECAN must be in Configuration mode
  711. * To set RXF6-RXF15 values,
  712. * ECAN_LIB_MODE_VAL = ECAN_LIB_MODE_RUN_TIME OR
  713. * ECAN_FUNC_MODE != ECAN_MODE_0
  714. *
  715. * Input: val - Value to be set
  716. * type - Type of filter
  717. * Allowable values are
  718. * ECAN_MSG_STD if this is Standard filter
  719. * ECAN_MSG_XTD if this is Extended filter
  720. *
  721. * Output: None
  722. *
  723. * Side Effects: None
  724. *
  725. * Overview: Use this macro to assign value to a receive filter.
  726. *
  727. * Note: There are total of sixteen macros - one for each
  728. * receive filter. e.g. for RXF0 use ECANSetRXF0Value()
  729. * for RXF2 use ECANSetRXF2Value()
  730. ********************************************************************/
  731. #define ECANSetRXF0Value(val, type) \
  732. RXFCON0_RXF0EN = 1; \
  733. _CANIDToRegs((BYTE*)&RXF0SIDH, val, type)
  734. #define ECANSetRXF1Value(val, type) \
  735. RXFCON0_RXF1EN = 1; \
  736. _CANIDToRegs((BYTE*)&RXF1SIDH, val, type);
  737. #define ECANSetRXF2Value(val, type) \
  738. RXFCON0_RXF2EN = 1; \
  739. _CANIDToRegs((BYTE*)&RXF2SIDH, val, type);
  740. #define ECANSetRXF3Value(val, type) \
  741. RXFCON0_RXF3EN = 1; \
  742. _CANIDToRegs((BYTE*)&RXF3SIDH, val, type);
  743. #define ECANSetRXF4Value(val, type) \
  744. RXFCON0_RXF4EN = 1; \
  745. _CANIDToRegs((BYTE*)&RXF4SIDH, val, type);
  746. #define ECANSetRXF5Value(val, type) \
  747. RXFCON0_RXF5EN = 1; \
  748. _CANIDToRegs((BYTE*)&RXF5SIDH, val, type);
  749. #if ( (ECAN_LIB_MODE_VAL == ECAN_LIB_MODE_RUN_TIME) || \
  750. (ECAN_FUNC_MODE_VAL != ECAN_MODE_0) )
  751. #define ECANSetRXF6Value(val, type) \
  752. RXFCON0_RXF6EN = 1; \
  753. _CANIDToRegs((BYTE*)&RXF6SIDH, val, type);
  754. #define ECANSetRXF7Value(val, type) \
  755. RXFCON0_RXF7EN = 1; \
  756. _CANIDToRegs((BYTE*)&RXF7SIDH, val, type);
  757. #define ECANSetRXF8Value(val, type) \
  758. RXFCON1_RXF8EN = 1; \
  759. _CANIDToRegs((BYTE*)&RXF8SIDH, val, type);
  760. #define ECANSetRXF9Value(val, type) \
  761. RXFCON1_RXF9EN = 1; \
  762. _CANIDToRegs((BYTE*)&RXF9SIDH, val, type);
  763. #define ECANSetRXF10Value(val, type) \
  764. RXFCON1_RXF10EN = 1; \
  765. _CANIDToRegs((BYTE*)&RXF10SIDH, val, type);
  766. #define ECANSetRXF11Value(val, type) \
  767. RXFCON1_RXF11EN = 1; \
  768. _CANIDToRegs((BYTE*)&RXF11SIDH, val, type);
  769. #define ECANSetRXF12Value(val, type) \
  770. RXFCON1_RXF12EN = 1; \
  771. _CANIDToRegs((BYTE*)&RXF12SIDH, val, type);
  772. #define ECANSetRXF13Value(val, type) \
  773. RXFCON1_RXF13EN = 1; \
  774. _CANIDToRegs((BYTE*)&RXF13SIDH, val, type);
  775. #define ECANSetRXF14Value(val, type) \
  776. RXFCON1_RXF14EN = 1; \
  777. _CANIDToRegs((BYTE*)&RXF14SIDH, val, type);
  778. #define ECANSetRXF15Value(val, type) \
  779. RXFCON1_RXF15EN = 1; \
  780. _CANIDToRegs((BYTE*)&RXF15SIDH, val, type);
  781. #endif
  782. #define ECAN_MSG_STD 0
  783. #define ECAN_MSG_XTD 1
  784. /*********************************************************************
  785. * Macro: ECANSetBnTxRxMode(buffer, mode)
  786. *
  787. * Overview: Use this macro to configure a programmable buffer (B0-B5)
  788. * as either transmit or receive buffer.
  789. * You may not need to call this macro if your
  790. * application does not require run-time change.
  791. *
  792. *
  793. * PreCondition: ECAN_LIB_MODE = ECAN_LIB_MODE_RUN_TIME OR
  794. * ECAN_FUNC_MODE_VAL != ECAN_MODE_0
  795. *
  796. * Input: buffer - Buffer that needs to be setup
  797. * Allowable values are:
  798. * B0, B1, B2, B3, B4, B5
  799. * mode - Mode to be set.
  800. * Allowable values are:
  801. * ECAN_BUFFER_TX, ECAN_BUFFER_RX
  802. *
  803. * Output: None
  804. *
  805. * Side Effects:
  806. *
  807. * Example: // Set B0 as Transmit buffer
  808. * ECANSetBnTxRxMode(B0, ECAN_TX)
  809. *
  810. * // Set B2 as receive buffer
  811. * ECANSetBnTxRxMode(B2, ECAN_RX)
  812. *
  813. * Note: Parameter buffer must be a constant symbol of either
  814. * B0, B1, B2, B3, B4 or B5.
  815. * A variable parameter would result in compiler error.
  816. *
  817. * e.g. ECANSetBnTxRxMode(myBuffer, ECAN_BUFFER_TX)
  818. * would not compile.
  819. *
  820. *
  821. ********************************************************************/
  822. #if ( (ECAN_LIB_MODE_VAL == ECAN_LIB_MODE_RUN_TIME) || \
  823. (ECAN_FUNC_MODE_VAL != ECAN_MODE_0) )
  824. #define ECANSetBnTxRxMode(buffer, mode) \
  825. BSEL0_##buffer##TXEN = mode
  826. #endif
  827. #define RXB0 0
  828. #define RXB1 1
  829. #define B0 2
  830. #define B1 3
  831. #define B2 4
  832. #define B3 5
  833. #define B4 6
  834. #define B5 7
  835. #define TXB0 8
  836. #define TXB1 9
  837. #define TXB2 10
  838. #define ECAN_BUFFER_RX 0
  839. #define ECAN_BUFFER_TX 1
  840. /*********************************************************************
  841. * Macro: ECANSetRXB0DblBuffer(mode)
  842. *
  843. * Overview: Use this macro to configure RXB0 in double buffering mode
  844. * You may not need to call this macro if your
  845. * application does not require run-time change.
  846. *
  847. *
  848. * PreCondition: None
  849. *
  850. * Input: mode - Double buffer mode
  851. * Allowable values are
  852. * ECAN_DBL_BUFFER_ENABLE
  853. * ECAN_DBL_BUFFER_DISABLE,
  854. *
  855. * Output: None
  856. *
  857. * Example: // Enable Double buffering mode
  858. * ECANSetRXB0DblBuffer(ECAN_DBL_BUFFER_ENABLE)
  859. *
  860. *
  861. * Side Effects:
  862. *
  863. * Note: None
  864. *
  865. ********************************************************************/
  866. #if ( (ECAN_LIB_MODE_VAL == ECAN_LIB_MODE_RUN_TIME) || \
  867. (ECAN_FUNC_MODE_VAL == ECAN_MODE_0) )
  868. #define ECANSetRXB0DblBuffer(mode) RXB0CON_RXB0DBEN = mode
  869. #endif
  870. #define ECAN_DBL_BUFFER_MODE_DISABLE 0
  871. #define ECAN_DBL_BUFFER_MODE_ENABLE 1
  872. /*********************************************************************
  873. * Macro: ECANSetRxBnRxMode(buffer, mode)
  874. *
  875. * Overview: Use this macro to configure receive mode of a fixed receive buffer.
  876. * You may not need to call this macro if your
  877. * application does not require run-time change.
  878. *
  879. *
  880. * PreCondition: None
  881. *
  882. * Input: buffer - Buffer that needs to be configured
  883. * Allowable values are
  884. * RXB0, RXB1
  885. * mode - Mode to be setup.
  886. * Allowable values are
  887. * ECAN_RECEIVE_ALL,
  888. * ECAN_RECEIVE_STANDARD,
  889. * ECAN_RECEIVE_EXTENDED,
  890. * ECAN_RECEIVE_ALL_VALID
  891. *
  892. * Output: None
  893. *
  894. * Example: // Configure RXB0 buffer to receive all valid messages.
  895. * ECANSetRxBnRxMode(RXB0, ECAN_RECEIVE_ALL_VALID)
  896. *
  897. * // Configure RXB1 buffer to receive only Standard messages.
  898. * ECANSetRxBnRxMode(RXB1, ECAN_RECEIVE_STANDARD)
  899. *
  900. * Side Effects:
  901. *
  902. * Note: Parameter buffer must be a constant symbol of either
  903. * RXB0 or RXB1.
  904. * A variable paraemter would result in compiler error.
  905. *
  906. * e.g. ECANSetRxBnTxRxMode(myBuffer, ECAN_RECEIVE_ALL_VALID)
  907. * would not compiler
  908. *
  909. ********************************************************************/
  910. #define ECANSetRxBnRxMode(buffer, mode) \
  911. ##buffer##CON_RXM1 = mode >> 1; \
  912. ##buffer##CON_RXM0 = mode;
  913. #define ECAN_RECEIVE_ALL_VALID 0
  914. #define ECAN_RECEIVE_STANDARD 1
  915. #define ECAN_RECEIVE_EXTENDED 2
  916. #define ECAN_RECEIVE_ALL 3
  917. /*********************************************************************
  918. * Macro: ECANSetBnRxMode(buffer, mode)
  919. *
  920. * Overview: Use this macro to configure receive mode of a programmable
  921. * receive buffer.
  922. * You may not need to call this macro if your
  923. * application does not require run-time change.
  924. *
  925. *
  926. * PreCondition: None
  927. *
  928. * Input: buffer - Buffer that needs to be configured
  929. * Allowable values are
  930. * B0, B1, B2, B3, B4, B5
  931. * mode - Mode to be setup.
  932. * Allowable values are
  933. * ECAN_RECEIVE_ALL,
  934. * ECAN_RECEIVE_ALL_VALID
  935. *
  936. * Output: None
  937. *
  938. * Example: // Configure B0 buffer to receive all valid messages.
  939. * ECANSetBnRxMode(B0, ECAN_RECEIVE_ALL_VALID)
  940. *
  941. * // Configure B1 buffer to receive only Standard messages.
  942. * ECANSetBnRxMode(RXB1, ECAN_RECEIVE_STANDARD)
  943. *
  944. * Side Effects:
  945. *
  946. * Note 1: Parameter buffer must be a constant symbol of either
  947. * B0, B1, B2, B3, B4 or B5.
  948. * A variable paraemter would result in compiler error.
  949. *
  950. * e.g. ECANSetBnTxRxMode(myBuffer, ECAN_RECEIVE_ALL_VALID)
  951. * would not compiler
  952. *
  953. * 2: This macro should be used in Mode 1 or 2 only.
  954. *
  955. ********************************************************************/
  956. #if ( (ECAN_LIB_MODE_VAL == ECAN_LIB_MODE_RUN_TIME) || \
  957. (ECAN_FUNC_MODE_VAL != ECAN_MODE_0) )
  958. #define ECANSetBnRxMode(buffer, mode) ##buffer##CON_RXM1 = mode
  959. #endif
  960. /*********************************************************************
  961. * Macro: BYTE ECANGetTxErrorCount()
  962. *
  963. * Overview: Use this macro to get current TXERRCNT value
  964. *
  965. * PreCondition: None
  966. *
  967. * Input: None
  968. *
  969. * Output: Current transmit error count as defined by
  970. * CAN specifications.
  971. *
  972. * Side Effects: None
  973. *
  974. ********************************************************************/
  975. #define ECANGetTxErrorCount() (TXERRCNT)
  976. /*********************************************************************
  977. * Macro: BYTE ECANGetRxErrorCount()
  978. *
  979. * Overview: Use this macro to get current RXERRCNT value.
  980. *
  981. * PreCondition: None
  982. *
  983. * Input: None
  984. *
  985. * Output: Current receive error count as defined by
  986. * CAN specifications.
  987. *
  988. * Side Effects: None
  989. *
  990. ********************************************************************/
  991. #define ECANGetRxErrorCount() (RXERRCNT)
  992. /*********************************************************************
  993. * Macro: BOOL ECANIsBusOff()
  994. *
  995. * Overview: Use this macro to check if CAN module is in
  996. * Bus off condition.
  997. *
  998. * PreCondition: None
  999. *
  1000. * Input: None
  1001. *
  1002. * Output: TRUE if CAN Module is off due to excessive error
  1003. * FALSE is it is not off.
  1004. *
  1005. * Side Effects: None
  1006. *
  1007. ********************************************************************/
  1008. #define ECANIsBusOff() (COMSTAT_TXB0)
  1009. /*********************************************************************
  1010. * Macro: BOOL ECANIsTxPassive()
  1011. *
  1012. * Overview: Use this macro to check if CAN module is in
  1013. * Tx passive mode.
  1014. *
  1015. * PreCondition: None
  1016. *
  1017. * Input: None
  1018. *
  1019. * Output: TRUE if CAN transmit module is error passive as
  1020. * defined by CAN specifications.
  1021. *
  1022. * Side Effects: None
  1023. *
  1024. ********************************************************************/
  1025. #define ECANIsTxPassive() (COMSTAT_TXBP)
  1026. /*********************************************************************
  1027. * Macro: BYTE ECANIsRxPassive()
  1028. *
  1029. * Overview: Use this macro to check if CAN is in Rx passive.
  1030. *
  1031. * PreCondition: None
  1032. *
  1033. * Input: None
  1034. *
  1035. * Output: TRUE if CAN receive module is error active as
  1036. * defined by CAN specifications.
  1037. *
  1038. * Side Effects: None
  1039. *
  1040. ********************************************************************/
  1041. #define ECANIsRxPassive() (COMSTAT_RXBP)
  1042. /*********************************************************************
  1043. * Macro: void ECANAbortAll()
  1044. *
  1045. * Overview: Use this macro to request abort for all tx buffers.
  1046. *
  1047. * PreCondition: None
  1048. *
  1049. * Input: None
  1050. *
  1051. * Output: None
  1052. *
  1053. * Side Effects: None
  1054. *
  1055. ********************************************************************/
  1056. #define ECANAbortAll() (CANCON_ABAT = 1)
  1057. /*********************************************************************
  1058. * Macro: BOOL ECANIsAllAborted()
  1059. *
  1060. * Overview: Use this macro to see if previous ECANAbortAll
  1061. * is complete or not.
  1062. *
  1063. * PreCondition: None
  1064. *
  1065. * Input: None
  1066. *
  1067. * Output: TRUE: if there are no pending messages.
  1068. * FALSE: if there abort is still in progress.
  1069. *
  1070. * Side Effects: None
  1071. *
  1072. ********************************************************************/
  1073. #define ECANIsAllAborted() (CANCON_ABAT)
  1074. /*********************************************************************
  1075. * Macro: ECANLinkRXFnFmToBuffer(RXFnBuffer, RXFmBuffer)
  1076. * n = { 0, 2, 4, 6, 8, 10, 12, 14 }
  1077. * m = ( 1, 3, 5, 7, 9, 11, 13, 15 }
  1078. * m = n + 1
  1079. *
  1080. * Overview: Use this macro to link RXFn and RXFm to
  1081. * any of RXB0, RXB1, B0, B1, B2, B3, B4, B5 buffer.
  1082. * You may not need to call this macro if your
  1083. * application does not require run-time change.
  1084. *
  1085. *
  1086. * PreCondition: ECAN must be in Configuration mode
  1087. * Given buffer must be configured as receive buffer.
  1088. * (See ECANSetRxBnTxRxMode and ECANSetBnTxRxMode)
  1089. *
  1090. *
  1091. * Input: RXFnBuffer - Buffer that is to be linked
  1092. * with RXFn filter
  1093. * RXFmBuffer - Buffer that is to be linked
  1094. * with RXFm filter
  1095. *
  1096. * Allowable values for both parameters
  1097. * RXB0, RXB1, B0, B1, B2, B3, B4, B5
  1098. *
  1099. * Output: None
  1100. *
  1101. * Side Effects: None
  1102. *
  1103. *
  1104. * Note: If possible, call this macro with constant
  1105. * parameters to reduce generated code.
  1106. ********************************************************************/
  1107. #if ( (ECAN_LIB_MODE_VAL == ECAN_LIB_MODE_RUN_TIME) || \
  1108. (ECAN_FUNC_MODE_VAL != ECAN_MODE_0) )
  1109. #define ECANLinkRXF0F1ToBuffer(RXF0Buffer, RXF1Buffer) \
  1110. RXFBCON0 = (RXF1Buffer << 4) | RXF0Buffer
  1111. #define ECANLinkRXF2F3ToBuffer(RXF2Buffer, RXF3Buffer) \
  1112. RXFBCON1 = (RXF2Buffer << 4) | RXF3Buffer
  1113. #define ECANLinkRXF4F5ToBuffer(RXF4Buffer, RXF5Buffer) \
  1114. RXFBCON2 = (RXF4Buffer << 4) | RXF5Buffer
  1115. #define ECANLinkRXF6F7ToBuffer(RXF6Buffer, RXF7Buffer) \
  1116. RXFBCON3 = (RXF6Buffer << 4) | RXF7Buffer
  1117. #define ECANLinkRXF8F9ToBuffer(RXF8Buffer, RXF9Buffer) \
  1118. RXFBCON4 = (RXF8Buffer << 4) | RXF9Buffer
  1119. #define ECANLinkRXF10F11ToBuffer(RXF10Buffer, RXF11Buffer) \
  1120. RXFBCON5 = (RXF10Buffer << 4) | RXF11Buffer
  1121. #define ECANLinkRXF12F13ToBuffer(RXF12Buffer, RXF13Buffer) \
  1122. RXFBCON6 = (RXF12Buffer << 4) | RXF13Buffer
  1123. #define ECANLinkRXF14F15ToBuffer(RXF14Buffer, RXF15Buffer) \
  1124. RXFBCON7 = (RXF14Buffer << 4) | RXF15Buffer
  1125. #endif
  1126. /*********************************************************************
  1127. * Macro: ECANLinkRXF0Thru3ToMask(m0, m1, m2, m3)
  1128. * ECANLinkRXF4Thru7ToMask(m4, m5, m6, m7)
  1129. * ECANLinkRXF8Thru11ToMask(m8, m9, m10, m11, m12)
  1130. * ECANLinkRXF12Thru15ToMask(m13, m14, m15, m16)
  1131. *
  1132. * Overview: Use this macro to link receive filters to masks.
  1133. * You may not need to call this macro if your
  1134. * application does not require run-time change.
  1135. *
  1136. *
  1137. * PreCondition: ECAN must be in Configuration mode
  1138. *
  1139. * Input: mn - Buffer that is to be linked
  1140. * with Mask
  1141. *
  1142. * Allowable values for both parameters
  1143. * ECAN_RXM0, ECAN_RXM1, ECAN_RXMF15
  1144. *
  1145. * Output: None
  1146. *
  1147. * Side Effects: None
  1148. *
  1149. *
  1150. * Note: If possible, call this macro with constant
  1151. * parameters to reduce generated code.
  1152. ********************************************************************/
  1153. #if ( (ECAN_LIB_MODE_VAL == ECAN_LIB_MODE_RUN_TIME) || \
  1154. (ECAN_FUNC_MODE_VAL != ECAN_MODE_0) )
  1155. #define ECANLinkRXF0Thru3ToMask(m0, m1, m2, m3) \
  1156. MSEL0 = m3 << 6 | m2 << 4 | m1 << 2 | m0;
  1157. #define ECANLinkRXF4Thru7ToMask(m4, m5, m6, m7) \
  1158. MSEL1 = m7 << 6 | m6 << 4 | m5 << 2 | m4;
  1159. #define ECANLinkRXF8Thru11ToMask(m8, m9, m10, m11) \
  1160. MSEL2 = m11 << 6 | m10 << 4 | m9 << 2 | m8;
  1161. #define ECANLinkRXF12Thru15ToMask(m12, m13, m14, m15) \
  1162. MSEL2 = m15 << 6 | m14 << 4 | m13 << 2 | m12;
  1163. #endif
  1164. #define ECAN_RXM0 0
  1165. #define ECAN_RXM1 1
  1166. #define ECAN_RXMF15 2
  1167. /*********************************************************************
  1168. * Macro: ECANSetBaudRate(sjw,
  1169. * brp,
  1170. * phseg1,
  1171. * phseg2,
  1172. * propseg)
  1173. *
  1174. * Overview: Use this macro to change ECAN baud rate. Normally
  1175. * you would call this macro only, if your application
  1176. * needs run-time baud rate changes.
  1177. *
  1178. * PreCondition: ECAN is in Configuration mode
  1179. *
  1180. * Input: sjw - SJW value of 1-4
  1181. * brp - BRP value of 1-64
  1182. * phseg1 - PHSEG1 value of 1-8
  1183. * phseg2 - PHSEG2 value of 1-8
  1184. *
  1185. * Output: None
  1186. *
  1187. * Side Effects: None
  1188. *
  1189. * Note: If possible, call this macro with constant values
  1190. * to reduce generated code size.
  1191. ********************************************************************/
  1192. #define ECANSetBaudRate(sjw, brp, phseg1, phseg2, propseg) \
  1193. BRGCON1 = ((sjw-1) << 6) | (brp-1); \
  1194. BRGCON2 |= (((phseg1-1) << 3) | (propseg-1)); \
  1195. BRGCON3 = phseg2;
  1196. /*
  1197. * This is a helper function used by some macros. Normally, you would
  1198. * not need to call this function directly.
  1199. */
  1200. void _CANIDToRegs(BYTE* ptr,
  1201. unsigned long val,
  1202. BYTE type );
  1203. /*
  1204. * Following compile-time logic switches symbols as per compiler
  1205. * being used. Currently, it supports Microchip C18 and HiTech
  1206. * PICC18 compilers only.
  1207. */
  1208. #if defined(MCHP_C18)
  1209. #define COMSTAT_TXB0 COMSTATbits.TXB0
  1210. #define COMSTAT_TXBP COMSTATbits.TXBP
  1211. #define COMSTAT_RXBP COMSTATbits.RXBP
  1212. #define COMSTAT_RXBnOVFL COMSTATbits.RXB1OVFL
  1213. #define COMSTAT_RXB0OVFL COMSTATbits.RXB0OVFL
  1214. #define COMSTAT_FIFOEMPTY COMSTATbits.FIFOEMPTY
  1215. #define COMSTAT_RXB1OVFL COMSTATbits.RXB1OVFL
  1216. #define BRGCON2_SEG2PHTS BRGCON2bits.SEG2PHTS
  1217. #define BRGCON2_SAM BRGCON2bits.SAM
  1218. #define BRGCON3_WAKDIS BRGCON3bits.WAKDIS
  1219. #define BRGCON3_WAKFIL BRGCON3bits.WAKFIL
  1220. #define CIOCON_ENDRHI CIOCONbits.ENDRHI
  1221. #define CIOCON_CANCAP CIOCONbits.CANCAP
  1222. #define PIR3_RXBnIF PIR3bits.RXB1IF
  1223. #define PIR3_RXB0IF PIR3bits.RXB0IF
  1224. #define PIR3_RXB1IF PIR3bits.RXB1IF
  1225. #define PIR3_IRXIF PIR3bits.IRXIF
  1226. #define CANCON_ABAT CANCONbits.ABAT
  1227. #define RXB0CON_RXFUL RXB0CONbits.RXFUL
  1228. #define RXB1CON_RXFUL RXB1CONbits.RXFUL
  1229. #define RXB0CON_RXB0DBEN RXB0CONbits.RXBODBEN
  1230. #define TXB0CON_TXREQ TXB0CONbits.TXREQ
  1231. #define TXB1CON_TXREQ TXB1CONbits.TXREQ
  1232. #define TXB2CON_TXREQ TXB2CONbits.TXREQ
  1233. #define RXB0CON_FILHIT0 RXB0CONbits.FILHIT0
  1234. #define RXB0CON_RXM1 RXB0CONbits.RXM1
  1235. #define RXB0CON_RXM0 RXB0CONbits.RXM0
  1236. #define BSEL0_B0TXEN BSEL0bits.B0TXEN
  1237. #define BSEL0_B1TXEN BSEL0bits.B1TXEN
  1238. #define BSEL0_B2TXEN BSEL0bits.B2TXEN
  1239. #define BSEL0_B3TXEN BSEL0bits.B3TXEN
  1240. #define BSEL0_B4TXEN BSEL0bits.B4TXEN
  1241. #define BSEL0_B5TXEN BSEL0bits.B5TXEN
  1242. #define RXFCON0_RXF0EN RXFCON0bits.RXF0EN
  1243. #define RXFCON0_RXF1EN RXFCON0bits.RXF1EN
  1244. #define RXFCON0_RXF2EN RXFCON0bits.RXF2EN
  1245. #define RXFCON0_RXF3EN RXFCON0bits.RXF3EN
  1246. #define RXFCON0_RXF4EN RXFCON0bits.RXF4EN
  1247. #define RXFCON0_RXF5EN RXFCON0bits.RXF5EN
  1248. #define RXFCON0_RXF6EN RXFCON0bits.RXF6EN
  1249. #define RXFCON0_RXF7EN RXFCON0bits.RXF7EN
  1250. #define RXFCON1_RXF8EN RXFCON1bits.RXF8EN
  1251. #define RXFCON1_RXF9EN RXFCON1bits.RXF9EN
  1252. #define RXFCON1_RXF10EN RXFCON1bits.RXF10EN
  1253. #define RXFCON1_RXF11EN RXFCON1bits.RXF11EN
  1254. #define RXFCON1_RXF12EN RXFCON1bits.RXF12EN
  1255. #define RXFCON1_RXF13EN RXFCON1bits.RXF13EN
  1256. #define RXFCON1_RXF14EN RXFCON1bits.RXF14EN
  1257. #define RXFCON1_RXF15EN RXFCON1bits.RXF15EN
  1258. #define RXFBCON0_F0BP_0 RXFBCON0bits.F0BP_0
  1259. #define RXFBCON0_F0BP_1 RXFBCON0bits.F0BP_1
  1260. #define RXFBCON0_F0BP_2 RXFBCON0bits.F0BP_2
  1261. #define RXFBCON0_F0BP_3 RXFBCON0bits.F0BP_3
  1262. #define RXFBCON0_F1BP_0 RXFBCON0bits.F1BP_0
  1263. #define RXFBCON0_F1BP_1 RXFBCON0bits.F1BP_1
  1264. #define RXFBCON0_F1BP_2 RXFBCON0bits.F1BP_2
  1265. #define RXFBCON0_F1BP_3 RXFBCON0bits.F1BP_3
  1266. #define RXFBCON1_F2BP_0 RXFBCON1bits.F2BP_0
  1267. #define RXFBCON1_F2BP_1 RXFBCON1bits.F2BP_1
  1268. #define RXFBCON1_F2BP_2 RXFBCON1bits.F2BP_2
  1269. #define RXFBCON1_F2BP_3 RXFBCON1bits.F2BP_3
  1270. #define RXFBCON1_F3BP_0 RXFBCON1bits.F3BP_0
  1271. #define RXFBCON1_F3BP_1 RXFBCON1bits.F3BP_1
  1272. #define RXFBCON1_F3BP_2 RXFBCON1bits.F3BP_2
  1273. #define RXFBCON1_F3BP_3 RXFBCON1bits.F3BP_3
  1274. #define RXFBCON2_F4BP_0 RXFBCON2bits.F4BP_0
  1275. #define RXFBCON2_F4BP_1 RXFBCON2bits.F4BP_1
  1276. #define RXFBCON2_F4BP_2 RXFBCON2bits.F4BP_2
  1277. #define RXFBCON2_F4BP_3 RXFBCON2bits.F4BP_3
  1278. #define RXFBCON2_F5BP_0 RXFBCON2bits.F5BP_0
  1279. #define RXFBCON2_F5BP_1 RXFBCON2bits.F5BP_1
  1280. #define RXFBCON2_F5BP_2 RXFBCON2bits.F5BP_2
  1281. #define RXFBCON2_F5BP_3 RXFBCON2bits.F5BP_3
  1282. #define RXFBCON3_F6BP_0 RXFBCON3BITS.F6BP_0
  1283. #define RXFBCON3_F6BP_1 RXFBCON3BITS.F6BP_1
  1284. #define RXFBCON3_F6BP_2 RXFBCON3BITS.F6BP_2
  1285. #define RXFBCON3_F6BP_3 RXFBCON3BITS.F6BP_3
  1286. #define RXFBCON3_F7BP_0 RXFBCON3BITS.F7BP_0
  1287. #define RXFBCON3_F7BP_1 RXFBCON3BITS.F7BP_1
  1288. #define RXFBCON3_F7BP_2 RXFBCON3BITS.F7BP_2
  1289. #define RXFBCON3_F7BP_3 RXFBCON3BITS.F7BP_3
  1290. #define RXFBCON4_F8BP_0 RXFBCON4bits.F8BP_0
  1291. #define RXFBCON4_F8BP_1 RXFBCON4bits.F8BP_1
  1292. #define RXFBCON4_F8BP_2 RXFBCON4bits.F8BP_2
  1293. #define RXFBCON4_F8BP_3 RXFBCON4bits.F8BP_3
  1294. #define RXFBCON4_F9BP_0 RXFBCON4bits.F9BP_0
  1295. #define RXFBCON4_F9BP_1 RXFBCON4bits.F9BP_1
  1296. #define RXFBCON4_F9BP_2 RXFBCON4bits.F9BP_2
  1297. #define RXFBCON4_F9BP_3 RXFBCON4bits.F9BP_3
  1298. #define RXFBCON5_F10BP_0 RXFBCON5bits.F10BP_0
  1299. #define RXFBCON5_F10BP_1 RXFBCON5bits.F10BP_1
  1300. #define RXFBCON5_F10BP_2 RXFBCON5bits.F10BP_2
  1301. #define RXFBCON5_F10BP_3 RXFBCON5bits.F10BP_3
  1302. #define RXFBCON5_F11BP_0 RXFBCON5bits.F11BP_0
  1303. #define RXFBCON5_F11BP_1 RXFBCON5bits.F11BP_1
  1304. #define RXFBCON5_F11BP_2 RXFBCON5bits.F11BP_2
  1305. #define RXFBCON5_F11BP_3 RXFBCON5bits.F11BP_3
  1306. #define RXFBCON6_F12BP_0 RXFBCON6bits.F12BP_0
  1307. #define RXFBCON6_F12BP_1 RXFBCON6bits.F12BP_1
  1308. #define RXFBCON6_F12BP_2 RXFBCON6bits.F12BP_2
  1309. #define RXFBCON6_F12BP_3 RXFBCON6bits.F12BP_3
  1310. #define RXFBCON6_F13BP_0 RXFBCON6bits.F13BP_0
  1311. #define RXFBCON6_F13BP_1 RXFBCON6bits.F13BP_1
  1312. #define RXFBCON6_F13BP_2 RXFBCON6bits.F13BP_2
  1313. #define RXFBCON6_F13BP_3 RXFBCON6bits.F13BP_3
  1314. #define RXFBCON7_F14BP_0 RXFBCON7bits.F14BP_0
  1315. #define RXFBCON7_F14BP_1 RXFBCON7bits.F14BP_1
  1316. #define RXFBCON7_F14BP_2 RXFBCON7bits.F14BP_2
  1317. #define RXFBCON7_F14BP_3 RXFBCON7bits.F14BP_3
  1318. #define RXFBCON7_F15BP_0 RXFBCON7bits.F15BP_0
  1319. #define RXFBCON7_F15BP_1 RXFBCON7bits.F15BP_1
  1320. #define RXFBCON7_F15BP_2 RXFBCON7bits.F15BP_2
  1321. #define RXFBCON7_F15BP_3 RXFBCON7bits.F15BP_3
  1322. #define B0CON_TXREQ B0CONbits.TXREQ
  1323. #define B1CON_TXREQ B1CONbits.TXREQ
  1324. #define B2CON_TXREQ B2CONbits.TXREQ
  1325. #define B3CON_TXREQ B3CONbits.TXREQ
  1326. #define B4CON_TXREQ B4CONbits.TXREQ
  1327. #define B5CON_TXREQ B5CONbits.TXREQ
  1328. #define B0CON_RXM1 B0CONbits.RXM1
  1329. #define B1CON_RXM1 B1CONbits.RXM1
  1330. #define B2CON_RXM1 B2CONbits.RXM1
  1331. #define B3CON_RXM1 B3CONbits.RXM1
  1332. #define B4CON_RXM1 B4CONbits.RXM1
  1333. #define B5CON_RXM1 B5CONbits.RXM1
  1334. #define B0CON_RXFUL B0CONbits.RXFUL
  1335. #define B1CON_RXFUL B1CONbits.RXFUL
  1336. #define B2CON_RXFUL B2CONbits.RXFUL
  1337. #define B3CON_RXFUL B3CONbits.RXFUL
  1338. #define B4CON_RXFUL B4CONbits.RXFUL
  1339. #define B5CON_RXFUL B5CONbits.RXFUL
  1340. #define RXM0SIDL_EXIDEN RXM0SIDLbits.EXIDEN
  1341. #define RXM1SIDL_EXIDEN RXM1SIDLbits.EXIDEN
  1342. #define ECANCON_MDSEL1 ECANCONbits.MDSEL1
  1343. #define ECANCON_MDSEL0 ECANCONbits.MDSEL0
  1344. #endif
  1345. #if defined(HITECH_C18)
  1346. #define COMSTAT_TXB0 TXB0
  1347. #define COMSTAT_TXBP TXBP
  1348. #define COMSTAT_RXBP RXBP
  1349. #define CANCON_ABAT ABAT
  1350. #define RXB0CON_RXFUL RXB0FUL
  1351. #define TXB0CON_TXREQ TXB0REQ
  1352. #define RXB0CON_RXM1 RXB0M1
  1353. #define RXB0CON_RXM0 RXB0M0
  1354. #define BSEL0_B0TXEN B0TXEN // configure buffer in Transmit=1 or receive mode=0
  1355. #define BSEL0_B1TXEN B1TXEN
  1356. #define BSEL0_B2TXEN B2TXEN
  1357. #define BSEL0_B3TXEN B3TXEN
  1358. #define BSEL0_B4TXEN B4TXEN
  1359. #define BSEL0_B5TXEN B5TXEN
  1360. #define RXFCON0_RXF0EN RXF0EN
  1361. #define RXFCON0_RXF1EN RXF1EN
  1362. #define RXFCON0_RXF2EN RXF2EN
  1363. #define RXFCON0_RXF3EN RXF3EN
  1364. #define RXFCON0_RXF4EN RXF4EN
  1365. #define RXFCON0_RXF5EN RXF5EN
  1366. #define RXFCON0_RXF6EN RXF6EN
  1367. #define RXFCON0_RXF7EN RXF7EN
  1368. #define RXFCON1_RXF8EN XF8EN
  1369. #define RXFCON1_RXF9EN XF9EN
  1370. #define RXFCON1_RXF10EN RXF10EN
  1371. #define RXFCON1_RXF11EN RXF11EN
  1372. #define RXFCON1_RXF12EN RXF12EN
  1373. #define RXFCON1_RXF13EN RXF13EN
  1374. #define RXFCON1_RXF14EN RXF14EN
  1375. #define RXFCON1_RXF15EN RXF15EN
  1376. #define RXFBCON0_F0BP_0 F0BP_01
  1377. #define RXFBCON0_F0BP_1 F0BP_1
  1378. #define RXFBCON0_F0BP_2 F0BP_2
  1379. #define RXFBCON0_F0BP_3 F0BP_3
  1380. #define RXFBCON0_F1BP_0 F1BP_0
  1381. #define RXFBCON0_F1BP_1 F1BP_1
  1382. #define RXFBCON0_F1BP_2 F1BP_2
  1383. #define RXFBCON0_F1BP_3 F1BP_3
  1384. #define RXFBCON1_F2BP_0 F2BP_01
  1385. #define RXFBCON1_F2BP_1 F2BP_1
  1386. #define RXFBCON1_F2BP_2 F2BP_2
  1387. #define RXFBCON1_F2BP_3 F2BP_3
  1388. #define RXFBCON1_F3BP_0 F3BP_0
  1389. #define RXFBCON1_F3BP_1 F3BP_1
  1390. #define RXFBCON1_F3BP_2 F3BP_2
  1391. #define RXFBCON1_F3BP_3 F3BP_3
  1392. #define RXFBCON2_F4BP_0 F4BP_01
  1393. #define RXFBCON2_F4BP_1 F4BP_1
  1394. #define RXFBCON2_F4BP_2 F4BP_2
  1395. #define RXFBCON2_F4BP_3 F4BP_3
  1396. #define RXFBCON2_F5BP_0 F5BP_0
  1397. #define RXFBCON2_F5BP_1 F5BP_1
  1398. #define RXFBCON2_F5BP_2 F5BP_2
  1399. #define RXFBCON2_F5BP_3 F5BP_3
  1400. #define RXFBCON3_F6BP_0 F6BP_01
  1401. #define RXFBCON3_F6BP_1 F6BP_1
  1402. #define RXFBCON3_F6BP_2 F6BP_2
  1403. #define RXFBCON3_F6BP_3 F6BP_3
  1404. #define RXFBCON3_F7BP_0 F7BP_0
  1405. #define RXFBCON3_F7BP_1 F7BP_1
  1406. #define RXFBCON3_F7BP_2 F7BP_2
  1407. #define RXFBCON3_F7BP_3 F7BP_3
  1408. #define RXFBCON4_F8BP_0 F8BP_01
  1409. #define RXFBCON4_F8BP_1 F8BP_1
  1410. #define RXFBCON4_F8BP_2 F8BP_2
  1411. #define RXFBCON4_F8BP_3 F8BP_3
  1412. #define RXFBCON4_F9BP_0 F9BP_0
  1413. #define RXFBCON4_F9BP_1 F9BP_1
  1414. #define RXFBCON4_F9BP_2 F9BP_2
  1415. #define RXFBCON4_F9BP_3 F9BP_3
  1416. #define RXFBCON5_F10BP_0 F10BP_01
  1417. #define RXFBCON5_F10BP_1 F10BP_1
  1418. #define RXFBCON5_F10BP_2 F10BP_2
  1419. #define RXFBCON5_F10BP_3 F10BP_3
  1420. #define RXFBCON5_F11BP_0 F11BP_0
  1421. #define RXFBCON5_F11BP_1 F11BP_1
  1422. #define RXFBCON5_F11BP_2 F11BP_2
  1423. #define RXFBCON5_F11BP_3 F11BP_3
  1424. #define RXFBCON6_F12BP_0 F12BP_01
  1425. #define RXFBCON6_F12BP_1 F12BP_1
  1426. #define RXFBCON6_F12BP_2 F12BP_2
  1427. #define RXFBCON6_F12BP_3 F12BP_3
  1428. #define RXFBCON6_F13BP_0 F13BP_0
  1429. #define RXFBCON6_F13BP_1 F13BP_1
  1430. #define RXFBCON6_F13BP_2 F13BP_2
  1431. #define RXFBCON6_F13BP_3 F13BP_3
  1432. #define RXFBCON7_F14BP_0 F14BP_01
  1433. #define RXFBCON7_F14BP_1 F14BP_1
  1434. #define RXFBCON7_F14BP_2 F14BP_2
  1435. #define RXFBCON7_F14BP_3 F14BP_3
  1436. #define RXFBCON7_F15BP_0 F15BP_0
  1437. #define RXFBCON7_F15BP_1 F15BP_1
  1438. #define RXFBCON7_F15BP_2 F15BP_2
  1439. #define RXFBCON7_F15BP_3 F15BP_3
  1440. #define B0CON_TXREQ B0TXREQ
  1441. #define B1CON_TXREQ B1TXREQ
  1442. #define B2CON_TXREQ B2TXREQ
  1443. #define B3CON_TXREQ B3TXREQ
  1444. #define B4CON_TXREQ B4TXREQ
  1445. #define B5CON_TXREQ B5TXREQ
  1446. #define B0CON_RXFUL B0RXFUL
  1447. #define B1CON_RXFUL B1RXFUL
  1448. #define B2CON_RXFUL B2RXFUL
  1449. #define B3CON_RXFUL B3RXFUL
  1450. #define B4CON_RXFUL B4RXFUL
  1451. #define B5CON_RXFUL B5RXFUL
  1452. #define B0CON_RXM1 B0RXM1
  1453. #define B1CON_RXM1 B1RXM1
  1454. #define B2CON_RXM1 B2RXM1
  1455. #define B3CON_RXM1 B3RXM1
  1456. #define B4CON_RXM1 B4RXM1
  1457. #define B5CON_RXM1 B5RXM1
  1458. /*
  1459. * Following are special defs to overcome compiler problem
  1460. * at the time of this re-write.
  1461. * Set following line to "#if 0" after verifiying correct
  1462. * compiler behavior.
  1463. */
  1464. #if 1
  1465. static struct
  1466. {
  1467. unsigned : 7;
  1468. unsigned RXFUL : 1;
  1469. } RXB1CONbits @ 0xf50;
  1470. #define RXB1CON_RXFUL RXB1CONbits.RXFUL
  1471. static struct
  1472. {
  1473. unsigned TXPRI0:1;
  1474. unsigned TXPRI1:1;
  1475. unsigned :1;
  1476. unsigned TXREQ:1;
  1477. unsigned TXERR:1;
  1478. unsigned TXLARB:1;
  1479. unsigned TXABT:1;
  1480. } TXB1CONbits @ 0xf30;
  1481. #define TXB1CON_TXREQ TXB1CONbits.TXREQ
  1482. static struct
  1483. {
  1484. unsigned TXPRI0:1;
  1485. unsigned TXPRI1:1;
  1486. unsigned :1;
  1487. unsigned TXREQ:1;
  1488. unsigned TXERR:1;
  1489. unsigned TXLARB:1;
  1490. unsigned TXABT:1;
  1491. } TXB2CONbits @ 0xf20;
  1492. #define TXB2CON_TXREQ TXB2CONbits.TXREQ
  1493. #else
  1494. #define RXB1CON_RXFUL RXB1RXFUL
  1495. #define TXB1CON_TXREQ TXB1REQ
  1496. #define TXB2CON_TXREQ TXB2REQ
  1497. #endif
  1498. #define RXM0SIDL_EXIDEN RXM0EXIDM
  1499. #define RXM1SIDL_EXIDEN RXM1EXIDEN
  1500. #define ECANCON_MDSEL1 MDSEL1
  1501. #define ECANCON_MDSEL0 MDSEL0
  1502. #define COMSTAT_FIFOEMPTY FIFOEMPTY
  1503. #define COMSTAT_RXBnOVFL RXB1OVFL
  1504. #define COMSTAT_RXB0OVFL RXB0OVFL
  1505. #define COMSTAT_RXB1OVFL RXB1OVFL
  1506. #define BRGCON2_SEG2PHTS SEG2PHT
  1507. #define BRGCON2_SAM SAM
  1508. #define BRGCON3_WAKDIS WAKDIS
  1509. #define BRGCON3_WAKFIL WAKFIL
  1510. #define CIOCON_ENDRHI ENDRHI
  1511. #define CIOCON_CANCAP CANCAP
  1512. #define PIR3_RXBnIF RXB1IF
  1513. #define PIR3_IRXIF IRXIF
  1514. #define PIR3_RXB0IF RXB0IF
  1515. #define PIR3_RXB1IF RXB1IF
  1516. #define RXB0CON_FILHIT0 RXB0FILHIT0
  1517. #define RXB0CON_RXB0DBEN RXBODBEN
  1518. static volatile near bit RXBODBEN @ ((unsigned)&RXB0CON*8)+2;
  1519. #endif
  1520. #endif