Nut/OS  4.10.3
API Reference
sppif0.c File Reference
#include <cfg/arch/avr.h>
#include <sys/timer.h>
#include <dev/sppif0.h>
Include dependency graph for sppif0.c:

Go to the source code of this file.

Functions

int Sppi0SetMode (uint8_t ix, uint8_t mode)
 Set mode for a given device at SPI0.
void Sppi0SetSpeed (uint8_t ix, uint32_t rate)
 Set transfer rate for a given device at SPI0.
void Sppi0Enable (uint8_t ix)
 Enable the serial peripheral interface 0.
void Sppi0ChipReset (uint8_t ix, uint8_t hi)
 Set or clear a configured reset line for a given device.
void Sppi0ChipSelect (uint8_t ix, uint8_t hi)
 Set or clear a configured chip select for a given device.
void Sppi0SelectDevice (uint8_t ix)
 Select the device at a given chip select.
void Sppi0DeselectDevice (uint8_t ix)
 Deselect the device at a given chip select.
void Sppi0NegSelectDevice (uint8_t ix)
 Select the device at a given negated chip select.
void Sppi0NegDeselectDevice (uint8_t ix)
 Deselect the device at a given negated chip select.
uint8_t Sppi0Byte (uint8_t data)
 Exchange a byte with the currently selected SPI device.
void Sppi0Transact (CONST void *wdata, void *rdata, size_t len)
 Exchange a specified number of bytes with the currently selected SPI device.

Function Documentation

int Sppi0SetMode ( uint8_t  ix,
uint8_t  mode 
)

Set mode for a given device at SPI0.

This is typically the first call in order to use the device. It will not directly enable the SPI hardware. This is done when selecting the device.

The transfer rate is set to the lowest possible value and can be adjusted by calling Sppi0SetSpeed().

Parameters:
ixThe device index, starting at 0.
modeThe mode to set.
  • 0: Leading edge is rising, data sampled on rising edge.
  • 1: Leading edge is rising, data sampled on falling edge.
  • 2: Leading edge is falling, data sampled on falling edge.
  • 3: Leading edge is falling, data sampled on rising edge.
Returns:
0, if the device index and the mode are both valid. Otherwise the return value will be -1.

Definition at line 76 of file sppif0.c.

References _BV, and SPPI0_MAX_DEVICES.

void Sppi0SetSpeed ( uint8_t  ix,
uint32_t  rate 
)

Set transfer rate for a given device at SPI0.

Parameters:
ixThe device index, starting at 0.
rateTransfer rate in bits per second.

Definition at line 99 of file sppif0.c.

References _BV, and NutGetCpuClock().

Here is the call graph for this function:

void Sppi0Enable ( uint8_t  ix)

Enable the serial peripheral interface 0.

Enables SPI with the parameters previously set by Sppi0SetMode() and Sppi0SetSpeed().

Parameters:
ixThe device index, starting at 0. The routine will not check if this is valid.

Definition at line 140 of file sppif0.c.

References _BV, bit_is_clear, cbi, inb, outb, and sbi.

void Sppi0ChipReset ( uint8_t  ix,
uint8_t  hi 
)

Set or clear a configured reset line for a given device.

Reset lines must be configured when building the system libraries. This routine silently ignores them, if not configured.

Parameters:
ixThe device index, starting at 0.
hiIf 0, the reset line is driven low. Otherwise the line is driven high.

Definition at line 187 of file sppif0.c.

void Sppi0ChipSelect ( uint8_t  ix,
uint8_t  hi 
)

Set or clear a configured chip select for a given device.

Chip selects must be configured when building the system libraries. This routine silently ignores selects, if they are not configured.

Parameters:
ixThe device index, starting at 0. Same as the chip select number.
hiIf 0, the chip select is driven low. Otherwise the line is driven high.

Definition at line 242 of file sppif0.c.

void Sppi0SelectDevice ( uint8_t  ix)

Select the device at a given chip select.

Enables the serial peripheral interface with the parameters previously set for the given device by Sppi0SetMode() and Sppi0SetSpeed(). Then the configured chip select line is driven high.

Parameters:
ixThe device index, starting at 0. The routine will not check if this is a valid number.

Definition at line 297 of file sppif0.c.

References Sppi0ChipSelect(), and Sppi0Enable().

Here is the call graph for this function:

void Sppi0DeselectDevice ( uint8_t  ix)

Deselect the device at a given chip select.

The configured chip select line will be driven low.

Parameters:
ixThe device index, starting at 0. The routine will not check if this is a valid number.

Definition at line 311 of file sppif0.c.

References Sppi0ChipSelect().

Here is the call graph for this function:

void Sppi0NegSelectDevice ( uint8_t  ix)

Select the device at a given negated chip select.

Enables the serial peripheral interface with the parameters previously set for the given device by Sppi0SetMode() and Sppi0SetSpeed(). Then the configured chip select line is driven low.

Parameters:
ixThe device index, starting at 0. The routine will not check if this is a valid number.

Definition at line 327 of file sppif0.c.

References Sppi0ChipSelect(), and Sppi0Enable().

Here is the call graph for this function:

void Sppi0NegDeselectDevice ( uint8_t  ix)

Deselect the device at a given negated chip select.

The configured chip select line will be driven high.

Parameters:
ixThe device index, starting at 0. The routine will not check if this is a valid number.

Definition at line 341 of file sppif0.c.

References Sppi0ChipSelect().

Here is the call graph for this function:

uint8_t Sppi0Byte ( uint8_t  data)

Exchange a byte with the currently selected SPI device.

Parameters:
dataByte to transmit.
Returns:
Received byte.

Definition at line 353 of file sppif0.c.

References inb, loop_until_bit_is_set, and outb.

Referenced by Sppi0Transact().

void Sppi0Transact ( CONST void *  wdata,
void *  rdata,
size_t  len 
)

Exchange a specified number of bytes with the currently selected SPI device.

It is assumed, that the serial peripheral interface has been properly initialized by calling Sppi0SetMode() and optionally Sppi0SetSpeed().

Further it is assumed, that the chip select (if there is one) had been enabled by a previous call to Sppi0SelectDevice() or Sppi0NegSelectDevice().

Parameters:
wdataPointer to the data to transmit.
rdataPointer to a buffer that receives the data from the device. Can be set to NULL for transmit only. May also point to the tranmit buffer, in which case the transmitted bytes are replaced by the bytes received.

Definition at line 377 of file sppif0.c.

References CONST, and Sppi0Byte().

Here is the call graph for this function: