This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

C/C++ atomic operation on ARM9 and ARM Cortex-M4

I have a question about C/C++ atomic operation on ARM9 and ARM Cortex-M4. I am using ARMCC compiler with C / C++ languages. It interests me if it is possible that an interrupt will be handled in the middle of operations:

  • Read 8-bit character form structure which is not aligned (packed).  From internal memory.
  • Read 8-bit character form structure which is not aligned (packed).  From external memory.
  • Read 32-bit integer from external memory. The memory is connected to the processor by 16 (or 8) bits data line.
  • Read 64-bit long long integer from internal memory.
  • Read 64-bit long long integer from external memory.

Does anything change if you access to these objects indirectly by pointer or reference?

Are there any other basic operations potentially unsafe in multi-thread application?

Thanks for answers.

Parents
  • Access of 64-bit data can be itnerrupted on Cortex-M3/M4:

    • If a 64-bit data is accessed using LDM/STM instructions, as Jens said, the instruction can get interrupted in the middle, the processor execute the ISR and then resume the LDM/STM from where it was interrupted.
    • If the 64-bit data is accessed using LDRD/STRD instructions, the instruction can get abandoned and restart after the ISR.
    • A compiler could also use multiple LDR/STR to access a 64-bit data.

    For 8-bit/16-bit/32-bit data, provided that the memory instruction generated is a single LDR/STR instruction, interrupt cannot happen in between. The external memory controller might convert 16-bit / 32-bit access into multiple transfers on the memory bus, but the processor doesn't know this and will wait until the transfer is done before taking the interrupt.

    One more thing to add: there is no 64-bit exclusive access instructions for Cortex-M4.

    regards,

    Joseph

Reply
  • Access of 64-bit data can be itnerrupted on Cortex-M3/M4:

    • If a 64-bit data is accessed using LDM/STM instructions, as Jens said, the instruction can get interrupted in the middle, the processor execute the ISR and then resume the LDM/STM from where it was interrupted.
    • If the 64-bit data is accessed using LDRD/STRD instructions, the instruction can get abandoned and restart after the ISR.
    • A compiler could also use multiple LDR/STR to access a 64-bit data.

    For 8-bit/16-bit/32-bit data, provided that the memory instruction generated is a single LDR/STR instruction, interrupt cannot happen in between. The external memory controller might convert 16-bit / 32-bit access into multiple transfers on the memory bus, but the processor doesn't know this and will wait until the transfer is done before taking the interrupt.

    One more thing to add: there is no 64-bit exclusive access instructions for Cortex-M4.

    regards,

    Joseph

Children