C++ and interrupts

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 
2,062件の閲覧回数
Vasilakes
Contributor II

Not new to embedded systems, not new to C++.

 

New to embedded C++ however.

 

I have interrupts 'working'  by putting them in a C file and accessing global variables.

 

Is there a more C++ way of doing this?

 

Using CW 5.9 and MC9s12

 

Thanks

Keith

ラベル(1)
タグ(1)
0 件の賞賛
返信
1 解決策
672件の閲覧回数
Lundin
Senior Contributor IV
If you mean private encapsulation, no that isn't possible. In both C and C++ you should communicate with the ISR through static variables (at file scope) and not global variables. All variables shared between an ISR and the rest of the program must also be declared as volatile.

元の投稿で解決策を見る

0 件の賞賛
返信
4 返答(返信)
673件の閲覧回数
Lundin
Senior Contributor IV
If you mean private encapsulation, no that isn't possible. In both C and C++ you should communicate with the ISR through static variables (at file scope) and not global variables. All variables shared between an ISR and the rest of the program must also be declared as volatile.
0 件の賞賛
返信
672件の閲覧回数
Vasilakes
Contributor II

Thanks, thats what I was suspecting and pretty much how I'm implementing it.

I'm following your intterupt example in another thread as a guide.

0 件の賞賛
返信
672件の閲覧回数
Lundin
Senior Contributor IV
Actually, you could -in theory- create a C++ class as a "Singelton" design pattern, ie a class that only allows one instance. It should then be possible to make the ISR as a static member function if you can guarantee that it will be allocated inside non-banked memory. Then you must trick the linker to believe that this function is called from the program, so it won't get optimized away.

Even if this is possible in theory (I have no idea if it is possible in reality), you achieve very little with this. Implementing and testing the class will take lots of time and you will get various code overhead. Worst of all it adds obscure complexity to the program.

So the above would be the academic's choise, while my first post would be the cynical, experienced engineer's choise :smileyhappy:
0 件の賞賛
返信
672件の閲覧回数
Vasilakes
Contributor II

Oh I am MUCH more interested in the cynical experienced engineers choice!

 

And that was really the reason for this thread. I had 1 way to do it, but I wanted at least an opinion on the subject.

 

I did find an article about doing interrupts in C++ using aggreation and virtual base classes, but for my little processor it seemed way overkill.

 

I mean C++ my prove to be too much. But a guy has to try right?

0 件の賞賛
返信