EVE 1.0
spi-memory.h
Go to the documentation of this file.
1 #ifndef DRIVER_SPI_MEMORY_H
2 #define DRIVER_SPI_MEMORY_H
3 /**********************************************************************/
4 /*
5  * Copyright (c) 2013-2015, Jetro AS
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without modification,
9  * are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote products
17  * derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONRIBUTORS ``AS IS'' AND ANY EXPRESS
20  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
22  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
28  * OF SUCH DAMAGE.
29  *
30  * This file is part of the EVE platform.
31  */
32 
33 /**
34  * \file
35  * @brief Driver for SPI-based memories.
36  *
37  * @author KLO, Jetro AS
38  */ /******************************************************************/
39 
40 #include <dev/spi.h>
41 #include <dev/eve-module.h>
42 
43 /**
44  * \defgroup spimem SPI-based memory driver
45  * \ingroup abstract
46  * \{
47  *
48  * This SPI Memory driver can be used for FLASH, EEPROM and SRAM configuration.
49  *
50  * The configuration data is of type struct spi_memory_t, and is used to
51  * configure used memory.
52  *
53  */
54 
55 /***********************************************************************
56  * Global defines
57 ***********************************************************************/
58 #define SPI_MEMORY_HINT_GENERIC 0 /**< No special handling is needed */
59 #define SPI_MEMORY_HINT_GENERIC_SRAM 1 /**< RAM status register is programmed for sequential access */
60 
61 #define SPI_MEMORY_DATA_BUFFER_COMMAND_SIZE 4 /**< Asynchronous data buffer header (command) size */
62 
63 struct spi_memory_t;
65 
66 /**
67  * Asynchronous callback type
68  *
69  * @param Memory Pointer to the SPI memory instance object
70  * @param BufferHeader Pointer to the header of the buffer object. To be up-casted to the target type by container_of.
71  */
72 typedef void (* spi_memory_completion_callback_t)(const struct spi_memory_t *Memory,
73  struct spi_memory_data_buffer_header *BufferHeader);
74 
75 struct spi_memory_state_t
76 {
77  spi_memory_completion_callback_t CompletionCallback;
78  struct spi_memory_data_buffer_header *AsyncTransfer;
79 };
80 
81 /**
82  * spi_memory_t structure is used for configuration of SPI-based memory.
83  * The structure must be initialized before the memory driver may be used.
84  *
85  */
87 {
88  const struct spi_t *Spi; /**< SPI instance */
89  struct spi_memory_state_t *State; /**< Pointer to the dynamic SPI memory state */
90  struct spi_cs_t ChipSelect; /**< Chip select */
91  uint32_t Baudrate; /**< Baudrate */
92  uint8_t MemorySizeExponent; /**< Exponent for memory size (example value 15: 2^15 = 32768) */
93  uint8_t PageSizeExponent; /**< Exponent for page size */
94  uint8_t SectorSizeExponent; /**< Exponent for sector size */
95  uint8_t BlockSizeExponent; /**< Exponent for block size */
96  uint32_t AddressBytes : 3; /**< Number of bytes in the address */
97  uint32_t HasPowerControl : 1; /**< true if memory has power down instruction */
98  uint32_t HasProtection : 1; /**< true if memory has protection bits */
99  uint32_t HasChipErase : 1; /**< true if memory has chip erase instruction */
100  uint32_t HasWriteEnable : 1; /**< true if memory has write enable instruction */
101  uint32_t HasProgrammingTime : 1; /**< true if memory needs programming time after a programming instruction */
102  uint32_t HasPowerPort : 1; /**< true if memory power pin is controlled by external power switch */
103  uint32_t Reserved1 : 3;
104  uint32_t PowerPin : 5; /**< If HasPowerPort = true: Set port pin (0 - 31) */
105  uint32_t PowerActiveHigh : 1; /**< If HasPowerPort = true: Set true if PowerPin is active high, else false */
106  uint32_t Reserved2 : 6;
107  uint32_t Hint : 8; /**< != 0 if memory need special program */
108  uint16_t EnterPdTimeUs; /**< Time needed to enter power down (us) */
109  uint16_t ReleasePdTimeAfterCommandUs; /**< Time needed to release from power down after release command (us) */
110  uint16_t ReleasePdTimeAfterCsActiveUs; /**< Time needed to release from power down after chip select active (us) */
111  uint16_t VccPowerUpTimeUs; /**< If HasPowerPort = true: Time needed after PowerPin is active (us) */
112  uint8_t PowerUpTimeMs; /**< Time needed after power on (ms) */
113 };
114 
115 /**
116  * spi_memory_data_buffer_header structure represents a buffer for SPI command exchange towards memory chip.
117  * Asynchronous data transfer functions use the buffer as a storage for the 'command' part of the SPI message.
118  */
120 {
121  uint8_t Command[SPI_MEMORY_DATA_BUFFER_COMMAND_SIZE]; /**< Command buffer */
122 };
123 
124 /**
125  * Defines a new type for the asynchronous SPI memory buffer of the desired size.
126  *
127  * @param type Typename of the newly created type.
128  * @param size Amount of bytes in the 'data' part of the message.
129  */
130 #define SPI_MEMORY_DATA_BUFFER_TYPE(type, size) \
131  typedef struct type \
132  { \
133  struct spi_memory_data_buffer_header Header; \
134  uint8_t Data[(size)]; \
135  } type
136 
137 /**
138  * Defines a type for a generic buffer with unknown size.
139  */
140 SPI_MEMORY_DATA_BUFFER_TYPE(spi_memory_generic_buffer_t, 0);
141 
142  /**
143  * @name Functions called from application programs
144  * @{
145  */
146 
147 /**********************************************************************/
148 /**
149  * @brief Name: SpiMemoryInit\n
150  * Waits for power on and then release SPI memory from deep powerdown. KŲ!! ????????????
151  * Called from main program level.
152  *
153  * @param Memory Pointer to the SPI memory instance object
154  * @return true if SPI memory was initialized, else false
155  ***********************************************************************/
156 extern bool SpiMemoryInit(const struct spi_memory_t *Memory);
157 
158 /**********************************************************************/
159 /**
160  * @brief Name: SpiMemoryDisable\n
161  * Sets SPI memory in deep powerdown.
162  * Called from main program level.
163  *
164  * @param Memory Pointer to the SPI memory instance object
165  * @return true if SPI memory was set disabled, else false
166  ***********************************************************************/
167 extern bool SpiMemoryDisable(const struct spi_memory_t *Memory);
168 
169 /**********************************************************************/
170 /**
171  * @brief Name: SpiMemorySetWriteProtection\n
172  * Sets write protection for SPI memory and waits for completion.
173  * Called from main program level.
174  *
175  * @param Memory Pointer to the SPI memory instance object
176  * @param Protection Parameters for protection to be used
177  * @return true if SPI memory protection was set properly, else false
178  ***********************************************************************/
179 extern bool SpiMemorySetWriteProtection(const struct spi_memory_t *Memory,
180  enum spi_memory_protection_t Protection);
181 
182 /**********************************************************************/
183 /**
184  * @brief Name: SpiMemoryEraseSectorAsync\n
185  * Begines erasing given sector in SPI memory.
186  * Called from main program level.
187  * At function return SPI transfer is completed; erase is started, but not completed.
188  * Caller code should use SpiMemoryIsBusy to wait for the completion.
189  *
190  * @param Memory Pointer to the SPI memory instance object
191  * @param SectorIndex Index for sector to be erased (0 to < (.MemorySize / .SectorSize))
192  * @return true if SPI memory sector erase command was sent, else false
193  ***********************************************************************/
194 extern bool SpiMemoryEraseSectorAsync(const struct spi_memory_t *Memory,
195  uint32_t SectorIndex);
196 
197 /**********************************************************************/
198 /**
199  * @brief Name: SpiMemoryEraseSector\n
200  * Erases given sector in SPI memory and waits for completion.
201  * Called from main program level.
202  *
203  * @param Memory Pointer to the SPI memory instance object
204  * @param SectorIndex Index for sector to be erased (0 to < (.MemorySize / .SectorSize))
205  * @return true if SPI memory sector was erased, else false
206  ***********************************************************************/
207 extern bool SpiMemoryEraseSector(const struct spi_memory_t *Memory,
208  uint32_t SectorIndex);
209 
210 /**********************************************************************/
211 /**
212  * @brief Name: SpiMemoryEraseBlockAsync\n
213  * Begines erasing given block in SPI memory.
214  * Called from main program level.
215  * At function return SPI transfer is completed; erase is started, but not completed.
216  * Caller code should use SpiMemoryIsBusy to wait for the completion.
217  *
218  * @param Memory Pointer to the SPI memory instance object
219  * @param BlockIndex Index for block to be erased (0 to < (.MemorySize / .BlockSize))
220  * @return true if SPI memory block erase command was sent, else false
221  ***********************************************************************/
222 extern bool SpiMemoryEraseBlockAsync(const struct spi_memory_t *Memory,
223  uint32_t BlockIndex);
224 
225 /**********************************************************************/
226 /**
227  * @brief Name: SpiMemoryEraseBlock\n
228  * Erases given block in SPI memory and waits for completion.
229  * Called from main program level.
230  *
231  * @param Memory Pointer to the SPI memory instance object
232  * @param BlockIndex Index for block to be erased (0 to < (.MemorySize / .BlockSize))
233  * @return true if SPI memory block was erased, else false
234  ***********************************************************************/
235 extern bool SpiMemoryEraseBlock(const struct spi_memory_t *Memory,
236  uint32_t BlockIndex);
237 
238 /**********************************************************************/
239 /**
240  * @brief Name: SpiMemoryEraseAsync\n
241  * Begines erasing the whole SPI memory.
242  * Called from main program level.
243  * At function return SPI transfer is completed; erase is started, but not completed.
244  * Caller code should use SpiMemoryIsBusy to wait for the completion.
245  *
246  * @param Memory Pointer to the SPI memory instance object
247  * @return true if SPI memory erase command was sent, else false
248  ***********************************************************************/
249 extern bool SpiMemoryEraseAsync(const struct spi_memory_t *Memory);
250 
251 /**********************************************************************/
252 /**
253  * @brief Name: SpiMemoryErase\n
254  * Erases the whole SPI memory and waits for completion.
255  * Called from main program level.
256  *
257  * @param Memory Pointer to the SPI memory instance object
258  * @return true if SPI memory was erased, else false
259  ***********************************************************************/
260 extern bool SpiMemoryErase(const struct spi_memory_t *Memory);
261 
262 /**********************************************************************/
263 /**
264  * @brief Name: SpiMemoryReadAsync\n
265  * Reads bytes from SPI memory to DstBuffer.
266  * Called from main program level.
267  * Does not wait for completion, the completion callback is called instead
268  * when transfer is finished. Calling code should not use SPI bus until
269  * the completion callback is called.
270  *
271  * @param Memory Pointer to the SPI memory instance object
272  * @param DstBuffer Destination buffer for read data.
273  * @param SrcAddress Address of first byte to read from SPI memory
274  * @param ByteCount Number of bytes to read from SPI memory
275  * @param Callback Completion callback
276  * @return true if SPI memory read command was sent, else false
277  ***********************************************************************/
278 extern bool SpiMemoryReadAsync(const struct spi_memory_t *Memory,
279  struct spi_memory_data_buffer_header *DstBuffer,
280  uint32_t SrcAddress,
281  uint32_t ByteCount,
283 
284 /**********************************************************************/
285 /**
286  * @brief Name: SpiMemoryRead\n
287  * Reads bytes from SPI memory to DstBuffer.
288  * Called from main program level.
289  *
290  * @param Memory Pointer to the SPI memory instance object
291  * @param DstBuffer Destination buffer for read data
292  * @param SrcAddress Address of first byte to read from SPI memory
293  * @param ByteCount Number of bytes to read from SPI memory
294  * @return true if SPI memory was read, else false
295  ***********************************************************************/
296 extern bool SpiMemoryRead(const struct spi_memory_t *Memory,
297  void *DstBuffer,
298  uint32_t SrcAddress,
299  uint32_t ByteCount);
300 
301 /**********************************************************************/
302 /**
303  * @brief Name: SpiMemoryReadPageAsync\n
304  * Reads the page PageIndex from SPI memory to DstBuffer.
305  * Called from main program level.
306  * Does not wait for completion, the completion callback is called instead
307  * when transfer is finished. Calling code should not use SPI bus until
308  * the completion callback is called.
309  *
310  * @param Memory Pointer to the SPI memory instance object
311  * @param DstBuffer Destination buffer for read data
312  * @param PageIndex Index of page to read from SPI memory
313  * @param Callback Completion callback
314  * @return true if SPI memory was read, else false
315  ***********************************************************************/
316 static inline bool SpiMemoryReadPageAsync(const struct spi_memory_t *Memory,
317  struct spi_memory_data_buffer_header *DstBuffer,
318  uint32_t PageIndex,
320 {
321  return SpiMemoryReadAsync(Memory, DstBuffer, PageIndex << Memory->PageSizeExponent, 1 << Memory->PageSizeExponent, Callback);
322 }
323 
324 /**********************************************************************/
325 /**
326  * @brief Name: SpiMemoryReadPage\n
327  * Reads the page PageIndex from SPI memory to DstBuffer.
328  * Called from main program level.
329  *
330  * @param Memory Pointer to the SPI memory instance object
331  * @param DstBuffer Destination buffer for read data
332  * @param PageIndex Index of page to read from SPI memory
333  * @return true if SPI memory was read, else false
334  ***********************************************************************/
335 static inline bool SpiMemoryReadPage(const struct spi_memory_t *Memory,
336  void *DstBuffer,
337  uint32_t PageIndex)
338 {
339  return SpiMemoryRead(Memory, DstBuffer, PageIndex << Memory->PageSizeExponent, 1 << Memory->PageSizeExponent);
340 }
341 
342 /**********************************************************************/
343 /**
344  * @brief Name: SpiMemoryReadPageWithOffsetAsync\n
345  * Reads the page PageIndex with offset from SPI memory to DstBuffer.
346  * Called from main program level.
347  * Does not wait for completion, the completion callback is called instead
348  * when transfer is finished. Calling code should not use SPI bus until
349  * the completion callback is called.
350  *
351  * @param Memory Pointer to the SPI memory instance object
352  * @param DstBuffer Destination buffer for read data
353  * @param PageIndex Index of page to read from SPI memory
354  * @param PageOffset Offset in page, must be < .PageSize
355  * @param ByteCount Number of bytes to read from SPI memory
356  * @param Callback Completion callback
357  * @return true if SPI memory was read, else false
358  ***********************************************************************/
359 static inline bool SpiMemoryReadPageWithOffsetAsync(const struct spi_memory_t *Memory,
360  struct spi_memory_data_buffer_header *DstBuffer,
361  uint32_t PageIndex,
362  uint32_t PageOffset,
363  uint32_t ByteCount,
365 {
366  return SpiMemoryReadAsync(Memory, DstBuffer, (PageIndex << Memory->PageSizeExponent) + PageOffset, ByteCount, Callback);
367 }
368 
369 /**********************************************************************/
370 /**
371  * @brief Name: SpiMemoryReadPageWithOffset\n
372  * Reads the page PageIndex with offset from SPI memory to DstBuffer.
373  * Called from main program level.
374  *
375  * @param Memory Pointer to the SPI memory instance object
376  * @param DstBuffer Destination buffer for read data
377  * @param PageIndex Index of page to read from SPI memory
378  * @param PageOffset Offset in page, must be < .PageSize
379  * @param ByteCount Number of bytes to read from SPI memory
380  * @return true if SPI memory was read, else false
381  ***********************************************************************/
382 static inline bool SpiMemoryReadPageWithOffset(const struct spi_memory_t *Memory,
383  void *DstBuffer,
384  uint32_t PageIndex,
385  uint32_t PageOffset,
386  uint32_t ByteCount)
387 {
388  return SpiMemoryRead(Memory, DstBuffer, (PageIndex << Memory->PageSizeExponent) + PageOffset, ByteCount);
389 }
390 
391 /**********************************************************************/
392 /**
393  * @brief Name: SpiMemoryWriteAsync\n
394  * Writes bytes from SrcBuffer to SPI memory.
395  * It the SPI memory is page based, the data must fit into a single page, and
396  * the page must be erased before writing.
397  * Return after writing is finished.
398  * Called from main program level.
399  * Does not wait for completion, the completion callback is called instead
400  * when SPI transfer is finished. Calling code should not use SPI bus until
401  * the completion callback is called. Note that completion of the in-chip
402  * writing process is not indicated by any kind of callback. Calling code
403  * should use SpiMemoryIsBusy to wait for the completion.
404  *
405  * @param Memory Pointer to the SPI memory instance object
406  * @param DstAddress Address of first byte to write to SPI memory
407  * @param SrcBuffer Source buffer for the data to be written
408  * @param ByteCount Number of bytes to write to SPI memory
409  * @param Callback Completion callback
410  * @return true if SPI memory was written, else false
411  ***********************************************************************/
412 extern bool SpiMemoryWriteAsync(const struct spi_memory_t *Memory,
413  uint32_t DstAddress,
414  struct spi_memory_data_buffer_header *SrcBuffer,
415  uint32_t ByteCount,
417 
418 /**********************************************************************/
419 /**
420  * @brief Name: SpiMemoryWrite\n
421  * Writes bytes from SrcBuffer to SPI memory.
422  * It the SPI memory is page based, the data must fit into a single page, and
423  * the page must be erased before writing.
424  * Return after writing is finished.
425  * Called from main program level.
426  *
427  * @param Memory Pointer to the SPI memory instance object
428  * @param DstAddress Address of first byte to write to SPI memory
429  * @param SrcBuffer Source buffer for the data to be written
430  * @param ByteCount Number of bytes to write to SPI memory
431  * @return true if SPI memory was written, else false
432  ***********************************************************************/
433 extern bool SpiMemoryWrite(const struct spi_memory_t *Memory,
434  uint32_t DstAddress,
435  const void *SrcBuffer,
436  uint32_t ByteCount);
437 
438 /**********************************************************************/
439 /**
440  * @brief Name: SpiMemoryWritePageAsync\n
441  * Writes page data from SrcBuffer to page PageIndex in SPI memory.
442  * The page must be erased before writing.
443  * Return after writing is finished.
444  * Called from main program level.
445  * Does not wait for completion, the completion callback is called instead
446  * when SPI transfer is finished. Calling code should not use SPI bus until
447  * the completion callback is called. Note that completion of the in-chip
448  * writing process is not indicated by any kind of callback. Calling code
449  * should use SpiMemoryIsBusy to wait for the completion.
450  *
451  * @param Memory Pointer to the SPI memory instance object
452  * @param PageIndex Index of page to write to SPI memory
453  * @param SrcBuffer Source buffer for page data to be written
454  * @param Callback Completion callback
455  * @return true if SPI memory was written, else false
456  ***********************************************************************/
457 static inline bool SpiMemoryWritePageAsync(const struct spi_memory_t *Memory,
458  uint32_t PageIndex,
459  struct spi_memory_data_buffer_header *SrcBuffer,
461 {
462  return SpiMemoryWriteAsync(Memory, PageIndex << Memory->PageSizeExponent, SrcBuffer, 1 << Memory->PageSizeExponent, Callback);
463 }
464 
465 /**********************************************************************/
466 /**
467  * @brief Name: SpiMemoryWritePage\n
468  * Writes page data from SrcBuffer to page PageIndex in SPI memory.
469  * The page must be erased before writing.
470  * Return after writing is finished.
471  * Called from main program level.
472  *
473  * @param Memory Pointer to the SPI memory instance object
474  * @param PageIndex Index of page to write to SPI memory
475  * @param SrcBuffer Source buffer for page data to be written
476  * @return true if SPI memory was written, else false
477  ***********************************************************************/
478 static inline bool SpiMemoryWritePage(const struct spi_memory_t *Memory, uint32_t PageIndex, const void *SrcBuffer)
479 {
480  return SpiMemoryWrite(Memory, PageIndex << Memory->PageSizeExponent, SrcBuffer, 1 << Memory->PageSizeExponent);
481 }
482 
483 /**********************************************************************/
484 /**
485  * @brief Name: SpiMemoryVerify\n
486  * Verifies data in SPI memory with SrcBuffer.
487  * Called from main program level.
488  *
489  * @param Memory Pointer to the SPI memory instance object
490  * @param SrcAddress First address to be verified in SPI memory
491  * @param SrcBuffer Source buffer for data to be verified
492  * @param ByteCount Number of bytes to verify in SPI memory
493  * @return true if flash is accessable and verify OK, else false
494  ***********************************************************************/
495 extern bool SpiMemoryVerify(const struct spi_memory_t *Memory, uint32_t SrcAddress, const void *SrcBuffer, uint32_t ByteCount);
496 
497 /**********************************************************************/
498 /**
499  * @brief Name: SpiMemoryVerifyPage\n
500  * Verifies data in page PageIndex in SPI memory with SrcBuffer.
501  * Called from main program level.
502  *
503  * @param Memory Pointer to the SPI memory instance object
504  * @param PageIndex Index of page to be verified in SPI memory
505  * @param SrcBuffer Source buffer for data to be verified
506  * @return true if flash is accessable and verify OK, else false
507  ***********************************************************************/
508 static inline bool SpiMemoryVerifyPage(const struct spi_memory_t *Memory, uint32_t PageIndex, const void *SrcBuffer)
509 {
510  return (SpiMemoryVerify(Memory, PageIndex << Memory->PageSizeExponent, SrcBuffer, 1 << Memory->PageSizeExponent));
511 }
512 
513 /**********************************************************************/
514 /**
515  * @brief Name: SpiMemoryIsBusy\n
516  * Checks if the memory write or erase operation is in progress
517  * Called from main program level.
518  *
519  * @param Memory Pointer to the SPI memory instance object
520  * @return true if flash is busy, else false
521  ***********************************************************************/
522 extern bool SpiMemoryIsBusy(const struct spi_memory_t *Memory);
523 
524 #ifdef CONTIKI
525 /**********************************************************************/
526 /**
527  * @brief Name: SpiMemoryChecksum\n
528  * Calculates CRC16 checksum for given range in SPI memory.
529  * Checksum is used as both input and output argument.
530  * Called from main program level.
531  *
532  * @param Memory Pointer to the SPI memory instance object
533  * @param Checksum Pointer to checksum accumulator
534  * @param SrcAddress First address to be verified in SPI memory
535  * @param ByteCount Number of bytes to verify in SPI memory
536  * @param Inverse Inverse content of the flash before the checksuming
537  * @return true if flash is accessable, else false
538  ***********************************************************************/
539 extern bool SpiMemoryChecksum(const struct spi_memory_t *Memory,
540  uint16_t *Checksum,
541  uint32_t SrcAddress,
542  uint32_t ByteCount,
543  bool Inverse);
544 #endif /* CONTIKI */
545 
546 /**********************************************************************/
547 /**
548  * @brief Name: SpiMemoryPowerUp\n
549  * Power up VCC for SPI memory.
550  * SpiEnable() must be called after this function to get SPI pin setup.
551  * Only to be used from EveSpiPowerUp()
552  *
553  * @param Memory Pointer to the SPI memory instance object
554  **********************************************************************/
555 extern void SpiMemoryPowerUp(const struct spi_memory_t *Memory);
556 
557 /**********************************************************************/
558 /**
559  * @brief Name: SpiMemoryPowerDown\n
560  * Power down VCC for SPI memory.
561  * SpiDisable() must be called prior to this function to get default pin setup.
562  * Only to be used from EveSpiPowerDown()
563  *
564  * @param Memory Pointer to the SPI memory instance object
565  **********************************************************************/
566 extern void SpiMemoryPowerDown(const struct spi_memory_t *Memory);
567 
568 /** @} */
569 /** \} */
570 
571 #endif // DRIVER_SPI_MEMORY_H
static bool SpiMemoryReadPageWithOffset(const struct spi_memory_t *Memory, void *DstBuffer, uint32_t PageIndex, uint32_t PageOffset, uint32_t ByteCount)
Name: SpiMemoryReadPageWithOffset Reads the page PageIndex with offset from SPI memory to DstBuffer...
Definition: spi-memory.h:382
bool SpiMemoryDisable(const struct spi_memory_t *Memory)
Name: SpiMemoryDisable Sets SPI memory in deep powerdown. Called from main program level...
uint32_t Baudrate
Definition: spi-memory.h:91
static bool SpiMemoryVerifyPage(const struct spi_memory_t *Memory, uint32_t PageIndex, const void *SrcBuffer)
Name: SpiMemoryVerifyPage Verifies data in page PageIndex in SPI memory with SrcBuffer. Called from main program level.
Definition: spi-memory.h:508
uint8_t BlockSizeExponent
Definition: spi-memory.h:95
bool SpiMemoryInit(const struct spi_memory_t *Memory)
Name: SpiMemoryInit Waits for power on and then release SPI memory from deep powerdown. KŲ!! ???????????? Called from main program level.
uint8_t SectorSizeExponent
Definition: spi-memory.h:94
bool SpiMemorySetWriteProtection(const struct spi_memory_t *Memory, enum spi_memory_protection_t Protection)
Name: SpiMemorySetWriteProtection Sets write protection for SPI memory and waits for completion...
bool SpiMemoryIsBusy(const struct spi_memory_t *Memory)
Name: SpiMemoryIsBusy Checks if the memory write or erase operation is in progress Called from main p...
const struct spi_t * Spi
Definition: spi-memory.h:88
EVE module stub.
bool SpiMemoryEraseBlock(const struct spi_memory_t *Memory, uint32_t BlockIndex)
Name: SpiMemoryEraseBlock Erases given block in SPI memory and waits for completion. Called from main program level.
bool SpiMemoryWriteAsync(const struct spi_memory_t *Memory, uint32_t DstAddress, struct spi_memory_data_buffer_header *SrcBuffer, uint32_t ByteCount, spi_memory_completion_callback_t Callback)
Name: SpiMemoryWriteAsync Writes bytes from SrcBuffer to SPI memory. It the SPI memory is page based...
uint16_t EnterPdTimeUs
Definition: spi-memory.h:108
uint8_t PowerUpTimeMs
Definition: spi-memory.h:112
uint16_t VccPowerUpTimeUs
Definition: spi-memory.h:111
void(* spi_memory_completion_callback_t)(const struct spi_memory_t *Memory, struct spi_memory_data_buffer_header *BufferHeader)
Definition: spi-memory.h:72
bool SpiMemoryEraseBlockAsync(const struct spi_memory_t *Memory, uint32_t BlockIndex)
Name: SpiMemoryEraseBlockAsync Begines erasing given block in SPI memory. Called from main program le...
struct spi_memory_state_t * State
Definition: spi-memory.h:89
bool SpiMemoryWrite(const struct spi_memory_t *Memory, uint32_t DstAddress, const void *SrcBuffer, uint32_t ByteCount)
Name: SpiMemoryWrite Writes bytes from SrcBuffer to SPI memory. It the SPI memory is page based...
static bool SpiMemoryWritePage(const struct spi_memory_t *Memory, uint32_t PageIndex, const void *SrcBuffer)
Name: SpiMemoryWritePage Writes page data from SrcBuffer to page PageIndex in SPI memory...
Definition: spi-memory.h:478
uint8_t MemorySizeExponent
Definition: spi-memory.h:92
Definition: spi.h:113
Driver for the MCU&#39;s SPI blocks.
uint16_t ReleasePdTimeAfterCommandUs
Definition: spi-memory.h:109
#define SPI_MEMORY_DATA_BUFFER_TYPE(type, size)
Definition: spi-memory.h:130
bool SpiMemoryErase(const struct spi_memory_t *Memory)
Name: SpiMemoryErase Erases the whole SPI memory and waits for completion. Called from main program l...
bool SpiMemoryVerify(const struct spi_memory_t *Memory, uint32_t SrcAddress, const void *SrcBuffer, uint32_t ByteCount)
Name: SpiMemoryVerify Verifies data in SPI memory with SrcBuffer. Called from main program level...
bool SpiMemoryReadAsync(const struct spi_memory_t *Memory, struct spi_memory_data_buffer_header *DstBuffer, uint32_t SrcAddress, uint32_t ByteCount, spi_memory_completion_callback_t Callback)
Name: SpiMemoryReadAsync Reads bytes from SPI memory to DstBuffer. Called from main program level...
static bool SpiMemoryReadPageAsync(const struct spi_memory_t *Memory, struct spi_memory_data_buffer_header *DstBuffer, uint32_t PageIndex, spi_memory_completion_callback_t Callback)
Name: SpiMemoryReadPageAsync Reads the page PageIndex from SPI memory to DstBuffer. Called from main program level. Does not wait for completion, the completion callback is called instead when transfer is finished. Calling code should not use SPI bus until the completion callback is called.
Definition: spi-memory.h:316
uint16_t ReleasePdTimeAfterCsActiveUs
Definition: spi-memory.h:110
uint8_t PageSizeExponent
Definition: spi-memory.h:93
static bool SpiMemoryReadPage(const struct spi_memory_t *Memory, void *DstBuffer, uint32_t PageIndex)
Name: SpiMemoryReadPage Reads the page PageIndex from SPI memory to DstBuffer. Called from main progr...
Definition: spi-memory.h:335
#define SPI_MEMORY_DATA_BUFFER_COMMAND_SIZE
Definition: spi-memory.h:61
bool SpiMemoryEraseAsync(const struct spi_memory_t *Memory)
Name: SpiMemoryEraseAsync Begines erasing the whole SPI memory. Called from main program level...
static bool SpiMemoryReadPageWithOffsetAsync(const struct spi_memory_t *Memory, struct spi_memory_data_buffer_header *DstBuffer, uint32_t PageIndex, uint32_t PageOffset, uint32_t ByteCount, spi_memory_completion_callback_t Callback)
Name: SpiMemoryReadPageWithOffsetAsync Reads the page PageIndex with offset from SPI memory to DstBuf...
Definition: spi-memory.h:359
void SpiMemoryPowerUp(const struct spi_memory_t *Memory)
Name: SpiMemoryPowerUp Power up VCC for SPI memory. SpiEnable() must be called after this function to...
bool SpiMemoryEraseSector(const struct spi_memory_t *Memory, uint32_t SectorIndex)
Name: SpiMemoryEraseSector Erases given sector in SPI memory and waits for completion. Called from main program level.
bool SpiMemoryEraseSectorAsync(const struct spi_memory_t *Memory, uint32_t SectorIndex)
Name: SpiMemoryEraseSectorAsync Begines erasing given sector in SPI memory. Called from main program ...
void SpiMemoryPowerDown(const struct spi_memory_t *Memory)
Name: SpiMemoryPowerDown Power down VCC for SPI memory. SpiDisable() must be called prior to this fun...
bool SpiMemoryRead(const struct spi_memory_t *Memory, void *DstBuffer, uint32_t SrcAddress, uint32_t ByteCount)
Name: SpiMemoryRead Reads bytes from SPI memory to DstBuffer. Called from main program level...
static bool SpiMemoryWritePageAsync(const struct spi_memory_t *Memory, uint32_t PageIndex, struct spi_memory_data_buffer_header *SrcBuffer, spi_memory_completion_callback_t Callback)
Name: SpiMemoryWritePageAsync Writes page data from SrcBuffer to page PageIndex in SPI memory...
Definition: spi-memory.h:457
Definition: spi.h:166