#ident "$Id: card-api.h,v 1.11 2006/12/29 22:36:03 craig Exp $"
/*
 *               Copyright (C) 2005, BroadOn Communications Corp.
 *
 *  These coded instructions, statements, and computer programs contain
 *  unpublished  proprietary information of BroadOn Communications Corp.,
 *  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 BroadOn Communications Corp.
 *
 */

#ifndef CARD_API_H
#define CARD_API_H

#define         BACKUP_MEM_FILE_NAME    "backup.data"
#define         TEMP_DIRECTORY_NAME     "/tmp"

typedef s32 CARDiOwner;

extern volatile u32 CardStatus;

enum {
    CARD_BUSY              = 0x1,       // Like CARD_STAT_BUSY
    CARD_ASYNC_BUSY        = 0x2,       // Like CARD_STAT_TASK
    CARD_CANCEL_BACKUP_OP  = 0x4        // Like CARD_STAT_CANCEL
};

typedef enum
{
    CARD_TARGET_NONE,
    CARD_TARGET_ROM,
    CARD_TARGET_BACKUP
}
CARDTargetMode;


typedef struct cardCommand_t {
    u32                 srcAddr;        
    u32                 length;
    u32                 destAddr;
    CARDRequest         req_type;      // Used for backup memory functions
    int                 req_retry;     // Used for backup memory functions
    CARDRequestMode     req_mode;      // Used for backup memory functions
    MIDmaCallback       callbackFunc;
    void                *callbackArg;
    CARDResult          result;        // Result of last card operation
} cardCommand_t;

extern cardCommand_t    CardCommand;
extern OSThreadQueue    CardBusyQueue[];
extern OSThread         *CurrentThread;
extern char             *TitleDataDir;

void CARDi_LockResource(CARDiOwner owner, CARDTargetMode target);
void CARDi_UnlockResource(CARDiOwner owner, CARDTargetMode target);
BOOL CARDi_IsIdle(void);
void CARDi_AssignAsyncWork(void (*whichFunc) (cardCommand_t *command));
void CARDi_EndCardAccess(BOOL isOwnTask);
void CARDi_FatalError(const char* const message);

// TODO: Comment these out for production
// #define DEBUG(...)      printf(__VA_ARGS__)
// #define THREAD_DEBUG(...) printf(__VA_ARGS__)
#define WARN(...)       printf(__VA_ARGS__)
#define ERROR(...)      printf(__VA_ARGS__)

// For production, these should be active
#define DEBUG(...)
#define THREAD_DEBUG(...)
// #define WARN(...)
// #define ERROR(...)

#endif // CARD_API_H
