??? 09/12/11 20:59 Modified: 09/12/11 21:00 Read: times |
#183730 - SDCC: function pointers in an ISR |
Oh, this is a good one. Trust me, my motivations are pure. Please don't ask "why?"
I'm using an Actel FPGA in a design, and embedded in this FPGA is their Core8051S. This soft core has an 8051 processor (ALU, instruction set, memory layout/spaces, etc) but dispenses with the usual ports and peripherals. Which is fine, I can build what I need out of FPGA logic. The processor is supported by both Keil and SDCC; I'm using the latter because of integration with the other Actel tools. This core has two interrupt inputs which function just like the standard 8051's INT0 and INT1. Those are the only interrupts provided. So I built a little 8-input Interrupt Controller in the fabric. This guy lets you select edge-vs-level triggering for any input, as well as polarity select. It has an interrupt output which is self-explanatory and drives the one of the 8051 core's INT inputs. This controller also exposes a couple of registers, which include things like which interrupts are active (priority is handled in firmware) and a mechanism to clear individual interrupts and all of that. Cool. Back in firmware land, I would like to be able to build an array of eight function pointers, which can be initialized to point to functions which ultimately handle the interrupt event for each of the eight controller inputs. The INT0 ISR simply reads the Interrupt Controller register to see which interrupts are active, then based on simple priority (0 highest, 7 lowest) call the appropriate handler through the function pointer. This is where things get hairy. Assume I have a typedef for the function pointer: typedef void (*phandler_t)(void); and an array of handlers: phandler_t phandlers[8] and an ISR: void Int0_isr(void) __interrupt(0) __using(1) { unsigned char intsrc; intsrc = ReadInterruptSourceFromController(); // not a function, this is pseudocode phandlers[intsrc](); // line 150 } // Int0_isr() SDCC throws the following warning: ..main.c:150: warning 139: call via function pointer in ISR using non-zero register bank. Cannot determine which register bank to save. Fine, a nice warning. How do I make it go away? I tried putting the __using() modifier in the function pointer typedef; no difference. I'm sorta baffled. I realize that I could do away with the whole idea of calling the handlers from within the ISR by simply capturing the interrupt source into a global, then back in my main loop using the global as an index into the array of function pointers, but it seems to me that what I want to do is (somewhat?) reasonable. Ideas? Thanks! -a |
Topic | Author | Date |
SDCC: function pointers in an ISR | 01/01/70 00:00 | |
Alternative | 01/01/70 00:00 | |
re: Alternative | 01/01/70 00:00 | |
Register bank 1 | 01/01/70 00:00 | |
re: register bank 1 | 01/01/70 00:00 | |
Using... | 01/01/70 00:00 | |
Lack of orthogonality | 01/01/70 00:00 | |
incorrect warning | 01/01/70 00:00 | |
re: incorrect warning | 01/01/70 00:00 | |
not fixed yet | 01/01/70 00:00 | |
re: not fixed yet | 01/01/70 00:00 | |
Actel's answer. | 01/01/70 00:00 | |
warning | 01/01/70 00:00 | |
function pointers in SDCC | 01/01/70 00:00 | |
bug fixed! | 01/01/70 00:00 | |
Actel support | 01/01/70 00:00 | |
Still on the payroll | 01/01/70 00:00 |