crosscontrol CrossCore XA Manual

Revision: 1.0
PROGRAMMER’S GUIDE Date: Jul 1, 10
Programmer's guide
www.crosscontrol.com
CrossCore XA

CrossCore XA Revision: 1.0
Programmers Guide Date: Jul 1, 10
Contents
o
8.1.Configuration of device interface .....................................................................................42
sscontrol.com
Revision history ...............................................................................................................................3
1.1. Purpose.....................................................................................................................................4
1.Introduction................................................................................................................................4
1.2. Conventions and defines.......................................................................................................4
1.3. References...............................................................................................................................4
1.4. Include files and libraries........................................................................................................4
1.5. Floating point support ............................................................................................................4
2.Debug card................................................................................................................................5
2.1. J14 - Configuration header ...................................................................................................5
2.2. J15 – Connection to CrossCore XA......................................................................................5
2.3. J18 – USB Serialport .................................................................................................................6
2.4. J19 – FPGA................................................................................................................................6
2.5. J20 – Ethernet JTAG ................................................................................................................6
2.6. J25 – ARM JTAG.......................................................................................................................6
2.7. J26 – RS232 ...............................................................................................................................7
2.8. J28 – I2C....................................................................................................................................7
2.9.J29 – RTC Battery.....................................................................................................................7
2.10. SW1 – Factory Reset........................................................................................................7
2.11.SW2 – Bootflash Disable..................................................................................................7
3.CAN Communication Interface...............................................................................................8
3.1. Configuration of device interface .......................................................................................8
3.2. Summary of data types........................................................................................................11
3.3. Interface functions................................................................................................................12
4.Digital I/O Device Interface ...................................................................................................24
4.1. Configuration of device interface .....................................................................................24
4.2. Summary of data types........................................................................................................24
4.3. Interface functions................................................................................................................24
5.Power Device Interface..........................................................................................................29
5.1. Configuration of device interface .....................................................................................29
5.2. Summary of data types........................................................................................................29
5.3. Interface functions................................................................................................................29
5.4. Power signal handling..........................................................................................................34
6.USB Device Interface...............................................................................................................35
6.1. Configuration of device interface .....................................................................................35
6.2. Summary of data types........................................................................................................35
6.3. Interface functions................................................................................................................35
7.Front LED Device Interface......................................................................................................38
7.1. Configuration of device interface .....................................................................................38
7.2. Summary of data types........................................................................................................38
7.3. Interface functions................................................................................................................38
8.Accelerometer Device Interface...........................................................................................42
www.cr

CrossCore XA Revision: 1.0
Programmers Guide Date: Jul 1, 10
8.2. Summary of data types........................................................................................................42
8.3. Interface functions................................................................................................................43
9.Watchdog Device Interface...................................................................................................46
9.1. Configuration of device interface .....................................................................................46
.2. Summary of data types........................................................................................................46
.3.Interface functions................................................................................................................46
9
10. erial Number Broadcast interface........................................................................................49
9
S
11.Technical support....................................................................................................................50
Trademark, etc. ............................................................................................................................50
Revision history
Rev Date Comments
1.0 2010-07-01
www.crosscontrol.com 3

CrossCore XA Revision: 1.0
Programmers Guide Date: Jul 1, 10
1. Introduction
1.1. Purpose
This document contains reference information describing driver calls and APIs used when
developing applications for the CrossCore XA product running the Linux operating system v1.0.0.
For non-platform specific access to driver calls there is a HALIO-library[3]. For CrossControl
specific canapi calls there is a CANAPI-library[5].
A good prior understanding of Linux systems and programming is needed to fully benefit from this
documentation.
1.2. Conventions and defines
Text formats used in this document.
Format Use
Italics Paths, filenames, Product names.
Bolded Command names and important information
Is used to highlight important information.
Common defines used in this document
True Non-zero value
False Zero value
The term CrossCore XA is used to refer both of the device types simultaneously.
1.3. References
[1] CrossCore XA – Software User Guide
[2] Codesourcery Sourcery G++ user manual
[3] CrossCore XA – HALIO
[4] http://openfacts.berlios.de/index-en.phtml?title=Socket-CAN
[5] CrossCore XA – CANAPI
1.4. Include files and libraries
The programmer’s guide contains references to include files needed when programming the device.
Note that these files can be downloaded separately in a development package from CrossControl
web site. This package also includes libraries to use for application development.
1.5. Floating point support
CrossCore XA does not have hardware floating point support, therefore the floating point
calculations are done by software. Codesourcery cross compiler tool chain [2] supports soft floats
and they are also used in CrossCore XA as default floats.
www.crosscontrol.com 4

