AnsweredAssumed Answered

Proper reset of port interrupts on MKL25Z128VLK4

Question asked by Stefan Dzisiewski-Smith on Apr 30, 2013
Latest reply on Apr 30, 2013 by Stefan Dzisiewski-Smith

Hi everyone

 

I'm trying to learn best practise with port interrupts for the M0+ chip I'm working with - the MKL25Z128VLK4 on the FRDM-KL15Z board. I'm using an external falling edge interrupt on PORTD Pin 4. It's all set up nicely using Processor Expert in CodeWarrior and I can correctly trigger into my PORTD ISR and test PORTD_PCR4 to determine the cause of the interrupt. So far so good. Since my ISR needs to trigger comms (which I can't do inside the ISR) I just test, clear and assert an asynchronous flag which I deal with elsewhere in the main loop. All works with this piece of code:

 

if(PORTD_PCR4 & 1<<24){

     PORTD_PCR4 |= 1<<24; // 1 clears, not 0...

     touchFlag = TRUE;

}


Easy, right? Except that it's not exactly ideal. It's using a non-atomic read-modify-write in the |= (along with the inline shift). This means that theoretically, another bit in the register could change between the read and the write. In this case it is unlikely (as each PCR only includes its own ISF) but I just wanted to see if there was a better way out there.


All thoughts gratefully received.


Stefan

Outcomes