ChibiOS/HAL 9.0.0
WSPI Driver

Generic WSPI Driver. More...

Detailed Description

Generic WSPI Driver.

This module defines an abstract interface for an wide SPI communication interface (Quad SPI, Octal SPI and similar).

Precondition
In order to use the WSPI driver the HAL_USE_WSPI option must be enabled in halconf.h.
Collaboration diagram for WSPI Driver:

WSPI configuration options

#define WSPI_USE_WAIT   TRUE
 Enables synchronous APIs.
#define WSPI_USE_MUTUAL_EXCLUSION   TRUE
 Enables the wspiAcquireBus() and wspiReleaseBus() APIs.

Transfer options

Note
The low level driver has the option to override the following definitions and use its own ones. In must take care to use the same name for the same function or compatibility is not ensured.
#define WSPI_CFG_CMD_MODE_MASK   (7LU << 0LU)
#define WSPI_CFG_CMD_MODE_NONE   (0LU << 0LU)
#define WSPI_CFG_CMD_MODE_ONE_LINE   (1LU << 0LU)
#define WSPI_CFG_CMD_MODE_TWO_LINES   (2LU << 0LU)
#define WSPI_CFG_CMD_MODE_FOUR_LINES   (3LU << 0LU)
#define WSPI_CFG_CMD_MODE_EIGHT_LINES   (4LU << 0LU)
#define WSPI_CFG_CMD_DTR   (1LU << 3LU)
#define WSPI_CFG_CMD_SIZE_MASK   (3LU << 4LU)
#define WSPI_CFG_CMD_SIZE_8   (0LU << 4LU)
#define WSPI_CFG_CMD_SIZE_16   (1LU << 4LU)
#define WSPI_CFG_CMD_SIZE_24   (2LU << 4LU)
#define WSPI_CFG_CMD_SIZE_32   (3LU << 4LU)
#define WSPI_CFG_ADDR_MODE_MASK   (7LU << 8LU)
#define WSPI_CFG_ADDR_MODE_NONE   (0LU << 8LU)
#define WSPI_CFG_ADDR_MODE_ONE_LINE   (1LU << 8LU)
#define WSPI_CFG_ADDR_MODE_TWO_LINES   (2LU << 8LU)
#define WSPI_CFG_ADDR_MODE_FOUR_LINES   (3LU << 8LU)
#define WSPI_CFG_ADDR_MODE_EIGHT_LINES   (4LU << 8LU)
#define WSPI_CFG_ADDR_DTR   (1LU << 11LU)
#define WSPI_CFG_ADDR_SIZE_MASK   (3LU << 12LU)
#define WSPI_CFG_ADDR_SIZE_8   (0LU << 12LU)
#define WSPI_CFG_ADDR_SIZE_16   (1LU << 12LU)
#define WSPI_CFG_ADDR_SIZE_24   (2LU << 12LU)
#define WSPI_CFG_ADDR_SIZE_32   (3LU << 12LU)
#define WSPI_CFG_ALT_MODE_MASK   (7LU << 16LU)
#define WSPI_CFG_ALT_MODE_NONE   (0LU << 16LU)
#define WSPI_CFG_ALT_MODE_ONE_LINE   (1LU << 16LU)
#define WSPI_CFG_ALT_MODE_TWO_LINES   (2LU << 16LU)
#define WSPI_CFG_ALT_MODE_FOUR_LINES   (3LU << 16LU)
#define WSPI_CFG_ALT_MODE_EIGHT_LINES   (4LU << 16LU)
#define WSPI_CFG_ALT_DTR   (1LU << 19LU)
#define WSPI_CFG_ALT_SIZE_MASK   (3LU << 20LU)
#define WSPI_CFG_ALT_SIZE_8   (0LU << 20LU)
#define WSPI_CFG_ALT_SIZE_16   (1LU << 20LU)
#define WSPI_CFG_ALT_SIZE_24   (2LU << 20LU)
#define WSPI_CFG_ALT_SIZE_32   (3LU << 20LU)
#define WSPI_CFG_DATA_MODE_MASK   (7LU << 24LU)
#define WSPI_CFG_DATA_MODE_NONE   (0LU << 24LU)
#define WSPI_CFG_DATA_MODE_ONE_LINE   (1LU << 24LU)
#define WSPI_CFG_DATA_MODE_TWO_LINES   (2LU << 24LU)
#define WSPI_CFG_DATA_MODE_FOUR_LINES   (3LU << 24LU)
#define WSPI_CFG_DATA_MODE_EIGHT_LINES   (4LU << 24LU)
#define WSPI_CFG_DATA_DTR   (1LU << 27LU)
#define WSPI_CFG_DQS_ENABLE   (1LU << 29LU)
#define WSPI_CFG_SIOO   (1LU << 31LU)
#define WSPI_CFG_ALL_DTR

Macro Functions

#define wspiStartCommandI(wspip, cmdp)
 Sends a command without data phase.
#define wspiStartSendI(wspip, cmdp, n, txbuf)
 Sends data over the WSPI bus.
#define wspiStartReceiveI(wspip, cmdp, n, rxbuf)
 Receives data from the WSPI bus.
#define wspiMapFlashI(wspip, cmdp, addrp)
 Maps in memory space a WSPI flash device.