CrossCore XA Revision: 1.0
Programmers Guide Date: Jul 1, 10
2. Debug card
For connecting and debugging software in CrossCore XA there exist a debug card. The debug card
has several configuration alternatives and connection interfaces accessibility using jumper
configuration.
2.1. J14 - Configuration header
Debug card has several different options that are user configurable. They are shown below.
Pins First option Second option
1 – 2
3 – 4 USB Serial port
DSUB Serial port
5 – 6 JTAG Debug JTAG Boundary scan
7 – 8 Enable Bootflash Disable Bootflash
9 – 10 No factory reset Factory reset
2.2. J15 – Connection to CrossCore XA
J15 is used to connect debug card to actual CrossCore XA hardware with a ribbon cable provided
with the debug card.
www.crosscontrol.com 5

CrossCore XA Revision: 1.0
Programmers Guide Date: Jul 1, 10
2.3. J18 – USB Serialport
To connect to debug console, either USB or DSUB9 serial port can be used. J18 is for the USB –
serial port. It requires external FT232 (or similar.) USB to RS232 – converter. USB and DSUB9
serial port cannot be used at the same time.
PIN DESC
1 GND
2 N/C
3 VDD +5V
4 TX
5 RX
6 N/C
2.4. J19 – FPGA
J19 provides interface to reprogram FPGA in CrossCore XA.
PIN DESC. PIN DESC.
1 GND 2 2.5V
3 GND 4 FPGA TMS
5 GND 6 FPGA TCK
7 GND 8 FPGA TDO
9 GND 10 FPGA TDI
11 GND 12 N/C
13 GND 14 N/C
2.5. J20 – Ethernet JTAG
The Ethernet JTAG is solely used for service related purposes
2.6. J25 – ARM JTAG
J25 is standard JTAG used for debuging software run by CPU.
PIN DESC. PIN DESC.
1 3.3V 2 3.3V
3 CPU NTRST 4 GND
5 CPU TDI 6 GND
7 CPU TMS 8 GND
9 CPU TCK 10 GND
11 CPU RTCK 12 GND
13 CPU TDO 14 GND
15 NRST 16 GND
17 N/C 18 GND
19 N/C 20 GND
www.crosscontrol.com 6

CrossCore XA Revision: 1.0
Programmers Guide Date: Jul 1, 10
2.7. J26 – RS232
J26 is standard DBUS RS232 – serial port for debug console. It’s alternative for J18 and they
cannot be used at the same time.
PIN DESC.
2 TX
3 RX
5 GND
REST N/C
2.8. J28 – I2C
I2C can be debugged via J28.
PIN DESC.
1 3.3V
2 SCL
3 SDA
4 GND
2.9. J29 – RTC Battery
RTC battery voltage can be measured here.
PIN DESC.
1 BATT+
2 GND
2.10. SW1 – Factory Reset
Factory reset can be activated by pressing this switch when powering up the device. After turning
power on for the device, the switch can be released. Factory reset will go through and device will
boot to normal operation mode once the factory reset is over.
Factory reset will remove all the data from /usr/local/ and /media/cf/.
Warning: After factory reset device will generate new SSH keys and do other initialization, that if
not done correctly may cause device not to function properly, so do not cut the power during this
state and wait until unit indicates boot completion by changing status LED to green.
2.11. SW2 – Bootflash Disable
In case of the device software being corrupted so badly that even backup system won’t work, the
device can be forced to internal Romboot mode where it can be reprogrammed via Serial – or USB
– port. Press Bootflash disable – switch when powering up the device and device will enter the
Romboot mode. After connecting power, the button can be released.
www.crosscontrol.com 7

