Keyboard Buffer Synchronozation
Posted: Wed Feb 02, 2005 12:00 am
I'v a problem in my OS code.
scenario :
1) There is a Keyboard Queue Buffer and a variable called 'sync' - Global
2) The Keyboard handler will put the read character(after scancode conversion) into this Queue Buffer
3) There is a blocking function getChar() which reads a character from Queue Buffer.
4) This function polls the Queue Buffer in a tight loop until it reads a character and then returns
Problem: The key pressed will echo on screen but with unpredictable output.... means junk chars, previous character
got from previous IRQ9 will also get displayed..... as a whole display is not proper...
a) Queue Read and Write are correct(tested)
b) Display function is Correct(tested)
pseuodo Code:
getChar()
{
while(readFromQueue() == success) ;
}
readFromQueue()
{
sync = 1
..... QUEUE read operation ......
sync = 0
}
keyboard_handler()
{
... All keyboard port related stuff
writeToBuffer() ;
..... IRET etc.....
}
writeToBuffer()
{
if(sync == 1)
return ;
..... QUEUE write operation ......
return ;
}
But if I put a waiting loop in getChar() like:
getchar()
{
while(readFromQueue() == success)
{
for(i=0;i<999;i++) ;
}
}
Then everything works fine.....
NOTE: I know that if sync = 1 and IRQ9 comes... the keyed in character is lost... but thats fine....
Please give a soluation or an alternative approach....
scenario :
1) There is a Keyboard Queue Buffer and a variable called 'sync' - Global
2) The Keyboard handler will put the read character(after scancode conversion) into this Queue Buffer
3) There is a blocking function getChar() which reads a character from Queue Buffer.
4) This function polls the Queue Buffer in a tight loop until it reads a character and then returns
Problem: The key pressed will echo on screen but with unpredictable output.... means junk chars, previous character
got from previous IRQ9 will also get displayed..... as a whole display is not proper...
a) Queue Read and Write are correct(tested)
b) Display function is Correct(tested)
pseuodo Code:
getChar()
{
while(readFromQueue() == success) ;
}
readFromQueue()
{
sync = 1
..... QUEUE read operation ......
sync = 0
}
keyboard_handler()
{
... All keyboard port related stuff
writeToBuffer() ;
..... IRET etc.....
}
writeToBuffer()
{
if(sync == 1)
return ;
..... QUEUE write operation ......
return ;
}
But if I put a waiting loop in getChar() like:
getchar()
{
while(readFromQueue() == success)
{
for(i=0;i<999;i++) ;
}
}
Then everything works fine.....
NOTE: I know that if sync = 1 and IRQ9 comes... the keyed in character is lost... but thats fine....
Please give a soluation or an alternative approach....