How to use 2 interrupts from RTC module

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

How to use 2 interrupts from RTC module

跳至解决方案
1,844 次查看
LordMark
Contributor IV

Hi everybody, I'm working on MCF52259 and I've already initialized RTC 1HZ interrupt for counting seconds. So I have the ISR for that purpose.

 

Now I would need another interrupt source from the RTC, the alarm; I need to set an alarm and generate an interrupt when time matches that alarm.

 

How can I get that, since the interrupt controller module allows only one interrupt source from RTC?

 

Thank you!

Marco. 

标签 (1)
0 项奖励
回复
1 解答
1,020 次查看
mjbcswitzerland
Specialist V

Hi Marco

 

There is only one interrupt vector but the source of the particular interrupt can be read from the RTCISR register. This means that the interrupt handler can dispatch the routine to handle the interrupt(s) in question. Below is the code from the RTC interrupt handler in the uTasker project:

 

 

static void ( *RTC_handler[6] )( void ) = {0}; // all possible RTC interrupts

// RTC interrupt handler
//
static __interrupt__ void _rtc_handler(void)
{ 
    int iIRQBit = 0;
    while ((RTCISR & RTCIENR) != 0) {    // while enabled interrupts exist
        if ((0x01 << iIRQBit) & RTCISR & RTCIENR) {
            RTCISR = (0x01 << iIRQBit);  // clear interrupt
            if ((0x01 << iIRQBit) & (RTC_ALARM_INT | RTC_STOPWATCH)) {
                RTCIENR &= ~(0x01 << iIRQBit); // ensure no second interrupt can occur
            }
            if (RTC_handler[iIRQBit] != 0) {
                iInterruptLevel = 1; // ensure interrupts remain blocked during subroutines
                RTC_handler[iIRQBit](); // call the interrupt handler
                iInterruptLevel = 0;
            }
        }
        if (++iIRQBit >= 6) {
            iIRQBit = 0;
        }
    }
}

 

For each of the 6 possible interrupts a handler is defined, which is entered by the routine that configured each interrupt type. The ISR dispatches the specific handler(s) depending on which interrupt bit are set. Note that it also handles single-shot and repetitive alarm types.

 

The uTasker simulator also simulates the operation of the RTC and its various alarm interrupts so that its use can be fully verified without needing to work on the target.

 

Regards

 

Mark

 

www.uTasker.com
- OS, TCP/IP stack, USB, device drivers and simulator for M521X, M521XX, M5221X, M5222X, M5223X, M5225X. One package does them all - "Embedding it better..."

 

 

在原帖中查看解决方案

0 项奖励
回复
2 回复数
1,020 次查看
LordMark
Contributor IV

Thank you for your answer. 

 

So, I have to modify the existing RTC ISR so that it can handle also the alarm occurrence, by verifying the status of the alarm bit in the RTCISR register.

 

Regards,

Marco. 

0 项奖励
回复
1,021 次查看
mjbcswitzerland
Specialist V

Hi Marco

 

There is only one interrupt vector but the source of the particular interrupt can be read from the RTCISR register. This means that the interrupt handler can dispatch the routine to handle the interrupt(s) in question. Below is the code from the RTC interrupt handler in the uTasker project:

 

 

static void ( *RTC_handler[6] )( void ) = {0}; // all possible RTC interrupts

// RTC interrupt handler
//
static __interrupt__ void _rtc_handler(void)
{ 
    int iIRQBit = 0;
    while ((RTCISR & RTCIENR) != 0) {    // while enabled interrupts exist
        if ((0x01 << iIRQBit) & RTCISR & RTCIENR) {
            RTCISR = (0x01 << iIRQBit);  // clear interrupt
            if ((0x01 << iIRQBit) & (RTC_ALARM_INT | RTC_STOPWATCH)) {
                RTCIENR &= ~(0x01 << iIRQBit); // ensure no second interrupt can occur
            }
            if (RTC_handler[iIRQBit] != 0) {
                iInterruptLevel = 1; // ensure interrupts remain blocked during subroutines
                RTC_handler[iIRQBit](); // call the interrupt handler
                iInterruptLevel = 0;
            }
        }
        if (++iIRQBit >= 6) {
            iIRQBit = 0;
        }
    }
}

 

For each of the 6 possible interrupts a handler is defined, which is entered by the routine that configured each interrupt type. The ISR dispatches the specific handler(s) depending on which interrupt bit are set. Note that it also handles single-shot and repetitive alarm types.

 

The uTasker simulator also simulates the operation of the RTC and its various alarm interrupts so that its use can be fully verified without needing to work on the target.

 

Regards

 

Mark

 

www.uTasker.com
- OS, TCP/IP stack, USB, device drivers and simulator for M521X, M521XX, M5221X, M5222X, M5223X, M5225X. One package does them all - "Embedding it better..."

 

 

0 项奖励
回复