Subversion Repositories pentevo

Rev

Rev 75 | Rev 117 | 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.  
  4. #include <util/delay.h>
  5.  
  6. #include "mytypes.h"
  7. #include "pins.h"
  8. #include "ps2.h"
  9. #include "rs232.h"
  10. #include "zx.h"
  11. #include "spi.h"
  12. #include "atx.h"
  13. #include "rtc.h"
  14.  
  15. ISR(TIMER2_OVF_vect)
  16. {
  17.         static UBYTE counter=0x00;
  18.         static BYTE dir=0x01;
  19.         static BYTE ocr=0x00;
  20.  
  21.         counter++; // just fucking shit to fadein-fadeout LED :-)))
  22.         if( counter&128 )
  23.         {
  24.                 counter=0;
  25.  
  26.                 ocr += dir;
  27.                 if( (ocr==(-1)) && (dir==(-1)) )
  28.                 {
  29.                         dir = -dir;
  30.                         ocr = 1;
  31.                 } else if( (ocr==0) && (dir==1) )
  32.                 {
  33.                         dir = -dir;
  34.                         ocr = 0xFF;
  35.                 }
  36.  
  37.                 OCR2 = ocr;
  38.         }
  39.  
  40.         // PS/2 keyboard timeout tracking
  41.         if( (ps2keyboard_count<11) && (ps2keyboard_count!=0) ) // track timeout for PS/2 keyboard
  42.         {
  43.                 if( ps2keyboard_timeout ) ps2keyboard_timeout--;
  44.  
  45.                 if( !ps2keyboard_timeout )
  46.                 {
  47.                         ps2keyboard_count = 11;
  48.                 }
  49.         }
  50.  
  51.         // pause for keyboard CS|SS
  52.         if( shift_pause )
  53.                 shift_pause--;
  54.  
  55.         // PS/2 mouse timeout tracking
  56.         if( (ps2mouse_count<12) && (ps2mouse_count!=0) )
  57.         {
  58.                 if( ps2mouse_timeout ) ps2mouse_timeout--;
  59.                 else
  60.                 {
  61.                         ps2mouse_count = 12;
  62.                 }
  63.         }
  64.  
  65.         //check soft reset
  66.         if ( SOFTRES_PIN & (1<<SOFTRES) )
  67.         {
  68.                 //not pressed
  69.                 atx_counter = 0;
  70.         }
  71.         else
  72.         {
  73.                 //pressed
  74.                 atx_counter++;
  75.         }
  76. }
  77.  
  78.  
  79. ISR(INT4_vect) // receive PS/2 keyboard data. TODO: sending mode...
  80. {
  81.         ps2keyboard_shifter >>= 1;
  82.         if( (PS2KBDAT_PIN&(1<<PS2KBDAT)) ) ps2keyboard_shifter |= 0x8000;
  83.  
  84.         if( !(--ps2keyboard_count) )
  85.         {
  86.                 PS2KBCLK_PORT &= ~(1<<PS2KBCLK);
  87.                 PS2KBCLK_DDR  |= (1<<PS2KBCLK);
  88.  
  89.                 EIFR = (1<<INTF4); // clr any additional int which can happen when we pulldown clock pin
  90.         }
  91.  
  92.         ps2keyboard_timeout = PS2KEYBOARD_TIMEOUT;
  93.  
  94.         //
  95.         EIFR = (1<<INTF4);
  96. }
  97.  
  98.  // receive/send PS/2 mouse data
  99. ISR(INT5_vect)
  100. {
  101.         if( (ps2_flags&PS2MOUSE_DIRECTION_FLAG) != 0 )
  102.         {
  103.                 //send mode
  104.                 if( --ps2mouse_count )
  105.                 {
  106.                         if ( ps2mouse_shifter&1 ) PS2MSDAT_PORT |= (1<<PS2MSDAT);
  107.                         else PS2MSDAT_PORT &= ~(1<<PS2MSDAT);
  108.  
  109.                         ps2mouse_shifter >>= 1;
  110.  
  111.                         if( ps2mouse_count == 11 )
  112.                         {
  113.                                 //first interrupt is programmed
  114.                                 PS2MSDAT_DDR |= (1<<PS2MSDAT);   //ps2mouse data pin to output mode
  115.                                 _delay_us(200);  //hold ps2mouse clk pin ~200us
  116.                                 PS2MSCLK_PORT |= (1<<PS2MSCLK);  //release ps2mouse clk pin
  117.                     PS2MSCLK_DDR  &= ~(1<<PS2MSCLK);
  118.                         }
  119.                         else if( ps2mouse_count == 1)
  120.                         {
  121.                                 PS2MSDAT_DDR &= ~(1<<PS2MSDAT); //ps2mouse data pin to input mode
  122.                         }
  123.                 }
  124.                 else
  125.                 {
  126.                         //ack received
  127.                         PS2MSCLK_PORT &= ~(1<<PS2MSCLK);
  128.             PS2MSCLK_DDR  |= (1<<PS2MSCLK);
  129.                 }
  130.         }
  131.         else
  132.         {
  133.                 //receive mode
  134.                 ps2mouse_shifter >>= 1;
  135.                 if( (PS2MSDAT_PIN&(1<<PS2MSDAT)) ) ps2mouse_shifter |= 0x8000;
  136.  
  137.                 if( (--ps2mouse_count) == 1 )
  138.                 {
  139.                         PS2MSCLK_PORT &= ~(1<<PS2MSCLK);
  140.                 PS2MSCLK_DDR  |= (1<<PS2MSCLK);
  141.                         ps2mouse_count = 0;
  142.                 }
  143.         }
  144.  
  145.         EIFR = (1<<INTF5);
  146.  
  147.         //set timeout
  148.         ps2mouse_timeout = PS2MOUSE_TIMEOUT;
  149. }
  150.  
  151.  // SPI_INT
  152. ISR(INT6_vect)
  153. {
  154.         ps2_flags |= SPI_INT_FLAG;
  155.         EIFR = (1<<INTF6);
  156. }
  157.  
  158.  // RTC up data
  159. ISR(INT7_vect)
  160. {
  161.         gluk_inc();
  162.  
  163.         EIFR = (1<<INTF7);
  164. }
  165.  
  166.