Common ATmega and ATxmega SPI internals
[Generic SPI polled internals]

Collaboration diagram for Common ATmega and ATxmega SPI internals:

Modules

 ATxmega SPI internals

Defines

#define MAXLOOPS   255
 Maximum number of polling loops.
#define SPI_MASTER_NATIVE_GET_BASE(spim_p)   (&((struct spi_master_priv *)spim_p)->base.base)
 Get base definition of spi_master.
#define SPI_DEVICE_NATIVE_GET_BASE(spid_p)   (&((struct spi_device_priv *)spid_p)->base)
 Get base definition of native spi_device.
#define SPI_ID_LAST   11
 Last SPI ID.
#define SPI_ID_UART_FIRST   4
 First SPI ID which is a uart.
#define spi_id_is_valid(spi_id)   (spi_id <= SPI_ID_LAST)
 Test if SPI Module ID is valid.
#define SPI_ID_NATIVE_IS_ENABLED   false
 true if native SPI is enabled
#define SPI_ID_UART_IS_ENABLED   false
 true if uart SPI is enabled
#define SPI_MASTER_TYPE_NAME(spi_id)   spi_master_type##spi_id
 Get spi_master derived type name from spi_id.
#define DECLARE_SPI_MASTER(spi_id, varname)   struct SPI_MASTER_TYPE_NAME(spi_id) varname
 Declare a spi_master derived struct for given SPI Module ID.
#define SPI_DEVICE_TYPE_NAME(spi_id)   spi_device_type##spi_id
 Get spi_device derived type name from spi_id.
#define DECLARE_SPI_DEVICE(spi_id, varname)   struct SPI_DEVICE_TYPE_NAME(spi_id) varname
 Declare a spi_device derived struct for given SPI Module ID.

Typedefs

typedef uint8_t maxloops_t
 Defintion of poll loop counter variable.

Functions

static void spi_poll (struct workqueue_task *task)
 Poll SPI registers for required actions.
void spi_priv_master_setup_device (spi_id_t spi_id, struct spi_device *device, spi_flags_t flags, unsigned long baud_rate, board_spi_select_id_t sel_id)
 Private setup SPI device.
void spi_priv_select_device (struct spi_master *master, struct spi_device *device)
 Private select SPI device.
void spi_priv_deselect_device (struct spi_master *master, struct spi_device *device)
 Private deselect SPI device.
void spi_priv_master_init (spi_id_t spi_id, struct spi_master *master)
 Private init SPI master.
static struct spi_masterspi_master_get_base (spi_id_t spi_id, void *priv)
 Multiplex statements based on spi_id.
static size_t spi_master_get_size (spi_id_t spi_id)
 Get spi_master derived struct size for the given SPI Module ID.
static struct spi_devicespi_device_get_base (spi_id_t spi_id, void *priv)
 Get base defintion of spi_device.
static size_t spi_device_get_size (spi_id_t spi_id)
 Get spi_device derived struct size for the given SPI Module ID.
static void spi_priv_enable (spi_id_t spi_id)
 Private SPI enable.
static void spi_priv_disable (spi_id_t spi_id)
 Private SPI disable.
static bool spi_priv_is_enabled (spi_id_t spi_id)
 Private SPI is enabled.
static bool spi_priv_is_int_flag_set (struct spi_master *spim)
 Test if SPI interrupt flag is set.
static uint8_t spi_priv_read_data (struct spi_master *spim)
 SPI read data register.
static void spi_priv_write_data (struct spi_master *spim, uint8_t data)
 SPI write data register.
static void spi_priv_master_setup_device_regs (struct spi_device *device, spi_flags_t flags, unsigned long baud_rate)
 Setup SPI device register specifics.
static void spi_priv_select_device_regs (struct spi_master *spim, struct spi_device *device)
 Select SPI device register specifics.
static void spi_priv_deselect_device_regs (struct spi_master *spim, struct spi_device *device)
 Deselect SPI device register specifics.
static void spi_priv_master_init_regs (spi_id_t spi_id, struct spi_master *spim)
 Init SPI master register specifics.

Define Documentation

#define DECLARE_SPI_DEVICE ( spi_id,
varname   )     struct SPI_DEVICE_TYPE_NAME(spi_id) varname

Declare a spi_device derived struct for given SPI Module ID.

Parameters:
spi_id SPI Module ID
varname Name to declare it as

Definition at line 331 of file spi_mega_xmega.h.

#define DECLARE_SPI_MASTER ( spi_id,
varname   )     struct SPI_MASTER_TYPE_NAME(spi_id) varname

Declare a spi_master derived struct for given SPI Module ID.

Parameters:
spi_id SPI Module ID
varname Name to declare it as

Definition at line 257 of file spi_mega_xmega.h.

#define MAXLOOPS   255

Maximum number of polling loops.

This is the maximum number of loops run in the polling function before it must reschedule itself.

