hgyxb ll

about function EnterCritical

Discussion created by hgyxb ll on Apr 10, 2013
Latest reply on Jan 30, 2014 by Petr_H

I have used Processor Expert Software 10.0.0 and IAR.

And  Processor Expert Software generate the code:

-----------------------------------------------------------------------

/* Save status register and disable interrupts */

#define EnterCritical() \

do {\

  if (++SR_lock == 1u) { \

  SR_reg = (uint8_t)__get_PRIMASK(); \

  __set_PRIMASK(0x01ul); \

  } \

} while(0)

-----------------------------------------------------------------------

 

I am afraid that it may have some leak.

For example:

when main task run EnterCritical() to change some important thing .

If it run over  ++SR_lock and do not run  SR_lock == 1u,

then an interrupt occurs and run  EnterCritical() to change some important thing too.

Then the interrupt can not run  __set_PRIMASK(0x01ul) because  now SR_lock is 2.

When the interrupt run the important code, a high priority interrupt may occurs and  run  EnterCritical() to change some important thing too.

Then change of the important thing  may be conflict.

 

 

 

 

 

Outcomes