CrossCore XA Revision: 1.0
Programmers Guide Date: Jul 1, 10
3. CAN Communication Interface
The CAN Communication interface enables the caller to receive messages from and send messages
to the CAN interfaces on the CrossCore XA device. The CAN communication is handled over the
SocketCAN interface, which is a method to use standard socket API functions for CAN
communication [4].
3.1. Configuration of device interface
The device node files for the two CAN interfaces are can0 and can1, which should be shown when
listing all network interfaces with the ifconfig command. The device driver is implemented as
loadable kernel modules, can_dev.ko, xilinx.ko and xilinx_platform.ko. In addition, there are at
least two CAN protocol modules providing access to the CAN protocol interface. A script handles
the loading of the kernel modules upon start-up.
When device has finished its start-up, the CAN driver modules are loaded as a part of the kernel.
This can be checked via terminal access using lsmod command:
# lsmod | egrep “can|xilinx”
can_raw 7552 0
can 23656 1 can_raw
xilinx_platform 2848 0
xilinx 6080 1 xilinx_platform
can_dev 15616 1 xilinx
Since the driver is compiled as modules, unnecessary protocols may be removed or new modules
inserted according to user needs.
The CAN bus itself is not initialized during start-up, it only loads the drivers. Before any
communications can be executed, user must set correct bus speed (as an example 250kbit/s) by
first writing value into bitrate parameter:
# echo 250000 > /sys/class/net/can0/can_bittiming/bitrate
and then setting interface up with ifconfig:
# ifconfig can0 up
After this, ifconfig should show can0 as a network interface:
# ifconfig
can0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00
UP RUNNING NOARP MTU:16 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:10
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Interrupt:49
Same applies to the second CAN interface by changing can0 to can1.
www.crosscontrol.com 8

CrossCore XA Revision: 1.0
Programmers Guide Date: Jul 1, 10
3.1.1. Selecting CAN driver operation modes
Starting from SW release 0.4.0.0, there are two different operation modes available for the CAN
driver xilinx.ko: accurate mode and rapid mode.
In accurate mode, received messages are handled one by one, which consumes more CPU time, but
ensures accurate timestamps of received CAN frames. This mode is recommended if busload is low
and/or there is a need to have as accurate timing as possible.
In rapid mode, received messages are buffered on the CAN controller and handled in groups. This
mode reduces CPU load, but since messages are stored for a while on the CAN controller, the
resulting timestamps are affected by this period.
Rapid mode is enabled with a module parameter given to the module at load time. Polling period is
given in parameter as micro seconds.
Warning: If period is set too long it will cause messages to be lost. What is too long depends on
bus speed and bus load.
# modprobe xilinx rapidmode=500
By default, the driver uses accurate mode. Operation mode cannot be changed during runtime. The
same operation mode is always used for both CAN interfaces.
3.1.2. Bus recovery options
There are two options for implementing bus recovery after busoff has occurred: manual and
automatic.
Manual recovery is initiated by writing a non-zero value to can_restart variable under sysfs:
echo 1 > /sys/class/net/can0/can_restart
Bus restart is then scheduled through kernel and implemented through can-core.
In automatic bus recovery, can-core detects state changes and re-initializes controller after
specified time period.
Automatic bus recovery from busoff state is turned off by default. User can turn it on via sysfs
setting wanted restart period in milliseconds into can_restart_ms variable. For example 100ms
restart period for can0 is set from command line like this:
ifconfig can0 down
echo 100 > /sys/class/net/can0/can_restart_ms
ifconfig can0 up
Same commands apply for can1 by replacing can0 appropriately. Period is possible to set as
needed. Value zero turns automatic bus recovery off.
Warning: Enabling automatic bus recovery may disturb other nodes on bus, if CAN interface is
incorrectly initialized.
www.crosscontrol.com 9

