How to use 2 interrupts from RTC module

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to use 2 interrupts from RTC module

Jump to solution
1,285 Views
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. 

Labels (1)
0 Kudos
Reply
1 Solution
461 Views
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..."

 

 

View solution in original post

0 Kudos
Reply
2 Replies
461 Views
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 Kudos
Reply
462 Views
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 Kudos
Reply