Keil Logo

C166: EXTS PROBLEMS USING THE _ATOMIC_ FUNCTION


Information in this article applies to:

  • C166 All Versions

SYMPTOMS

I have written the following code:

_atomic_(4);
Event = *ISREventPointer;
_atomic_(4);
*ISREventPointer = 0;

expecting interrupts to be disabled for the duration of the execution of both lines of C code. However, the assembly code generated was:

150E D130          ATOMIC    #04H
                                           ; SOURCE LINE # 1347
1510 DC0F          EXTS      R15,#01H
1512 A9AE          MOVB      RL5,[R14]
;---- Variable 'Event' assigned to Register 'RL5' ----
                                           ; SOURCE LINE # 1348
1514 D130          ATOMIC    #04H
                                           ; SOURCE LINE # 1349
1516 E10C          MOVB      RL6,#00H
1518 DC0F          EXTS      R15,#01H
151A B9CE          MOVB      [R14],RL6

If I am reading this correctly, the EXTS instruction will reset the internal counter being used for the ATOMIC instruction back to 1, causing only the following instruction (MOVB) to be non-interruptable.

Is there a workaround for this problem?

CAUSE

This happens because the EXTS instruction is required to execute the two lines of C code you have written. The result is that you run into a limitation of the microcontroller which cannot properly handle situations where EXTS instructions follow ATOMIC instructions.

RESOLUTION

There are two other methods to disable interrupts.

  1. Use #pragma DISABLE. This generates the necessary code to disable interrupts for the following function. For example:
    #pragma DISABLE
    
    void foo(void)
    {
      Event = *ISREventPointer;
      *ISREventPointer = 0;
    }
    
  2. Use the intrinsic _bfld_ function to achieve the same result as #pragma DISABLE, but for part of a function:
    _bfld_(PSW, 0xF000, 0xF000);     // disable interrupts
    _nop_();
    _nop_();
    Event = *ISREventPointer;
    *ISREventPointer = 0;
    _bfld_(PSW, 0xF000, 0x0000);     // enable interrupts
    

    Note the insertion of the two NOPs after the BFLD instruction. This is to avoid pipelining problems as it takes two instruction cycles for the interrupts to actually be disabled.

MORE INFORMATION

  • Refer to DISABLE in the C166 User's Guide.
  • Refer to _atomic_ in the C166 User's Guide.
  • Refer to _bfld_ in the C166 User's Guide.
  • Refer to _nop_ in the C166 User's Guide.
  • Refer to Using Interrupts in the C166 User's Guide.
  • Refer to sections 19.8 and 19.9 in the Siemens C167 Derivatives User's Manual (03.96) for more information on the ATOMIC and EXTS instructions and the problems associated with using them together.

Last Reviewed: Friday, July 15, 2005


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.