Contiki-NG
|
Files | |
file | spi.c |
Implementation of the platform-independent aspects of the SPI HAL. | |
file | spi.h |
Header file for the SPI HAL. | |
Data Structures | |
struct | spi_device |
SPI Device Configuration. More... | |
Macros | |
#define | SPI_DEVICE_PORT(member, device) (device)->port_spi_##member |
Retrieve the SPI device's port number if applicable. | |
Functions | |
spi_status_t | spi_acquire (const spi_device_t *dev) |
Locks and then opens an SPI controller. | |
spi_status_t | spi_release (const spi_device_t *dev) |
Closes and then unlocks an SPI controller. | |
spi_status_t | spi_select (const spi_device_t *dev) |
Selects the SPI peripheral. | |
spi_status_t | spi_deselect (const spi_device_t *dev) |
Deselects the SPI peripheral. | |
bool | spi_has_bus (const spi_device_t *dev) |
Checks if a device has locked an SPI controller. | |
spi_status_t | spi_write_byte (const spi_device_t *dev, uint8_t data) |
Writes a single byte to an SPI device. | |
spi_status_t | spi_write (const spi_device_t *dev, const uint8_t *data, int size) |
Writes a buffer to an SPI device. | |
spi_status_t | spi_read_byte (const spi_device_t *dev, uint8_t *data) |
Reads a single byte from an SPI device. | |
spi_status_t | spi_read (const spi_device_t *dev, uint8_t *data, int size) |
Reads a buffer from an SPI device. | |
spi_status_t | spi_read_skip (const spi_device_t *dev, int size) |
Reads and ignores data from an SPI device. | |
spi_status_t | spi_transfer (const spi_device_t *dev, const uint8_t *data, int wsize, uint8_t *buf, int rsize, int ignore) |
Performs a generic SPI transfer. | |
spi_status_t | spi_read_register (const spi_device_t *dev, uint8_t reg, uint8_t *data, int size) |
Reads a buffer of bytes from a register of an SPI device. | |
spi_status_t | spi_strobe (const spi_device_t *dev, uint8_t strobe, uint8_t *status) |
Reads and Writes one byte from/to an SPI device. | |
bool | spi_arch_has_lock (const spi_device_t *dev) |
Checks if a device has locked an SPI controller. | |
bool | spi_arch_is_bus_locked (const spi_device_t *dev) |
Checks if an SPI controller is locked by any device. | |
spi_status_t | spi_arch_lock_and_open (const spi_device_t *dev) |
Locks and opens an SPI controller to the configuration specified. | |
spi_status_t | spi_arch_close_and_unlock (const spi_device_t *dev) |
Closes and unlocks an SPI controller. | |
spi_status_t | spi_arch_transfer (const spi_device_t *dev, const uint8_t *data, int wlen, uint8_t *buf, int rlen, int ignore_len) |
Performs an SPI transfer. | |
enum | spi_status_t |
SPI return codes. | |
typedef struct spi_device | spi_device_t |
SPI Device Configuration. | |
The SPI HAL provides a set of common functions that can be used in a platform-independent fashion.
#define SPI_DEVICE_PORT | ( | member, | |
device ) (device)->port_spi_##member |
Retrieve the SPI device's port number if applicable.
member | Retrieve struct member port_spi_member (e.g. port_spi_miso) |
device | A pointer the a variable of type spi_device_t |
The same macro is used for all four port_spi_foo members of the struct. So to retrieve port_spi_cs, use SPI_DEVICE_PORT(cs, device). Replace cs with mosi to retrieve port_spi_mosi.
Definition at line 129 of file spi.h.
Referenced by spi_deselect(), and spi_select().
typedef struct spi_device spi_device_t |
SPI Device Configuration.
This is a structure to an architecture-independent SPI configuration.
spi_status_t spi_acquire | ( | const spi_device_t * | dev | ) |
Locks and then opens an SPI controller.
dev | An SPI device configuration which defines the controller to be locked and the opening configuration. |
Definition at line 46 of file spi.c.
References spi_arch_lock_and_open().
Referenced by ext_flash_open().
spi_status_t spi_arch_close_and_unlock | ( | const spi_device_t * | dev | ) |
Closes and unlocks an SPI controller.
dev | An SPI device configuration that specifies the controller. |
This should turn off the SPI controller to put it in low power mode and unlock it. It should work only if the device has already locked the SPI controller.
< SSI[1:0] clocks - active mode
Definition at line 268 of file spi-arch.c.
References spi_arch_has_lock(), and SYS_CTRL_RCGCSSI.
Referenced by spi_release().
bool spi_arch_has_lock | ( | const spi_device_t * | dev | ) |
Checks if a device has locked an SPI controller.
dev | An SPI device configuration which defines the controller to be checked if it is locked and the respective device. |
Definition at line 151 of file spi-arch.c.
Referenced by spi_arch_close_and_unlock(), spi_arch_transfer(), spi_has_bus(), spi_read(), spi_read_byte(), spi_read_skip(), spi_select(), spi_strobe(), spi_transfer(), spi_write(), and spi_write_byte().
bool spi_arch_is_bus_locked | ( | const spi_device_t * | dev | ) |
Checks if an SPI controller is locked by any device.
dev | An SPI device configuration which defines the controller to be checked. |
Definition at line 161 of file spi-arch.c.
Referenced by spi_arch_lock_and_open().
spi_status_t spi_arch_lock_and_open | ( | const spi_device_t * | dev | ) |
Locks and opens an SPI controller to the configuration specified.
dev | An SPI device configuration. |
This should work only if the device has already locked the SPI controller.
< Serial clock phase (H)
< Serial clock phase (O)
< GPIO_A
< Mode control select
< Override Disabled
< GPIO_A
< Data direction register
< GPIO_A
< Data register
< SSI[1:0] clocks - active mode
< Control register 1
< Clock configuration
< GPIO_A
< Mode control select
< GPIO_A
< Mode control select
< GPIO_A
< Mode control select
< Override Disabled
< Override Disabled
< Override Disabled
< Clock divider
< Control register 0
< Control register 0
< Control register 0
< Serial clock rate mask
< Serial clock rate shift
< Control register 1
< Synchronous serial port enable
Definition at line 171 of file spi-arch.c.
References GPIO_PERIPHERAL_CONTROL, GPIO_PIN_MASK, GPIO_PORT_TO_BASE, GPIO_SET_OUTPUT, GPIO_SET_PIN, GPIO_SOFTWARE_CONTROL, IOC_OVERRIDE_DIS, ioc_set_over(), ioc_set_sel(), spi_arch_is_bus_locked(), SSI_CC, SSI_CPSR, SSI_CR0, SSI_CR0_SCR_S, SSI_CR0_SPH, SSI_CR0_SPO, SSI_CR1, SSI_CR1_SSE, and SYS_CTRL_RCGCSSI.
Referenced by spi_acquire().
spi_status_t spi_arch_transfer | ( | const spi_device_t * | dev, |
const uint8_t * | data, | ||
int | wlen, | ||
uint8_t * | buf, | ||
int | rlen, | ||
int | ignore_len ) |
Performs an SPI transfer.
dev | An SPI device configuration that specifies the controller. |
data | A pointer to the data to be written. Set it to NULL to skip writing. |
wlen | Length of data to write. |
buf | A pointer to buffer to copy the data read. Set to NULL to skip reading. |
rlen | Length of data to read. |
ignore_len | Length of data to read and ignore. |
It should work only if the device has already locked the SPI controller. A total of rlen+ignore_len bytes will be read. The first rlen bytes will be copied to buf. The remaining ignore_len bytes won't be copied to the buffer. The maximum of wlen and rlen+ignore_len of bytes will be transfered.
Definition at line 286 of file spi-arch.c.
References spi_arch_has_lock().
Referenced by spi_read(), spi_read_byte(), spi_read_skip(), spi_strobe(), spi_transfer(), spi_write(), and spi_write_byte().
spi_status_t spi_deselect | ( | const spi_device_t * | dev | ) |
Deselects the SPI peripheral.
dev | An SPI device configuration which defines the CS pin. |
Sets the CS pin. Lock is not required.
Definition at line 80 of file spi.c.
References SPI_DEVICE_PORT.
Referenced by deselect().
bool spi_has_bus | ( | const spi_device_t * | dev | ) |
Checks if a device has locked an SPI controller.
dev | An SPI device configuration which defines the controller. |
Definition at line 88 of file spi.c.
References spi_arch_has_lock().
spi_status_t spi_read | ( | const spi_device_t * | dev, |
uint8_t * | data, | ||
int | size ) |
Reads a buffer from an SPI device.
dev | An SPI device configuration. |
data | A pointer to the data |
size | Size of the data to read |
It should work only if the device has already locked the SPI controller.
Definition at line 140 of file spi.c.
References spi_arch_has_lock(), and spi_arch_transfer().
Referenced by ext_flash_read(), spi_read_register(), verify_part(), and wait_ready().
spi_status_t spi_read_byte | ( | const spi_device_t * | dev, |
uint8_t * | data ) |
Reads a single byte from an SPI device.
dev | An SPI device configuration. |
data | A pointer to a byte of data |
It should work only if the device has already locked the SPI controller.
Definition at line 126 of file spi.c.
References spi_arch_has_lock(), and spi_arch_transfer().
spi_status_t spi_read_register | ( | const spi_device_t * | dev, |
uint8_t | reg, | ||
uint8_t * | data, | ||
int | size ) |
Reads a buffer of bytes from a register of an SPI device.
dev | An SPI device configuration. |
reg | Register |
data | A pointer to the data |
size | Size of the data to read |
It should work only if the device has already locked the SPI controller.
Definition at line 192 of file spi.c.
References spi_read(), and spi_write_byte().
spi_status_t spi_read_skip | ( | const spi_device_t * | dev, |
int | size ) |
Reads and ignores data from an SPI device.
dev | An SPI device configuration. |
size | Size of the data to read and ignore |
Reads size bytes from the SPI and throws them away. It should work only if the device has already locked the SPI controller.
Definition at line 154 of file spi.c.
References spi_arch_has_lock(), and spi_arch_transfer().
spi_status_t spi_release | ( | const spi_device_t * | dev | ) |
Closes and then unlocks an SPI controller.
dev | An SPI device configuration which defines the controller to be closed and unlocked. |
Releasing an SPI controller should put it in low-power mode. This should work only if the device has already locked the SPI controller.
Definition at line 57 of file spi.c.
References spi_arch_close_and_unlock().
Referenced by ext_flash_close(), and ext_flash_open().
spi_status_t spi_select | ( | const spi_device_t * | dev | ) |
Selects the SPI peripheral.
dev | An SPI device configuration which defines the CS pin. |
Clears the CS pin. This should work only if the device has already locked the SPI controller.
Definition at line 68 of file spi.c.
References spi_arch_has_lock(), and SPI_DEVICE_PORT.
Referenced by select_on_bus().
spi_status_t spi_strobe | ( | const spi_device_t * | dev, |
uint8_t | strobe, | ||
uint8_t * | status ) |
Reads and Writes one byte from/to an SPI device.
dev | An SPI device configuration. |
strobe | Byte to write |
status | Pointer to byte to read |
It should work only if the device has already locked the SPI controller.
Definition at line 215 of file spi.c.
References spi_arch_has_lock(), and spi_arch_transfer().
spi_status_t spi_transfer | ( | const spi_device_t * | dev, |
const uint8_t * | data, | ||
int | wsize, | ||
uint8_t * | buf, | ||
int | rsize, | ||
int | ignore ) |
Performs a generic SPI transfer.
dev | An SPI device configuration. |
data | A pointer to the data to be written. Set it to NULL to skip writing. |
wsize | Size of data to write. |
buf | A pointer to buffer to copy the data read. Set to NULL to skip reading. |
rsize | Size of data to read. |
ignore | Size of data to read and ignore. |
It should work only if the device has already locked the SPI controller. A total of rlen+ignore_len bytes will be read. The first rlen bytes will be copied to buf. The remaining ignore_len bytes won't be copied to the buffer. The maximum of wlen and rlen+ignore_len of bytes will be transfered.
Definition at line 168 of file spi.c.
References spi_arch_has_lock(), and spi_arch_transfer().
spi_status_t spi_write | ( | const spi_device_t * | dev, |
const uint8_t * | data, | ||
int | size ) |
Writes a buffer to an SPI device.
dev | An SPI device configuration. |
data | A pointer to the data |
size | Size of the data to write |
It should work only if the device has already locked the SPI controller.
Definition at line 112 of file spi.c.
References spi_arch_has_lock(), and spi_arch_transfer().
Referenced by ext_flash_erase(), ext_flash_read(), ext_flash_write(), power_standby(), verify_part(), wait_ready(), and write_enable().
spi_status_t spi_write_byte | ( | const spi_device_t * | dev, |
uint8_t | data ) |
Writes a single byte to an SPI device.
dev | An SPI device configuration. |
data | A byte of data |
It should work only if the device has already locked the SPI controller.
Definition at line 98 of file spi.c.
References spi_arch_has_lock(), and spi_arch_transfer().
Referenced by power_down(), and spi_read_register().