#define wspiUnmapFlashI(wspip)
 Maps in memory space a WSPI flash device.

Low level driver helper macros

#define _wspi_wakeup_isr(wspip, msg)
 Wakes up the waiting thread.
#define _wspi_isr_code(wspip)
 Common ISR code.
#define _wspi_error_code(wspip)
 Common error ISR code.

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.

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...

Macros

#define wspi_lld_driver_fields
 Low level fields of the WSPI driver structure.
#define wspi_lld_config_fields
 Low level fields of the WSPI configuration structure.

Typedefs

typedef struct hal_wspi_driver WSPIDriver
 Type of a structure representing an WSPI driver.
typedef struct hal_wspi_config WSPIConfig
 Type of a structure representing an WSPI driver configuration.
typedef void(* wspicallback_t) (WSPIDriver *wspip)
 Type of a WSPI notification callback.

Enumerations

enum  wspistate_t {
  WSPI_UNINIT = 0 , WSPI_STOP = 1 , WSPI_READY = 2 , WSPI_SEND = 3 ,
  WSPI_RECEIVE = 4 , WSPI_COMPLETE = 5 , WSPI_MEMMAP = 6
}
 Driver state machine possible states. More...

Functions

void wspiInit (void)
 WSPI Driver initialization.
void wspiObjectInit (WSPIDriver *wspip)
 Initializes the standard part of a WSPIDriver structure.
msg_t wspiStart (WSPIDriver *wspip, const WSPIConfig *config)
 Configures and activates the WSPI peripheral.
void wspiStop (WSPIDriver *wspip)
 Deactivates the WSPI peripheral.
void wspiStartCommand (WSPIDriver *wspip, const wspi_command_t *cmdp)
 Sends a command without data phase.
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.
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.
bool wspiCommand (WSPIDriver *wspip, const wspi_command_t *cmdp)
 Sends a command without data phase.
bool wspiSend (WSPIDriver *wspip, const wspi_command_t *cmdp, size_t n, const uint8_t *txbuf)
 Sends a command with data over the WSPI bus.
bool wspiReceive (WSPIDriver *wspip, const wspi_command_t *cmdp, size_t n, uint8_t *rxbuf)
 Sends a command then receives data over the WSPI bus.
void wspiMapFlash (WSPIDriver *wspip, const wspi_command_t *cmdp, uint8_t **addrp)
 Maps in memory space a WSPI flash device.
void wspiUnmapFlash (WSPIDriver *wspip)
 Unmaps from memory space a WSPI flash device.
void wspiAcquireBus (WSPIDriver *wspip)
 Gains exclusive access to the WSPI bus.
void wspiReleaseBus (WSPIDriver *wspip)
 Releases exclusive access to the WSPI bus.
void wspi_lld_init (void)
 Low level WSPI driver initialization.
void wspi_lld_start (WSPIDriver *wspip)
 Configures and activates the WSPI peripheral.
void wspi_lld_stop (WSPIDriver *wspip)
 Deactivates the WSPI peripheral.
void wspi_lld_command (WSPIDriver *wspip, const wspi_command_t *cmdp)
 Sends a command without data phase.
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.
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.
void wspi_lld_map_flash (WSPIDriver *wspip, const wspi_command_t *cmdp, uint8_t **addrp)
 Maps in memory space a WSPI flash device.
void wspi_lld_unmap_flash (WSPIDriver *wspip)
 Unmaps from memory space a WSPI flash device.

Variables

WSPIDriver WSPID1
 WSPID1 driver identifier.

Macro Definition Documentation

◆ WSPI_USE_WAIT

#define WSPI_USE_WAIT   TRUE

Enables synchronous APIs.

Note
Disabling this option saves both code and data space.

Definition at line 47 of file hal_wspi.h.

◆ WSPI_USE_MUTUAL_EXCLUSION

#define WSPI_USE_MUTUAL_EXCLUSION   TRUE

Enables the wspiAcquireBus() and wspiReleaseBus() APIs.

Note
Disabling this option saves both code and data space.

Definition at line 55 of file hal_wspi.h.

◆ WSPI_CFG_CMD_MODE_MASK

#define WSPI_CFG_CMD_MODE_MASK   (7LU << 0LU)

Definition at line 196 of file hal_wspi.h.

◆ WSPI_CFG_CMD_MODE_NONE

#define WSPI_CFG_CMD_MODE_NONE   (0LU << 0LU)

Definition at line 197 of file hal_wspi.h.

Referenced by n25q_reset_xip().

◆ WSPI_CFG_CMD_MODE_ONE_LINE

#define WSPI_CFG_CMD_MODE_ONE_LINE   (1LU << 0LU)

Definition at line 198 of file hal_wspi.h.

Referenced by __n25q_init_impl(), __n25q_mmap_on_impl(), and n25q_read_id().

◆ WSPI_CFG_CMD_MODE_TWO_LINES

#define WSPI_CFG_CMD_MODE_TWO_LINES   (2LU << 0LU)

Definition at line 199 of file hal_wspi.h.

Referenced by __n25q_mmap_on_impl().

◆ WSPI_CFG_CMD_MODE_FOUR_LINES

#define WSPI_CFG_CMD_MODE_FOUR_LINES   (3LU << 0LU)

