1 | /*
|
---|
2 | * TOPPERS/ASP Kernel
|
---|
3 | * Toyohashi Open Platform for Embedded Real-Time Systems/
|
---|
4 | * Advanced Standard Profile Kernel
|
---|
5 | *
|
---|
6 | * Copyright (C) 2008-2011 by Embedded and Real-Time Systems Laboratory
|
---|
7 | * Graduate School of Information Science, Nagoya Univ., JAPAN
|
---|
8 | * Copyright (C) 2015-2017 by TOPPERS PROJECT Educational Working Group.
|
---|
9 | *
|
---|
10 | * 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
|
---|
11 | * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
|
---|
12 | * 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
|
---|
13 | * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
|
---|
14 | * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
|
---|
15 | * スコード中に含まれていること.
|
---|
16 | * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
|
---|
17 | * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
|
---|
18 | * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
|
---|
19 | * の無保証規定を掲載すること.
|
---|
20 | * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
|
---|
21 | * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
|
---|
22 | * と.
|
---|
23 | * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
|
---|
24 | * 作権表示,この利用条件および下記の無保証規定を掲載すること.
|
---|
25 | * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
|
---|
26 | * 報告すること.
|
---|
27 | * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
|
---|
28 | * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
|
---|
29 | * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
|
---|
30 | * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
|
---|
31 | * 免責すること.
|
---|
32 | *
|
---|
33 | * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
|
---|
34 | * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
|
---|
35 | * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
|
---|
36 | * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
|
---|
37 | * の責任を負わない.
|
---|
38 | *
|
---|
39 | * @(#) $Id$
|
---|
40 | */
|
---|
41 | /*
|
---|
42 | *
|
---|
43 | * QSPIデバイスドライバの外部宣言
|
---|
44 | *
|
---|
45 | */
|
---|
46 |
|
---|
47 | #ifndef _QSPI_H_
|
---|
48 | #define _QSPI_H_
|
---|
49 |
|
---|
50 | #ifdef __cplusplus
|
---|
51 | extern "C"
|
---|
52 | {
|
---|
53 | #endif /* __cplusplus */
|
---|
54 |
|
---|
55 | /*
|
---|
56 | * QSPIポート定義
|
---|
57 | */
|
---|
58 | #define QSPI1_PORTID 1
|
---|
59 | #define NUM_QSPIPORT 1
|
---|
60 |
|
---|
61 | /*
|
---|
62 | * フラッシュ・コマンド
|
---|
63 | */
|
---|
64 | #define QSPI_STIG_OPCODE_WR_STAT_REG (0x01)
|
---|
65 | #define QSPI_STIG_OPCODE_PP (0x02)
|
---|
66 | #define QSPI_STIG_OPCODE_READ (0x03)
|
---|
67 | #define QSPI_STIG_OPCODE_WRDIS (0x04)
|
---|
68 | #define QSPI_STIG_OPCODE_RD_STAT_REG (0x05)
|
---|
69 | #define QSPI_STIG_OPCODE_WREN (0x06)
|
---|
70 | #define QSPI_STIG_OPCODE_FASTREAD (0x0B)
|
---|
71 | #define QSPI_DEVSZ_BYTESPERSUBSECTOR_RESET (0x10)
|
---|
72 | #define QSPI_STIG_OPCODE_4BYTE_WRITE (0x12)
|
---|
73 | #define QSPI_STIG_OPCODE_4BYTE_READ (0x13)
|
---|
74 | #define QSPI_STIG_OPCODE_READ_CFG_REG (0x15)
|
---|
75 | #define QSPI_STIG_OPCODE_SUBSEC_ERASE (0x20)
|
---|
76 | #define QSPI_STIG_OPCODE_4BYTE_SEC_ERASE (0x21)
|
---|
77 | #define QSPI_STIG_OPCODE_QUAD_PP (0x32)
|
---|
78 | #define QSPI_STIG_OPCODE_4QUAD_WRITE (0x34)
|
---|
79 | #define QSPI_STIG_OPCODE_ENTER_QUAD_CMD (0x35)
|
---|
80 | #define QSPI_STIG_OPCODE_FASTREAD_DUAL_OUTPUT (0x3B)
|
---|
81 | #define QSPI_STIG_OPCODE_4BYTE_BLOCK_ERASE (0x5C)
|
---|
82 | #define QSPI_STIG_OPCODE_CHIP_ERASE (0x60)
|
---|
83 | #define QSPI_STIG_OPCODE_FASTREAD_QUAD_OUTPUT (0x6B)
|
---|
84 | #define QSPI_STIG_OPCODE_WRITE_VOL_CFG_REG_CMD (0x81)
|
---|
85 | #define QSPI_STIG_OPCODE_READ_VOL_CFG_REG_CMD (0x85)
|
---|
86 | #define QSPI_STIG_OPCODE_RDID (0x9F)
|
---|
87 | #define QSPI_STIG_OPCODE_DUAL_PP (0xA2)
|
---|
88 | #define QSPI_STIG_OPCODE_ENTER_4BYTE_MODE (0xB7)
|
---|
89 | #define QSPI_STIG_OPCODE_FASTREAD_DUAL_IO (0xBB)
|
---|
90 | #define QSPI_STIG_OPCODE_DIE_ERASE (0xC4)
|
---|
91 | #define QSPI_STIG_OPCODE_WR_EXT_REG (0xC5)
|
---|
92 | #define QSPI_STIG_OPCODE_BULK_ERASE (0xC7)
|
---|
93 | #define QSPI_STIG_OPCODE_RD_EXT_REG (0xC8)
|
---|
94 | #define QSPI_STIG_OPCODE_SEC_ERASE (0xD8)
|
---|
95 | #define QSPI_STIG_OPCODE_4BYTE_Q_SEC_ERASE (0xDC)
|
---|
96 | #define QSPI_STIG_OPCODE_EXIT_4BYTE_MODE (0xE9)
|
---|
97 | #define QSPI_STIG_OPCODE_FASTREAD_QUAD_IO (0xEB)
|
---|
98 | #define QSPI_STIG_OPCODE_4QUAD_READ (0xEC)
|
---|
99 |
|
---|
100 | /*
|
---|
101 | * フラッシュコマンド Micron依存
|
---|
102 | */
|
---|
103 | #define QSPI_STIG_OPCODE_N25Q512A_CLRFLGSR (0x50)
|
---|
104 | #define QSPI_STIG_OPCODE_N25Q512A_DISCVR_PARAM (0x5A)
|
---|
105 | #define QSPI_STIG_OPCODE_N25Q128 (0x61)
|
---|
106 | #define QSPI_STIG_REGISTER_N25Q128_VECR (0x65)
|
---|
107 | #define QSPI_STIG_OPCODE_N25Q512A_RESET_EN (0x66)
|
---|
108 | #define QSPI_STIG_OPCODE_N25Q512A_RDFLGSR (0x70)
|
---|
109 | #define QSPI_STIG_OPCODE_N25Q512A_RESET_MEM (0x99)
|
---|
110 |
|
---|
111 | /*
|
---|
112 | * マニュファクチャID
|
---|
113 | */
|
---|
114 | #define QSPI_STIG_RDID_JEDECID_MICRON (0x20)
|
---|
115 | #define QSPI_STIG_RDID_JEDECID_SPANSION (0x01)
|
---|
116 | #define QSPI_STIG_RDID_JEDECID_MACRONIX (0xC2)
|
---|
117 |
|
---|
118 |
|
---|
119 | #define QSPI_MAX_ERASE_CMDS 2
|
---|
120 |
|
---|
121 |
|
---|
122 | /*
|
---|
123 | * QSPI Sample Shifting
|
---|
124 | */
|
---|
125 | #define QSPI_SAMPLE_SHIFTING_NONE 0x00000000 /* No clock cycle shift to sample data */
|
---|
126 | #define QSPI_SAMPLE_SHIFTING_HALFCYCLE QUADSPI_CR_SSHIFT /* 1/2 clock cycle shift to sample data */
|
---|
127 | /**
|
---|
128 | * @}
|
---|
129 | */
|
---|
130 |
|
---|
131 | /*
|
---|
132 | * QSPI ChipSelect High Time
|
---|
133 | */
|
---|
134 | #define QSPI_CS_HIGH_TIME_1_CYCLE 0x00000000 /* nCS stay high for at least 1 clock cycle between commands */
|
---|
135 | #define QSPI_CS_HIGH_TIME_2_CYCLE QUADSPI_DCR_CSHT_0 /* nCS stay high for at least 2 clock cycles between commands */
|
---|
136 | #define QSPI_CS_HIGH_TIME_3_CYCLE QUADSPI_DCR_CSHT_1 /* nCS stay high for at least 3 clock cycles between commands */
|
---|
137 | #define QSPI_CS_HIGH_TIME_4_CYCLE (QUADSPI_DCR_CSHT_0 | QUADSPI_DCR_CSHT_1) /* nCS stay high for at least 4 clock cycles between commands*/
|
---|
138 | #define QSPI_CS_HIGH_TIME_5_CYCLE QUADSPI_DCR_CSHT_2 /* nCS stay high for at least 5 clock cycles between commands */
|
---|
139 | #define QSPI_CS_HIGH_TIME_6_CYCLE (QUADSPI_DCR_CSHT_2 | QUADSPI_DCR_CSHT_0) /* nCS stay high for at least 6 clock cycles between commands*/
|
---|
140 | #define QSPI_CS_HIGH_TIME_7_CYCLE (QUADSPI_DCR_CSHT_2 | QUADSPI_DCR_CSHT_1) /* nCS stay high for at least 7 clock cycles between commands*/
|
---|
141 | #define QSPI_CS_HIGH_TIME_8_CYCLE QUADSPI_DCR_CSHT /* nCS stay high for at least 8 clock cycles between commands */
|
---|
142 |
|
---|
143 | /*
|
---|
144 | * QSPI Clock Mode
|
---|
145 | */
|
---|
146 | #define QSPI_CLOCK_MODE_0 0x00000000 /* Clk stays low while nCS is released */
|
---|
147 | #define QSPI_CLOCK_MODE_3 QUADSPI_DCR_CKMODE /* Clk goes high while nCS is released */
|
---|
148 |
|
---|
149 | /*
|
---|
150 | * QSPI Flash Select
|
---|
151 | */
|
---|
152 | #define QSPI_FLASH_ID_1 0x00000000 /* FLASH 1 selected */
|
---|
153 | #define QSPI_FLASH_ID_2 QUADSPI_CR_FSEL /* FLASH 2 selected */
|
---|
154 |
|
---|
155 | /*
|
---|
156 | * QSPI Dual Flash Mode
|
---|
157 | */
|
---|
158 | #define QSPI_DUALFLASH_DISABLE 0x00000000 /* Dual-flash mode disabled */
|
---|
159 | #define QSPI_DUALFLASH_ENABLE QUADSPI_CR_DFM /* Dual-flash mode enabled */
|
---|
160 |
|
---|
161 | /*
|
---|
162 | * QSPI DDR Mode
|
---|
163 | */
|
---|
164 | #define QSPI_DDR_MODE_DISABLE 0x00000000 /* Double data rate mode disabled */
|
---|
165 | #define QSPI_DDR_MODE_ENABLE QUADSPI_CCR_DDRM /* Double data rate mode enabled */
|
---|
166 |
|
---|
167 | /*
|
---|
168 | * QSPI DDR Data Output Delay
|
---|
169 | */
|
---|
170 | #define QSPI_DDR_HHC_ANALOG_DELAY 0x00000000 /* Delay the data output using analog delay in DDR mode */
|
---|
171 | #ifdef QUADSPI_CCR_DHHC
|
---|
172 | #define QSPI_DDR_HHC_HALF_CLK_DELAY QUADSPI_CCR_DHHC /* Delay the data output by 1/2 clock cycle in DDR mode */
|
---|
173 | #endif
|
---|
174 |
|
---|
175 | /*
|
---|
176 | * QSPI Send Instruction Mode
|
---|
177 | */
|
---|
178 | #define QSPI_SIOO_INST_EVERY_CMD 0x00000000 /* Send instruction on every transaction */
|
---|
179 | #define QSPI_SIOO_INST_ONLY_FIRST_CMD QUADSPI_CCR_SIOO /* Send instruction only for the first command */
|
---|
180 |
|
---|
181 |
|
---|
182 |
|
---|
183 | /*
|
---|
184 | * QSPI Address Size
|
---|
185 | */
|
---|
186 | #define QSPI_ADDRESS_8_BITS 0x00000000 /* 8-bit address*/
|
---|
187 | #define QSPI_ADDRESS_16_BITS QUADSPI_CCR_ADSIZE_0 /* 16-bit address*/
|
---|
188 | #define QSPI_ADDRESS_24_BITS QUADSPI_CCR_ADSIZE_1 /* 24-bit address*/
|
---|
189 | #define QSPI_ADDRESS_32_BITS QUADSPI_CCR_ADSIZE /* 32-bit address*/
|
---|
190 |
|
---|
191 | /*
|
---|
192 | * QSPI Alternate Bytes Size
|
---|
193 | */
|
---|
194 | #define QSPI_ALTERNATE_BYTES_8_BITS 0x00000000 /* 8-bit alternate bytes*/
|
---|
195 | #define QSPI_ALTERNATE_BYTES_16_BITS QUADSPI_CCR_ABSIZE_0 /* 16-bit alternate bytes*/
|
---|
196 | #define QSPI_ALTERNATE_BYTES_24_BITS QUADSPI_CCR_ABSIZE_1 /* 24-bit alternate bytes*/
|
---|
197 | #define QSPI_ALTERNATE_BYTES_32_BITS QUADSPI_CCR_ABSIZE /* 32-bit alternate bytes*/
|
---|
198 |
|
---|
199 | /*
|
---|
200 | * QSPI Instruction Mode
|
---|
201 | */
|
---|
202 | #define QSPI_INSTRUCTION_NONE 0x00000000 /* No instruction*/
|
---|
203 | #define QSPI_INSTRUCTION_1_LINE QUADSPI_CCR_IMODE_0 /* Instruction on a single line*/
|
---|
204 | #define QSPI_INSTRUCTION_2_LINES QUADSPI_CCR_IMODE_1 /* Instruction on two lines*/
|
---|
205 | #define QSPI_INSTRUCTION_4_LINES QUADSPI_CCR_IMODE /* Instruction on four lines*/
|
---|
206 |
|
---|
207 | /*
|
---|
208 | * QSPI Address Mode
|
---|
209 | */
|
---|
210 | #define QSPI_ADDRESS_NONE 0x00000000 /* No address*/
|
---|
211 | #define QSPI_ADDRESS_1_LINE QUADSPI_CCR_ADMODE_0 /* Address on a single line*/
|
---|
212 | #define QSPI_ADDRESS_2_LINES QUADSPI_CCR_ADMODE_1 /* Address on two lines*/
|
---|
213 | #define QSPI_ADDRESS_4_LINES QUADSPI_CCR_ADMODE /* Address on four lines*/
|
---|
214 |
|
---|
215 | /*
|
---|
216 | * QSPI Alternate Bytes Mode
|
---|
217 | */
|
---|
218 | #define QSPI_ALTERNATE_BYTES_NONE 0x00000000 /* No alternate bytes*/
|
---|
219 | #define QSPI_ALTERNATE_BYTES_1_LINE QUADSPI_CCR_ABMODE_0 /* Alternate bytes on a single line*/
|
---|
220 | #define QSPI_ALTERNATE_BYTES_2_LINES QUADSPI_CCR_ABMODE_1 /* Alternate bytes on two lines*/
|
---|
221 | #define QSPI_ALTERNATE_BYTES_4_LINES QUADSPI_CCR_ABMODE /* Alternate bytes on four lines*/
|
---|
222 |
|
---|
223 | /*
|
---|
224 | * QSPI Data Mode
|
---|
225 | */
|
---|
226 | #define QSPI_DATA_NONE 0x00000000 /* No data */
|
---|
227 | #define QSPI_DATA_1_LINE QUADSPI_CCR_DMODE_0 /* Data on a single line */
|
---|
228 | #define QSPI_DATA_2_LINES QUADSPI_CCR_DMODE_1 /* Data on two lines */
|
---|
229 | #define QSPI_DATA_4_LINES QUADSPI_CCR_DMODE /* Data on four lines */
|
---|
230 |
|
---|
231 |
|
---|
232 | /*
|
---|
233 | * QSPI Match Mode
|
---|
234 | */
|
---|
235 | #define QSPI_MATCH_MODE_AND 0x00000000 /* AND match mode between unmasked bits */
|
---|
236 | #define QSPI_MATCH_MODE_OR QUADSPI_CR_PMM /* OR match mode between unmasked bits*/
|
---|
237 |
|
---|
238 | /*
|
---|
239 | * QSPI Automatic Stop
|
---|
240 | */
|
---|
241 | #define QSPI_AUTOMATIC_STOP_DISABLE 0x00000000 /* AutoPolling stops only with abort or QSPI disabling*/
|
---|
242 | #define QSPI_AUTOMATIC_STOP_ENABLE QUADSPI_CR_APMS /* AutoPolling stops as soon as there is a match*/
|
---|
243 |
|
---|
244 |
|
---|
245 | /*
|
---|
246 | * QSPI ステータス
|
---|
247 | */
|
---|
248 | #define QSPI_STATUS_RESET 0x00000000 /* Peripheral not initialized */
|
---|
249 | #define QSPI_STATUS_READY 0x00000001 /* Peripheral initialized and ready for use */
|
---|
250 | #define QSPI_STATUS_BUSY 0x00000002 /* Peripheral in indirect mode and busy */
|
---|
251 | #define QSPI_STATUS_BUSY_TX 0x00000012 /* Peripheral in indirect mode with transmission ongoing */
|
---|
252 | #define QSPI_STATUS_BUSY_RX 0x00000022 /* Peripheral in indirect mode with reception ongoing */
|
---|
253 | #define QSPI_STATUS_BUSY_AP 0x00000042 /* Peripheral in auto polling mode ongoing */
|
---|
254 | #define QSPI_STATUS_BUSY_MM 0x00000082 /* Peripheral in memory mapped mode ongoing */
|
---|
255 | #define QSPI_STATUS_ABORT 0x00010000 /* Peripheral with abort request ongoing */
|
---|
256 | #define QSPI_STATUS_ERROR 0x00020000 /* Peripheral in error */
|
---|
257 |
|
---|
258 | /*
|
---|
259 | * QSPIエラー
|
---|
260 | */
|
---|
261 | #define QSPI_ERROR_NONE 0x00000000 /* No error */
|
---|
262 | #define QSPI_ERROR_TRANERR 0x00000002 /* transfer error */
|
---|
263 | #define QSPI_ERROR_TIMEOUT 0x00001000 /* Timeout */
|
---|
264 |
|
---|
265 |
|
---|
266 |
|
---|
267 | /*
|
---|
268 | * QSPIハードウェア設定構造体
|
---|
269 | */
|
---|
270 | typedef struct _QSPI_PortControlBlock{
|
---|
271 | uint32_t base;
|
---|
272 | uint32_t gioclockbase;
|
---|
273 |
|
---|
274 | uint32_t giocsclockbit;
|
---|
275 | uint32_t giocsbase;
|
---|
276 | uint32_t giocspin;
|
---|
277 | uint32_t giocsaf;
|
---|
278 | uint32_t gioclkclockbit;
|
---|
279 | uint32_t gioclkbase;
|
---|
280 | uint32_t gioclkpin;
|
---|
281 | uint32_t gioclkaf;
|
---|
282 | uint32_t giod0clockbit;
|
---|
283 | uint32_t giod0base;
|
---|
284 | uint32_t giod0pin;
|
---|
285 | uint32_t giod0af;
|
---|
286 | uint32_t giod1clockbit;
|
---|
287 | uint32_t giod1base;
|
---|
288 | uint32_t giod1pin;
|
---|
289 | uint32_t giod1af;
|
---|
290 | uint32_t giod2clockbit;
|
---|
291 | uint32_t giod2base;
|
---|
292 | uint32_t giod2pin;
|
---|
293 | uint32_t giod2af;
|
---|
294 | uint32_t giod3clockbit;
|
---|
295 | uint32_t giod3base;
|
---|
296 | uint32_t giod3pin;
|
---|
297 | uint32_t giod3af;
|
---|
298 | } QSPI_PortControlBlock;
|
---|
299 |
|
---|
300 |
|
---|
301 | typedef ER (*QSPI_INIT_FUNC_T)(void *h);
|
---|
302 | typedef ER (*QSPI_EWRI_FUNC_T)(void *h, uint32_t timeout);
|
---|
303 | typedef ER (*QSPI_WAIT_FUNC_T)(void *h, uint32_t timeout);
|
---|
304 |
|
---|
305 | /*
|
---|
306 | * QSPIデバイス設定構造体
|
---|
307 | */
|
---|
308 | typedef struct QSPI_Init
|
---|
309 | {
|
---|
310 | uint16_t manuf_id;
|
---|
311 | uint16_t type_capacity;
|
---|
312 | uint32_t clockprescaler; /* prescaler factor for generating clock based on the AHB clock. */
|
---|
313 | uint32_t fifothreshold; /* threshold number of bytes in the FIFO (used only in indirect mode) */
|
---|
314 | uint32_t sampleshift; /* Sample Shift. The data is sampled 1/2 clock cycle delay later to take in account external signal delays */
|
---|
315 | uint32_t chipselecthightime; /* Chip Select High Time. */
|
---|
316 | uint32_t clockmode; /* the Clock Mode. It indicates the level that clock takes between commands. */
|
---|
317 | uint32_t flashid; /* the FlashID */
|
---|
318 | uint32_t dualflash; /* the Dual Flash Mode State */
|
---|
319 | uint32_t ddrmode;
|
---|
320 | uint32_t ddrholdhalfcycle;
|
---|
321 | uint32_t sioomode;
|
---|
322 | uint32_t addr_size;
|
---|
323 | uint32_t inst_type;
|
---|
324 | uint32_t inst_data_xfer_type;
|
---|
325 | uint32_t read_op_code;
|
---|
326 | uint32_t read_addr_xfer_type;
|
---|
327 | uint32_t read_data_xfer_type;
|
---|
328 | uint32_t read_dummy_cycles;
|
---|
329 | uint32_t write_op_code;
|
---|
330 | uint32_t write_addr_xfer_type;
|
---|
331 | uint32_t write_data_xfer_type;
|
---|
332 | uint32_t write_dummy_cycles;
|
---|
333 | uint8_t erase_count;
|
---|
334 | uint32_t erase_sizes[QSPI_MAX_ERASE_CMDS];
|
---|
335 | uint8_t erase_cmds[QSPI_MAX_ERASE_CMDS];
|
---|
336 | uint32_t erase_addr_xfer_type;
|
---|
337 | uint8_t erase_sector_idx;
|
---|
338 | uint32_t device_size;
|
---|
339 | QSPI_INIT_FUNC_T init_func;
|
---|
340 | QSPI_EWRI_FUNC_T enable_write_func;
|
---|
341 | QSPI_WAIT_FUNC_T wait_func;
|
---|
342 | const char *friendly_name;
|
---|
343 | } QSPI_Init_t;
|
---|
344 |
|
---|
345 | /*
|
---|
346 | * QSPIコマンド定義型
|
---|
347 | */
|
---|
348 | typedef struct
|
---|
349 | {
|
---|
350 | uint32_t InstructionMode; /* the Instruction Mode */
|
---|
351 | uint32_t Instruction; /* the Instruction to be sent */
|
---|
352 | uint32_t AddressMode; /* the Address Mode */
|
---|
353 | uint32_t AddressSize; /* the Address Size */
|
---|
354 | uint32_t Address; /* the Address to be sent (Size from 1 to 4 bytes according AddressSize) */
|
---|
355 | uint32_t AlternateByteMode; /* the Alternate Bytes Mode */
|
---|
356 | uint32_t AlternateBytesSize; /* the Alternate Bytes Size */
|
---|
357 | uint32_t AlternateBytes; /* the Alternate Bytes to be sent (Size from 1 to 4 bytes according AlternateBytesSize) */
|
---|
358 | uint32_t DummyCycles; /* the Number of Dummy Cycles. */
|
---|
359 | uint32_t DataMode; /* the Data Mode (used for dummy cycles and data phases) */
|
---|
360 | uint32_t NbData; /* the number of data to transfer. (This is the number of bytes) */
|
---|
361 | } QSPI_Command_t;
|
---|
362 |
|
---|
363 | /*
|
---|
364 | * QSPIオートポーリング型
|
---|
365 | */
|
---|
366 | typedef struct
|
---|
367 | {
|
---|
368 | uint32_t Match; /* the value to be compared with the masked status register to get a match. */
|
---|
369 | uint32_t Mask; /* the mask to be applied to the status bytes received. */
|
---|
370 | uint32_t Interval; /* the number of clock cycles between two read during automatic polling phases. */
|
---|
371 | uint32_t StatusBytesSize; /* the size of the status bytes received. */
|
---|
372 | uint32_t MatchMode; /* the method used for determining a match. */
|
---|
373 | uint32_t AutomaticStop; /* if automatic polling is stopped after a match. */
|
---|
374 | } QSPI_AutoPolling_t;
|
---|
375 |
|
---|
376 | /*
|
---|
377 | * QSPIデバイスハンドラ定義
|
---|
378 | */
|
---|
379 | typedef struct _QSPI_Handle_t QSPI_Handle_t;
|
---|
380 | struct _QSPI_Handle_t
|
---|
381 | {
|
---|
382 | uint32_t base; /* QSPI レジスタベースアドレス */
|
---|
383 | QSPI_Init_t Init; /* QSPI FLASHデータ */
|
---|
384 | uint32_t *pBuffPtr; /* QSPI 通信バッファへのポインタ */
|
---|
385 | uint32_t XferSize; /* QSPI 通信サイズ */
|
---|
386 | volatile uint32_t XferCount; /* QSPI 通信カウンタ */
|
---|
387 | void (*timeoutcallback)(QSPI_Handle_t * hqspi); /* タイムアウトコールバック関数 */
|
---|
388 | void (*errorcallback)(QSPI_Handle_t * hqspi); /* エラーコールバック関数 */
|
---|
389 | volatile uint32_t istatus; /* QSPI 割込みステータス */
|
---|
390 | uint32_t timeout; /* QSPI タイムアウト値(ms) */
|
---|
391 | int semid; /* QSPI 通信用セマフォ値 */
|
---|
392 | uint32_t status; /* QSPI ステータス */
|
---|
393 | volatile uint32_t errorcode; /* QSPI エラーコード */
|
---|
394 | };
|
---|
395 |
|
---|
396 | extern QSPI_Handle_t *qspi_init(ID portid, QSPI_Init_t *pini);
|
---|
397 | extern ER qspi_deinit(QSPI_Handle_t *hqspi);
|
---|
398 | extern ER qspi_read(QSPI_Handle_t *hqspi, void * dest, uint32_t src, uint32_t size);
|
---|
399 | extern ER qspi_write(QSPI_Handle_t *hqspi, uint32_t dest, const void * src, uint32_t size);
|
---|
400 | extern ER qspi_erase(QSPI_Handle_t *hqspi, uint32_t address, uint32_t size);
|
---|
401 | extern ER qspi_erase_sector(QSPI_Handle_t *hqspi, uint32_t address);
|
---|
402 | extern ER qspi_direct_disable(QSPI_Handle_t *hqspi);
|
---|
403 | extern ER qspi_direct_enable(QSPI_Handle_t *hqspi);
|
---|
404 | extern void qspi_handler(QSPI_Handle_t *hqspi);
|
---|
405 | extern void qspi_isr(intptr_t exinf);
|
---|
406 |
|
---|
407 | /*
|
---|
408 | * CHIP消去
|
---|
409 | * parameter1 hqspi QSPIハンドラへのポインタ
|
---|
410 | * return 正常終了時、E_OK
|
---|
411 | */
|
---|
412 | #define qspi_erase_chip(h) qspi_erase(h, 0, (h)->Init.device_size)
|
---|
413 |
|
---|
414 |
|
---|
415 | /*
|
---|
416 | * セクターサイズを取り出す
|
---|
417 | * parameter1 hqspi QSPIハンドラへのポインタ
|
---|
418 | * return セクターバイトサイズ
|
---|
419 | */
|
---|
420 | #define get_smallest_sector_size(h) (h)->Init.erase_sizes[(h)->Init.erase_sector_idx]
|
---|
421 |
|
---|
422 |
|
---|
423 | /*
|
---|
424 | * デバイスサイズを取り出す
|
---|
425 | * parameter1 hqspi QSPIハンドラへのポインタ
|
---|
426 | * return デバイスバイトサイズ
|
---|
427 | */
|
---|
428 | #define qspi_get_device_size(h) (h)->Init.device_size;
|
---|
429 |
|
---|
430 | extern ER qspi_command(QSPI_Handle_t *hqspi, QSPI_Command_t *cmd, uint32_t Timeout);
|
---|
431 | extern ER qspi_autopolling(QSPI_Handle_t *hqspi, QSPI_Command_t *cmd, QSPI_AutoPolling_t *cfg, uint32_t Timeout);
|
---|
432 | extern ER qspi_transmit(QSPI_Handle_t *hqspi, uint32_t *pData, uint32_t Timeout);
|
---|
433 | extern ER qspi_receive(QSPI_Handle_t *hqspi, uint32_t *pData, uint32_t Timeout);
|
---|
434 |
|
---|
435 |
|
---|
436 | #ifdef __cplusplus
|
---|
437 | }
|
---|
438 | #endif /* __cplusplus */
|
---|
439 |
|
---|
440 | #endif /* _QSPI_H_ */
|
---|
441 |
|
---|