CrossCore XA Revision: 1.0
Programmers Guide Date: Jul 1, 10
3.1.3. Error interrupt options
Error interrupts are disabled by default. Enabled them by giving module parameter errorirq=1
during module loading. By enabling error interrupts user can receive error frames. Bus off errors
will come through even if the error interrupts are not enabled.
# modprobe xilinx errorirq=1
Warning: Enabling error interrupts and sending frames when module is not connected to active
bus may cause CAN acknowledge errors to overload CPU. User caution required. It is
recommended to avoid sending, until one frame is received.
3.1.4. Silent mode option
The Xilinx platform module implements a common listen-only mode for both CAN interfaces. In
this mode, CAN controller only listens to the CAN receive line without acknowledging the received
messages. Sending messages is also disabled. This mode is useful for bus loggers and also needed
for undisturbed bus communication under automatic baud rate detection.
Silent mode can be enabled or disabled for each CAN interface using module parameter silent with
xilinx_platform driver.
# modprobe xilinx_platform silent=0x3
Silent value is an interpret bitwise value for setting each CAN interface to listen-only mode or
normal mode. Lowest bit is for can0 and second bit is for can1. Bit value ‘1’ is for listen-only and ‘0’
is for normal operation mode. In example above, both interfaces are set to listen-only mode.
3.1.5. Automatic baud rate detection
Automatic baud rate detection is implemented as a part of canapi library. Automatic baud rate
detection is started by calling:
CanHandle Handle = CanOpen("can1");
CanSetBaudrate(Handle, CCCAN_BAUDRATE_AUTO);
Because canapi is running on top of SocketCAN and using a socket API, there are three limitations
in calling automatic baud rate detection:
1. CanSetBaudrate can be called only once with CCCAN_BAUDRATE_AUTO after driver
modules are loaded.
2. Other access to CAN interface under detection is disturbed by detection (interface is
dropped during detection).
3. Both silent mode and error interrupts must be enabled in drivers for successful baud rate
detection.
See CC CANAPI documentation[5] for more details.
Detection speed depends on actual baud rate as well as bus load. Once the baud rate has been
found the baud rate detection is disabled.
www.crosscontrol.com 10

CrossCore XA Revision: 1.0
Programmers Guide Date: Jul 1, 10
3.2. Summary of data types
The following data types are needed to access SocketCAN interface from user application. Note that
this list is only partial set of all socket features.
SocketCAN uses its own protocol family PF_CAN coexisting with others like PF_INET.
Communication is done analogue to the use of Internet Protocol via Sockets. The protocol family
provide the structures to enable different protocols on the bus.
CrossCore XA module support by default raw sockets for direct communication and broadcast
manager (bcm) for sending messages periodically or realizing complex message filters.
Definitions for particular protocols of the protocol family PF_CAN:
Define Description
CAN_RAW Raw sockets
CAN_BCM Broadcast manager
CAN_TP16 VAG transport protocol v1.6
CAN_TP20 VAG transport protocol v2.0
CAN_MCNET Bosch MCNet
CAN_ISOTP ISO 15765-2
Enum value defining raw socket protocol level options for setsockopt:
Define Description
CAN_RAW_FILTER = 1 Set 0..n can_filter(s)
CAN_RAW_ERR_FILTER Set filter for error frames
CAN_RAW_LOOPBACK Set local loopback (echo,
default: on)
CAN_RAW_RECV_OWN_MSGS Set receiving of own messages
(default: off)
For socket level options to use with setsockopt, see sys/socket.h.
Definitions for CAN_ID description flags:
Define Description
CAN_EFF_FLAG Extended identifier flag is set
CAN_RTR_FLAG Remote transmission request
CAN_ERR_FLAG Error frame
The interface uses following struct to transfer data to and from the driver:
struct can_frame {
canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */
__u8 can_dlc; /* data length code: 0 .. 8 */
__u8 data[8] __attribute__((aligned(8))); /* payload */
};
www.crosscontrol.com 11

