首页 > 编程语言 > 详细

C++ interrupt handle

时间:2021-05-08 23:30:07      阅读:35      评论:0      收藏:0      [点我收藏+]

 

 

Method one:

It comes from embedded.com.

 

The interrupt class is the interface. The device interrupt class is the specific driver interrupt handler, it is the friend class of driver class.

技术分享图片

 

 

 

The demo code:

class Interrupt{public:
    Interrupt(void);
    static void Register(int interrupt_numberber, Interrupt* intThisPtr);
    // wrapper functions to ISR()
    static void Interrupt_0(void);
    static void Interrupt_1(void);
    static void Interrupt_2(void);
    /* etc.*/
    virtual void ISR(void) = 0;

private:
    static Interrupt* ISRVectorTable[MAX_INTERRUPTS];
    };

void Interrupt::Interrupt_0(void)
{
    ISRVectorTable[0]->ISR();
}

void Interrupt::Interrupt_1(void)
{
ISRVectorTable[1]->ISR();
}

/* etc. */

void Interrupt::Register(int interrupt_number, Interrupt* intThisPtr)
{
    ISRVectorTable[interrupt_number] = intThisPtr;
}
class Timer; // forward declaration

class TimerInterrupt : public Interrupt
{
public:
    TimerInterrupt(Timer* ownerptr);
    virtual void ISR(void);
private:
    Timer* InterruptOwnerPtr;
};

class Timer
{
friend class TimerInterrupt;

public:
    Timer(void);
    int GetCount(void) { return Count; }
private:
    TimerInterrupt* InterruptPtr;
    int Count;
};
Timer::Timer(void)
{
    InterruptPtr = new TimerInterrupt(this);
}

TimerInterrupt::TimerInterrupt(Timer* owner)
{
    InterruptOwnerPtr = owner;    
    // Allows interrupt to access owner‘s data
    Interrupt::Register(TIMER_INTERRUPT_NUMBER, this);
}

 

C++ interrupt handle

原文:https://www.cnblogs.com/zjbfvfv/p/11943884.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!