/**
 * @file exo_osal_mem_debug.h
 *
 * @brief This file contains enumeration and function prototypes
 *        for memory debugging.
 *
 *  @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 EXO_OS_EXO_OSAL_MEMORY_MANAGEMENT_INC_EXO_OSAL_MEM_DEBUG_H_
#define EXO_OS_EXO_OSAL_MEMORY_MANAGEMENT_INC_EXO_OSAL_MEM_DEBUG_H_

#include "stdint.h"
#include "stdio.h"

#define OBC_MEMORY_DEBUG_TEST_BYTE_LENGTH 1024      ///< length of the buffer in bytes
#define OBC_MEMORY_EEPROM_TEST_BYTE_LENGTH 2048      ///< length of the buffer in bytes
#define MEM_TEST_PATTERN_55 0x55                   ///< Memory test pattern type A
#define MEM_TEST_PATTERN_AA 0xAA                   ///< Memory test pattern type B
#define MEM_TEST_PATTERN_00 0x0
#define MEM_TEST_PATTERN_FF 0xFF


#define QSPI_FLASH_MEM 1
#define FMC_FLASH_MEM  2
#define EXT_SDRAM_MEM  0
#define EXT_EEPROM_MEM_1 3
#define EXT_EEPROM_MEM_2 4

#define FULLCHIP_MEM_TEST  1
#define BLOCK_LVL_MEM_TEST 0

#define FMC_NOR_FLASH_MEM_SIZE 16*1024*1024
#define QSPI_NOR_FLASH_MEM_SIZE 64*1024*1024

typedef enum
{
	EXT_MEM_WRITE_55,
	EXT_MEM_WRITE_AA,
	EXT_MEM_WRITE_00,
	EXT_MEM_WRITE_FF,
	EXT_MEM_READ_55,
	EXT_MEM_READ_AA,
	EXT_MEM_READ_00,
	EXT_MEM_READ_FF,
	EXT_MEM_ERASE_WRITE_READ,
	EXT_MEM_ERASE,
	EXT_MEM_OPERATION_MAX,
}ext_mem_test_typ;

typedef struct
{
	uint8_t mem_intf_type;
	uint8_t block_or_fullchip;
	uint8_t test_type;
	uint8_t sts;
}ext_mem_test_tc_tm_s;

/**
 * @brief Different memory type enumeration.
 */
typedef enum
{
    e_mem_debug_sdram_test=1,          /*!< Memory type SDRAM  				*/
	e_mem_debug_fmc_nor_flash_test,    /*!< Memory type FMC NOR flash   	*/
	e_mem_debug_qspi_nor_flash_test,   /*!< Memory type QSPI NOR flash 		*/
	e_iram_heap_availablity_test,      /*!< check heap availability 	 			*/
	e_max_memory_flash                 

}obc_debug_mem_type_e;

/**
 * @brief This API decode the test command and call the respective memory test function
 * @param[in]  mem_type_1 : Type of memory
 * @return success status
 */
int8_t obc_mem_debug_tc_decode(void *mem_type_1);

/**
 * @brief This API returns the encoded data frame
 * @return Return the telemetry frame
 */
uint8_t obc_mem_debug_tm_pack_data();


uint8_t ext_mem_validation(ext_mem_test_tc_tm_s* mem_test_info);
#endif /* EXO_OS_EXO_OSAL_MEMORY_MANAGEMENT_INC_EXO_OSAL_MEM_DEBUG_H_ */
