freertos, ksdk and interrupts - accessing hardware

peter-au wrote on Thursday, January 19, 2017:

Using freertos and ksdk on a Cortex M4. Using kdsk if your accessing hardware from inside and outside interrupts do you need to add disable and enable interrupts around the hardware access in the main thread?

Like this:
void main(void)
while (1)
//do other stuff


rtel wrote on Friday, January 20, 2017:

I’m not sure why KSDK would be relevant to your question other than if
you are asking about the thread safety of the libraries that come with
it (and hence if you need to disable interrupts). If that is the case
then I’m afraid the answer is I have no idea, and you would either have
to look at the implementation of the libraries, or ask the vendor that
supplied the libraries.

peter-au wrote on Friday, January 20, 2017:

Hi, say kdsk-accessHardware() calls Kinetis SDK (kdsk) function GPIO_WritePinOutput(). kdsk-accessHardware() is called from the main loop and within the interrupt.
Then inside main() do I you need to include the lines disableInterruptXYZ() and enableInterruptXYZ()?

ie if the code inside GPIO_WritePinOutput() in main() is running and the interrupt decides to run - and also run GPIO_WritePinOutput() whilst GPIO_WritePinOutput() is partially complete - is that a problem?

rtel wrote on Friday, January 20, 2017:

I still don’t know anything about how the KSDK libraries are
implemented, so my previous answer still holds. They might have that
sort of critical section in them already, which would be doubtful, but
if you are just toggling a pin you might find it is atomic anyway
depending on how the registers are implemented.

Never disable and enable interrupts directly though, use
taskENTER_CRITICAL() and taskEXIT_CRITICAL() (Google them to find the
docs on the site or download the reference manual, or
download the book for a broader picture).