Definition at line 200 of file hal_wspi.h.

Referenced by __n25q_mmap_on_impl().

◆ WSPI_CFG_CMD_MODE_EIGHT_LINES

#define WSPI_CFG_CMD_MODE_EIGHT_LINES   (4LU << 0LU)

Definition at line 201 of file hal_wspi.h.

◆ WSPI_CFG_CMD_DTR

#define WSPI_CFG_CMD_DTR   (1LU << 3LU)

Definition at line 203 of file hal_wspi.h.

◆ WSPI_CFG_CMD_SIZE_MASK

#define WSPI_CFG_CMD_SIZE_MASK   (3LU << 4LU)

Definition at line 205 of file hal_wspi.h.

◆ WSPI_CFG_CMD_SIZE_8

#define WSPI_CFG_CMD_SIZE_8   (0LU << 4LU)

Definition at line 206 of file hal_wspi.h.

◆ WSPI_CFG_CMD_SIZE_16

#define WSPI_CFG_CMD_SIZE_16   (1LU << 4LU)

Definition at line 207 of file hal_wspi.h.

◆ WSPI_CFG_CMD_SIZE_24

#define WSPI_CFG_CMD_SIZE_24   (2LU << 4LU)

Definition at line 208 of file hal_wspi.h.

◆ WSPI_CFG_CMD_SIZE_32

#define WSPI_CFG_CMD_SIZE_32   (3LU << 4LU)

Definition at line 209 of file hal_wspi.h.

◆ WSPI_CFG_ADDR_MODE_MASK

#define WSPI_CFG_ADDR_MODE_MASK   (7LU << 8LU)

Definition at line 211 of file hal_wspi.h.

◆ WSPI_CFG_ADDR_MODE_NONE

#define WSPI_CFG_ADDR_MODE_NONE   (0LU << 8LU)

Definition at line 212 of file hal_wspi.h.

◆ WSPI_CFG_ADDR_MODE_ONE_LINE

#define WSPI_CFG_ADDR_MODE_ONE_LINE   (1LU << 8LU)

Definition at line 213 of file hal_wspi.h.

Referenced by __n25q_mmap_on_impl(), and n25q_reset_xip().

◆ WSPI_CFG_ADDR_MODE_TWO_LINES

#define WSPI_CFG_ADDR_MODE_TWO_LINES   (2LU << 8LU)

Definition at line 214 of file hal_wspi.h.

Referenced by __n25q_mmap_on_impl(), and n25q_reset_xip().

◆ WSPI_CFG_ADDR_MODE_FOUR_LINES

#define WSPI_CFG_ADDR_MODE_FOUR_LINES   (3LU << 8LU)

Definition at line 215 of file hal_wspi.h.

Referenced by __n25q_mmap_on_impl(), and n25q_reset_xip().

◆ WSPI_CFG_ADDR_MODE_EIGHT_LINES

#define WSPI_CFG_ADDR_MODE_EIGHT_LINES   (4LU << 8LU)

Definition at line 216 of file hal_wspi.h.

◆ WSPI_CFG_ADDR_DTR

#define WSPI_CFG_ADDR_DTR   (1LU << 11LU)

Definition at line 218 of file hal_wspi.h.

◆ WSPI_CFG_ADDR_SIZE_MASK

#define WSPI_CFG_ADDR_SIZE_MASK   (3LU << 12LU)

Definition at line 220 of file hal_wspi.h.

◆ WSPI_CFG_ADDR_SIZE_8

#define WSPI_CFG_ADDR_SIZE_8   (0LU << 12LU)

Definition at line 221 of file hal_wspi.h.

◆ WSPI_CFG_ADDR_SIZE_16

#define WSPI_CFG_ADDR_SIZE_16   (1LU << 12LU)

Definition at line 222 of file hal_wspi.h.

◆ WSPI_CFG_ADDR_SIZE_24

#define WSPI_CFG_ADDR_SIZE_24   (2LU << 12LU)

Definition at line 223 of file hal_wspi.h.

Referenced by __n25q_mmap_on_impl(), and n25q_reset_xip().

◆ WSPI_CFG_ADDR_SIZE_32

#define WSPI_CFG_ADDR_SIZE_32   (3LU << 12LU)

Definition at line 224 of file hal_wspi.h.

◆ WSPI_CFG_ALT_MODE_MASK

#define WSPI_CFG_ALT_MODE_MASK   (7LU << 16LU)

Definition at line 226 of file hal_wspi.h.

◆ WSPI_CFG_ALT_MODE_NONE

#define WSPI_CFG_ALT_MODE_NONE   (0LU << 16LU)

Definition at line 227 of file hal_wspi.h.

◆ WSPI_CFG_ALT_MODE_ONE_LINE

#define WSPI_CFG_ALT_MODE_ONE_LINE   (1LU << 16LU)

Definition at line 228 of file hal_wspi.h.

◆ WSPI_CFG_ALT_MODE_TWO_LINES

#define WSPI_CFG_ALT_MODE_TWO_LINES   (2LU << 16LU)

Definition at line 229 of file hal_wspi.h.

◆ WSPI_CFG_ALT_MODE_FOUR_LINES

