/*---------------------------------------------------------------------------*
  Project:  NitroSDK - CARD - include
  File:     backup.h

  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: backup.h,v $
  Revision 1.5  2004/09/06 13:44:31  yosizaki
  move CARD_(Lock/Unlock)Backup

  Revision 1.4  2004/08/23 10:39:07  yosizaki
  add write-command.
  delete erase-command. (FLASH)

  Revision 1.3  2004/08/18 13:40:49  yosizaki
  add FLASH 2Mbit.

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

  Revision 1.1  2004/07/23 08:32:18  yosizaki
  (none)

  $NoKeywords: $
 *---------------------------------------------------------------------------*/


#if	!defined(NITRO_CARD_BACKUP_H_)
#define NITRO_CARD_BACKUP_H_


#include <nitro/types.h>


#if	defined(__cplusplus)
extern "C" {
#endif


void	CARD_LockBackup(u16 lock_id);
void	CARD_UnlockBackup(u16 lock_id);


BOOL	CARDi_ReadBackup(u32 src, void *dst, u32 len, MIDmaCallback callback, void *arg, BOOL is_async);
BOOL	CARDi_ProgramBackup(u32 dst, const void *src, u32 len, MIDmaCallback callback, void *arg, BOOL is_async);
BOOL	CARDi_WriteBackup(u32 dst, const void *src, u32 len, MIDmaCallback callback, void *arg, BOOL is_async);
BOOL	CARDi_VerifyBackup(u32 dst, const void *src, u32 len, MIDmaCallback callback, void *arg, BOOL is_async);
BOOL	CARDi_ProgramAndVerifyBackup(u32 dst, const void *src, u32 len, MIDmaCallback callback, void *arg, BOOL is_async);
BOOL	CARDi_WriteAndVerifyBackup(u32 dst, const void *src, u32 len, MIDmaCallback callback, void *arg, BOOL is_async);


/* Data read (equivalent to chip command "read") */
static inline void	CARD_ReadBackupAsync(
	u32 src, void *dst, u32 len,
	MIDmaCallback callback, void *arg)
{
	(void)CARDi_ReadBackup(src, dst, len, callback, arg, TRUE);
}
static inline BOOL	CARD_ReadBackup(u32 src, void *dst, u32 len)
{
	return	CARDi_ReadBackup(src, dst, len, NULL, NULL, FALSE);
}

/* Data program (equivalent to chip command "program") */
static inline void	CARD_ProgramBackupAsync(
	u32 dst, const void *src, u32 len,
	MIDmaCallback callback, void *arg)
{
	(void)CARDi_ProgramBackup(dst, src, len, callback, arg, TRUE);
}
static inline BOOL	CARD_ProgramBackup(u32 dst, const void *src, u32 len)
{
	return	CARDi_ProgramBackup(dst, src, len, NULL, NULL, FALSE);
}

/* Data write (equvalent to chip command "write") */
static inline void	CARD_WriteBackupAsync(
	u32 dst, const void *src, u32 len,
	MIDmaCallback callback, void *arg)
{
	(void)CARDi_WriteBackup(dst, src, len, callback, arg, TRUE);
}
static inline BOOL	CARD_WriteBackup(u32 dst, const void *src, u32 len)
{
	return	CARDi_WriteBackup(dst, src, len, NULL, NULL, FALSE);
}

/* Data verify (use chip command "read") */
static inline void	CARD_VerifyBackupAsync(
	u32 dst, const void *src, u32 len,
	MIDmaCallback callback, void *arg)
{
	(void)CARDi_VerifyBackup(dst, src, len, callback, arg, TRUE);
}
static inline BOOL	CARD_VerifyBackup(u32 dst, const void *src, u32 len)
{
	return	CARDi_VerifyBackup(dst, src, len, NULL, NULL, FALSE);
}

/* Data program + Verify */
static inline void	CARD_ProgramAndVerifyBackupAsync(
	u32 dst, const void *src, u32 len,
	MIDmaCallback callback, void *arg)
{
	(void)CARDi_ProgramAndVerifyBackup(dst, src, len, callback, arg, TRUE);
}
static inline BOOL	CARD_ProgramAndVerifyBackup(u32 dst, const void *src, u32 len)
{
	return	CARDi_ProgramAndVerifyBackup(dst, src, len, NULL, NULL, FALSE);
}

/* Data write + Verify */
static inline void	CARD_WriteAndVerifyBackupAsync(
	u32 dst, const void *src, u32 len,
	MIDmaCallback callback, void *arg)
{
	(void)CARDi_WriteAndVerifyBackup(dst, src, len, callback, arg, TRUE);
}
static inline BOOL	CARD_WriteAndVerifyBackup(u32 dst, const void *src, u32 len)
{
	return	CARDi_WriteAndVerifyBackup(dst, src, len, NULL, NULL, FALSE);
}


/* Wait for asynchronous */
BOOL	CARD_TryWaitBackupAsync(void);
BOOL	CARD_WaitBackupAsync(void);


#if	defined(__cplusplus)
} /* extern "C" */
#endif


#endif	/* NITRO_CARD_BACKUP_H_ */
