Re: static class member as interrupt handler works, but not if class is templated

2021-04-12 Thread Bruce D. Lightner
David, Good points.  As you probably are aware, avr-gcc interrupt handlers are very special things.  The generated code saves a minimal set of processor state (i.e., registers) in entry. Calling an external function forces the compiler to save "everything" to preserve the avr-gcc "execution m

Re: static class member as interrupt handler works, but not if class is templated

2021-04-12 Thread Klaus Rudolph
Am 12.04.21 um 16:25 schrieb Anton Staaf: Klaus, I'm not sure if my previous answer didn't make it through or was just missed, but I believe your problem is related to this GCC bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70435 Yes, look

Re: static class member as interrupt handler works, but not if class is templated

2021-04-12 Thread Klaus Rudolph
Am 12.04.21 um 15:46 schrieb David Brown: Certainly templates can be instantiated zero, once, or multiple times. And certainly some templates are intended only to be instantiated a single time. But it would surely be difficult to have a feature that only works when there is a single instantiati

Re: static class member as interrupt handler works, but not if class is templated

2021-04-12 Thread Anton Staaf
Klaus, I'm not sure if my previous answer didn't make it through or was just missed, but I believe your problem is related to this GCC bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70435 -Anton On Mon, Apr 12, 2021 at 5:14 AM Klaus Rudolph wrote: > Am 12.04.21 um 13:53 schrieb Matthijs Koo

Re: static class member as interrupt handler works, but not if class is templated

2021-04-12 Thread David Kelly
All of this might not be a bug at all but an undefined work around for deficiencies in C++ primitive functions in the avr-gcc support library? To prevent one from using? In the early days of avr-gcc, just plain C, not all support primitive functions were reentrant. If memory serves me, math fun

Re: static class member as interrupt handler works, but not if class is templated

2021-04-12 Thread David Brown
On 12/04/2021 14:12, Klaus Rudolph via Gcc-help wrote: > Am 12.04.21 um 13:53 schrieb Matthijs Kooijman: - figure out, where the special handling of the __vector_10 seems to happen, and why it is not happening in the class template case. This might help diagnose if and where to fix i

Re: static class member as interrupt handler works, but not if class is templated

2021-04-12 Thread Klaus Rudolph
Am 12.04.21 um 13:53 schrieb Matthijs Kooijman: - figure out, where the special handling of the __vector_10 seems to happen, and why it is not happening in the class template case. This might help diagnose if and where to fix it within the compiler. That is compiler internals... yes, if it is a

Re: static class member as interrupt handler works, but not if class is templated

2021-04-12 Thread Matthijs Kooijman
> > - figure out, where the special handling of the __vector_10 seems to > > happen, and why it is not happening in the class template case. This > > might help diagnose if and where to fix it within the compiler. > > That is compiler internals... yes, if it is a compiler bug, it is the > way to h

Re: static class member as interrupt handler works, but not if class is templated

2021-04-12 Thread Klaus Rudolph
Hi, Am 12.04.21 um 11:20 schrieb Peter Sommerlad (C++): - why is the special name __vector_10 used to get the function address into the interrupt table? Is there another way, or is the environment insisting on such a name? Can you change the linker (i.e. with a dedicated map file) to get the D

Re: static class member as interrupt handler works, but not if class is templated

2021-04-12 Thread Peter Sommerlad (C++)
Klaus, I do not have a solution, but I try to be helpful and give a list what I would try to understand the situation: - why is the special name __vector_10 used to get the function address into the interrupt table? Is there another way, or is the environment insisting on such a name? Can yo

Re: static class member as interrupt handler works, but not if class is templated

2021-04-12 Thread David Brown
On 12/04/2021 10:46, Klaus Rudolph wrote: > Thank you all so much for wasting my thread! > > Please do NOT answer, you all produced enough spam! Would be nice if > someone can help on *MY* topic! > > Thanks! > Sorry, but that is not the way mailing lists or other public discussion mediums work.

Re: static class member as interrupt handler works, but not if class is templated

2021-04-12 Thread Klaus Rudolph
Thank you all so much for wasting my thread! Please do NOT answer, you all produced enough spam! Would be nice if someone can help on *MY* topic! Thanks!

Re: static class member as interrupt handler works, but not if class is templated

2021-04-12 Thread David Brown
Hi, C++ is a language designed to be used with optimising compilers. Turning off optimisations cripples it - either you end up with so absurdly poor object code that you massively change the timing, and therefore behaviour, of your embedded system, or you have to limit yourself drastically in the

Re: static class member as interrupt handler works, but not if class is templated

2021-04-11 Thread Anton Staaf
I also find it very helpful to extensively unit test my embedded code on the host machine. Even sensor handling code can often be tested by writing signedness tests (given a change in input value what is the expected sign of the change of the output). -Anton On Sun, Apr 11, 2021 at 5:32 PM Tramp

