| [1] | 1 | /**
|
|---|
| 2 | ******************************************************************************
|
|---|
| 3 | * @file EEPROM_Emul/Core/eeprom_emul.h
|
|---|
| 4 | * @author MCD Application Team
|
|---|
| 5 | * @brief This file contains all the functions prototypes for the EEPROM
|
|---|
| 6 | * emulation firmware library.
|
|---|
| 7 | ******************************************************************************
|
|---|
| 8 | * @attention
|
|---|
| 9 | *
|
|---|
| 10 | * <h2><center>© Copyright (c) 2020 STMicroelectronics International N.V.
|
|---|
| 11 | * All rights reserved.</center></h2>
|
|---|
| 12 | *
|
|---|
| 13 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 14 | * modification, are permitted, provided that the following conditions are met:
|
|---|
| 15 | *
|
|---|
| 16 | * 1. Redistribution of source code must retain the above copyright notice,
|
|---|
| 17 | * this list of conditions and the following disclaimer.
|
|---|
| 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 | * 3. Neither the name of STMicroelectronics nor the names of other
|
|---|
| 22 | * contributors to this software may be used to endorse or promote products
|
|---|
| 23 | * derived from this software without specific written permission.
|
|---|
| 24 | * 4. This software, including modifications and/or derivative works of this
|
|---|
| 25 | * software, must execute solely and exclusively on microcontroller or
|
|---|
| 26 | * microprocessor devices manufactured by or for STMicroelectronics.
|
|---|
| 27 | * 5. Redistribution and use of this software other than as permitted under
|
|---|
| 28 | * this license is void and will automatically terminate your rights under
|
|---|
| 29 | * this license.
|
|---|
| 30 | *
|
|---|
| 31 | * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
|
|---|
| 32 | * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
|
|---|
| 33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|---|
| 34 | * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
|
|---|
| 35 | * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
|
|---|
| 36 | * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 37 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|---|
| 38 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|---|
| 39 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|---|
| 40 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|---|
| 41 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|---|
| 42 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 43 | *
|
|---|
| 44 | ******************************************************************************
|
|---|
| 45 | */
|
|---|
| 46 |
|
|---|
| 47 | /* Define to prevent recursive inclusion -------------------------------------*/
|
|---|
| 48 | #ifndef __EEPROM_EMUL_H
|
|---|
| 49 | #define __EEPROM_EMUL_H
|
|---|
| 50 |
|
|---|
| 51 | /* Includes ------------------------------------------------------------------*/
|
|---|
| 52 | #include "eeprom_emul_conf.h"
|
|---|
| 53 | #include "eeprom_emul_types.h"
|
|---|
| 54 | #include "flash_interface.h"
|
|---|
| 55 |
|
|---|
| 56 | /** @addtogroup EEPROM_Emulation
|
|---|
| 57 | * @{
|
|---|
| 58 | */
|
|---|
| 59 |
|
|---|
| 60 | /* Private constants ---------------------------------------------------------*/
|
|---|
| 61 | /** @defgroup EEPROM_Private_Constants EEPROM Private Constants
|
|---|
| 62 | * @{
|
|---|
| 63 | */
|
|---|
| 64 |
|
|---|
| 65 | /** @defgroup Private_Other_Constants Private Other Constants
|
|---|
| 66 | * @{
|
|---|
| 67 | */
|
|---|
| 68 |
|
|---|
| 69 | /* Page definitions */
|
|---|
| 70 | #define PAGE_SIZE FLASH_PAGE_SIZE /*!< Page size */
|
|---|
| 71 | #define PAGE_HEADER_SIZE EE_ELEMENT_SIZE * 4U /*!< Page Header is 4 elements to save page state */
|
|---|
| 72 | #define NB_MAX_ELEMENTS_BY_PAGE ((PAGE_SIZE - PAGE_HEADER_SIZE) / EE_ELEMENT_SIZE) /*!< Max number of elements by page */
|
|---|
| 73 | #define PAGES_NUMBER (((((NB_OF_VARIABLES + NB_MAX_ELEMENTS_BY_PAGE) / NB_MAX_ELEMENTS_BY_PAGE) * 2U) * CYCLES_NUMBER) + GUARD_PAGES_NUMBER)
|
|---|
| 74 | /*!< Number of consecutives pages used by the application */
|
|---|
| 75 | #define NB_MAX_WRITTEN_ELEMENTS ((NB_MAX_ELEMENTS_BY_PAGE * PAGES_NUMBER) / 2U) /*!< Max number of elements written before triggering pages transfer */
|
|---|
| 76 | #define START_PAGE PAGE(START_PAGE_ADDRESS) /*!< Page index of the 1st page used for EEPROM emul, in the bank */
|
|---|
| 77 | #define END_EEPROM_ADDRESS (START_PAGE_ADDRESS + (PAGES_NUMBER * FLASH_PAGE_SIZE) - 1) /*!< Last address of EEPROM emulation flash pages */
|
|---|
| 78 |
|
|---|
| 79 | /* No page define */
|
|---|
| 80 | #define EE_NO_PAGE_FOUND ((uint32_t)0xFFFFFFFFU)
|
|---|
| 81 |
|
|---|
| 82 | /**
|
|---|
| 83 | * @}
|
|---|
| 84 | */
|
|---|
| 85 |
|
|---|
| 86 | /**
|
|---|
| 87 | * @}
|
|---|
| 88 | */
|
|---|
| 89 |
|
|---|
| 90 | /* Private macro -------------------------------------------------------------*/
|
|---|
| 91 | /** @defgroup EEPROM_Private_Macros EEPROM Private Macros
|
|---|
| 92 | * @{
|
|---|
| 93 | */
|
|---|
| 94 |
|
|---|
| 95 | /** @defgroup Macros_Pages Macros to manipulate pages
|
|---|
| 96 | * @{
|
|---|
| 97 | */
|
|---|
| 98 |
|
|---|
| 99 | /* Macros to manipulate pages */
|
|---|
| 100 | #ifdef SECURE_FEATURES
|
|---|
| 101 | #define PAGE_ADDRESS(__PAGE__) (uint32_t)(FLASH_BASE_NS + (__PAGE__) * PAGE_SIZE + ((START_PAGE_ADDRESS - FLASH_BASE_NS) / BANK_SIZE) * BANK_SIZE) /*!< Get page address from page index */
|
|---|
| 102 | #define PAGE(__ADDRESS__) (uint32_t)((((__ADDRESS__) - FLASH_BASE_NS) % BANK_SIZE) / FLASH_PAGE_SIZE) /*!< Get page index from page address */
|
|---|
| 103 | #else
|
|---|
| 104 | #define PAGE_ADDRESS(__PAGE__) (uint32_t)(FLASH_BASE + (__PAGE__) * PAGE_SIZE + ((START_PAGE_ADDRESS - FLASH_BASE) / BANK_SIZE) * BANK_SIZE) /*!< Get page address from page index */
|
|---|
| 105 | #define PAGE(__ADDRESS__) (uint32_t)((((__ADDRESS__) - FLASH_BASE) % BANK_SIZE) / FLASH_PAGE_SIZE) /*!< Get page index from page address */
|
|---|
| 106 | #endif
|
|---|
| 107 | #define PREVIOUS_PAGE(__PAGE__) (uint32_t)((((__PAGE__) - START_PAGE - 1U + PAGES_NUMBER) % PAGES_NUMBER) + START_PAGE) /*!< Get page index of previous page, among circular page list */
|
|---|
| 108 | #define FOLLOWING_PAGE(__PAGE__) (uint32_t)((((__PAGE__) - START_PAGE + 1U) % PAGES_NUMBER) + START_PAGE) /*!< Get page index of following page, among circular page list */
|
|---|
| 109 |
|
|---|
| 110 | /**
|
|---|
| 111 | * @}
|
|---|
| 112 | */
|
|---|
| 113 |
|
|---|
| 114 | /** @defgroup Macros_Elements Macros to manipulate elements
|
|---|
| 115 | * @{
|
|---|
| 116 | */
|
|---|
| 117 |
|
|---|
| 118 | /* Macros to manipulate elements */
|
|---|
| 119 | #define EE_VIRTUALADDRESS_VALUE(__ELEMENT__) (EE_VIRTUALADDRESS_TYPE)((__ELEMENT__) & EE_MASK_VIRTUALADDRESS) /*!< Get virtual address value from element value */
|
|---|
| 120 | #define EE_DATA_VALUE(__ELEMENT__) (EE_DATA_TYPE)(((__ELEMENT__) & EE_MASK_DATA) >> EE_DATA_SHIFT) /*!< Get Data value from element value */
|
|---|
| 121 | #define EE_CRC_VALUE(__ELEMENT__) (EE_CRC_TYPE)(((__ELEMENT__) & EE_MASK_CRC) >> EE_CRC_SHIFT) /*!< Get Crc value from element value */
|
|---|
| 122 | #define EE_ELEMENT_VALUE(__VIRTADDR__,__DATA__,__CRC__) (((EE_ELEMENT_TYPE)(__DATA__) << EE_DATA_SHIFT) | (__CRC__) << EE_CRC_SHIFT | (__VIRTADDR__)) /*!< Get element value from virtual addr, data and crc values */
|
|---|
| 123 |
|
|---|
| 124 | /**
|
|---|
| 125 | * @}
|
|---|
| 126 | */
|
|---|
| 127 |
|
|---|
| 128 | /**
|
|---|
| 129 | * @}
|
|---|
| 130 | */
|
|---|
| 131 |
|
|---|
| 132 | /* Exported constants --------------------------------------------------------*/
|
|---|
| 133 | /* Exported types ------------------------------------------------------------*/
|
|---|
| 134 | /* Exported macro ------------------------------------------------------------*/
|
|---|
| 135 | /* Exported functions ------------------------------------------------------- */
|
|---|
| 136 | /** @defgroup EEPROM_Exported_Functions EEPROM Exported Functions
|
|---|
| 137 | * @{
|
|---|
| 138 | */
|
|---|
| 139 | EE_Status EE_Format(EE_Erase_type EraseType);
|
|---|
| 140 | EE_Status EE_Init(EE_Erase_type EraseType);
|
|---|
| 141 | #if defined(EE_ACCESS_32BITS)
|
|---|
| 142 | EE_Status EE_ReadVariable32bits(uint16_t VirtAddress, uint32_t* pData);
|
|---|
| 143 | EE_Status EE_WriteVariable32bits(uint16_t VirtAddress, uint32_t Data);
|
|---|
| 144 | #endif
|
|---|
| 145 | EE_Status EE_ReadVariable16bits(uint16_t VirtAddress, uint16_t* pData);
|
|---|
| 146 | EE_Status EE_WriteVariable16bits(uint16_t VirtAddress, uint16_t Data);
|
|---|
| 147 | EE_Status EE_ReadVariable8bits(uint16_t VirtAddress, uint8_t* pData);
|
|---|
| 148 | EE_Status EE_WriteVariable8bits(uint16_t VirtAddress, uint8_t Data);
|
|---|
| 149 | EE_Status EE_CleanUp(void);
|
|---|
| 150 | EE_Status EE_CleanUp_IT(void);
|
|---|
| 151 | EE_Status EE_DeleteCorruptedFlashAddress(uint32_t Address);
|
|---|
| 152 | void EE_EndOfCleanup_UserCallback(void);
|
|---|
| 153 |
|
|---|
| 154 | /**
|
|---|
| 155 | * @}
|
|---|
| 156 | */
|
|---|
| 157 |
|
|---|
| 158 | /**
|
|---|
| 159 | * @}
|
|---|
| 160 | */
|
|---|
| 161 |
|
|---|
| 162 | #endif /* __EEPROM_EMUL_H */
|
|---|
| 163 |
|
|---|
| 164 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
|---|