diff --git a/hal/critical_section_api.h b/hal/critical_section_api.h index 3ca51cfd2a..e16ac7f962 100644 --- a/hal/critical_section_api.h +++ b/hal/critical_section_api.h @@ -28,41 +28,55 @@ extern "C" { */ /** - * Mark the start of a critical section - * - * This function is called directly by core_util_critical_section_enter on - * first entrance to a critical section. - * - * There is a default implementation of this function which will save the - * current state of interrupts before disabling them. This implementation can - * be found in mbed_critical_section_api.c. This behaviour is can be overridden - * on a per platform basis by providing a different implementation within the - * correct targets directory. - * - * The function is only called once per critical section by - * core_util_critical_section_enter. When implementing this function for a - * platform you must store any state that you intend to alter within this - * function so it can be restored when exiting the critical section. - * - */ + * Mark the start of a critical section + * + * This function will be called by core_util_critical_section_enter() each time + * the application requests to enter a critical section. The purpose of the + * critical section is to ensure mutual-exclusion synchronisation of the + * processor by preventing any change in processor control, the default + * behaviour requires storing the state of interrupts in the system before + * disabling them. + * + * The critical section code supports nesting. When a thread has entered a + * critical section it can make additional calls to + * core_util_critical_section_enter() without deadlocking itself. The critical + * section driver API tracks the number of nested calls to the critical section. + * The critical section will only be exited when + * core_util_critical_section_exit() has been called once for each time it + * entered the critical section. + * + * On the first call to enter a critical section this function MUST store the + * state of any interrupts or other application settings it will modify to + * facilitate the critical section. + * + * Each successive call to enter the critical section MUST ignore storing or + * modifying any application state. + * + * The default implementation of this function which will save the current state + * of interrupts before disabling them. This implementation can be found in + * mbed_critical_section_api.c. This behaviour is can be overridden on a per + * platform basis by providing a different implementation within the correct + * targets directory. + */ void hal_critical_section_enter(void); -/** Mark the end of a critical section - * - * This function is called directly by core_util_critical_section_exit on the - * final exit from a critical section. - * - * There is a default implementation of this function, it will restore the - * state of the interrupts as they were prior to entering this critical - * section, this implementation can be found in mbed_critical_section_api.c. - * This behavior is overridable by providing a different function - * implementation within the correct targets directory. - * - * This function is only called once per critical section. When implemented - * for a specific platform it must restore any state that was saved upon - * entering the current critical section. - * - */ +/** Mark the end of a critical section. + * + * The purpose of this function is to restore any state that was modified upon + * entering the critical section, allowing other threads or interrupts to change + * the processor control. + * + * This function will be called once by core_util_critical_section_exit() per + * critical section on last call to exit. When called, the application MUST + * restore the saved interrupt/application state that was saved when entering + * the critical section. + * + * There is a default implementation of this function, it will restore the state + * of interrupts that were previously saved when hal_critical_section_enter was + * first called, this implementation can be found in + * mbed_critical_section_api.c. This behaviour is overridable by providing a + * different function implementation within the correct targets directory. + */ void hal_critical_section_exit(void); /**@}*/