cardstatus.c 1.39 KB
#include <ultra64.h>
#include "bcp.h"
#include "bbnand.h"
#include "bbfs.h"
#include "os_bbcard.h"
#include "bbint.h"
#include "piint.h"

#define VERBOSE(x)

s32
osBbCardUnhappy(void) {
    if (!__osBbCardInit) return -1;
    else if (!__osBbCardPresent()) return BBCARD_ERR_NO_CARD;
    else if (__osBbCardChange) return BBCARD_ERR_CHANGED;
    else return 0;
}

s32
__osBbCardStatus(u32 dev, u8 *status, u32 buf) {
    s32 rv;
    u32 cmd = __osBbCardMultiplane ? NAND_CMD_MP_STATUS : NAND_CMD_STATUS;
    IO_WRITE(PI_FLASH_CTRL_REG, PI_FLASH_CTRL_START |
				PI_FLASH_CTRL_INTR |
				PI_FLASH_CTRL_RDPH |
				(cmd << PI_FLASH_CTRL_CMD_SHIFT) |
				(buf << PI_FLASH_CTRL_BUF_SHIFT) |
				(dev << PI_FLASH_CTRL_DEV_SHIFT) |
				(1 << PI_FLASH_CTRL_SIZE_SHIFT));
    rv = __osBbCardWaitEvent();
    *status =  rv ? 0 : (u8)((IO_READ(buf ? PI_BUFFER_1_START : PI_BUFFER_0_START)>>24) & 0xff);
    return rv;
}

s32
osBbCardStatus(u32 dev, u8 *status) {
    s32 rv;
    if ((rv = __osBbCardGetAccess()) < 0) return rv;
    rv = __osBbCardStatus(dev, status, 0);
    __osBbCardRelAccess();
    return rv;
}

s32
osBbCardChange(void) {
    return __osBbCardChange;
}

s32
osBbCardClearChange(void) {
    __osBbCardChange = 0;
    return __osBbCardPresent();
}

u32
osBbCardBlocks(u32 dev) {
    s32 rv;
    if ((rv = __osBbCardGetAccess()) < 0) return rv;
    rv = __osBbCardBlocks;
    __osBbCardRelAccess();
    return rv;
}