CrossCore XA Revision: 1.0
Programmers Guide Date: Jul 1, 10
The interface uses following struct to define sockaddr structure for CAN sockets:
struct sockaddr_can {
sa_family_t can_family;
int can_ifindex;
union {
/* transport protocol class address information (e.g. ISOTP) */
struct { canid_t rx_id, tx_id; } tp;
/* reserved for future CAN protocols address information */
} can_addr;
};
The interface to the uses following struct to transfer define CAN id base filter:
struct can_filter {
canid_t can_id;
canid_t can_mask;
};
3.3. Interface functions
SocketCAN access is similar to network socket. Only some basic functionality needed for socket
access is introduced here. Please see general Linux socket API documentation for further
information regarding socket communication.
Function Description
socket Creates a communication socket.
bind Binds socket to a name.
setsockopt Sets socket options.
select Tests given socket(s) for accessibility.
read Reads from a socket.
recvfrom Receives from a socket (same as read).
write Writes to a socket.
sendto Sends to a socket (same as write).
connect Creates a connection.
listen Waits for incoming connection.
accept Accepts a connection from client.
close Closes a socket.
3.3.1. socket
Description
Create an endpoint for communication.
Include files
#include <sys/socket.h>
www.crosscontrol.com 12

CrossCore XA Revision: 1.0
Programmers Guide Date: Jul 1, 10
Syntax
int socket(
int domain,
int type,
int protocol
)
Parameters
domain Specifies communication domain
type Specifies socket type
protocol Specifies a particular protocol to be used with the socket
Return value
Returns a non-negative integer, the socket file descriptor, on success. In case of errors, -1 is
returned and errno is set appropriately.
Example
The following example shows how to use SocketCAN for initial scope of CAN_RAW socket
communication. Note that this is an example; all possible errors are not handled.
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <linux/can.h>
#include <linux/can/raw.h>
#include <string.h>
/* Define constants, if not defined in the headers */
#ifndef PF_CAN
#define PF_CAN 29
#endif
#ifndef AF_CAN
#define AF_CAN PF_CAN
#endif
/* ... */
/* Somewhere in your app */
/* Create the socket */
int skt = socket( PF_CAN, SOCK_RAW, CAN_RAW );
/* Locate the interface you wish to use */
struct ifreq ifr;
strcpy(ifr.ifr_name, "can0");
ioctl(skt, SIOCGIFINDEX, &ifr); /* ifr.ifr_ifindex gets filled
* with that device's index */
www.crosscontrol.com 13

CrossCore XA Revision: 1.0
Programmers Guide Date: Jul 1, 10
/* Select that CAN interface, and bind the socket to it. */
struct sockaddr_can addr;
addr.can_family = AF_CAN;
addr.can_ifindex = ifr.ifr_ifindex;
bind( skt, (struct sockaddr*)&addr, sizeof(addr) );
/* Send a message to the CAN bus */
struct can_frame frame;
frame.can_id = 0x123;
strcpy( &frame.data, "foo" );
frame.can_dlc = strlen( &frame.data );
int bytes_sent = write( skt, &frame, sizeof(frame) );
/* Read a message back from the CAN bus */
int bytes_read = read( skt, &frame, sizeof(frame) );
3.3.2. bind
Description
Bind a name to a socket.
Include files
#include <sys/socket.h>
Syntax
int bind(
int socket,
const struct sockaddr *address,
socklen_t address_len
)
Parameters
fd Socket descriptor
address Pointer to sockaddr structure containing address to be bound
address_len Specifies the length of sockaddr structure
Return value
Returns zero on success. In case of errors, -1 is returned and errno is set appropriately.
Example
See example of socket.
3.3.3. setsockopt
Description
Set socket options
Include files
#include <sys/socket.h>
www.crosscontrol.com 14

