sppif0.c File Reference

Go to the source code of this file.

Functions

int Sppi0SetMode (u_char ix, u_char mode)
 Set mode for a given device at SPI0.
void Sppi0SetSpeed (u_char ix, u_long rate)
 Set transfer rate for a given device at SPI0.
void Sppi0Enable (u_char ix)
 Enable the serial peripheral interface 0.
void Sppi0ChipReset (u_char ix, u_char hi)
 Set or clear a configured reset line for a given device.
void Sppi0ChipSelect (u_char ix, u_char hi)
 Set or clear a configured chip select for a given device.
void Sppi0SelectDevice (u_char ix)
 Select the device at a given chip select.
void Sppi0DeselectDevice (u_char ix)
 Deselect the device at a given chip select.
void Sppi0NegSelectDevice (u_char ix)
 Select the device at a given negated chip select.
void Sppi0NegDeselectDevice (u_char ix)
 Deselect the device at a given negated chip select.
u_char Sppi0Byte (u_char 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 ( u_char  ix,
u_char  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:
ix The device index, starting at 0.
mode The 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 73 of file sppif0.c.

References _BV, and SPPI0_MAX_DEVICES.

void Sppi0SetSpeed ( u_char  ix,
u_long  rate 
)

Set transfer rate for a given device at SPI0.

Parameters:
ix The device index, starting at 0.
rate Transfer rate in bits per second.

Definition at line 96 of file sppif0.c.

References _BV, and NutGetCpuClock().

void Sppi0Enable ( u_char  ix  ) 

Enable the serial peripheral interface 0.

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

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

Definition at line 137 of file sppif0.c.

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

void Sppi0ChipReset ( u_char  ix,
u_char  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:
ix The device index, starting at 0.
hi If 0, the reset line is driven low. Otherwise the line is driven high.

Definition at line 184 of file sppif0.c.

void Sppi0ChipSelect ( u_char  ix,
u_char  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:
ix The device index, starting at 0. Same as the chip select number.
hi If 0, the chip select is driven low. Otherwise the line is driven high.

Definition at line 239 of file sppif0.c.

void Sppi0SelectDevice ( u_char  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:
ix The device index, starting at 0. The routine will not check if this is a valid number.

Definition at line 294 of file sppif0.c.

References Sppi0ChipSelect(), and Sppi0Enable().

void Sppi0DeselectDevice ( u_char  ix  ) 

Deselect the device at a given chip select.

The configured chip select line will be driven low.

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

Definition at line 308 of file sppif0.c.

References Sppi0ChipSelect().

void Sppi0NegSelectDevice ( u_char  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:
ix The device index, starting at 0. The routine will not check if this is a valid number.

Definition at line 324 of file sppif0.c.

References Sppi0ChipSelect(), and Sppi0Enable().

void Sppi0NegDeselectDevice ( u_char  ix  ) 

Deselect the device at a given negated chip select.

The configured chip select line will be driven high.

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

Definition at line 338 of file sppif0.c.

References Sppi0ChipSelect().

u_char Sppi0Byte ( u_char  data  ) 

Exchange a byte with the currently selected SPI device.

Parameters:
data Byte to transmit.
Returns:
Received byte.

Definition at line 350 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:
wdata Pointer to the data to transmit.
rdata Pointer 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 374 of file sppif0.c.

References CONST, and Sppi0Byte().


© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/