knet.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  knet_bus_s
struct  knet_dev_s

Defines

#define KNET_BUS_ANY   -1
#define KNET_BUS_I2C   0
#define KNET_BUS_SPI   1
#define KNET_BUS_RS232   2
#define KNET_MAX_BUSSES   3
#define KNET_ORDER_LITTLE   (0<<0)
#define KNET_ORDER_BIG   (1<<0)
#define KNET_ORDER_LSB_FIRST   (0<<1)
#define KNET_ORDER_MSB_FIRST   (1<<1)
#define KNET_ORDER_BIT_SWAP   (1<<2)
#define KNET_ORDER_REP_ADR   (1<<3)
#define knet_write(dev, reg, val)   knet_write8( dev , reg , val )

Typedefs

typedef unsigned int knet_ext_t
typedef unsigned int knet_mod_t
typedef unsigned char knet_reg_t
typedef void * knet_bus_info_t
typedef void * knet_dev_info_t
typedef struct knet_bus_s knet_bus_t
typedef struct knet_dev_s knet_dev_t

Functions

int knet_init (int argc, char *argv[])
void knet_exit (void)
knet_dev_tknet_bus_find_device (knet_bus_t *bus, knet_ext_t ext_addr, knet_mod_t mod_addr)
knet_dev_tknet_bus_find_device_by_name (knet_bus_t *bus, const char *dev_name)
knet_dev_tknet_open (const char *device, int preferred_bus, int argc, char *argv[])
void knet_set_order (knet_dev_t *dev, unsigned long order)
void knet_close (knet_dev_t *dev)
knet_dev_tknet_device_create (knet_bus_t *bus, knet_ext_t ext_addr, knet_mod_t mod_addr, const char *name)
int knet_device_destroy (knet_dev_t *dev)
int knet_lltransfer (knet_dev_t *dev, const char *write_buf, unsigned int write_len, char *read_buf, unsigned int read_len)
int knet_llread (knet_dev_t *dev, char *buf, unsigned int len)
int knet_llwrite (knet_dev_t *dev, const char *buf, unsigned int len)
int knet_convert (knet_dev_t *dev, char *buf, unsigned int len, int type)
int knet_read8 (knet_dev_t *dev, knet_reg_t reg, unsigned char *val)
int knet_read16 (knet_dev_t *dev, knet_reg_t reg, unsigned short *val)
int knet_read32 (knet_dev_t *dev, knet_reg_t reg, unsigned long *val)
int knet_readxBytes (knet_dev_t *dev, knet_reg_t reg, unsigned char *val, unsigned char rx_len)
int knet_write8 (knet_dev_t *dev, knet_reg_t reg, unsigned char val)
int knet_write16 (knet_dev_t *dev, knet_reg_t reg, unsigned short val)
int knet_write32 (knet_dev_t *dev, knet_reg_t reg, unsigned long val)
int knet_read (knet_dev_t *dev, knet_reg_t reg)
int knet_vprintf (knet_dev_t *dev, const char *format, va_list argptr)
int knet_printf (knet_dev_t *dev, const char *format,...)
int knet_read_string (knet_dev_t *dev, char *buffer, unsigned int size, unsigned char terminator)

Variables

const char * knet_bus_names []


Define Documentation

#define KNET_BUS_ANY   -1

K-Net Busses Constants

Definition at line 21 of file knet.h.

Referenced by AltMotorOpen(), kbot_SetLeds(), knet_open(), ltc1663_SendCommand(), main(), MotorOpen(), and PantiltOpen().

#define KNET_BUS_I2C   0

Definition at line 22 of file knet.h.

Referenced by initGripper(), initKH3(), knet_init(), knet_open(), and main().

#define KNET_BUS_RS232   2

Definition at line 24 of file knet.h.

Referenced by knet_init(), and knet_open().

#define KNET_BUS_SPI   1

Definition at line 23 of file knet.h.

