Author |
Message |
Pezac
Member |
Spinning off the recent topic about interrupts, I thought I could ask a little question of mine here.
When using interrupts, is it possible to have the same vector on multiple levels i.e. using the same code to handle multiple levels (or at least two different levels)? I can't get this to work completely when trying. I do something like:
* Test if the higher priority interrupt is active in INTREQR
* If it is, branch to that code
* Else do the lower prirority code
I may be mixing up things here, especially about how those flags are working. I get interrupts that "fall through" it seems, or rather the wrong code is executed.. I "clear" interrupt flags at the end of the code, maybe it *should* be done at the beginning?
If you have multiple interrupts activated on the same level you always have to do something like this, maybe it just doesn't work that well with multiple levels :)
|
TheDarkCoder
Member |
I never thought of having the same handler for two different interrupt level.
Why do you want this?
Anyway, I see no problem in this.
You should always check the INTREQR bits:
btst #x, INTREQR
beq ..
and of course clear the appropriate bit of INTREQ.
You may as well check what level of interrupts are you in, by reading the SR register of the CPU.
For clearing an interrupt on 040/060, wait for my next tutorial!
Meanwhile, it's better to clear them as soon as possible, so in the beginning.
|
Pezac
Member |
The reason for this is to save size, if possible. It's more convenient also, at least for me.
Ofcourse you have to check INTREQR, but there could be problems with higher priority interrupt going in while another is running. So you have to be smart with the bit checking there, and in what order you branch. I tried to do that, but I didn't get it to work.
Thanks for the tip about SR, I will check it out!
Can you explain why you should clear interrupts ASAP? Aren't you supposed to clear when the interrupt is done? I mean the code can take some time in certain cases, f.ex. audio.
|
TheDarkCoder
Member |
Of course an higher level interrupt can interrupt a lower level. But why this relates with INTREQR?
It's not necessary to clear the bit at the end. The bit in INTREQR does not determine whether you are in interrupt-mode or not, it is just there to allow the handler to identify the interrupt source (e.g. the type of interrupt).
On the contrary, clear it at the beginning could be better for subtile reasons I'll explain in my tutorial.
|
Pezac
Member |
It relates to INTREQR because you use that to check interrupt type. And if the lower priority interrupt is running and the higher priority interrupts that, you can get problems (thinking of the INTREQR check). At least you must consider what will happen in this case. Simple parallel processing stuff really. It seems you didn't read what I wrote *sniff*
Anyway, even with this in mind I couldn't make it work completely - the wrong interrupt code is run now and then. Your tip about SR was helpful, thanks again.
|
TheDarkCoder
Member |
@Pezac
sorry, now I see why you need INTREQR. In principle, it should work, if first check the highest priority levels in INTREQR. In this way if a level 3 interrupt is interrupted by a level 4, you have both bit sets, and you understand you are in level 4 by checking first the level 4 bits (which is only audio I think).
Either there is some bug in your code, or you don't reset bits correcly so you have double interrupt requests. Have you checked if you have the same problems with a simple 1 level interrupt handler?
|
Pezac
Member |
Yes that's exactly what I meant and what I have tried. I "clear" bits accordingly, at the end of the routines. It could be something there. The problem is, I'm getting errors now and then, probably when the two interrupts trigger about the same time. But looking at SR is a solution, and it seems to be working without flaws in my case.
|
skan
Member |
@Pezac
Wow, Master Pezac in the house! :D
Should I think you're working on some code for Codex? ;)
|
z5_
Member |
Should I think you're working on some code for Codex? ;)
What is Codex? A new ruling intro from Nature?
|
skan
Member |
@z5
I wish... but it's only a demoparty I'm trying to organize with someone else... see Codex Alpe Adria 2005 thread in the forums... :)
|