ChibiOS/HAL 9.0.0
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 * @brief Size of the buffer for internal operations.
44 */
45#define SNOR_BUFFER_SIZE 32
46
47/*===========================================================================*/
48/* Driver pre-compile time settings. */
49/*===========================================================================*/
50
51/**
52 * @name Configuration options
53 * @{
54 */
55/**
56 * @brief Physical transport interface.
57 */
58#if !defined(SNOR_BUS_DRIVER) || defined(__DOXYGEN__)
59#define SNOR_BUS_DRIVER SNOR_BUS_DRIVER_WSPI
60#endif
61
62/**
63 * @brief Shared bus switch.
64 * @details If set to @p TRUE the device acquires bus ownership
65 * on each transaction.
66 * @note Requires @p SPI_USE_MUTUAL_EXCLUSION or
67 * @p WSPI_USE_MUTUAL_EXCLUSION depending on mode selected
68 * with @p SNOR_BUS_MODE.
69 */
70#if !defined(SNOR_SHARED_BUS) || defined(__DOXYGEN__)
71#define SNOR_SHARED_BUS TRUE
72#endif
73
74/**
75 * @brief Exclusive access control.
76 * @note Disabling this option saves both code and data space.
77 */
78#if !defined(SNOR_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
79#define SNOR_USE_MUTUAL_EXCLUSION TRUE
80#endif
81
82/**
83 * @brief SPI 4-bytes address switch
84 * @details If set to @p TRUE the device will use 4-bytes address
85 * in SPI bus, only relevant if SPI is used
86 */
87#if !defined(SNOR_SPI_4BYTES_ADDRESS) || defined(__DOXYGEN__)
88#define SNOR_SPI_4BYTES_ADDRESS FALSE
89#endif
90/** @} */
91
92/*===========================================================================*/
93/* Derived constants and error checks. */
94/*===========================================================================*/
95
96#if (SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_SPI) || defined(__DOXYGEN__)
97#define BUSConfig SPIConfig
98#define BUSDriver SPIDriver
99#elif SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI
100#define BUSConfig WSPIConfig
101#define BUSDriver WSPIDriver
102#else
103#error "invalid SNOR_BUS_DRIVER setting"
104#endif
105
106/*===========================================================================*/
107/* Driver data structures and types. */
108/*===========================================================================*/
109
110/**
111 * @brief Type of a SNOR configuration structure.
112 */
113typedef struct {
116} SNORConfig;
117
118/**
119 * @brief @p SNORDriver specific methods.
120 */
121#define _snor_flash_methods_alone \
122 /* Read SFDP.*/ \
123 flash_error_t (*read_sfdp)(void *instance, \
124 flash_offset_t offset, \
125 size_t n, \
126 uint8_t *rp);
127
128/**
129 * @brief @p SNORDriver specific methods with inherited ones.
130 */
131#define _snor_flash_methods \
132 _base_flash_methods \
133 _snor_flash_methods_alone
134
135/**
136 * @extends BaseFlashVMT
137 *
138 * @brief @p SNOR virtual methods table.
139 */
143
144typedef struct snor_nocache_buffer {
145 /**
146 * @brief Temporary generic buffer.
147 */
149#if (SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI) || defined(__DOXYGEN__)
150 /**
151 * @brief Temporary command buffer.
152 */
154#endif
156
157/**
158 * @extends BaseFlash
159 *
160 * @brief Type of SNOR flash class.
161 */
162typedef struct {
163 /**
164 * @brief SNORDriver Virtual Methods Table.
165 */
166 const struct SNORDriverVMT *vmt;
168 /**
169 * @brief Current configuration data.
170 */
172 /**
173 * @brief Non-cacheable buffer associated to this instance.
174 */
176#if (SNOR_USE_MUTUAL_EXCLUSION == TRUE) || defined(__DOXYGEN__)
177 /**
178 * @brief Mutex protecting SNOR.
179 */
181#endif /* EFL_USE_MUTUAL_EXCLUSION == TRUE */
182} SNORDriver;
183
184/*===========================================================================*/
185/* Driver macros. */
186/*===========================================================================*/
187
188#if SNOR_SHARED_BUS == FALSE
189#define bus_acquire(busp, config)
190#define bus_release(busp)
191#endif
192
193/*===========================================================================*/
194/* External declarations. */
195/*===========================================================================*/
196
197#ifdef __cplusplus
198extern "C" {
199#endif
200#if SNOR_SHARED_BUS == TRUE
201 void bus_acquire(BUSDriver *busp, const BUSConfig *config);
202 void bus_release(BUSDriver *busp);
203#endif
204 void bus_cmd(BUSDriver *busp, uint32_t cmd);
205 void bus_cmd_send(BUSDriver *busp, uint32_t cmd, size_t n, const uint8_t *p);
206 void bus_cmd_receive(BUSDriver *busp,
207 uint32_t cmd,
208 size_t n,
209 uint8_t *p);
210 void bus_cmd_addr(BUSDriver *busp, uint32_t cmd, flash_offset_t offset);
211 void bus_cmd_addr_send(BUSDriver *busp,
212 uint32_t cmd,
213 flash_offset_t offset,
214 size_t n,
215 const uint8_t *p);
217 uint32_t cmd,
218 flash_offset_t offset,
219 size_t n,
220 uint8_t *p);
222 uint32_t cmd,
223 uint32_t dummy,
224 size_t n,
225 uint8_t *p);
227 uint32_t cmd,
228 flash_offset_t offset,
229 uint32_t dummy,
230 size_t n,
231 uint8_t *p);
232 void snorObjectInit(SNORDriver *devp, snor_nocache_buffer_t *nocache);
233 void snorStart(SNORDriver *devp, const SNORConfig *config);
234 void snorStop(SNORDriver *devp);
235#if (SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI) || defined(__DOXYGEN__)
236#if (WSPI_SUPPORTS_MEMMAP == TRUE) || defined(__DOXYGEN__)
237 void snorMemoryMap(SNORDriver *devp, uint8_t ** addrp);
238 void snorMemoryUnmap(SNORDriver *devp);
239#endif /* QSPI_SUPPORTS_MEMMAP == TRUE */
240#endif /* SNOR_BUS_MODE != SNOR_BUS_MODE_SPI */
241#ifdef __cplusplus
242}
243#endif
244
245/* Device-specific implementations.*/
246#include "hal_flash_device.h"
247
248#endif /* HAL_SERIAL_NOR_H */
249
250/** @} */
251
#define _base_flash_data
BaseFlash specific data.
Definition hal_flash.h:214
uint32_t flash_offset_t
Type of a flash offset.
Definition hal_flash.h:112
void bus_cmd(BUSDriver *busp, uint32_t cmd)
Sends a naked command.
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.
#define BUSConfig
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 snorStop(SNORDriver *devp)
Deactivates the SNOR driver.
#define bus_acquire(busp, config)
void snorStart(SNORDriver *devp, const SNORConfig *config)
Configures and activates SNOR driver.
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.
#define bus_release(busp)
#define BUSDriver
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 snorMemoryUnmap(SNORDriver *devp)
Leaves the memory Mapping mode.
void bus_cmd_addr(BUSDriver *busp, uint32_t cmd, flash_offset_t offset)
Sends a command followed by a flash address.
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 snorMemoryMap(SNORDriver *devp, uint8_t **addrp)
Enters 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.
struct snor_nocache_buffer snor_nocache_buffer_t
#define _snor_flash_methods
SNORDriver specific methods with inherited ones.
#define SNOR_BUFFER_SIZE
Size of the buffer for internal operations.
void snorObjectInit(SNORDriver *devp, snor_nocache_buffer_t *nocache)
Initializes an instance.
uint32_t mutex_t
Type of a mutex.
Definition osal.h:229
Generic flash driver class header.
Type of a SNOR configuration structure.
BUSDriver * busp
const BUSConfig * buscfg
Type of SNOR flash class.
const struct SNORDriverVMT * vmt
SNORDriver Virtual Methods Table.
mutex_t mutex
Mutex protecting SNOR.
snor_nocache_buffer_t * nocache
Non-cacheable buffer associated to this instance.
_base_flash_data const SNORConfig * config
Current configuration data.
SNOR virtual methods table.
wspi_command_t cmd
Temporary command buffer.
uint8_t buf[SNOR_BUFFER_SIZE]
Temporary generic buffer.
Type of a WSPI command descriptor.
Definition hal_wspi.h:101