Nut/OS  4.10.3
API Reference
at91_spi.h File Reference

AT91 peripherals. More...

#include <sys/types.h>
#include <cfg/arch.h>
Include dependency graph for at91_spi.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define SPI_SETSPEED   0x0401
#define SPI_GETSPEED   0x0402
#define SPI_SETMODE   0x0403
#define SPI_GETMODE   0x0404
#define SPIMF_MASTER   0x00000001
#define SPIMF_PCSDEC   0x00000002
#define SPIMF_MFDETECT   0x00000004
#define SPIMF_LOOPBACK   0x00000008
#define SPIMF_SCKIAHI   0x00000010
#define SPIMF_CAPRISE   0x00000020
#define SPIMF_KEEPCS   0x00000040
#define SPI_SETDATABITS   0x0405
#define SPI_GETDATABITS   0x0406

Functions

int At91Spi0Init (void)
 Initialize the first serial peripheral interface on the AT91 MCU.
int At91Spi0InitChipSelects (unsigned int mask)
 Initialize specified SPI0 chip selects on the AT91 MCU.
int At91Spi0Enable (void)
 Initialize the second serial peripheral interface on the AT91 MCU.
int At91SpiInit (unsigned int base)
 Initialize serial peripheral interface on the AT91 MCU.
int At91SpiReset (unsigned int base)
 Reset serial peripheral interface on the AT91 MCU.
int At91SpiInitChipSelects (unsigned int base, unsigned int mask)
 Initialize specified SPI chip selects on the AT91 MCU.
int At91SpiSetRate (unsigned int base, unsigned int cs, uint32_t rate)
 Configure the SPI rate.
uint32_t At91SpiGetModeFlags (unsigned int base, unsigned int cs)
int At91SpiSetModeFlags (unsigned int base, unsigned int cs, uint32_t mode)
 Configure the SPI operation mode.
unsigned int At91SpiGetBits (unsigned int base, unsigned int cs)
int At91SpiSetBits (unsigned int base, unsigned int cs, unsigned int bits)
unsigned int At91SpiGetSckDelay (unsigned int base, unsigned int cs)
int At91SpiSetSckDelay (unsigned int base, unsigned int cs, unsigned int dly)
unsigned int At91SpiGetTxDelay (unsigned int base, unsigned int cs)
int At91SpiSetTxDelay (unsigned int base, unsigned int cs, unsigned int dly)
unsigned int At91SpiGetCsDelay (unsigned int base)
int At91SpiSetCsDelay (unsigned int base, unsigned int dly)
int At91SpiTransfer2 (unsigned int base, unsigned int cs, CONST void *txbuf, void *rxbuf, int xlen, CONST void *txnbuf, void *rxnbuf, int xnlen)
 Transfer two SPI buffers.

Detailed Description

AT91 peripherals.

 *
 * $Log$
 * Revision 1.4  2009/01/17 11:26:47  haraldkipp
 * Getting rid of two remaining BSD types in favor of stdint.
 * Replaced 'u_int' by 'unsinged int' and 'uptr_t' by 'uintptr_t'.
 *
 * Revision 1.3  2008/08/11 06:59:59  haraldkipp
 * BSD types replaced by stdint types (feature request #1282721).
 *
 * Revision 1.2  2006/10/08 16:48:09  haraldkipp
 * Documentation fixed
 *
 * Revision 1.1  2006/09/29 12:34:59  haraldkipp
 * Basic AT91 SPI support added.
 *
 *
 * 

Definition in file at91_spi.h.


Define Documentation

#define SPI_SETSPEED   0x0401

Definition at line 63 of file at91_spi.h.

#define SPI_GETSPEED   0x0402

Definition at line 64 of file at91_spi.h.

#define SPI_SETMODE   0x0403

Definition at line 66 of file at91_spi.h.

#define SPI_GETMODE   0x0404

Definition at line 67 of file at91_spi.h.

#define SPIMF_MASTER   0x00000001

Definition at line 69 of file at91_spi.h.

Referenced by At45dbInit(), At91SpiGetModeFlags(), and At91SpiSetModeFlags().

#define SPIMF_PCSDEC   0x00000002

Definition at line 70 of file at91_spi.h.

Referenced by At91SpiSetModeFlags().

#define SPIMF_MFDETECT   0x00000004

Definition at line 71 of file at91_spi.h.

Referenced by At91SpiGetModeFlags(), and At91SpiSetModeFlags().

#define SPIMF_LOOPBACK   0x00000008

Definition at line 72 of file at91_spi.h.

Referenced by At91SpiGetModeFlags(), and At91SpiSetModeFlags().

#define SPIMF_SCKIAHI   0x00000010

Definition at line 73 of file at91_spi.h.

Referenced by At45dbInit(), At91SpiGetModeFlags(), and At91SpiSetModeFlags().

#define SPIMF_CAPRISE   0x00000020

Definition at line 74 of file at91_spi.h.

Referenced by At45dbInit(), At91SpiGetModeFlags(), and At91SpiSetModeFlags().

#define SPIMF_KEEPCS   0x00000040

Definition at line 75 of file at91_spi.h.

Referenced by At91SpiSetModeFlags().

#define SPI_SETDATABITS   0x0405

Definition at line 77 of file at91_spi.h.

#define SPI_GETDATABITS   0x0406

Definition at line 78 of file at91_spi.h.


Function Documentation

int At91Spi0Init ( void  )

Initialize the first serial peripheral interface on the AT91 MCU.

Definition at line 96 of file at91_spi.c.

References _BV, At91Spi0Enable(), At91SpiReset(), NutIrqEnable(), NutRegisterIrqHandler(), outr, PMC_PCER, sig_SPI0, SPI0_BASE, and SPI0_ID.

Referenced by At91SpiInit().

Here is the call graph for this function:

int At91Spi0InitChipSelects ( unsigned int  mask)

Initialize specified SPI0 chip selects on the AT91 MCU.

Parameters:
maskChip selects to use. Set bit 0 for NPCS0, bit 1 for NPCS1 and so on.
Returns:
0 on success or -1 if any of the specified chip selects is not available.

Definition at line 119 of file at91_spi.c.

References _BV, outr, PIO_PDR_OFF, SPI0_CS0_PIN, SPI0_CS0_PIO_BASE, SPI0_CS0_PSR_OFF, SPI0_CS1_PIN, SPI0_CS1_PIO_BASE, SPI0_CS1_PSR_OFF, SPI0_CS2_PIN, SPI0_CS2_PIO_BASE, SPI0_CS2_PSR_OFF, SPI0_CS3_PIN, SPI0_CS3_PIO_BASE, and SPI0_CS3_PSR_OFF.

Referenced by At91SpiInitChipSelects().

int At91Spi0Enable ( void  )

Initialize the second serial peripheral interface on the AT91 MCU.

Definition at line 155 of file at91_spi.c.

References outr, PIO_PDR_OFF, SPI0_PINS, SPI0_PIO_BASE, and SPI0_PSR_OFF.

Referenced by At91Spi0Init().

int At91SpiInit ( unsigned int  base)

Initialize serial peripheral interface on the AT91 MCU.

Parameters:
baseInterface base address, either SPI_BASE, SPI0_BASE or SPI1_BASE.
Returns:
0 on success or -1 if SPI is not available.

Definition at line 257 of file at91_spi.c.

References At91Spi0Init(), SPI0_BASE, and SPI1_BASE.

Referenced by At45dbInit().

Here is the call graph for this function:

int At91SpiReset ( unsigned int  base)

Reset serial peripheral interface on the AT91 MCU.

Parameters:
baseInterface base address, either SPI_BASE, SPI0_BASE or SPI1_BASE.
Returns:
0 on success or -1 if SPI is not available.

Definition at line 297 of file at91_spi.c.

References At91SpiDisable(), At91SpiEnable(), outr, SPI_CR_OFF, SPI_DLYBCS_LSB, SPI_MODFDIS, SPI_MR_OFF, SPI_MSTR, SPI_PCS, and SPI_SWRST.

Referenced by At45dbInit(), and At91Spi0Init().

Here is the call graph for this function:

int At91SpiInitChipSelects ( unsigned int  base,
unsigned int  mask 
)

Initialize specified SPI chip selects on the AT91 MCU.

Parameters:
baseInterface base address, either SPI_BASE, SPI0_BASE or SPI1_BASE.
maskChip selects to use. Set bit 0 for NPCS0, bit 1 for NPCS1 and so on.
Returns:
0 on success or -1 if any of the specified chip selects is not available.

Definition at line 327 of file at91_spi.c.

References At91Spi0InitChipSelects(), SPI0_BASE, and SPI1_BASE.

Referenced by At45dbInit().

Here is the call graph for this function:

int At91SpiSetRate ( unsigned int  base,
unsigned int  cs,
uint32_t  rate 
)

Configure the SPI rate.

Parameters:
baseSPI register base.
csChip select line.
rateBaudrate. The maximum is MCK/1 and the minimum is MCK/255. If the specified rate is above the maximum or below the minimum, the maximum or minimum value resp. will be set.

Definition at line 353 of file at91_spi.c.

References inr, NUT_HWCLK_PERIPHERAL, NutClockGet, outr, SPI_CSR0_OFF, SPI_CSR1_OFF, SPI_CSR2_OFF, SPI_CSR3_OFF, SPI_SCBR, and SPI_SCBR_LSB.

Referenced by At45dbInit().

uint32_t At91SpiGetModeFlags ( unsigned int  base,
unsigned int  cs 
)
int At91SpiSetModeFlags ( unsigned int  base,
unsigned int  cs,
uint32_t  mode 
)

Configure the SPI operation mode.

Parameters:
baseSPI register base.
csChip select line.
modeAny of the following
  • SPIMF_MASTER Master mode.
  • SPIMF_PCSDEC Decoded chip selects.
  • SPIMF_MFDETECT Mode fault detection.
  • SPIMF_LOOPBACK Loopback mode.
  • SPIMF_SCKIAHI Clock is high when inactive.
  • SPIMF_CAPRISE Data cpatured on rising edge.
  • SPIMF_KEEPCS Chip select remains active after transfer.
baseSPI register base.
csChip select line.
modeAny of the following
  • SPIMF_MASTER Master mode.
  • SPIMF_PCSDEC Decoded chip selects.
  • SPIMF_MFDETECT Mode fault detection.
  • SPIMF_LOOPBACK Loopback mode.
  • SPIMF_SCKIAHI Clock is high when inactive.
  • SPIMF_CAPRISE Data captured on rising edge.
  • SPIMF_KEEPCS Chip select remains active after transfer.

Definition at line 436 of file at91_spi.c.

References At91SpiGetModeFlags(), inr, outr, SPI_CPOL, SPI_CSAAT, SPI_CSR0_OFF, SPI_LLB, SPI_MODFDIS, SPI_MR_OFF, SPI_MSTR, SPI_NCPHA, SPI_PCSDEC, SPIMF_CAPRISE, SPIMF_KEEPCS, SPIMF_LOOPBACK, SPIMF_MASTER, SPIMF_MFDETECT, SPIMF_PCSDEC, and SPIMF_SCKIAHI.

Referenced by At45dbInit().

Here is the call graph for this function:

unsigned int At91SpiGetBits ( unsigned int  base,
unsigned int  cs 
)
int At91SpiSetBits ( unsigned int  base,
unsigned int  cs,
unsigned int  bits 
)

Definition at line 514 of file at91_spi.c.

References At91SpiGetBits(), inr, outr, SPI_BITS, SPI_BITS_10, SPI_BITS_11, SPI_BITS_12, SPI_BITS_13, SPI_BITS_14, SPI_BITS_15, SPI_BITS_16, SPI_BITS_8, SPI_BITS_9, and SPI_CSR0_OFF.

Here is the call graph for this function:

unsigned int At91SpiGetSckDelay ( unsigned int  base,
unsigned int  cs 
)

Definition at line 556 of file at91_spi.c.

References inr, SPI_CSR0_OFF, and SPI_DLYBS_LSB.

Referenced by At91SpiSetSckDelay().

int At91SpiSetSckDelay ( unsigned int  base,
unsigned int  cs,
unsigned int  dly 
)

Definition at line 561 of file at91_spi.c.

References At91SpiGetSckDelay(), inr, outr, SPI_CSR0_OFF, SPI_DLYBS, and SPI_DLYBS_LSB.

Here is the call graph for this function:

unsigned int At91SpiGetTxDelay ( unsigned int  base,
unsigned int  cs 
)

Definition at line 573 of file at91_spi.c.

References inr, SPI_CSR0_OFF, and SPI_DLYBCT_LSB.

Referenced by At91SpiSetTxDelay().

int At91SpiSetTxDelay ( unsigned int  base,
unsigned int  cs,
unsigned int  dly 
)

Definition at line 578 of file at91_spi.c.

References At91SpiGetTxDelay(), inr, outr, SPI_CSR0_OFF, SPI_DLYBCT, and SPI_DLYBCT_LSB.

Here is the call graph for this function:

unsigned int At91SpiGetCsDelay ( unsigned int  base)

Definition at line 590 of file at91_spi.c.

References inr, SPI_DLYBCS_LSB, and SPI_MR_OFF.

Referenced by At91SpiSetCsDelay().

int At91SpiSetCsDelay ( unsigned int  base,
unsigned int  dly 
)

Definition at line 595 of file at91_spi.c.

References At91SpiGetCsDelay(), inr, outr, SPI_DLYBCS, SPI_DLYBCS_LSB, and SPI_MR_OFF.

Here is the call graph for this function:

int At91SpiTransfer2 ( unsigned int  base,
unsigned int  cs,
CONST void *  txbuf,
void *  rxbuf,
int  xlen,
CONST void *  txnbuf,
void *  rxnbuf,
int  xnlen 
)

Transfer two SPI buffers.

Parameters:
baseSPI port base address.
csSPI device chip select.
txbufFirst transmit buffer.
rxbufFirst receive buffer.
xlenLength of first transfer.
txnbufSecond transmit buffer.
rxnbufSecond receive buffer.
xnlenLength of second transfer.

Definition at line 617 of file at91_spi.c.

References inr, NutEventWait(), outr, PDC_RXTDIS, PDC_RXTEN, PDC_TXTDIS, PDC_TXTEN, PERIPH_PTCR_OFF, PERIPH_RCR_OFF, PERIPH_RNCR_OFF, PERIPH_RNPR_OFF, PERIPH_RPR_OFF, PERIPH_TCR_OFF, PERIPH_TNCR_OFF, PERIPH_TNPR_OFF, PERIPH_TPR_OFF, SPI0_BASE, SPI1_BASE, SPI_IDR_OFF, SPI_IER_OFF, SPI_MR_OFF, SPI_PCS, SPI_PCS_0, SPI_PCS_1, SPI_PCS_2, SPI_PCS_3, SPI_RXBUFF, and SPI_SR_OFF.

Referenced by At45dbGetStatus(), and At45dbSendCmd().

Here is the call graph for this function: