ChibiOS/HAL
7.0.3
|
Generic WSPI Driver. More...
![]() |
Generic WSPI Driver.
This module defines an abstract interface for an wide SPI communication interface (Quad SPI, Octal SPI and similar).
HAL_USE_WSPI
option must be enabled in halconf.h
. Macros | |
#define | wspi_lld_driver_fields |
Low level fields of the WSPI driver structure. More... | |
#define | wspi_lld_config_fields |
Low level fields of the WSPI configuration structure. More... | |
WSPI configuration options | |
#define | WSPI_USE_WAIT TRUE |
Enables synchronous APIs. More... | |
#define | WSPI_USE_MUTUAL_EXCLUSION TRUE |
Enables the wspiAcquireBus() and wspiReleaseBus() APIs. More... | |
Macro Functions | |
#define | wspiStartCommandI(wspip, cmdp) |
Sends a command without data phase. More... | |
#define | wspiStartSendI(wspip, cmdp, n, txbuf) |
Sends data over the WSPI bus. More... | |
#define | wspiStartReceiveI(wspip, cmdp, n, rxbuf) |
Receives data from the WSPI bus. More... | |
#define | wspiMapFlashI(wspip, cmdp, addrp) wspi_lld_map_flash(wspip, cmdp, addrp) |
Maps in memory space a WSPI flash device. More... | |
#define | wspiUnmapFlashI(wspip) wspi_lld_unmap_flash(wspip) |
Maps in memory space a WSPI flash device. More... | |
Low level driver helper macros | |
#define | _wspi_wakeup_isr(wspip) |
Wakes up the waiting thread. More... | |
#define | _wspi_isr_code(wspip) |
Common ISR code. More... | |
WSPI implementation capabilities | |
#define | WSPI_SUPPORTS_MEMMAP TRUE |
#define | WSPI_DEFAULT_CFG_MASKS TRUE |
Configuration options | |
#define | PLATFORM_WSPI_USE_WSPI1 FALSE |
WSPID1 driver enable switch. More... | |
Typedefs | |
typedef struct hal_wspi_driver | WSPIDriver |
Type of a structure representing an WSPI driver. More... | |
typedef struct hal_wspi_config | WSPIConfig |
Type of a structure representing an WSPI driver configuration. More... | |
typedef void(* | wspicallback_t) (WSPIDriver *wspip) |
Type of a WSPI notification callback. More... | |
Data Structures | |
struct | wspi_command_t |
Type of a WSPI command descriptor. More... | |
struct | hal_wspi_config |
Driver configuration structure. More... | |
struct | hal_wspi_driver |
Structure representing an WSPI driver. More... | |
Functions | |
void | wspiInit (void) |
WSPI Driver initialization. More... | |
void | wspiObjectInit (WSPIDriver *wspip) |
Initializes the standard part of a WSPIDriver structure. More... | |
void | wspiStart (WSPIDriver *wspip, const WSPIConfig *config) |
Configures and activates the WSPI peripheral. More... | |
void | wspiStop (WSPIDriver *wspip) |
Deactivates the WSPI peripheral. More... | |
void | wspiStartCommand (WSPIDriver *wspip, const wspi_command_t *cmdp) |
Sends a command without data phase. More... | |
void | wspiStartSend (WSPIDriver *wspip, const wspi_command_t *cmdp, size_t n, const uint8_t *txbuf) |
Sends a command with data over the WSPI bus. More... | |
void | wspiStartReceive (WSPIDriver *wspip, const wspi_command_t *cmdp, size_t n, uint8_t *rxbuf) |
Sends a command then receives data over the WSPI bus. More... | |
void | wspiCommand (WSPIDriver *wspip, const wspi_command_t *cmdp) |
Sends a command without data phase. More... | |
void | wspiSend (WSPIDriver *wspip, const wspi_command_t *cmdp, size_t n, const uint8_t *txbuf) |
Sends a command with data over the WSPI bus. More... | |
void | wspiReceive (WSPIDriver *wspip, const wspi_command_t *cmdp, size_t n, uint8_t *rxbuf) |
Sends a command then receives data over the WSPI bus. More... | |
void | wspiMapFlash (WSPIDriver *wspip, const wspi_command_t *cmdp, uint8_t **addrp) |
Maps in memory space a WSPI flash device. More... | |
void | wspiUnmapFlash (WSPIDriver *wspip) |
Unmaps from memory space a WSPI flash device. More... | |
void | wspiAcquireBus (WSPIDriver *wspip) |
Gains exclusive access to the WSPI bus. More... | |
void | wspiReleaseBus (WSPIDriver *wspip) |
Releases exclusive access to the WSPI bus. More... | |
void | wspi_lld_init (void) |
Low level WSPI driver initialization. More... | |
void | wspi_lld_start (WSPIDriver *wspip) |
Configures and activates the WSPI peripheral. More... | |
void | wspi_lld_stop (WSPIDriver *wspip) |
Deactivates the WSPI peripheral. More... | |
void | wspi_lld_command (WSPIDriver *wspip, const wspi_command_t *cmdp) |
Sends a command without data phase. More... | |
void | wspi_lld_send (WSPIDriver *wspip, const wspi_command_t *cmdp, size_t n, const uint8_t *txbuf) |
Sends a command with data over the WSPI bus. More... | |
void | wspi_lld_receive (WSPIDriver *wspip, const wspi_command_t *cmdp, size_t n, uint8_t *rxbuf) |
Sends a command then receives data over the WSPI bus. More... | |
void | wspi_lld_map_flash (WSPIDriver *wspip, const wspi_command_t *cmdp, uint8_t **addrp) |
Maps in memory space a WSPI flash device. More... | |
void | wspi_lld_unmap_flash (WSPIDriver *wspip) |
Unmaps from memory space a WSPI flash device. More... | |
Enumerations |
Variables | |
WSPIDriver | WSPID1 |
WSPID1 driver identifier. More... | |
#define WSPI_USE_WAIT TRUE |
Enables synchronous APIs.
Definition at line 47 of file hal_wspi.h.
#define WSPI_USE_MUTUAL_EXCLUSION TRUE |
Enables the wspiAcquireBus()
and wspiReleaseBus()
APIs.
Definition at line 55 of file hal_wspi.h.
#define wspiStartCommandI | ( | wspip, | |
cmdp | |||
) |
Sends a command without data phase.
[in] | wspip | pointer to the WSPIDriver object |
[in] | cmdp | pointer to the command descriptor |
Definition at line 269 of file hal_wspi.h.
Referenced by wspiCommand(), and wspiStartCommand().
#define wspiStartSendI | ( | wspip, | |
cmdp, | |||
n, | |||
txbuf | |||
) |
Sends data over the WSPI bus.
This asynchronous function starts a transmit operation.
[in] | wspip | pointer to the WSPIDriver object |
[in] | cmdp | pointer to the command descriptor |
[in] | n | number of bytes to send or zero if no data phase |
[in] | txbuf | the pointer to the transmit buffer |
Definition at line 289 of file hal_wspi.h.
Referenced by wspiSend(), and wspiStartSend().
#define wspiStartReceiveI | ( | wspip, | |
cmdp, | |||
n, | |||
rxbuf | |||
) |
Receives data from the WSPI bus.
This asynchronous function starts a receive operation.
[in] | wspip | pointer to the WSPIDriver object |
[in] | cmdp | pointer to the command descriptor |
[in] | n | number of bytes to receive or zero if no data phase |
[out] | rxbuf | the pointer to the receive buffer |
Definition at line 309 of file hal_wspi.h.
Referenced by wspiReceive(), and wspiStartReceive().
#define wspiMapFlashI | ( | wspip, | |
cmdp, | |||
addrp | |||
) | wspi_lld_map_flash(wspip, cmdp, addrp) |
Maps in memory space a WSPI flash device.
[in] | wspip | pointer to the WSPIDriver object |
[in] | cmdp | pointer to the command descriptor |
[out] | addrp | pointer to the memory start address of the mapped flash or NULL |
Definition at line 330 of file hal_wspi.h.
Referenced by wspiMapFlash().
#define wspiUnmapFlashI | ( | wspip | ) | wspi_lld_unmap_flash(wspip) |
Maps in memory space a WSPI flash device.
[in] | wspip | pointer to the WSPIDriver object |
Definition at line 342 of file hal_wspi.h.
Referenced by wspiUnmapFlash().
#define _wspi_wakeup_isr | ( | wspip | ) |
Wakes up the waiting thread.
[in] | wspip | pointer to the WSPIDriver object |
Definition at line 359 of file hal_wspi.h.
#define _wspi_isr_code | ( | wspip | ) |
Common ISR code.
This code handles the portable part of the ISR code:
[in] | wspip | pointer to the WSPIDriver object |
Definition at line 382 of file hal_wspi.h.
#define PLATFORM_WSPI_USE_WSPI1 FALSE |
WSPID1 driver enable switch.
If set to TRUE
the support for WSPID1 is included.
FALSE
. Definition at line 56 of file hal_wspi_lld.h.
#define wspi_lld_driver_fields |
Low level fields of the WSPI driver structure.
Definition at line 75 of file hal_wspi_lld.h.
#define wspi_lld_config_fields |
Low level fields of the WSPI configuration structure.
Definition at line 82 of file hal_wspi_lld.h.
typedef struct hal_wspi_driver WSPIDriver |
Type of a structure representing an WSPI driver.
Definition at line 82 of file hal_wspi.h.
typedef struct hal_wspi_config WSPIConfig |
Type of a structure representing an WSPI driver configuration.
Definition at line 87 of file hal_wspi.h.
typedef void(* wspicallback_t) (WSPIDriver *wspip) |
Type of a WSPI notification callback.
[in] | wspip | pointer to the WSPIDriver object triggering the callback |
Definition at line 95 of file hal_wspi.h.
enum wspistate_t |
Driver state machine possible states.
Enumerator | |
---|---|
WSPI_UNINIT |
Not initialized. |
WSPI_STOP |
Stopped. |
WSPI_READY |
Ready. |
WSPI_ACTIVE |
Exchanging data. |
WSPI_COMPLETE |
Asynchronous operation complete. |
WSPI_MEMMAP |
In memory mapped mode. |
Definition at line 70 of file hal_wspi.h.
void wspiInit | ( | void | ) |
WSPI Driver initialization.
halInit()
, there is no need to explicitly initialize the driver.Definition at line 56 of file hal_wspi.c.
References wspi_lld_init().
Referenced by halInit().
void wspiObjectInit | ( | WSPIDriver * | wspip | ) |
Initializes the standard part of a WSPIDriver
structure.
[out] | wspip | pointer to the WSPIDriver object |
Definition at line 68 of file hal_wspi.c.
References hal_wspi_driver::config, hal_wspi_driver::mutex, osalMutexObjectInit(), hal_wspi_driver::state, hal_wspi_driver::thread, and WSPI_STOP.
Referenced by wspi_lld_init().
void wspiStart | ( | WSPIDriver * | wspip, |
const WSPIConfig * | config | ||
) |
Configures and activates the WSPI peripheral.
[in] | wspip | pointer to the WSPIDriver object |
[in] | config | pointer to the WSPIConfig object |
Definition at line 91 of file hal_wspi.c.
References hal_wspi_driver::config, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), hal_wspi_driver::state, wspi_lld_start(), WSPI_READY, and WSPI_STOP.
Referenced by bus_acquire().
void wspiStop | ( | WSPIDriver * | wspip | ) |
Deactivates the WSPI peripheral.
[in] | wspip | pointer to the WSPIDriver object |
Definition at line 116 of file hal_wspi.c.
References hal_wspi_driver::config, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), hal_wspi_driver::state, wspi_lld_stop(), WSPI_READY, and WSPI_STOP.
Referenced by bus_stop().
void wspiStartCommand | ( | WSPIDriver * | wspip, |
const wspi_command_t * | cmdp | ||
) |
Sends a command without data phase.
[in] | wspip | pointer to the WSPIDriver object |
[in] | cmdp | pointer to the command descriptor |
Definition at line 141 of file hal_wspi.c.
References osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), hal_wspi_driver::state, WSPI_READY, and wspiStartCommandI.
void wspiStartSend | ( | WSPIDriver * | wspip, |
const wspi_command_t * | cmdp, | ||
size_t | n, | ||
const uint8_t * | txbuf | ||
) |
Sends a command with data over the WSPI bus.
[in] | wspip | pointer to the WSPIDriver object |
[in] | cmdp | pointer to the command descriptor |
[in] | n | number of bytes to send |
[in] | txbuf | the pointer to the transmit buffer |
Definition at line 165 of file hal_wspi.c.
References osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), hal_wspi_driver::state, WSPI_READY, and wspiStartSendI.
void wspiStartReceive | ( | WSPIDriver * | wspip, |
const wspi_command_t * | cmdp, | ||
size_t | n, | ||
uint8_t * | rxbuf | ||
) |
Sends a command then receives data over the WSPI bus.
[in] | wspip | pointer to the WSPIDriver object |
[in] | cmdp | pointer to the command descriptor |
[in] | n | number of bytes to send |
[out] | rxbuf | the pointer to the receive buffer |
Definition at line 191 of file hal_wspi.c.
References osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), hal_wspi_driver::state, WSPI_READY, and wspiStartReceiveI.
void wspiCommand | ( | WSPIDriver * | wspip, |
const wspi_command_t * | cmdp | ||
) |
Sends a command without data phase.
WSPI_USE_WAIT
must be enabled. end_cb
= NULL
).[in] | wspip | pointer to the WSPIDriver object |
[in] | cmdp | pointer to the command descriptor |
Definition at line 219 of file hal_wspi.c.
References wspi_command_t::cfg, hal_wspi_driver::config, hal_wspi_config::end_cb, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), osalThreadSuspendS(), hal_wspi_driver::state, hal_wspi_driver::thread, WSPI_READY, and wspiStartCommandI.
Referenced by bus_cmd(), and bus_cmd_addr().
void wspiSend | ( | WSPIDriver * | wspip, |
const wspi_command_t * | cmdp, | ||
size_t | n, | ||
const uint8_t * | txbuf | ||
) |
Sends a command with data over the WSPI bus.
WSPI_USE_WAIT
must be enabled. end_cb
= NULL
).[in] | wspip | pointer to the WSPIDriver object |
[in] | cmdp | pointer to the command descriptor |
[in] | n | number of bytes to send |
[in] | txbuf | the pointer to the transmit buffer |
Definition at line 249 of file hal_wspi.c.
References wspi_command_t::cfg, hal_wspi_driver::config, hal_wspi_config::end_cb, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), osalThreadSuspendS(), hal_wspi_driver::state, hal_wspi_driver::thread, WSPI_READY, and wspiStartSendI.
Referenced by bus_cmd_addr_send(), and bus_cmd_send().
void wspiReceive | ( | WSPIDriver * | wspip, |
const wspi_command_t * | cmdp, | ||
size_t | n, | ||
uint8_t * | rxbuf | ||
) |
Sends a command then receives data over the WSPI bus.
WSPI_USE_WAIT
must be enabled. end_cb
= NULL
).[in] | wspip | pointer to the WSPIDriver object |
[in] | cmdp | pointer to the command descriptor |
[in] | n | number of bytes to send |
[out] | rxbuf | the pointer to the receive buffer |
Definition at line 281 of file hal_wspi.c.
References wspi_command_t::cfg, hal_wspi_driver::config, hal_wspi_config::end_cb, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), osalThreadSuspendS(), hal_wspi_driver::state, hal_wspi_driver::thread, WSPI_READY, and wspiStartReceiveI.
Referenced by bus_cmd_addr_dummy_receive(), bus_cmd_addr_receive(), bus_cmd_dummy_receive(), and bus_cmd_receive().
void wspiMapFlash | ( | WSPIDriver * | wspip, |
const wspi_command_t * | cmdp, | ||
uint8_t ** | addrp | ||
) |
Maps in memory space a WSPI flash device.
[in] | wspip | pointer to the WSPIDriver object |
[in] | cmdp | pointer to the command descriptor |
[out] | addrp | pointer to the memory start address of the mapped flash or NULL |
Definition at line 313 of file hal_wspi.c.
References wspi_command_t::cfg, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), hal_wspi_driver::state, WSPI_MEMMAP, WSPI_READY, and wspiMapFlashI.
Referenced by snorMemoryMap().
void wspiUnmapFlash | ( | WSPIDriver * | wspip | ) |
Unmaps from memory space a WSPI flash device.
[in] | wspip | pointer to the WSPIDriver object |
Definition at line 339 of file hal_wspi.c.
References osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), hal_wspi_driver::state, WSPI_MEMMAP, WSPI_READY, and wspiUnmapFlashI.
Referenced by snorMemoryUnmap().
void wspiAcquireBus | ( | WSPIDriver * | wspip | ) |
Gains exclusive access to the WSPI bus.
This function tries to gain ownership to the WSPI bus, if the bus is already being used then the invoking thread is queued.
WSPI_USE_MUTUAL_EXCLUSION
must be enabled.[in] | wspip | pointer to the WSPIDriver object |
Definition at line 366 of file hal_wspi.c.
References hal_wspi_driver::mutex, osalDbgCheck, and osalMutexLock().
Referenced by bus_acquire().
void wspiReleaseBus | ( | WSPIDriver * | wspip | ) |
Releases exclusive access to the WSPI bus.
WSPI_USE_MUTUAL_EXCLUSION
must be enabled.[in] | wspip | pointer to the WSPIDriver object |
Definition at line 382 of file hal_wspi.c.
References hal_wspi_driver::mutex, osalDbgCheck, and osalMutexUnlock().
Referenced by bus_release().
void wspi_lld_init | ( | void | ) |
Low level WSPI driver initialization.
Definition at line 63 of file hal_wspi_lld.c.
References wspiObjectInit().
Referenced by wspiInit().
void wspi_lld_start | ( | WSPIDriver * | wspip | ) |
Configures and activates the WSPI peripheral.
[in] | wspip | pointer to the WSPIDriver object |
Definition at line 77 of file hal_wspi_lld.c.
References hal_wspi_driver::state, and WSPI_STOP.
Referenced by wspiStart().
void wspi_lld_stop | ( | WSPIDriver * | wspip | ) |
Deactivates the WSPI peripheral.
[in] | wspip | pointer to the WSPIDriver object |
Definition at line 99 of file hal_wspi_lld.c.
References hal_wspi_driver::state, and WSPI_READY.
Referenced by wspiStop().
void wspi_lld_command | ( | WSPIDriver * | wspip, |
const wspi_command_t * | cmdp | ||
) |
Sends a command without data phase.
[in] | wspip | pointer to the WSPIDriver object |
[in] | cmdp | pointer to the command descriptor |
Definition at line 123 of file hal_wspi_lld.c.
void wspi_lld_send | ( | WSPIDriver * | wspip, |
const wspi_command_t * | cmdp, | ||
size_t | n, | ||
const uint8_t * | txbuf | ||
) |
Sends a command with data over the WSPI bus.
[in] | wspip | pointer to the WSPIDriver object |
[in] | cmdp | pointer to the command descriptor |
[in] | n | number of bytes to send |
[in] | txbuf | the pointer to the transmit buffer |
Definition at line 140 of file hal_wspi_lld.c.
void wspi_lld_receive | ( | WSPIDriver * | wspip, |
const wspi_command_t * | cmdp, | ||
size_t | n, | ||
uint8_t * | rxbuf | ||
) |
Sends a command then receives data over the WSPI bus.
[in] | wspip | pointer to the WSPIDriver object |
[in] | cmdp | pointer to the command descriptor |
[in] | n | number of bytes to send |
[out] | rxbuf | the pointer to the receive buffer |
Definition at line 160 of file hal_wspi_lld.c.
void wspi_lld_map_flash | ( | WSPIDriver * | wspip, |
const wspi_command_t * | cmdp, | ||
uint8_t ** | addrp | ||
) |
Maps in memory space a WSPI flash device.
[in] | wspip | pointer to the WSPIDriver object |
[in] | cmdp | pointer to the command descriptor |
[out] | addrp | pointer to the memory start address of the mapped flash or NULL |
Definition at line 182 of file hal_wspi_lld.c.
void wspi_lld_unmap_flash | ( | WSPIDriver * | wspip | ) |
Unmaps from memory space a WSPI flash device.
[in] | wspip | pointer to the WSPIDriver object |
Definition at line 200 of file hal_wspi_lld.c.
WSPIDriver WSPID1 |
WSPID1 driver identifier.
Definition at line 39 of file hal_wspi_lld.c.