#define WSPI_CFG_ALT_MODE_FOUR_LINES   (3LU << 16LU)

Definition at line 230 of file hal_wspi.h.

Referenced by __n25q_mmap_on_impl(), and n25q_reset_xip().

◆ WSPI_CFG_ALT_MODE_EIGHT_LINES

#define WSPI_CFG_ALT_MODE_EIGHT_LINES   (4LU << 16LU)

Definition at line 231 of file hal_wspi.h.

◆ WSPI_CFG_ALT_DTR

#define WSPI_CFG_ALT_DTR   (1LU << 19LU)

Definition at line 233 of file hal_wspi.h.

◆ WSPI_CFG_ALT_SIZE_MASK

#define WSPI_CFG_ALT_SIZE_MASK   (3LU << 20LU)

Definition at line 235 of file hal_wspi.h.

◆ WSPI_CFG_ALT_SIZE_8

#define WSPI_CFG_ALT_SIZE_8   (0LU << 20LU)

Definition at line 236 of file hal_wspi.h.

Referenced by __n25q_mmap_on_impl(), and n25q_reset_xip().

◆ WSPI_CFG_ALT_SIZE_16

#define WSPI_CFG_ALT_SIZE_16   (1LU << 20LU)

Definition at line 237 of file hal_wspi.h.

◆ WSPI_CFG_ALT_SIZE_24

#define WSPI_CFG_ALT_SIZE_24   (2LU << 20LU)

Definition at line 238 of file hal_wspi.h.

◆ WSPI_CFG_ALT_SIZE_32

#define WSPI_CFG_ALT_SIZE_32   (3LU << 20LU)

Definition at line 239 of file hal_wspi.h.

◆ WSPI_CFG_DATA_MODE_MASK

#define WSPI_CFG_DATA_MODE_MASK   (7LU << 24LU)

Definition at line 241 of file hal_wspi.h.

Referenced by wspiCommand(), wspiMapFlash(), wspiReceive(), and wspiSend().

◆ WSPI_CFG_DATA_MODE_NONE

#define WSPI_CFG_DATA_MODE_NONE   (0LU << 24LU)

Definition at line 242 of file hal_wspi.h.

Referenced by wspiCommand(), wspiMapFlash(), wspiReceive(), and wspiSend().

◆ WSPI_CFG_DATA_MODE_ONE_LINE

#define WSPI_CFG_DATA_MODE_ONE_LINE   (1LU << 24LU)

Definition at line 243 of file hal_wspi.h.

Referenced by __n25q_init_impl(), __n25q_mmap_on_impl(), n25q_read_id(), and n25q_reset_xip().

◆ WSPI_CFG_DATA_MODE_TWO_LINES

#define WSPI_CFG_DATA_MODE_TWO_LINES   (2LU << 24LU)

Definition at line 244 of file hal_wspi.h.

Referenced by __n25q_mmap_on_impl(), and n25q_reset_xip().

◆ WSPI_CFG_DATA_MODE_FOUR_LINES

#define WSPI_CFG_DATA_MODE_FOUR_LINES   (3LU << 24LU)

Definition at line 245 of file hal_wspi.h.

Referenced by __n25q_mmap_on_impl(), and n25q_reset_xip().

◆ WSPI_CFG_DATA_MODE_EIGHT_LINES

#define WSPI_CFG_DATA_MODE_EIGHT_LINES   (4LU << 24LU)

Definition at line 246 of file hal_wspi.h.

◆ WSPI_CFG_DATA_DTR

#define WSPI_CFG_DATA_DTR   (1LU << 27LU)

Definition at line 248 of file hal_wspi.h.

◆ WSPI_CFG_DQS_ENABLE

#define WSPI_CFG_DQS_ENABLE   (1LU << 29LU)

Definition at line 250 of file hal_wspi.h.

◆ WSPI_CFG_SIOO

#define WSPI_CFG_SIOO   (1LU << 31LU)

Definition at line 252 of file hal_wspi.h.

Referenced by __n25q_mmap_on_impl().

◆ WSPI_CFG_ALL_DTR

#define WSPI_CFG_ALL_DTR
Value:
#define WSPI_CFG_ADDR_DTR
Definition hal_wspi.h:218
#define WSPI_CFG_DATA_DTR
Definition hal_wspi.h:248
#define WSPI_CFG_ALT_DTR
Definition hal_wspi.h:233
#define WSPI_CFG_CMD_DTR
Definition hal_wspi.h:203

Definition at line 254 of file hal_wspi.h.

◆ wspiStartCommandI

#define wspiStartCommandI ( wspip,
cmdp )
Value:
{ \
osalDbgAssert(((cmdp)->cfg & WSPI_CFG_DATA_MODE_MASK) == \
"data mode specified"); \
(wspip)->state = WSPI_SEND; \
wspi_lld_command(wspip, cmdp); \
}
#define WSPI_CFG_DATA_MODE_MASK
Definition hal_wspi.h:241
#define WSPI_CFG_DATA_MODE_NONE
Definition hal_wspi.h:242
@ WSPI_SEND
Definition hal_wspi.h:74

Sends a command without data phase.

Postcondition
At the end of the operation the configured callback is invoked.
Parameters
[in]wspippointer to the WSPIDriver object
[in]cmdppointer to the command descriptor
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 274 of file hal_wspi.h.

