/*
 * storage_mem_def.h
 *
 *  Created on: Jul 29, 2022
 *      Author: Invcuser52
 */

#ifndef STORAGE_MEM_DEF_H_
#define STORAGE_MEM_DEF_H_

#include <stdint.h>
#include "boot_lut_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_occupy_sts
{
	occupied_lut1 =3,
	occupied_lut2,
	occupied_none
}e_sector_occupy_sts;

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_bank_selection bank_id;
} s_storageRegion;


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


typedef struct sectorInfo   // size in bytes = 8100
{
	uint8_t *sectorStartAddress;
	uint8_t *sectorEndAddress;
	uint8_t *current_free_address;
	uint32_t freeBytes;
	uint32_t sector_length;
	e_sector_usage_mode mode;
	e_bank_selection bank_id;
	uint32_t block_incr;   // u32 is used to avaoid structure padding...
	e_sbl_list sector_occupy_status;
	s_blockInfo block[SECTOR_BLOCK_LIMIT];
} s_sectorInfo;



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


#endif /* STORAGE_MEM_DEF_H_ */
