background image

 

 

CrossCore XA 

Revision: 1.0 

Programmers Guide 

Date: Jul 1, 10 

 

7.3.1.

 

open 

Description 

Opens the front LED device. The call will return a file descriptor used in subsequent calls such as 
write() or close()

Include files 

#include <fctnl.h> 

Syntax 

int open( 
    const char *pathname, 
    int flags 
 ) 

Parameters 

pathname 

Path to the device file 

flags 

Parameter flag must include one of the following access modes: O_RDONLY, 
O_WRONLY or O_RDWR 

Return value 

The new file descriptor if successful. In case of errors, -1 is returned and errno is set appropriately. 

Example 

See example of write

7.3.2.

 

close 

Description 

Closes the file descriptor. 

Include files 

#include <unistd.h> 

Syntax 

 int close( 
    int fd 
 ) 

Parameters 

fd   File 

descriptor 

Return value 

Returns zero on success. In case of errors, -1 is returned and errno is set appropriately. 

Example 

See example of write

www.crosscontrol.com 

39

Summary of Contents for CrossCore XA

Page 1: ...Revision 1 0 PROGRAMMER S GUIDE Date Jul 1 10 Programmer s guide www crosscontrol com CrossCore XA ...

Page 2: ... 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 func...

Page 3: ...ace 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 ...

Page 4: ...n 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 contai...

Page 5: ...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...

Page 6: ...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 ...

Page 7: ...ill 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 LE...

Page 8: ...aded 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 u...

Page 9: ...y 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_...

Page 10: ...rameter 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...

Page 11: ...on 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_...

Page 12: ...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...

Page 13: ...cketCAN 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 ...

Page 14: ... 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 Retu...

Page 15: ...opriately 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...

Page 16: ...s 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 p...

Page 17: ... 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 ...

Page 18: ... 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 i...

Page 19: ...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 ...

Page 20: ...lush 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...

Page 21: ...struct sockaddr caddr sizeof caddr 3 3 9 connect Description Attempt to make a connection on socket Include files include sys socket h Syntax int connect int socket const struct sockaddr address socklen_t address_len Parameters Socket Socket file descriptor address Points to a sockaddr structure containing the peer address address_len Specifies the length of the address argument Return value Retur...

Page 22: ...1 accept Description Accept a new connection on a socket Accept may be called to a socket that was created with socket has been bound to an address with bind and has issued a successful call to listen Include files include sys socket h Syntax int accept int socket struct sockaddr address socklen_t address_len Parameters socket Socket file descriptor address Either a null pointer or a pointer to a ...

Page 23: ...rrors 1 is returned and errno is set appropriately Example See example of send 3 3 12 close Description Closes the file descriptor Include files include unistd h Syntax int close int fd Parameters Fd File descriptor Return value Returns zero on success In case of errors 1 is returned and errno is set appropriately Example close socket www crosscontrol com 23 ...

Page 24: ... CROSS_DIG_IOC_SET 16 bit unsigned integer Upper 8 bit is the output pin number 1 8 Lower 8 bit is the state value of the pin 0 or 1 CROSS_DIG_IOC_GET 8 bit unsigned integer Number of input pin to get 1 8 CROSS_DIG_IOC_GET_ALL Returns 16 bit unsigned integer Upper 8 bits contain values for connector 1 Lower 8 bits contain values for connector 2 In both 8 bits lowest 4 bits are values of input pins...

Page 25: ... Include files include unistd h Syntax int close int fd Parameters fd File descriptor Return value Returns zero on success In case of errors 1 is returned and errno is set appropriately Example See example of ioctl 4 3 3 read Description Reads data from the digital I O device Note that the returned data is in a textual format that shows the status of all the digital in signals described in the I O...

Page 26: ...This example shows how to open a device dev digio and read data Note that this example is intended to show how to make the different function calls All possible errors are not handled int fd result unsigned char buffer 1000 Open device fd open dev digio O_NONBLOCK O_RDWR if fd 0 printf open OK n else printf open FAILED n Read data from the device result read fd buffer 512 if result 0 printf read E...

Page 27: ... success the number of written bytes is returned In case of errors 1 is returned and errno is set appropriately Example Note that this example is intended to show how to make the different function calls All possible errors are not handled int fd retval unsigned char buffer 1000 fd open dev digio O_WRONLY if fd 0 perror Unable to open device return 1 Set the output 1 to 0 memset buffer 0 100 memcp...

