/**
 * @file ft_sender.h
 *
 * @brief This file contains function prototypes of memory layout functions
 *
 * @copyright Copyright 2023 Antaris, Inc.
 *
 * 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 OTSU_MEM_DEF_H_
#define OTSU_MEM_DEF_H_

#include <stdint.h>
#include "otsu_tctm_msg_def.h"


#define TOTAL_SECTOR 24
#define SECTOR_BLOCK_LIMIT       16   // dividing 32 bloacks = 32*4KB = 128KB , it is assumed that module can accomadate 4kb code size



typedef enum sector_usage_mode
{
	sector_mode_storage =0x10,
	sector_mode_boot_load = 0x20,
	sector_mode_rtl_load = 0x30,
	sector_mode_undefined = 0xff
}e_sector_usage_mode;

typedef struct storageRegion
{
	uint8_t *pucStartAddress;
	uint32_t xSizeInBytes;
	e_otsu_mem_type_def mem_type;
} s_otsu_storageRegion;


typedef struct blockInfo
{
	uint8_t *blockStartAddress;
	uint8_t *blockEndAddress;
	uint32_t blockSize;
	uint16_t m_id;
	uint16_t reserv;
} s_blockInfo;


typedef struct s_otsu_mem_RegionInfo_def   // size in bytes = 8100
{
	uint8_t *memoryStartAddress;
	uint8_t *memoryEndAddress;
	uint8_t *current_free_address;
	uint32_t freeBytes;
	uint32_t memory_length;
} s_otsu_mem_RegionInfo;



typedef struct storageInfo
{
	uint8_t *pStartAddress;
	uint8_t *pEndAddress;
	uint8_t *current_free_address;
	uint32_t freeBytes;
} s_storageInfo;



/**
* @brief This function used to configure different memory regions like internal flash,
* external flash, sdram.
*
* @param[in]  mem_type : type of memory such as execution area, storage area, backup area
* @param[in]  mem_address_set : start address of memory
* @param[in]  size : allocate memory size
*
* @return memory address
* @retval allocated address
*/
void otsu_mem_configure(e_otsu_mem_type_def mem_type, uint32_t mem_address_set, uint32_t size);

/**
* @brief This function used to initialize the memories that used for OTSU to
* manage different firmwares
*
* @param[in]  void : none
*
* @return memory address
* @retval allocated address
*/
void otsu_mem_init(void);




/**
* @brief This function will return the download address to be allocated for file transfer
*
* @param[in]  void : none
*
* @return memory address
* @retval allocated address
*/
uint32_t otsu_get_ftm_download_address(void);

/**
* @brief This function will return the storage address to be used to move firmware stored in sdram to
* external flash
*
* @param[in]  void : none
*
* @return memory address
* @retval allocated address
*/
uint32_t otsu_get_fw_storage_address(void);


/**
* @brief This function will return the firmware execution address
*
* @param[in]  void : none
*
* @return memory address
* @retval allocated address
*/
uint32_t get_fw_execution_address(void);

/**
* @brief This function will return the backup firmware stored in internal flash
*
* @param[in]  void : none
*
* @return memory address
* @retval allocated address
*/
uint32_t get_previous_fwstored_address(void);

/**
* @brief This function will return the backup firmware stored in external flash
* this is the factory firmware copy
*
* @param[in]  void : none
*
* @return memory address
* @retval allocated address
*/
uint32_t get_factory_fwstored_address(void);


#endif /* STORAGE_MEM_DEF_H_ */
