ConOpSys V2970  P004.07
ANVILEX control operating system
FM25V02.h
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 //! @file FM25V02.h
3 //! @brief NVRAM chip FM25V02 hardware driver class header file.
4 //! @attention No special attention requered.
5 //! @copyright (C) 2015-2020 ANVILEX LLC
6 //! $HeadURL: https://192.168.3.4:8443/svn/P004_07/ConOpSys/Peripherals/SPI_Memory/FM25V02.h $
7 //! $Revision: 2904 $
8 //! $Date: 2021-12-02 02:39:23 +0500 (Do, 02 Dez 2021) $
9 //! $Author: minch $
10 //------------------------------------------------------------------------------
11 //
12 // Redistribution and use in source and binary forms, with or without
13 // modification, are permitted provided that the following conditions are met:
14 //
15 // 1. Redistributions of source code must retain the above copyright notice,
16 // this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright notice,
19 // this list of conditions and the following disclaimer in the documentation
20 // and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of ANVILEX nor the names of its contributors may be
23 // used to endorse or promote products derived from this software without
24 // specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
30 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 // POSSIBILITY OF SUCH DAMAGE.
37 //
38 //------------------------------------------------------------------------------
39 
40 //------------------------------------------------------------------------------
41 // Protecting header files from mutual, recursive inclusion.
42 //------------------------------------------------------------------------------
43 
44 #pragma once
45 
46 //------------------------------------------------------------------------------
47 // Include project files
48 //------------------------------------------------------------------------------
49 
50 #include "SPI_Memory_Base.h"
51 
52 //------------------------------------------------------------------------------
53 // Defines
54 //------------------------------------------------------------------------------
55 
56 #define NVRAM_READY_TIMEOUT_MS 5 // 5us @ 20 MHz
57 
58 //------------------------------------------------------------------------------
59 // Class
60 //------------------------------------------------------------------------------
61 
62 //! @brief NVRAM memory hardware driver
63 class TFM25V02 : public TSPI_Memory_Base
64 {
65 
66  //----------------------------------------------------------------------------
67  // Public defines, methods and variables
68  //----------------------------------------------------------------------------
69 
70  public:
71 
72  //--------------------------------------------------------------------------
73  // Public defines
74  //--------------------------------------------------------------------------
75 
76  //! @brief device ID structure
77  typedef union TDevice_ID
78  {
79 
80  //! @brief Device ID buffer
82 
83  //! @brief Bitfield structure
84  struct
85  {
86 
87  //! @brief Device manufacturer ID
89 
90  //! @brief Device density and family structure
91  struct
92  {
93 
94  //! @brief Bits 4-0 : Device density
96 
97  //! @brief Bits 7-5 : Device family
99 
100  };
101 
102  //! @brief Device revision and subversion structure
103  struct
104  {
105 
106  //! @brief Bits 2-0 : Reserved bits
108 
109  //! @brief Bits 5-3 : Device revision
111 
112  //! @brief Bits 7-6 : Device subversion
114 
115  };
116 
117  };
118 
120 
121  //--------------------------------------------------------------------------
122  // Public methods
123  //--------------------------------------------------------------------------
124 
125  //!-------------------------------------------------------------------------
126  //! @brief Class constructor method.
127  //! @note None
128  //! \par Override
129  //! Not allowed
130  //! @attention Don't call this method directly.
131  //--------------------------------------------------------------------------
132 
133  TFM25V02();
134 
135  //!-------------------------------------------------------------------------
136  //! @brief Class destructor method.
137  //! @note None
138  //! \par Override
139  //! Not allowed
140  //! @attention Don't call this method directly.
141  //--------------------------------------------------------------------------
142 
143  virtual ~TFM25V02();
144 
145  //!-------------------------------------------------------------------------
146  //! @brief Driver initialisation method.
147  //! @note By calling this method driver make internal initialisation and prepering for operation.
148  //! @return None
149  //! \par Override
150  //! Not allowed
151  //! @attention None
152  //--------------------------------------------------------------------------
153 
154  VOID Init();
155 
156  //!-------------------------------------------------------------------------
157  //! @brief Driver start operation method.
158  //! @note By calling this method driver starts opration.
159  //! @return None
160  //! \par Override
161  //! Not allowed
162  //! @attention None
163  //--------------------------------------------------------------------------
164 
165  virtual VOID Start();
166 
167  //!-------------------------------------------------------------------------
168  //! @brief Read data from memory into buffer.
169  //! @note None
170  //! @param [in] u32_Linear_Address - Linear address of the data in memory
171  //! @param [in] u32_Size - Size of the data to read
172  //! @param [out] *u8_Data_Buffer - Pointer to the data buffer
173  //! @return BOOL - Data read operation status
174  //! @retval false - Read operation failed
175  //! @retval true - Read operation successed
176  //! \par Override
177  //! Not requered
178  //! @attention None
179  //--------------------------------------------------------------------------
180 
181  virtual BOOL Read_Buffer( U32 u32_Linear_Address, U32 u32_Size, U8 *u8_Data_Buffer );
182 
183  //!-------------------------------------------------------------------------
184  //! @brief Write data from buffer into memory.
185  //! @note None
186  //! @param [in] u32_Linear_Address - Linear address of the data in memory
187  //! @param [in] u32_Size - Size of the data to write
188  //! @param [out] *u8_Data_Buffer - Pointer to the data buffer
189  //! @return BOOL - Data write operation status
190  //! @retval false - Write operation failed
191  //! @retval true - Write operation successed
192  //! \par Override
193  //! Not requered
194  //! @attention None
195  //--------------------------------------------------------------------------
196 
197  virtual BOOL Write_Buffer( U32 u32_Linear_Address, U32 u32_Size, U8 *u8_Data_Buffer );
198 
199  //!-------------------------------------------------------------------------
200  //! @brief Write data from buffer into memory.
201  //! @note None
202  //! @param [in] u32_Linear_Address - Linear address
203  //! @param [in] u32_Size - Size of the data
204  //! @param [out] *u8_Data_Buffer - Pointer to the data buffer
205  //! @return BOOL - Oeration status
206  //! @retval false - Operation failed
207  //! @retval true - Operation successed
208  //! \par Override
209  //! Not requered
210  //! @attention None
211  //--------------------------------------------------------------------------
212 
213  virtual BOOL Verify_Buffer( U32 u32_Linear_Address, U32 u32_Size, U8 *u8_Data_Buffer ); // ANVILEX KM: To implement
214 
215  //----------------------------------------------------------------------------
216  // Protected methods and variables
217  //----------------------------------------------------------------------------
218 
219  protected:
220 
221  //----------------------------------------------------------------------------
222  // Private methods and variables
223  //----------------------------------------------------------------------------
224 
225  private:
226 
227  //--------------------------------------------------------------------------
228  // Private defines
229  //--------------------------------------------------------------------------
230 
231  //! @brief Define NVRAM commands
233  {
234  //! @brief Write Enable Latch command
235  commandWREN = (U8)0x06,
236 
237  //! @brief Write Disable command
238  commandWRDI = (U8)0x04,
239 
240  //! @brief Read Status Register command
241  commandRDSR = (U8)0x05,
242 
243  //! @brief Write Status Register command
244  commandWRSR = (U8)0x01,
245 
246  //! @brief Read Memory Data command
247  commandREAD = (U8)0x03,
248 
249  //! @brief Fast Read Memory Data command
250  commandFSTRD = (U8)0x0B,
251 
252  //! @brief Write Memory Data command
253  commandWRITE = (U8)0x02,
254 
255  //! @brief Enter sleep mode command
256  commandSLEEP = (U8)0xB9,
257 
258  //! @brief Read device ID command
259  commandRDID = (U8)0x9F,
260 
261  //! @brief Read device serial number command
262  commandSNR = (U8)0xC3
263 
264  };
265 
266  //--------------------------------------------------------------------------
267  // Private methods
268  //--------------------------------------------------------------------------
269 
270  //!-------------------------------------------------------------------------
271  //! @brief Read memory device status register method.
272  //! @note None
273  //! @param [out] *u8_Status_Register - Pointer to status register value
274  //! @return BOOL - Read operation status
275  //! @retval false - Read operation failed
276  //! @retval true - Read operation successed
277  //! \par Override
278  //! Requered
279  //! @attention None
280  //--------------------------------------------------------------------------
281 
282  virtual BOOL Read_Status_Register( U8 *u8_Status_Register );
283 
284  //!-------------------------------------------------------------------------
285  //! @brief Write memory device status register method.
286  //! @note None
287  //! @param [in] u8_Status_Register - Status register value
288  //! @return BOOL - Write operation status
289  //! @retval false - Write operation failed
290  //! @retval true - Write operation successed
291  //! \par Override
292  //! Requered
293  //! @attention None
294  //--------------------------------------------------------------------------
295 
296  virtual BOOL Write_Status_Register( U8 u8_Status_Register );
297 
298  //!-------------------------------------------------------------------------
299  //! @brief Read byte from device method.
300  //! @note None
301  //! @param [in] u32_Address - Address
302  //! @param [out] *u8_Data - Pointer to returned data value
303  //! @return BOOL - Read operation status
304  //! @retval false - Read operation failed
305  //! @retval true - Read operation successed
306  //! \par Override
307  //! Requered
308  //! @attention None
309  //--------------------------------------------------------------------------
310 
311  virtual BOOL Read_Memory( U32 u32_Address, U8 *u8_Data );
312 
313  //!-------------------------------------------------------------------------
314  //! @brief Write byte into device method.
315  //! @note None
316  //! @param [in] u32_Address - Address
317  //! @param [in] u8_Data - Data value
318  //! @return BOOL - Write operation status
319  //! @retval false - Write operation failed
320  //! @retval true - Write operation successed
321  //! \par Override
322  //! Requered
323  //! @attention None
324  //--------------------------------------------------------------------------
325 
326  virtual BOOL Write_Memory( U32 u32_Address, U8 u8_Data );
327 
328  //!-------------------------------------------------------------------------
329  //! @brief Read memory device identification information method.
330  //! @note None
331  //! @return BOOL - Read operation status
332  //! @retval false - Read operation failed
333  //! @retval true - Read operation successed
334  //! \par Override
335  //! Requered
336  //! @attention None
337  //--------------------------------------------------------------------------
338 
339  virtual BOOL Read_Identification();
340 
341  //!-------------------------------------------------------------------------
342  //! @brief Read manufacturer identifier pure virtual method.
343  //! @note None
344  //! @return None
345  //! \par Override
346  //! Requered
347  //! @attention Depricated method.
348  //--------------------------------------------------------------------------
349 
350 // virtual BOOL Read_Manufacturer_ID();
351 
352  //!-------------------------------------------------------------------------
353  //! @brief Read device identifier pure virtual method.
354  //! @note None
355  //! @return None
356  //! \par Override
357  //! Requered
358  //! @attention Depricated method.
359  //--------------------------------------------------------------------------
360 
361  virtual BOOL Read_Device_ID();
362 
363  //!-------------------------------------------------------------------------
364  //! @brief Read device serial number pure virtual method.
365  //! @note None
366  //! @return None
367  //! \par Override
368  //! Requered
369  //! @attention Depricated method.
370  //--------------------------------------------------------------------------
371 
372  virtual BOOL Read_Serial_Number();
373 
374  //!-------------------------------------------------------------------------
375  //! @brief Exit from sleep mode.
376  //! @note None
377  //! @return None
378  //! \par Override
379  //! Requered
380  //! @attention Depricated method.
381  //--------------------------------------------------------------------------
382 
384 
385  //!-------------------------------------------------------------------------
386  //! @brief Address translation method.
387  //! @note None
388  //! @param [in] u32_Address - Address (4 bytes)
389  //! @param [out] *u8_Address_Size - Size of the address in bytes
390  //! @param [out] *u8_Address_Byte_2 - Address (2th byte)
391  //! @param [out] *u8_Address_Byte_1 - Address (1th byte)
392  //! @param [out] *u8_Address_Byte_0 - Address (0th byte)
393  //! @return None
394  //! \par Override
395  //! Not requered
396  //! @attention Depricated method.
397  //--------------------------------------------------------------------------
398 
399  VOID Translate_Address( U32 u32_Address, U8 *u8_Address_Size, U8 *u8_Address_Byte_2, U8 *u8_Address_Byte_1, U8 *u8_Address_Byte_0 );
400 
401  //!-------------------------------------------------------------------------
402  //! @brief Address in range checking method.
403  //! @note None
404  //! @param [in] u32_Address - Address (4 bytes)
405  //! @param [in] u32_Size - Data size
406  //! @return None
407  //! \par Override
408  //! Not requered
409  //! @attention Depricated method.
410  //--------------------------------------------------------------------------
411 
412  BOOL Is_Address_In_Range( U32 u32_Address, U32 u32_Size );
413 
414  //--------------------------------------------------------------------------
415  // Private variables
416  //--------------------------------------------------------------------------
417 
418  //! @brief Serial number storage
419  U8 u8_Serial_Number[ 8 ] = { (U8)0x00, (U8)0x00, (U8)0x00, (U8)0x00, (U8)0x00, (U8)0x00, (U8)0x00, (U8)0x00 };
420 
421  //! @brief Memory device ID structure
423 
424 };
425 
426 //------------------------------------------------------------------------------
427 // Export global objects
428 //------------------------------------------------------------------------------
429 
430 //! @brief Export global NVRAM object
431 extern TFM25V02 object_FM25V02;
432 
433 //------------------------------------------------------------------------------
434 // End of file
435 //------------------------------------------------------------------------------
int BOOL
Boolean datatype definition.
Definition: Defines.h:124
unsigned char U8
Binary 8-Bit unsigned integer datatype defenition.
Definition: Defines.h:183
void VOID
Datatypesess datatype definition.
Definition: Defines.h:105
unsigned long U32
Binary 32-Bit unsigned integer datatype defenition.
Definition: Defines.h:203
TFM25V02 object_FM25V02
Export global NVRAM object.
Definition: FM25V02.cpp:66
SPI connected memory base class header file.
NVRAM memory hardware driver.
Definition: FM25V02.h:64
virtual BOOL Read_Buffer(U32 u32_Linear_Address, U32 u32_Size, U8 *u8_Data_Buffer)
Read data from memory into buffer.
Definition: FM25V02.cpp:679
TFM25V02()
Class constructor method.
Definition: FM25V02.cpp:72
VOID Translate_Address(U32 u32_Address, U8 *u8_Address_Size, U8 *u8_Address_Byte_2, U8 *u8_Address_Byte_1, U8 *u8_Address_Byte_0)
Address translation method.
Definition: FM25V02.cpp:403
virtual BOOL Write_Buffer(U32 u32_Linear_Address, U32 u32_Size, U8 *u8_Data_Buffer)
Write data from buffer into memory.
Definition: FM25V02.cpp:819
BOOL Is_Address_In_Range(U32 u32_Address, U32 u32_Size)
Address in range checking method.
Definition: FM25V02.cpp:526
VOID Init()
Driver initialisation method.
Definition: FM25V02.cpp:88
virtual BOOL Verify_Buffer(U32 u32_Linear_Address, U32 u32_Size, U8 *u8_Data_Buffer)
Write data from buffer into memory.
Definition: FM25V02.cpp:967
TNVRAMCommand
Define NVRAM commands.
Definition: FM25V02.h:233
@ commandWRITE
Write Memory Data command.
Definition: FM25V02.h:253
@ commandWREN
Write Enable Latch command.
Definition: FM25V02.h:235
@ commandWRDI
Write Disable command.
Definition: FM25V02.h:238
@ commandWRSR
Write Status Register command.
Definition: FM25V02.h:244
@ commandRDSR
Read Status Register command.
Definition: FM25V02.h:241
@ commandSLEEP
Enter sleep mode command.
Definition: FM25V02.h:256
@ commandSNR
Read device serial number command.
Definition: FM25V02.h:262
@ commandREAD
Read Memory Data command.
Definition: FM25V02.h:247
@ commandRDID
Read device ID command.
Definition: FM25V02.h:259
@ commandFSTRD
Fast Read Memory Data command.
Definition: FM25V02.h:250
U8 u8_Serial_Number[8]
Serial number storage.
Definition: FM25V02.h:419
virtual BOOL Read_Status_Register(U8 *u8_Status_Register)
Read memory device status register method.
Definition: FM25V02.cpp:1109
virtual VOID Start()
Driver start operation method.
Definition: FM25V02.cpp:111
virtual BOOL Read_Memory(U32 u32_Address, U8 *u8_Data)
Read byte from device method.
Definition: FM25V02.cpp:1185
VOID Exit_Sleep_Mode()
Exit from sleep mode.
Definition: FM25V02.cpp:1584
virtual BOOL Write_Memory(U32 u32_Address, U8 u8_Data)
Write byte into device method.
Definition: FM25V02.cpp:1290
union TFM25V02::TDevice_ID TDevice_ID
device ID structure
TDevice_ID struct_Device_ID
Memory device ID structure.
Definition: FM25V02.h:422
virtual BOOL Write_Status_Register(U8 u8_Status_Register)
Write memory device status register method.
Definition: FM25V02.cpp:1135
virtual ~TFM25V02()
Class destructor method.
Definition: FM25V02.cpp:80
virtual BOOL Read_Serial_Number()
Read device serial number pure virtual method.
Definition: FM25V02.cpp:1516
virtual BOOL Read_Identification()
Read memory device identification information method.
Definition: FM25V02.cpp:1408
virtual BOOL Read_Device_ID()
Read manufacturer identifier pure virtual method.
Definition: FM25V02.cpp:1447
SPI memory base class.
Definition: SPI_Memory_Base.h:55
device ID structure
Definition: FM25V02.h:78
U8 u8_Revision
Bits 5-3 : Device revision.
Definition: FM25V02.h:110
U8 u8_Device_ID[9]
Device ID buffer.
Definition: FM25V02.h:81
U8 u8_Reserved
Bits 2-0 : Reserved bits.
Definition: FM25V02.h:107
U8 u8_Family
Bits 7-5 : Device family.
Definition: FM25V02.h:98
U8 u8_Density
Bits 4-0 : Device density.
Definition: FM25V02.h:95
U8 u8_Subtype
Bits 7-6 : Device subversion.
Definition: FM25V02.h:113
U8 u8_Manufacturere_ID[7]
Device manufacturer ID.
Definition: FM25V02.h:88