AVR SPI bus 0 driver. More...
#include <cfg/spi.h>
#include <cfg/arch/gpio.h>
#include <dev/spibus_avr.h>
#include <dev/irqreg.h>
#include <sys/event.h>
#include <sys/nutdebug.h>
#include <errno.h>
#include <stdlib.h>
#include <memdebug.h>
Functions | |
int | AvrSpiBus0Transfer (NUTSPINODE *node, const void *txbuf, void *rxbuf, int xlen) |
Transfer data on the SPI bus. | |
int | AvrSpiBus0NodeInit (NUTSPINODE *node) |
Initialize an SPI bus node. | |
int | AvrSpiBus0Select (NUTSPINODE *node, uint32_t tmo) |
Select a device on the SPI bus. | |
int | AvrSpiBus0Deselect (NUTSPINODE *node) |
Deselect a device on the SPI bus. | |
Variables | |
NUTSPIBUS | spiBus0Avr |
AVR SPI bus driver implementation structure. |
AVR SPI bus 0 driver.
May be configured as an interrupt driven or polling driver. The interrupt driven version may use single or double buffering.
Single buffer interrupt mode is the default.
Polling mode requires about 300 bytes less code and is roughly 10% faster. However, it blocks the CPU during the whole transfer.
Double buffering additionally requires about 200 bytes of code space and is only slightly faster (less than 1%).
* $Id: spibus0avr.c 4473 2012-08-20 15:12:45Z haraldkipp $ *
int AvrSpiBus0Transfer | ( | NUTSPINODE * | node, |
const void * | txbuf, | ||
void * | rxbuf, | ||
int | xlen | ||
) |
Transfer data on the SPI bus.
A device must have been selected by calling AvrSpi0Select().
Depending on the configuration, this routine implemets polling or interrupt mode. For the latter either single or double buffering may have been selected.
When using double buffered interrupt mode, then the transfer may be still in progress when returning from this function.
node | Specifies the SPI bus node. |
txbuf | Pointer to the transmit buffer. If NULL, undetermined byte values are transmitted. |
rxbuf | Pointer to the receive buffer. If NULL, then incoming data is discarded. |
xlen | Number of bytes to transfer. |
References cbi, inb, NULL, NUT_WAIT_INFINITE, NUTASSERT, NutEventWait(), outb, sbi, SPCR, SPDR, and SPSR.
int AvrSpiBus0NodeInit | ( | NUTSPINODE * | node | ) |
Initialize an SPI bus node.
This routine is called for each SPI node, which is registered via NutRegisterSpiDevice().
node | Specifies the SPI bus node. |
References AvrSpiSetup(), _NUTSPIBUS::bus_sig, malloc(), _NUTSPINODE::node_bus, _NUTSPINODE::node_cs, _NUTSPINODE::node_mode, _NUTSPINODE::node_stat, NULL, NUTASSERT, NutRegisterIrqHandler(), rc, and SPI_MODE_CSHIGH.
int AvrSpiBus0Select | ( | NUTSPINODE * | node, |
uint32_t | tmo | ||
) |
Select a device on the SPI bus.
Locks and activates the bus for the specified node.
node | Specifies the SPI bus node. |
tmo | Timeout in milliseconds. To disable timeout, set this parameter to NUT_WAIT_INFINITE. |
References _BV, _AVRSPIREG::avrspi_spcr, AvrSpiSetup(), bit_is_clear, _NUTSPIBUS::bus_mutex, cbi, EIO, errno, inb, _NUTSPINODE::node_bus, _NUTSPINODE::node_cs, _NUTSPINODE::node_mode, _NUTSPINODE::node_stat, NULL, NUTASSERT, NutEventPost(), NutEventWait(), outb, rc, sbi, SPCR, SPDR, SPI_MODE_CSHIGH, SPI_MODE_UPDATE, and SPSR.
int AvrSpiBus0Deselect | ( | NUTSPINODE * | node | ) |
Deselect a device on the SPI bus.
Deactivates the chip select and unlocks the bus.
node | Specifies the SPI bus node. |
References _NUTSPIBUS::bus_mutex, _NUTSPINODE::node_bus, _NUTSPINODE::node_cs, _NUTSPINODE::node_mode, NULL, NUT_WAIT_INFINITE, NUTASSERT, NutEventPost(), and SPI_MODE_CSHIGH.
{ NULL, NULL, 0, &sig_SPI, AvrSpiBus0NodeInit, AvrSpiBus0Select, AvrSpiBus0Deselect, AvrSpiBus0Transfer, NutSpiBusWait, NutSpiBusSetMode, NutSpiBusSetRate, NutSpiBusSetBits }
AVR SPI bus driver implementation structure.