/* Copyright Statement:
 *
 * This software/firmware and related documentation ("AutoChips Software") are
 * protected under relevant copyright laws. The information contained herein is
 * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
 * the prior written permission of AutoChips inc. and/or its licensors, any
 * reproduction, modification, use or disclosure of AutoChips Software, and
 * information contained herein, in whole or in part, shall be strictly
 * prohibited.
 *
 * AutoChips Inc. (C) 2022. All rights reserved.
 *
 * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
 * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
 * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
 * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
 * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
 * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
 * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
 * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
 * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
 * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
 * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
 * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
 * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
 * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
 * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
 * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
 * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
 * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
 */

/* PRQA S 3630 EOF */ /* struct/union type will be used by user app. */
/* PRQA S 3116 EOF */

#ifndef EEP_DRV_H
#define EEP_DRV_H
/*!
* @file eep_drv.h
* @brief This file provides EEP integration functions interface.
*
*/
#ifdef __cplusplus
extern "C" {
#endif

/* ===========================================  Includes  =========================================== */
#include <stdint.h>

/*=====================================SOURCE FILE VERSION INFORMATION==============================*/
#define EEP_HAL_MODULE_ID                    (331U)
#define EEP_HAL_SW_MAJOR_VERSION             (3U)
#define EEP_HAL_SW_MINOR_VERSION             (2U)
#define EEP_HAL_SW_PATCH_VERSION             (4U)

/* ============================================  Define  ============================================ */

/* ===========================================  Typedef  ============================================ */
/*!< Callback typedef for eep module */
typedef void (*Eep_CallbackType)(void);

/*!
 * @brief IC type code.
 */
typedef enum
{
    EEP_HAL_AC78406 = 406U,
    EEP_HAL_AC78036 = 36U,
}Eep_Hal_IcType;

/*!
 * @brief EEP operate status.
 */
typedef enum
{
    EEP_HAL_SUCCESS         = 0U,   /*!< EEP operate successfully */
    EEP_HAL_STATUS_ERROR     = 1U,   /*!< EEP operate status error which can check FLASH status register */
    EEP_HAL_PARAM_ERROR      = 2U,   /*!< EEP input parameter error */
    EEP_HAL_TIMEOUT         = 3U,   /*!< EEP operate timeout when unlock FLASH */
    EEP_HAL_BUSY            = 4U,   /*!< EEP operate busy when FLASH command not finished */
    EEP_HAL_OTHER_ERROR     = 5U,  /*!< EEP other error, normally this will not occur */
}Eep_Hal_StatusType;
/*
    EEP size        RAM size        Flash size
    4096 byte       =EEP size       64KB
    2048 byte       =EEP size       32KB
    1024 byte       =EEP size       16KB
    <=512 byte      =EEP size       8KB
*/
#pragma pack(push)
#pragma pack(4)
typedef struct
{
    uint16_t EepSize;           /*!< The size of EEP (byte) */
    uint32_t EepRamBaseAddr;    /*!< The base address of EEP RAM */
    uint32_t EepFlashBaseAddr;  /*!< The base address of EEP FLASH */
    uint32_t FlashPageSize;     /*!< The FLASH page size (byte) */
    uint32_t FlashMinProByte;   /*!< The FLASH min program byte */
    uint32_t Retry;             /*!< Retry times of the FLASH timeout */
    Eep_Hal_IcType IcType;       /*!< The IC type */
    Eep_CallbackType CallbackType;    /*!< Call back function */
}Eep_Hal_ConfigType;
#pragma pack(pop)

/*
    Main version
    Sub version
    Rev version
    Year of the current lib version released
    Year of the current lib version released
    Month of the current lib version released
    Date of the current lib version released
    Code branch
*/
#pragma pack(push)
#pragma pack(4)
typedef struct
{
    uint32_t Main;
    uint32_t Sub;
    uint32_t Rev;
    uint32_t Year;
    uint32_t Month;
    uint32_t Day;
}Eep_Hal_VersionType;
#pragma pack(pop)
/* ====================================  Functions declaration  ===================================== */
/*!
 * @brief EEP initialize
 *
 * @param[in] config: EEP parameter struct
 * @return EEP operate status
 */
Eep_Hal_StatusType Eep_Hal_Init(const Eep_Hal_ConfigType *Config);

/*!
 * @brief EEP Write
 *
 * @param[in] addr: EEP address
 * @param[in] data: data buffer pointer
 * @param[in] size: the size of write data(uint is byte)
 * @return EEP operate status
 */
Eep_Hal_StatusType Eep_Hal_Write(uint32_t Addr, const uint8_t *Data, uint16_t Size);

/*!
 * @brief EEP read
 *
 * @param[in] addr: EEP read address
 * @param[in] data: Point to the buffer ready to read the data from EEP
 * @param[in] size: the number of read data(uint is byte)
 * @return EEP operate status
 */
Eep_Hal_StatusType Eep_Hal_Read(uint32_t Addr, uint8_t *Data, uint16_t Size);

/*!
 * @brief erase all EEP space
 *
 * @param[in] none
 * @return EEP operate status
 */
Eep_Hal_StatusType Eep_Hal_Erase(void);

/*!
 * @brief Get EEP lib version
 *
 * @param[in] EEP version struct
 * @return EEP operate status
 */
Eep_Hal_StatusType Eep_Hal_GetVersion(Eep_Hal_VersionType *Version);

/*!
 * @brief Reload flash data to eeprom
 *
 * @param[in] none
 * @return EEP operate status
 */
Eep_Hal_StatusType Eep_Hal_Refresh(void);

/*!
 * @brief Check EEPROM current busy status
 *
 * @param[in] none
 * @return EEP current status busy or idle
 */
Eep_Hal_StatusType Eep_Hal_CheckBusy(void);

#ifdef __cplusplus
}
#endif

#endif /* EEP_DRV_H */

/* =============================================  EOF  ============================================== */
