Subversion Repositories svn.mios32

Rev

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

Rev 2646 Rev 2657
Line 103... Line 103...
103
// for frame rate calculation
103
// for frame rate calculation
104
static u32 frame_rate;
104
static u32 frame_rate;
105
static u32 can_last_baudrate;
105
static u32 can_last_baudrate;
106
106
107
// callback for direct sysex stream
107
// callback for direct sysex stream
108
static s32 (*sysex_stream_callback_func)(mcan_header_t header, u8* stream, u16 size);
108
static s32 (*sysex_stream_callback_func)(mios32_mcan_header_t header, u8* stream, u16 size);
109
static s32 (*direct_package_callback_func)(mcan_header_t header, mios32_midi_package_t package);
109
static s32 (*direct_package_callback_func)(mios32_mcan_header_t header, mios32_midi_package_t package);
110
110
111
// verbose
111
// verbose
112
static u8 can_midi_verbose = 2;
112
static u8 can_midi_verbose = 2;
113
113
114
#endif
114
#endif
Line 143... Line 143...
143
}
143
}
144
/////////////////////////////////////////////////////////////////////////////
144
/////////////////////////////////////////////////////////////////////////////
145
/////////////////////////////////////////////////////////////////////////////
145
/////////////////////////////////////////////////////////////////////////////
146
146
147
// internal function to parse configuration commands
147
// internal function to parse configuration commands
148
static s32 MIOS32_CAN_MIDI_LocalCmdParser(mcan_header_t header, mios32_midi_package_t* package)
148
static s32 MIOS32_CAN_MIDI_LocalCmdParser(mios32_mcan_header_t header, mios32_midi_package_t* package)
149
{
149
{
150
#if MIOS32_CAN_NUM > 0
150
#if MIOS32_CAN_NUM > 0
151
 
151
 
152
152
153
 
153
 
Line 346... Line 346...
346
#if MIOS32_CAN_NUM == 0
346
#if MIOS32_CAN_NUM == 0
347
  return -1; // no CAN enabled
347
  return -1; // no CAN enabled
348
#else
348
#else
349
 
349
 
350
  //u8 i;
350
  //u8 i;
351
  //can_ext_filter_t filt32;
351
  //mios32_can_ext_filter_t filt32;
352
  can_std_filter_t filt16[2];
352
  mios32_can_std_filter_t filt16[2];
353
 
353
 
354
//  /* Node System messages and bypass -> Fifo0 */
354
//  /* Node System messages and bypass -> Fifo0 */
355
//  // filter Bank#0, checks for incoming Node SysEx and SysCom messages
355
//  // filter Bank#0, checks for incoming Node SysEx and SysCom messages
356
//  filt32.filt.ALL = 0;
356
//  filt32.filt.ALL = 0;
357
//  filt32.filt.event = 0xf8;
357
//  filt32.filt.event = 0xf8;
Line 477... Line 477...
477
  if( (--node_active_sense_ctr) <=0 ){
477
  if( (--node_active_sense_ctr) <=0 ){
478
    node_active_sense_ctr = 1000; // every second
478
    node_active_sense_ctr = 1000; // every second
479
    u32 new_frame_rate;
479
    u32 new_frame_rate;
480
    if( MIOS32_CAN_MIDI_CheckAvailable(0) ){
480
    if( MIOS32_CAN_MIDI_CheckAvailable(0) ){
481
481
482
      can_stat_report_t report;
482
      mios32_can_stat_report_t report;
483
      MIOS32_CAN_ReportGetCurr(0, &report);
483
      MIOS32_CAN_ReportGetCurr(0, &report);
484
484
485
      new_frame_rate = report.rx_packets_ctr - can_last_baudrate;
485
      new_frame_rate = report.rx_packets_ctr - can_last_baudrate;
486
      can_last_baudrate = report.rx_packets_ctr;
486
      can_last_baudrate = report.rx_packets_ctr;
487
      if(frame_rate != new_frame_rate){
487
      if(frame_rate != new_frame_rate){
Line 514... Line 514...
514
//! \return -1: CAN_MIDI device not available
514
//! \return -1: CAN_MIDI device not available
515
//! \return -2: CAN_MIDI buffer is full
515
//! \return -2: CAN_MIDI buffer is full
516
//!             caller should retry until buffer is free again
516
//!             caller should retry until buffer is free again
517
//! \note Applications shouldn't call this function directly, instead please use \ref MIOS32_MIDI layer functions
517
//! \note Applications shouldn't call this function directly, instead please use \ref MIOS32_MIDI layer functions
518
/////////////////////////////////////////////////////////////////////////////
518
/////////////////////////////////////////////////////////////////////////////
519
s32 MIOS32_CAN_MIDI_PacketTransmit_NonBlocking(mcan_packet_t p)
519
s32 MIOS32_CAN_MIDI_PacketTransmit_NonBlocking(mios32_mcan_packet_t p)
520
{
520
{
521
#if MIOS32_CAN_NUM == 0
521
#if MIOS32_CAN_NUM == 0
522
  return -1; // all CANs explicitely disabled
522
  return -1; // all CANs explicitely disabled
523
#else
523
#else
524
  // tx enabler bit
524
  // tx enabler bit
Line 544... Line 544...
544
//! \param[in] MCAN Packet
544
//! \param[in] MCAN Packet
545
//! \return 0: no error
545
//! \return 0: no error
546
//! \return -1: CAN_MIDI device not available
546
//! \return -1: CAN_MIDI device not available
547
//! \note Applications shouldn't call this function directly, instead please use \ref MIOS32_MIDI layer functions
547
//! \note Applications shouldn't call this function directly, instead please use \ref MIOS32_MIDI layer functions
548
/////////////////////////////////////////////////////////////////////////////
548
/////////////////////////////////////////////////////////////////////////////
549
s32 MIOS32_CAN_MIDI_PacketTransmit(mcan_packet_t p)
549
s32 MIOS32_CAN_MIDI_PacketTransmit(mios32_mcan_packet_t p)
550
{
550
{
551
  s32 error;
551
  s32 error;
552
 
552
 
553
  while( (error=MIOS32_CAN_MIDI_PacketTransmit_NonBlocking(p)) == -2);
553
  while( (error=MIOS32_CAN_MIDI_PacketTransmit_NonBlocking(p)) == -2);
554
 
554
 
Line 560... Line 560...
560
//! \param[in] header MCAN Extra Infos
560
//! \param[in] header MCAN Extra Infos
561
//! \param[in] package MIDI package
561
//! \param[in] package MIDI package
562
//! \return 0: no error
562
//! \return 0: no error
563
//! \note Applications shouldn't call this function directly, instead please use \ref MIOS32_MIDI layer functions
563
//! \note Applications shouldn't call this function directly, instead please use \ref MIOS32_MIDI layer functions
564
/////////////////////////////////////////////////////////////////////////////
564
/////////////////////////////////////////////////////////////////////////////
565
s32 MIOS32_CAN_MIDI_PacketSend_NonBlocking(mcan_header_t header, mios32_midi_package_t package)
565
s32 MIOS32_CAN_MIDI_PacketSend_NonBlocking(mios32_mcan_header_t header, mios32_midi_package_t package)
566
{
566
{
567
#if MIOS32_CAN_NUM == 0
567
#if MIOS32_CAN_NUM == 0
568
  return -1; // all CANs explicitely disabled
568
  return -1; // all CANs explicitely disabled
569
#else
569
#else
570
  // exit if MCANx port not available
570
  // exit if MCANx port not available
Line 590... Line 590...
590
  }else if(package.type == 0x6 || package.type == 0x7){
590
  }else if(package.type == 0x6 || package.type == 0x7){
591
    //header.cin_cable = 0x70 + package.cable;  // end
591
    //header.cin_cable = 0x70 + package.cable;  // end
592
    error = MIOS32_CAN_MIDI_SysexRepackSend(header, package);
592
    error = MIOS32_CAN_MIDI_SysexRepackSend(header, package);
593
    return error;
593
    return error;
594
  }else{ // This is not Sysex
594
  }else{ // This is not Sysex
595
    mcan_packet_t p;
595
    mios32_mcan_packet_t p;
596
    //p.frame_id = header.frame_id;
596
    //p.frame_id = header.frame_id;
597
    u8* byte = &p.data.bytes[0];
597
    u8* byte = &p.data.bytes[0];
598
    p.ctrl.dlc = 0;
598
    p.ctrl.dlc = 0;
599
#if defined(MIOS32_CAN_MIDI_ENHANCED)
599
#if defined(MIOS32_CAN_MIDI_ENHANCED)
600
    // On extended frame adds the src/dst ports infos
600
    // On extended frame adds the src/dst ports infos
Line 644... Line 644...
644
//! \param[in] package MIDI package
644
//! \param[in] package MIDI package
645
//! \return 0: no error
645
//! \return 0: no error
646
//! \return -1: CAN_MIDI device not available
646
//! \return -1: CAN_MIDI device not available
647
//! \note Applications shouldn't call this function directly, instead please use \ref MIOS32_MIDI layer functions
647
//! \note Applications shouldn't call this function directly, instead please use \ref MIOS32_MIDI layer functions
648
/////////////////////////////////////////////////////////////////////////////
648
/////////////////////////////////////////////////////////////////////////////
649
s32 MIOS32_CAN_MIDI_PacketSend(mcan_header_t header, mios32_midi_package_t package)
649
s32 MIOS32_CAN_MIDI_PacketSend(mios32_mcan_header_t header, mios32_midi_package_t package)
650
{
650
{
651
  s32 error;
651
  s32 error;
652
  //DEBUG_MSG("[MIOS32_CAN_MIDI_PackageSend] 0x%08x\n", package.ALL);
652
  //DEBUG_MSG("[MIOS32_CAN_MIDI_PackageSend] 0x%08x\n", package.ALL);
653
 
653
 
654
  while( (error=MIOS32_CAN_MIDI_PacketSend_NonBlocking(header, package)) == -2);
654
  while( (error=MIOS32_CAN_MIDI_PacketSend_NonBlocking(header, package)) == -2);
Line 664... Line 664...
664
/////////////////////////////////////////////////////////////////////////////
664
/////////////////////////////////////////////////////////////////////////////
665
s32 MIOS32_CAN_MIDI_PackageSend_NonBlocking(mios32_midi_package_t package)
665
s32 MIOS32_CAN_MIDI_PackageSend_NonBlocking(mios32_midi_package_t package)
666
{
666
{
667
  s32 error;
667
  s32 error;
668
 
668
 
669
  mcan_header_t header;
669
  mios32_mcan_header_t header;
670
  MIOS32_CAN_MIDI_DefaultHeaderInit(&header);
670
  MIOS32_CAN_MIDI_DefaultHeaderInit(&header);
671
  header.cable = package.cable;
671
  header.cable = package.cable;
672
  header.type = package.type;
672
  header.type = package.type;
673
  error = MIOS32_CAN_MIDI_PacketSend_NonBlocking(header, package);
673
  error = MIOS32_CAN_MIDI_PacketSend_NonBlocking(header, package);
674
 
674
 
Line 701... Line 701...
701
//! \param[in] package MIDI package
701
//! \param[in] package MIDI package
702
//! \return 0: no error
702
//! \return 0: no error
703
//! \return -1: CAN_MIDI device not available
703
//! \return -1: CAN_MIDI device not available
704
//! \note Applications shouldn't call this function directly, instead please use \ref MIOS32_MIDI layer functions
704
//! \note Applications shouldn't call this function directly, instead please use \ref MIOS32_MIDI layer functions
705
/////////////////////////////////////////////////////////////////////////////
705
/////////////////////////////////////////////////////////////////////////////
706
s32 MIOS32_CAN_MIDI_SysexRepackSend(mcan_header_t header, mios32_midi_package_t package)
706
s32 MIOS32_CAN_MIDI_SysexRepackSend(mios32_mcan_header_t header, mios32_midi_package_t package)
707
{
707
{
708
#if MIOS32_CAN_NUM == 0
708
#if MIOS32_CAN_NUM == 0
709
  return -1; // all CANs explicitely disabled
709
  return -1; // all CANs explicitely disabled
710
#else
710
#else
711
 
711
 
Line 776... Line 776...
776
  }
776
  }
777
 
777
 
778
  if(rpk->ctr >= 8){ // a full packet is ready
778
  if(rpk->ctr >= 8){ // a full packet is ready
779
    if (rpk->packet == 0)header.type = 0x4;  // =>Start
779
    if (rpk->packet == 0)header.type = 0x4;  // =>Start
780
    else header.type = 0x6;  // =>Cont
780
    else header.type = 0x6;  // =>Cont
781
    mcan_packet_t p;
781
    mios32_mcan_packet_t p;
782
    // copy id
782
    // copy id
783
    p.id = header.id;
783
    p.id = header.id;
784
    // dlc
784
    // dlc
785
    p.ctrl.dlc = 8;
785
    p.ctrl.dlc = 8;
786
    for(i=0;i<8;i++)p.data.bytes[i] = rpk->buffer[i]; // Copy to packet
786
    for(i=0;i<8;i++)p.data.bytes[i] = rpk->buffer[i]; // Copy to packet
Line 794... Line 794...
794
#endif
794
#endif
795
  }
795
  }
796
  if(rpk->stat.ending == 1){ // this is last packet
796
  if(rpk->stat.ending == 1){ // this is last packet
797
    if (rpk->packet == 0)header.type = 0x4;  // =>Start(special case only one packet stream)
797
    if (rpk->packet == 0)header.type = 0x4;  // =>Start(special case only one packet stream)
798
    else header.type = 0x7;  // =>End
798
    else header.type = 0x7;  // =>End
799
    mcan_packet_t p;
799
    mios32_mcan_packet_t p;
800
    // copy id
800
    // copy id
801
    p.id = header.id;
801
    p.id = header.id;
802
    // dlc
802
    // dlc
803
    p.ctrl.dlc = rpk->ctr;
803
    p.ctrl.dlc = rpk->ctr;
804
    for(i=0;i<rpk->ctr;i++)p.data.bytes[i] = rpk->buffer[i]; // Copy to packet
804
    for(i=0;i<rpk->ctr;i++)p.data.bytes[i] = rpk->buffer[i]; // Copy to packet
Line 822... Line 822...
822
//! \param[in] stream
822
//! \param[in] stream
823
//! \param[in] size of the stream
823
//! \param[in] size of the stream
824
//! \return 0: no error
824
//! \return 0: no error
825
//! \return -1: CAN_MIDI device not available
825
//! \return -1: CAN_MIDI device not available
826
/////////////////////////////////////////////////////////////////////////////
826
/////////////////////////////////////////////////////////////////////////////
827
s32 MIOS32_CAN_MIDI_SysexSend_NonBlocking(mcan_header_t header, u8 *stream, u16 size)
827
s32 MIOS32_CAN_MIDI_SysexSend_NonBlocking(mios32_mcan_header_t header, u8 *stream, u16 size)
828
{
828
{
829
#if MIOS32_CAN_NUM == 0
829
#if MIOS32_CAN_NUM == 0
830
  return -1; // all CANs explicitely disabled
830
  return -1; // all CANs explicitely disabled
831
#else
831
#else
832
  // exit if MCANx port not available
832
  // exit if MCANx port not available
Line 836... Line 836...
836
  if( !size )
836
  if( !size )
837
    return 0;
837
    return 0;
838
 
838
 
839
  // Prepare the Packet
839
  // Prepare the Packet
840
  s32 error;
840
  s32 error;
841
  mcan_packet_t p;
841
  mios32_mcan_packet_t p;
842
  p.ctrl.ALL = 0;
842
  p.ctrl.ALL = 0;
843
  p.data.data_l = 0;
843
  p.data.data_l = 0;
844
  p.data.data_h = 0;
844
  p.data.data_h = 0;
845
 
845
 
846
  // On extended frame adds the src/dst ports
846
  // On extended frame adds the src/dst ports
Line 907... Line 907...
907
//! \param[in] can_port CAN_MIDI module number (0..1)
907
//! \param[in] can_port CAN_MIDI module number (0..1)
908
//! \param[in] package MIDI package
908
//! \param[in] package MIDI package
909
//! \return 0: no error
909
//! \return 0: no error
910
//! \return -1: CAN_MIDI device not available
910
//! \return -1: CAN_MIDI device not available
911
/////////////////////////////////////////////////////////////////////////////
911
/////////////////////////////////////////////////////////////////////////////
912
s32 MIOS32_CAN_MIDI_SysexSend(mcan_header_t header, u8 *stream, u16 size)
912
s32 MIOS32_CAN_MIDI_SysexSend(mios32_mcan_header_t header, u8 *stream, u16 size)
913
{
913
{
914
#if MIOS32_CAN_NUM == 0
914
#if MIOS32_CAN_NUM == 0
915
  return -1; // all CANs explicitely disabled - accordingly no package in buffer
915
  return -1; // all CANs explicitely disabled - accordingly no package in buffer
916
#else
916
#else
917
  s32 error;
917
  s32 error;
Line 957... Line 957...
957
//! \endcode
957
//! \endcode
958
//! If the function returns 0, SysEx bytes will be forwarded to APP_MIDI_NotifyPackage() as well.
958
//! If the function returns 0, SysEx bytes will be forwarded to APP_MIDI_NotifyPackage() as well.
959
//! With return value != 0, APP_MIDI_NotifyPackage() won't get the already processed package.
959
//! With return value != 0, APP_MIDI_NotifyPackage() won't get the already processed package.
960
//! \return < 0 on errors
960
//! \return < 0 on errors
961
/////////////////////////////////////////////////////////////////////////////
961
/////////////////////////////////////////////////////////////////////////////
962
s32 MIOS32_CAN_MIDI_SysExStreamCallback_Init(s32 (*callback_sysex_stream)(mcan_header_t header, u8* stream, u16 size))
962
s32 MIOS32_CAN_MIDI_SysExStreamCallback_Init(s32 (*callback_sysex_stream)(mios32_mcan_header_t header, u8* stream, u16 size))
963
{
963
{
964
#if MIOS32_CAN_NUM == 0
964
#if MIOS32_CAN_NUM == 0
965
  return -1; // all CANs explicitely disabled - accordingly no package in buffer
965
  return -1; // all CANs explicitely disabled - accordingly no package in buffer
966
#else
966
#else
967
  sysex_stream_callback_func = callback_sysex_stream;
967
  sysex_stream_callback_func = callback_sysex_stream;
Line 974... Line 974...
974
//! Installs an optional Direct Midi package Callback callback
974
//! Installs an optional Direct Midi package Callback callback
975
//! If the function returns 0, SysEx bytes will be forwarded to APP_MIDI_NotifyPackage() as well.
975
//! If the function returns 0, SysEx bytes will be forwarded to APP_MIDI_NotifyPackage() as well.
976
//! With return value != 0, APP_MIDI_NotifyPackage() won't get the already processed package.
976
//! With return value != 0, APP_MIDI_NotifyPackage() won't get the already processed package.
977
//! \return < 0 on errors
977
//! \return < 0 on errors
978
/////////////////////////////////////////////////////////////////////////////
978
/////////////////////////////////////////////////////////////////////////////
979
s32 MIOS32_CAN_MIDI_PackageCallback_Init(s32 (*direct_package_callback)(mcan_header_t header, mios32_midi_package_t package))
979
s32 MIOS32_CAN_MIDI_PackageCallback_Init(s32 (*direct_package_callback)(mios32_mcan_header_t header, mios32_midi_package_t package))
980
{
980
{
981
#if MIOS32_CAN_NUM == 0
981
#if MIOS32_CAN_NUM == 0
982
  return -1; // all CANs explicitely disabled - accordingly no package in buffer
982
  return -1; // all CANs explicitely disabled - accordingly no package in buffer
983
#else
983
#else
984
  direct_package_callback_func = direct_package_callback;
984
  direct_package_callback_func = direct_package_callback;
Line 1067... Line 1067...
1067
    if(sysex_unpack[i].stat.ready == 1)
1067
    if(sysex_unpack[i].stat.ready == 1)
1068
      status = MIOS32_CAN_MIDI_SysexUnPack(i, package);
1068
      status = MIOS32_CAN_MIDI_SysexUnPack(i, package);
1069
    if(status == 1)return status;
1069
    if(status == 1)return status;
1070
  }
1070
  }
1071
 
1071
 
1072
  mcan_packet_t p;
1072
  mios32_mcan_packet_t p;
1073
  // Something in the buffer?
1073
  // Something in the buffer?
1074
  if(MIOS32_CAN_RxBufferGet(0, &p.packet) >= 0) {
1074
  if(MIOS32_CAN_RxBufferGet(0, &p.packet) >= 0) {
1075
    // usable structure
1075
    // usable structure
1076
    mcan_header_t header;
1076
    mios32_mcan_header_t header;
1077
    header.id = p.id;
1077
    header.id = p.id;
1078
    // exit if CAN port not available
1078
    // exit if CAN port not available
1079
    if( !MIOS32_CAN_MIDI_CheckAvailable(header.cable) )
1079
    if( !MIOS32_CAN_MIDI_CheckAvailable(header.cable) )
1080
      return 0;
1080
      return 0;
1081
//    //test
1081
//    //test
Line 1176... Line 1176...
1176
        return status;  // no midi package
1176
        return status;  // no midi package
1177
      }
1177
      }
1178
1178
1179
    } else { // Others messages than Sysex
1179
    } else { // Others messages than Sysex
1180
      // prepare header
1180
      // prepare header
1181
      mcan_header_t header;
1181
      mios32_mcan_header_t header;
1182
      header.id = p.id;
1182
      header.id = p.id;
1183
      // data pointer
1183
      // data pointer
1184
      u8* byte = &p.data.bytes[0];
1184
      u8* byte = &p.data.bytes[0];
1185
      // is enhanced packet
1185
      // is enhanced packet
1186
      if(header.is_extended){
1186
      if(header.is_extended){
Line 1223... Line 1223...
1223
}
1223
}
1224
1224
1225
/////////////////////////////////////////////////////////////////////////////
1225
/////////////////////////////////////////////////////////////////////////////
1226
//
1226
//
1227
/////////////////////////////////////////////////////////////////////////////
1227
/////////////////////////////////////////////////////////////////////////////
1228
u32 MIOS32_CAN_MIDI_DefaultHeaderInit(mcan_header_t* header)
1228
u32 MIOS32_CAN_MIDI_DefaultHeaderInit(mios32_mcan_header_t* header)
1229
{
1229
{
1230
#if MIOS32_CAN_NUM == 0
1230
#if MIOS32_CAN_NUM == 0
1231
  return -1; // all CANs explicitely disabled - accordingly no package in buffer
1231
  return -1; // all CANs explicitely disabled - accordingly no package in buffer
1232
#else
1232
#else
1233
  // reset
1233
  // reset