ChibiOS/HAL  7.0.3
hal_serial_nor.c
Go to the documentation of this file.
1 /*
2  ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 
17 /**
18  * @file hal_serial_nor.c
19  * @brief Serial NOR serial flash driver code.
20  *
21  * @addtogroup HAL_SERIAL_NOR
22  * @{
23  */
24 
25 #include "hal.h"
26 #include "hal_serial_nor.h"
27 
28 /*===========================================================================*/
29 /* Driver local definitions. */
30 /*===========================================================================*/
31 
32 /*===========================================================================*/
33 /* Driver exported variables. */
34 /*===========================================================================*/
35 
36 /*===========================================================================*/
37 /* Driver local variables and types. */
38 /*===========================================================================*/
39 
40 static const flash_descriptor_t *snor_get_descriptor(void *instance);
41 static flash_error_t snor_read(void *instance, flash_offset_t offset,
42  size_t n, uint8_t *rp);
43 static flash_error_t snor_program(void *instance, flash_offset_t offset,
44  size_t n, const uint8_t *pp);
45 static flash_error_t snor_start_erase_all(void *instance);
46 static flash_error_t snor_start_erase_sector(void *instance,
47  flash_sector_t sector);
48 static flash_error_t snor_verify_erase(void *instance,
49  flash_sector_t sector);
50 static flash_error_t snor_query_erase(void *instance, uint32_t *msec);
51 static flash_error_t snor_read_sfdp(void *instance, flash_offset_t offset,
52  size_t n, uint8_t *rp);
53 
54 /**
55  * @brief Virtual methods table.
56  */
57 static const struct SNORDriverVMT snor_vmt = {
58  (size_t)0,
59  snor_get_descriptor, snor_read, snor_program,
60  snor_start_erase_all, snor_start_erase_sector,
61  snor_query_erase, snor_verify_erase,
62  snor_read_sfdp
63 };
64 
65 /*===========================================================================*/
66 /* Driver local functions. */
67 /*===========================================================================*/
68 
69 #if ((SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI) && \
70  (SNOR_SHARED_BUS == TRUE)) || defined(__DOXYGEN__)
71 /**
72  * @brief Bus acquisition and lock.
73  *
74  * @param[in] busp pointer to the bus driver
75  * @param[in] config bus configuration
76  *
77  * @notapi
78  */
79 static void bus_acquire(BUSDriver *busp, const BUSConfig *config) {
80 
81  (void)config;
82 
83  wspiAcquireBus(busp);
84  if (busp->config != config) {
85  wspiStart(busp, config);
86  }
87 }
88 
89 /**
90  * @brief Bus release.
91  *
92  * @param[in] busp pointer to the bus driver
93  *
94  * @notapi
95  */
96 static void bus_release(BUSDriver *busp) {
97 
98  wspiReleaseBus(busp);
99 }
100 
101 #elif (SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_SPI) && \
102  (SNOR_SHARED_BUS == TRUE)
103 void bus_acquire(BUSDriver *busp, const BUSConfig *config) {
104 
105  spiAcquireBus(busp);
106  if (busp->config != config) {
107  spiStart(busp, config);
108  }
109 }
110 
111 void bus_release(BUSDriver *busp) {
112 
113  spiReleaseBus(busp);
114 }
115 
116 #else
117 /* No bus sharing, empty macros.*/
118 #define bus_acquire(busp)
119 #define bus_release(busp)
120 #endif
121 
122 /**
123  * @brief Returns a pointer to the device descriptor.
124  *
125  * @param[in] instance instance pointer
126  * @return Pointer to a static descriptor structure.
127  */
128 static const flash_descriptor_t *snor_get_descriptor(void *instance) {
129  SNORDriver *devp = (SNORDriver *)instance;
130 
131  osalDbgCheck(instance != NULL);
132  osalDbgAssert((devp->state != FLASH_UNINIT) && (devp->state != FLASH_STOP),
133  "invalid state");
134 
135  return &snor_descriptor;
136 }
137 
138 static flash_error_t snor_read(void *instance, flash_offset_t offset,
139  size_t n, uint8_t *rp) {
140  SNORDriver *devp = (SNORDriver *)instance;
141  flash_error_t err;
142 
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),
147  "invalid state");
148 
149  if (devp->state == FLASH_ERASE) {
150  return FLASH_BUSY_ERASING;
151  }
152 
153  /* Bus acquired.*/
154  bus_acquire(devp->config->busp, devp->config->buscfg);
155 
156  /* FLASH_READY state while the operation is performed.*/
157  devp->state = FLASH_READ;
158 
159  /* Actual read implementation.*/
160  err = snor_device_read(devp, offset, n, rp);
161 
162  /* Ready state again.*/
163  devp->state = FLASH_READY;
164 
165  /* Bus released.*/
166  bus_release(devp->config->busp);
167 
168  return err;
169 }
170 
171 static flash_error_t snor_program(void *instance, flash_offset_t offset,
172  size_t n, const uint8_t *pp) {
173  SNORDriver *devp = (SNORDriver *)instance;
174  flash_error_t err;
175 
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),
180  "invalid state");
181 
182  if (devp->state == FLASH_ERASE) {
183  return FLASH_BUSY_ERASING;
184  }
185 
186  /* Bus acquired.*/
187  bus_acquire(devp->config->busp, devp->config->buscfg);
188 
189  /* FLASH_PGM state while the operation is performed.*/
190  devp->state = FLASH_PGM;
191 
192  /* Actual program implementation.*/
193  err = snor_device_program(devp, offset, n, pp);
194 
195  /* Ready state again.*/
196  devp->state = FLASH_READY;
197 
198  /* Bus released.*/
199  bus_release(devp->config->busp);
200 
201  return err;
202 }
203 
204 static flash_error_t snor_start_erase_all(void *instance) {
205  SNORDriver *devp = (SNORDriver *)instance;
206  flash_error_t err;
207 
208  osalDbgCheck(instance != NULL);
209  osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE),
210  "invalid state");
211 
212  if (devp->state == FLASH_ERASE) {
213  return FLASH_BUSY_ERASING;
214  }
215 
216  /* Bus acquired.*/
217  bus_acquire(devp->config->busp, devp->config->buscfg);
218 
219  /* FLASH_ERASE state while the operation is performed.*/
220  devp->state = FLASH_ERASE;
221 
222  /* Actual erase implementation.*/
223  err = snor_device_start_erase_all(devp);
224 
225  /* Ready state again.*/
226  devp->state = FLASH_READY;
227 
228  /* Bus released.*/
229  bus_release(devp->config->busp);
230 
231  return err;
232 }
233 
234 static flash_error_t snor_start_erase_sector(void *instance,
235  flash_sector_t sector) {
236  SNORDriver *devp = (SNORDriver *)instance;
237  flash_error_t err;
238 
239  osalDbgCheck(instance != NULL);
240  osalDbgCheck(sector < snor_descriptor.sectors_count);
241  osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE),
242  "invalid state");
243 
244  if (devp->state == FLASH_ERASE) {
245  return FLASH_BUSY_ERASING;
246  }
247 
248  /* Bus acquired.*/
249  bus_acquire(devp->config->busp, devp->config->buscfg);
250 
251  /* FLASH_ERASE state while the operation is performed.*/
252  devp->state = FLASH_ERASE;
253 
254  /* Actual erase implementation.*/
255  err = snor_device_start_erase_sector(devp, sector);
256 
257  /* Bus released.*/
258  bus_release(devp->config->busp);
259 
260  return err;
261 }
262 
263 static flash_error_t snor_verify_erase(void *instance,
264  flash_sector_t sector) {
265  SNORDriver *devp = (SNORDriver *)instance;
266  flash_error_t err;
267 
268  osalDbgCheck(instance != NULL);
269  osalDbgCheck(sector < snor_descriptor.sectors_count);
270  osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE),
271  "invalid state");
272 
273  if (devp->state == FLASH_ERASE) {
274  return FLASH_BUSY_ERASING;
275  }
276 
277  /* Bus acquired.*/
278  bus_acquire(devp->config->busp, devp->config->buscfg);
279 
280  /* FLASH_READY state while the operation is performed.*/
281  devp->state = FLASH_READ;
282 
283  /* Actual verify erase implementation.*/
284  err = snor_device_verify_erase(devp, sector);
285 
286  /* Ready state again.*/
287  devp->state = FLASH_READY;
288 
289  /* Bus released.*/
290  bus_release(devp->config->busp);
291 
292  return err;
293 }
294 
295 static flash_error_t snor_query_erase(void *instance, uint32_t *msec) {
296  SNORDriver *devp = (SNORDriver *)instance;
297  flash_error_t err;
298 
299  osalDbgCheck(instance != NULL);
300  osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE),
301  "invalid state");
302 
303  /* If there is an erase in progress then the device must be checked.*/
304  if (devp->state == FLASH_ERASE) {
305 
306  /* Bus acquired.*/
307  bus_acquire(devp->config->busp, devp->config->buscfg);
308 
309  /* Actual query erase implementation.*/
310  err = snor_device_query_erase(devp, msec);
311 
312  /* The device is ready to accept commands.*/
313  if (err == FLASH_NO_ERROR) {
314  devp->state = FLASH_READY;
315  }
316 
317  /* Bus released.*/
318  bus_release(devp->config->busp);
319  }
320  else {
321  err = FLASH_NO_ERROR;
322  }
323 
324  return err;
325 }
326 
327 static flash_error_t snor_read_sfdp(void *instance, flash_offset_t offset,
328  size_t n, uint8_t *rp) {
329  SNORDriver *devp = (SNORDriver *)instance;
330  flash_error_t err;
331 
332  osalDbgCheck((instance != NULL) && (rp != NULL) && (n > 0U));
333  osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE),
334  "invalid state");
335 
336  if (devp->state == FLASH_ERASE) {
337  return FLASH_BUSY_ERASING;
338  }
339 
340  /* Bus acquired.*/
341  bus_acquire(devp->config->busp, devp->config->buscfg);
342 
343  /* Actual read SFDP implementation.*/
344  err = snor_device_read_sfdp(devp, offset, n, rp);
345 
346  /* The device is ready to accept commands.*/
347  if (err == FLASH_NO_ERROR) {
348  devp->state = FLASH_READY;
349  }
350 
351  /* Bus released.*/
352  bus_release(devp->config->busp);
353 
354  return err;
355 }
356 
357 /*===========================================================================*/
358 /* Driver exported functions. */
359 /*===========================================================================*/
360 
361 /**
362  * @brief Stops the underlying bus driver.
363  *
364  * @param[in] busp pointer to the bus driver
365  *
366  * @notapi
367  */
368 void bus_stop(BUSDriver *busp) {
369 
370 #if SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI
371  wspiStop(busp);
372 #else
373  spiStop(busp);
374 #endif
375 }
376 
377 /**
378  * @brief Sends a naked command.
379  *
380  * @param[in] busp pointer to the bus driver
381  * @param[in] cmd instruction code
382  *
383  * @notapi
384  */
385 void bus_cmd(BUSDriver *busp, uint32_t cmd) {
386 #if SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI
387  wspi_command_t mode;
388 
389  mode.cmd = cmd;
390  mode.cfg = SNOR_WSPI_CFG_CMD;
391  mode.addr = 0U;
392  mode.alt = 0U;
393  mode.dummy = 0U;
394  wspiCommand(busp, &mode);
395 #else
396  uint8_t buf[1];
397 
398  spiSelect(busp);
399  buf[0] = cmd;
400  spiSend(busp, 1, buf);
401  spiUnselect(busp);
402 #endif
403 }
404 
405 /**
406  * @brief Sends a command followed by a data transmit phase.
407  *
408  * @param[in] busp pointer to the bus driver
409  * @param[in] cmd instruction code
410  * @param[in] n number of bytes to receive
411  * @param[in] p data buffer
412  *
413  * @notapi
414  */
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
417  wspi_command_t mode;
418 
419  mode.cmd = cmd;
420  mode.cfg = SNOR_WSPI_CFG_CMD_DATA;
421  mode.addr = 0U;
422  mode.alt = 0U;
423  mode.dummy = 0U;
424  wspiSend(busp, &mode, n, p);
425 #else
426  uint8_t buf[1];
427 
428  spiSelect(busp);
429  buf[0] = cmd;
430  spiSend(busp, 1, buf);
431  spiSend(busp, n, p);
432  spiUnselect(busp);
433 #endif
434 }
435 
436 /**
437  * @brief Sends a command followed by a data receive phase.
438  *
439  * @param[in] busp pointer to the bus driver
440  * @param[in] cmd instruction code
441  * @param[in] n number of bytes to receive
442  * @param[out] p data buffer
443  *
444  * @notapi
445  */
446 void bus_cmd_receive(BUSDriver *busp,
447  uint32_t cmd,
448  size_t n,
449  uint8_t *p) {
450 #if SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI
451  wspi_command_t mode;
452 
453  mode.cmd = cmd;
454  mode.cfg = SNOR_WSPI_CFG_CMD_DATA;
455  mode.addr = 0U;
456  mode.alt = 0U;
457  mode.dummy = 0U;
458  wspiReceive(busp, &mode, n, p);
459 #else
460  uint8_t buf[1];
461 
462  spiSelect(busp);
463  buf[0] = cmd;
464  spiSend(busp, 1, buf);
465  spiReceive(busp, n, p);
466  spiUnselect(busp);
467 #endif
468 }
469 
470 /**
471  * @brief Sends a command followed by a flash address.
472  *
473  * @param[in] busp pointer to the bus driver
474  * @param[in] cmd instruction code
475  * @param[in] offset flash offset
476  *
477  * @notapi
478  */
479 void bus_cmd_addr(BUSDriver *busp, uint32_t cmd, flash_offset_t offset) {
480 #if SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI
481  wspi_command_t mode;
482 
483  mode.cmd = cmd;
484  mode.cfg = SNOR_WSPI_CFG_CMD_ADDR;
485  mode.addr = offset;
486  mode.alt = 0U;
487  mode.dummy = 0U;
488  wspiCommand(busp, &mode);
489 #else
490  uint8_t buf[4];
491 
492  spiSelect(busp);
493  buf[0] = cmd;
494  buf[1] = (uint8_t)(offset >> 16);
495  buf[2] = (uint8_t)(offset >> 8);
496  buf[3] = (uint8_t)(offset >> 0);
497  spiSend(busp, 4, buf);
498  spiUnselect(busp);
499 #endif
500 }
501 
502 /**
503  * @brief Sends a command followed by a flash address and a data transmit
504  * phase.
505  *
506  * @param[in] busp pointer to the bus driver
507  * @param[in] cmd instruction code
508  * @param[in] offset flash offset
509  * @param[in] n number of bytes to receive
510  * @param[in] p data buffer
511  *
512  * @notapi
513  */
514 void bus_cmd_addr_send(BUSDriver *busp,
515  uint32_t cmd,
516  flash_offset_t offset,
517  size_t n,
518  const uint8_t *p) {
519 #if SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI
520  wspi_command_t mode;
521 
522  mode.cmd = cmd;
523  mode.cfg = SNOR_WSPI_CFG_CMD_ADDR_DATA;
524  mode.addr = offset;
525  mode.alt = 0U;
526  mode.dummy = 0U;
527  wspiSend(busp, &mode, n, p);
528 #else
529  uint8_t buf[4];
530 
531  spiSelect(busp);
532  buf[0] = cmd;
533  buf[1] = (uint8_t)(offset >> 16);
534  buf[2] = (uint8_t)(offset >> 8);
535  buf[3] = (uint8_t)(offset >> 0);
536  spiSend(busp, 4, buf);
537  spiSend(busp, n, p);
538  spiUnselect(busp);
539 #endif
540 }
541 
542 /**
543  * @brief Sends a command followed by a flash address and a data receive
544  * phase.
545  *
546  * @param[in] busp pointer to the bus driver
547  * @param[in] cmd instruction code
548  * @param[in] offset flash offset
549  * @param[in] n number of bytes to receive
550  * @param[out] p data buffer
551  *
552  * @notapi
553  */
554 void bus_cmd_addr_receive(BUSDriver *busp,
555  uint32_t cmd,
556  flash_offset_t offset,
557  size_t n,
558  uint8_t *p) {
559 #if SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI
560  wspi_command_t mode;
561 
562  mode.cmd = cmd;
563  mode.cfg = SNOR_WSPI_CFG_CMD_ADDR_DATA;
564  mode.addr = offset;
565  mode.alt = 0U;
566  mode.dummy = 0U;
567  wspiReceive(busp, &mode, n, p);
568 #else
569  uint8_t buf[4];
570 
571  spiSelect(busp);
572  buf[0] = cmd;
573  buf[1] = (uint8_t)(offset >> 16);
574  buf[2] = (uint8_t)(offset >> 8);
575  buf[3] = (uint8_t)(offset >> 0);
576  spiSend(busp, 4, buf);
577  spiReceive(busp, n, p);
578  spiUnselect(busp);
579 #endif
580 }
581 
582 #if (SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI) || defined(__DOXYGEN__)
583 /**
584  * @brief Sends a command followed by dummy cycles and a
585  * data receive phase.
586  *
587  * @param[in] busp pointer to the bus driver
588  * @param[in] cmd instruction code
589  * @param[in] dummy number of dummy cycles
590  * @param[in] n number of bytes to receive
591  * @param[out] p data buffer
592  *
593  * @notapi
594  */
595 void bus_cmd_dummy_receive(BUSDriver *busp,
596  uint32_t cmd,
597  uint32_t dummy,
598  size_t n,
599  uint8_t *p) {
600  wspi_command_t mode;
601 
602  mode.cmd = cmd;
603  mode.cfg = SNOR_WSPI_CFG_CMD_DATA;
604  mode.addr = 0U;
605  mode.alt = 0U;
606  mode.dummy = dummy;
607  wspiReceive(busp, &mode, n, p);
608 }
609 
610 /**
611  * @brief Sends a command followed by a flash address, dummy cycles and a
612  * data receive phase.
613  *
614  * @param[in] busp pointer to the bus driver
615  * @param[in] cmd instruction code
616  * @param[in] offset flash offset
617  * @param[in] dummy number of dummy cycles
618  * @param[in] n number of bytes to receive
619  * @param[out] p data buffer
620  *
621  * @notapi
622  */
623 void bus_cmd_addr_dummy_receive(BUSDriver *busp,
624  uint32_t cmd,
625  flash_offset_t offset,
626  uint32_t dummy,
627  size_t n,
628  uint8_t *p) {
629  wspi_command_t mode;
630 
631  mode.cmd = cmd;
632  mode.cfg = SNOR_WSPI_CFG_CMD_ADDR_DATA;
633  mode.addr = offset;
634  mode.alt = 0U;
635  mode.dummy = dummy;
636  wspiReceive(busp, &mode, n, p);
637 }
638 #endif /* SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI */
639 
640 /**
641  * @brief Initializes an instance.
642  *
643  * @param[out] devp pointer to the @p SNORDriver object
644  *
645  * @init
646  */
648 
649  osalDbgCheck(devp != NULL);
650 
651  devp->vmt = &snor_vmt;
652  devp->state = FLASH_STOP;
653  devp->config = NULL;
654 }
655 
656 /**
657  * @brief Configures and activates SNOR driver.
658  *
659  * @param[in] devp pointer to the @p SNORDriver object
660  * @param[in] config pointer to the configuration
661  *
662  * @api
663  */
664 void snorStart(SNORDriver *devp, const SNORConfig *config) {
665 
666  osalDbgCheck((devp != NULL) && (config != NULL));
667  osalDbgAssert(devp->state != FLASH_UNINIT, "invalid state");
668 
669  devp->config = config;
670 
671  if (devp->state == FLASH_STOP) {
672 
673  /* Bus acquisition.*/
674  bus_acquire(devp->config->busp, devp->config->buscfg);
675 
676  /* Device identification and initialization.*/
677  snor_device_init(devp);
678 
679  /* Driver in ready state.*/
680  devp->state = FLASH_READY;
681 
682  /* Bus release.*/
683  bus_release(devp->config->busp);
684  }
685 }
686 
687 /**
688  * @brief Deactivates the SNOR driver.
689  *
690  * @param[in] devp pointer to the @p SNORDriver object
691  *
692  * @api
693  */
694 void snorStop(SNORDriver *devp) {
695 
696  osalDbgCheck(devp != NULL);
697  osalDbgAssert(devp->state != FLASH_UNINIT, "invalid state");
698 
699  if (devp->state != FLASH_STOP) {
700 
701  /* Bus acquisition.*/
702  bus_acquire(devp->config->busp, devp->config->buscfg);
703 
704  /* Stopping bus device.*/
705  bus_stop(devp->config->busp);
706 
707  /* Driver stopped.*/
708  devp->state = FLASH_STOP;
709 
710  /* Bus release.*/
711  bus_release(devp->config->busp);
712 
713  /* Deleting current configuration.*/
714  devp->config = NULL;
715  }
716 }
717 
718 #if (SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI) || defined(__DOXYGEN__)
719 #if (WSPI_SUPPORTS_MEMMAP == TRUE) || defined(__DOXYGEN__)
720 /**
721  * @brief Enters the memory Mapping mode.
722  * @details The memory mapping mode is only available when the WSPI mode
723  * is selected and the underlying WSPI controller supports the
724  * feature.
725  *
726  * @param[in] devp pointer to the @p SNORDriver object
727  * @param[out] addrp pointer to the memory start address of the mapped
728  * flash or @p NULL
729  *
730  * @api
731  */
732 void snorMemoryMap(SNORDriver *devp, uint8_t **addrp) {
733 
734  /* Bus acquisition.*/
735  bus_acquire(devp->config->busp, devp->config->buscfg);
736 
737 #if SNOR_DEVICE_SUPPORTS_XIP == TRUE
738  /* Activating XIP mode in the device.*/
739  snor_activate_xip(devp);
740 #endif
741 
742  /* Starting WSPI memory mapped mode.*/
743  wspiMapFlash(devp->config->busp, &snor_memmap_read, addrp);
744 
745  /* Bus release.*/
746  bus_release(devp->config->busp);
747 }
748 
749 /**
750  * @brief Leaves the memory Mapping mode.
751  *
752  * @param[in] devp pointer to the @p SNORDriver object
753  *
754  * @api
755  */
757 
758  /* Bus acquisition.*/
759  bus_acquire(devp->config->busp, devp->config->buscfg);
760 
761  /* Stopping WSPI memory mapped mode.*/
762  wspiUnmapFlash(devp->config->busp);
763 
764 #if SNOR_DEVICE_SUPPORTS_XIP == TRUE
765  snor_reset_xip(devp);
766 #endif
767 
768  /* Bus release.*/
769  bus_release(devp->config->busp);
770 }
771 #endif /* WSPI_SUPPORTS_MEMMAP == TRUE */
772 #endif /* SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI */
773 
774 /** @} */
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.
Definition: hal_wspi.c:313
uint32_t flash_sector_t
Type of a flash sector number.
Definition: hal_flash.h:88
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.
Definition: hal_spi.c:152
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.
Definition: hal_spi.c:134
void wspiAcquireBus(WSPIDriver *wspip)
Gains exclusive access to the WSPI bus.
Definition: hal_wspi.c:366
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.
Definition: hal_wspi.h:120
const struct SNORDriverVMT * vmt
SNORDriver Virtual Methods Table.
void spiReceive(SPIDriver *spip, size_t n, void *rxbuf)
Receives data from the SPI bus.
Definition: hal_spi.c:416
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.
Definition: hal_spi.c:91
HAL subsystem header.
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.
Definition: hal_wspi.c:91
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.
Definition: hal_wspi.c:249
static const struct SNORDriverVMT snor_vmt
Virtual methods table.
void wspiStop(WSPIDriver *wspip)
Deactivates the WSPI peripheral.
Definition: hal_wspi.c:116
Type of a SNOR configuration structure.
void wspiReleaseBus(WSPIDriver *wspip)
Releases exclusive access to the WSPI bus.
Definition: hal_wspi.c:382
void spiReleaseBus(SPIDriver *spip)
Releases exclusive access to the SPI bus.
Definition: hal_spi.c:459
void wspiUnmapFlash(WSPIDriver *wspip)
Unmaps from memory space a WSPI flash device.
Definition: hal_wspi.c:339
uint32_t addr
Address phase data.
Definition: hal_wspi.h:112
void spiAcquireBus(SPIDriver *spip)
Gains exclusive access to the SPI bus.
Definition: hal_spi.c:443
void snorObjectInit(SNORDriver *devp)
Initializes an instance.
Type of a flash device descriptor.
Definition: hal_flash.h:107
uint32_t alt
Alternate phase data.
Definition: hal_wspi.h:116
flash_error_t
Type of a flash error code.
Definition: hal_flash.h:70
#define osalDbgCheck(c)
Function parameters check.
Definition: osal.h:278
void bus_stop(BUSDriver *busp)
Stops the underlying bus driver.
uint32_t cmd
Command phase data.
Definition: hal_wspi.h:108
uint32_t flash_offset_t
Type of a flash offset.
Definition: hal_flash.h:83
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.
Definition: hal_wspi.c:281
static const flash_descriptor_t * snor_get_descriptor(void *instance)
Returns a pointer to the device descriptor.
Type of a WSPI command descriptor.
Definition: hal_wspi.h:100
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.
Definition: hal_spi.c:386
void wspiCommand(WSPIDriver *wspip, const wspi_command_t *cmdp)
Sends a command without data phase.
Definition: hal_wspi.c:219
static void bus_release(BUSDriver *busp)
Bus release.
_base_flash_data const SNORConfig * config
Current configuration data.
#define osalDbgAssert(c, remark)
Condition assertion.
Definition: osal.h:258
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.
Definition: hal_wspi.h:104
void spiStop(SPIDriver *spip)
Deactivates the SPI peripheral.
Definition: hal_spi.c:111
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.