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

Allocating memory from heap from within a ISR on Cortex

Is there is recommandations, hints on do-do-not-do when ISR requires to allocate dynamic memory?

Parents
  • Almost every OS and bare metal library prohibit such things in an ISR and for very good reason.  If you need to fill in a buffer or something in an ISR, make sure it is allocated beforehand and the address accessible to the ISR.

    Problems:

    1. What do you do in case of allocation failure?

    2. ISRs are supposed to do two, and only two, thing: Stop the hardware from interrupting and schedule post processing in normal context.  To do anything else risks severely degrading the performance and reliability of the system.

    3. Most calls, like allocating memory, requires some sort of process context.  An ISR has no such context, unless it is bare metal.

    Potential solutions:

    1. Rotating buffers.

    2. Pre-allocated single buffer

    3. Allocate and copy data in post processing AFTER the HW interrupt has been acknowledged and system interrupts reenabled.

Reply
  • Almost every OS and bare metal library prohibit such things in an ISR and for very good reason.  If you need to fill in a buffer or something in an ISR, make sure it is allocated beforehand and the address accessible to the ISR.

    Problems:

    1. What do you do in case of allocation failure?

    2. ISRs are supposed to do two, and only two, thing: Stop the hardware from interrupting and schedule post processing in normal context.  To do anything else risks severely degrading the performance and reliability of the system.

    3. Most calls, like allocating memory, requires some sort of process context.  An ISR has no such context, unless it is bare metal.

    Potential solutions:

    1. Rotating buffers.

    2. Pre-allocated single buffer

    3. Allocate and copy data in post processing AFTER the HW interrupt has been acknowledged and system interrupts reenabled.

Children