/*---------------------------------------------------------------------------*
  Project:  NitroSDK - CARD - libraries
  File:     card_device.c

  Copyright 2003,2004 Nintendo.  All rights reserved.

  These coded instructions, statements, and computer programs contain
  proprietary information of Nintendo of America Inc. and/or Nintendo
  Company Ltd., and are protected by Federal copyright law.  They may
  not be disclosed to third parties or copied or duplicated in any form,
  in whole or in part, without the prior written consent of Nintendo.

  $Log: card_device.c,v $
  Revision 1.8  2004/09/09 07:11:34  yosizaki
  delete CARD_BACKUP_TYPE_EEPROM_ 512k, 1M.

  Revision 1.7  2004/09/02 11:54:42  yosizaki
  fix CARD include directives.

  Revision 1.6  2004/08/23 10:38:10  yosizaki
  add write-command.
  add retry count on writing timeout.

  Revision 1.5  2004/08/18 13:42:05  yosizaki
  add FLASH 2Mbit.

  Revision 1.4  2004/08/18 12:11:37  yosizaki
  small fix (cardi_device->type)

  Revision 1.3  2004/08/18 08:19:02  yosizaki
  change CARDBackupType format.

  Revision 1.2  2004/07/28 13:18:06  yosizaki
  asynchronous mode support.

  Revision 1.1  2004/07/23 08:29:16  yosizaki
  (none)

 *---------------------------------------------------------------------------*/


#include <nitro.h>

#include "../include/card_common.h"
#include "../include/card_spi.h"



/******************************************************************************/
/* Functions */

/*
 * Get the information about the designated device type.
 * Returns a NULL if there is no relevant information.
 */
const CardDeviceInfo*	CARDi_FindDeviceInfo(CARDBackupType type)
{
	const CardDeviceInfo	*pd = cardi_device_list;
	for( ; ; ) {
		if(pd->type == type)
			return	pd;
		else if(pd->type == CARD_BACKUP_TYPE_NOT_USE)
			return	NULL;
		else
			++pd;
	}
}


/******************************************************************************/
/* Constants */

/* device property array */
const CardDeviceInfo	cardi_device_list[] = {

/* EEPROM ***********************************************************/

	/* Only the program-page timeout is needed. */

	/* 4kbit EEPROM */
	{
		CARD_BACKUP_TYPE_EEPROM_4KBITS,
		0x00000200,	0x00000200,	0x0010,	1,
		{
			79,
			0,
			0,
			0,
			0,
			0,
		},
	},
	/* 64kbit EEPROM */
	{
		CARD_BACKUP_TYPE_EEPROM_64KBITS,
		0x00002000,	0x00002000,	0x0020,	2,
		{
			79,
			0,
			0,
			0,
			0,
			0,
		},
	},

/* FLASH ************************************************************/

	/* All erases and program-page timeouts are needed */

	/* 2Mbit FLASH (SANYO Fixed?) */
	{
		CARD_BACKUP_TYPE_FLASH_2MBITS,
		0x00040000,	0x00010000,	0x0100,	3,
		{
			79,
			394,
			4720,
			79000,
			79000,
			4720,
		},
	},

#if	0
	/* If a new device is introduced, add in order to the CARDBackupType */

	/* 512kbit EEPROM */
	{
		CARD_BACKUP_TYPE_EEPROM_512KBITS,
		0x00010000,	0x00010000,	0x0080,	3,
		{
			158,
			0,
			0,
			0,
			0,
			0,
		},
	},
	/* 1Mbit EEPROM */
	{
		CARD_BACKUP_TYPE_EEPROM_1MBITS,
		0x00020000,	0x00020000,	0x0080,	3,
		{
			158,
			0,
			0,
			0,
			0,
			0,
		},
	},

	{	/* 16 Mbit FLASH (STMicro) */
		CARD_BACKUP_TYPE_FLASH_16MBITS,
		0x00200000,	0x00010000,	0x0100,	3,
		{
			79,
			0,	/* (not support) */
			0,	/* (not support) */
			629370,
			47202,
			0,	/* (not support) */
		},
	},

	{	/* 32 Mbit FLASH (STMicro) */
		CARD_BACKUP_TYPE_FLASH_32MBITS,
		0x00400000,	0x00010000,	0x0100,	3,
		{
			79,
			0,	/* (not support) */
			0,	/* (not support) */
			1258740,
			47202,
			0,	/* (not support) */
		},
	},

/* FRAM *************************************************************/

	/* No timeouts are needed. No page with read/write. */

	{	/* 64kbit FRAM */
		CARD_BACKUP_TYPE_FRAM_64KBITS,
		0x00002000,	0x00002000,	0x00002000,	2,
		{
			0,
			0,
			0,
			0,
			0,
		},
	},


	{	/* 256kbit FRAM */
		CARD_BACKUP_TYPE_FRAM_256KBITS,
		0x00008000,	0x00008000,	0x00008000,	2,
		{
			0,
			0,
			0,
			0,
			0,
		},
	},

#endif

	{	/* invalid device */
		CARD_BACKUP_TYPE_NOT_USE,
		0x00000000,	0x00000000,	0x0000,	0,
		{
			0,
			0,
			0,
			0,
			0,
		},
	}
} ;
