source: avrstuff/EPRoxygen/at29c040.cpp@ 34c57e8

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

More work.

  • Power on/off sequence OK
  • Code to read chip ID written, but not working yet...

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

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