/*-----------------------------------------------------------------------------------
!
!                              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        : otp.h
  DESCRIPTION : otp.c header
  Revision    : $Rev: 4 $
  Author      : $Author
  Date        : $Date: 2015-09-09 15:19:58 +0900 (豌ｴ, 09 9 2015) $
-----------------------------------------------------------------------------------*/
#ifndef ___OTP_H_INCLUDED___
#define ___OTP_H_INCLUDED___

/********************************************************************************************
include
********************************************************************************************/
#include <stdint.h>
#include "otp_reg.h"

/********************************************************************************************
define
********************************************************************************************/
#define LTS3TYPE_TEST    (0x00u)  // 巻き戻し禁止フラグ(0), 開発実機フラグ(0)
#define LTS3TYPE_DEV     (0x01u)  // 巻き戻し禁止フラグ(0), 開発実機フラグ(1) 
#define LTS3TYPE_MP      (0x02u)  // 巻き戻し禁止フラグ(1), 開発実機フラグ(0) 
#define LTS3TYPE_MP2DEV  (0x03u)  // 巻き戻し禁止フラグ(1), 開発実機フラグ(1)

#define MTP_SIZE    (8)
#define OTP_BASE    (0x00008000u)
#define OTP_SIZE    (2 * 1024)


/********************************************************************************************
struct
********************************************************************************************/
typedef struct _TagOTP {
	uint32_t skeyn[64];
	uint32_t skeyd[64];
	uint32_t lts3Cert[256];
	uint32_t lts3DeviceID[4];
	uint32_t crc;
	uint8_t  reserve1[1888/8];
	uint32_t pair_no;
	uint8_t  reserve2[32/8];
	uint32_t hw_version_main;
	uint32_t hw_version_sub;
	uint8_t  reserve3[64/8];
	uint8_t  blank_check_pass_flag;
	uint8_t  blank_check_fail_flag;
	uint8_t  reserve4[112/8];
	uint64_t good_die_flag;
	uint64_t good_die_flag_reserved;
	uint64_t test_mode_prohibition_flag;
	uint64_t test_mode_prohibition_flag_reserved;
//	uint32_t test_area[32];
}OTP;


/********************************************************************************************
macro
********************************************************************************************/
//
//
// BootCodeサイズを抑えるため、一部マクロ化しています
//
//

/*---------------------------------------------------------------------------
  function  : MTPの取得
  arguments : none
  return    : MTP情報
  detail    : none
--------------------------------------------------------------------------*/
#define MTP_GetMTP()  (&OTPR.rdata)



/*---------------------------------------------------------------------------
  function  : OTPモジュールの停止
  arguments : none
  return    : void
  detale    : none
--------------------------------------------------------------------------*/
#define  OTPMTP_Kill() (OTPR.otp_mask = OTPR_KILL)


/*---------------------------------------------------------------------------
  function  : ラストFWバージョンの更新
  arguments : fwVersion : I  : FW Vestion
  return    : 0(Pass), !0(False)
  detale    : none
--------------------------------------------------------------------------*/
#define MTP_SetLastFWVersion(fwVersion)  MTP_Update((fwVersion) & MTP_VERSION_MASK)

/*---------------------------------------------------------------------------
  function  : 開発実機フラグのセット
  arguments : none
  return    : void
  detail    : 0(成功), !0(失敗)
--------------------------------------------------------------------------*/
#define MTP_SetLotus3DevFlag() MTP_Update(DEV_FLAG_MASK)




/********************************************************************************************
prottype
********************************************************************************************/
volatile OTP* OTPMTP_Init(void);
void OTPMTP_Update(uint8_t mode);
int MTP_Update(uint64_t wrData);


#endif // ___OTP_H_INCLUDED___
