Critical section in MPC5604

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

Critical section in MPC5604

665 Views
remigiuszmachur
Contributor I


What is construction for EnterCritical and ExitCritical macro (function) to have part of code without interrupt?

Micro: MPC5604

I found these examples below.

methode #1:

Disable/Enable interrupts

 

void interrupt_enable_interrupt(void)

{

  asm(" wrteei 1");   /* Enable external interrupts */

}


void interrupt_disable_interrupt(void)

{

  asm(" wrteei 0");   /* disable external interrupts */

}

 

 

method #2:

Save/Restore   interrupt status to local variable

A local variable 'cpu_sr' of type 'vint32_t' needs to be defined in this method.

 

vuint32_t interrupt_enter_critical(void)

{

  asm("mfmsr r3");   /* save the register on the local variable */

  asm("wrteei 0");   /* disable the interrupt */

}


void interrupt_exit_critical(vuint32_t status_reg)

{

  asm("mtmsr r3");   /* Enable external interrupts */

}

 

Somebody used these constructions? Is it working?

Labels (1)
0 Kudos
1 Reply

400 Views
martin_kovar
NXP Employee
NXP Employee

Hi,

you can use both constructions. Both are HW methods which allow execute code atomically.

Call function interrupt_disable_interrupt() before the code which must be executed without interrupt. This function disable external interrupts and your code will be executed atomically. After the code in critical section is executed call interrupt_enable_interrupt() function. This function enables external interrupts.

 

Regards,

Martin

0 Kudos