/*-----------------------------------------------------------------------------------
!
!                              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        : rsa_reg.h
  DESCRIPTION : RSA Register
  Revision    : $Rev: 4 $
  Author      : $Author: shirait $
  Date        : $Date: 2015-09-09 15:19:58 +0900 (水, 09 9 2015) $
-----------------------------------------------------------------------------------*/
#ifndef ___RSA_REG_H_INCLUDED___
#define ___RSA_REG_H_INCLUDED___

#include <stdint.h>

#define RSA_REG_BASE (0x40006000u)

#define RSAR_TXT_SIZE (256)
#define RSAR_N_SIZE   (256)
#define RSAR_E_D_SIZE (256)
#define RSAR_R2D_SIZE (256)

typedef struct _tagRsaReg {
	uint8_t  exe;

	uint8_t reserved1[3];

	union {
		uint8_t byte;
		struct {
			uint8_t cal_sel  : 1;
			uint8_t dec_enc  : 1;
			uint8_t sel_rom_d: 1;
			uint8_t reserved : 5;
		} bit;
	} set;

	uint8_t reserved2[3];

	union {
		uint8_t byte;
		struct {
			uint8_t busy     : 1;
			uint8_t int_     : 1;
			uint8_t reserved : 6;
		} bit;
	} status;

	uint8_t reserved3[3];

	union {
		uint8_t byte;
		struct {
			uint8_t rsafin   : 1;
			uint8_t reserved : 7;
		} bit;
	} intst;

	uint8_t reserved4[3];

	union {
		uint8_t byte;
		struct {
			uint8_t rsafin   : 1;
			uint8_t reserved : 7;
		} bit;
	} inten;

	uint8_t reserved5[239];
	uint32_t txt[RSAR_TXT_SIZE / sizeof(uint32_t)];
	uint32_t n[RSAR_N_SIZE / sizeof(uint32_t)];
	uint32_t e_d[RSAR_E_D_SIZE / sizeof(uint32_t)];
	uint32_t r2n[RSAR_R2D_SIZE / sizeof(uint32_t)];
	uint32_t nm;
} RsaReg;

#define RSAR (*(volatile RsaReg*)(RSA_REG_BASE))

#define RSAR_EXE (0)

#define RSAR_SET_DEC   (0x02u)
#define RSAR_SET_ENC   (0x00u)
#define RSAR_SET_CAL   (0x01u)
#define RSAR_SET_ROM_D (0x04u)

#define RSAR_STATUS_INT  (0x02u)
#define RSAR_STATUS_BUSY (0x01u)

#define RSAR_INTST_RSAFIN (0x01u)
#define RSAR_INTST_ALL_CLR (0x01u)

#define RSAR_INTEN_RSAFIN (0x01u)

#endif // ___RSA_REG_H_INCLUDED___
