PIC32 CP0 operations

The code for the PIC32 in portmacro.h does a read-modify-write on CP0 to control stuff like interrupts, which does not seem safe.  For example this code enables interrupts.
    ulStatus = _CP0_GET_STATUS()
    ulStatus &= ~portALL_IPL_BITS;
    _CP0_SET_STATUS( ulStatus );
why do that rather than this
    _CP0_BIC_STATUS(portALL)IPL_BITS);

PIC32 CP0 operations

The code generated by your suggestion is: 9D000020  40026000   mfc0        v0,Status << read
9D000024  00401821   addu        v1,v0,zero
9D000028  3C02FFFF   lui         v0,0xffff
9D00002C  344203FF   ori         v0,v0,0x3ff
9D000030  00621024   and         v0,v1,v0
9D000034  40826000   mtc0        v0,Status << write so it is still performing a read/modify/write sequence so I’m not sure what is to be gained. That said, the original code is probably less than ideal, however I don’t think it is problematic because each task has its own Status value, and its own stack onto which ulStatus is stored. Regards.

PIC32 CP0 operations

Thanks for the reply, I should have looked at the assembly first.
I’m still left wondering how atomic the operation is, but the is independent of FreeRTOS. Eric