Referenced by knet_open().

#define KNET_MAX_BUSSES   3

Definition at line 25 of file knet.h.

Referenced by knet_exit(), and knet_init().

#define KNET_ORDER_BIG   (1<<0)

Definition at line 38 of file knet.h.

Referenced by knet_convert(), knet_read16(), knet_read32(), knet_write16(), and knet_write32().

#define KNET_ORDER_BIT_SWAP   (1<<2)

#define KNET_ORDER_LITTLE   (0<<0)

Definition at line 37 of file knet.h.

Referenced by ltc1663_SendCommand().

#define KNET_ORDER_LSB_FIRST   (0<<1)

Definition at line 39 of file knet.h.

#define KNET_ORDER_MSB_FIRST   (1<<1)

Definition at line 40 of file knet.h.

Referenced by knet_read16(), knet_read32(), knet_write16(), and knet_write32().

#define KNET_ORDER_REP_ADR   (1<<3)

Definition at line 42 of file knet.h.

Referenced by knet_read16(), knet_read32(), knet_write16(), and knet_write32().

#define knet_write ( dev,
reg,
val   )     knet_write8( dev , reg , val )

Definition at line 216 of file knet.h.


Typedef Documentation

typedef void* knet_bus_info_t

Register Number

Definition at line 50 of file knet.h.

typedef struct knet_bus_s knet_bus_t

typedef void* knet_dev_info_t

Bus Private Data Pointer

Definition at line 51 of file knet.h.

typedef struct knet_dev_s knet_dev_t

typedef unsigned int knet_ext_t

Definition at line 47 of file knet.h.

typedef unsigned int knet_mod_t

Extension ID

Definition at line 48 of file knet.h.

typedef unsigned char knet_reg_t

Module ID

Definition at line 49 of file knet.h.


Function Documentation

knet_dev_t* knet_bus_find_device ( knet_bus_t bus,
knet_ext_t  ext_addr,
knet_mod_t  mod_addr 
)

This function finds a K-Net device descriptor given its K-Net Extension and K-Net Module IDs.

Parameters:
bus K-Net Bus Handle
ext_addr K-Net Extension Id
mod_addr K-Net Module Id
Returns:
A pointer to a K-Net device descriptor or NULL if no device found.

Definition at line 201 of file knet.c.

References knet_bus_s::devices, knet_dev_s::ext_addr, knet_dev_s::mod_addr, and knet_dev_s::next.

Referenced by knet_i2c_open().

knet_dev_t* knet_bus_find_device_by_name ( knet_bus_t bus,
const char *  dev_name 
)

This function finds a K-Net device descriptor given its Device Name.

Parameters:
bus K-Net Bus Descriptor
dev_name Device Name
Returns:
A pointer to a K-Net device descriptor or NULL if no device found.

Definition at line 229 of file knet.c.

References knet_bus_s::devices, knet_dev_s::name, and knet_dev_s::next.

Referenced by knet_rs232_open().

void knet_close ( knet_dev_t dev  ) 

This function closes a K-Net Device

Parameters:
dev K-Net device descriptor to close
Remarks:
This function is thread safe.

Definition at line 435 of file knet.c.

References knet_dev_s::bus, knet_bus_s::close, knet_bus_s::lock, and knet_dev_s::usage_counter.

Referenced by kbot_SetLeds(), ltc1663_SendCommand(), and main().

int knet_convert ( knet_dev_t dev,
char *  buf,
unsigned int  len,
int  type 
)

This function converts a data buffer into the encoding of a given K-Net device.

Parameters:
dev K-Net device descriptor
buf Pointer to the buffer that contains the data to convert
len Number of data bytes in the buffer
type Size of the primitive type in the buffer:
  • 1 8-bit
  • 2 16-bit
  • 4 32-bit
Returns:
An error code
  • <0 on error
  • 0 on success

Definition at line 708 of file knet.c.

