Nut/OS  4.10.3
API Reference
spibus0avr.c File Reference

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>
Include dependency graph for spibus0avr.c:

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.

Detailed Description

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.


Function Documentation

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.

Parameters:
nodeSpecifies the SPI bus node.
txbufPointer to the transmit buffer. If NULL, undetermined byte values are transmitted.
rxbufPointer to the receive buffer. If NULL, then incoming data is discarded.
xlenNumber of bytes to transfer.
Returns:
Always 0.

Definition at line 255 of file spibus0avr.c.

References cbi, inb, NUT_WAIT_INFINITE, NUTASSERT, NutEventWait(), outb, and sbi.

Here is the call graph for this function:

int AvrSpiBus0NodeInit ( NUTSPINODE node)

Initialize an SPI bus node.

This routine is called for each SPI node, which is registered via NutRegisterSpiDevice().

Parameters:
nodeSpecifies the SPI bus node.
Returns:
0 on success or -1 if there is no valid chip select.

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.

Here is the call graph for this function:

int AvrSpiBus0Select ( NUTSPINODE node,
uint32_t  tmo 
)

Select a device on the SPI bus.

Locks and activates the bus for the specified node.

Parameters:
nodeSpecifies the SPI bus node.
tmoTimeout in milliseconds. To disable timeout, set this parameter to NUT_WAIT_INFINITE.
Returns:
0 on success. In case of an error, -1 is returned and the bus is not locked.

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.

Here is the call graph for this function:

int AvrSpiBus0Deselect ( NUTSPINODE node)

Deselect a device on the SPI bus.

Deactivates the chip select and unlocks the bus.

Parameters:
nodeSpecifies the SPI bus node.
Returns:
Always 0.

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.

Here is the call graph for this function:


Variable Documentation

Initial value:

AVR SPI bus driver implementation structure.

Definition at line 498 of file spibus0avr.c.