Microchip® Advanced Software Framework

sensor_bus.c File Reference

Sensor API Platform Bus Interfaces.

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

#include <asf.h>
#include "conf_sensors.h"
#include "sensor_bus.h"

Macros

#define twi_bus_init   bus_init
 
#define twi_bus_probe   bus_probe
 
#define twi_bus_read   bus_read
 
#define twi_bus_write   bus_write
 

Functions

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...
 
bool twi_bus_init (volatile void *bus, uint32_t bus_speed)
 
bool twi_bus_probe (bus_desc_t *bus, int arg)
 
size_t twi_bus_read (bus_desc_t *bus, uint8_t addr, void *data, size_t count)
 
size_t twi_bus_write (bus_desc_t *bus, uint8_t addr, const void *data, size_t count)
 

#define twi_bus_init   bus_init

Sensor API Bus I/O Implementations

#define twi_bus_probe   bus_probe
#define twi_bus_read   bus_read
#define twi_bus_write   bus_write

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.

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().

bool twi_bus_init ( volatile void *  bus,
uint32_t  bus_speed 
)

Initialize the TWI (master) bus I/O interface.

Parameters
busThe address of an AVR or AVR32 bus interface descriptor.
bus_speedThe bus data rate.
Return values
trueThe bus was initialized.
falseThe bus was not initialized.

References twi_options_t::speed, STATUS_OK, and twi_master_setup().

bool twi_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.

References ERR_UNSUPPORTED_DEV, and bus_desc_t::status.

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

Read bytes from remote device using TWI (master) interface

This routine reads "count" Bytes of data into location "data" from a specified TWI "bus_id" device register or memory address, "addr".

The caller must ensure that "data" specifies a valid memory address that is capable of storing the specified "count" Bytes of data.

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.

References bus_desc_t::addr, twi_package_t::chip, bus_desc_t::id, bus_desc_t::no_wait, pkg, bus_desc_t::status, STATUS_OK, and twi_master_read().

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

Write bytes to remote device using TWI (master) interface

This routine writes "count" Bytes of data from location "data" to a specified TWI "bus_id" device register or memory address, "addr".

The caller must ensure that "data" specifies a valid memory address.

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.

References bus_desc_t::addr, twi_package_t::chip, bus_desc_t::id, bus_desc_t::no_wait, pkg, bus_desc_t::status, STATUS_OK, and twi_master_write().