i2ccom.c File Reference

This module is the low-level communication layer between the KoreBot Library and the Linux Operating System. More...

Include dependency graph for i2ccom.c:

Go to the source code of this file.

Functions

int i2c_open (i2c_t *i2c, char const *device)
void i2c_close (i2c_t *i2c)
static int i2c_priv_select_device (i2c_t *i2c, i2c_dev_t address)
int i2c_llread (i2c_t *i2c, i2c_dev_t dev, char *buf, unsigned int len)
int i2c_llwrite (i2c_t *i2c, i2c_dev_t dev, const char *buf, unsigned int len)
int i2c_lltransfer (i2c_t *i2c, i2c_dev_t dev, const char *write_buf, unsigned int write_len, char *read_buf, unsigned int read_len)
int i2c_exists (i2c_t *i2c, i2c_dev_t dev)
int i2c_scan (i2c_t *i2c, int(*callback)(i2c_t *i2c, i2c_dev_t dev, void *context), void *context)


Detailed Description

This module is the low-level communication layer between the KoreBot Library and the Linux Operating System.

IC Low-Level Communication Layer

Author:
Yves Piguet (Calerga Sarl)

Pierre Bureau (K-Team SA)

Cdric Gaudin (K-Team SA)

Note:
Copyright (C) 2004 K-TEAM SA
Bug:
none discovered.
Todo:
nothing.

Definition in file i2ccom.c.


Function Documentation

void i2c_close ( i2c_t i2c  ) 

This procedure closes an IC Bus.

Parameters:
i2c IC Bus Handle

Definition at line 87 of file i2ccom.c.

References i2c_t::fd.

Referenced by knet_i2c_exit(), and knet_i2c_init().

int i2c_exists ( i2c_t i2c,
i2c_dev_t  dev 
)

This function verifies the existance of a given device on a given IC Bus.

Parameters:
i2c IC Bus Handle.
dev IC Device Address. This value contains only the IC address bits (7-bit or 10-bit).
Returns:
A value indicating if a device is present or not:
  • 1 device present
  • 0 no device present

Definition at line 243 of file i2ccom.c.

References i2c_t::fd.

Referenced by knet_i2c_open().

int i2c_llread ( i2c_t i2c,
i2c_dev_t  dev,
char *  buf,
unsigned int  len 
)

This function is the primitive to read data from a given device on a given IC Bus.

Parameters:
i2c IC Bus Handle
dev IC Device Address. This value contains only the IC address bits (7-bit or 10-bit).
buf Pointer to the buffer that will receive the data bytes.
len Size of the buffer in bytes.
Returns:
an error code:
  • <0 standard error number. See errno.h
  • >=0 number of bytes read

Definition at line 138 of file i2ccom.c.

References i2c_t::fd, and i2c_priv_select_device().

Referenced by knet_i2c_read().

Here is the call graph for this function:

int i2c_lltransfer ( i2c_t i2c,
i2c_dev_t  dev,
const char *  write_buf,
unsigned int  write_len,
char *  read_buf,
unsigned int  read_len 
)

This function is the primitive to write data to and then read data from a given device on a given IC Bus.

Parameters:
i2c IC Bus Handle.
dev IC Device Address. This value contains only the IC address bits (7-bit or 10-bit).
write_buf Pointer to the buffer that contains the data to be written.
write_len Number of bytes to write. The data are in the write buffer.
read_buf Pointer to the buffer that will receive the data.
read_len Size of the read buffer in bytes.
Returns:
an error code:
  • <0 standard error code. See errno.h
  • >=0 on success

Definition at line 202 of file i2ccom.c.

References i2c_t::fd.

Referenced by knet_i2c_transfer().

int i2c_llwrite ( i2c_t i2c,
i2c_dev_t  dev,
const char *  buf,
unsigned int  len 
)

This function is the primitive to write data to a given device on a given IC Bus.

Parameters:
i2c IC Bus Handle
dev IC Device Address. This value contains only the IC address bits (7-bit or 10-bit).
buf Pointer to the buffer that will be written.
len Number of bytes to write
Returns:
an error code:
  • <0 standard error number. See errno.h
  • >=0 number of bytes written

Definition at line 166 of file i2ccom.c.

References i2c_t::fd, and i2c_priv_select_device().

Referenced by knet_i2c_write().

Here is the call graph for this function:

int i2c_open ( i2c_t i2c,
char const *  device 
)

This function opens an IC Bus.

Parameters:
i2c Pointer to IC Bus Descriptor. This descriptor must be allocated by the caller.
device A string representing the device name. A NULL should be used for default IC Bus. (e.g. /dev/i2c/0)
Returns:
an error code
  • <0 standard error number. See errno.h
  • 0 if IC Bus Device has been opened

Definition at line 66 of file i2ccom.c.

References i2c_t::dev, and i2c_t::fd.

Referenced by knet_i2c_init().

static int i2c_priv_select_device ( i2c_t i2c,
i2c_dev_t  address 
) [static]

This function selects an IC Device on a given IC Bus.

Parameters:
i2c IC Bus Handle
address IC Device Address. This value contains only the IC address bits (7-bit or 10-bit).
Returns:
an error code
  • <0 standard error code. See errno.h
  • 0 on success
Remarks:
This function is used internally and is never exported outside this module.

Definition at line 109 of file i2ccom.c.

References i2c_t::dev, and i2c_t::fd.

Referenced by i2c_llread(), and i2c_llwrite().

int i2c_scan ( i2c_t i2c,
int(*)(i2c_t *i2c, i2c_dev_t dev, void *context)  callback,
void *  context 
)

This function scans a given IC Bus to find devices

Parameters:
i2c IC Bus Handle.
callback A callback function called when a device is found. If this callback function returns a value <0 the bus scan stops immedialety and the value is used as return value by i2c_scan.
context A value or a pointer passed to the callback function.
Returns:
an error code:
  • <0 standard error code (See errno.h) or a user error code.
  • >=0 Number of devices found on the IC bus.

Definition at line 280 of file i2ccom.c.

References i2c_t::fd.

Referenced by knet_i2c_init().


Generated on Wed Dec 15 11:49:27 2010 for KoreBot Library by  doxygen 1.5.5