cardprobe.c
1.11 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
#include <ultra64.h>
#include "bcp.h"
#include "bbnand.h"
#include "bbfs.h"
#include "os_bbcard.h"
#include "bbint.h"
#include "piint.h"
s32
osBbCardProbe(u32 dev) {
s32 count, rv;
u8 save = __osBbCardChange;
__osBbCardChange = 0;
if ((rv = __osBbCardGetAccess()) < 0) return rv;
IO_WRITE(PI_BUFFER_0_START, 0);
IO_WRITE(PI_FLASH_CTRL_REG, PI_FLASH_CTRL_START |
PI_FLASH_CTRL_RDPH |
(NAND_CMD_STATUS << PI_FLASH_CTRL_CMD_SHIFT) |
(0 << PI_FLASH_CTRL_BUF_SHIFT) |
(dev << PI_FLASH_CTRL_DEV_SHIFT) |
(1 << PI_FLASH_CTRL_SIZE_SHIFT));
rv = BBCARD_ERR_NO_CARD;
count = 0;
while(count < 1000) {
if (!(IO_READ(PI_FLASH_CTRL_REG)&PI_FLASH_CTRL_BUSY)) {
if (((IO_READ(PI_BUFFER_0_START)>>24)&0xff) ==
(NAND_STATUS_WRITE_OK|NAND_STATUS_READY)) {
#ifdef _DEBUG
osSyncPrintf("probe succeeds\n");
#endif
__osBbCardFlushEvent();
rv = 0;
goto out;
}
break;
}
__osBbDelay(10);
count++;
}
IO_WRITE(PI_FLASH_CTRL_REG, 0);
__osBbCardChange = save;
#ifdef _DEBUG
osSyncPrintf("probe fails\n");
#endif
out:
__osBbCardRelAccess();
return rv;
}