CrossCore XA Revision: 1.0
Programmers Guide Date: Jul 1, 10
Syntax
int setsockopt(
int socket,
int level,
int option_name,
const void *option_value,
socklen_t option_len
)
Parameters
socket Socket file descriptor
level Protocol level (SOL_CAN_RAW or similar)
option_name Option to set, see definitions in 2.2
option_value Pointer to new value
option_len Specifies length of option_value
Return value
Returns zero on success. In case of errors, -1 is returned and errno is set appropriately.
Example
This example shows how to disable filters and loopback feature using setsockopt.
int s = socket(PF_CAN, SOCK_RAW, CAN_RAW);
setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0);
if (opt == 'B') {
const int loopback = 0;
setsockopt(s, SOL_CAN_RAW, CAN_RAW_LOOPBACK,
&loopback, sizeof(loopback));
}
3.3.4. select
Description
Performs synchronous I/O multiplexing. Select is used to examine several file descriptors at once to
determine if some of them is ready for reading, ready for writing or have an exceptional condition
pending.
Include files
#include <sys/select.h>
Syntax
int select(
int nfds,
fd_set *readfds,
fd_set *writefds,
fd_set *errorfds,
struct timeval *timeout
)
www.crosscontrol.com 15

CrossCore XA Revision: 1.0
Programmers Guide Date: Jul 1, 10
Parameters
nfds Specifies sizes of fd_set type parameters
readfds Read file descriptor list
writefds Write file descriptor list
errorfds Error file descriptor list
timeout Specifies maximum wait time for select to block
Return value
Returns zero on success. In case of errors, -1 is returned and errno is set appropriately.
Example
This example shows how to use select to determine readability of sockets and how data is received
from sockets using recvfrom().
fd_set rdfs;
int s[MAXDEV];
int currmax = 1; /* we assume at least one can bus */
int running = 1
int nbytes, i;
struct sockaddr_can addr;
struct can_filter rfilter;
struct can_frame frame;
/* … Initialize sockets and set currmax to correct value in here … */
while (running) {
FD_ZERO(&rdfs);
for (i=0; i<currmax; i++)
FD_SET(s[i], &rdfs);
if ((ret = select(s[currmax-1]+1, &rdfs, NULL, NULL, NULL)) < 0) {
perror("select");
running = 0;
continue;
}
for (i=0; i<currmax; i++) { /* check all CAN RAW sockets */
if (FD_ISSET(s[i], &rdfs)) {
socklen_t len = sizeof(addr);
int idx;
if ((nbytes = recvfrom(s[i], &frame,
sizeof(struct can_frame), 0,
(struct sockaddr*)&addr, &len)) < 0) {
perror("read");
return 1;
}
www.crosscontrol.com 16

CrossCore XA Revision: 1.0
Programmers Guide Date: Jul 1, 10
if (nbytes < sizeof(struct can_frame)) {
fprintf(stderr, "read: incomplete CAN frame\n");
return 1;
}
}
}
}
3.3.5. read
Description
Read from file.
Include files
#include <unistd.h>
Syntax
ssize_t read(
int fd,
void *buf,
size_t nbyte
)
Parameters
fd File descriptor
buf Points to buffer where the data should be stored
nbyte Specifies buffer length in bytes
Return value
Returns a non-negative integer indicating the number of bytes actually read. In case of errors, -1 is
returned and errno is set appropriately.
Example
See example of socket.
3.3.6. recvfrom
Description
Receive a message from a socket. If no messages are available, it shall block until a message arrives.
Include files
#include <sys/socket.h>
www.crosscontrol.com 17