Page 28: ... Request Code of the request Argp Used for transferring data in the ioctl call In this case it is an integer Return value Returns a positive value on success In case of errors 1 is returned and errno is set appropriately Example This example shows a range of different configuration settings by calling ioctl All possible errors are not handled since the purpose of the example is to explain how the ...

Page 29: ...WR_PIN to get CROSS_PWR_IOC_GET_PWRFAIL_ST ATUS Return either true if the pwr fail is active or false if the pwr fail status is not active CROSS_PWR_IOC_GET_OVERVOLT AGE_STATUS Return either true if the overvoltage is active or false if the overvoltage is not active CROSS_PWR_IOC_GET_SIGNAL Return status of which event caused the signal Power down is bit 0 and over voltage is bit 2 CROSS_PWR_IOC_S...

Page 30: ...rameter flag must include one of the following access modes O_RDONLY O_WRONLY or O_RDWR Return value The new file descriptor if successful In case of errors 1 is returned and errno is set appropriately Example See example of ioctl 5 3 2 close Description Closes the file descriptor Include files include unistd h Syntax int close int fd Parameters fd File descriptor Return value Returns zero on succ...

Page 31: ...m the PWR device Return value On success the number of read bytes is returned In case of errors 1 is returned and errno is set appropriately Example This example shows how to open a device dev cross_pwr_io and read data Note that this example is intended to show how to make the different function calls All possible errors are not handled int fd result unsigned char buffer 1000 Open device fd open ...

Page 32: ...vice Return value On success the number of written bytes is returned In case of errors 1 is returned and errno is set appropriately Example Note that this example is intended to show how to make the different function calls All possible errors are not handled int fd retval fd open dev cross_pwr_io O_WRONLY if fd 0 perror Unable to open cross_pwr_io return 1 Set the output 0 Eth to 0 memset resp_bu...

Page 33: ...SS_PWR_IOC_SET_PWR_STATE Set power state of specific subsystem Include files include sys ioctl h include pwr io h Syntax int ioctl int fd int request void argp Parameters fd The file descriptor request The code of the request argp Used for transferring data in the ioctl call Return value Returns a positive value on success In case of errors 1 is returned and errno is set appropriately Example This...

Page 34: ... cross_pwr_io device s ioctl call CROSS_IOC_SET_SIGNAL The handler receives reason for the signal as an argument Argument bitfield Define Description POWER_DOWN_SIGNAL Power down occurred OVERVOLTAGE_SIGNAL Overvoltage occurred It is possible to have only one or both reasons active at the same time especially in case of overvoltage Example This example shows a very simple signal handler All possib...

Page 35: ... CROSS_USB_IOC_GET_SIGNAL Return status of which event caused the signal USB connected is bit 0 CROSS_USB_IOC_SET_SIGNAL Set the signal handler that is called when power signals change state Argument is pointer to set_usb_signal_struct typedef struct uint32 sig Signal number to be used uint32 pid Process ID of the handler set_usb_signal_struct 6 3 Interface functions open Opens the I O device clos...

Page 36: ... errno is set appropriately Example See example of ioctl 6 3 2 close Description Closes the file descriptor Include files include unistd h Syntax int close int fd Parameters fd File descriptor Return value Returns zero on success In case of errors 1 is returned and errno is set appropriately Example See example of ioctl www crosscontrol com 36 ...

Page 37: ... pid and signal number to zero Include files include sys ioctl h include usb io h Syntax int ioctl int fd int request void argp Parameters fd File descriptor request Code of the request argp Used for transferring data in the ioctl call Return value Returns a positive value on success In case of errors 1 is returned and errno is set appropriately Example This example shows the different configurati...

Page 38: ...bit unsigned integer Upper 8 bit contains the LED color to control 0 RED 1 GREEN 2 AMBER Lower 8 bit containing the LED flash interval in Hertz 0 off 1 50 valid Hertz 50 constantly on CROSS_DIG_IOC_SET_CAN0_LED Set state of the CAN0 LED 16 bit unsigned integer Upper 8 bit contains the LED color to control 0 RED 1 GREEN 2 AMBER Lower 8 bit containing the LED flash interval in Hertz 0 off 1 50 valid...

