Functions | |
long | can_ioctl (struct file *file, unsigned int cmd, unsigned long arg) |
int ioctl(int fd, int request, ...); the CAN controllers io-control interface More... | |
long can_ioctl | ( | struct file * | file, |
unsigned int | cmd, | ||
unsigned long | arg | ||
) |
int ioctl(int fd, int request, ...); the CAN controllers io-control interface
fd | The descriptor to change properties |
request | special configuration request |
... | traditional a char *argp |
The ioctl function manipulates the underlying device parameters of the CAN special device. In particular, many operating characteristics of character CAN driver may be controlled with ioctl requests. The argument fd must be an open file descriptor.
An ioctl request has encoded in it whether the argument is an in parameter or out parameter, and the size of the argument argp in bytes. Macros and defines used in specifying an ioctl request are located in the file can4linux.h .
The following requests are defined:
CAN_IOCTL_COMMAND
some commands for start, stop and reset the CAN controller chip CAN_IOCTL_CONFIG
configure some of the device properties like acceptance filtering, bit timings, mode of the output control register or the optional software message filter configuration(not implemented yet). CAN_IOCTL_STATUS
request the CAN controllers status CAN_IOCTL_SEND
a single message over the ioctl interface CAN_IOCTL_RECEIVE
poll a receive message CAN_IOCTL_CONFIGURERTR
configure automatic RTR responses(not implemented)The third argument is a parameter structure depending on the request. These are
described in can4linux.h
The following commands are available
CMD_START
calls the target specific can_start_chip function. This normally clears all pending interrupts, enables interrupts and starts the CAN controller by releasing the RESET bit. CMD_STOP
calls the target specific can_stopchip function. This sets only the RESET bit of the CAN controller which will stop working. CMD_RESET
calls the target specific can_chip_reset function. This command also sets the RESET bit of the CAN controller, but additionally initializes CAN bit timing the output control register and acceptance and mask registers. The CAN controller itself stays in the RESET mode until CMD_START is called. CMD_CLEARBUFFERS
clears/empties both the RX fifo of the associated process and the one and only global TX fifo. CMD_CTRL_LED
control on board LEDs The driver defines different LEDs red, gree, yellow are standard, but may be more and each of the LEDS can have a state on or off.The normal way of reinitializing CAN is the following ioctl()-command sequence:
CMD_STOP
CMD_CLEARBUFFERS
CMD_RESET
CMD_START
If the driver is used by more than one application, one should take care that this functionality (like some others) can not be called by any application. Stopping the shared CAN will stop it for all other processes as well. In can4linux the first process opening a device like /dev/canX gets some more privileges marked in the private structure .su as TRUE.
Basic CAN. In the case of using base format identifiers in Basic CAN mode for receiving CAN messages only the low bytes are used to set acceptance code and mask for bits ID.10 ... ID.3
AccCode
and AccMask
are used like specified in the controllers manual for Single Filter Configuration . Both are 4 byte entries. In the case of using base format identifiers for receiving CAN messages also all 4 bytes can be used. In this case two bytes are used for acceptance code and mask for all 11 identifier bits plus additional the first two data bytes. The SJA1000 is working in the Single Filter \ Mode .Example for extended message format
Example for base message format
You have to shift the CAN-ID by 5 bits and two bytes to shift them into ACR0 and ACR1 (acceptance code register)
In case of the base format match the content of bits 0...20 is of no interest, it can be 0x00000 or 0xFFFFF.
can4linux provides direct access to the bit timing registers, besides an implicit setting using the ioctl CONF_TIMING
and fixed values in Kbit/s. In this case ioctl(can_fd, CAN_IOCTL_CONFIG, &cfg); is used with configuration target CONF_BTR
The configuration structure contains two values, val1 and val2 . The following relation to the bit timing registers is used regarding the CAN controller:
(see can4linux.h)