CrossCore XA Revision: 1.0
Programmers Guide Date: Jul 1, 10
Syntax
ssize_t recvfrom(
int socket,
void *buffer,
size_t length,
int flags,
struct sockaddr *address,
socklen_t *address_len
)
Parameters
socket Socket file descriptor
buffer Points to buffer where the message should be stored
length Specifies the length of receive buffer
flags Specifies the type of message reception
address A null pointer or points to a sockaddr structure in which the sending address is to
be stored
address_len Specifies the length of address structure
Return value
Returns length of the message in bytes on success. In case of errors, -1 is returned and errno is set
appropriately.
Example
See example of select.
3.3.7. write
Description
Write on file.
Include files
#include <unistd.h>
Syntax
int write(
int fd,
const void *buf,
size_t nbyte
)
Parameters
Fd File descriptor
Buf Points to buffer containing data to write
Nbyt Specifies write size in bytes
www.crosscontrol.com 18

CrossCore XA Revision: 1.0
Programmers Guide Date: Jul 1, 10
Return value
Returns non-negative integer indicating the number of bytes actually written. In case of errors, -1 is
returned and errno is set appropriately.
Example
See example of socket.
3.3.8. sendto
Description
Send a message to a socket.
Include files
#include <sys/socket.h>
Syntax
ssize_t sendto(
int socket,
const void *buffer,
size_t length,
int flags,
const struct sockaddr *to,
socklen_t tolen
)
Parameters
socket Socket file descriptor
buffer Points to a buffer containing message to send
length Specifies message length in bytes
flags Specifies the type of message transmission
to Specifies address of the target
tolen Specifies address size
Return value
Returns non-negative integer indicating bytes sent on success. In case of errors, -1 is returned and
errno is set appropriately.
Example
This example shows how to operate bcm socket and send data to it.
int sl, sa, sc;
struct sockaddr_can caddr;
socklen_t caddrlen = sizeof(caddr);
struct ifreq ifr;
struct {
struct bcm_msg_head msg_head;
struct can_frame frame;
} msg;
www.crosscontrol.com 19

CrossCore XA Revision: 1.0
Programmers Guide Date: Jul 1, 10
if((sl = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
perror("inetsocket");
exit(1);
}
/* open “regular” network socket */
saddr.sin_family = AF_INET;
saddr.sin_addr.s_addr = htonl(INADDR_ANY);
saddr.sin_port = htons(PORT);
while(bind(sl,(struct sockaddr*)&saddr, sizeof(saddr)) < 0) {
printf(".");fflush(NULL);
usleep(100000);
}
/* Listen socket for a connection */
if (listen(sl,3) != 0) {
perror("listen");
exit(1);
}
while (1) {
sa = accept(sl,(struct sockaddr *)&clientaddr, &sin_size);
if (sa > 0 ){
if (fork())
close(sa);
else
break;
}
}
/* open BCM socket */
if ((sc = socket(PF_CAN, SOCK_DGRAM, CAN_BCM)) < 0) {
perror("bcmsocket");
return 1;
}
/* Connect socket */
if (connect(sc, (struct sockaddr *)&caddr, sizeof(caddr)) < 0) {
perror("connect");
return 1;
}
caddr.can_family = PF_CAN;
caddr.can_ifindex = ifr.ifr_ifindex;
while(1){
FD_ZERO(&readfds);
FD_SET(sc, &readfds);
FD_SET(sa, &readfds);
www.crosscontrol.com 20
Table of contents
Popular Motherboard manuals by other brands

Freescale Semiconductor
Freescale Semiconductor MED-SPI quick start guide

Intel
Intel DP965LT specification

National Semiconductor
National Semiconductor UCD3138ACCEVM149 user guide

ASROCK
ASROCK A770CROSSFIRE - V1.0 user manual

Microchip Technology
Microchip Technology MCP1252 user guide

LAPIS Semiconductor
LAPIS Semiconductor ML620Q151A user manual