Re: static class member as interrupt handler works, but not if class is templated

2021-04-11 Thread Trampas Stern
David, On the real cost of C++ I do not see the problems with debugging you do. That is when I debug code I turn optimizations off, as such I can debug C++ just like C. Now with compiler optimizations on all bets are off as to what the compiler does. At this point you have to have near complete

Re: static class member as interrupt handler works, but not if class is templated

2021-04-11 Thread Trampas Stern
In C++ for interrupt vectors in drivers I set up an array of pointers to function all the peripheral driver code like this for timer counters. static voidCallback_t _isr_funcs[TC_INST_NUM]={NULL}; Then in each handler if the pointer is not null I call it. This is a lot of work and overhead but

Re: static class member as interrupt handler works, but not if class is templated

2021-04-11 Thread David Brown
On 10/04/2021 22:11, Klaus via Gcc-help wrote: > Hi, > > > > Am 10.04.21 um 17:26 schrieb Jonathan Wakely: > >> >>     Dummy<1> d1; >> >> >> This doesn't cause the instantiation of the member function. >> >> Have you tried an explicit instantiation? >> >> template class Dummy<1>; > > Did not c

Re: static class member as interrupt handler works, but not if class is templated

2021-04-11 Thread Trampas Stern
"The man who grasps principles can successfully handle his own methods. The man who tries methods, ignoring principles, is sure to have trouble." -Ralph Waldo Emerson When you understand your requirements, processor, and tools (compiler) then you can pick the best method to optimize for desired r

Re: static class member as interrupt handler works, but not if class is templated

2021-04-11 Thread David Brown
Well, if you want a flame war, then let me chime in - you are wrong, Trampas is right. You are /wrong/ to suggest that "commercial embedded systems ALWAYS directly benefit from being small and fast". Some do - for many, it is irrelevant as long as they are small enough and fast enough. Once you

Re: static class member as interrupt handler works, but not if class is templated

2021-04-10 Thread Anton Staaf
For those that care, and ignoring the flame war, I believe that your (Klaus) problem likely stems from the following GCC bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70435 Sadly, support for C++ in AVR GCC is not a priority, so I wouldn't expect it to be fixed. I've been able to work around

Re: static class member as interrupt handler works, but not if class is templated

2021-04-10 Thread Russell Shaw
On 11/4/21 8:36 am, Trampas Stern wrote: Actually C++ is not slower or more bloat than C, depending on the features used. For example I do not use RTTI or exceptions, so that makes it about the same as C for size. Yes you have to turn these features off in your compiler (-fno-rtti, -fno-except

Re: static class member as interrupt handler works, but not if class is templated

2021-04-10 Thread Bruce D. Lightner
Trampas Stern, I'm sorry, but I've got to chime in here grasshopper.  David Kelly put it well: just "don't use C++"! I somehow knew that this would start a flame war. :-) [FLAME ON] We've been there, done that, bought the T-shirt, here in forums like this before, going back many decades!  I'

Re: static class member as interrupt handler works, but not if class is templated

2021-04-10 Thread Trampas Stern
Actually C++ is not slower or more bloat than C, depending on the features used. For example I do not use RTTI or exceptions, so that makes it about the same as C for size. Yes you have to turn these features off in your compiler (-fno-rtti, -fno-exceptions). Sure you have trampolines or jump tab

Re: static class member as interrupt handler works, but not if class is templated

2021-04-10 Thread David Kelly
On Apr 10, 2021, at 2:37 PM, Trampas Stern wrote: > If you guys have a better way I would love to know. Don’t use C++? What does object-oriented coding do for embedded projects? It’s akin to using printf(). Slow and lots of bloat. Time once was I put uint32 in a union so as to code ++ inline

Re: static class member as interrupt handler works, but not if class is templated

2021-04-10 Thread Klaus
Hi, Am 10.04.21 um 17:26 schrieb Jonathan Wakely: Dummy<1> d1; This doesn't cause the instantiation of the member function. Have you tried an explicit instantiation? template class Dummy<1>; Did not change anything. If I use my original code, I get the instantiation of the functio

Re: static class member as interrupt handler works, but not if class is templated

2021-04-10 Thread Trampas Stern
I wish there was a better way to interrupt handlers in classes, for embedded. For example I write a UART class as a driver which I initialize by passing a pointer to hardware address. However because different UARTs use different interrupt vectors I end up having to have the extern C and create e

Re: static class member as interrupt handler works, but not if class is templated

2021-04-10 Thread Jonathan Wakely
On Sat, 10 Apr 2021, 15:07 Klaus Rudolph via Gcc-help, wrote: > Hi all, > > if I write a class with static member function I can use it as an > interrupt handler as follows: > > class Dummy > { > static void Handler() __asm__("__vector_10") > __attribute__((__signal__, __used__, __externally