Changeset 34c57e8 in avrstuff
- Timestamp:
- Jul 7, 2012, 6:19:53 PM (11 years ago)
- Branches:
- main
- Children:
- a6ae6ac
- Parents:
- d09030d
- Location:
- EPRoxygen
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
EPRoxygen/Makefile
rd09030d r34c57e8 1 1 eproxygen: main.o at29c040.o 2 g++ $^ -o $@2 g++ -Wall -g -O3 -fno-rtti -fno-exceptions $^ -o $@ 3 3 4 4 %.o: %.cpp 5 g++ - c $^ -o $@5 g++ -Wall -g -save-temps -O3 -fno-rtti -fno-exceptions -c $^ -o $@ -
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 } -
EPRoxygen/at29c040.h
rd09030d r34c57e8 4 4 { 5 5 public: 6 AT29C040(); 7 8 void power(void); 9 void shutdown(void); 6 10 void read(const char* filename); 7 11 void write(const char* filename); 8 12 void erase(void); 13 private: 14 bool checkId(void); 15 16 // Write a byte to a 16-bit address (bits 16 17 18 are 0) 17 inline void wr16(uint16_t addr, uint8_t val) 18 { 19 Device::write(ADR0, addr); 20 Device::write(ADR1, addr >> 8); 21 22 Device::write(CTRL, OE | CTRLmask); 23 24 Device::write(DATA, val); 25 26 Device::write(CTRL, WE | OE | CTRLmask); 27 } 28 29 static const uint8_t CTRLmask = 0b01100000; 30 static const uint8_t VOLTmask = 0b10110011; 9 31 }; 10 32 -
EPRoxygen/device.h
rd09030d r34c57e8 4 4 #pragma once 5 5 6 #include <errno.h> 7 #include <stdio.h> 8 #include <stdint.h> 9 10 // FreeBSD 11 #include <sys/types.h> 12 #include <machine/cpufunc.h> 13 #include <machine/sysarch.h> 14 15 6 16 class Device { 7 17 public: 18 Device() 19 {}; 20 21 void shutdown(); 22 virtual void power() = 0; 23 8 24 virtual void read(const char* file) = 0; 9 25 virtual void write(const char* file) = 0; 10 26 virtual void erase(void) = 0; 27 28 int setup(const int port_base) { 29 port = port_base; 30 if (i386_set_ioperm(port_base, 3, true) != 0) 31 { 32 perror("Unable to get access to parallel port"); 33 return errno; 34 } 35 shutdown(); 36 37 return 0; 38 } 39 40 virtual ~Device() {}; 41 42 protected: 43 typedef enum { 44 NONE = 0b0101, /* Nothing selected */ 45 NYBLE = 0b0010, /* Read low nyble */ 46 /* When 0, status reg shows D0.3 47 * When 1, status reg shows D4.7 48 */ 49 CTRL = 0b0011, /* Control reg. */ 50 /* b0: A16 51 * b1: /A17 52 * b2: WE 53 * b3: A18 54 * b4: OE 55 * b5: VPP on pin 25 (0 = enable) 56 * b6: VPP on pin 24 (0 = enable) 57 * b7: CE 58 */ 59 VOLT = 0b0110, /* Power config reg. */ 60 /* b0: VPP on pin 1 (0 = enable) 61 * b1: VPP on pin 3 (0 = enable) 62 * b2: VCC on pin 32 (0 = enable) 63 * b3: Data reg. output enable (and green led) 64 * b4: VPP config 65 * b5: VPP config 66 * 00 = 24V 67 * 01 = ?? 68 * 10 = ?? 69 * 11 = 12V 70 * b6: Address reg. output enable 71 * b7: VCC enable (1 = power ON) 72 */ 73 ADR0 = 0b1011, /* Low address byte A0.7 */ 74 DATA = 0b1110, /* Data byte */ 75 ADR1 = 0b1111, /* High address byte A8.15 */ 76 } Register; 77 78 typedef enum { 79 A16 = 1, 80 A17 = 2, 81 WE = 4, 82 A18 = 8, 83 OE = 16, 84 VPP25 = 32, 85 VPP24 = 64, 86 CE = 128 87 } CTRLbits; 88 89 typedef enum { 90 VPP1 = 1, 91 VPP3 = 2, 92 VCC32 = 4, 93 DOE = 8, 94 95 V24 = 0, 96 V12 = 48, 97 98 AOE = 64, 99 VCC30 = 128 100 } VOLTbits; 101 102 static inline void write(const Register reg, const uint8_t val) 103 { 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 ! 107 outb(port + 2, reg); 108 outb(port, val); 109 } 110 111 static inline uint8_t read() 112 { 113 uint8_t byte = (inb(port + 1) ^ 0x80) & 0xF0; 114 115 outb(port+2, NYBLE); 116 byte |= (inb(port + 1) ^ 0x80) >> 4; 117 return byte; 118 } 119 120 private: 121 static int port; 11 122 }; 12 123 -
EPRoxygen/main.cpp
rd09030d r34c57e8 9 9 #include <getopt.h> 10 10 11 // FreeBSD12 #include <osreldate.h>13 #include <sys/types.h>14 #include <machine/cpufunc.h>15 #include <machine/sysarch.h>16 17 11 #include "device.h" 18 12 #include "at29c040.h" 19 13 20 /* TODO21 Linux compatibility (ioperm, reversed outb)22 wrap IOs in a class to hide the mess (BSD/Linux)23 wrap ROM access in a class as well (read or write a byte/block, and so on)24 */25 14 26 15 int main(int argc, char* argv[]) 27 16 { 28 17 char c; 29 const char* file ;18 const char* file = NULL; 30 19 char opcode = 0; 31 20 int port_base = 0x378; 32 21 Device* device = NULL; 22 int error = 0; 33 23 34 24 puts("EPRoxygen - UNIX driver for SEEIT EPR-02 ROM programmer\n" … … 37 27 ); 38 28 39 while( c = getopt(argc, argv, "p:d:r:w:e"))29 while((c = getopt(argc, argv, "p:d:r:w:e")) >= 0) 40 30 { 41 31 switch(c) … … 45 35 fprintf(stderr, "Unrecognized option -%c\n", optopt); 46 36 // TODO print help 47 exit(-1); 37 error = -1; 38 goto abort; 48 39 case 'p': 49 40 // Set port … … 51 42 { 52 43 fprintf(stderr, "Invalid I/O port address\n"); 53 exit(-4); 44 error = -4; 45 goto abort; 54 46 } 55 47 break; … … 59 51 { 60 52 fprintf(stderr,"Unknown device (only AT29C040 is supported)\n"); 61 exit(-3); 53 error = -3; 54 goto abort; 62 55 } 63 56 device = new AT29C040(); … … 73 66 { 74 67 fprintf(stderr, "Multiple operations requested (only one of r,w,e is allowed)\n"); 75 exit(-2); 68 error = -2; 69 goto abort; 76 70 } 77 71 opcode = c; … … 82 76 { 83 77 fprintf(stderr, "No operation specified (one of r,w,e). Aborting.\n"); 84 exit(-5); 78 error = -5; 79 goto abort; 85 80 } 86 81 87 i386_set_ioperm(port_base, 3, true); 82 if (device == NULL) 83 { 84 fprintf(stderr, "No device specified.\n"); 85 error = -6; 86 goto abort; 87 } 88 88 89 89 // Configure voltage and powerpins according to device 90 if(device->setup(port_base) != 0) 91 { 92 error = -7; 93 goto abort; 94 } 90 95 91 // Ask user to put ROM on socket 96 // TODO Ask user to put ROM on socket 97 puts("Now insert chip into socket, then press any key..."); 98 getchar(); 99 100 device->power(); 92 101 93 102 // Do action (program/erase/write) … … 103 112 device->erase(); 104 113 break; 114 default: 115 fprintf(stderr, "!!? invalid operation ?!\n"); 105 116 } 106 117 107 exit(0); 118 abort: 119 device->shutdown(); 120 delete device; 121 122 exit(error); 108 123 } 109 124 125 int Device::port; 110 126 111
Note:
See TracChangeset
for help on using the changeset viewer.