/**
 * Eeprom object for generic microcontroller.
 *
 * This file is a template for MM32MCU.
 *
 * @file        CO_flash.h
 * @ingroup     CO_flash
 *
 * This file is part of CANopenNode, an opensource CANopen Stack.
 * Project home page is <https://github.com/CANopenNode/CANopenNode>.
 * For more information on CANopen see <http://www.can-cia.org/>.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


#ifndef CO_FLASH_H
#define CO_FLASH_H

#ifdef __cplusplus
extern "C" {
#endif

//============================================================================
//                                DEFINES
//============================================================================
#define PARAM_STORE_PASSWORD   0x65766173
#define PARAM_RESTORE_PASSWORD 0x64616F6C

#define LAST_PAGE_ADDRESS           0
#define PAGES_PER_FLASH_AREA        16
#define FLASH_PAGE_SIZE             256u
#define CO_OD_FLASH_PARAM_DEFAULT   (0*PAGES_PER_FLASH_AREA*FLASH_PAGE_SIZE)
#define CO_OD_FLASH_PARAM_RUNTIME   (2*PAGES_PER_FLASH_AREA*FLASH_PAGE_SIZE)

#define CO_UNUSED(v)  (void)(v)

/**
 * Initialize flash library and data storage in flash
 * We use two blocks in flash for data storage. One block is used for the
 * default data that will be restored. The default parameters are stored
 * at address CO_OD_Flash_Default_Param. The data that will be loaded at
 * startup or saved if user modifies data.
 */
void CO_FlashInit(void);

/**
 * Register object dictionary functions for parameter storage and restoring
 * parameters (Object dictionary index 0x1010 Store Param and 0x1011 Restore
 * default param.
 */
void CO_FlashRegisterODFunctions(CO_t* CO);

#ifdef __cplusplus
}
#endif /*__cplusplus*/

/** @} */
#endif
