Page 1 of 1

Problem with interrupts after setup keyboard

Posted: Sat Dec 20, 2003 9:49 am
by guest
My AMD Duron (1 GHz) restarts when I enable interrupts after I had setup the keyboard

Code: Select all

enable_irq(1, keyboardInt, INT_GATE|BITS_32|PRESENT|RING_2);
   
SendData(0xFF);      //Restart keyboard
SendData(0xF4);      //Enables keyboard and Scanning
SetRate(KDefault);     //Sets default scanning rate]

// if I enable interrups yet the cpu restart
// else it goes on
the funny thing is that it all works in my AMD K6 (586, 133MHz)

Re:Problem with interrupts after setup keyboard

Posted: Mon Dec 22, 2003 12:59 pm
by Pype.Clicker
this is likely to be a problem with delays ...

Re:Problem with interrupts after setup keyboard

Posted: Mon Dec 22, 2003 1:27 pm
by petrusss
What do the SendData and SetRate functions look like?

Re:Problem with interrupts after setup keyboard

Posted: Tue Dec 23, 2003 5:49 am
by guest
The SendData function:

Code: Select all

void SendData(unsigned char data) //Sends a command or data to keyboard
{
   WaitForReady();      //MicroDelay((unsigned long) 10);
   outportb(0x60, data);
}
The SetRate function:

Code: Select all

void SetRate(unsigned char rate)   //Sets the typing rate and delay
{
   SendData(0xF3);
   SendData(rate);
}
the WaitForReady function:

Code: Select all

void WaitForReady(void)   //determines if the keyboard is ready to accept a command
{
    volatile long i = MAX_TRYES_FOR_READY;
    while(i-- && (inportb(0x64) & 0x02));
}
the inportb and outportb function:

Code: Select all

inline static unsigned char inportb(int port)
{
   register unsigned char r;
   
      asm volatile
   ( 
      "inb %%dx, %%al\n\t" 
      : "=a" (r) 
      : "d" (port)
   );

      return (r);
}

inline static void outportb(int port, unsigned char data)
{
   asm volatile
   (
      "outb %%al, %%dx\n\t" 
      :
      : "a" (data), "d" (port)
   );
}

Re:Problem with interrupts after setup keyboard

Posted: Tue Dec 23, 2003 5:57 am
by Candy
guest wrote: The SendData function:

Code: Select all

void SendData(unsigned char data) //Sends a command or data to keyboard
{
   WaitForReady();      //MicroDelay((unsigned long) 10);
   outportb(0x60, data);
}
the WaitForReady function:

Code: Select all

void WaitForReady(void)   //determines if the keyboard is ready to accept a command
{
    volatile long i = MAX_TRYES_FOR_READY;
    while(i-- && (inportb(0x64) & 0x02));
}
MAX_TRYES_FOR_READY is probably a compile-time constant, and if it's large enough for a 1mhz computer bochs emulates, it might be a little low for the 1000mhz computer your real one is.

You might even have some constants swapped around, I have no experience with the keyboard programming.