ChibiOS/HAL  7.0.3
hal_serial_nor.h
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.h
19  * @brief Serial NOR driver header.
20  *
21  * @addtogroup HAL_SERIAL_NOR
22  * @{
23  */
24 
25 #ifndef HAL_SERIAL_NOR_H
26 #define HAL_SERIAL_NOR_H
27 
28 #include "hal_flash.h"
29 
30 /*===========================================================================*/
31 /* Driver constants. */
32 /*===========================================================================*/
33 
34 /**
35  * @name Bus interface modes.
36  * @{
37  */
38 #define SNOR_BUS_DRIVER_SPI 0U
39 #define SNOR_BUS_DRIVER_WSPI 1U
40 /** @} */
41 
42 /*===========================================================================*/
43 /* Driver pre-compile time settings. */
44 /*===========================================================================*/
45 
46 /**
47  * @name Configuration options
48  * @{
49  */
50 /**
51  * @brief Physical transport interface.
52  */
53 #if !defined(SNOR_BUS_DRIVER) || defined(__DOXYGEN__)
54 #define SNOR_BUS_DRIVER SNOR_BUS_DRIVER_WSPI
55 #endif
56 
57 /**
58  * @brief Shared bus switch.
59  * @details If set to @p TRUE the device acquires bus ownership
60  * on each transaction.
61  * @note Requires @p SPI_USE_MUTUAL_EXCLUSION or
62  * @p WSPI_USE_MUTUAL_EXCLUSION depending on mode selected
63  * with @p SNOR_BUS_MODE.
64  */
65 #if !defined(SNOR_SHARED_BUS) || defined(__DOXYGEN__)
66 #define SNOR_SHARED_BUS TRUE
67 #endif
68 /** @} */
69 
70 /*===========================================================================*/
71 /* Derived constants and error checks. */
72 /*===========================================================================*/
73 
74 #if (SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_SPI) || defined(__DOXYGEN__)
75 #define BUSConfig SPIConfig
76 #define BUSDriver SPIDriver
77 #elif SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI
78 #define BUSConfig WSPIConfig
79 #define BUSDriver WSPIDriver
80 #else
81 #error "invalid SNOR_BUS_DRIVER setting"
82 #endif
83 
84 /*===========================================================================*/
85 /* Driver data structures and types. */
86 /*===========================================================================*/
87 
88 /**
89  * @brief Type of a SNOR configuration structure.
90  */
91 typedef struct {
92  BUSDriver *busp;
93  const BUSConfig *buscfg;
94 } SNORConfig;
95 
96 /**
97  * @brief @p SNORDriver specific methods.
98  */
99 #define _snor_flash_methods_alone \
100  /* Read SFDP.*/ \
101  flash_error_t (*read_sfdp)(void *instance, \
102  flash_offset_t offset, \
103  size_t n, \
104  uint8_t *rp);
105 
106 /**
107  * @brief @p SNORDriver specific methods with inherited ones.
108  */
109 #define _snor_flash_methods \
110  _base_flash_methods \
111  _snor_flash_methods_alone
112 
113 /**
114  * @extends BaseFlashVMT
115  *
116  * @brief @p SNOR virtual methods table.
117  */
120 };
121 
122 /**
123  * @extends BaseFlash
124  *
125  * @brief Type of SNOR flash class.
126  */
127 typedef struct {
128  /**
129  * @brief SNORDriver Virtual Methods Table.
130  */
131  const struct SNORDriverVMT *vmt;
133  /**
134  * @brief Current configuration data.
135  */
137  /**
138  * @brief Device ID and unique ID.
139  */
140  uint8_t device_id[20];
141 } SNORDriver;
142 
143 /*===========================================================================*/
144 /* Driver macros. */
145 /*===========================================================================*/
146 
147 /*===========================================================================*/
148 /* External declarations. */
149 /*===========================================================================*/
150 
151 #ifdef __cplusplus
152 extern "C" {
153 #endif
154  void bus_cmd(BUSDriver *busp, uint32_t cmd);
155  void bus_cmd_send(BUSDriver *busp, uint32_t cmd, size_t n, const uint8_t *p);
156  void bus_cmd_receive(BUSDriver *busp,
157  uint32_t cmd,
158  size_t n,
159  uint8_t *p);
160  void bus_cmd_addr(BUSDriver *busp, uint32_t cmd, flash_offset_t offset);
161  void bus_cmd_addr_send(BUSDriver *busp,
162  uint32_t cmd,
163  flash_offset_t offset,
164  size_t n,
165  const uint8_t *p);
166  void bus_cmd_addr_receive(BUSDriver *busp,
167  uint32_t cmd,
168  flash_offset_t offset,
169  size_t n,
170  uint8_t *p);
171 #if (SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI) || defined(__DOXYGEN__)
172  void bus_cmd_dummy_receive(BUSDriver *busp,
173  uint32_t cmd,
174  uint32_t dummy,
175  size_t n,
176  uint8_t *p);
177  void bus_cmd_addr_dummy_receive(BUSDriver *busp,
178  uint32_t cmd,
179  flash_offset_t offset,
180  uint32_t dummy,
181  size_t n,
182  uint8_t *p);
183 #endif
184  void snorObjectInit(SNORDriver *devp);
185  void snorStart(SNORDriver *devp, const SNORConfig *config);
186  void snorStop(SNORDriver *devp);
187 #if (SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI) || defined(__DOXYGEN__)
188 #if (WSPI_SUPPORTS_MEMMAP == TRUE) || defined(__DOXYGEN__)
189  void snorMemoryMap(SNORDriver *devp, uint8_t ** addrp);
190  void snorMemoryUnmap(SNORDriver *devp);
191 #endif /* QSPI_SUPPORTS_MEMMAP == TRUE */
192 #endif /* SNOR_BUS_MODE != SNOR_BUS_MODE_SPI */
193 #ifdef __cplusplus
194 }
195 #endif
196 
197 /* Device-specific implementations.*/
198 #include "hal_flash_device.h"
199 
200 #endif /* HAL_SERIAL_NOR_H */
201 
202 /** @} */
203 
void bus_cmd(BUSDriver *busp, uint32_t cmd)
Sends a naked command.
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 bus_cmd_addr(BUSDriver *busp, uint32_t cmd, flash_offset_t offset)
Sends a command followed by a flash address.
#define _base_flash_data
BaseFlash specific data.
Definition: hal_flash.h:177
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.
const struct SNORDriverVMT * vmt
SNORDriver Virtual Methods Table.
void snorStart(SNORDriver *devp, const SNORConfig *config)
Configures and activates SNOR driver.
void snorStop(SNORDriver *devp)
Deactivates the SNOR driver.
Type of a SNOR configuration structure.
void snorObjectInit(SNORDriver *devp)
Initializes an instance.
uint32_t flash_offset_t
Type of a flash offset.
Definition: hal_flash.h:83
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.
Generic flash driver class header.
_base_flash_data const SNORConfig * config
Current configuration data.
#define _snor_flash_methods
SNORDriver specific methods with inherited ones.
void snorMemoryMap(SNORDriver *devp, uint8_t **addrp)
Enters the memory Mapping mode.
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.
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.