References KNET_ORDER_BIG, KNET_ORDER_BIT_SWAP, and knet_dev_s::order.

knet_dev_t* knet_device_create ( knet_bus_t bus,
knet_ext_t  ext_addr,
knet_mod_t  mod_addr,
const char *  name 
)

This function creates a new K-Net device descriptor

Parameters:
bus Pointer to a given KNet Bus Descriptor
ext_addr K-Net Device Extension Id
mod_addr K-Net Device Module Id
name K-Net Device Name
Returns:
A pointer to a K-Net device descriptor
Remarks:
This function is thread safe.

Definition at line 504 of file knet.c.

References knet_dev_s::bus, knet_bus_s::devices, knet_dev_s::ext_addr, KB_ALLOC, knet_dev_s::mod_addr, knet_dev_s::next, knet_dev_s::order, and knet_dev_s::usage_counter.

Referenced by knet_i2c_open(), knet_i2c_scan_callback(), and knet_rs232_open().

int knet_device_destroy ( knet_dev_t dev  ) 

This function destroys a K-Net device descriptor

Parameters:
dev Pointer to K-Net device descriptor
Returns:
An error code:
  • <0 on error
  • 0 on success
Remarks:
This function is thread safe.

Definition at line 539 of file knet.c.

References knet_dev_s::bus, knet_bus_s::devices, kb_error(), KB_ERROR_DEVICEINUSE, KB_ERROR_UNLINKDEV, kb_free, knet_bus_s::lock, knet_dev_s::next, and knet_dev_s::usage_counter.

Referenced by knet_exit().

Here is the call graph for this function:

void knet_exit ( void   ) 

This function releases all resources used by the K-Net layer

Remarks:
Never call this function !

Definition at line 165 of file knet.c.

References knet_bus_s::devices, knet_bus_s::exit, kb_free, knet_buffer, knet_buffer_size, knet_bus_count, knet_device_destroy(), KNET_MAX_BUSSES, and knet_bus_s::usage_counter.

Referenced by kb_exit().

Here is the call graph for this function:

int knet_init ( int  argc,
char *  argv[] 
)

This function initializes the K-Net layer. This function should be called once at startup.

Parameters:
argc Number of arguments
argv An array of strings containing a list of arguments
Returns:
An error code:
  • <0 on error
  • 0 on success

Definition at line 110 of file knet.c.

References kb_alloc(), knet_buffer, knet_buffer_lock, knet_buffer_size, knet_bus_count, KNET_BUS_I2C, KNET_BUS_RS232, knet_i2c_init(), KNET_MAX_BUSSES, knet_rs232_init(), knet_bus_s::lock, and knet_bus_s::usage_counter.

Referenced by kb_init().

Here is the call graph for this function:

int knet_llread ( knet_dev_t dev,
char *  buf,
unsigned int  len 
)

This function reads data from a given device

Parameters:
dev K-Net device descriptor
buf Pointer to the buffer that will receive the data
len Size of the buffer
Returns:
A value:
  • <0 on error
  • >=0 number of bytes read
Remarks:
This function is thread safe.

Definition at line 643 of file knet.c.

References knet_dev_s::bus, knet_bus_s::lock, and knet_bus_s::read.

Referenced by braitenbergAvoidance(), hem_fastRead(), kh3_getcommand(), and knet_read_string().

int knet_lltransfer ( knet_dev_t dev,
const char *  write_buf,
unsigned int  write_len,
char *  read_buf,
unsigned int  read_len 
)

This function transfers data to and from a given device.

Parameters:
dev Pointer to a given K-Net Device Descriptor
write_buf Pointer to the buffer that contains the data to be written
write_len Length in bytes of the data 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 on error
  • >=0 on success
Remarks:
This function is thread safe.

Definition at line 604 of file knet.c.

References knet_dev_s::bus, knet_bus_s::lock, knet_bus_s::read, knet_bus_s::transfer, and knet_bus_s::write.

