Subversion Repositories pentevo

Rev

Rev 104 | Rev 129 | 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. #include "mytypes.h"
  8. #include "depacker_dirty.h"
  9. #include "getfaraddress.h"
  10. #include "pins.h"
  11.  
  12. #include "ps2.h"
  13. #include "zx.h"
  14. #include "spi.h"
  15. #include "rs232.h"
  16. #include "rtc.h"
  17. #include "atx.h"
  18. #include "joystick.h"
  19.  
  20. //fpga compressed data
  21. extern const char fpga[] PROGMEM; // linker symbol
  22.  
  23. ULONG indata;
  24.  
  25. //buffer for depacking FPGA configuration
  26. //you can USED for other purposed after setup FPGA
  27. UBYTE dbuf[DBSIZE];
  28.  
  29. void put_buffer(UWORD size)
  30. {
  31.         // writes specified length of buffer to the output
  32.         UBYTE * ptr = dbuf;
  33.  
  34.         do
  35.         {
  36.                 spi_send( *(ptr++) );
  37.  
  38.         } while(--size);
  39. }
  40.  
  41. void hardware_init(void)
  42. {
  43.         //Initialized AVR pins
  44.  
  45.         cli(); // disable interrupts
  46.  
  47.         // configure pins
  48.  
  49.         PORTG = 0b11111111;
  50.         DDRG  = 0b00000000;
  51.  
  52. //      PORTF = 0b11110000; // ATX off (zero output), fpga config/etc inputs
  53.         DDRF  = 0b00001000;
  54.  
  55.         PORTE = 0b11111111;
  56.         DDRE  = 0b00000000; // inputs pulled up
  57.  
  58.         PORTD = 0b11111111;
  59.         DDRD  = 0b00000000; // same
  60.  
  61.         PORTC = 0b11011111;
  62.         DDRC  = 0b00000000; // PWRGOOD input, other pulled up
  63.  
  64.         PORTB = 0b11110001;
  65.         DDRB  = 0b10000111; // LED off, spi outs inactive
  66.  
  67.         PORTA = 0b11111111;
  68.         DDRA  = 0b00000000; // pulled up
  69.  
  70.         ACSR = 0x80; // DISABLE analog comparator
  71. }
  72.  
  73. int main()
  74. {
  75. start:
  76.  
  77.         hardware_init();
  78.  
  79. #ifdef LOGENABLE
  80.         rs232_init();
  81. #endif
  82.  
  83.         wait_for_atx_power();
  84.  
  85.         spi_init();
  86.  
  87.         DDRF |= (1<<nCONFIG); // pull low for a time
  88.         _delay_us(40);
  89.         DDRF &= ~(1<<nCONFIG);
  90.         while( !(PINF & (1<<nSTATUS)) ); // wait ready
  91.         indata = (ULONG)GET_FAR_ADDRESS(fpga); // prepare for data fetching
  92.         depacker_dirty();
  93.  
  94.         //LED off
  95.         PORTB |= (1<<LED);
  96.  
  97.         // start timer (led dimming and timeouts for ps/2)
  98.         TCCR2 = 0b01110011; // FOC2=0, {WGM21,WGM20}=01, {COM21,COM20}=11, {CS22,CS21,CS20}=011
  99.                             // clk/64 clocking,
  100.                             // 1/512 overflow rate, total 11.059/32768 = 337.5 Hz interrupt rate
  101.         TIFR = (1<<TOV2);
  102.         TIMSK = (1<<TOIE2);
  103.  
  104.  
  105.         //init some device
  106.     ps2keyboard_count = 11;
  107.         ps2mouse_count = 12;
  108.         ps2mouse_initstep = 0;
  109.         ps2mouse_resp_count = 0;
  110.  
  111.         //enable mouse
  112.         zx_mouse_reset(1);
  113.  
  114.         //set external interrupt
  115.         //INT4 - PS2 Keyboard  (falling edge)
  116.         //INT5 - PS2 Mouse     (falling edge)
  117.         //INT6 - SPI  (falling edge)
  118.         //INT7 - RTC  (falling edge)
  119.         EICRB = (1<<ISC41)+(0<<ISC40) + (1<<ISC51)+(0<<ISC50) + (1<<ISC61)+(0<<ISC60) + (1<<ISC71)+(0<<ISC70); // set condition for interrupt
  120.         EIFR = (1<<INTF4)|(1<<INTF5)|(1<<INTF6)|(1<<INTF7); // clear spurious ints there
  121.         EIMSK |= (1<<INT4)|(1<<INT5)|(1<<INT6)|(1<<INT7); // enable
  122.  
  123.         rtc_init();
  124.         zx_init();
  125.  
  126. #ifdef LOGENABLE
  127.         to_log("zx_init OK\r\n");
  128. #endif
  129.  
  130.  
  131.         sei(); // globally go interrupting
  132.  
  133.         //main loop
  134.         do
  135.     {
  136.         ps2keyboard_task();
  137.                 ps2mouse_task();
  138.         zx_task(ZX_TASK_WORK);
  139.                 zx_mouse_task();
  140.                 joystick_task();
  141.  
  142.                 //
  143.                 if ( ps2_flags&SPI_INT_FLAG )
  144.                 {
  145.                         //get status byte
  146.                         UBYTE status;
  147.                         nSPICS_PORT &= ~(1<<nSPICS);
  148.                         nSPICS_PORT |= (1<<nSPICS);
  149.                         status = spi_send(0);
  150.                         zx_wait_task( status );
  151.                 }
  152.     }
  153.         while( atx_power_task() );
  154.  
  155.         goto start;
  156. }
  157.