cardstatus.c
1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#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;
}