Referenced by kio_i2c_ListScan(), kio_i2c_ReturnRead(), kio_ReadCAN(), knet_read16(), knet_read32(), knet_read8(), knet_readxBytes(), and pcf8574_Read().

int knet_llwrite ( knet_dev_t dev,
const char *  buf,
unsigned int  len 
)

This function writes data into a given device.

Parameters:
dev K-Net device descriptor
buf Pointer to the buffer that contains the data to be written
len Length in bytes of the data in the buffer
Returns:
A value:
  • <0 on error
  • >=0 number of bytes written
Remarks:
This function is thread safe.

Definition at line 674 of file knet.c.

References knet_dev_s::bus, knet_bus_s::lock, and knet_bus_s::write.

Referenced by kh3_sendcommand(), knet_printf(), knet_vprintf(), knet_write16(), knet_write32(), knet_write8(), and pcf8574_Write().

knet_dev_t* knet_open ( const char *  device,
int  preferred_bus,
int  argc,
char *  argv[] 
)

This function opens a K-Net device given its name.

Parameters:
device K-Net Device name to open
preferred_bus Preferred Bus.
Preferred bus value:
  • KNET_BUS_ANY tells to choose any bus for communicating with the given device.

  • KNET_BUS_I2C tells to choose an IC bus for communicating with the given device.

  • KNET_BUS_SPI tells to choose an SPI bus for communicating with the given device.

  • KNET_BUS_RS232 tells to choose a rs232 port for communicating with the given device.

Returns:
A pointer to a K-Net device descriptor or NULL if no device is found
Remarks:
This function is thread safe.

Definition at line 270 of file knet.c.

References kb_device_config_s::address, kb_device_config_s::defined, kb_device_config_s::device_name, KB_ALLOC, KB_DEVICE_CLASS_I2C, KB_DEVICE_CLASS_MODULE, KB_DEVICE_CLASS_RS232, KB_DEVICE_CLASS_SPI, KB_ERROR, kb_error(), KB_ERROR_NOBUSADDR, KB_ERROR_NOBUSFOUND, KB_ERROR_NODEVFOUNDSTR, KB_ERROR_NOMODBUS, kb_free, kb_lookup_device(), kb_device_config_s::kclass, KNET_BUS_ANY, KNET_BUS_I2C, KNET_BUS_RS232, KNET_BUS_SPI, knet_bus_s::lock, kb_section_config_s::module_bus, kb_section_config_s::module_bus_addr, knet_bus_s::open, kb_device_config_s::section, and knet_bus_s::usage_counter.

Referenced by AltMotorOpen(), initGripper(), initKH3(), kbot_SetLeds(), ltc1663_SendCommand(), main(), MotorOpen(), and PantiltOpen().

Here is the call graph for this function:

int knet_printf ( knet_dev_t dev,
const char *  format,
  ... 
)

int knet_read ( knet_dev_t dev,
knet_reg_t  reg 
)

This function reads an 8-bit value from a given K-Net device and return this value.

Parameters:
dev K-Net device descriptor
reg K-Net register address
Returns:
A value:
  • <0 on error
  • >=0 the value read
Remarks:
This function is thread safe.

Definition at line 1195 of file knet.c.

References knet_read8().

Referenced by kmot_SearchLimits(), and kmot_SetPoint().

Here is the call graph for this function:

int knet_read16 ( knet_dev_t dev,
knet_reg_t  reg,
unsigned short *  val 
)

This function reads a 16-bit value from a given K-Net device

Parameters:
dev K-Net device descriptor
reg K-Net register address
val A pointer to a variable that will receive the 16-bit value
Returns:
A value:
  • <0 on error
  • >= on success
Remarks:
This function is thread safe.

Definition at line 792 of file knet.c.

References knet_lltransfer(), KNET_ORDER_BIG, KNET_ORDER_BIT_SWAP, KNET_ORDER_MSB_FIRST, KNET_ORDER_REP_ADR, and knet_dev_s::order.

Referenced by kgripper_Arm_Get_Current(), kgripper_Arm_Get_Limits(), kgripper_Arm_Get_Order(), kgripper_Arm_Get_Position(), kgripper_Arm_Get_Voltage(), kgripper_Gripper_Get_Ambiant_IR_Light(), kgripper_Gripper_Get_Current(), kgripper_Gripper_Get_Distance_Sensors(), kgripper_Gripper_Get_Resistivity(), kgripper_Gripper_Get_Torque(), and kmot_GetMeasure().

Here is the call graph for this function:

int knet_read32 ( knet_dev_t dev,
knet_reg_t  reg,
unsigned long *  val 
)

This function reads a 32-bit value from a given K-Net device.

Parameters:
dev K-Net device descriptor
reg K-Net register address
val A pointer to a 32-bit value that will receive the value
Remarks:
This function is thread safe.

Definition at line 861 of file knet.c.

References knet_lltransfer(), KNET_ORDER_BIG, KNET_ORDER_BIT_SWAP, KNET_ORDER_MSB_FIRST, KNET_ORDER_REP_ADR, and knet_dev_s::order.

Referenced by kmot_GetMeasure(), and kmot_SearchLimits().

Here is the call graph for this function:

int knet_read8 ( knet_dev_t dev,
knet_reg_t  reg,
unsigned char *  val 
)

This function reads a 8-bit value of data from a K-Net device.

Parameters:
dev K-Net device descriptor
reg K-Net register address
val Pointer to a variable that will receive the value
Returns:
An error code:
  • <0 on error
  • >=0 on success
Remarks:
This function is thread safe.

Definition at line 760 of file knet.c.

References knet_lltransfer(), KNET_ORDER_BIT_SWAP, and knet_dev_s::order.

Referenced by kgripper_Arm_Get_Capacity(), kgripper_Arm_Get_Max_Speed(), kgripper_Arm_Get_Search_Limit(), kgripper_Arm_Get_Speed(), kgripper_Arm_Get_Version(), kgripper_Arm_OnTarget(), kgripper_Gripper_Get_Limits(), kgripper_Gripper_Get_Order(), kgripper_Gripper_Get_Position(), kgripper_Gripper_Get_Search_Limit(), kgripper_Gripper_Get_Speed(), kgripper_Gripper_Get_Version(), kgripper_Gripper_Object_Detected(), kgripper_Gripper_OnTarget(), kio_GetFWVersion(), kio_i2c_ListScan(), kio_ReadAnalog(), kio_ReadIO(), kio_SendCAN(), kmot_GetFWVersion(), kmot_GetOptions(), kmot_GetSpeedMultiplier(), kmot_GetStatus(), and knet_read().

Here is the call graph for this function:

int knet_read_string ( knet_dev_t dev,
char *  buffer,
unsigned int  size,
unsigned char  terminator 
)

int knet_readxBytes ( knet_dev_t dev,
knet_reg_t  reg,
unsigned char *  val,
unsigned char  rx_len 
)

This function reads a x Bytes value from a given K-Net device.

Parameters:
dev K-Net device descriptor
reg K-Net register address
val A pointer to a table value that will receive the value
rx_len the number of Bytes to be read
Remarks:
This function is thread safe.

Definition at line 948 of file knet.c.

References knet_lltransfer(), KNET_ORDER_BIT_SWAP, and knet_dev_s::order.

Here is the call graph for this function:

void knet_set_order ( knet_dev_t dev,
unsigned long  order 
)

This function changes the order flags. These flags are used by knet_{read|write}{8|16|32} functions to choose the desired encoding before and after reading from or writing to a K-Net device.

Parameters:
dev K-Net device descriptor
order New order flags.
Order Flags:

  • KNET_ORDER_LITTLE tells that the target device use little endian encoding. In little endian, the least significant BYTE is at the lowest address value.

  • KNET_ORDER_BIG tells that the target device use big endian encoding. In big endian, the most significant BYTE is at the lowest address value.

  • KNET_ORDER_LSB_FIRST tells that the lowest address is the first sent. This flag takes effect only if KNET_ORDER_REP_ADR is set.

  • KNET_ORDER_MSB_FIRST tells that the highest address is the first sent. This flag takes effect only if K NET_ORDER_REP_ADR is set.

  • KNET_ORDER_BIT_SWAP tells to reverse the bit order.
  • KNET_ORDER_REP_ADR tells to use multiple atomic 8-bit reads or writes in order to read or write a 16-bit or 32-bit.

Remarks:
This function is thread safe.

Definition at line 482 of file knet.c.

References knet_dev_s::bus, knet_bus_s::lock, and knet_dev_s::order.

Referenced by kgripper_Arm_Set_Order(), kgripper_Gripper_Set_Torque(), kmot_ConfigurePID(), kmot_GetMeasure(), kmot_SearchLimits(), kmot_SetLimits(), kmot_SetMinSpeed(), kmot_SetPoint(), kmot_SetPosition(), kmot_SetSampleTime(), kmot_SetSpeedProfile(), and ltc1663_SendCommand().

int knet_vprintf ( knet_dev_t dev,
const char *  format,
va_list  argptr 
)

This function writes into a device using a vprintf-like formatting function.

Parameters:
dev K-Net device descriptor
format printf-like formatted string.
argptr arguments list
Returns:
<0 on error and >=0 number of characters written.

Definition at line 1217 of file knet.c.

References kb_realloc(), knet_buffer, knet_buffer_lock, knet_buffer_size, and knet_llwrite().

Here is the call graph for this function:

int knet_write16 ( knet_dev_t dev,
knet_reg_t  reg,
unsigned short  val 
)

This function writes an 16-bit value to a given K-Net device.

Parameters:
dev K-Net device descriptor
reg K-Net register address
val a 16-bit value
Returns:
A value:
  • <0 on error
  • >=0 on success
Remarks:
This function is thread safe.

Definition at line 1012 of file knet.c.

References buf, knet_llwrite(), KNET_ORDER_BIG, KNET_ORDER_BIT_SWAP, KNET_ORDER_MSB_FIRST, KNET_ORDER_REP_ADR, and knet_dev_s::order.

Referenced by kgripper_Arm_Set_Order(), kgripper_Gripper_Set_Torque(), kmot_ConfigurePID(), kmot_SetLimits(), kmot_SetMinSpeed(), kmot_SetSpeedProfile(), and ltc1663_SendCommand().

Here is the call graph for this function:

int knet_write32 ( knet_dev_t dev,
knet_reg_t  reg,
unsigned long  val 
)

This function writes a 32-bit value to a given K-Net device.

Parameters:
dev K-Net device descriptor
reg K-Net register address
val a 32-bit value
Returns:
A value:
  • <0 on error
  • >=0 on success
Remarks:
This function is thread safe.

Definition at line 1090 of file knet.c.

References buf, knet_llwrite(), KNET_ORDER_BIG, KNET_ORDER_BIT_SWAP, KNET_ORDER_MSB_FIRST, KNET_ORDER_REP_ADR, and knet_dev_s::order.

Referenced by kmot_SearchLimits(), kmot_SetLimits(), kmot_SetPoint(), and kmot_SetPosition().

Here is the call graph for this function:

int knet_write8 ( knet_dev_t dev,
knet_reg_t  reg,
unsigned char  val 
)


Variable Documentation

const char* knet_bus_names[]

List of existing knet bus names, as they should appear in configuration files. Device class names are defined in kb_config.h

Definition at line 94 of file knet.c.

Referenced by kb_parse_modbus().


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