Subversion Repositories pentevo

Rev

Rev 6 | Rev 71 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #include <avr/io.h>
  2. #include <avr/interrupt.h>
  3. #include <avr/pgmspace.h>
  4.  
  5. #include <util/delay.h>
  6.  
  7.  
  8. #include "mytypes.h"
  9. #include "depacker_dirty.h"
  10. #include "getfaraddress.h"
  11. #include "pins.h"
  12.  
  13. #include "ps2.h"
  14. #include "zx.h"
  15. #include "spi.h"
  16.  
  17.  
  18.  
  19.  
  20.  
  21. extern const char fpga[] PROGMEM; // linker symbol
  22.  
  23.  
  24. ULONG indata;
  25. UBYTE dbuf[DBSIZE];
  26.  
  27.  
  28.  
  29.  
  30.  
  31. void InitHardware(void);
  32.  
  33.  
  34. int main()
  35. {
  36.         UBYTE j;
  37.  
  38.  
  39.         InitHardware();
  40.  
  41.  
  42.  
  43.  
  44.         PORTF |= (1<<PF3); // turn POWER on
  45.  
  46.         j=50;
  47.         do _delay_ms(20); while(--j); //1 sec delay
  48.  
  49.  
  50.         //begin configuring, led ON
  51.         PORTB &= ~(1<<LED);
  52.  
  53.  
  54.         spi_init();
  55.  
  56.  
  57.  
  58.         DDRF |= (1<<nCONFIG); // pull low for a time
  59.         _delay_us(40);
  60.         DDRF &= ~(1<<nCONFIG);
  61.         while( !(PINF & (1<<nSTATUS)) ); // wait ready
  62.         indata = (ULONG)GET_FAR_ADDRESS(fpga); // prepare for data fetching
  63.         depacker_dirty();
  64.  
  65.  
  66.         //LED off
  67.         PORTB |= (1<<LED);
  68.  
  69.  
  70.  
  71.         // start timer (led dimming and timeouts for ps/2)
  72.         TCCR2 = 0b01110011; // FOC2=0, {WGM21,WGM20}=01, {COM21,COM20}=11, {CS22,CS21,CS20}=011
  73.                             // clk/64 clocking,
  74.                             // 1/512 overflow rate, total 11.059/32768 = 337.5 Hz interrupt rate
  75.         TIFR = (1<<TOV2);
  76.         TIMSK = (1<<TOIE2);
  77.  
  78.  
  79.         ps2_count = 11;
  80.  
  81.         EICRB = (1<<ISC41) + (0<<ISC40); // falling edge INT4
  82.         EIFR = (1<<INTF4); // clear spurious ints there
  83.         EIMSK |= (1<<INT4); // enable int4
  84.  
  85.         zx_init();
  86.  
  87.         sei(); // globally go interrupting
  88.  
  89.  
  90.         for(;;)
  91.         {
  92.                 ps2_task();
  93.                 zx_task(ZX_TASK_WORK);
  94.         }
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107. }
  108.  
  109. void InitHardware(void)
  110. {
  111.  
  112.         cli(); // disable interrupts
  113.  
  114.  
  115.  
  116.         // configure pins
  117.  
  118.         PORTG = 0b11111111;
  119.         DDRG  = 0b00000000;
  120.  
  121.         PORTF = 0b11110000; // ATX off (zero output), fpga config/etc inputs
  122.         DDRF  = 0b00001000;
  123.  
  124.         PORTE = 0b11111111;
  125.         DDRE  = 0b00000000; // inputs pulled up
  126.  
  127.         PORTD = 0b11111111;
  128.         DDRD  = 0b00000000; // same
  129.  
  130.         PORTC = 0b11011111;
  131.         DDRC  = 0b00000000; // PWRGOOD input, other pulled up
  132.  
  133.         PORTB = 0b11110001;
  134.         DDRB  = 0b10000111; // LED off, spi outs inactive
  135.  
  136.         PORTA = 0b11111111;
  137.         DDRA  = 0b00000000; // pulled up
  138.  
  139.  
  140.         ACSR = 0x80; // DISABLE analog comparator
  141. }
  142.  
  143.  
  144. void put_buffer(UWORD size)
  145. { // writes specified length of buffer to the output
  146.         UBYTE * ptr;
  147.         ptr=dbuf;
  148.  
  149.         do
  150.         {
  151.                 spi_send( *(ptr++) );
  152.  
  153.         } while(--size);
  154. }
  155.  
  156.