TWR54418 BSP,  flexcan API

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

TWR54418 BSP,  flexcan API

876 Views
francois_boucha
Contributor III

Target:   M54418 TWR

Target    Kernel Version:ltib-modelo-20100709

Host:      ubuntu 10.10


Our development team is fairly new to the uC Linuc environment.  So far we have acheive a the 'welcome' project (on CW10.0) on the target board but some questions comes to mind regarding the BSP (flexcan for instance):

- where to find the drivers (socket can for instance)
- Which header file to use the BSP, in other words which API to start coding?



 regards,



FB

Labels (1)
0 Kudos
1 Reply

402 Views
francois_boucha
Contributor III

One way is to use the socketCAN On the linux 2.6.29 Kernel.

 

For setting the bit rate this command is typed to the target's terminal. ex: 1Mbps:
$ echo 1000000 > /sys/devices/platform/mcf-flexcan.1/net\:can1/can_bittiming/bitrate

 

Then for enabling the can interface:

$ ifconfig can1 ip

 

Then you can program a linux application using the open source socket can I/F.  It is like coding with the socket API but it is on the  CAN bus.

 

So far the experiences has gone OK except when stress testing the CAN interface, the Whole system seems to reboot when running the following CAN loop program. :

 

while(numofmsg){        nbytes = write(can_socket, &tx_frame, sizeof(struct can_frame));        numofmsg--;            // recv()        nbytes = recv(can_socket, &rx_frame, sizeof(struct can_frame),  MSG_DONTWAIT );        // ...}

 

 

now prior to reboot the following message is displayed via the serialk terminal:

 

     Transmission code active 0xc080000
     reg->caniflg = 0x3
     ** MB[1] : CODE=0x6 LEN=8
     ** RX
     OVERRUN
     DATA[0]                       

                  = 0x4c
     DATA[1]                                         = 0x2e
     DATA[2]                                         = 0x1
     DATA[3]                                         = 0x22
     DATA[4]                                         = 0x0
     DATA[5]                                         = 0x0
     DATA[6]                                         = 0x72
     DATA[7]                                         = 0x14
     ID = 0x0
 
    Transmission code active 0xc080000
    reg->caniflg = 0x3
     ** MB[1] : CODE=0x6 LEN=8
     ** RX
     OVERRUN
     DATA[0]                                         = 0x4c
     DATA[1]                                         = 0x2e
     DATA[2]                                         = 0x1
     DATA[3]                                         = 0x42
     DATA[4]
   * incomplete received data printing...
   * THEN reboot HERE...

 

every time I looked it rebooting either in the middle of DATA[4] or DATA[3].

 

 

 

Any ideas why?

 

thanks,

 

Francois

 

P.S.socket creation code    // create socket    if ((can_socket = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {        int err_num = errno;        if(verbose)fprintf(stderr, "CAN_Open_Socket() socket() %d", err_num);        return -1; // error socket    }       // bind to specific address       strcpy(ifr.ifr_name, "can1" );    ioctl(can_socket, SIOCGIFINDEX, &ifr);    addr.can_family = AF_CAN;    addr.can_ifindex = ifr.ifr_ifindex;           // bind    if (bind(can_socket, (struct sockaddr*) &addr, sizeof(addr)) != 0) {        int err_num  = errno;        if(verbose)fprintf(stderr,"CAN_Open_Socket() bind() %d", err_num);        return -1; // error socket    }

 

 

0 Kudos