#ifndef __SECURE_BOOT_CONFIG_H__
#define __SECURE_BOOT_CONFIG_H__

#include "Std_Types.h"

#ifdef __cplusplus
extern "C" {
#endif

/* the max. secure boot section number, support max. 8 section for YTM32B1HAx */
#define MAX_SECURE_BOOT_SECT_NUM        ( 8u )
/* BVT valid marker */
#define BVT_VALID_MARK                  ( 0xA55AA55A )
/* Valid marker for secure boot group */
#define SECURE_BOOT_GROUP_MARKER        ( 0xACBEEFDD )
/* Valid marker for secure boot section */
#define SECURE_BOOT_SECTION_MARKER      ( 0x5AA5 )

/* boot configuration word bit-filed definiton */
#define CPSRC_PLL_BIT          (17)
#define WDG_RECFG_EN_BIT       (16)
#define WDG_CLKSRC_SHIFT       (14)
#define CPDIVS_SHIFT           (10)
#define ROM_BOOT_SCST_EN_BIT   (9)
#define APP_WDG_EN_BIT         (8)
#define BOOT_SEQ_STRICT_BIT    (7)
#define BOOT_SEQ_EN_BIT        (6)
#define CM33_0_BIT             (0)

#define CPDIVS_MASK            (15)
#define WDG_CLKSRC_MASK        (0x3U)


#define BVT_CPSRC_PLL          (1<<CPSRC_PLL_BIT)
#define BVT_WDG_RECFG_EN       (1<<WDG_RECFG_EN_BIT)
#define BVT_BCW_CPDIVS_SET(x)  (((x) & CPDIVS_MASK) << CPDIVS_SHIFT)
#define BVT_BCW_CPDIVS_GET(x)  (((x) >> CPDIVS_SHIFT) & CPDIVS_MASK)
#define BVT_WDG_CLKSRC_SET(x)  (((x) & WDG_CLKSRC_MASK) << WDG_CLKSRC_SHIFT)
#define BVT_WDG_CLKSRC_GET(x)  (((x) >> WDG_CLKSRC_SHIFT) & WDG_CLKSRC_MASK)
#define APP_WDG_EN             (1<<APP_WDG_EN_BIT)
#define BOOT_SEQ_STRICT        (1<<BOOT_SEQ_STRICT_BIT)
#define BOOT_SEQ_EN            (1<<BOOT_SEQ_EN_BIT)
#define CM33_0_EN              (1<<CM33_0_BIT)

/*!
 * @brief Specify the key length to be used to implement the requested cryptographic
 * operation.
 *
 * Implements : HCU_KeyLenType_Class
 */
typedef enum
{
    KEY_LEN_128_BITS = 0x00U,   /**< 128-bit key length */
    KEY_LEN_192_BITS = 0x01U,   /**< 192-bit key length */
    KEY_LEN_256_BITS = 0x02U,   /**< 256-bit key length */
} HCU_KeyLenType;

/*!
 * @brief the config struct of secure boot section.
 *
 * Implements : SBOOT_SectionConfigType_Class
 */
typedef struct
{
    uint16 SBootMarker;         /**< 2B: fixed marker to identify the secure config */
    HCU_KeyLenType AesKeySize;  /**< 1B: AES key type/size for the CMAC calculation, AES-128/192/256 */
    uint8 KeySlot;              /**< 1B: allow to use 0~31 key group */
    uint32 StartAddr;           /**< 4B: the start address of secure boot section for CMAC generation/authorization */
    uint32 Length;              /**< 4B: the length of secure boot section for CMAC generation/authorization */
    uint32 CmacAddr;            /**< 4B: the CMAC result store address */
} SBOOT_SectionConfigType;

/*!
 * @brief the config struct of secure boot group
 *
 * Implements : SBOOT_GroupConfigType_Class
 */
typedef struct
{
    uint32 GroupMarker;         /**< 4B: fixed marker to identify the the secure boot group info */
    uint8 SectionNum;           /**< 1B: the secure boot section config number, limited by the max. support number of the device family */
    boolean Encrypt;            /**< 1B: the section config encrypt or not */
    HCU_KeyLenType AesKeySize;  /**< 1B: the AES key type/size for the encrypt */
    uint8 KeySlot;              /**< 1B: the key for section config encrypt, allow to use 0~31 key group */
    /**< the secure boot section config struct pointers, it's configured per actual project/application requirements */
    uint32 SectionConfigAddr[MAX_SECURE_BOOT_SECT_NUM];
} SBOOT_GroupConfigType;

/*!
 * @brief the BVT structure type definition
 *
 * Implements : BVT_HeaderConfigType_Class
 */
typedef struct
{
    uint32 BvtMarker;           /**< BVT marker */
    uint32 BootConfigWord;      /**< Boot configuration word */
    uint32 SBootStartAddress;   /**< secure boot start address */
    uint32 Reserved1;           /**< Reserved configuration */
    uint32 CM33MainAppAddr;    /**< CM33 main core start address */
    uint32 Reserved2;           /**< Reserved configuration */
    uint32 Reserved3;           /**< Reserved configuration */
    uint32 Reserved4;           /**< Reserved configuration */
    uint32 Reserved5;           /**< Reserved configuration */
    uint32 Reserved6;           /**< Reserved configuration */
    uint32 AppWdgTimeout;       /**< timeout set of the WDG watchdog of the  application core */
    uint32 RESERVED7;           /**< Reserved configuration */
} BVT_HeaderConfigType;

#ifdef __cplusplus
}
#endif

/*! @}*/
#endif  /* #if !defined(__SECURE_BOOT_CONFIG_H__) */

