BeckIPCSource


Some sample C code to initialize the CAN controller on Beck's IPC@Chip SC143.


 /*
 // Sample C code - customize as your IPC application
 */
 
 #include <clib.h>
 #include <CAN_API?.H>
 #include <mem.h>
 #include <RTOS.h>
 
 
 void main(void)
 {
     int ret=0;
     int ret2=0;
     CAN_PORT_INIT?  canStru;
     CAN_MSG? can_msg?,m2;
     CAN_RX_FILT? fil;
     CAN_STATUS? st;
     int i=0;
 
     /* fill can_structure? */
     canStru.Rx_Q_Size? = 2;
     canStru.Tx_Q_Size?[0] = 10;
     canStru.Tx_Q_Size?[1] = 17;
     canStru.Tx_Q_Size?[2] = 18;
     canStru.Config.Baud=125;
     canStru.Config.Mask=0x0;
     canStru.fDisable_Rx?=0;
     canStru.Config.Mode=0;
 
      /* configure filter mask to receive all messages */
      fil.Data_Mask?=0xffff;
      fil.Data_Value=0xffff;
      fil.Id_Mask.Normal=0xffff;
      fil.Id_Mask.Extended=0xFFF8;
      fil.Id_Value?.Extended=0xfff8;
      fil.Id_Value?.Normal=0xfff;
 
 
      /* open CAN-Controller */
      ret = CAN_Open_Port?(CAN0_PORT,&canStru);
 
      if (ret != CAN_EC_SUCCESS? ) {
          helper_printf("Fehler: %d  \n\r", ret);
      }   else {
          helper_printf("CAN0 offen\n\r");
      }
 
      /* set RX-Filters */
      ret = CAN_Rx_Filters?(CAN0_PORT,CAN_FILT3,&fil);
      ret = CAN_Rx_Filters?(CAN0_PORT,CAN_FILT2,&fil);
      ret = CAN_Rx_Filters?(CAN0_PORT,CAN_FILT1,&fil);
      if (ret == CAN_EC_SUCCESS? ) {
          helper_printf("Filter ging zu setzen\r\n");
      } else {
          helper_printf("Filter ging nicht zu setzen: %d\r\n",ret);
      }
      /* Build a CAN-Message */
      can_msg?.Id.Normal=0x101<<5;  /* ID left justified */
      can_msg?.Len_Ctrl=8;
 
      /* Device uff machen */
      ret = CAN_Control?(CAN0_PORT,
             CAN_RX_SEL? | CAN_TX1_SEL? | CAN_TX2_SEL? | CAN_TX3_SEL?,        // = enables
             0,        // = disables
             0); // purges
 
      if ( ret != CAN_EC_SUCCESS?) {
          helper_printf("Fehler bei CAN_CONTROL?: %d\r\n");
      } else {
          helper_printf("CAN-Control ging wohl\r\n");
      }
 
      /* Wait for messages and send some messages */
      while(i < 20) {
          ret2 = CAN_Recv?(CAN0_PORT,&m2,200);
          if ( ret2 == CAN_EC_SUCCESS?) {
              helper_printf("Empf: 0x%x\r\n",m2.Id.Normal>>5);
          } else {
              helper_printf("Nix da: %d\r\n",ret2);
          }
          ret = CAN_Send?(CAN0_PORT,0,&can_msg);
          if (ret != CAN_EC_SUCCESS?) {
             helper_printf("Fehler beim  Senden: %d\n\r",ret);
          } else {
             helper_printf("gesendet\n\r");
          }
          i++;
      }
 
      helper_printf("\n\rThe end");
 
      /* Let's close the can port */
      CAN_Close_Port?(CAN0_PORT);
 }

The question marks behind some functions are inserted by the wiki and should be ignored.

Maybe a volunteer wants to translate the German parts ...


Edit BeckIPCSource FrontPage PageList RecentChanges PageHistory