Calling an interrupt from the handling of another.
Re: Calling an interrupt from the handling of another.
Ring buffer needs only for static implementation FIFO queue. It is not ring queue. And if it has the size defined as power of 2 it can be wraped by "and size-1" operation. Usually in my kernel event queue has the size 16 K and so it can contain queuesize/packagesize-1 event packages. When posting event and queue is full kernel cleans the queue by setting one pointer as other one and posts RESET event.
If you have seen bad English in my words, tell me what's wrong, please.
Re: Calling an interrupt from the handling of another.
Something really bazaar just happened..
This code works:
but all of these, DON'T!
(p.s: don't worry about indexes, read_from_pipe() and write_to_pipe() handle them already. and also, excuse me from the lousy names, will be changed in future)
(write_to_pipe() is called from the IRQ and sets the flag to 1, read_from_pipe() from the process sets the flag to 1 if there's absolutely no data to be read which I also check with the indexes)
(also, only write_to_pipe() is external to keyboard.c, what i have shown you now is kbdapi.c)
any explanation to this?
This code works:
Code: Select all
char getch()
{
while(1)
{
if(flag) break;
printf("%d", flag); // printing is actually essential!
}
return read_from_pipe();
}
Code: Select all
char getch()
{
while(!flag)
printf("%d", flag); // doesn't even show a number!
return read_from_pipe();
}
Code: Select all
char getch()
{
while(!flag);
return read_from_pipe();
}
(write_to_pipe() is called from the IRQ and sets the flag to 1, read_from_pipe() from the process sets the flag to 1 if there's absolutely no data to be read which I also check with the indexes)
(also, only write_to_pipe() is external to keyboard.c, what i have shown you now is kbdapi.c)
any explanation to this?
Last edited by eXeCuTeR on Sat Jul 24, 2010 2:40 am, edited 1 time in total.
Re: Calling an interrupt from the handling of another.
You need to declare flag as volatile.
If a trainstation is where trains stop, what is a workstation ?
Re: Calling an interrupt from the handling of another.
Oh that's great! Thanks, all good now!gerryg400 wrote:You need to declare flag as volatile.
But I don't see why this actually matters? Because if it was kept into a register, and the IRQ actually change 5 registers (which i remember 3 of them ATM) and if one was it, the results would not be very nice. Just not sure about it, but what the heck.
Re: Calling an interrupt from the handling of another.
If a variable can be modified outside of the normal flow of the program (e.g. by interrupt service routine or by hardware) you need to declare it as volatile.But I don't see why this actually matters?
In this case
Code: Select all
flag=0;
while(!flag)
;
Code: Select all
flag=0;
while(1)
;
If a trainstation is where trains stop, what is a workstation ?