Critical section in MPC5604

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Critical section in MPC5604

676件の閲覧回数
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?

ラベル(1)
0 件の賞賛
1 返信

411件の閲覧回数
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 件の賞賛