Merge branch 'bugfix/fix_disable_interrupt_then_call_newlib_fn' into 'master'

Fix application disable intterupt then call newlib internal mutex function

See merge request sdk/ESP8266_RTOS_SDK!349
This commit is contained in:
Dong Heng
2018-07-30 20:31:46 +08:00
3 changed files with 29 additions and 0 deletions

View File

@ -224,6 +224,13 @@ void esp_mem_trace(const void *ptr, const char *trace, int no);
*/
#define esp_mem_mark_file(ptr) esp_mem_trace((ptr), __FILE__, LINE__)
/*
* @brief check if CPU core interrupt is disable
*
* @return true if interrupt is disable or false
*/
bool interrupt_is_disable(void);
#ifdef __cplusplus
}
#endif

View File

@ -300,6 +300,20 @@ void ResetCcountVal(unsigned int cnt_val)
asm volatile("wsr a2, ccount");
}
/*
* @brief check if CPU core interrupt is disable
*/
bool interrupt_is_disable(void)
{
uint32_t tmp;
__asm__ __volatile__ (
"rsr %0, PS\n"
: "=a"(tmp) : : "memory");
return tmp & 0xFUL ? true : false;
}
_xt_isr_entry isr[16];
char _xt_isr_status = 0;

View File

@ -112,6 +112,10 @@ void _lock_close_recursive(_lock_t *lock) {
mutex_type is queueQUEUE_TYPE_RECURSIVE_MUTEX or queueQUEUE_TYPE_MUTEX
*/
static int lock_acquire_generic(_lock_t *lock, uint32_t delay, uint8_t mutex_type) {
/* If application function has disabled interrupt, then it must not acquire the mutex */
if (interrupt_is_disable() == true && !xPortInIsrContext())
return 0;
xSemaphoreHandle h = (xSemaphoreHandle)(*lock);
if (!h) {
if (xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED) {
@ -171,6 +175,10 @@ int _lock_try_acquire_recursive(_lock_t *lock) {
mutex_type is queueQUEUE_TYPE_RECURSIVE_MUTEX or queueQUEUE_TYPE_MUTEX
*/
static void lock_release_generic(_lock_t *lock, uint8_t mutex_type) {
/* If application function has disabled interrupt, then it must not release the mutex */
if (interrupt_is_disable() == true && !xPortInIsrContext())
return ;
xSemaphoreHandle h = (xSemaphoreHandle)(*lock);
if (h == NULL) {
/* This is probably because the scheduler isn't running yet,