Referenced by wspiCommand(), and wspiStartCommand().

◆ wspiStartSendI

#define wspiStartSendI ( wspip,
cmdp,
n,
txbuf )
Value:
{ \
osalDbgAssert(((cmdp)->cfg & WSPI_CFG_DATA_MODE_MASK) != \
"data mode required"); \
(wspip)->state = WSPI_SEND; \
wspi_lld_send(wspip, cmdp, n, txbuf); \
}

Sends data over the WSPI bus.

This asynchronous function starts a transmit operation.

Postcondition
At the end of the operation the configured callback is invoked.
Parameters
[in]wspippointer to the WSPIDriver object
[in]cmdppointer to the command descriptor
[in]nnumber of bytes to send or zero if no data phase
[in]txbufthe pointer to the transmit buffer
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 294 of file hal_wspi.h.

Referenced by wspiSend(), and wspiStartSend().

◆ wspiStartReceiveI

#define wspiStartReceiveI ( wspip,
cmdp,
n,
rxbuf )
Value:
{ \
osalDbgAssert(((cmdp)->cfg & WSPI_CFG_DATA_MODE_MASK) != \
"data mode required"); \
(wspip)->state = WSPI_RECEIVE; \
wspi_lld_receive(wspip, cmdp, n, rxbuf); \
}
@ WSPI_RECEIVE
Definition hal_wspi.h:75

Receives data from the WSPI bus.

This asynchronous function starts a receive operation.

Postcondition
At the end of the operation the configured callback is invoked.
Parameters
[in]wspippointer to the WSPIDriver object
[in]cmdppointer to the command descriptor
[in]nnumber of bytes to receive or zero if no data phase
[out]rxbufthe pointer to the receive buffer
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 314 of file hal_wspi.h.

Referenced by wspiReceive(), and wspiStartReceive().

◆ wspiMapFlashI

#define wspiMapFlashI ( wspip,
cmdp,
addrp )
Value:
wspi_lld_map_flash(wspip, cmdp, addrp)
void wspi_lld_map_flash(WSPIDriver *wspip, const wspi_command_t *cmdp, uint8_t **addrp)
Maps in memory space a WSPI flash device.

Maps in memory space a WSPI flash device.

Precondition
The memory flash device must be initialized appropriately before mapping it in memory space.
Parameters
[in]wspippointer to the WSPIDriver object
[in]cmdppointer to the command descriptor
[out]addrppointer to the memory start address of the mapped flash or NULL
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 335 of file hal_wspi.h.

Referenced by wspiMapFlash().

◆ wspiUnmapFlashI

#define wspiUnmapFlashI ( wspip)
Value:
void wspi_lld_unmap_flash(WSPIDriver *wspip)
Unmaps from memory space a WSPI flash device.

Maps in memory space a WSPI flash device.

Postcondition
The memory flash device must be re-initialized for normal commands exchange.
Parameters
[in]wspippointer to the WSPIDriver object
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 347 of file hal_wspi.h.

Referenced by wspiUnmapFlash().

◆ _wspi_wakeup_isr

#define _wspi_wakeup_isr ( wspip,
msg )
Value:
{ \
osalSysLockFromISR(); \
osalThreadResumeI(&(wspip)->thread, msg); \
osalSysUnlockFromISR(); \
}

Wakes up the waiting thread.

Parameters
[in]wspippointer to the WSPIDriver object
[in]msgthe wakeup message
Function Class:
Not an API, this function is for internal use only.

Definition at line 365 of file hal_wspi.h.

◆ _wspi_isr_code

#define _wspi_isr_code ( wspip)
Value:
{ \
if ((wspip)->config->end_cb) { \
(wspip)->state = WSPI_COMPLETE; \
(wspip)->config->end_cb(wspip); \
if ((wspip)->state == WSPI_COMPLETE) \
(wspip)->state = WSPI_READY; \
} \
else \
(wspip)->state = WSPI_READY; \
_wspi_wakeup_isr(wspip, MSG_OK); \
}
#define MSG_OK
Definition osal.h:56
@ WSPI_COMPLETE
Definition hal_wspi.h:76
@ WSPI_READY
Definition hal_wspi.h:73

Common ISR code.

This code handles the portable part of the ISR code:

  • Callback invocation.
  • Waiting thread wakeup, if any.
  • Driver state transitions.
Note
This macro is meant to be used in the low level drivers implementation only.
Parameters
[in]wspippointer to the WSPIDriver object
Function Class:
Not an API, this function is for internal use only.

Definition at line 388 of file hal_wspi.h.

◆ _wspi_error_code

#define _wspi_error_code ( wspip)
Value:
{ \
if ((wspip)->config->error_cb) { \
(wspip)->state = WSPI_COMPLETE; \
(wspip)->config->error_cb(wspip); \
if ((wspip)->state == WSPI_COMPLETE) \
(wspip)->state = WSPI_READY; \
} \
else \
(wspip)->state = WSPI_READY; \
_wspi_wakeup_isr(wspip, MSG_RESET); \
}
#define MSG_RESET
Definition osal.h:58

Common error ISR code.

This code handles the portable part of the ISR code:

  • Callback invocation.
  • Waiting thread wakeup, if any.
  • Driver state transitions.
