flread.c
1.64 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
63
64
65
#include "cpusim.h"
#include "bbnand.h"
void
passed(void) {
message("test flread passed\n");
test_postamble();
}
void
failed(const char* code) {
message("test flread failed (");
message(code);
message(")\n");
test_postamble();
}
static inline int
read_page(unsigned addr, int which_buf) {
IO_WRITE(PI_FLASH_ADDR_REG, addr << PI_FLASH_PAGE_ADDR_SHIFT);
IO_WRITE(PI_FLASH_CTRL_REG, PI_FLASH_CTRL_START |
PI_FLASH_CTRL_RDPH |
0xf << PI_FLASH_CTRL_ADPH_SHIFT |
0x0 << PI_FLASH_CTRL_CMD_SHIFT |
PI_FLASH_CTRL_WRDY |
which_buf << PI_FLASH_CTRL_BUF_SHIFT |
0 << PI_FLASH_CTRL_DEV_SHIFT |
PI_FLASH_CTRL_ECC |
528);
do {
if (IO_READ(MI_EINTR_REG)&MI_INTR_MD) return 1;
} while(IO_READ(PI_FLASH_CTRL_REG)&PI_FLASH_CTRL_BUSY);
return (IO_READ(PI_FLASH_CTRL_REG) & PI_FLASH_CTRL_DBERR) ? 1 : 0;
}
int
main() {
int i;
unsigned short csum = 0;
test_preamble();
/* configure flash */
IO_WRITE(PI_FLASH_CONFIG_REG, 7 << 28 | // end of cycle time - 2
5 << 24 | // read data sample time - 1
0x3e << 16 | // RE active time
0x1f << 8 | // WE active time
0x3f << 0); // CLE/ALE active time
if (read_page(1, 0)) {
failed("0");
}
for(i = 0; i < 512/4; i++) {
unsigned x = IO_READ(PI_BUFFER_0_START+i*4);
csum += (x >> 24) + ((x >> 16)&0xff) + ((x >> 8)&0xff) + (x&0xff) ;
}
for(i = 0; i < 16/4; i++) {
unsigned x = IO_READ(PI_BUFFER_0_OOB_START+i*4);
csum += (x >> 24) + ((x >> 16)&0xff) + ((x >> 8)&0xff) + (x&0xff) ;
}
IO_WRITE(PI_IDE3_BASE_REG, csum);
if (csum == 0x01c2)
passed();
else
failed("1");
return 0;
}