Contiki-NG
|
The SPI HAL provides a set of common functions that can be used in a platform-independent fashion. More...
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... | |
Functions | |
spi_status_t | spi_acquire (spi_device_t *dev) |
Locks and then opens an SPI controller. More... | |
spi_status_t | spi_release (spi_device_t *dev) |
Closes and then unlocks an SPI controller. More... | |
spi_status_t | spi_select (spi_device_t *dev) |
Selects the SPI peripheral. More... | |
spi_status_t | spi_deselect (spi_device_t *dev) |
Deselects the SPI peripheral. More... | |
bool | spi_has_bus (spi_device_t *dev) |
Checks if a device has locked an SPI controller. More... | |
spi_status_t | spi_write_byte (spi_device_t *dev, uint8_t data) |
Writes a single byte to an SPI device. More... | |
spi_status_t | spi_write (spi_device_t *dev, const uint8_t *data, int size) |
Writes a buffer to an SPI device. More... | |
spi_status_t | spi_read_byte (spi_device_t *dev, uint8_t *data) |
Reads a single byte from an SPI device. More... | |
spi_status_t | spi_read (spi_device_t *dev, uint8_t *data, int size) |
Reads a buffer from an SPI device. More... | |
spi_status_t | spi_read_skip (spi_device_t *dev, int size) |
Reads and ignores data from an SPI device. More... | |
spi_status_t | spi_transfer (spi_device_t *dev, const uint8_t *data, int wsize, uint8_t *buf, int rsize, int ignore) |
Performs a generic SPI transfer. More... | |
spi_status_t | spi_read_register (spi_device_t *dev, uint8_t reg, uint8_t *data, int size) |
Reads a buffer of bytes from a register of an SPI device. More... | |
spi_status_t | spi_strobe (spi_device_t *dev, uint8_t strobe, uint8_t *status) |
Reads and Writes one byte from/to an SPI device. More... | |
bool | spi_arch_has_lock (spi_device_t *dev) |
Checks if a device has locked an SPI controller. More... | |
bool | spi_arch_is_bus_locked (spi_device_t *dev) |
Checks if an SPI controller is locked by any device. More... | |
spi_status_t | spi_arch_lock_and_open (spi_device_t *dev) |
Locks and opens an SPI controller to the configuration specified. More... | |
spi_status_t | spi_arch_close_and_unlock (spi_device_t *dev) |
Closes and unlocks an SPI controller. More... | |
spi_status_t | spi_arch_transfer (spi_device_t *dev, const uint8_t *data, int wlen, uint8_t *buf, int rlen, int ignore_len) |
Performs an SPI transfer. More... | |
spi_status_t | spi_arch_select (spi_device_t *dev) |
Selects an SPI device. More... | |
spi_status_t | spi_arch_deselect (spi_device_t *dev) |
Deselects an SPI device. More... | |
typedef struct spi_device | spi_device_t |
SPI Device Configuration. More... | |
The SPI HAL provides a set of common functions that can be used in a platform-independent fashion.
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 | ( | 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 | ( | 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.
Definition at line 268 of file spi-arch.c.
References mutex_unlock, spi_arch_has_lock(), and SYS_CTRL_RCGCSSI.
Referenced by spi_release().
spi_status_t spi_arch_deselect | ( | spi_device_t * | dev | ) |
Deselects an SPI device.
dev | An SPI device configuration that specifies the CS pin. |
Set the CS pin. Locking the SPI controller is not needed.
Definition at line 298 of file spi-arch.c.
Referenced by spi_deselect().
bool spi_arch_has_lock | ( | 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_select(), spi_arch_transfer(), spi_has_bus(), spi_read(), spi_read_byte(), spi_read_skip(), spi_strobe(), spi_transfer(), spi_write(), and spi_write_byte().
bool spi_arch_is_bus_locked | ( | 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.
spi_status_t spi_arch_lock_and_open | ( | 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.
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(), mutex_try_lock, SSI_CC, SSI_CPSR, SSI_CR0, SSI_CR0_SCR_M, 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_select | ( | spi_device_t * | dev | ) |
Selects an SPI device.
dev | An SPI device configuration that specifies the CS pin. |
Clears the CS pin. It should work only if the device has already locked the SPI controller.
Definition at line 285 of file spi-arch.c.
References spi_arch_has_lock().
Referenced by spi_select().
spi_status_t spi_arch_transfer | ( | 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 307 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 | ( | 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 74 of file spi.c.
References spi_arch_deselect().
Referenced by deselect().
bool spi_has_bus | ( | 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 80 of file spi.c.
References spi_arch_has_lock().
spi_status_t spi_read | ( | 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 132 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 | ( | 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 118 of file spi.c.
References spi_arch_has_lock(), and spi_arch_transfer().
spi_status_t spi_read_register | ( | 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 184 of file spi.c.
References spi_read(), and spi_write_byte().
spi_status_t spi_read_skip | ( | 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 146 of file spi.c.
References spi_arch_has_lock(), and spi_arch_transfer().
spi_status_t spi_release | ( | 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 | ( | 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_select().
Referenced by select_on_bus().
spi_status_t spi_strobe | ( | 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 207 of file spi.c.
References spi_arch_has_lock(), and spi_arch_transfer().
spi_status_t spi_transfer | ( | 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 160 of file spi.c.
References spi_arch_has_lock(), and spi_arch_transfer().
spi_status_t spi_write | ( | 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 104 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 | ( | 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 90 of file spi.c.
References spi_arch_has_lock(), and spi_arch_transfer().
Referenced by power_down(), and spi_read_register().