Changeset e07597b in avrstuff


Ignore:
Timestamp:
Jan 14, 2012, 9:54:32 PM (12 years ago)
Author:
Adrien Destugues <pulkomandy@…>
Branches:
main
Children:
e69146a
Parents:
4af90bf
Message:
  • Remove binary file for now
  • Make sure the output stays high when not generating pulses, and also stop the timer to get no interrupt storm.

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

Location:
V-USB_Dev/firmwares/CrO2
Files:
1 deleted
1 edited

Legend:

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

    r4af90bf re07597b  
    3535        readPos = 0;
    3636
     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
    3770        // Setup TIMER 1 for MFM pulses generation
    3871        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.
    3973        // CTC mode with OCR1A as MAXregister
    40         TCCR1B = (1<<WGM12) | (1<<CS10);
     74        TCCR1B = (1<<WGM12);
    4175        OCR1A = 12800; // 800us bit clock
    4276        OCR1B = 6400; // Half-clock for 1 bits
    4377        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)
    4479
    45         // TODO only start the timer when actually needed (start of block)
    46         // and stop it when done.
    4780        DDRB |= 2; // OC1A/PB1 as output
    4881
     
    5184                wdt_reset();
    5285                usbPoll();
    53 
    54                 // TODO send data to tape !
     86                // TODO watch for motor on/off
    5587        }
    5688}
     
    91123        {
    92124                // TODO leave place for sync header and block type+size
    93                 ioblock[writePos++] = data[i];
     125//              ioblock[writePos] = data[i];
     126                writePos++;
    94127        }
    95128
    96129        // TODO compute checksum as we go
    97130
    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        }
    99140        // returns 0: "needs more data"
    100141        // returns 1: "done"
     
    102143}
    103144
    104 ISR (TIMER1_COMPA_vect)
     145ISR (TIMER1_COMPA_vect, ISR_NOBLOCK)
    105146{
    106147        // generate next bit
     
    111152                bitpos = 0;
    112153                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                }
    115163        }
    116164}
    117165
    118 ISR (TIMER1_COMPB_vect)
     166ISR (TIMER1_COMPB_vect, ISR_NOBLOCK)
    119167{
    120168        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.