/*-----------------------------------------------------------------------------------
!
!                              COPYRIGHT 2015 BY
!                            MegaChips Corporation
!
!------------------------------------------------------------------------------------
! These coded instructions, statements, and computer programs include
! intellectual property and know-how belonging to MegaChips
! Corporaiton ("MCC") and its partner companies.
! Therefore, do not use these specifications for any purpose other than
! the purpose
! expressly agreed to by MCCs customer and MCC.  Also, do not duplicate,
! copy,
! or reproduce these specifications, nor reveal these specifications to
! any third party
! without MCCs prior written consent.
!
*/
/*-----------------------------------------------------------------------------------
  FILE        : aes_reg.h
  DESCRIPTION : AES Register
  Revision    : $Rev: 4 $
  Author      : $Author: shirait $
  Date        : $Date: 2015-09-09 15:19:58 +0900 (水, 09 9 2015) $
-----------------------------------------------------------------------------------*/


#ifndef ___AES_REG_H_INCLUDED___
#define ___AES_REG_H_INCLUDED___

#include <stdint.h>

#define AES_REG_BASE (0x40005000u)

#define AESR_KEY_SIZE (16)
#define AESR_IV_SIZE  (16)
#define AESR_ODATA_SIZE  (48)
#define AESR_IDATA_SIZE (48)

typedef struct _tagAesReg {
	union {
		uint8_t byte;
		struct {
			uint8_t fin      : 1;
			uint8_t efin     : 1;
			uint8_t reserved : 6;
		} bit;
	} intst;

	union {
		uint8_t byte;
		struct {
			uint8_t fin      : 1;
			uint8_t efin     : 1;
			uint8_t reserved : 6;
		} bit;
	} inten;

	union {
		uint8_t byte;
		struct {
			uint8_t fin      : 1;
			uint8_t efin     : 1;
			uint8_t reserved : 6;
		} bit;
	} intsel;

	uint8_t  reserved1;

	union {
		uint8_t byte;
		struct {
			uint8_t en       : 1;
			uint8_t reserved : 7;
		} bit;
	} en;

	uint8_t  reserved2[3];

	union {
		uint8_t byte;
		struct {
			uint8_t dec      : 1;
			uint8_t reserved : 7;
		} bit;
	} dec;

	uint8_t  reserved3[3];

	union {
		uint8_t byte;
		struct {
			uint8_t mode     : 3;
			uint8_t reserved : 5;
		} bit;
	} mode;

	uint8_t  reserved4[3];

	union {
		uint8_t byte;
		struct {
			uint8_t kmode    : 2;
			uint8_t reserved : 6;
		} bit;
	} key_mode;

	uint8_t  reserved5[3];

	union {
		uint8_t byte;
		struct {
			uint8_t en       : 1;
			uint8_t reserved : 6;
		} bit;
	} fix_en;

	uint8_t  reserved6[3];

	union {
		uint8_t byte;
		struct {
			uint8_t byte     : 1;
			uint8_t reserved : 7;
		} bit;
	} dset;

	uint8_t  reserved7[3];

	union {
		uint8_t byte;
		struct {
			uint8_t status   : 1;
			uint8_t reserved : 7;
		} bit;
	} status;

	uint8_t  reserved8[35];
	uint32_t key[AESR_KEY_SIZE/ sizeof(uint32_t)];
	uint8_t  reserved9[48];
	uint32_t iv[AESR_IV_SIZE / sizeof(uint32_t)];
	uint8_t  reserved10[112];
	uint32_t data[AESR_IDATA_SIZE / sizeof(uint32_t)];
	uint8_t  reserved11[208];
	uint32_t odata[AESR_ODATA_SIZE / sizeof(uint32_t)];
} AesReg;

#define AESR (*(volatile AesReg*)(AES_REG_BASE))

#define AESR_INTST_EFIN  (0x02)
#define AESR_INTST_FIN   (0x01)
#define AESR_INTST_ALL_CLR (0x03)

#define AESR_INTEN_EFIN  (0x02)
#define AESR_INTEN_FIN   (0x01)

#define AESR_INTSEL_EFIN (0x02)
#define AESR_INTSEL_FIN  (0x01)

#define AESR_EN_EN (0x01)

#define AESR_DEC_DEC (0x01)

#define AESR_MODE_ECB (0x00)
#define AESR_MODE_CBC (0x01)
#define AESR_MODE_CTR (0x02)

#define AESR_KEY_MODE_128 (0x00)

#define AESR_DSET_16 (0x00)
#define AESR_DSET_48 (0x01)

#define AESR_STATUS_IDLE (0x00)
#define AESR_STATUS_BUSY (0x01)

#endif // ___AES_REG_H_INCLUDED___