Note
This macro is meant to be used in the low level drivers implementation only.
Parameters
[in]wspippointer to the WSPIDriver object
Function Class:
Not an API, this function is for internal use only.

Definition at line 414 of file hal_wspi.h.

◆ WSPI_SUPPORTS_MEMMAP

#define WSPI_SUPPORTS_MEMMAP   TRUE

Definition at line 38 of file hal_wspi_lld.h.

◆ WSPI_DEFAULT_CFG_MASKS

#define WSPI_DEFAULT_CFG_MASKS   TRUE

Definition at line 39 of file hal_wspi_lld.h.

◆ PLATFORM_WSPI_USE_WSPI1

#define PLATFORM_WSPI_USE_WSPI1   FALSE

WSPID1 driver enable switch.

If set to TRUE the support for WSPID1 is included.

Note
The default is FALSE.

Definition at line 56 of file hal_wspi_lld.h.

◆ wspi_lld_driver_fields

#define wspi_lld_driver_fields
Value:
/* Dummy field, it is not needed.*/ \
uint32_t dummy;

Low level fields of the WSPI driver structure.

Definition at line 75 of file hal_wspi_lld.h.

◆ wspi_lld_config_fields

#define wspi_lld_config_fields
Value:
/* Dummy configuration, it is not needed.*/ \
uint32_t dummy;

Low level fields of the WSPI configuration structure.

Definition at line 82 of file hal_wspi_lld.h.

Typedef Documentation

◆ WSPIDriver

typedef struct hal_wspi_driver WSPIDriver

Type of a structure representing an WSPI driver.

Definition at line 83 of file hal_wspi.h.

◆ WSPIConfig

typedef struct hal_wspi_config WSPIConfig

Type of a structure representing an WSPI driver configuration.

Definition at line 88 of file hal_wspi.h.

◆ wspicallback_t

typedef void(* wspicallback_t) (WSPIDriver *wspip)

Type of a WSPI notification callback.

Parameters
[in]wspippointer to the WSPIDriver object triggering the callback

Definition at line 96 of file hal_wspi.h.

Enumeration Type Documentation

◆ wspistate_t

Driver state machine possible states.

Enumerator
WSPI_UNINIT 

Not initialized.

WSPI_STOP 

Stopped.

WSPI_READY 

Ready.

WSPI_SEND 

Sending data.

WSPI_RECEIVE 

Receiving data.

WSPI_COMPLETE 

Asynchronous operation complete.

WSPI_MEMMAP 

In memory mapped mode.

Definition at line 70 of file hal_wspi.h.

Function Documentation

◆ wspiInit()

void wspiInit ( void )

WSPI Driver initialization.

Note
This function is implicitly invoked by halInit(), there is no need to explicitly initialize the driver.
Function Class:
Object or module nitializer function.

Definition at line 56 of file hal_wspi.c.

References wspi_lld_init().

Referenced by halInit().

Here is the call graph for this function:

◆ wspiObjectInit()

void wspiObjectInit ( WSPIDriver * wspip)

Initializes the standard part of a WSPIDriver structure.

Parameters
[out]wspippointer to the WSPIDriver object
Function Class:
Object or module nitializer function.

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().

Here is the call graph for this function:

◆ wspiStart()

msg_t wspiStart ( WSPIDriver * wspip,
const WSPIConfig * config )

Configures and activates the WSPI peripheral.

Parameters
[in]wspippointer to the WSPIDriver object
[in]configpointer to the WSPIConfig object
Returns
The operation status.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 92 of file hal_wspi.c.

References hal_wspi_driver::config, HAL_RET_SUCCESS, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), hal_wspi_driver::state, wspi_lld_start(), WSPI_READY, and WSPI_STOP.

Referenced by __xsnor_bus_acquire(), bus_acquire(), snorStart(), and xsnorStart().

Here is the call graph for this function:

◆ wspiStop()

void wspiStop ( WSPIDriver * wspip)

Deactivates the WSPI peripheral.

Note
Deactivating the peripheral also enforces a release of the slave select line.
Parameters
[in]wspippointer to the WSPIDriver object
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 131 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(), and xsnorStop().

Here is the call graph for this function:

◆ wspiStartCommand()

void wspiStartCommand ( WSPIDriver * wspip,
const wspi_command_t * cmdp )

Sends a command without data phase.

Postcondition
At the end of the operation the configured callback is invoked.
Parameters
[in]wspippointer to the WSPIDriver object
[in]cmdppointer to the command descriptor
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 156 of file hal_wspi.c.

References osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), hal_wspi_driver::state, WSPI_READY, and wspiStartCommandI.

Here is the call graph for this function:

◆ wspiStartSend()

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.

Postcondition
At the end of the operation the configured callback is invoked.
Parameters
[in]wspippointer to the WSPIDriver object
[in]cmdppointer to the command descriptor
[in]nnumber of bytes to send
[in]txbufthe pointer to the transmit buffer
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 180 of file hal_wspi.c.

References osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), hal_wspi_driver::state, WSPI_READY, and wspiStartSendI.

Here is the call graph for this function:

◆ wspiStartReceive()

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.

