RTEMS  5.0.0
Files | Data Structures | Macros | Functions

Files

file  i2c-bus.c
 Inter-Integrated Circuit (I2C) Bus Implementation.
 

Data Structures

struct  i2c_bus
 I2C bus control. More...
 

Macros

#define I2C_BUS_CLOCK_DEFAULT   100000
 Default I2C bus clock in Hz.
 

Functions

int i2c_bus_init (i2c_bus *bus)
 Initializes a bus control. More...
 
i2c_busi2c_bus_alloc_and_init (size_t size)
 Allocates a bus control from the heap and initializes it. More...
 
void i2c_bus_destroy (i2c_bus *bus)
 Destroys a bus control. More...
 
void i2c_bus_destroy_and_free (i2c_bus *bus)
 Destroys a bus control and frees its memory. More...
 
int i2c_bus_register (i2c_bus *bus, const char *bus_path)
 Registers a bus control. More...
 
void i2c_bus_obtain (i2c_bus *bus)
 Obtains the bus. More...
 
void i2c_bus_release (i2c_bus *bus)
 Releases the bus. More...
 
int i2c_bus_transfer (i2c_bus *bus, i2c_msg *msgs, uint32_t msg_count)
 Transfers I2C messages. More...
 

I2C IO Control Commands

#define I2C_BUS_OBTAIN   0x800
 Obtains the bus. More...
 
#define I2C_BUS_RELEASE   0x801
 Releases the bus. More...
 
#define I2C_BUS_GET_CONTROL   0x802
 Gets the bus control. More...
 
#define I2C_BUS_SET_CLOCK   0x803
 Sets the bus clock in Hz. More...
 

Detailed Description

Macro Definition Documentation

◆ I2C_BUS_GET_CONTROL

#define I2C_BUS_GET_CONTROL   0x802

Gets the bus control.

The argument type is a pointer to i2c_bus pointer.

◆ I2C_BUS_OBTAIN

#define I2C_BUS_OBTAIN   0x800

Obtains the bus.

This command has no argument.

◆ I2C_BUS_RELEASE

#define I2C_BUS_RELEASE   0x801

Releases the bus.

This command has no argument.

◆ I2C_BUS_SET_CLOCK

#define I2C_BUS_SET_CLOCK   0x803

Sets the bus clock in Hz.

The argument type is unsigned long.

Function Documentation

◆ i2c_bus_alloc_and_init()

i2c_bus* i2c_bus_alloc_and_init ( size_t  size)

Allocates a bus control from the heap and initializes it.

After a sucessful allocation and initialization the bus control must be destroyed via i2c_bus_destroy_and_free(). A registered bus control will be automatically destroyed in case the device file is unlinked. Make sure to call i2c_bus_destroy_and_free() in a custom destruction handler.

Parameters
[in]sizeThe size of the bus control. This enables the addition of bus controller specific data to the base bus control. The bus control is zero initialized.
Return values
non-NULLThe new bus control.
NULLAn error occurred. The errno is set to indicate the error.
See also
i2c_bus_register()

◆ i2c_bus_destroy()

void i2c_bus_destroy ( i2c_bus bus)

Destroys a bus control.

Parameters
[in]busThe bus control.

◆ i2c_bus_destroy_and_free()

void i2c_bus_destroy_and_free ( i2c_bus bus)

Destroys a bus control and frees its memory.

Parameters
[in]busThe bus control.

◆ i2c_bus_init()

int i2c_bus_init ( i2c_bus bus)

Initializes a bus control.

After a sucessful initialization the bus control must be destroyed via i2c_bus_destroy(). A registered bus control will be automatically destroyed in case the device file is unlinked. Make sure to call i2c_bus_destroy() in a custom destruction handler.

Parameters
[in]busThe bus control.
Return values
0Successful operation.
-1An error occurred. The errno is set to indicate the error.
See also
i2c_bus_register()

◆ i2c_bus_obtain()

void i2c_bus_obtain ( i2c_bus bus)

Obtains the bus.

Parameters
[in]busThe bus control.

◆ i2c_bus_register()

int i2c_bus_register ( i2c_bus bus,
const char *  bus_path 
)

Registers a bus control.

This function claims ownership of the bus control regardless if the registration is successful or not.

Parameters
[in]busThe bus control.
[in]bus_pathThe path to the bus device file.
Return values
0Successful operation.
-1An error occurred. The errno is set to indicate the error.

◆ i2c_bus_release()

void i2c_bus_release ( i2c_bus bus)

Releases the bus.

Parameters
[in]busThe bus control.

◆ i2c_bus_transfer()

int i2c_bus_transfer ( i2c_bus bus,
i2c_msg msgs,
uint32_t  msg_count 
)

Transfers I2C messages.

The bus is obtained before the transfer and released afterwards.

Parameters
[in]busThe bus control.
[in]msgsThe messages to transfer.
[in]msg_countThe count of messages to transfer. It must be positive.
Return values
0Successful operation.
negativeNegative error number in case of an error.