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,
69 #if ((SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI) && \ 70 (SNOR_SHARED_BUS == TRUE)) || defined(__DOXYGEN__) 79 static void bus_acquire(BUSDriver *busp,
const BUSConfig *config) {
84 if (busp->config != config) {
101 #elif (SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_SPI) && \ 102 (SNOR_SHARED_BUS == TRUE) 103 void bus_acquire(BUSDriver *busp,
const BUSConfig *config) {
106 if (busp->config != config) {
118 #define bus_acquire(busp) 119 #define bus_release(busp) 132 osalDbgAssert((devp->state != FLASH_UNINIT) && (devp->state != FLASH_STOP),
135 return &snor_descriptor;
139 size_t n, uint8_t *rp) {
143 osalDbgCheck((instance != NULL) && (rp != NULL) && (n > 0U));
144 osalDbgCheck((
size_t)offset + n <= (
size_t)snor_descriptor.sectors_count *
145 (
size_t)snor_descriptor.sectors_size);
146 osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE),
149 if (devp->state == FLASH_ERASE) {
150 return FLASH_BUSY_ERASING;
157 devp->state = FLASH_READ;
160 err = snor_device_read(devp, offset, n, rp);
163 devp->state = FLASH_READY;
172 size_t n,
const uint8_t *pp) {
176 osalDbgCheck((instance != NULL) && (pp != NULL) && (n > 0U));
177 osalDbgCheck((
size_t)offset + n <= (
size_t)snor_descriptor.sectors_count *
178 (
size_t)snor_descriptor.sectors_size);
179 osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE),
182 if (devp->state == FLASH_ERASE) {
183 return FLASH_BUSY_ERASING;
190 devp->state = FLASH_PGM;
193 err = snor_device_program(devp, offset, n, pp);
196 devp->state = FLASH_READY;
209 osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE),
212 if (devp->state == FLASH_ERASE) {
213 return FLASH_BUSY_ERASING;
220 devp->state = FLASH_ERASE;
223 err = snor_device_start_erase_all(devp);
226 devp->state = FLASH_READY;
241 osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE),
244 if (devp->state == FLASH_ERASE) {
245 return FLASH_BUSY_ERASING;
252 devp->state = FLASH_ERASE;
255 err = snor_device_start_erase_sector(devp, sector);
270 osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE),
273 if (devp->state == FLASH_ERASE) {
274 return FLASH_BUSY_ERASING;
281 devp->state = FLASH_READ;
284 err = snor_device_verify_erase(devp, sector);
287 devp->state = FLASH_READY;
295 static flash_error_t snor_query_erase(
void *instance, uint32_t *msec) {
300 osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE),
304 if (devp->state == FLASH_ERASE) {
310 err = snor_device_query_erase(devp, msec);
313 if (err == FLASH_NO_ERROR) {
314 devp->state = FLASH_READY;
321 err = FLASH_NO_ERROR;
328 size_t n, uint8_t *rp) {
332 osalDbgCheck((instance != NULL) && (rp != NULL) && (n > 0U));
333 osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE),
336 if (devp->state == FLASH_ERASE) {
337 return FLASH_BUSY_ERASING;
344 err = snor_device_read_sfdp(devp, offset, n, rp);
347 if (err == FLASH_NO_ERROR) {
348 devp->state = FLASH_READY;
370 #if SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI 386 #if SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI 390 mode.
cfg = SNOR_WSPI_CFG_CMD;
415 void bus_cmd_send(BUSDriver *busp, uint32_t cmd,
size_t n,
const uint8_t *p) {
416 #if SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI 420 mode.
cfg = SNOR_WSPI_CFG_CMD_DATA;
450 #if SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI 454 mode.
cfg = SNOR_WSPI_CFG_CMD_DATA;
480 #if SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI 484 mode.
cfg = SNOR_WSPI_CFG_CMD_ADDR;
494 buf[1] = (uint8_t)(offset >> 16);
495 buf[2] = (uint8_t)(offset >> 8);
496 buf[3] = (uint8_t)(offset >> 0);
519 #if SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI 523 mode.
cfg = SNOR_WSPI_CFG_CMD_ADDR_DATA;
533 buf[1] = (uint8_t)(offset >> 16);
534 buf[2] = (uint8_t)(offset >> 8);
535 buf[3] = (uint8_t)(offset >> 0);
559 #if SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI 563 mode.
cfg = SNOR_WSPI_CFG_CMD_ADDR_DATA;
573 buf[1] = (uint8_t)(offset >> 16);
574 buf[2] = (uint8_t)(offset >> 8);
575 buf[3] = (uint8_t)(offset >> 0);
582 #if (SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI) || defined(__DOXYGEN__) 603 mode.
cfg = SNOR_WSPI_CFG_CMD_DATA;
632 mode.
cfg = SNOR_WSPI_CFG_CMD_ADDR_DATA;
652 devp->state = FLASH_STOP;
671 if (devp->state == FLASH_STOP) {
677 snor_device_init(devp);
680 devp->state = FLASH_READY;
699 if (devp->state != FLASH_STOP) {
708 devp->state = FLASH_STOP;
718 #if (SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI) || defined(__DOXYGEN__) 719 #if (WSPI_SUPPORTS_MEMMAP == TRUE) || defined(__DOXYGEN__) 737 #if SNOR_DEVICE_SUPPORTS_XIP == TRUE 739 snor_activate_xip(devp);
764 #if SNOR_DEVICE_SUPPORTS_XIP == TRUE 765 snor_reset_xip(devp);
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.
uint32_t flash_sector_t
Type of a flash sector number.
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 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 spiUnselect(SPIDriver *spip)
Deasserts the slave select signal.
void bus_cmd_addr(BUSDriver *busp, uint32_t cmd, flash_offset_t offset)
Sends a command followed by a flash address.
void spiSelect(SPIDriver *spip)
Asserts the slave select signal and prepares for transfers.
void wspiAcquireBus(WSPIDriver *wspip)
Gains exclusive access to the WSPI bus.
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.
SNOR virtual methods table.
uint32_t dummy
Number of dummy cycles to be inserted.
const struct SNORDriverVMT * vmt
SNORDriver Virtual Methods Table.
void spiReceive(SPIDriver *spip, size_t n, void *rxbuf)
Receives data from the SPI bus.
void snorStart(SNORDriver *devp, const SNORConfig *config)
Configures and activates SNOR driver.
void spiStart(SPIDriver *spip, const SPIConfig *config)
Configures and activates the SPI peripheral.
static void bus_acquire(BUSDriver *busp, const BUSConfig *config)
Bus acquisition and lock.
void snorStop(SNORDriver *devp)
Deactivates the SNOR driver.
void wspiStart(WSPIDriver *wspip, const WSPIConfig *config)
Configures and activates the WSPI peripheral.
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.
static const struct SNORDriverVMT snor_vmt
Virtual methods table.
void wspiStop(WSPIDriver *wspip)
Deactivates the WSPI peripheral.
Type of a SNOR configuration structure.
void wspiReleaseBus(WSPIDriver *wspip)
Releases exclusive access to the WSPI bus.
void spiReleaseBus(SPIDriver *spip)
Releases exclusive access to the SPI bus.
void wspiUnmapFlash(WSPIDriver *wspip)
Unmaps from memory space a WSPI flash device.
uint32_t addr
Address phase data.
void spiAcquireBus(SPIDriver *spip)
Gains exclusive access to the SPI bus.
void snorObjectInit(SNORDriver *devp)
Initializes an instance.
Type of a flash device descriptor.
uint32_t alt
Alternate phase data.
flash_error_t
Type of a flash error code.
#define osalDbgCheck(c)
Function parameters check.
void bus_stop(BUSDriver *busp)
Stops the underlying bus driver.
uint32_t cmd
Command phase data.
uint32_t flash_offset_t
Type of a flash offset.
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.
static const flash_descriptor_t * snor_get_descriptor(void *instance)
Returns a pointer to the device descriptor.
Type of a WSPI command descriptor.
void bus_cmd_receive(BUSDriver *busp, uint32_t cmd, size_t n, uint8_t *p)
Sends a command followed by a data receive phase.
Type of SNOR flash class.
void spiSend(SPIDriver *spip, size_t n, const void *txbuf)
Sends data over the SPI bus.
void wspiCommand(WSPIDriver *wspip, const wspi_command_t *cmdp)
Sends a command without data phase.
static void bus_release(BUSDriver *busp)
Bus release.
_base_flash_data const SNORConfig * config
Current configuration data.
#define osalDbgAssert(c, remark)
Condition assertion.
void snorMemoryMap(SNORDriver *devp, uint8_t **addrp)
Enters the memory Mapping mode.
Serial NOR driver header.
void snorMemoryUnmap(SNORDriver *devp)
Leaves the memory Mapping mode.
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.
uint32_t cfg
Transfer configuration field.
void spiStop(SPIDriver *spip)
Deactivates the SPI peripheral.
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.