Changeset 3c17057 in avrstuff
- Timestamp:
- Jan 15, 2012, 10:44:43 AM (12 years ago)
- Branches:
- main
- Children:
- 89e680d
- Parents:
- e69146a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
V-USB_Dev/firmwares/CrO2/main.c
re69146a r3c17057 14 14 static uint16_t writePos; 15 15 static uint16_t blksz; 16 static uint8_t cksum; 16 17 17 18 static uint16_t readPos; … … 41 42 ioblock[i] = 1; 42 43 } 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 44 ioblock[16] = 0x3C; 45 ioblock[17] = 0x5A; 69 46 70 47 // Setup TIMER 1 for MFM pulses generation … … 89 66 90 67 68 static inline void startGen() 69 { 70 TCCR1A &= ~(1<<COM1A1); // Toggle output on compare match 71 TCCR1B |= (1<<CS10); // Enable timer clock (prescaler = 1) 72 } 73 74 91 75 uint8_t usbFunctionSetup(uint8_t data[8]) { 92 76 usbRequest_t *rq = (void *)data; … … 108 92 /* SEND DATA (USB > TAPE) */ 109 93 /* Get ready, actual data will come in usbFunctionWrite */ 110 // TODO store type of MO5 block + size in ioblock 111 writePos = 0; 112 blksz = rq->wLength.word; 113 return USB_NO_MSG; // Call usbFunctionWrite to send the data 94 95 // store type of MO5 block + size in ioblock 96 writePos = 20; // Leave space for Sync header, block type, and block size. 97 ioblock[18] = rq->wValue.word; 98 ioblock[19] = rq->wLength.word + 2; // Add blktype and cksum to data length 99 blksz = rq->wLength.word + 21; 100 cksum = 0; 101 if (rq->wLength.word == 0) 102 { 103 // No data in this block - start generating now ! 104 ioblock[20] = 0; // checksum 105 startGen(); 106 } else { 107 return USB_NO_MSG; // Call usbFunctionWrite to send the data 108 } 114 109 } 115 110 } … … 122 117 for (int i = 0; i < len; i++) 123 118 { 124 // TODO leave place for sync header and block type+size125 // ioblock[writePos]= data[i];119 ioblock[writePos] = data[i]; 120 cksum -= data[i]; 126 121 writePos++; 127 122 } 128 123 129 // TODO compute checksum as we go124 ioblock[writePos] = cksum; 130 125 131 if (writePos >= blksz )126 if (writePos >= blksz - 1) 132 127 { 133 128 // start generating 134 TCCR1A &= ~(1<<COM1A1); 135 TCCR1B |= (1<<CS10); 136 blksz = 35; 129 startGen(); 137 130 return 1; 138 131 } else { … … 155 148 if (readPos > blksz) 156 149 { 157 // Make sure output is high 150 // Make sure output is high step 1: match action = force high level 158 151 TCCR1A |= (1<<COM1A1); 152 159 153 // Stop generating (and interrupts) 160 154 TCCR1B &= ~(1<<CS10); 161 155 readPos = 0; 156 157 // make sure output is high step 2 : force a match. 162 158 TCCR1A |= (1 << FOC1A); 163 159 }
Note:
See TracChangeset
for help on using the changeset viewer.