Postcondition
At the end of the operation the configured callback is invoked.
Parameters
[in]wspippointer to the WSPIDriver object
[in]cmdppointer to the command descriptor
[in]nnumber of bytes to send
[out]rxbufthe pointer to the receive buffer
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 206 of file hal_wspi.c.

References osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), hal_wspi_driver::state, WSPI_READY, and wspiStartReceiveI.

Here is the call graph for this function:

◆ wspiCommand()

bool wspiCommand ( WSPIDriver * wspip,
const wspi_command_t * cmdp )

Sends a command without data phase.

Precondition
In order to use this function the option WSPI_USE_WAIT must be enabled.
In order to use this function the driver must have been configured without callbacks (end_cb = NULL).
Parameters
[in]wspippointer to the WSPIDriver object
[in]cmdppointer to the command descriptor
Returns
The operation status.
Return values
falseif the operation succeeded.
trueif the operation failed because HW issues.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 237 of file hal_wspi.c.

References wspi_command_t::cfg, hal_wspi_driver::config, hal_wspi_config::end_cb, MSG_OK, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), osalThreadSuspendS(), hal_wspi_driver::state, hal_wspi_driver::thread, WSPI_CFG_DATA_MODE_MASK, WSPI_CFG_DATA_MODE_NONE, WSPI_READY, and wspiStartCommandI.

Referenced by __n25q_init_impl(), __xsnor_bus_cmd(), __xsnor_bus_cmd_addr(), bus_cmd(), bus_cmd_addr(), mx25_reset_memory(), mx25_write_cr2(), and n25q_reset_memory().

Here is the call graph for this function:

◆ wspiSend()

bool wspiSend ( WSPIDriver * wspip,
const wspi_command_t * cmdp,
size_t n,
const uint8_t * txbuf )

Sends a command with data over the WSPI bus.

Precondition
In order to use this function the option WSPI_USE_WAIT must be enabled.
In order to use this function the driver must have been configured without callbacks (end_cb = NULL).
Parameters
[in]wspippointer to the WSPIDriver object
[in]cmdppointer to the command descriptor
[in]nnumber of bytes to send
[in]txbufthe pointer to the transmit buffer
Returns
The operation status.
Return values
falseif the operation succeeded.
trueif the operation failed because HW issues.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 273 of file hal_wspi.c.

References wspi_command_t::cfg, hal_wspi_driver::config, hal_wspi_config::end_cb, MSG_OK, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), osalThreadSuspendS(), hal_wspi_driver::state, hal_wspi_driver::thread, WSPI_CFG_DATA_MODE_MASK, WSPI_CFG_DATA_MODE_NONE, WSPI_READY, and wspiStartSendI.

Referenced by __n25q_init_impl(), __xsnor_bus_cmd_addr_send(), __xsnor_bus_cmd_send(), bus_cmd_addr_send(), bus_cmd_send(), and mx25_write_cr2().

Here is the call graph for this function:

◆ wspiReceive()

bool wspiReceive ( WSPIDriver * wspip,
const wspi_command_t * cmdp,
size_t n,
uint8_t * rxbuf )

Sends a command then receives data over the WSPI bus.

Precondition
In order to use this function the option WSPI_USE_WAIT must be enabled.
In order to use this function the driver must have been configured without callbacks (end_cb = NULL).
Parameters
[in]wspippointer to the WSPIDriver object
[in]cmdppointer to the command descriptor
[in]nnumber of bytes to send
[out]rxbufthe pointer to the receive buffer
Returns
The operation status.
Return values
falseif the operation succeeded.
trueif the operation failed because HW issues.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 311 of file hal_wspi.c.

References wspi_command_t::cfg, hal_wspi_driver::config, hal_wspi_config::end_cb, MSG_OK, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), osalThreadSuspendS(), hal_wspi_driver::state, hal_wspi_driver::thread, WSPI_CFG_DATA_MODE_MASK, WSPI_CFG_DATA_MODE_NONE, WSPI_READY, and wspiStartReceiveI.

Referenced by __xsnor_bus_cmd_addr_dummy_receive(), __xsnor_bus_cmd_addr_receive(), __xsnor_bus_cmd_dummy_receive(), __xsnor_bus_cmd_receive(), bus_cmd_addr_dummy_receive(), bus_cmd_addr_receive(), bus_cmd_dummy_receive(), bus_cmd_receive(), mx25_read_id(), n25q_read_id(), and n25q_reset_xip().

Here is the call graph for this function:

◆ wspiMapFlash()

void wspiMapFlash ( WSPIDriver * wspip,
const wspi_command_t * cmdp,
uint8_t ** addrp )

Maps in memory space a WSPI flash device.

Precondition
The memory flash device must be initialized appropriately before mapping it in memory space.
Parameters
[in]wspippointer to the WSPIDriver object
[in]cmdppointer to the command descriptor
[out]addrppointer to the memory start address of the mapped flash or NULL
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 346 of file hal_wspi.c.

References wspi_command_t::cfg, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), hal_wspi_driver::state, WSPI_CFG_DATA_MODE_MASK, WSPI_CFG_DATA_MODE_NONE, WSPI_MEMMAP, WSPI_READY, and wspiMapFlashI.

Referenced by __mx25_mmap_on_impl(), __n25q_mmap_on_impl(), and snorMemoryMap().

