Changeset 34c57e8 in avrstuff for EPRoxygen/at29c040.cpp
- Timestamp:
- Jul 7, 2012, 6:19:53 PM (12 years ago)
- Branches:
- main
- Children:
- a6ae6ac
- Parents:
- d09030d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
EPRoxygen/at29c040.cpp
rd09030d r34c57e8 1 1 #include "at29c040.h" 2 3 #include <stdio.h> 4 #include <unistd.h> 5 6 7 AT29C040::AT29C040() 8 : Device() 9 { 10 } 11 12 void AT29C040::power() 13 { 14 Device::write(CTRL, 0b10011111 | CTRLmask); 15 Device::write(VOLT, 0b11001000 | VOLTmask); 16 } 17 18 void 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 } 2 26 3 27 void AT29C040::read(const char* filename) 4 28 { 29 if (!checkId()) { 30 return; 31 } 5 32 } 6 33 7 34 void AT29C040::write(const char* filename) 8 35 { 36 if (!checkId()) { 37 return; 38 } 9 39 } 10 40 11 41 void AT29C040::erase(void) 12 42 { 43 if (!checkId()) { 44 return; 45 } 46 47 puts("Perfomring chip erase..."); 13 48 } 49 50 bool 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 TracChangeset
for help on using the changeset viewer.