Hey guys,
I'm new to the Hercules series, and I'm trying to port some of my Cortex-M3 code to the Hercules. Specifically I'm trying to implement a critical section on the RM42, where IRQ interrupts are disabled.
I'm using this to synchronize access to a ringbuffer shared between an ISR and some application code.
As far as I can tell, this cannot be done in USER mode, and thus I need to implement a software trap/interrupt.
Now I haven't been able to do this via the system libraries, so I've implemented a handler in assembly. Are my assumptions above correct? Cause if there is an easier way to synchronize or enable/disable interrupts, without having to resort to assembly, I'd prefer it :)
I have tried to do something like this:
- Implement the SCV handler in assembly
- Wrap the SWI/SVC "call" in a C function, e.g. so that the C function EnterCritical() calls an assembly intrinsic _EnterCritical()
- Save/restore the stack and affected registers on entry/exit
- switch back to thumb mode before exiting
I can't get the code to work consistently, so I think I need some help on this. Looks like things doesn't work smoothly, when the CPU switches from ARM to Thumb mode (or fails to do so).
The function to disable interrupts, looks like the this (the function for enabling places 0x01 in R0 before calling SVC): http://pastie.org/8100400
My svc handler function looks like this: http://pastie.org/8100409
To be very specific, I'm trying to make two functions: one for disabling IRQ interrupts, and one for enabling them again. If this can be done easier than my current approach with SVC and assembly intrinsics..
I'd appreciate any help as I'm having a rough time making progress in assembly :)