|
int ioctl(int fd, int request, ...); the CAN controllers control interface.
-
Parameters:
-
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:
-
COMMAND some commands for start, stop and reset the CAN controller chip -
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). -
STATUS request the CAN controllers status -
SEND a single message over the ioctl interface -
RECEIVE poll a receive message -
CONFIGURERTR configure automatic rtr responses(not implemented)
The third argument is a parameter structure depending on the request. These are struct Command_par
struct Config_par
struct CanSja1000Status_par
struct ConfigureRTR_par
struct Receive_par
struct Send_par
described in can4linux.h-
Acceptance Filtering
-
Basic CAN. In the case of using standard 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
PeliCAN. For acceptance filtering the entries 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 standard 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 . Bits
mask 31 30 ..... 4 3 2 1 0
code
-------------------------------------------
ID 28 27 ..... 1 0 R +--+-> unused
T
R
-
Returns:
-
On success, zero is returned. On error, -1 is returned, and errno is set appropriately.
-
Example
-
Config_par_t cfg;
volatile Command_par_t cmd;
cmd.cmd = CMD_STOP;
ioctl(can_fd, COMMAND, &cmd);
cfg.target = CONF_ACCM;
cfg.val = acc_mask;
ioctl(can_fd, CONFIG, &cfg);
cfg.target = CONF_ACCC;
cfg.val = acc_code;
ioctl(can_fd, CONFIG, &cfg);
cmd.cmd = CMD_START;
ioctl(can_fd, COMMAND, &cmd);
|