Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
Andy Peters
09/12/11 14:59
Modified:
  09/12/11 15:00

Read: 1712 times
Tucson, Az
USA


 
#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



List of 17 messages in thread
TopicAuthorDate
SDCC: function pointers in an ISR      Andy Peters      09/12/11 14:59      
   Alternative      Per Westermark      09/12/11 15:12      
      re: Alternative      Andy Peters      09/12/11 15:44      
         Register bank 1      Per Westermark      09/12/11 15:55      
            re: register bank 1      Andy Peters      09/12/11 15:57      
               Using...      Michael Karas      09/12/11 16:27      
               Lack of orthogonality      Per Westermark      09/12/11 16:38      
                  incorrect warning      Maarten Brock      09/13/11 03:39      
                     re: incorrect warning      Andy Peters      09/14/11 11:38      
                        not fixed yet      Maarten Brock      09/14/11 12:54      
                           re: not fixed yet      Andy Peters      09/14/11 13:38      
                              Actel's answer.      Andy Peters      09/16/11 10:42      
   warning      Jan Waclawek      09/12/11 17:00      
   function pointers in SDCC      Rich Bayless      09/12/11 20:26      
   bug fixed!      Andy Peters      09/20/11 10:45      
      Actel support      Jan Waclawek      09/20/11 11:13      
         Still on the payroll      Maarten Brock      09/21/11 01:49      

Back to Subject List