Nut/OS  4.10.3
API Reference
sbbif0.c File Reference
#include <sys/timer.h>
#include <dev/gpio.h>
#include <dev/sbbif0.h>
Include dependency graph for sbbif0.c:

Go to the source code of this file.

Functions

int Sbbi0SetMode (ureg_t ix, ureg_t mode)
 Set mode for a given device at SPI0.
void Sbbi0SetSpeed (ureg_t ix, uint32_t rate)
 Set transfer rate for a given device at SPI0.
void Sbbi0Enable (ureg_t ix)
 Enable the serial peripheral interface 0.
void Sbbi0ChipReset (ureg_t ix, ureg_t hi)
 Set or clear a configured reset line for a given device.
void Sbbi0ChipSelect (ureg_t ix, ureg_t hi)
 Set or clear a configured chip select for a given device.
void Sbbi0SelectDevice (ureg_t ix)
 Select the device at a given chip select.
void Sbbi0DeselectDevice (ureg_t ix)
 Deselect the device at a given chip select.
void Sbbi0NegSelectDevice (ureg_t ix)
 Select the device at a given negated chip select.
void Sbbi0NegDeselectDevice (ureg_t ix)
 Deselect the device at a given negated chip select.
uint8_t Sbbi0Byte (uint8_t data)
 Exchange a byte with the currently selected SPI device.
void Sbbi0Transact (CONST void *wdata, void *rdata, size_t len)
 Exchange a specified number of bytes with the currently selected SPI device.

Function Documentation

int Sbbi0SetMode ( ureg_t  ix,
ureg_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.

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 84 of file sbbif0.c.

References SBBI0_MAX_DEVICES.

void Sbbi0SetSpeed ( ureg_t  ix,
uint32_t  rate 
)

Set transfer rate for a given device at SPI0.

This is currently a dummy and does nothing.

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

Definition at line 102 of file sbbif0.c.

References NutGetCpuClock().

Here is the call graph for this function:

void Sbbi0Enable ( ureg_t  ix)

Enable the serial peripheral interface 0.

Enables SPI with the parameters previously set by Sbbi0SetMode().

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

Definition at line 138 of file sbbif0.c.

References SBBI0_MISO_ENA, SBBI0_MOSI_CLR, SBBI0_MOSI_ENA, SBBI0_SCK_CLR, SBBI0_SCK_ENA, and SBBI0_SCK_SET.

Referenced by Sbbi0NegSelectDevice(), and Sbbi0SelectDevice().

void Sbbi0ChipReset ( ureg_t  ix,
ureg_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 165 of file sbbif0.c.

References SBBI0_RST0_CLR, SBBI0_RST0_ENA, SBBI0_RST0_SET, SBBI0_RST1_CLR, SBBI0_RST1_ENA, SBBI0_RST1_SET, SBBI0_RST2_CLR, SBBI0_RST2_ENA, SBBI0_RST2_SET, SBBI0_RST3_CLR, SBBI0_RST3_ENA, and SBBI0_RST3_SET.

void Sbbi0ChipSelect ( ureg_t  ix,
ureg_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 220 of file sbbif0.c.

References SBBI0_CS0_CLR, SBBI0_CS0_ENA, SBBI0_CS0_SET, SBBI0_CS1_CLR, SBBI0_CS1_ENA, SBBI0_CS1_SET, SBBI0_CS2_CLR, SBBI0_CS2_ENA, SBBI0_CS2_SET, SBBI0_CS3_CLR, SBBI0_CS3_ENA, and SBBI0_CS3_SET.

Referenced by Sbbi0DeselectDevice(), Sbbi0NegDeselectDevice(), Sbbi0NegSelectDevice(), and Sbbi0SelectDevice().

void Sbbi0SelectDevice ( ureg_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 Sbbi0SetMode() and Sbbi0SetSpeed(). 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 275 of file sbbif0.c.

References Sbbi0ChipSelect(), and Sbbi0Enable().

Here is the call graph for this function:

void Sbbi0DeselectDevice ( ureg_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 289 of file sbbif0.c.

References Sbbi0ChipSelect().

Here is the call graph for this function:

void Sbbi0NegSelectDevice ( ureg_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 Sbbi0SetMode() and Sbbi0SetSpeed(). 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 305 of file sbbif0.c.

References Sbbi0ChipSelect(), and Sbbi0Enable().

Here is the call graph for this function:

void Sbbi0NegDeselectDevice ( ureg_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 319 of file sbbif0.c.

References Sbbi0ChipSelect().

Here is the call graph for this function:

uint8_t Sbbi0Byte ( uint8_t  data)

Exchange a byte with the currently selected SPI device.

Parameters:
dataByte to transmit.
Returns:
Received byte.

Definition at line 331 of file sbbif0.c.

References SBBI0_MISO_TST, SBBI0_MOSI_CLR, SBBI0_MOSI_SET, SBBI0_SCK_CLR, and SBBI0_SCK_SET.

Referenced by Sbbi0Transact().

void Sbbi0Transact ( 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 Sbbi0SetMode() and optionally Sbbi0SetSpeed().

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

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 436 of file sbbif0.c.

References CONST, and Sbbi0Byte().

Here is the call graph for this function: