Subversion Repositories svn.mios32

Rev

Rev 2653 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2653 Rev 2657
Line 94... Line 94...
94
// Local variables
94
// Local variables
95
/////////////////////////////////////////////////////////////////////////////
95
/////////////////////////////////////////////////////////////////////////////
96
96
97
#if NUM_SUPPORTED_CANS >= 1
97
#if NUM_SUPPORTED_CANS >= 1
98
static u8  can_assigned_to_midi;
98
static u8  can_assigned_to_midi;
99
static can_packet_t rx_buffer[NUM_SUPPORTED_CANS][MIOS32_CAN_RX_BUFFER_SIZE];
99
static mios32_can_packet_t rx_buffer[NUM_SUPPORTED_CANS][MIOS32_CAN_RX_BUFFER_SIZE];
100
static volatile u16 rx_buffer_tail[NUM_SUPPORTED_CANS];
100
static volatile u16 rx_buffer_tail[NUM_SUPPORTED_CANS];
101
static volatile u16 rx_buffer_head[NUM_SUPPORTED_CANS];
101
static volatile u16 rx_buffer_head[NUM_SUPPORTED_CANS];
102
static volatile u16 rx_buffer_size[NUM_SUPPORTED_CANS];
102
static volatile u16 rx_buffer_size[NUM_SUPPORTED_CANS];
103
103
104
static can_packet_t tx_buffer[NUM_SUPPORTED_CANS][MIOS32_CAN_TX_BUFFER_SIZE];
104
static mios32_can_packet_t tx_buffer[NUM_SUPPORTED_CANS][MIOS32_CAN_TX_BUFFER_SIZE];
105
static volatile u16 tx_buffer_tail[NUM_SUPPORTED_CANS];
105
static volatile u16 tx_buffer_tail[NUM_SUPPORTED_CANS];
106
static volatile u16 tx_buffer_head[NUM_SUPPORTED_CANS];
106
static volatile u16 tx_buffer_head[NUM_SUPPORTED_CANS];
107
static volatile u16 tx_buffer_size[NUM_SUPPORTED_CANS];
107
static volatile u16 tx_buffer_size[NUM_SUPPORTED_CANS];
108
108
109
static can_stat_report_t can_stat_report[NUM_SUPPORTED_CANS];
109
static mios32_can_stat_report_t can_stat_report[NUM_SUPPORTED_CANS];
110
#endif
110
#endif
111
111
112
#if defined MIOS32_CAN_VERBOSE
112
#if defined MIOS32_CAN_VERBOSE
113
static u8 can_verbose = MIOS32_CAN_VERBOSE;
113
static u8 can_verbose = MIOS32_CAN_VERBOSE;
114
#else
114
#else
115
static u8 can_verbose = 0;
115
static u8 can_verbose = 0;
116
#endif
116
#endif
117
-
 
118
u32 can_temp;
-
 
119
-
 
120
117
121
118
122
/////////////////////////////////////////////////////////////////////////////
119
/////////////////////////////////////////////////////////////////////////////
123
//! Initializes CAN MIDI layer
120
//! Initializes CAN MIDI layer
124
//! \param[in] mode currently only mode 0 supported
121
//! \param[in] mode currently only mode 0 supported
Line 420... Line 417...
420
//! \param[in] can filter bank number
417
//! \param[in] can filter bank number
421
//! \param[in] extended id for filter
418
//! \param[in] extended id for filter
422
//! \param[in] extended id for mask
419
//! \param[in] extended id for mask
423
//! \return < 0 if initialisation failed
420
//! \return < 0 if initialisation failed
424
/////////////////////////////////////////////////////////////////////////////
421
/////////////////////////////////////////////////////////////////////////////
425
s32 MIOS32_CAN_Init32bitFilter(u8 bank, u8 fifo, can_ext_filter_t filter, u8 enabled)
422
s32 MIOS32_CAN_Init32bitFilter(u8 bank, u8 fifo, mios32_can_ext_filter_t filter, u8 enabled)
426
{
423
{
427
#if MIOS32_CAN_NUM == 0
424
#if MIOS32_CAN_NUM == 0
428
  return -1; // no CAN enabled
425
  return -1; // no CAN enabled
429
#else
426
#else
430
  CAN_FilterInitTypeDef CAN_FilterInitStructure;
427
  CAN_FilterInitTypeDef CAN_FilterInitStructure;
Line 451... Line 448...
451
//! \param[in] can filter bank number
448
//! \param[in] can filter bank number
452
//! \param[in] standard id for filter
449
//! \param[in] standard id for filter
453
//! \param[in] standard id for mask
450
//! \param[in] standard id for mask
454
//! \return < 0 if initialisation failed
451
//! \return < 0 if initialisation failed
455
/////////////////////////////////////////////////////////////////////////////
452
/////////////////////////////////////////////////////////////////////////////
456
s32 MIOS32_CAN_Init16bitFilter(u8 bank, u8 fifo, can_std_filter_t filter1, can_std_filter_t filter2, u8 enabled)
453
s32 MIOS32_CAN_Init16bitFilter(u8 bank, u8 fifo, mios32_can_std_filter_t filter1, mios32_can_std_filter_t filter2, u8 enabled)
457
{
454
{
458
#if MIOS32_CAN_NUM == 0
455
#if MIOS32_CAN_NUM == 0
459
  return -1; // no CAN enabled
456
  return -1; // no CAN enabled
460
#else
457
#else
461
  CAN_FilterInitTypeDef CAN_FilterInitStructure;
458
  CAN_FilterInitTypeDef CAN_FilterInitStructure;
Line 483... Line 480...
483
//! \param[in] CAN number (0..1)
480
//! \param[in] CAN number (0..1)
484
//! \return -1: can not available
481
//! \return -1: can not available
485
//! \return -2: function not prepared for this CAN
482
//! \return -2: function not prepared for this CAN
486
//! \return -3: CAN Initialisation failed
483
//! \return -3: CAN Initialisation failed
487
/////////////////////////////////////////////////////////////////////////////
484
/////////////////////////////////////////////////////////////////////////////
488
s32 MIOS32_CAN_InitPacket(can_packet_t *packet)
485
s32 MIOS32_CAN_InitPacket(mios32_can_packet_t *packet)
489
{
486
{
490
#if NUM_SUPPORTED_CANS == 0
487
#if NUM_SUPPORTED_CANS == 0
491
  return -1; // no CAN available
488
  return -1; // no CAN available
492
#else
489
#else
493
  // reset
490
  // reset
Line 545... Line 542...
545
//! \return -1 if CAN not available
542
//! \return -1 if CAN not available
546
//! \return -2 if no new byte available
543
//! \return -2 if no new byte available
547
//! \return >= 0: number of received bytes
544
//! \return >= 0: number of received bytes
548
//! \note Applications shouldn't call these functions directly, instead please use \ref MIOS32_COM or \ref MIOS32_MIDI layer functions
545
//! \note Applications shouldn't call these functions directly, instead please use \ref MIOS32_COM or \ref MIOS32_MIDI layer functions
549
/////////////////////////////////////////////////////////////////////////////
546
/////////////////////////////////////////////////////////////////////////////
550
s32 MIOS32_CAN_RxBufferGet(u8 can, can_packet_t *p)
547
s32 MIOS32_CAN_RxBufferGet(u8 can, mios32_can_packet_t *p)
551
{
548
{
552
#if NUM_SUPPORTED_CANS == 0
549
#if NUM_SUPPORTED_CANS == 0
553
  return -1; // no CAN available
550
  return -1; // no CAN available
554
#else
551
#else
555
  if( can >= NUM_SUPPORTED_CANS )
552
  if( can >= NUM_SUPPORTED_CANS )
Line 579... Line 576...
579
//! \return -1 if CAN not available
576
//! \return -1 if CAN not available
580
//! \return -2 if no new byte available
577
//! \return -2 if no new byte available
581
//! \return >= 0: number of received bytes
578
//! \return >= 0: number of received bytes
582
//! \note Applications shouldn't call these functions directly, instead please use \ref MIOS32_COM or \ref MIOS32_MIDI layer functions
579
//! \note Applications shouldn't call these functions directly, instead please use \ref MIOS32_COM or \ref MIOS32_MIDI layer functions
583
/////////////////////////////////////////////////////////////////////////////
580
/////////////////////////////////////////////////////////////////////////////
584
s32 MIOS32_CAN_RxBufferPeek(u8 can, can_packet_t *p)
581
s32 MIOS32_CAN_RxBufferPeek(u8 can, mios32_can_packet_t *p)
585
{
582
{
586
#if NUM_SUPPORTED_CANS == 0
583
#if NUM_SUPPORTED_CANS == 0
587
  return -1; // no CAN available
584
  return -1; // no CAN available
588
#else
585
#else
589
  if( can >= NUM_SUPPORTED_CANS )
586
  if( can >= NUM_SUPPORTED_CANS )
Line 638... Line 635...
638
//! \return 0 if no error
635
//! \return 0 if no error
639
//! \return -1 if CAN not available
636
//! \return -1 if CAN not available
640
//! \return -2 if buffer full (retry)
637
//! \return -2 if buffer full (retry)
641
//! \note Applications shouldn't call these functions directly, instead please use \ref MIOS32_COM or \ref MIOS32_MIDI layer functions
638
//! \note Applications shouldn't call these functions directly, instead please use \ref MIOS32_COM or \ref MIOS32_MIDI layer functions
642
/////////////////////////////////////////////////////////////////////////////
639
/////////////////////////////////////////////////////////////////////////////
643
s32 MIOS32_CAN_RxBufferPut(u8 can, can_packet_t p)
640
s32 MIOS32_CAN_RxBufferPut(u8 can, mios32_can_packet_t p)
644
{
641
{
645
#if NUM_SUPPORTED_CANS == 0
642
#if NUM_SUPPORTED_CANS == 0
646
  return -1; // no CAN available
643
  return -1; // no CAN available
647
#else
644
#else
648
  if( can >= NUM_SUPPORTED_CANS )
645
  if( can >= NUM_SUPPORTED_CANS )
Line 712... Line 709...
712
//! \return -1 if CAN not available
709
//! \return -1 if CAN not available
713
//! \return -2 if no new byte available
710
//! \return -2 if no new byte available
714
//! \return >= 0: transmitted byte
711
//! \return >= 0: transmitted byte
715
//! \note Applications shouldn't call these functions directly, instead please use \ref MIOS32_COM or \ref MIOS32_MIDI layer functions
712
//! \note Applications shouldn't call these functions directly, instead please use \ref MIOS32_COM or \ref MIOS32_MIDI layer functions
716
/////////////////////////////////////////////////////////////////////////////
713
/////////////////////////////////////////////////////////////////////////////
717
s32 MIOS32_CAN_TxBufferGet(u8 can, can_packet_t *p)
714
s32 MIOS32_CAN_TxBufferGet(u8 can, mios32_can_packet_t *p)
718
{
715
{
719
#if NUM_SUPPORTED_CANS == 0
716
#if NUM_SUPPORTED_CANS == 0
720
  return -1; // no CAN available
717
  return -1; // no CAN available
721
#else
718
#else
722
  if( can >= NUM_SUPPORTED_CANS )
719
  if( can >= NUM_SUPPORTED_CANS )
Line 747... Line 744...
747
//! \return -1 if CAN not available
744
//! \return -1 if CAN not available
748
//! \return -2 if buffer full or cannot get all requested bytes (retry)
745
//! \return -2 if buffer full or cannot get all requested bytes (retry)
749
//! \return -3 if CAN not supported by MIOS32_CAN_TxBufferPut Routine
746
//! \return -3 if CAN not supported by MIOS32_CAN_TxBufferPut Routine
750
//! \note Applications shouldn't call these functions directly, instead please use \ref MIOS32_COM or \ref MIOS32_MIDI layer functions
747
//! \note Applications shouldn't call these functions directly, instead please use \ref MIOS32_COM or \ref MIOS32_MIDI layer functions
751
/////////////////////////////////////////////////////////////////////////////
748
/////////////////////////////////////////////////////////////////////////////
752
s32 MIOS32_CAN_TxBufferPutMore_NonBlocking(u8 can, can_packet_t* p,u16 len)
749
s32 MIOS32_CAN_TxBufferPutMore_NonBlocking(u8 can, mios32_can_packet_t* p,u16 len)
753
{
750
{
754
#if NUM_SUPPORTED_CANS == 0
751
#if NUM_SUPPORTED_CANS == 0
755
  return -1; // no CAN available
752
  return -1; // no CAN available
756
#else
753
#else
757
  if( can >= NUM_SUPPORTED_CANS )
754
  if( can >= NUM_SUPPORTED_CANS )
Line 822... Line 819...
822
//! \return 0 if no error
819
//! \return 0 if no error
823
//! \return -1 if CAN not available
820
//! \return -1 if CAN not available
824
//! \return -3 if CAN not supported by MIOS32_CAN_TxBufferPut Routine
821
//! \return -3 if CAN not supported by MIOS32_CAN_TxBufferPut Routine
825
//! \note Applications shouldn't call these functions directly, instead please use \ref MIOS32_COM or \ref MIOS32_MIDI layer functions
822
//! \note Applications shouldn't call these functions directly, instead please use \ref MIOS32_COM or \ref MIOS32_MIDI layer functions
826
/////////////////////////////////////////////////////////////////////////////
823
/////////////////////////////////////////////////////////////////////////////
827
s32 MIOS32_CAN_TxBufferPutMore(u8 can, can_packet_t *packets, u16 len)
824
s32 MIOS32_CAN_TxBufferPutMore(u8 can, mios32_can_packet_t *packets, u16 len)
828
{
825
{
829
  s32 error;
826
  s32 error;
830
 
827
 
831
  while( (error=MIOS32_CAN_TxBufferPutMore_NonBlocking(can, packets, len)) == -2 );
828
  while( (error=MIOS32_CAN_TxBufferPutMore_NonBlocking(can, packets, len)) == -2 );
832
 
829
 
Line 842... Line 839...
842
//! \return -1 if CAN not available
839
//! \return -1 if CAN not available
843
//! \return -2 if buffer full (retry)
840
//! \return -2 if buffer full (retry)
844
//! \return -3 if CAN not supported by MIOS32_CAN_TxBufferPut Routine
841
//! \return -3 if CAN not supported by MIOS32_CAN_TxBufferPut Routine
845
//! \note Applications shouldn't call these functions directly, instead please use \ref MIOS32_COM or \ref MIOS32_MIDI layer functions
842
//! \note Applications shouldn't call these functions directly, instead please use \ref MIOS32_COM or \ref MIOS32_MIDI layer functions
846
/////////////////////////////////////////////////////////////////////////////
843
/////////////////////////////////////////////////////////////////////////////
847
s32 MIOS32_CAN_TxBufferPut_NonBlocking(u8 can, can_packet_t p)
844
s32 MIOS32_CAN_TxBufferPut_NonBlocking(u8 can, mios32_can_packet_t p)
848
{
845
{
849
  // for more comfortable usage...
846
  // for more comfortable usage...
850
  // -> just forward to MIOS32_CAN_TxBufferPutMore
847
  // -> just forward to MIOS32_CAN_TxBufferPutMore
851
  return MIOS32_CAN_TxBufferPutMore(can, &p, 1);
848
  return MIOS32_CAN_TxBufferPutMore(can, &p, 1);
852
}
849
}
Line 860... Line 857...
860
//! \return 0 if no error
857
//! \return 0 if no error
861
//! \return -1 if CAN not available
858
//! \return -1 if CAN not available
862
//! \return -3 if CAN not supported by MIOS32_CAN_TxBufferPut Routine
859
//! \return -3 if CAN not supported by MIOS32_CAN_TxBufferPut Routine
863
//! \note Applications shouldn't call these functions directly, instead please use \ref MIOS32_COM or \ref MIOS32_MIDI layer functions
860
//! \note Applications shouldn't call these functions directly, instead please use \ref MIOS32_COM or \ref MIOS32_MIDI layer functions
864
/////////////////////////////////////////////////////////////////////////////
861
/////////////////////////////////////////////////////////////////////////////
865
s32 MIOS32_CAN_TxBufferPut(u8 can, can_packet_t p)
862
s32 MIOS32_CAN_TxBufferPut(u8 can, mios32_can_packet_t p)
866
{
863
{
867
  s32 error;
864
  s32 error;
868
 
865
 
869
  while( (error=MIOS32_CAN_TxBufferPutMore(can, &p, 1)) == -2 );
866
  while( (error=MIOS32_CAN_TxBufferPutMore(can, &p, 1)) == -2 );
870
 
867
 
Line 886... Line 883...
886
{
883
{
887
#if NUM_SUPPORTED_CANS == 0
884
#if NUM_SUPPORTED_CANS == 0
888
  return -1; // no CAN available
885
  return -1; // no CAN available
889
#else
886
#else
890
887
891
  can_stat_err_t err;
888
  mios32_can_stat_err_t err;
892
  err = can_stat_report[can].bus_last_err;
889
  err = can_stat_report[can].bus_last_err;
893
  //if((CANx->ESR &7)!=0){
890
  //if((CANx->ESR &7)!=0){
894
  if((err.tec) > (can_stat_report[can].bus_curr_err.tec)){
891
  if((err.tec) > (can_stat_report[can].bus_curr_err.tec)){
895
      if(can_verbose)MIOS32_MIDI_SendDebugMessage("[MIOS32_CAN_BusErrorCheck] %s %s %s. rec:%d, tec:%d>", err.ewgf? "warning" : "", err.epvf? "passive" : "", err.boff? "off" : "", err.rec, err.tec);
892
      if(can_verbose)MIOS32_MIDI_SendDebugMessage("[MIOS32_CAN_BusErrorCheck] %s %s %s. rec:%d, tec:%d>", err.ewgf? "warning" : "", err.epvf? "passive" : "", err.boff? "off" : "", err.rec, err.tec);
896
893
Line 965... Line 962...
965
//! \return -1 if CAN not available
962
//! \return -1 if CAN not available
966
//! \return -2 if buffer full or cannot get all requested bytes (retry)
963
//! \return -2 if buffer full or cannot get all requested bytes (retry)
967
//! \return -3 if CAN not supported by MIOS32_CAN_TxBufferPut Routine
964
//! \return -3 if CAN not supported by MIOS32_CAN_TxBufferPut Routine
968
//! \note Applications shouldn't call these functions directly, instead please use \ref MIOS32_COM or \ref MIOS32_MIDI layer functions
965
//! \note Applications shouldn't call these functions directly, instead please use \ref MIOS32_COM or \ref MIOS32_MIDI layer functions
969
/////////////////////////////////////////////////////////////////////////////
966
/////////////////////////////////////////////////////////////////////////////
970
s32 MIOS32_CAN_Transmit(u8 can, can_packet_t p, s16 block_time)
967
s32 MIOS32_CAN_Transmit(u8 can, mios32_can_packet_t p, s16 block_time)
971
{
968
{
972
#if NUM_SUPPORTED_CANS == 0
969
#if NUM_SUPPORTED_CANS == 0
973
  return -1; // no CAN available
970
  return -1; // no CAN available
974
#else
971
#else
975
  if( can >= NUM_SUPPORTED_CANS )
972
  if( can >= NUM_SUPPORTED_CANS )
Line 1026... Line 1023...
1026
      if(MIOS32_CAN_TxBufferUsed(0) >= 1){
1023
      if(MIOS32_CAN_TxBufferUsed(0) >= 1){
1027
        u8 mailbox = -1;
1024
        u8 mailbox = -1;
1028
        if( MIOS32_CAN1->TSR & CAN_TSR_TME0)mailbox = 0;
1025
        if( MIOS32_CAN1->TSR & CAN_TSR_TME0)mailbox = 0;
1029
        else if( MIOS32_CAN1->TSR & CAN_TSR_TME1)mailbox = 1;
1026
        else if( MIOS32_CAN1->TSR & CAN_TSR_TME1)mailbox = 1;
1030
        else if( MIOS32_CAN1->TSR & CAN_TSR_TME2)mailbox = 2;
1027
        else if( MIOS32_CAN1->TSR & CAN_TSR_TME2)mailbox = 2;
1031
        can_packet_t p;
1028
        mios32_can_packet_t p;
1032
        MIOS32_CAN_TxBufferGet(0, &p);
1029
        MIOS32_CAN_TxBufferGet(0, &p);
1033
        p.id.txrq = 1; //TX Req flag, this reset RQCPx
1030
        p.id.txrq = 1; //TX Req flag, this reset RQCPx
1034
        MIOS32_CAN1->sTxMailBox[mailbox].TDTR = p.ctrl.ALL;
1031
        MIOS32_CAN1->sTxMailBox[mailbox].TDTR = p.ctrl.ALL;
1035
        MIOS32_CAN1->sTxMailBox[mailbox].TDLR = p.data.data_l;
1032
        MIOS32_CAN1->sTxMailBox[mailbox].TDLR = p.data.data_l;
1036
        MIOS32_CAN1->sTxMailBox[mailbox].TDHR = p.data.data_h;
1033
        MIOS32_CAN1->sTxMailBox[mailbox].TDHR = p.data.data_h;
Line 1048... Line 1045...
1048
MIOS32_CAN1_RX0_IRQHANDLER_FUNC
1045
MIOS32_CAN1_RX0_IRQHANDLER_FUNC
1049
{
1046
{
1050
 
1047
 
1051
  while(MIOS32_CAN1->RF0R & CAN_RF0R_FMP0){     // FMP0 contains number of messages
1048
  while(MIOS32_CAN1->RF0R & CAN_RF0R_FMP0){     // FMP0 contains number of messages
1052
    // get EID, MSG and DLC
1049
    // get EID, MSG and DLC
1053
    can_packet_t p;
1050
    mios32_can_packet_t p;
1054
    p.id.ALL = MIOS32_CAN1->sFIFOMailBox[0].RIR;
1051
    p.id.ALL = MIOS32_CAN1->sFIFOMailBox[0].RIR;
1055
    p.ctrl.ALL = MIOS32_CAN1->sFIFOMailBox[0].RDTR;
1052
    p.ctrl.ALL = MIOS32_CAN1->sFIFOMailBox[0].RDTR;
1056
    p.data.data_l = MIOS32_CAN1->sFIFOMailBox[0].RDLR;
1053
    p.data.data_l = MIOS32_CAN1->sFIFOMailBox[0].RDLR;
1057
    p.data.data_h = MIOS32_CAN1->sFIFOMailBox[0].RDHR;
1054
    p.data.data_h = MIOS32_CAN1->sFIFOMailBox[0].RDHR;
1058
    can_stat_report[0].rx_packets_ctr++;
1055
    can_stat_report[0].rx_packets_ctr++;
Line 1105... Line 1102...
1105
MIOS32_CAN1_RX1_IRQHANDLER_FUNC
1102
MIOS32_CAN1_RX1_IRQHANDLER_FUNC
1106
{
1103
{
1107
 
1104
 
1108
  while(MIOS32_CAN1->RF1R & CAN_RF1R_FMP1){     // FMP1 contains number of messages
1105
  while(MIOS32_CAN1->RF1R & CAN_RF1R_FMP1){     // FMP1 contains number of messages
1109
    // get EID, MSG and DLC
1106
    // get EID, MSG and DLC
1110
    can_packet_t p;
1107
    mios32_can_packet_t p;
1111
    p.id.ALL = MIOS32_CAN1->sFIFOMailBox[1].RIR;
1108
    p.id.ALL = MIOS32_CAN1->sFIFOMailBox[1].RIR;
1112
    p.ctrl.ALL = MIOS32_CAN1->sFIFOMailBox[1].RDTR;
1109
    p.ctrl.ALL = MIOS32_CAN1->sFIFOMailBox[1].RDTR;
1113
    p.data.data_l = MIOS32_CAN1->sFIFOMailBox[1].RDLR;
1110
    p.data.data_l = MIOS32_CAN1->sFIFOMailBox[1].RDLR;
1114
    p.data.data_h = MIOS32_CAN1->sFIFOMailBox[1].RDHR;
1111
    p.data.data_h = MIOS32_CAN1->sFIFOMailBox[1].RDHR;
1115
    can_stat_report[0].rx_packets_ctr++;
1112
    can_stat_report[0].rx_packets_ctr++;
Line 1157... Line 1154...
1157
{
1154
{
1158
 
1155
 
1159
  if( CAN_GetITStatus(MIOS32_CAN1, CAN_IT_ERR) ) { // General Err interrupt is enabled
1156
  if( CAN_GetITStatus(MIOS32_CAN1, CAN_IT_ERR) ) { // General Err interrupt is enabled
1160
1157
1161
    if( (can_stat_report[0].bus_last_err.ALL & 7) != (MIOS32_CAN1->ESR & 7) ){
1158
    if( (can_stat_report[0].bus_last_err.ALL & 7) != (MIOS32_CAN1->ESR & 7) ){
1162
      //can_stat_err_t err = MIOS32_CAN1->ESR;
1159
      //mios32_can_stat_err_t err = MIOS32_CAN1->ESR;
1163
      can_stat_report[0].bus_last_err.ALL = MIOS32_CAN1->ESR;
1160
      can_stat_report[0].bus_last_err.ALL = MIOS32_CAN1->ESR;
1164
      //if(can_verbose)MIOS32_MIDI_SendDebugMessage("0x%0x", can_stat_report[0].bus_last_err.ALL & 7);
1161
      //if(can_verbose)MIOS32_MIDI_SendDebugMessage("0x%0x", can_stat_report[0].bus_last_err.ALL & 7);
1165
     
1162
     
1166
      if(can_stat_report[0].bus_last_err.ewgf){
1163
      if(can_stat_report[0].bus_last_err.ewgf){
1167
        //can_stat_report[0].bus_state = WARNING;
1164
        //can_stat_report[0].bus_state = WARNING;
Line 1204... Line 1201...
1204
    if(MIOS32_CAN_TxBufferUsed(1) >= 1){
1201
    if(MIOS32_CAN_TxBufferUsed(1) >= 1){
1205
      u8 mailbox = -1;
1202
      u8 mailbox = -1;
1206
      if( MIOS32_CAN2->TSR & CAN_TSR_TME0)mailbox = 0;
1203
      if( MIOS32_CAN2->TSR & CAN_TSR_TME0)mailbox = 0;
1207
      else if( MIOS32_CAN2->TSR & CAN_TSR_TME1)mailbox = 1;
1204
      else if( MIOS32_CAN2->TSR & CAN_TSR_TME1)mailbox = 1;
1208
      else if( MIOS32_CAN2->TSR & CAN_TSR_TME2)mailbox = 2;
1205
      else if( MIOS32_CAN2->TSR & CAN_TSR_TME2)mailbox = 2;
1209
      can_packet_t p;
1206
      mios32_can_packet_t p;
1210
      MIOS32_CAN_TxBufferGet(1, &p);
1207
      MIOS32_CAN_TxBufferGet(1, &p);
1211
      p.id.txrq = 1; //TX Req flag, this reset RQCPx
1208
      p.id.txrq = 1; //TX Req flag, this reset RQCPx
1212
      MIOS32_CAN2->sTxMailBox[mailbox].TDTR = p.ctrl.ALL;
1209
      MIOS32_CAN2->sTxMailBox[mailbox].TDTR = p.ctrl.ALL;
1213
      MIOS32_CAN2->sTxMailBox[mailbox].TDLR = p.data.data_l;
1210
      MIOS32_CAN2->sTxMailBox[mailbox].TDLR = p.data.data_l;
1214
      MIOS32_CAN2->sTxMailBox[mailbox].TDHR = p.data.data_h;
1211
      MIOS32_CAN2->sTxMailBox[mailbox].TDHR = p.data.data_h;
Line 1226... Line 1223...
1226
#endif
1223
#endif
1227
MIOS32_CAN2_RX0_IRQHANDLER_FUNC
1224
MIOS32_CAN2_RX0_IRQHANDLER_FUNC
1228
{
1225
{
1229
  while(MIOS32_CAN2->RF0R & CAN_RF0R_FMP0){     // FMP0 contains number of messages
1226
  while(MIOS32_CAN2->RF0R & CAN_RF0R_FMP0){     // FMP0 contains number of messages
1230
    // get EID, MSG and DLC
1227
    // get EID, MSG and DLC
1231
    can_packet_t p;
1228
    mios32_can_packet_t p;
1232
    p.id.ALL = MIOS32_CAN2->sFIFOMailBox[0].RIR;
1229
    p.id.ALL = MIOS32_CAN2->sFIFOMailBox[0].RIR;
1233
    p.ctrl.ALL = MIOS32_CAN2->sFIFOMailBox[0].RDTR;
1230
    p.ctrl.ALL = MIOS32_CAN2->sFIFOMailBox[0].RDTR;
1234
    p.data.data_l = MIOS32_CAN2->sFIFOMailBox[0].RDLR;
1231
    p.data.data_l = MIOS32_CAN2->sFIFOMailBox[0].RDLR;
1235
    p.data.data_h = MIOS32_CAN2->sFIFOMailBox[0].RDHR;
1232
    p.data.data_h = MIOS32_CAN2->sFIFOMailBox[0].RDHR;
1236
   
1233
   
Line 1247... Line 1244...
1247
1244
1248
MIOS32_CAN2_RX1_IRQHANDLER_FUNC
1245
MIOS32_CAN2_RX1_IRQHANDLER_FUNC
1249
{
1246
{
1250
  while(MIOS32_CAN2->RF1R & CAN_RF1R_FMP1 ){     // FMP1 contains number of messages
1247
  while(MIOS32_CAN2->RF1R & CAN_RF1R_FMP1 ){     // FMP1 contains number of messages
1251
    // get EID, MSG and DLC
1248
    // get EID, MSG and DLC
1252
    can_packet_t p;
1249
    mios32_can_packet_t p;
1253
    p.id.ALL = MIOS32_CAN2->sFIFOMailBox[1].RIR;
1250
    p.id.ALL = MIOS32_CAN2->sFIFOMailBox[1].RIR;
1254
    p.ctrl.ALL = MIOS32_CAN2->sFIFOMailBox[1].RDTR;
1251
    p.ctrl.ALL = MIOS32_CAN2->sFIFOMailBox[1].RDTR;
1255
    p.data.data_l = MIOS32_CAN2->sFIFOMailBox[1].RDLR;
1252
    p.data.data_l = MIOS32_CAN2->sFIFOMailBox[1].RDLR;
1256
    p.data.data_h = MIOS32_CAN2->sFIFOMailBox[1].RDHR;
1253
    p.data.data_h = MIOS32_CAN2->sFIFOMailBox[1].RDHR;
1257
   
1254
   
Line 1311... Line 1308...
1311
1308
1312
1309
1313
/////////////////////////////////////////////////////////////////////////////
1310
/////////////////////////////////////////////////////////////////////////////
1314
//
1311
//
1315
/////////////////////////////////////////////////////////////////////////////
1312
/////////////////////////////////////////////////////////////////////////////
1316
s32 MIOS32_CAN_ReportLastErr(u8 can, can_stat_err_t* err)
1313
s32 MIOS32_CAN_ReportLastErr(u8 can, mios32_can_stat_err_t* err)
1317
{
1314
{
1318
#if NUM_SUPPORTED_CANS == 0
1315
#if NUM_SUPPORTED_CANS == 0
1319
  return -1; // no CAN available
1316
  return -1; // no CAN available
1320
#else
1317
#else
1321
  *err= can_stat_report[can].bus_last_err;
1318
  *err= can_stat_report[can].bus_last_err;
Line 1324... Line 1321...
1324
}
1321
}
1325
1322
1326
/////////////////////////////////////////////////////////////////////////////
1323
/////////////////////////////////////////////////////////////////////////////
1327
//
1324
//
1328
/////////////////////////////////////////////////////////////////////////////
1325
/////////////////////////////////////////////////////////////////////////////
1329
s32 MIOS32_CAN_ReportGetCurr(u8 can, can_stat_report_t* report)
1326
s32 MIOS32_CAN_ReportGetCurr(u8 can, mios32_can_stat_report_t* report)
1330
{
1327
{
1331
#if NUM_SUPPORTED_CANS == 0
1328
#if NUM_SUPPORTED_CANS == 0
1332
  return -1; // no CAN available
1329
  return -1; // no CAN available
1333
#else
1330
#else
1334
  CAN_TypeDef* CANx = NULL;
1331
  CAN_TypeDef* CANx = NULL;