Page 39: ... Parameter flag must include one of the following access modes O_RDONLY O_WRONLY or O_RDWR Return value The new file descriptor if successful In case of errors 1 is returned and errno is set appropriately Example See example of write 7 3 2 close Description Closes the file descriptor Include files include unistd h Syntax int close int fd Parameters fd File descriptor Return value Returns zero on s...

Page 40: ...s fd File descriptor buf Code of the request count Number of bytes to write to the front LED device Return value On success the number of written bytes is returned In case of errors 1 is returned and errno is set appropriately Example Note that this example is intended to show how to make the different function calls All possible errors are not handled int fd retval fd open dev frontled O_WRONLY i...

Page 41: ... int request void argp Parameters fd File descriptor request Code of the request argp Used for transferring data in the ioctl call In this case it is an integer Return value Returns a positive value on success In case of errors 1 is returned and errno is set appropriately Example This example shows how to operate the frontled by calling ioctl Note that this example is intended to show how to make ...

Page 42: ...ged int32 trigger_client_pid If this is set nonzero it is taken as a pid to send a signal to when acceleration surveillance triggers int32 trigger_signo If trigger_client_pid 0 this is the signal to send uint8 trigger_signal_latch Everytime signal should be sent this latch is examined If the value is zero signal is sent and this flag is raised In order to receive signal again this flag has to be s...

Page 43: ...lerometer device close Closes the accelerometer device mmap Maps accelerometer device into memory 8 3 1 open Description Opens the accelerometer device The call will return a file descriptor used in subsequent calls such as mmap close Include files include fctnl h Syntax int open const char pathname int flags Parameters pathname Path to the device file flags Parameter flag must include following a...

Page 44: ... Syntax void mmap void start size_t length int prot int flags int fd off_t offset Parameters start Start of the virtual address NULL Let kernel choose length Length of the mapped memory prot Desired memory protections flags Flags to determne whether updates to the mapping are visible to other processes mapping the same region fd File descriptor offset Offset of the file where mapping should start ...

Page 45: ...e modules 0 define TRIGGER_SIGNAL SIGUSR2 void handle_trigger int sno printf Trigger signal received n fd open dev accelerometer O_RDWR O_SYNC modules mmap 0 mmapsize PROT_READ PROT_WRITE MAP_SHARED MAP_LOCKED fd 0 signal TRIGGER_SIGNAL handle_trigger modules update 1 modules trigger_client_pid getpid modules trigger_signo TRIGGER_SIGNAL modules trigger_signal_latch 0 sleep 30 modules trigger_clie...

Page 46: ...ymore then the wdt should be restarted Wdt is started at start up every time if the watchdog timeout is something other than zero Watchdog timeout is 16 seconds by default Timeout can be changed from a file etc watchdog_timeout conf Value should be between 0 disabled and 16 9 2 Summary of data types The interface to the Watchdog device doesn t use parameters in ioctl calls 9 3 Interface functions ...

Page 47: ...scriptor Return value Returns zero on success In case of errors 1 is returned and errno is set appropriately Example See example of ioctl 9 3 3 ioctl Description The ioctl function calls are used for accessing the Watchdog The available ioctl operations are summarized in the table below Define Description WDIOC_KEEPALIVE Pat the dog to keep it from waking WDIOC_GETTIMEOUT Get the current watchdog ...

Page 48: ... value on success On error 1 is returned and errno is set appropriately Example This example shows a way for kicking watchdog by calling ioctl All possible errors are not handled since the purpose of the example is to explain how the calls are made int fd result dummy Open device fd open dev watchdog O_RDWR O_NONBLOCK Pat the watchdog result ioctl fd WDIOC_KEEPALIVE dummy www crosscontrol com 48 ...

Page 49: ...re even in another CrossCore XA device if required The message sent is a multicast UDP datagram to address 224 0 0 27 The message contains a char array with three values separated by tabs Serial number Firmware version and Device type The sender IP address is available in datagram headers Example data contents without quotes PR01 tab 0 3 0 tab 0 An example implementation of the data listener is av...

Page 50: ...which the problem arises LED indicator flash patterns CrossCore XA device log files if possible Description of external equipment which is connected to the CrossCore XA Trademark etc 2006 2010 CrossControl AB All trademarks sighted in this document are the property of their respective owners Linux is the registered trademark of Linus Torvalds in the U S and other countries CrossControl AB is not r...

Reviews: