Microchip® Advanced Software Framework

sensor_bus.h File Reference

Sensor API Platform Bus Interfaces.

Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.

#include <status_codes.h>

Data Structures

struct  bus_desc_t
 Platform Bus Interface Descriptor. More...
 

Typedefs

typedef status_code_t bus_status_t
 Platform Bus Status Constants. More...
 
typedef SPI_t * spi_if
 

Enumerations

enum  bus_type_t {
  BUS_TYPE_UNKNOWN,
  BUS_TYPE_TWI,
  BUS_TYPE_SPI,
  BUS_TYPE_PMBUS,
  BUS_TYPE_SMBUS
}
 Platform Bus Type Constants. More...
 

Functions

System Bus I/O Access Methods
bool bus_init (volatile void *busif, uint32_t speed)
 
size_t bus_read (bus_desc_t *bus, uint8_t addr, void *data, size_t count)
 Read multiple Bytes from a bus interface. More...
 
size_t bus_write (bus_desc_t *bus, uint8_t addr, const void *data, size_t count)
 Write multiple Bytes to a bus interface. More...
 
bool bus_probe (bus_desc_t *bus, int arg)
 Determine the existence of a bus device. More...
 
static uint8_t bus_get (bus_desc_t *bus, uint8_t addr)
 Read a single Byte from a bus interface. More...
 
static void bus_put (bus_desc_t *bus, uint8_t addr, uint8_t data)
 Write a single Byte to a bus interface. More...
 
static void bus_reg_bitclear (bus_desc_t *bus, uint8_t addr, uint8_t mask)
 Clear a bit at a bus device register or memory address. More...
 
static void bus_reg_bitset (bus_desc_t *bus, uint8_t addr, uint8_t mask)
 Set a bit at a bus device register or memory address. More...
 
uint8_t bus_reg_fieldget (bus_desc_t *bus, uint8_t addr, uint8_t mask)
 Read a field stored at a device register or memory address. More...
 
void bus_reg_fieldset (bus_desc_t *bus, uint8_t addr, uint8_t mask, uint8_t value)
 Write a field stored at a device register or memory address. More...
 

Platform Bus Status Constants.

typedef SPI_t* spi_if

Platform Bus Interface Types

enum bus_type_t

Platform Bus Type Constants.

Enumerator
BUS_TYPE_UNKNOWN 

Unknown bus.

BUS_TYPE_TWI 

TWI/I2C bus.

BUS_TYPE_SPI 

SPI bus.

BUS_TYPE_PMBUS 

PMBus protocol.

BUS_TYPE_SMBUS 

SMBus protocol.

static uint8_t bus_get ( bus_desc_t bus,
uint8_t  addr 
)
inlinestatic

Read a single Byte from a bus interface.

Parameters
busAn initialized bus interface descriptor.
addrThe device register or memory address.
Returns
A value fetched from the device. This value is undefined in the event of an I/O error.

References bus_read().

Referenced by bus_reg_bitclear(), bus_reg_bitset(), bus_reg_fieldget(), and bus_reg_fieldset().

bool bus_init ( volatile void *  busif,
uint32_t  speed 
)

Initialize the bus I/O interface.

Parameters
busifThe address of a system bus (registers) interface.
speedThe bus data rate.
Return values
trueThe bus was initialized.
falseThe bus was not initialized.
bool bus_probe ( bus_desc_t bus,
int  arg 
)

Determine the existence of a bus device.

This routine determines the existence of a device located at a bus interface and address specified by an initialized bus descriptor. Implementations are only required to return true when it can be determined that a device is installed at the bus interface address.

Parameters
busAn initialized bus interface descriptor.
argIgnored reserved argument.
Return values
trueA device responded to the bus address.
falseA device did not respond to the bus address.
static void bus_put ( bus_desc_t bus,
uint8_t  addr,
uint8_t  data 
)
inlinestatic

Write a single Byte to a bus interface.

Parameters
busAn initialized bus interface descriptor.
addrThe device register or memory address.
dataThe value of the Byte to write.
Returns
Nothing

References bus_write().

Referenced by bus_reg_bitclear(), bus_reg_bitset(), and bus_reg_fieldset().

size_t bus_read ( bus_desc_t bus,
uint8_t  addr,
void *  data,
size_t  count 
)

Read multiple Bytes from a bus interface.

Parameters
busAn initialized bus interface descriptor.
addrThe device register or memory address.
dataThe destination read buffer address.
countThe destination read buffer size (Bytes).
Returns
The number of Bytes read, which may be less than the requested number of Bytes in the event of an error.

Referenced by bus_get().

static void bus_reg_bitclear ( bus_desc_t bus,
uint8_t  addr,
uint8_t  mask 
)
inlinestatic

Clear a bit at a bus device register or memory address.

Parameters
busAn initialized bus interface descriptor.
addrThe device register or memory address.
maskThe mask value of the bit to clear.
Returns
Nothing

References bus_get(), and bus_put().

static void bus_reg_bitset ( bus_desc_t bus,
uint8_t  addr,
uint8_t  mask 
)
inlinestatic

Set a bit at a bus device register or memory address.

Parameters
busAn initialized bus interface descriptor.
addrThe device register or memory address.
maskThe mask value of the bit to set.
Returns
Nothing

References bus_get(), and bus_put().

uint8_t bus_reg_fieldget ( bus_desc_t bus,
uint8_t  addr,
uint8_t  mask 
)

Read a field stored at a device register or memory address.

This routine reads a specified value from a bit field within a 1-Byte device register or memory address. The set bits in the mask parameter determine the field location. For example, if the mask is 30h and the value AFh is stored in the register, the value 2h will be returned.

Parameters
busAn initialized bus interface descriptor.
addrThe device register or memory address.
maskThe mask of the field to set.
Returns
The value stored in the register or memory field.

Sensor Platform Board ConfigurationThis routine reads a specified value from a bit field within a 1-Byte device register or memory address. The set bits in the mask parameter determine the field location. For example, if the mask is 30h and the value AFh is stored in the register, the value 2h will be returned.

Parameters
busAn initialized bus interface descriptor.
addrThe device register or memory address.
maskThe mask of the field to set.
Returns
The value stored in the register or memory field.

References bus_get().

void bus_reg_fieldset ( bus_desc_t bus,
uint8_t  addr,
uint8_t  mask,
uint8_t  value 
)

Write a field stored at a device register or memory address.

This routine writes a specified value to a bit field within a 1-Byte device register or memory address. The set bits in the mask parameter determine the field location. For example, if the mask is 30h and the value is 2h, the value 20h will be bitwise logically OR'd into the 1-Byte register value after clearing the bit values in the field.

Parameters
busAn initialized bus interface descriptor.
addrThe device register or memory address.
maskThe mask of the field to set.
valueThe value of the field to set.
Returns
Nothing

References bus_get(), and bus_put().

size_t bus_write ( bus_desc_t bus,
uint8_t  addr,
const void *  data,
size_t  count 
)

Write multiple Bytes to a bus interface.

Parameters
busAn initialized bus interface descriptor.
addrThe device register or memory address.
dataThe source write buffer address.
countThe source write buffer size (Bytes).
Returns
The number of Bytes written, which may be less than the requested number of Bytes in the event of an error.

Referenced by bus_put().