Electronic – Is it possible to interrupt the copy process of a struct by an interrupt in embedded C

cembeddedinterruptsmicrocontroller

Inside the driver I have got a function to copy the data from the internal struct into a struct from the application.

Can this process be interrupted by a microcontroller interrupt trigger?

uint16_t getRawData(struct Data *Data_external)
{
  if(Data_external == NULL)
  {
    return ERR_PARA;
  }
  else
  {
    *Data_external = Data_internal;            // the copy process. Could this be interrupted? 
  }
  return ERR_NONE;
}

Best Answer

Yes. Pretty much everything in an MCU can be interrupted by an interrupt request. When the interrupt handler completes the previous code will just continue so it is usually not a problem.

In a special case the interrupt handlers can be interrupted themselves by interrupts of higher priorities (nested interrupts).

If a series of instructions must not be interrupted then you need to implement a critical section (basically globally disable interrupts, do the job, enable again).

Remember that depending on architecture of the target CPU a single line of C can be compiled to many assembly instructions. A simple i++ on an AVR is compiled to multiple instructions if i is for example uint32_t.