WE310F5  39.00.000

This section describes the M2MB APIs to perform various I2C operations. More...

enum  M2MB_I2C_IOCTL_REQUEST {
  M2MB_I2C_IOCTL_SET_CFG,
  M2MB_I2C_IOCTL_GET_CFG
}
 
enum  M2MB_I2C_MODE {
  M2MB_I2C_MODE_SLAVE = 0,
  M2MB_I2C_MODE_MASTER = 1
}
 
enum  M2MB_I2C_ADDR {
  M2MB_I2C_ADDR_7BIT = 0,
  M2MB_I2C_ADDR_10BIT = 1
}
 
typedef enum M2MB_I2C_IOCTL_REQUEST M2MB_I2C_IOCTL_REQUEST_T
 
typedef enum M2MB_I2C_MODE M2MB_I2C_MODE_T
 
typedef enum M2MB_I2C_ADDR M2MB_I2C_ADDR_T
 
INT32 m2mb_i2c_open (const CHAR *path, INT32 flags,...)
 Open an I2C device. More...
 
INT32 m2mb_i2c_close (INT32 fd)
 Closes an I2C device. More...
 
INT32 m2mb_i2c_ioctl (INT32 fd, M2MB_I2C_IOCTL_REQUEST_T request,...)
 Configure the I2C device. More...
 
SSIZE_T m2mb_i2c_read (INT32 fd, void *buf, SSIZE_T nbyte)
 Read the I2C device. More...
 
SSIZE_T m2mb_i2c_write (INT32 fd, const void *buf, SSIZE_T nbyte)
 Write to I2C device. More...
 
INT32 m2mb_i2c_reset (INT32 fd)
 Reset the I2C device. More...
 

Detailed Description

This section describes the M2MB APIs to perform various I2C operations.

Typedef Documentation

◆ M2MB_I2C_ADDR_T

◆ M2MB_I2C_IOCTL_REQUEST_T

◆ M2MB_I2C_MODE_T

Enumeration Type Documentation

◆ M2MB_I2C_ADDR

Enumerator
M2MB_I2C_ADDR_7BIT 

i2c slave uses 7 bit addressing

M2MB_I2C_ADDR_10BIT 

i2c slave uses 10 bit addressing

Definition at line 71 of file m2mb_i2c.h.

◆ M2MB_I2C_IOCTL_REQUEST

Enumerator
M2MB_I2C_IOCTL_SET_CFG 

set i2c device configuration

M2MB_I2C_IOCTL_GET_CFG 

get i2c device configuration

Definition at line 58 of file m2mb_i2c.h.

◆ M2MB_I2C_MODE

Enumerator
M2MB_I2C_MODE_SLAVE 

set i2c slave mode

M2MB_I2C_MODE_MASTER 

set i2c master mode

Definition at line 65 of file m2mb_i2c.h.

Function Documentation

◆ m2mb_i2c_close()

INT32 m2mb_i2c_close ( INT32  fd)

Closes an I2C device.

This API closes the requested I2C device

Parameters
[in]fdFile Descriptor of I2C device
Returns
0 on SUCCESS
-1 on FAILURE
Note
This API frees the allocated memory to the configuration of type M2MB_I2C_CFG_T and releases the I2C device. On successful closing of the I2C port, allocated memory to the configuration is freed. In case of an error, memory allocation to configuration is not freed. Allowed From De-initialization and tasks Preemption Possible No

Example

INT32 fd;
INT32 status;
status = m2mb_i2c_close( fd );
if(status == -1)
Diagprintf("ERROR CLOSING I2C port\r\n");

◆ m2mb_i2c_ioctl()

INT32 m2mb_i2c_ioctl ( INT32  fd,
M2MB_I2C_IOCTL_REQUEST_T  request,
  ... 
)

Configure the I2C device.

This API set/get the I2C device configuration