Definition at line 69 of file spi_mega_xmega.c.

Referenced by spi_poll().

#define SPI_DEVICE_NATIVE_GET_BASE ( spid_p   )     (&((struct spi_device_priv *)spid_p)->base)

Get base definition of native spi_device.

Parameters:
spid_p Pointer to spi_device_priv

Referenced by spi_device_get_base().

#define SPI_DEVICE_TYPE_NAME ( spi_id   )     spi_device_type##spi_id

Get spi_device derived type name from spi_id.

Parameters:
spi_id SPI Module ID

Definition at line 323 of file spi_mega_xmega.h.

#define spi_id_is_valid ( spi_id   )     (spi_id <= SPI_ID_LAST)

Test if SPI Module ID is valid.

Parameters:
spi_id SPI Module ID
Return values:
true Id is valid
false Not a valid id

Definition at line 232 of file spi_mega_xmega.h.

Referenced by spi_device_get_base(), spi_device_get_size(), spi_disable(), spi_enable(), spi_is_enabled(), spi_master_get_base(), and spi_master_get_size().

#define SPI_ID_LAST   11

Last SPI ID.

Definition at line 72 of file spi.h.

#define SPI_ID_NATIVE_IS_ENABLED   false

true if native SPI is enabled

Definition at line 78 of file spi.h.

#define SPI_ID_UART_FIRST   4

First SPI ID which is a uart.

Definition at line 71 of file spi.h.

#define SPI_ID_UART_IS_ENABLED   false

true if uart SPI is enabled

Definition at line 87 of file spi.h.

#define SPI_MASTER_NATIVE_GET_BASE ( spim_p   )     (&((struct spi_master_priv *)spim_p)->base.base)

Get base definition of spi_master.

Parameters:
spim_p Pointer to private derived spi_master

Referenced by spi_master_get_base().

#define SPI_MASTER_TYPE_NAME ( spi_id   )     spi_master_type##spi_id

Get spi_master derived type name from spi_id.

Parameters:
spi_id SPI Module ID

Definition at line 249 of file spi_mega_xmega.h.


Typedef Documentation

Defintion of poll loop counter variable.

For internal use only.

This helps the compiler in optimizing the loop to be as fast as possible

Definition at line 79 of file spi_mega_xmega.c.


Function Documentation

static struct spi_device* spi_device_get_base ( spi_id_t  spi_id,
void *  priv 
) [static, read]

Get base defintion of spi_device.

Parameters:
spi_id SPI Module ID
priv Pointer to private declared SPI device struct

Definition at line 340 of file spi_mega_xmega.h.

References assert, SPI_DEVICE_NATIVE_GET_BASE, and spi_id_is_valid.

static size_t spi_device_get_size ( spi_id_t  spi_id  )  [inline, static]

Get spi_device derived struct size for the given SPI Module ID.

Parameters:
spi_id SPI Module ID

Definition at line 355 of file spi_mega_xmega.h.

References assert, SPI_DEVICE_NATIVE_TYPE, and spi_id_is_valid.

static struct spi_master* spi_master_get_base ( spi_id_t  spi_id,
void *  priv 
) [static, read]

Multiplex statements based on spi_id.

This multiplexing definition is set up based on what SPI driver variants have been enabled thru config. For a single variant any testing on spi_id is bypassed, and for several spi_id is used for multiplexing.

The statements in native and uart are a bit off in concern to c-syntax, but contains the whole statement to be used for that variant.

Parameters:
spi_id SPI Module ID
native Statement to run if it's native based
uart Statement to run if it's uart based Get base defintion of spi_master
spi_id SPI Module ID
priv Pointer to private declared spi master

Definition at line 294 of file spi_mega_xmega.h.

References assert, spi_id_is_valid, and SPI_MASTER_NATIVE_GET_BASE.

static size_t spi_master_get_size ( spi_id_t  spi_id  )  [inline, static]

Get spi_master derived struct size for the given SPI Module ID.

Parameters:
spi_id SPI Module ID

Definition at line 309 of file spi_mega_xmega.h.

References assert, spi_id_is_valid, and SPI_MASTER_NATIVE_TYPE.

static void spi_poll ( struct workqueue_task task  )  [static]

Poll SPI registers for required actions.

For internal use only.

Parameters:
task Polling task structure
Note:
This poll function flow is optimized for best performance with the SPI hardware. There are two critical paths that should be as short as possible:

1. Time between interrupt flag is set to write of data register for next transfer should be as short as possible. This to keep the time between transfers as short as possible.

2. Time between writing and checking the interrupt flag should be minimum 16 cycles long. Maximum speed of spi is half of cpu clock, and with a 8-bit transfer this ideally should happen within 16 cpu cycles.

Definition at line 102 of file spi_mega_xmega.c.

References spi_master_polled::base, container_of, nested_workqueue::current, main_workqueue, MAXLOOPS, spi_master::nwq, spi_master_polled::op, spi_master_polled::poll, spi_master_polled::read_data, spi_master::residue, SPI_OP_READ, SPI_OP_WRITE, spi_polled_is_buffer_op(), spi_polled_sched_next_buffer(), spi_polled_sched_poll(), spi_priv_is_int_flag_set(), spi_priv_read_data(), spi_priv_write_data(), spi_master::status, STATUS_OK, test_bit, workqueue_add_task(), and spi_master_polled::write_data.

void spi_priv_deselect_device ( struct spi_master master,
struct spi_device device 
)

Private deselect SPI device.

Parameters:
master SPI master struct
device SPI device struct

Referenced by spi_deselect_device().

void spi_priv_deselect_device_regs ( struct spi_master spim,
struct spi_device device 
) [inline, static]

Deselect SPI device register specifics.

Parameters:
spim SPI master struct
device SPI device struct

Definition at line 170 of file spi_xmega.h.

void spi_priv_disable ( spi_id_t  spi_id  )  [inline, static]

Private SPI disable.

Parameters:
spi_id SPI Module ID

Definition at line 104 of file spi_xmega.h.

References spi_write_reg, sysclk_disable_module(), and SYSCLK_SPI.

Referenced by spi_disable().

void spi_priv_enable ( spi_id_t  spi_id  )  [inline, static]

Private SPI enable.

Parameters:
spi_id SPI Module ID

Definition at line 98 of file spi_xmega.h.

References SPI_BIT, spi_write_reg, sysclk_enable_module(), and SYSCLK_SPI.

Referenced by spi_enable().

bool spi_priv_is_enabled ( spi_id_t  spi_id  )  [inline, static]

Private SPI is enabled.

Parameters:
spi_id SPI Module ID
Return values:
true SPI is enabled
false SPI is disabled

Definition at line 110 of file spi_xmega.h.

References SPI_BIT, and spi_read_reg.

Referenced by spi_is_enabled().

bool spi_priv_is_int_flag_set ( struct spi_master spim  )  [inline, static]

Test if SPI interrupt flag is set.

Parameters:
spim SPI master struct
Return values:
true Interrupt flag is set
false Interrupt flag is not set

Definition at line 116 of file spi_xmega.h.

References spi_master_priv::regs, SPI_BIT, and spi_read_reg.

Referenced by spi_poll().

void spi_priv_master_init ( spi_id_t  spi_id,
struct spi_master master 
)

Private init SPI master.

Parameters:
spi_id SPI Module ID
master SPI master struct

Referenced by spi_master_init().

void spi_priv_master_init_regs ( spi_id_t  spi_id,
struct spi_master spim 
) [inline, static]

Init SPI master register specifics.

Parameters:
spi_id SPI Module ID
spim SPI master struct

Definition at line 175 of file spi_xmega.h.

References spi_master_priv::regs, SPI_BIT, spi_read_reg, and spi_write_reg.

void spi_priv_master_setup_device ( spi_id_t  spi_id,
struct spi_device device,
spi_flags_t  flags,
unsigned long  baud_rate,
board_spi_select_id_t  sel_id 
)

Private setup SPI device.

Parameters:
spi_id SPI Module ID
device SPI device struct
flags Flags
baud_rate Baud rate
sel_id Board select id

Referenced by spi_master_setup_device().

void spi_priv_master_setup_device_regs ( struct spi_device device,
spi_flags_t  flags,
unsigned long  baud_rate 
) [inline, static]

Setup SPI device register specifics.

Parameters:
device SPI device struct
flags Flags
baud_rate Baud rate

Definition at line 137 of file spi_xmega.h.

References spi_device_priv::ctrl, SPI_BF, and SPI_BIT.

uint8_t spi_priv_read_data ( struct spi_master spim  )  [inline, static]

SPI read data register.

Parameters:
spim SPI master struct
Returns:
Value from data register

Definition at line 123 of file spi_xmega.h.

References spi_master_priv::regs, and spi_read_reg.

Referenced by spi_poll().

void spi_priv_select_device ( struct spi_master master,
struct spi_device device 
)

Private select SPI device.

Parameters:
master SPI master struct
device SPI device struct

Referenced by spi_select_device().

void spi_priv_select_device_regs ( struct spi_master spim,
struct spi_device device 
) [inline, static]

Select SPI device register specifics.

Parameters:
spim SPI master struct
device SPI device struct

Definition at line 161 of file spi_xmega.h.

References spi_device_priv::ctrl, spi_master_priv::regs, and spi_write_reg.

void spi_priv_write_data ( struct spi_master spim,
uint8_t  data 
) [inline, static]

SPI write data register.

Parameters:
spim SPI master struct
data Data byte to write

Definition at line 130 of file spi_xmega.h.

References spi_master_priv::regs, and spi_write_reg.

Referenced by spi_poll().

Generated on Thu Apr 29 15:18:24 2010 for display-training by  doxygen 1.6.3