/**
 * @file adcs_vapi_fw.h
 *
 * @brief This file contains OS abstracted ADCS functions for ADCS firmware
 * upload related functions
 *
 * @copyright Copyright 2023 Antaris, Inc.
 */

#ifndef ADCS_VSIM_FW_H_
#define ADCS_VSIM_FW_H_

#include "exo_types.h"

/**
 * @brief This API return the SDRAM storage address for ADCS firmware
 *
 * @return Address of SDRAM firmware storage
 * @retval address
 */
uint8* adcs_get_sdram_storage_address(void);

/**
 * @brief This API return the NOR Flash storage address for ADCS firmware
 *
 * @return Address of NOR Flash firmware storage
 * @retval address
 */
uint8* adcs_get_nor_flash_address(void);

/**
 * @brief This API calculate checksum for given address upto the length.
 * CRC calculation method referred from Cube ADCS reference manual.
 *
 * @param[in] start : pointer to memory address CRC need to be calculated.
 * @param[in] len   : length of memory.
 *
 * @return Checksum value of given memory
 * @retval 2byte CRC value
 */
uint16 adcs_crc_calc(uint8 *start, uint32 len);

/**
 * @brief This API erase the selected destination block and return the status
 *
 * @param[in] data      : pointer to data for firmware destination.
 *
 * @return Return value of flash erase status.
 * @retval 0 -> Success
 *         Other values -> Error
 */
int8 adcs_initiate_upload(uint8 *data);

/**
 * @brief This API upload the data_buffer to ADCS by transferring 20kb
 * every time and write to flash upto data_len
 *
 * @param[in] data_buffer   : pointer to file need to uploaded.
 * @param[in] data_len      : length of file.
 *
 * @return Return value of file upload status.
 * @retval 0 -> Success
 *         Other values -> Error
 */
int8 adcs_file_upload(uint8 *data_buffer, uint32 data_len);

/**
 * @brief This API Copy uploaded firmware to internal flash of ADCS
 * and reset the MCU to run the new firmware.
 *
 * @param[in] data      : pointer to data for firmware destination.
 *
 * @return Return value of firmware upload status.
 * @retval 0 -> Success
 *         Other values -> Error
 */
int8 adcs_frimware_boot(uint8* data);

/**
 * @brief This API Verify firmware availability, upload the firmware to ADCS
 * and run uploaded firmware.
 *
 * @param[in] data      : pointer to data for firmware destination.
 *
 * @return Return value of firmware upload status.
 * @retval 0 -> Success
 *         Other values -> Error
 */
int8 adcs_firmware_upload(uint8 *data);

/**
 * @brief This API return the ADCS firmware update status
 *
 * @return Return value of firmware update status.
 * @retval 0 -> Success
 *         Other values -> Error
 */
int8 get_adcs_fw_upd_sts();

#endif /* ADCS_VSIM_FW_H_ */
