Changeset a6ae6ac in avrstuff
- Timestamp:
- Jul 9, 2012, 11:05:43 PM (11 years ago)
- Branches:
- main
- Children:
- 16cf6ff
- Parents:
- 34c57e8
- Location:
- EPRoxygen
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
EPRoxygen/at29c040.cpp
r34c57e8 ra6ae6ac 14 14 Device::write(CTRL, 0b10011111 | CTRLmask); 15 15 Device::write(VOLT, 0b11001000 | VOLTmask); 16 outb(port + 2, NONE); 16 17 } 17 18 … … 20 21 // All pins of the ROM are put either in high-Z, or 0V when it's not 21 22 // possible 22 Device::write(CTRL, 0 x62);23 Device::write(VOLT, 0 x7F);23 Device::write(CTRL, 0b01100010); 24 Device::write(VOLT, 0b01111111); 24 25 outb(port + 2, NONE); 25 26 } … … 51 52 { 52 53 // Chip enable 53 Device::write(CTRL, CTRLmask | CE);54 Device::write(CTRL, CTRLmask | WE | OE | CE | A17); 54 55 // Address bits low, WE = 1, CE = 0, OE = 1 55 56 // TC and TD = 1 … … 60 61 61 62 wr16(0x5555, 0xAA); 62 wr16(0x 2AAA, 0x55);63 wr16(0xAAAA, 0x55); 63 64 wr16(0x5555, 0x90); 64 65 … … 70 71 // Read the result now 71 72 Device::write(ADR0, 0x00); 72 Device::write(ADR1, 0x00); 73 Device::write(CTRL, WE | CE | CTRLmask); 73 usleep(1000); 74 Device::write(ADR1, 0x00 ^ A13); 75 usleep(1000); 76 Device::write(CTRL, WE | A17 | CTRLmask); 77 usleep(1000); 74 78 uint8_t manufacturer = Device::read(); 75 79 76 getchar();77 80 78 Device::write(CTRL, OE | WE | CE | CTRLmask); 81 Device::write(CTRL, CE | OE | WE | A17 | CTRLmask); 82 usleep(1000); 79 83 Device::write(ADR0, 0x01); 80 Device::write(CTRL, WE | CE | CTRLmask); 84 usleep(1000); 85 Device::write(CTRL, WE | A17 | CTRLmask); 86 usleep(1000); 81 87 82 88 uint8_t product = Device::read(); 83 89 90 Device::write(CTRL, CE | WE | OE | A17 | CTRLmask); 91 usleep(1000); 84 92 // re enable DOE, we are going to write again... 85 Device::write(CTRL, WE | OE | CE | CTRLmask);86 93 Device::write(VOLT, VOLTmask); 94 usleep(1000); 87 95 88 96 wr16(0x5555, 0xAA); 89 wr16(0x 2AAA, 0x55);97 wr16(0xAAAA, 0x55); 90 98 wr16(0x5555, 0xF0); 91 99 usleep(10000); … … 93 101 // Chip disable - we're done ! 94 102 Device::write(CTRL, 0xFF | CTRLmask); 103 usleep(1000); 95 104 96 105 bool ok = (manufacturer == 0x1F && product == 0xA4); -
EPRoxygen/at29c040.h
r34c57e8 ra6ae6ac 17 17 inline void wr16(uint16_t addr, uint8_t val) 18 18 { 19 Device::write(CTRL, A17 | CE | WE | OE | CTRLmask); 20 usleep(10000); 21 22 Device::write(ADR1, (addr >> 8) ^ A13); 23 usleep(10000); 19 24 Device::write(ADR0, addr); 20 Device::write(ADR1, addr >> 8); 21 22 Device::write(CTRL, OE | CTRLmask); 25 usleep(10000); 23 26 24 27 Device::write(DATA, val); 28 usleep(10000); 29 Device::write(CTRL, A17 | OE | CTRLmask); 30 usleep(10000); 25 31 26 Device::write(CTRL, WE | OE | CTRLmask); 32 printf("W %X %X", addr, val); 33 getchar(); 34 Device::write(CTRL, A17 | CE | WE | OE | CTRLmask); 35 usleep(10000); 27 36 } 28 37 -
EPRoxygen/device.h
r34c57e8 ra6ae6ac 7 7 #include <stdio.h> 8 8 #include <stdint.h> 9 #include <unistd.h> 9 10 10 11 // FreeBSD … … 42 43 protected: 43 44 typedef enum { 44 NONE = 0b0 101, /* Nothing selected */45 NYBLE = 0b0 010, /* Read low nyble */45 NONE = 0b0011, /* Nothing selected */ 46 NYBLE = 0b0100, /* Read low nyble */ 46 47 /* When 0, status reg shows D0.3 47 48 * When 1, status reg shows D4.7 48 49 */ 49 CTRL = 0b0 011, /* Control reg. */50 CTRL = 0b0101, /* Control reg. */ 50 51 /* b0: A16 51 * b1: /A17 52 * b1: /A17 (A17 is reversed !) 52 53 * b2: WE 53 54 * b3: A18 … … 71 72 * b7: VCC enable (1 = power ON) 72 73 */ 73 ADR0 = 0b1 011, /* Low address byte A0.7 */74 ADR0 = 0b1101, /* Low address byte A0.7 */ 74 75 DATA = 0b1110, /* Data byte */ 75 76 ADR1 = 0b1111, /* High address byte A8.15 */ 77 /* A13 is reversed ! (also used as VCC pin in smaller packages) 78 */ 76 79 } Register; 80 81 static const uint8_t A13 = 1 << 5; 77 82 78 83 typedef enum { … … 102 107 static inline void write(const Register reg, const uint8_t val) 103 108 { 104 // The register latches the data only when another register gets 105 // selected. If this is a problem, select the NONE reg after 106 // writing ! 109 // To avoid glitches, first set the bits that select the register, 110 // then enable the output. And disable the output when we are done 111 // while not touching the selected reg. This is the only way to 112 // avoid glitches (another reg may be selected long enough for 113 // losing some bits) 114 outb(port, val); 115 usleep(1000); 116 outb(port + 2, reg ^ 4); 117 usleep(1000); 107 118 outb(port + 2, reg); 108 outb(port, val); 119 usleep(1000); 120 outb(port + 2, reg ^ 4); 121 usleep(1000); 109 122 } 110 123 111 124 static inline uint8_t read() 112 125 { 113 uint8_t byte = (inb(port + 1) ^ 0x80) & 0xF0; 126 outb(port+2, NYBLE ^ 4); 127 usleep(1000); 128 uint8_t byte = inb(port + 1) & 0xF0; 114 129 115 130 outb(port+2, NYBLE); 116 byte |= (inb(port + 1) ^ 0x80) >> 4; 117 return byte; 131 usleep(1000); 132 byte |= inb(port + 1) >> 4; 133 printf("R %X", byte ^ 0x88); 134 getchar(); 135 outb(port+2, NYBLE ^ 4); 136 usleep(1000); 137 return byte ^ 0x88; 118 138 } 119 139 140 static int port; 120 141 private: 121 static int port;122 142 }; 123 143
Note:
See TracChangeset
for help on using the changeset viewer.