Changeset 3c17057 in avrstuff


Ignore:
Timestamp:
Jan 15, 2012, 10:44:43 AM (12 years ago)
Author:
Adrien Destugues <pulkomandy@…>
Branches:
main
Children:
89e680d
Parents:
e69146a
Message:

Fix bugs related to minimal-size blocks. Loading a standard game works !

git-svn-id: svn://pulkomandy.tk/avrstuff@54 c6672c3c-f6b6-47f9-9001-1fd6b12fecbe

File:
1 edited

Legend:

Unmodified
Added
Removed
  • V-USB_Dev/firmwares/CrO2/main.c

    re69146a r3c17057  
    1414static uint16_t writePos;
    1515static uint16_t blksz;
     16static uint8_t cksum;
    1617
    1718static uint16_t readPos;
     
    4142                ioblock[i] = 1;
    4243        }
    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;
    6946
    7047        // Setup TIMER 1 for MFM pulses generation
     
    8966
    9067
     68static 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
    9175uint8_t usbFunctionSetup(uint8_t data[8]) {
    9276        usbRequest_t *rq = (void *)data;
     
    10892                                /* SEND DATA (USB > TAPE) */
    10993                                /* 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                                }
    114109                        }
    115110        }
     
    122117        for (int i = 0; i < len; i++)
    123118        {
    124                 // TODO leave place for sync header and block type+size
    125 //              ioblock[writePos] = data[i];
     119                ioblock[writePos] = data[i];
     120                cksum -= data[i];
    126121                writePos++;
    127122        }
    128123
    129         // TODO compute checksum as we go
     124        ioblock[writePos] = cksum;
    130125
    131         if (writePos >= blksz)
     126        if (writePos >= blksz - 1)
    132127        {
    133128                // start generating
    134                 TCCR1A &= ~(1<<COM1A1);
    135                 TCCR1B |= (1<<CS10);
    136                 blksz = 35;
     129                startGen();
    137130                return 1;
    138131        } else {
     
    155148                if (readPos > blksz)
    156149                {
    157                         // Make sure output is high
     150                        // Make sure output is high step 1: match action = force high level
    158151                        TCCR1A |= (1<<COM1A1);
     152
    159153                        // Stop generating (and interrupts)
    160154                        TCCR1B &= ~(1<<CS10);
    161155                        readPos = 0;
     156
     157                        // make sure output is high step 2 : force a match.
    162158                        TCCR1A |= (1 << FOC1A);
    163159                }
Note: See TracChangeset for help on using the changeset viewer.