blob: 9db5cd0bc6f087bf93f22418caeb4d2aaec310f5 [file] [log] [blame]
Adrien Destugues16cf6ff2012-07-12 20:20:53 +00001#include "27c020.h"
2
3#include <stdio.h>
4#include <unistd.h>
5
6
7x27C020::x27C020()
8 : Device()
9{
10}
11
12void x27C020::power()
13{
14 Device::write(CTRL, 0b10011111 | CTRLmask);
15 Device::write(VOLT, 0b11001000 | VOLTmask);
16 outb(port + 2, NONE);
17}
18
19void x27C020::read(const char* filename)
20{
21 for (int address = 0; address < 256*1024; address++)
22 {
23 Device::write(VOLT, DOE | VOLTmask);
24 Device::write(CTRL, CE | OE | WE | A17 | CTRLmask);
25 usleep(1000);
26
27 Device::write(ADR0, address);
28 usleep(1000);
29 Device::write(ADR1, address >> 8);
30 usleep(1000);
31 // TODO A16, A17
32 Device::write(CTRL, WE | A17 | CTRLmask);
33 usleep(1000);
34 uint8_t val = Device::read();
35 Device::write(CTRL, CE | OE | WE | A17 | CTRLmask);
36
37 // TODO write to file, or stdout if file is null
38 putc(val, stdout);
39 // TODO flush every 512 bytes or so
40 fflush(stdout);
41 }
42}
43
44void x27C020::write(const char* filename)
45{
46 // TODO support it !
47 puts("Writing not supported");
48}
49
50void x27C020::erase(void)
51{
52 // TODO return error
53 puts("Erasing not supported");
54}
55