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>
Go to the source code of this file.
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 2467 2009-02-17 09:30:02Z haraldkipp $ *
Definition in file spibus0avr.c.
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. |
Definition at line 255 of file spibus0avr.c.
References cbi, inb, NUT_WAIT_INFINITE, NUTASSERT, NutEventWait(), outb, and sbi.
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. |
Definition at line 366 of file spibus0avr.c.
References AvrSpiSetup(), _NUTSPIBUS::bus_sig, malloc(), _NUTSPINODE::node_bus, _NUTSPINODE::node_cs, _NUTSPINODE::node_mode, _NUTSPINODE::node_stat, NUTASSERT, NutRegisterIrqHandler(), 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. |
Definition at line 405 of file spibus0avr.c.
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, NUTASSERT, NutEventPost(), NutEventWait(), outb, sbi, SPI_MODE_CSHIGH, and SPI_MODE_UPDATE.
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. |
Definition at line 477 of file spibus0avr.c.
References _NUTSPIBUS::bus_mutex, _NUTSPINODE::node_bus, _NUTSPINODE::node_cs, _NUTSPINODE::node_mode, 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.
Definition at line 498 of file spibus0avr.c.