Changeset e07597b in avrstuff for V-USB_Dev/firmwares/CrO2
- Timestamp:
- Jan 14, 2012, 9:54:32 PM (12 years ago)
- Branches:
- main
- Children:
- e69146a
- Parents:
- 4af90bf
- Location:
- V-USB_Dev/firmwares/CrO2
- Files:
-
- 1 deleted
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
V-USB_Dev/firmwares/CrO2/main.c
r4af90bf re07597b 35 35 readPos = 0; 36 36 37 // Generate sync header (this never changes) 38 int i; 39 for (i = 0; i< 16; i++) 40 { 41 ioblock[i] = 1; 42 } 43 ioblock[i++] = 0x3C; 44 ioblock[i++] = 0x5A; 45 46 // HEAD block 47 ioblock[i++] = 0x0; 48 ioblock[i++] = 0x10; 49 50 int j = i; 51 ioblock[i++] = 'C'; 52 ioblock[i++] = 'r'; 53 ioblock[i++] = 'O'; 54 ioblock[i++] = '2'; 55 ioblock[i++] = ' '; 56 ioblock[i++] = ' '; 57 ioblock[i++] = ' '; 58 ioblock[i++] = ' '; 59 ioblock[i++] = 'B'; 60 ioblock[i++] = 'A'; 61 ioblock[i++] = 'S'; 62 ioblock[i++] = 0; 63 ioblock[i++] = 0; 64 ioblock[i++] = 0; 65 uint8_t s = 0; 66 for (;j<i;j++) s -= ioblock[j]; 67 ioblock[i++] = s; 68 69 37 70 // Setup TIMER 1 for MFM pulses generation 38 71 TCCR1A = (1<<COM1A0); // Enable OC1A output 72 TCCR1A |= (1<<COM1A1); // Compare match will always SET OC1A instead of toggling it. Thus the output is always high. 39 73 // CTC mode with OCR1A as MAXregister 40 TCCR1B = (1<<WGM12) | (1<<CS10);74 TCCR1B = (1<<WGM12); 41 75 OCR1A = 12800; // 800us bit clock 42 76 OCR1B = 6400; // Half-clock for 1 bits 43 77 TIMSK = (1 << OCIE1B) | (1 << OCIE1A); // interrupts on both timer matches. 78 TCCR1A |= (bit << FOC1A); // Force toggle of A (make sure output is a logic 1 to allow MO5 to detect tapedrive) 44 79 45 // TODO only start the timer when actually needed (start of block)46 // and stop it when done.47 80 DDRB |= 2; // OC1A/PB1 as output 48 81 … … 51 84 wdt_reset(); 52 85 usbPoll(); 53 54 // TODO send data to tape ! 86 // TODO watch for motor on/off 55 87 } 56 88 } … … 91 123 { 92 124 // TODO leave place for sync header and block type+size 93 ioblock[writePos++] = data[i]; 125 // ioblock[writePos] = data[i]; 126 writePos++; 94 127 } 95 128 96 129 // TODO compute checksum as we go 97 130 98 return writePos>= blksz ? 1:0; 131 if (writePos >= blksz) 132 { 133 // start generating 134 TCCR1A &= ~(1<<COM1A1); 135 TCCR1B |= (1<<CS10); 136 return 1; 137 } else { 138 return 0; 139 } 99 140 // returns 0: "needs more data" 100 141 // returns 1: "done" … … 102 143 } 103 144 104 ISR (TIMER1_COMPA_vect )145 ISR (TIMER1_COMPA_vect, ISR_NOBLOCK) 105 146 { 106 147 // generate next bit … … 111 152 bitpos = 0; 112 153 readPos++; 113 if (readPos > 270) 114 readPos = 0; // TODO stop timer 154 if (readPos > blksz) 155 { 156 // Make sure output is high 157 TCCR1A |= (1<<COM1A1); 158 // Stop generating (and interrupts) 159 TCCR1B &= ~(1<<CS10); 160 readPos = 0; 161 TCCR1A |= (1 << FOC1A); 162 } 115 163 } 116 164 } 117 165 118 ISR (TIMER1_COMPB_vect )166 ISR (TIMER1_COMPB_vect, ISR_NOBLOCK) 119 167 { 120 168 TCCR1A |= (bit << FOC1A); // Force toggle of A on B compare when generating a 1 bit
Note:
See TracChangeset
for help on using the changeset viewer.