pic24_ecan.c

00001 /*
00002  * "Copyright (c) 2008 Robert B. Reese, Bryan A. Jones, J. W. Bruce ("AUTHORS")"
00003  * All rights reserved.
00004  * (R. Reese, reese_AT_ece.msstate.edu, Mississippi State University)
00005  * (B. A. Jones, bjones_AT_ece.msstate.edu, Mississippi State University)
00006  * (J. W. Bruce, jwbruce_AT_ece.msstate.edu, Mississippi State University)
00007  *
00008  * Permission to use, copy, modify, and distribute this software and its
00009  * documentation for any purpose, without fee, and without written agreement is
00010  * hereby granted, provided that the above copyright notice, the following
00011  * two paragraphs and the authors appear in all copies of this software.
00012  *
00013  * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR
00014  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
00015  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS"
00016  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00017  *
00018  * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES,
00019  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
00020  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
00021  * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO
00022  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
00023  *
00024  * Please maintain this header in its entirety when copying/modifying
00025  * these files.
00026  *
00027  *
00028  */
00029 
00030 #include "pic24_all.h"
00031 #include <stdio.h>   //for NULL definition
00032 
00033 // Only include if this module exists.
00034 #if (NUM_ECAN_MODS >= 1)
00035 
00036 
00037 // Documentation for this file. If the \file tag is not present,
00038 // this file will not be documented.
00039 // Note: place this comment below the #if NUM_ECAN_MODS so Doxygen
00040 // will only see it once.
00047 #ifndef ECAN_1TIME_CODE_DEFS
00048 
00057 void formatStandardDataFrameECAN (ECANMSG* p_ecanmsg, uint16 u16_id, uint8 u8_len){
00058  p_ecanmsg->w0.IDE = 0;
00059  p_ecanmsg->w0.SRR = 0;
00060  p_ecanmsg->w0.SID = u16_id;
00061  p_ecanmsg->w1.EID17_6 = 0;
00062  p_ecanmsg->w2.EID5_0 = 0;
00063  p_ecanmsg->w2.RTR = 0;
00064  p_ecanmsg->w2.RB1 = 0;
00065  p_ecanmsg->w2.RB0 = 0;
00066  p_ecanmsg->w2.DLC = u8_len;     //length of the message
00067 }
00068 
00069 
00077 void formatExtendedDataFrameECAN (ECANMSG* p_ecanmsg, uint32 u32_id, uint8 u8_len){
00078   
00079  p_ecanmsg->w0.IDE = 1;
00080  p_ecanmsg->w0.SRR = 0;
00081  p_ecanmsg->w0.SID =  (u32_id >> 18) & 0x7FF;
00082  p_ecanmsg->w1.EID17_6 = (u32_id >> 6) & 0xFFF;
00083  p_ecanmsg->w2.EID5_0 = u32_id & 0x3F;
00084  p_ecanmsg->w2.RTR = 0;
00085  p_ecanmsg->w2.RB1 = 0;
00086  p_ecanmsg->w2.RB0 = 0;
00087  p_ecanmsg->w2.DLC = u8_len;   //length of the message
00088 }
00089 
00096 uint32 getIdExtendedDataFrameECAN (ECANMSG* p_ecanmsg){
00097   uint32 u32_id, u32_tmp;
00098   u32_tmp = p_ecanmsg->w0.SID;
00099   u32_id = u32_tmp << 18;
00100   u32_tmp = p_ecanmsg->w1.EID17_6;
00101   u32_id = u32_id | (u32_tmp << 6) | p_ecanmsg->w2.EID5_0; 
00102   return u32_id;
00103 }
00104 
00105 #define ECAN_1TIME_CODE_DEFS
00106 #endif
00107 
00108 
00109 
00115 void clrRxFullFlagECAN1(uint8 u8_bufNum) {
00116   u8_bufNum &= 0x1F; //0-31
00117   if (u8_bufNum > 15) {
00118        u8_bufNum = u8_bufNum - 16;
00119        C1RXFUL2 = C1RXFUL2 & ~(1<<u8_bufNum);
00120   } else {
00121       C1RXFUL1 = C1RXFUL1 & ~(1<<u8_bufNum);
00122   }  
00123 } 
00124 
00130 uint8 getRxFullFlagECAN1(uint8 u8_bufNum) {
00131   u8_bufNum &= 0x1F; //0-31
00132   if (u8_bufNum > 15) {
00133        u8_bufNum = u8_bufNum - 16;
00134        return(C1RXFUL2 & (1<<u8_bufNum));
00135   } else {
00136        return(C1RXFUL1 & (1<<u8_bufNum));
00137   }  
00138 } 
00139 
00143 void clrRxFullOvfFlagsECAN1(void) {
00144   C1RXFUL1=0x0000;
00145   C1RXFUL2=0x0000;
00146   C1RXOVF1=0x0000;
00147   C1RXOVF2=0x0000;
00148 }
00149 
00156 void configTxRxBufferECAN1(uint8 u8_bufNum, uint8 u8_type, uint8 u8_priority ) {
00157   u8_bufNum &= 0x07; //0-7
00158   switch (u8_bufNum) {
00159     case 0:  C1TR01CONbits.TXEN0 = u8_type; 
00160              C1TR01CONbits.TX0PRI = u8_priority;
00161              break;
00162     case 1:  C1TR01CONbits.TXEN1 = u8_type; 
00163              C1TR01CONbits.TX1PRI = u8_priority;
00164              break;
00165     case 2:  C1TR23CONbits.TXEN2 = u8_type; 
00166              C1TR23CONbits.TX2PRI = u8_priority;
00167              break;
00168     case 3:  C1TR23CONbits.TXEN3 = u8_type; 
00169              C1TR23CONbits.TX3PRI = u8_priority;
00170              break;
00171     case 4:  C1TR45CONbits.TXEN4 = u8_type; 
00172              C1TR45CONbits.TX4PRI = u8_priority;
00173              break;
00174     case 5:  C1TR45CONbits.TXEN5 = u8_type; 
00175              C1TR45CONbits.TX5PRI = u8_priority;
00176              break;
00177     case 6:  C1TR67CONbits.TXEN6 = u8_type; 
00178              C1TR67CONbits.TX6PRI = u8_priority;
00179              break;
00180     default:  C1TR67CONbits.TXEN7 = u8_type; 
00181              C1TR67CONbits.TX7PRI = u8_priority;
00182              break;
00183   }
00184 }
00185 
00190 void startTxECAN1(uint8 u8_bufNum) {
00191   u8_bufNum &= 0x07; //0-7
00192   switch (u8_bufNum) {
00193     case 0:  C1TR01CONbits.TXREQ0 = 1; break;
00194     case 1:  C1TR01CONbits.TXREQ1 = 1; break;
00195     case 2:  C1TR23CONbits.TXREQ2 = 1; break;
00196     case 3:  C1TR23CONbits.TXREQ3 = 1; break;
00197     case 4:  C1TR45CONbits.TXREQ4 = 1;; break;
00198     case 5:  C1TR45CONbits.TXREQ5 = 1; break;
00199     case 6:  C1TR67CONbits.TXREQ6 = 1;  break;
00200     default:  C1TR67CONbits.TXREQ7 = 1; break;
00201   }
00202 }
00203 
00208 uint8 getTxInProgressECAN1(uint8 u8_bufNum) {
00209   u8_bufNum &= 0x07; //0-7
00210   switch (u8_bufNum) {
00211     case 0:  return(C1TR01CONbits.TXREQ0);
00212     case 1:  return(C1TR01CONbits.TXREQ1);
00213     case 2:  return(C1TR23CONbits.TXREQ2);
00214     case 3:  return(C1TR23CONbits.TXREQ3);
00215     case 4:  return(C1TR45CONbits.TXREQ4);
00216     case 5:  return(C1TR45CONbits.TXREQ5);
00217     case 6:  return(C1TR67CONbits.TXREQ6);
00218     default:  return(C1TR67CONbits.TXREQ7);
00219   }
00220 }
00221 
00222  
00223 
00224 
00233 void configRxFilterECAN1(uint8 u8_filtNum, uint32 u32_id, uint8 u8_idType, uint8 u8_bufnum, uint8 u8_maskReg) {
00234  uint16 *pu16_CxRXFySID,*pu16_CxRXFyEID, *pu16_CxFMSKSEL1, *pu16_CxBUFPNT1;
00235  uint16 u16_sid;
00236  uint16 u16_eid15_0;
00237  uint16 u16_eid17_16;
00238  uint16 u16_mask;
00239  uint8 u8_startPos;
00240 
00241  u8_filtNum &= 0xF;  //0-15
00242  u8_bufnum &= 0xF;   //0-15
00243  u8_maskReg &= 0x07;    //0-7
00244    
00245  pu16_CxRXFySID =  (uint16*) &C1RXF0SID + (u8_filtNum << 1);
00246  pu16_CxRXFyEID = pu16_CxRXFySID + 1;
00247  pu16_CxFMSKSEL1 = (uint16*) &C1FMSKSEL1 + (u8_filtNum >> 3);
00248  pu16_CxBUFPNT1 = (uint16*) &C1BUFPNT1 + (u8_filtNum >> 2);
00249  
00250  C1CTRL1bits.WIN=1;  //select filter register window
00251 
00252  //write to the CxRXFySID, CxRXFyEID registers 
00253  if(u8_idType) { // EID    
00254    u16_sid = (u32_id >> 18) & 0x7FF;
00255    u16_eid17_16 = (u32_id >>16) & 0x3;
00256    u16_eid15_0 = u32_id & 0xFFFF; 
00257    *pu16_CxRXFySID =(u16_sid <<5) | ECAN_MATCH_EID |  u16_eid17_16;     
00258    *pu16_CxRXFyEID = u16_eid15_0;                                           
00259   } else  {   //SID
00260     u16_sid = u32_id  & 0x7FF;
00261         *pu16_CxRXFySID = u16_sid <<5;   
00262         *pu16_CxRXFyEID = 0;             
00263   }
00264 
00265  //point the filter to the RX buffer (modify CxBUFPNT1 register)
00266  u8_startPos = 4 * (u8_filtNum & 0x3);  //starting bit position to mask
00267  u16_mask = ~ ( 0xF << u8_startPos);
00268  *pu16_CxBUFPNT1 = (*pu16_CxBUFPNT1 & u16_mask) | (u8_bufnum << u8_startPos);
00269 
00270  //point the filter to the mask register (modify CxFMSKSEL1 register)
00271  u8_startPos = 2 * (u8_filtNum & 0x7);
00272  u16_mask = ~ ( 0x3 << u8_startPos);
00273  *pu16_CxFMSKSEL1 = (*pu16_CxFMSKSEL1 & u16_mask) | (u8_maskReg << u8_startPos);
00274 
00275  C1FEN1 = C1FEN1 | (1 << u8_filtNum) ; // Enable the filter
00276 
00277  C1CTRL1bits.WIN=0; 
00278 
00279 }
00280 
00291 void configRxMaskECAN1(uint8 u8_maskNum, uint32 u32_idMask, uint8 u8_idType, uint8 u8_matchType){
00292 uint16 *pu16_CxRXMySID,*pu16_CxRXMyEID;
00293 uint16 u16_msid;
00294 uint16 u16_meid15_0;
00295 uint16 u16_meid17_16;
00296 
00297 pu16_CxRXMySID =(uint16*) &C1RXM0SID + (u8_maskNum << 1);
00298 pu16_CxRXMyEID = pu16_CxRXMySID + 1;
00299 
00300 C1CTRL1bits.WIN=1;  //select filter register window
00301 
00302  //write to the CxRXMySID, CxRXMyEID registers 
00303  if(u8_idType) { // EID  
00304    u16_msid = (u32_idMask >> 18) & 0x7FF;
00305    u16_meid17_16 = (u32_idMask >>16) & 0x3;
00306    u16_meid15_0 = u32_idMask & 0xFFFF; 
00307    if (u8_matchType) *pu16_CxRXMySID =(u16_msid <<5) | ECAN_MATCH_EID |  u16_meid17_16; 
00308     else *pu16_CxRXMySID =(u16_msid <<5) |   u16_meid17_16;
00309    *pu16_CxRXMyEID = u16_meid15_0;
00310  } else {
00311    u16_msid = u32_idMask  & 0x7FF;
00312    if (u8_matchType) *pu16_CxRXMySID = (u16_msid <<5) | ECAN_MATCH_EID ;   
00313    else  *pu16_CxRXMySID = (u16_msid <<5);
00314    *pu16_CxRXMyEID = 0;
00315  }   
00316 C1CTRL1bits.WIN=0; 
00317 }
00318 
00319 #endif // #if (NUM_ECAN_MODS >= ${x})
00320 
00321 
00322 
00323 
00324 
00325 
00326 
00327 
00328 
00329 
00330 
00331 
00332 
00333 /*
00334  * "Copyright (c) 2008 Robert B. Reese, Bryan A. Jones, J. W. Bruce ("AUTHORS")"
00335  * All rights reserved.
00336  * (R. Reese, reese_AT_ece.msstate.edu, Mississippi State University)
00337  * (B. A. Jones, bjones_AT_ece.msstate.edu, Mississippi State University)
00338  * (J. W. Bruce, jwbruce_AT_ece.msstate.edu, Mississippi State University)
00339  *
00340  * Permission to use, copy, modify, and distribute this software and its
00341  * documentation for any purpose, without fee, and without written agreement is
00342  * hereby granted, provided that the above copyright notice, the following
00343  * two paragraphs and the authors appear in all copies of this software.
00344  *
00345  * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR
00346  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
00347  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS"
00348  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00349  *
00350  * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES,
00351  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
00352  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
00353  * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO
00354  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
00355  *
00356  * Please maintain this header in its entirety when copying/modifying
00357  * these files.
00358  *
00359  *
00360  */
00361 
00362 #include "pic24_all.h"
00363 #include <stdio.h>   //for NULL definition
00364 
00365 // Only include if this module exists.
00366 #if (NUM_ECAN_MODS >= 2)
00367 
00368 
00369 // Documentation for this file. If the \file tag is not present,
00370 // this file will not be documented.
00371 // Note: place this comment below the #if NUM_ECAN_MODS so Doxygen
00372 // will only see it once.
00379 #ifndef ECAN_1TIME_CODE_DEFS
00380 
00389 void formatStandardDataFrameECAN (ECANMSG* p_ecanmsg, uint16 u16_id, uint8 u8_len){
00390  p_ecanmsg->w0.IDE = 0;
00391  p_ecanmsg->w0.SRR = 0;
00392  p_ecanmsg->w0.SID = u16_id;
00393  p_ecanmsg->w1.EID17_6 = 0;
00394  p_ecanmsg->w2.EID5_0 = 0;
00395  p_ecanmsg->w2.RTR = 0;
00396  p_ecanmsg->w2.RB1 = 0;
00397  p_ecanmsg->w2.RB0 = 0;
00398  p_ecanmsg->w2.DLC = u8_len;     //length of the message
00399 }
00400 
00401 
00409 void formatExtendedDataFrameECAN (ECANMSG* p_ecanmsg, uint32 u32_id, uint8 u8_len){
00410   
00411  p_ecanmsg->w0.IDE = 1;
00412  p_ecanmsg->w0.SRR = 0;
00413  p_ecanmsg->w0.SID =  (u32_id >> 18) & 0x7FF;
00414  p_ecanmsg->w1.EID17_6 = (u32_id >> 6) & 0xFFF;
00415  p_ecanmsg->w2.EID5_0 = u32_id & 0x3F;
00416  p_ecanmsg->w2.RTR = 0;
00417  p_ecanmsg->w2.RB1 = 0;
00418  p_ecanmsg->w2.RB0 = 0;
00419  p_ecanmsg->w2.DLC = u8_len;   //length of the message
00420 }
00421 
00428 uint32 getIdExtendedDataFrameECAN (ECANMSG* p_ecanmsg){
00429   uint32 u32_id, u32_tmp;
00430   u32_tmp = p_ecanmsg->w0.SID;
00431   u32_id = u32_tmp << 18;
00432   u32_tmp = p_ecanmsg->w1.EID17_6;
00433   u32_id = u32_id | (u32_tmp << 6) | p_ecanmsg->w2.EID5_0; 
00434   return u32_id;
00435 }
00436 
00437 #define ECAN_1TIME_CODE_DEFS
00438 #endif
00439 
00440 
00441 
00447 void clrRxFullFlagECAN2(uint8 u8_bufNum) {
00448   u8_bufNum &= 0x1F; //0-31
00449   if (u8_bufNum > 15) {
00450        u8_bufNum = u8_bufNum - 16;
00451        C2RXFUL2 = C2RXFUL2 & ~(1<<u8_bufNum);
00452   } else {
00453       C2RXFUL1 = C2RXFUL1 & ~(1<<u8_bufNum);
00454   }  
00455 } 
00456 
00462 uint8 getRxFullFlagECAN2(uint8 u8_bufNum) {
00463   u8_bufNum &= 0x1F; //0-31
00464   if (u8_bufNum > 15) {
00465        u8_bufNum = u8_bufNum - 16;
00466        return(C2RXFUL2 & (1<<u8_bufNum));
00467   } else {
00468        return(C2RXFUL1 & (1<<u8_bufNum));
00469   }  
00470 } 
00471 
00475 void clrRxFullOvfFlagsECAN2(void) {
00476   C2RXFUL1=0x0000;
00477   C2RXFUL2=0x0000;
00478   C2RXOVF1=0x0000;
00479   C2RXOVF2=0x0000;
00480 }
00481 
00488 void configTxRxBufferECAN2(uint8 u8_bufNum, uint8 u8_type, uint8 u8_priority ) {
00489   u8_bufNum &= 0x07; //0-7
00490   switch (u8_bufNum) {
00491     case 0:  C2TR01CONbits.TXEN0 = u8_type; 
00492              C2TR01CONbits.TX0PRI = u8_priority;
00493              break;
00494     case 1:  C2TR01CONbits.TXEN1 = u8_type; 
00495              C2TR01CONbits.TX1PRI = u8_priority;
00496              break;
00497     case 2:  C2TR23CONbits.TXEN2 = u8_type; 
00498              C2TR23CONbits.TX2PRI = u8_priority;
00499              break;
00500     case 3:  C2TR23CONbits.TXEN3 = u8_type; 
00501              C2TR23CONbits.TX3PRI = u8_priority;
00502              break;
00503     case 4:  C2TR45CONbits.TXEN4 = u8_type; 
00504              C2TR45CONbits.TX4PRI = u8_priority;
00505              break;
00506     case 5:  C2TR45CONbits.TXEN5 = u8_type; 
00507              C2TR45CONbits.TX5PRI = u8_priority;
00508              break;
00509     case 6:  C2TR67CONbits.TXEN6 = u8_type; 
00510              C2TR67CONbits.TX6PRI = u8_priority;
00511              break;
00512     default:  C2TR67CONbits.TXEN7 = u8_type; 
00513              C2TR67CONbits.TX7PRI = u8_priority;
00514              break;
00515   }
00516 }
00517 
00522 void startTxECAN2(uint8 u8_bufNum) {
00523   u8_bufNum &= 0x07; //0-7
00524   switch (u8_bufNum) {
00525     case 0:  C2TR01CONbits.TXREQ0 = 1; break;
00526     case 1:  C2TR01CONbits.TXREQ1 = 1; break;
00527     case 2:  C2TR23CONbits.TXREQ2 = 1; break;
00528     case 3:  C2TR23CONbits.TXREQ3 = 1; break;
00529     case 4:  C2TR45CONbits.TXREQ4 = 1;; break;
00530     case 5:  C2TR45CONbits.TXREQ5 = 1; break;
00531     case 6:  C2TR67CONbits.TXREQ6 = 1;  break;
00532     default:  C2TR67CONbits.TXREQ7 = 1; break;
00533   }
00534 }
00535 
00540 uint8 getTxInProgressECAN2(uint8 u8_bufNum) {
00541   u8_bufNum &= 0x07; //0-7
00542   switch (u8_bufNum) {
00543     case 0:  return(C2TR01CONbits.TXREQ0);
00544     case 1:  return(C2TR01CONbits.TXREQ1);
00545     case 2:  return(C2TR23CONbits.TXREQ2);
00546     case 3:  return(C2TR23CONbits.TXREQ3);
00547     case 4:  return(C2TR45CONbits.TXREQ4);
00548     case 5:  return(C2TR45CONbits.TXREQ5);
00549     case 6:  return(C2TR67CONbits.TXREQ6);
00550     default:  return(C2TR67CONbits.TXREQ7);
00551   }
00552 }
00553 
00554  
00555 
00556 
00565 void configRxFilterECAN2(uint8 u8_filtNum, uint32 u32_id, uint8 u8_idType, uint8 u8_bufnum, uint8 u8_maskReg) {
00566  uint16 *pu16_CxRXFySID,*pu16_CxRXFyEID, *pu16_CxFMSKSEL1, *pu16_CxBUFPNT1;
00567  uint16 u16_sid;
00568  uint16 u16_eid15_0;
00569  uint16 u16_eid17_16;
00570  uint16 u16_mask;
00571  uint8 u8_startPos;
00572 
00573  u8_filtNum &= 0xF;  //0-15
00574  u8_bufnum &= 0xF;   //0-15
00575  u8_maskReg &= 0x07;    //0-7
00576    
00577  pu16_CxRXFySID =  (uint16*) &C2RXF0SID + (u8_filtNum << 1);
00578  pu16_CxRXFyEID = pu16_CxRXFySID + 1;
00579  pu16_CxFMSKSEL1 = (uint16*) &C2FMSKSEL1 + (u8_filtNum >> 3);
00580  pu16_CxBUFPNT1 = (uint16*) &C2BUFPNT1 + (u8_filtNum >> 2);
00581  
00582  C2CTRL1bits.WIN=1;  //select filter register window
00583 
00584  //write to the CxRXFySID, CxRXFyEID registers 
00585  if(u8_idType) { // EID    
00586    u16_sid = (u32_id >> 18) & 0x7FF;
00587    u16_eid17_16 = (u32_id >>16) & 0x3;
00588    u16_eid15_0 = u32_id & 0xFFFF; 
00589    *pu16_CxRXFySID =(u16_sid <<5) | ECAN_MATCH_EID |  u16_eid17_16;     
00590    *pu16_CxRXFyEID = u16_eid15_0;                                           
00591   } else  {   //SID
00592     u16_sid = u32_id  & 0x7FF;
00593         *pu16_CxRXFySID = u16_sid <<5;   
00594         *pu16_CxRXFyEID = 0;             
00595   }
00596 
00597  //point the filter to the RX buffer (modify CxBUFPNT1 register)
00598  u8_startPos = 4 * (u8_filtNum & 0x3);  //starting bit position to mask
00599  u16_mask = ~ ( 0xF << u8_startPos);
00600  *pu16_CxBUFPNT1 = (*pu16_CxBUFPNT1 & u16_mask) | (u8_bufnum << u8_startPos);
00601 
00602  //point the filter to the mask register (modify CxFMSKSEL1 register)
00603  u8_startPos = 2 * (u8_filtNum & 0x7);
00604  u16_mask = ~ ( 0x3 << u8_startPos);
00605  *pu16_CxFMSKSEL1 = (*pu16_CxFMSKSEL1 & u16_mask) | (u8_maskReg << u8_startPos);
00606 
00607  C2FEN1 = C2FEN1 | (1 << u8_filtNum) ; // Enable the filter
00608 
00609  C2CTRL1bits.WIN=0; 
00610 
00611 }
00612 
00623 void configRxMaskECAN2(uint8 u8_maskNum, uint32 u32_idMask, uint8 u8_idType, uint8 u8_matchType){
00624 uint16 *pu16_CxRXMySID,*pu16_CxRXMyEID;
00625 uint16 u16_msid;
00626 uint16 u16_meid15_0;
00627 uint16 u16_meid17_16;
00628 
00629 pu16_CxRXMySID =(uint16*) &C2RXM0SID + (u8_maskNum << 1);
00630 pu16_CxRXMyEID = pu16_CxRXMySID + 1;
00631 
00632 C2CTRL1bits.WIN=1;  //select filter register window
00633 
00634  //write to the CxRXMySID, CxRXMyEID registers 
00635  if(u8_idType) { // EID  
00636    u16_msid = (u32_idMask >> 18) & 0x7FF;
00637    u16_meid17_16 = (u32_idMask >>16) & 0x3;
00638    u16_meid15_0 = u32_idMask & 0xFFFF; 
00639    if (u8_matchType) *pu16_CxRXMySID =(u16_msid <<5) | ECAN_MATCH_EID |  u16_meid17_16; 
00640     else *pu16_CxRXMySID =(u16_msid <<5) |   u16_meid17_16;
00641    *pu16_CxRXMyEID = u16_meid15_0;
00642  } else {
00643    u16_msid = u32_idMask  & 0x7FF;
00644    if (u8_matchType) *pu16_CxRXMySID = (u16_msid <<5) | ECAN_MATCH_EID ;   
00645    else  *pu16_CxRXMySID = (u16_msid <<5);
00646    *pu16_CxRXMyEID = 0;
00647  }   
00648 C2CTRL1bits.WIN=0; 
00649 }
00650 
00651 #endif // #if (NUM_ECAN_MODS >= ${x})
00652 
00653 
00654 
00655 
00656 
00657 
00658 
00659 
00660 
00661 
00662 
00663 
00664 

Generated on Mon Oct 18 07:40:46 2010 for Python-on-a-chip by  doxygen 1.5.9