can_isr.c

00001 #include <includes.h>
00002 
00003 unsigned long can_elapsed_ms = 0;   // CAN module time variable
00004 
00005 // CAN error global variables:
00006 volatile unsigned long can_error_1 = 0;
00007 volatile unsigned long can_error_2 = 0;
00008 volatile unsigned long can_error_3 = 0;
00009 volatile unsigned long can_error_4 = 0;
00010 
00011 unsigned short can_get_error_1(CAN_FRAME * frame)
00012 {
00013   frame->payload.w.w1 = can_error_1;
00014   can_error_1 = 0;     //Reset error
00015   frame->payload.w.w2 = can_elapsed_ms;
00016   return 0;
00017 }
00018 
00019 unsigned short can_get_error_2(CAN_FRAME * frame)
00020 {
00021   frame->payload.w.w1 = can_error_2;
00022   can_error_2 = 0;     //Reset error
00023   frame->payload.w.w2 = can_elapsed_ms;
00024   return 0;
00025 }
00026 
00027 unsigned short can_get_error_3(CAN_FRAME * frame)
00028 {
00029   frame->payload.w.w1 = can_error_3;
00030   can_error_3 = 0;     //Reset error
00031   frame->payload.w.w2 = can_elapsed_ms;
00032   return 0;
00033 }
00034 
00035 unsigned short can_get_error_4(CAN_FRAME * frame)
00036 {
00037   frame->payload.w.w1 = can_error_4;
00038   can_error_4 = 0;     //Reset error
00039   frame->payload.w.w2 = can_elapsed_ms;
00040   return 0;
00041 }
00042 
00043 // CAN receive frame count global variables:
00044 extern volatile unsigned short can_rx_frame_count_1;
00045 extern volatile unsigned short can_rx_frame_count_2;
00046 extern volatile unsigned short can_rx_frame_count_3;
00047 extern volatile unsigned short can_rx_frame_count_4;
00048 
00049 /*
00050 // CAN error storage ring buffer, non-ISR
00051 const unsigned short can_error_buffer_size = 10;
00052 unsigned short can_error_type_buffer[can_error_buffer_size];
00053 unsigned short can_error_freq_buffer[can_error_buffer_size];
00054 unsigned long can_error_time_buffer[can_error_buffer_size];
00055 unsigned short can_error_write_index = 0; // when write_index = read_index, no errors.
00056 unsigned short can_error_read_index = 0;
00057 
00058 // CAN error storage ring buffer, IRQ
00059 const unsigned short can_error_irq_buffer_size = 10;
00060 unsigned short can_error_type_irq_buffer[can_error_buffer_size];
00061 unsigned short can_error_freq_irq_buffer[can_error_buffer_size];
00062 unsigned long can_error_time_irq_buffer[can_error_buffer_size];
00063 unsigned short can_error_write_irq_index = 0; // when write_index = read_index, no errors.
00064 unsigned short can_error_read_irq_index = 0;
00065 
00067 unsigned short can_get_error(CAN_FRAME * frame_ptr)
00068 {
00069   static unsigned short irq_first = 0;
00070 
00071   if (irq_first) //Check first the IRQ buffer for errors, then the normal buffer
00072   {
00073     irq_first = 0;  // Toggle irq_first value, so both buffers have a chance to be read eventually
00074     if (!can_error_irq_pop(frame_ptr))
00075     {
00076       return 0; // Error data popped from buffer successfully
00077     }
00078     if (!can_error_pop(frame_ptr))
00079     {
00080       return 0; // Error data popped from buffer successfully
00081     }
00082   }
00083   else  //Check first the normal buffer for errors, then the IRQ buffer
00084   {
00085     irq_first = 1;  // Toggle irq_first value, so both buffers have a chance to be read eventually
00086     if (!can_error_pop(frame_ptr))
00087     {
00088       return 0; // Error data popped from buffer successfully
00089     }
00090     if (!can_error_irq_pop(frame_ptr))
00091     {
00092       return 0; // Error data popped from buffer successfully
00093     }
00094   }
00095 
00096   return 1; // No error data in buffers
00097 }
00099 
00101 unsigned short can_error_irq_pop(CAN_FRAME * frame)
00102 {
00103   if (can_error_read_irq_index != can_error_write_irq_index)
00104   {
00105     frame->payload.w.w1 = can_error_type_irq_buffer[can_error_read_irq_index];       // Start with the basic ERROR_ID
00106     frame->payload.w.w1 |= (can_error_freq_irq_buffer[can_error_read_irq_index] & 0xFF) << 13;  // OR in the frequency value
00107     frame->payload.w.w2 = can_error_time_irq_buffer[can_error_read_irq_index];  // Include timestamp of error
00108 
00109     //advance error ring buffer read index
00110     if (can_error_read_irq_index >= (can_error_irq_buffer_size - 1))
00111     {
00112       can_error_read_irq_index = 0;  // wrap around to zero
00113     }
00114     else
00115     {
00116       ++can_error_read_irq_index; // increment
00117     }
00118     return 0; // Error data popped from buffer successfully
00119   }
00120   return 1; // No error data in ring buffer
00121 }
00123 
00125 unsigned short can_error_pop(CAN_FRAME * frame)
00126 {
00127   if (can_error_read_index != can_error_write_index)
00128   {
00129     frame->payload.w.w1 = can_error_type_buffer[can_error_read_index];       // Start with the basic ERROR_ID
00130     frame->payload.w.w1 |= (can_error_freq_buffer[can_error_read_index] & 0xFF) << 13;  // OR in the frequency value
00131     frame->payload.w.w2 = can_error_time_buffer[can_error_read_index];  // Include timestamp of error
00132 
00133     //advance error ring buffer read index
00134     if (can_error_read_index >= (can_error_buffer_size - 1))
00135     {
00136       can_error_read_index = 0;  // wrap around to zero
00137     }
00138     else
00139     {
00140       ++can_error_read_index; // increment
00141     }
00142     return 0; // Error data popped from buffer successfully
00143   }
00144   return 1; // No error data in ring buffer
00145 }
00147 
00149 void can_error_irq_push(unsigned short err)
00150 {
00151   unsigned short temp_index = can_error_read_irq_index;
00152 
00153   while (temp_index != can_error_write_irq_index)
00154   {
00155     if (can_error_type_irq_buffer[temp_index] == err) // Error match found to exist already in buffer
00156     {
00157       ++can_error_freq_irq_buffer[temp_index];   // Increment frequency value
00158       can_error_time_irq_buffer[temp_index] = can_elapsed_ms; // Update time value (most recent occurrence)
00159       return; // No need to search further, error update is done.
00160     }
00161     if (++temp_index >= can_error_irq_buffer_size)
00162     {
00163       temp_index = 0; // Wrap around to zero in ring buffer
00164     }
00165   }
00166 
00167   temp_index = can_error_write_irq_index;
00168 
00169   //No ERROR_ID match found in buffer, push new one on
00170   can_error_type_irq_buffer[temp_index] = err;
00171   can_error_freq_irq_buffer[temp_index] = 1;   // This is the first error of this type.
00172   can_error_time_irq_buffer[temp_index] = can_elapsed_ms;
00173 
00174   if (++temp_index >= can_error_irq_buffer_size)
00175   {
00176     temp_index = 0;  // Wrap around to zero in ring buffer
00177   }
00178   if (temp_index != can_error_read_irq_index)
00179   {
00180     can_error_write_irq_index = temp_index;
00181   }
00182   // else //error - this should only be able to happen if the buffer size is smaller than
00183   // the number of CAN ERROR_IDs possible.
00184 } 
00186 
00188 void can_error_push(unsigned short err)
00189 {
00190   unsigned short temp_index = can_error_read_index;
00191 
00192   while (temp_index != can_error_write_index)
00193   {
00194     if (can_error_type_buffer[temp_index] == err) // Error match found to exist already in buffer
00195     {
00196       ++can_error_freq_buffer[temp_index];   // Increment frequency value
00197       can_error_time_buffer[temp_index] = can_elapsed_ms; // Update time value (most recent occurrence)
00198       return; // No need to search further, error update is done.
00199     }
00200     if (++temp_index >= can_error_buffer_size)
00201     {
00202       temp_index = 0; // Wrap around to zero in ring buffer
00203     }
00204   }
00205 
00206   temp_index = can_error_write_index;
00207 
00208   //No ERROR_ID match found in buffer, push new one on
00209   can_error_type_buffer[temp_index] = err;
00210   can_error_freq_buffer[temp_index] = 1;   // This is the first error of this type.
00211   can_error_time_buffer[temp_index] = can_elapsed_ms;
00212 
00213   if (++temp_index >= can_error_buffer_size)
00214   {
00215     temp_index = 0;  // Wrap around to zero in ring buffer
00216   }
00217   if (temp_index != can_error_read_index)
00218   {
00219     can_error_write_index = temp_index;
00220   }
00221   // else //error - this should only be able to happen if the buffer size is smaller than
00222   // the number of CAN ERROR_IDs possible.
00223 } 
00224 */
00225 unsigned short can_set_elapsed_ms(CAN_FRAME * frame)
00226 {
00227   can_elapsed_ms = frame->payload.w.w2;
00228   return 0;
00229 } 
00230 
00231 void can_rx1_isr(void)__irq{
00232 //  volatile int can1icr = C1ICR;
00233   
00234   #ifdef DEBUG
00235     if (FIO0PIN & 1<<14)
00236     {
00237       VICIntEnClr = 0xFFFFFFFF; //Disable all interrupts before debugging
00238       VICVectAddr = 0;
00239       return;
00240     }
00241   #endif 
00242   ++can_rx_frame_count_1; // Count received frame
00243   can_rx_now(CHAN_CAN1);//Get and dispatch received frame
00244   VICVectAddr = 0;    // Clear interrupt in VIC. 
00245 }
00246 
00247 void can_rx2_isr(void)__irq{
00248  // volatile int can2icr = C2ICR;
00249   
00250     #ifdef DEBUG
00251     if (FIO0PIN & 1<<14)
00252     {
00253       VICIntEnClr = 0xFFFFFFFF; //Disable all interrupts before debugging
00254       VICVectAddr = 0;
00255       return;
00256     }
00257   #endif
00258   ++can_rx_frame_count_2; // Count received frame
00259   can_rx_now(CHAN_CAN2);//Get and dispatch received frame
00260   VICVectAddr = 0;    // Clear interrupt in VIC. 
00261 }
00262 
00263 void can_rx3_isr(void)__irq{
00264 //  volatile int can3icr = C3ICR;
00265   
00266     #ifdef DEBUG
00267     if (FIO0PIN & 1<<14)
00268     {
00269       VICIntEnClr = 0xFFFFFFFF; //Disable all interrupts before debugging
00270       VICVectAddr = 0;
00271       return;
00272     }
00273   #endif
00274   ++can_rx_frame_count_3; // Count received frame
00275   can_rx_now(CHAN_CAN3);//Get and dispatch received frame
00276   VICVectAddr = 0;    // Clear interrupt in VIC. 
00277 }
00278 
00279 void can_rx4_isr(void)__irq{
00280 //  volatile int can4icr = C4ICR;
00281   
00282     #ifdef DEBUG
00283     if (FIO0PIN & 1<<14)
00284     {
00285       VICIntEnClr = 0xFFFFFFFF; //Disable all interrupts before debugging
00286       VICVectAddr = 0;
00287       return;
00288     }
00289   #endif
00290   ++can_rx_frame_count_4; // Count received frame
00291   can_rx_now(CHAN_CAN4);//Get and dispatch received frame
00292   VICVectAddr = 0;    // Clear interrupt in VIC. 
00293 }
00294 
00295 /*
00296 void can_tx1_isr(void)__irq
00297 {
00298   volatile int can1icr = C1ICR;
00299   #ifdef DEBUG
00300       if (FIO0PIN & 1<<14)
00301     {
00302       VICIntEnClr = 0xFFFFFFFF; //Disable all interrupts before debugging
00303       VICVectAddr = 0;
00304       return;
00305     }
00306   #endif
00307 
00308   can_tx_send_next_frame(CHAN_CAN1);  
00309   VICVectAddr = 0;    // Clear interrupt in VIC. 
00310 }
00311 
00312 void can_tx2_isr(void)__irq
00313 {
00314   volatile int can2icr = C2ICR;
00315   
00316   #ifdef DEBUG
00317     if (FIO0PIN & 1<<14)
00318     {
00319       VICIntEnClr = 0xFFFFFFFF; //Disable all interrupts before debugging
00320       VICVectAddr = 0;
00321       return;
00322     }
00323   #endif
00324 
00325   can_tx_send_next_frame(CHAN_CAN2);
00326   VICVectAddr = 0;    // Clear interrupt in VIC. 
00327 }
00328 
00329 void can_tx3_isr(void)__irq
00330 {
00331   volatile int can1icr = C3ICR;
00332   
00333   #ifdef DEBUG
00334     if (FIO0PIN & 1<<14)
00335     {
00336       VICIntEnClr = 0xFFFFFFFF; //Disable all interrupts before debugging
00337       VICVectAddr = 0;
00338       return;
00339     }
00340   #endif
00341 
00342   can_tx_send_next_frame(CHAN_CAN3);
00343   VICVectAddr = 0;    // Clear interrupt in VIC. 
00344 }
00345 
00346 void can_tx4_isr(void)__irq
00347 {
00348   volatile int can1icr = C4ICR;
00349   
00350   #ifdef DEBUG
00351     if (FIO0PIN & 1<<14)
00352     {
00353       VICIntEnClr = 0xFFFFFFFF; //Disable all interrupts before debugging
00354       VICVectAddr = 0;
00355       return;
00356     }
00357   #endif
00358 
00359   can_tx_send_next_frame(CHAN_CAN4);
00360   VICVectAddr = 0;    // Clear interrupt in VIC. 
00361 }
00362 */
00363 /*
00364 void can_tx1_isr(void)__irq
00365 {
00366 
00367   volatile int can1icr = C1ICR;
00368   #ifdef DEBUG
00369       if (FIO0PIN & 1<<14)
00370     {
00371       VICIntEnClr = 0xFFFFFFFF; //Disable all interrupts before debugging
00372       VICVectAddr = 0;
00373       return;
00374     }
00375   #endif
00376   
00377   // Callback function to keep track of transmit frame quantities on each channel
00378   (*can_tx_frame_count)(CHAN_CAN1); //Problem: this is only called if the isr fires, not if stalled.
00379   can_tx_send_next_frame(CHAN_CAN1);  
00380   VICVectAddr = 0;    // Clear interrupt in VIC. 
00381 }
00382 
00383 void can_tx2_isr(void)__irq
00384 {
00385   volatile int can2icr = C2ICR;
00386   
00387   #ifdef DEBUG
00388     if (FIO0PIN & 1<<14)
00389     {
00390       VICIntEnClr = 0xFFFFFFFF; //Disable all interrupts before debugging
00391       VICVectAddr = 0;
00392       return;
00393     }
00394   #endif
00395 
00396   // Callback function to keep track of transmit frame quantities on each channel
00397   (*can_tx_frame_count)(CHAN_CAN2);
00398   can_tx_send_next_frame(CHAN_CAN2);
00399   VICVectAddr = 0;    // Clear interrupt in VIC. 
00400 }
00401 
00402 void can_tx3_isr(void)__irq
00403 {
00404   volatile int can1icr = C3ICR;
00405   
00406   #ifdef DEBUG
00407     if (FIO0PIN & 1<<14)
00408     {
00409       VICIntEnClr = 0xFFFFFFFF; //Disable all interrupts before debugging
00410       VICVectAddr = 0;
00411       return;
00412     }
00413   #endif
00414 
00415   // Callback function to keep track of transmit frame quantities on each channel
00416   (*can_tx_frame_count)(CHAN_CAN3);
00417   can_tx_send_next_frame(CHAN_CAN3);
00418   VICVectAddr = 0;    // Clear interrupt in VIC. 
00419 }
00420 
00421 void can_tx4_isr(void)__irq
00422 {
00423   volatile int can1icr = C4ICR;
00424   
00425   #ifdef DEBUG
00426     if (FIO0PIN & 1<<14)
00427     {
00428       VICIntEnClr = 0xFFFFFFFF; //Disable all interrupts before debugging
00429       VICVectAddr = 0;
00430       return;
00431     }
00432   #endif
00433   // Callback function to keep track of transmit frame quantities on each channel
00434   (*can_tx_frame_count)(CHAN_CAN4);
00435   can_tx_send_next_frame(CHAN_CAN4);
00436   VICVectAddr = 0;    // Reset interrupt address in VIC. 
00437 }
00438 */
00439 
00440 void can_error_isr(void) __irq
00441 {
00442  volatile int can_status1; //save state of capture register
00443  volatile int can_status2; //save state of capture register
00444  volatile int can_status3; //save state of capture register
00445  volatile int can_status4; //save state of capture register
00446  
00447  volatile unsigned long can_acc_filter_error;   //save location of error in AF lookup table
00448   
00449   #ifdef DEBUG
00450     if (FIO0PIN & 1<<14)
00451     {
00452       VICIntEnClr = 0xFFFFFFFF; //Disable all interrupts before debugging
00453       VICVectAddr = 0;
00454       return;
00455     }
00456   #endif
00457 
00458   if (LUTerr & (1<<0))
00459   {
00460     can_acc_filter_error = LUTerrAd;  // Address in look-up table RAM (AF) at which error was encountered
00461                                       // Reading this register clears LUTerr error flag
00462     error_occurred_irq(ERROR_CAN_ACC_FILTER);  // Acceptance filter error - most likely a table error
00463   }
00464 
00465 #ifdef USE_CAN1
00466   if (C1GSR & (1<<7))
00467   { //Bus-off due to too many transmit errors. Probably because someone flashed a board somewhere...
00468     C1MOD = 0; //restart the can bus
00469     error_occurred_irq(ERROR_CAN1_TX_BUSOFF);  // Transmit errors leading to bus off error state
00470     can_error_1 = ERROR_CAN1_TX_BUSOFF;
00471     //can_tx_send_next_frame(CHAN_CAN1); //start the transmissions again
00472     //VICSoftInt = 1<<20;   //Force CAN1 TX interrupt     // **** TEST CODE ****
00473   }
00474   can_status1 = C1ICR; //save state of capture register
00475     if (can_status1 & ((1<<2)|(1<<3)|(1<<5)|(1<<7)))
00476   {
00477     if (can_status1 & (1<<2))
00478     {
00479       can_error_1 = ERROR_CAN1_ERR_WARN;
00480       error_occurred_irq(ERROR_CAN1_ERR_WARN);  // Shows change in error or bus status bits in either direction
00481     }
00482     if (can_status1 & (1<<3))
00483     {
00484       can_error_1 = ERROR_CAN1_DATA_OVRN;
00485       error_occurred_irq(ERROR_CAN1_DATA_OVRN);  // Receive data overrun on CAN1 - receive buffer not read before
00486                                                     // arrival of next received frame, data lost
00487     }
00488     if (can_status1 & (1<<5))
00489     {
00490       can_error_1 = ERROR_CAN1_ERR_PASS;
00491       error_occurred_irq(ERROR_CAN1_ERR_PASS);  // Shows change in active or passive error status in either direction
00492     }
00493     if (can_status1 & (1<<7))
00494     {
00495       if (can_status1 & (1<<21))
00496       {
00497         can_error_1 = ERROR_CAN1_BUS_RX;
00498         error_occurred_irq(ERROR_CAN1_BUS_RX);  // CAN1 has detected an rx bus error. Details of the error require reading
00499                                                   // the other bits in can_status1. For now that has to be done in the debugger,
00500                                                   // including all the possiblities in the ERROR_IDs would be cumbersome.
00501                                                   // But we could make a non-error CAN_FRAME dedicated to the CAN error status register,
00502       }                                           // if we wanted.
00503       else
00504       {
00505          can_error_1 = ERROR_CAN1_BUS_TX;
00506          error_occurred_irq(ERROR_CAN1_BUS_TX);
00507       }
00508     }
00509   } 
00510 #endif
00511 
00512 #ifdef USE_CAN2
00513   if (C2GSR & (1<<7))
00514   { //Bus-off due to too many transmit errors. Probably because someone flashed a board somewhere...
00515     C2MOD = 0; //restart the can bus
00516     error_occurred_irq(ERROR_CAN2_TX_BUSOFF);  // Transmit errors leading to bus off error state
00517     can_error_2 = ERROR_CAN2_TX_BUSOFF;
00518    // can_tx_send_next_frame(CHAN_CAN2); //start the transmissions again
00519     //VICSoftInt = 1<<21;   //Force CAN2 TX interrupt     // **** TEST CODE ****
00520   }
00521   can_status2 = C2ICR; //save state of capture register
00522   if (can_status2 & (((1<<2)|(1<<3)|(1<<5)|(1<<7))&0x7FF))
00523   {
00524     if (can_status2 & (1<<2))
00525     {
00526       can_error_2 = ERROR_CAN2_ERR_WARN;
00527       error_occurred_irq(ERROR_CAN2_ERR_WARN);  // Shows change in error or bus status bits in either direction
00528     }
00529     if (can_status2 & (1<<3))
00530     {
00531       can_error_2 = ERROR_CAN2_DATA_OVRN;
00532       error_occurred_irq(ERROR_CAN2_DATA_OVRN);  // Receive data overrun on CAN2 - receive buffer not read before
00533                                                     // arrival of next received frame, data lost
00534     }
00535     if (can_status2 & (1<<5))
00536     {
00537       can_error_2 = ERROR_CAN2_ERR_PASS;
00538       error_occurred_irq(ERROR_CAN2_ERR_PASS);  // Shows change in active or passive error status in either direction
00539     }
00540     if (can_status2 & (1<<7))
00541     {
00542       if (can_status2 & (1<<21))
00543       {
00544         can_error_2 = ERROR_CAN2_BUS_RX;
00545         error_occurred_irq(ERROR_CAN2_BUS_RX);  // CAN2 has detected an rx bus error. Details of the error require reading
00546                                                   // the other bits in can_status1. For now that has to be done in the debugger,
00547                                                   // including all the possiblities in the ERROR_IDs would be cumbersome.
00548                                                   // But we could make a non-error CAN_FRAME dedicated to the CAN error status register,
00549                                                   // if we wanted.
00550       }
00551       else
00552       {
00553         can_error_2 = ERROR_CAN2_BUS_TX;
00554          error_occurred_irq(ERROR_CAN2_BUS_TX);
00555       }
00556     }
00557   }
00558 #endif
00559 
00560 #ifdef USE_CAN3
00561   if (C3GSR & (1<<7))
00562   { //Bus-off due to too many transmit errors. Probably because someone flashed a board somewhere...
00563     C3MOD = 0; //restart the can bus
00564     error_occurred_irq(ERROR_CAN3_TX_BUSOFF);  // Transmit errors leading to bus off error state
00565     can_error_3 = ERROR_CAN3_TX_BUSOFF;
00566     //can_tx_send_next_frame(CHAN_CAN3); //start the transmissions again
00567     //VICSoftInt = 1<<22;   //Force CAN3 TX interrupt     // **** TEST CODE ****
00568   } 
00569   can_status3 = C3ICR; //save state of capture register
00570   if (can_status3 & (((1<<2)|(1<<3)|(1<<5)|(1<<7))&0x7FF))
00571   {
00572     if (can_status3 & (1<<2))
00573     {
00574       can_error_3 = ERROR_CAN3_ERR_WARN;
00575       error_occurred_irq(ERROR_CAN3_ERR_WARN);  // Shows change in error or bus status bits in either direction
00576     }
00577     if (can_status3 & (1<<3))
00578     {
00579       can_error_3 = ERROR_CAN3_DATA_OVRN;
00580       error_occurred_irq(ERROR_CAN3_DATA_OVRN);  // Receive data overrun on CAN3 - receive buffer not read before
00581                                                     // arrival of next received frame, data lost
00582     }
00583     if (can_status3 & (1<<5))
00584     {
00585       can_error_3 = ERROR_CAN3_ERR_PASS;
00586       error_occurred_irq(ERROR_CAN3_ERR_PASS);  // Shows change in active or passive error status in either direction
00587     }
00588     if (can_status3 & (1<<7))
00589     {
00590       if (can_status3 & (1<<21))
00591       {
00592         can_error_3 = ERROR_CAN3_BUS_RX;
00593         error_occurred_irq(ERROR_CAN3_BUS_RX);  // CAN3 has detected an rx bus error. Details of the error require reading
00594                                                   // the other bits in can_status1. For now that has to be done in the debugger,
00595                                                   // including all the possiblities in the ERROR_IDs would be cumbersome.
00596                                                   // But we could make a non-error CAN_FRAME dedicated to the CAN error status register,
00597                                                   // if we wanted.
00598       }
00599       else
00600       {
00601          can_error_3 = ERROR_CAN3_BUS_TX;
00602          error_occurred_irq(ERROR_CAN3_BUS_TX);
00603       }
00604     }
00605   }
00606 #endif
00607 
00608 #ifdef USE_CAN4
00609   if (C4GSR & (1<<7))
00610   { //Bus-off due to too many transmit errors. Probably because someone flashed a board somewhere...
00611     C4MOD = 0; //restart the can bus
00612     error_occurred_irq(ERROR_CAN4_TX_BUSOFF);  // Transmit errors leading to bus off error state
00613     can_error_4 = ERROR_CAN4_TX_BUSOFF;
00614    // can_tx_send_next_frame(CHAN_CAN4); //start the transmissions again
00615    // VICSoftInt = 1<<23;   //Force CAN4 TX interrupt     // **** TEST CODE ****
00616   }
00617   can_status4 = C4ICR; //save state of capture register 
00618   
00619   if (can_status4 & (((1<<2)|(1<<3)|(1<<5)|(1<<7))&0x7FF))
00620   {
00621     if (can_status4 & (1<<2))
00622     {
00623       can_error_4 = ERROR_CAN4_ERR_WARN;
00624       error_occurred_irq(ERROR_CAN4_ERR_WARN);  // Shows change in error or bus status bits in either direction
00625     }
00626     if (can_status4 & (1<<3))
00627     {
00628       can_error_4 = ERROR_CAN4_DATA_OVRN;
00629       error_occurred_irq(ERROR_CAN4_DATA_OVRN);  // Receive data overrun on CAN4 - receive buffer not read before
00630                                                     // arrival of next received frame, data lost
00631     }
00632     if (can_status4 & (1<<5))
00633     {
00634       can_error_4 = ERROR_CAN4_ERR_PASS;
00635       error_occurred_irq(ERROR_CAN4_ERR_PASS);  // Shows change in active or passive error status in either direction
00636     }
00637     if (can_status4 & (1<<7))
00638     {
00639       if (can_status4 & (1<<21))
00640       {
00641         can_error_4 = ERROR_CAN4_BUS_RX;
00642         error_occurred_irq(ERROR_CAN4_BUS_RX);  // CAN4 has detected an rx bus error. Details of the error require reading
00643                                                   // the other bits in can_status1. For now that has to be done in the debugger,
00644                                                   // including all the possiblities in the ERROR_IDs would be cumbersome.
00645                                                   // But we could make a non-error CAN_FRAME dedicated to the CAN error status register,
00646                                                   // if we wanted.
00647       }
00648       else
00649       {
00650         can_error_4 = ERROR_CAN4_BUS_TX;
00651         error_occurred_irq(ERROR_CAN4_BUS_TX);
00652       }
00653     }
00654   }
00655  #endif
00656   //To do? Put software interrupt force bits for all tx channels here? What about 2-channel MCUs vs. 4-channel?
00657 
00658   VICVectAddr = 0;
00659 }
00660 
00662 // Default function for callback functions of type void int,
00663 // to avoid problems with calling a non-initialized function pointer
00664 void can_voidint(unsigned short chan)
00665 {
00666 }
00668 
Generated on Tue Jun 29 16:36:14 2010 by  doxygen 1.6.3