Go to the documentation of this file.
42 size_t n, uint8_t *rp);
44 size_t n,
const uint8_t *pp);
50 static flash_error_t snor_query_erase(
void *instance, uint32_t *msec);
52 size_t n, uint8_t *rp);
60 snor_start_erase_all, snor_start_erase_sector,
61 snor_query_erase, snor_verify_erase,
79 osalDbgAssert((devp->state != FLASH_UNINIT) && (devp->state != FLASH_STOP),
82 return &snor_descriptor;
86 size_t n, uint8_t *rp) {
90 osalDbgCheck((instance != NULL) && (rp != NULL) && (n > 0U));
91 osalDbgCheck((
size_t)offset + n <= (
size_t)snor_descriptor.sectors_count *
92 (
size_t)snor_descriptor.sectors_size);
93 osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE),
96 if (devp->state == FLASH_ERASE) {
97 return FLASH_BUSY_ERASING;
104 devp->state = FLASH_READ;
107 err = snor_device_read(devp, offset, n, rp);
110 devp->state = FLASH_READY;
119 size_t n,
const uint8_t *pp) {
123 osalDbgCheck((instance != NULL) && (pp != NULL) && (n > 0U));
124 osalDbgCheck((
size_t)offset + n <= (
size_t)snor_descriptor.sectors_count *
125 (
size_t)snor_descriptor.sectors_size);
126 osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE),
129 if (devp->state == FLASH_ERASE) {
130 return FLASH_BUSY_ERASING;
137 devp->state = FLASH_PGM;
140 err = snor_device_program(devp, offset, n, pp);
143 devp->state = FLASH_READY;
156 osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE),
159 if (devp->state == FLASH_ERASE) {
160 return FLASH_BUSY_ERASING;
167 devp->state = FLASH_ERASE;
170 err = snor_device_start_erase_all(devp);
173 devp->state = FLASH_READY;
188 osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE),
191 if (devp->state == FLASH_ERASE) {
192 return FLASH_BUSY_ERASING;
199 devp->state = FLASH_ERASE;
202 err = snor_device_start_erase_sector(devp, sector);
217 osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE),
220 if (devp->state == FLASH_ERASE) {
221 return FLASH_BUSY_ERASING;
228 devp->state = FLASH_READ;
231 err = snor_device_verify_erase(devp, sector);
234 devp->state = FLASH_READY;
242 static flash_error_t snor_query_erase(
void *instance, uint32_t *msec) {
247 osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE),
251 if (devp->state == FLASH_ERASE) {
257 err = snor_device_query_erase(devp, msec);
260 if (err == FLASH_NO_ERROR) {
261 devp->state = FLASH_READY;
268 err = FLASH_NO_ERROR;
275 size_t n, uint8_t *rp) {
279 osalDbgCheck((instance != NULL) && (rp != NULL) && (n > 0U));
280 osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE),
283 if (devp->state == FLASH_ERASE) {
284 return FLASH_BUSY_ERASING;
291 err = snor_device_read_sfdp(devp, offset, n, rp);
294 if (err == FLASH_NO_ERROR) {
295 devp->state = FLASH_READY;
308 #if ((SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI) && \
309 (SNOR_SHARED_BUS == TRUE)) || defined(__DOXYGEN__)
323 if (busp->config != config) {
341 #if (SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_SPI) && \
342 (SNOR_SHARED_BUS == TRUE)
343 void bus_acquire(BUSDriver *busp,
const BUSConfig *config) {
346 if (busp->config != config) {
366 #if SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI
382 #if SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI
386 mode.
cfg = SNOR_WSPI_CFG_CMD;
411 void bus_cmd_send(BUSDriver *busp, uint32_t cmd,
size_t n,
const uint8_t *p) {
412 #if SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI
416 mode.
cfg = SNOR_WSPI_CFG_CMD_DATA;
446 #if SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI
450 mode.
cfg = SNOR_WSPI_CFG_CMD_DATA;
476 #if SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI
480 mode.
cfg = SNOR_WSPI_CFG_CMD_ADDR;
490 buf[1] = (uint8_t)(offset >> 16);
491 buf[2] = (uint8_t)(offset >> 8);
492 buf[3] = (uint8_t)(offset >> 0);
515 #if SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI
519 mode.
cfg = SNOR_WSPI_CFG_CMD_ADDR_DATA;
529 buf[1] = (uint8_t)(offset >> 16);
530 buf[2] = (uint8_t)(offset >> 8);
531 buf[3] = (uint8_t)(offset >> 0);
555 #if SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI
559 mode.
cfg = SNOR_WSPI_CFG_CMD_ADDR_DATA;
569 buf[1] = (uint8_t)(offset >> 16);
570 buf[2] = (uint8_t)(offset >> 8);
571 buf[3] = (uint8_t)(offset >> 0);
578 #if (SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI) || defined(__DOXYGEN__)
599 mode.
cfg = SNOR_WSPI_CFG_CMD_DATA;
628 mode.
cfg = SNOR_WSPI_CFG_CMD_ADDR_DATA;
648 devp->state = FLASH_STOP;
667 if (devp->state == FLASH_STOP) {
673 snor_device_init(devp);
676 devp->state = FLASH_READY;
695 if (devp->state != FLASH_STOP) {
704 devp->state = FLASH_STOP;
714 #if (SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI) || defined(__DOXYGEN__)
715 #if (WSPI_SUPPORTS_MEMMAP == TRUE) || defined(__DOXYGEN__)
733 #if SNOR_DEVICE_SUPPORTS_XIP == TRUE
735 snor_activate_xip(devp);
760 #if SNOR_DEVICE_SUPPORTS_XIP == TRUE
761 snor_reset_xip(devp);
void bus_cmd_dummy_receive(BUSDriver *busp, uint32_t cmd, uint32_t dummy, size_t n, uint8_t *p)
Sends a command followed by dummy cycles and a data receive phase.
void bus_release(BUSDriver *busp)
Bus release.
void spiSelect(SPIDriver *spip)
Asserts the slave select signal and prepares for transfers.
Type of SNOR flash class.
Type of a WSPI command descriptor.
uint32_t addr
Address phase data.
void wspiAcquireBus(WSPIDriver *wspip)
Gains exclusive access to the WSPI bus.
void spiReceive(SPIDriver *spip, size_t n, void *rxbuf)
Receives data from the SPI bus.
void wspiStart(WSPIDriver *wspip, const WSPIConfig *config)
Configures and activates the WSPI peripheral.
void snorMemoryMap(SNORDriver *devp, uint8_t **addrp)
Enters the memory Mapping mode.
Type of a SNOR configuration structure.
void wspiUnmapFlash(WSPIDriver *wspip)
Unmaps from memory space a WSPI flash device.
void bus_cmd_addr_receive(BUSDriver *busp, uint32_t cmd, flash_offset_t offset, size_t n, uint8_t *p)
Sends a command followed by a flash address and a data receive phase.
void bus_acquire(BUSDriver *busp, const BUSConfig *config)
Bus acquisition and lock.
uint32_t dummy
Number of dummy cycles to be inserted.
Type of a flash device descriptor.
void wspiStop(WSPIDriver *wspip)
Deactivates the WSPI peripheral.
void wspiReleaseBus(WSPIDriver *wspip)
Releases exclusive access to the WSPI bus.
SNOR virtual methods table.
static const struct SNORDriverVMT snor_vmt
Virtual methods table.
const struct SNORDriverVMT * vmt
SNORDriver Virtual Methods Table.
static const flash_descriptor_t * snor_get_descriptor(void *instance)
Returns a pointer to the device descriptor.
uint32_t flash_sector_t
Type of a flash sector number.
void bus_cmd_receive(BUSDriver *busp, uint32_t cmd, size_t n, uint8_t *p)
Sends a command followed by a data receive phase.
void spiStop(SPIDriver *spip)
Deactivates the SPI peripheral.
void snorObjectInit(SNORDriver *devp)
Initializes an instance.
Serial NOR driver header.
void spiReleaseBus(SPIDriver *spip)
Releases exclusive access to the SPI bus.
void bus_cmd_addr_dummy_receive(BUSDriver *busp, uint32_t cmd, flash_offset_t offset, uint32_t dummy, size_t n, uint8_t *p)
Sends a command followed by a flash address, dummy cycles and a data receive phase.
void spiSend(SPIDriver *spip, size_t n, const void *txbuf)
Sends data over the SPI bus.
void bus_cmd_send(BUSDriver *busp, uint32_t cmd, size_t n, const uint8_t *p)
Sends a command followed by a data transmit phase.
void spiAcquireBus(SPIDriver *spip)
Gains exclusive access to the SPI bus.
void spiStart(SPIDriver *spip, const SPIConfig *config)
Configures and activates the SPI peripheral.
#define osalDbgCheck(c)
Function parameters check.
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.
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.
void bus_stop(BUSDriver *busp)
Stops the underlying bus driver.
flash_error_t
Type of a flash error code.
uint32_t alt
Alternate phase data.
bool wspiCommand(WSPIDriver *wspip, const wspi_command_t *cmdp)
Sends a command without data phase.
void snorStart(SNORDriver *devp, const SNORConfig *config)
Configures and activates SNOR driver.
uint32_t cfg
Transfer configuration field.
uint32_t cmd
Command phase data.
#define osalDbgAssert(c, remark)
Condition assertion.
void bus_cmd_addr(BUSDriver *busp, uint32_t cmd, flash_offset_t offset)
Sends a command followed by a flash address.
uint32_t flash_offset_t
Type of a flash offset.
void spiUnselect(SPIDriver *spip)
Deasserts the slave select signal.
const _base_flash_data SNORConfig * config
Current configuration data.
void snorStop(SNORDriver *devp)
Deactivates the SNOR driver.
void snorMemoryUnmap(SNORDriver *devp)
Leaves the memory Mapping mode.
void bus_cmd_addr_send(BUSDriver *busp, uint32_t cmd, flash_offset_t offset, size_t n, const uint8_t *p)
Sends a command followed by a flash address and a data transmit phase.
void bus_cmd(BUSDriver *busp, uint32_t cmd)
Sends a naked command.
void wspiMapFlash(WSPIDriver *wspip, const wspi_command_t *cmdp, uint8_t **addrp)
Maps in memory space a WSPI flash device.