#ident "$Id: card-lock.h,v 1.3 2006/11/15 00:21:15 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_LOCK_H
#define CARD_LOCK_H

#include "card-api.h"

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

/*
 * Wait until no other thread is accessing the card, then indicate
 * that this thread is accessing the card.

 * Does what CARDi_WaitTask does in Nintendo's card code, except
 * it doesn't set the callbacks
 */
static inline void
CARD_WaitIdle(void)
{
    OSIntrMode  mode;

    mode = OS_DisableInterrupts();
    while ((CardStatus & CARD_BUSY) != 0) {
        OS_SleepThread(CardBusyQueue);
    }
    CardStatus |= CARD_BUSY;
    OS_RestoreInterrupts(mode);
}

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

/*
 * Does what CARDi_WaitAsync does in Nintendo's card code.
 */
static inline BOOL
CARD_WaitDone(void)
{
    OSIntrMode  mode;

    mode = OS_DisableInterrupts();
    while ((CardStatus & CARD_BUSY) != 0) {
        OS_SleepThread(CardBusyQueue);
    }
    OS_RestoreInterrupts(mode);
    return(CardCommand.result == CARD_RESULT_SUCCESS);
}

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

#endif
