DCMD_I2C_SENDS

QNX SDP8.0Customizing a BSPConfigurationDeveloper
#include <hw/i2c.h>

#define DCMD_I2C_SENDS              __DIOT (_DCMD_I2C, 11, i2c_send_t)
The arguments to devctl() are:
Argument Value
filedes A file descriptor that you obtained by opening the device.
dcmd DCMD_I2C_SENDS
dev_data_ptr A pointer to a i2c_send_t, followed by additional data
n_bytes sizeof(i2c_send_t), plus the size of the additional data
dev_info_ptr NULL

The DCMD_I2C_SENDS command executes multiple send transactions atomically. The atomic property of this command guarantees that another client application won't interrupt the transaction by accessing the I2C bus. This command blocks until the transaction is complete.

Input
  • i2c_send_t — the message header:
    typedef struct {
    	i2c_addr_t slave;  /* slave address */
    	uint32_t   len;    /* length of send data in bytes */
    	uint32_t   stop;   /* send stop when complete? (0=no, 1=yes) */
    } i2c_send_t;
  • uint8_t[] — the data buffer
The messages sent from the client to libi2c has the following DCMD_I2C_SENDS input data structure:
Input data structure of DCMD_I2C_SENDS
Output
None.
If an error occurs, the command returns:
EIO
The master send failed. The causes include: bad slave address, bad bus speed, bus is busy.
EFAULT
An error occurred while accessing the data buffer.
EINVAL
Bad message format.
ENOMEM
Insufficient memory.
EPERM
The master is locked by another connection.
A code example of using DCMD_I2C_SENDS:
/* This sample code is accessing device /dev/i2c0.
 * It sends 2 commands to slave device 0x20.
 * All the transactions are atomic.
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <devctl.h>
#include <fcntl.h>
#include <hw/i2c.h>

#define CMD_NUM  2

char        *devname = "/dev/i2c0";
unsigned    bus_speed = 0;

int main(int argc, char *argv[])
{
    int fd;
    int status;

    fd = open(devname, O_RDWR);
    if (fd < 0) {
        fprintf(stderr, "open(%s): %s\n", devname, strerror(errno));
        exit(-1);
    }

    if (bus_speed) {
        if ((status = devctl(fd, DCMD_I2C_SET_BUS_SPEED, &bus_speed, sizeof(bus_speed), NULL))) {
            errno = status;
            perror("devctl(BUS_SPEED)");
            exit(-1);
        }
    }

    iov_t       siov[2*CMD_NUM];
    i2c_send_t  cmd[CMD_NUM] = {{.len = 1, .slave.addr = 0x20, .slave.fmt = I2C_ADDRFMT_7BIT, .stop = 1},
                                {.len = 3, .slave.addr = 0x20, .slave.fmt = I2C_ADDRFMT_7BIT, .stop = 1}
                               };
    uint8_t     data0 = 0x0c;
    uint8_t     data1[3] = {0x04, 0x0c, 0x04};

    SETIOV(&siov[0], &cmd[0], sizeof(i2c_send_t));
    SETIOV(&siov[1], &data0, sizeof(data0));   
    SETIOV(&siov[2], &cmd[1], sizeof(i2c_send_t));
    SETIOV(&siov[3], &data1, sizeof(data1));

    if ((status = devctlv(fd, DCMD_I2C_SENDS, 2*CMD_NUM, 0, siov, NULL, NULL))) {
        errno = status;
        perror("MASTER_SEND");
        exit(-1);
    }

    exit(0);
}
Page updated: