source: avrstuff/EPRoxygen/at29c040.cpp@ a6ae6ac

main
Last change on this file since a6ae6ac was a6ae6ac, checked in by Adrien Destugues <pulkomandy@…>, 12 years ago

Still not working...
Added very agressive timing, fixed some potential glitches, but still not enough to even read the device ID !

git-svn-id: svn://pulkomandy.tk/avrstuff@60 c6672c3c-f6b6-47f9-9001-1fd6b12fecbe

  • Property mode set to 100644
File size: 2.1 KB
Line 
1#include "at29c040.h"
2
3#include <stdio.h>
4#include <unistd.h>
5
6
7AT29C040::AT29C040()
8 : Device()
9{
10}
11
12void AT29C040::power()
13{
14 Device::write(CTRL, 0b10011111 | CTRLmask);
15 Device::write(VOLT, 0b11001000 | VOLTmask);
16 outb(port + 2, NONE);
17}
18
19void Device::shutdown()
20{
21 // All pins of the ROM are put either in high-Z, or 0V when it's not
22 // possible
23 Device::write(CTRL, 0b01100010);
24 Device::write(VOLT, 0b01111111);
25 outb(port + 2, NONE);
26}
27
28void AT29C040::read(const char* filename)
29{
30 if (!checkId()) {
31 return;
32 }
33}
34
35void AT29C040::write(const char* filename)
36{
37 if (!checkId()) {
38 return;
39 }
40}
41
42void AT29C040::erase(void)
43{
44 if (!checkId()) {
45 return;
46 }
47
48 puts("Perfomring chip erase...");
49}
50
51bool AT29C040::checkId(void)
52{
53 // Chip enable
54 Device::write(CTRL, CTRLmask | WE | OE | CE | A17);
55 // Address bits low, WE = 1, CE = 0, OE = 1
56 // TC and TD = 1
57 Device::write(VOLT, VOLTmask);
58 // D and A OE = 0
59 // VPP config ?
60 // TA, TB, TE, TF = ?
61
62 wr16(0x5555, 0xAA);
63 wr16(0xAAAA, 0x55);
64 wr16(0x5555, 0x90);
65
66 // clear DOE for reading
67 Device::write(VOLT, DOE | VOLTmask);
68
69 usleep(10000);
70
71 // Read the result now
72 Device::write(ADR0, 0x00);
73 usleep(1000);
74 Device::write(ADR1, 0x00 ^ A13);
75 usleep(1000);
76 Device::write(CTRL, WE | A17 | CTRLmask);
77 usleep(1000);
78 uint8_t manufacturer = Device::read();
79
80
81 Device::write(CTRL, CE | OE | WE | A17 | CTRLmask);
82 usleep(1000);
83 Device::write(ADR0, 0x01);
84 usleep(1000);
85 Device::write(CTRL, WE | A17 | CTRLmask);
86 usleep(1000);
87
88 uint8_t product = Device::read();
89
90 Device::write(CTRL, CE | WE | OE | A17 | CTRLmask);
91 usleep(1000);
92 // re enable DOE, we are going to write again...
93 Device::write(VOLT, VOLTmask);
94 usleep(1000);
95
96 wr16(0x5555, 0xAA);
97 wr16(0xAAAA, 0x55);
98 wr16(0x5555, 0xF0);
99 usleep(10000);
100
101 // Chip disable - we're done !
102 Device::write(CTRL, 0xFF | CTRLmask);
103 usleep(1000);
104
105 bool ok = (manufacturer == 0x1F && product == 0xA4);
106
107 if (!ok)
108 {
109 fprintf(stderr, "Chip ID %X:%X does not match expected %X:%X\n",
110 manufacturer, product, 0x1F, 0xA4);
111 } else {
112 fprintf(stderr, "AT29C040 detected successfully!\n");
113 }
114
115 return ok;
116}
Note: See TracBrowser for help on using the repository browser.