Here is the call graph for this function:

◆ wspiUnmapFlash()

void wspiUnmapFlash ( WSPIDriver * wspip)

Unmaps from memory space a WSPI flash device.

Postcondition
The memory flash device must be re-initialized for normal commands exchange.
Parameters
[in]wspippointer to the WSPIDriver object
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 372 of file hal_wspi.c.

References osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), hal_wspi_driver::state, WSPI_MEMMAP, WSPI_READY, and wspiUnmapFlashI.

Referenced by __mx25_mmap_off_impl(), __n25q_mmap_off_impl(), and snorMemoryUnmap().

Here is the call graph for this function:

◆ wspiAcquireBus()

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.

Precondition
In order to use this function the option WSPI_USE_MUTUAL_EXCLUSION must be enabled.
Parameters
[in]wspippointer to the WSPIDriver object
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 399 of file hal_wspi.c.

References hal_wspi_driver::mutex, osalDbgCheck, and osalMutexLock().

Referenced by __xsnor_bus_acquire(), and bus_acquire().

Here is the call graph for this function:

◆ wspiReleaseBus()

void wspiReleaseBus ( WSPIDriver * wspip)

Releases exclusive access to the WSPI bus.

Precondition
In order to use this function the option WSPI_USE_MUTUAL_EXCLUSION must be enabled.
Parameters
[in]wspippointer to the WSPIDriver object
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 415 of file hal_wspi.c.

References hal_wspi_driver::mutex, osalDbgCheck, and osalMutexUnlock().

Referenced by __xsnor_bus_release(), and bus_release().

Here is the call graph for this function:

◆ wspi_lld_init()

void wspi_lld_init ( void )

Low level WSPI driver initialization.

Function Class:
Not an API, this function is for internal use only.

Definition at line 63 of file hal_wspi_lld.c.

References WSPID1, and wspiObjectInit().

Referenced by wspiInit().

Here is the call graph for this function:

◆ wspi_lld_start()

void wspi_lld_start ( WSPIDriver * wspip)

Configures and activates the WSPI peripheral.

Parameters
[in]wspippointer to the WSPIDriver object
Function Class:
Not an API, this function is for internal use only.

Definition at line 77 of file hal_wspi_lld.c.

References hal_wspi_driver::state, WSPI_STOP, and WSPID1.

Referenced by wspiStart().

◆ wspi_lld_stop()

void wspi_lld_stop ( WSPIDriver * wspip)

Deactivates the WSPI peripheral.

Parameters
[in]wspippointer to the WSPIDriver object
Function Class:
Not an API, this function is for internal use only.

Definition at line 99 of file hal_wspi_lld.c.

References hal_wspi_driver::state, WSPI_READY, and WSPID1.

Referenced by wspiStop().

◆ wspi_lld_command()

void wspi_lld_command ( WSPIDriver * wspip,
const wspi_command_t * cmdp )

Sends a command without data phase.

Postcondition
At the end of the operation the configured callback is invoked.
Parameters
[in]wspippointer to the WSPIDriver object
[in]cmdppointer to the command descriptor
Function Class:
Not an API, this function is for internal use only.

Definition at line 123 of file hal_wspi_lld.c.

◆ wspi_lld_send()

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.

Postcondition
At the end of the operation the configured callback is invoked.
Parameters
[in]wspippointer to the WSPIDriver object
[in]cmdppointer to the command descriptor
[in]nnumber of bytes to send
[in]txbufthe pointer to the transmit buffer
Function Class:
Not an API, this function is for internal use only.

Definition at line 140 of file hal_wspi_lld.c.

◆ wspi_lld_receive()

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.

Postcondition
At the end of the operation the configured callback is invoked.
Parameters
[in]wspippointer to the WSPIDriver object
[in]cmdppointer to the command descriptor
[in]nnumber of bytes to send
[out]rxbufthe pointer to the receive buffer
Function Class:
Not an API, this function is for internal use only.

Definition at line 160 of file hal_wspi_lld.c.

◆ wspi_lld_map_flash()

void wspi_lld_map_flash ( WSPIDriver * wspip,
const wspi_command_t * cmdp,
uint8_t ** addrp )

Maps in memory space a WSPI flash device.

Precondition
The memory flash device must be initialized appropriately before mapping it in memory space.
Parameters
[in]wspippointer to the WSPIDriver object
[in]cmdppointer to the command descriptor
[out]addrppointer to the memory start address of the mapped flash or NULL
Function Class:
Not an API, this function is for internal use only.

Definition at line 182 of file hal_wspi_lld.c.

◆ wspi_lld_unmap_flash()

void wspi_lld_unmap_flash ( WSPIDriver * wspip)

Unmaps from memory space a WSPI flash device.

Postcondition
The memory flash device must be re-initialized for normal commands exchange.
Parameters
[in]wspippointer to the WSPIDriver object
Function Class:
Not an API, this function is for internal use only.

Definition at line 200 of file hal_wspi_lld.c.

Variable Documentation

◆ WSPID1

WSPIDriver WSPID1

WSPID1 driver identifier.

Definition at line 39 of file hal_wspi_lld.c.

Referenced by wspi_lld_init(), wspi_lld_start(), and wspi_lld_stop().