From 7c165d29b989a15e2fd23a6d17c08d1981411bc3 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Sun, 4 Dec 2011 02:05:02 +0100 Subject: Created member function interrupt gate. --- hal/interrupt.h | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'hal/interrupt.h') diff --git a/hal/interrupt.h b/hal/interrupt.h index f817103..34651f2 100644 --- a/hal/interrupt.h +++ b/hal/interrupt.h @@ -75,7 +75,8 @@ namespace Interrupt { DMA2_Channel1, DMA2_Channel2, DMA2_Channel3, - DMA2_Channel4_5 + DMA2_Channel4_5, + NUM_IRQs }; inline void enable(IRQ n) { @@ -89,6 +90,26 @@ namespace Interrupt { inline void set_priority(IRQ n, uint8_t priority) { NVIC.IPR[n] = priority; } + + struct MFP { + void (*func_p)(void*); + void* instance_p; + }; + + extern MFP mf_vectors[]; + + template + inline void set_handler(IRQ n, void (T::*f)(), T* i) { + MFP& mfp = mf_vectors[16 + n]; + mfp.func_p = reinterpret_cast(f); + mfp.instance_p = i; + } + + template + inline void enable(IRQ n, void (T::*f)(), T* i) { + set_handler(n, f, i); + enable(n); + } }; template -- cgit v1.2.3