Parameters
[in]fdFile Descriptor of I2C device
[in]requestrequired operation set/get configuration(see M2MB_I2C_IOCTL_REQUEST)
Returns
0 on SUCCESS
-1 on FAILURE
Note
This API allows to read/write the I2C configuration of type M2MB_I2C_CFG_T. On successful configuration, the requested operation (set/get configuration) is done. In case of an error, the requested operation (set/get configuration) could not be completed. Allowed From Events and tasks Preemption Possible No

Example

INT32 fd;
INT32 status;
M2MB_I2C_CFG_T *P_ReadCFG;
fd = m2mb_i2c_open("/dev/i2c-1", 0);
if(fd == -1)
Diagprintf("ERROR OPENING I2C port\r\n");
P_CFG.bus_Frequency_KHz = I2C_SLAVE_FREQ;
P_CFG.slave_Address = I2C_SLAVE_ADDR;
P_CFG.SMBUS_Mode = 0;
P_CFG.flags = 0;
status = m2mb_i2c_ioctl( fd, M2MB_I2C_IOCTL_SET_CFG, P_CFG );
if(status == -1)
Diagprintf("ERROR IN SET I2C\r\n");
status = m2mb_i2c_ioctl( fd, M2MB_I2C_IOCTL_GET_CFG, P_ReadCFG );
if(status == -1)
Diagprintf("ERROR IN GET I2C\r\n");

◆ m2mb_i2c_open()

INT32 m2mb_i2c_open ( const CHAR path,
INT32  flags,
  ... 
)

Open an I2C device.

This API opens the requested I2C device

Parameters
[in]pathPointer to an I2C device to open
[in]flagscurrently unused
Returns
File Descriptor on SUCCESS
-1 on FAILURE
Note
This API allocates memory to the configuration of type M2MB_I2C_CFG_T. After successful opening of the I2C port, the File Descriptor points to M2MB_I2C_CFG_T. In case of an error in memory allocation or opening of the I2C port, it returns -1 Allowed From Initialization and tasks Preemption Possible No

Example

INT32 fd;
fd = m2mb_i2c_open("/dev/i2c-1", 0);
if(fd == -1)
app_dbg_printf("ERROR OPENING I2C port\r\n");

◆ m2mb_i2c_read()

SSIZE_T m2mb_i2c_read ( INT32  fd,
void *  buf,
SSIZE_T  nbyte 
)

Read the I2C device.

This API reads the data bytes from the I2C device

Parameters
[in]fdFile Descriptor of I2C device
[in,out]bufreference to the data to be read
[in]nbytenumber of data bytes to be read
Returns
number of data bytes read on SUCCESS
-1 on FAILURE
Note
This API reads the data bytes from the I2C device. On success, the read data bytes are updated in the reference provided. In case of an error, data bytes are not read from the I2C device. Allowed From Events and tasks Preemption Possible No

Example

bytecnt = m2mb_i2c_read( fd, (void* )P_ReadByte, 1);

◆ m2mb_i2c_reset()

INT32 m2mb_i2c_reset ( INT32  fd)

Reset the I2C device.

This API resets the I2C Master from the blocked I2C state

Parameters
[in]fdFile Descriptor of I2C device
Returns
0 on SUCCESS
-1 on FAILURE
Note
This API reads the data bytes from the I2C device. On success, the read data bytes are updated in the reference provided. In case of an error, data bytes are not read from the I2C device. Allowed From Events and tasks Preemption Possible No

Example

bytecnt = m2mb_i2c_read( fd, (void* )P_ReadByte, 1);

◆ m2mb_i2c_write()

SSIZE_T m2mb_i2c_write ( INT32  fd,
const void *  buf,
SSIZE_T  nbyte 
)

Write to I2C device.

This API writes the data bytes to the I2C device

Parameters
[in]fdFile Descriptor of the I2C device
[in]bufreference to the data to be written
[in]nbytenumber of data bytes to be write
Returns
number of data bytes written on SUCCESS
-1 on FAILURE
Note
This API writes the data bytes to the I2C device. On success, the data bytes are successfully written to the I2C device. In case of an error, write data bytes to the I2C device has failed. Every API allowed from events and tasks preemption possible No

Example

bytecnt = m2mb_i2c_write( fd, (void* )P_WriteByte, size);