lwip sys_arch: Add functional xInsideISR implementation
Relies on global flags set when the user ISR is executing. Unclear if this fixes any bugs as ISR code may not have been calling into LWIP, but the previous implementation was broken.
This commit is contained in:
parent
0caab973a5
commit
640609c3f5
2 changed files with 598 additions and 585 deletions
|
@ -9,6 +9,8 @@
|
|||
|
||||
_xt_isr isr[16];
|
||||
|
||||
bool esp_in_isr;
|
||||
|
||||
void IRAM _xt_isr_attach(uint8_t i, _xt_isr func)
|
||||
{
|
||||
isr[i] = func;
|
||||
|
@ -20,6 +22,8 @@ void IRAM _xt_isr_attach(uint8_t i, _xt_isr func)
|
|||
*/
|
||||
uint16_t IRAM _xt_isr_handler(uint16_t intset)
|
||||
{
|
||||
esp_in_isr = true;
|
||||
|
||||
/* WDT has highest priority (occasional WDT resets otherwise) */
|
||||
if(intset & BIT(INUM_WDT)) {
|
||||
_xt_clear_ints(BIT(INUM_WDT));
|
||||
|
@ -35,5 +39,7 @@ uint16_t IRAM _xt_isr_handler(uint16_t intset)
|
|||
intset -= mask;
|
||||
}
|
||||
|
||||
esp_in_isr = false;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -49,10 +49,18 @@
|
|||
#include "lwip/mem.h"
|
||||
#include "lwip/stats.h"
|
||||
|
||||
/* Very crude mechanism used to determine if the critical section handling
|
||||
functions are being called from an interrupt context or not. This relies on
|
||||
the interrupt handler setting this variable manually. */
|
||||
portBASE_TYPE xInsideISR = pdFALSE;
|
||||
extern bool esp_in_isr;
|
||||
|
||||
/* Based on the default xInsideISR mechanism to determine
|
||||
if an ISR is running.
|
||||
|
||||
Doesn't support the possibility that LWIP functions are called from the NMI
|
||||
handler (none are called from NMI when using current/SDK implementation.)
|
||||
*/
|
||||
static inline bool is_inside_isr()
|
||||
{
|
||||
return esp_in_isr;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
* Routine: sys_mbox_new
|
||||
|
@ -66,7 +74,7 @@ portBASE_TYPE xInsideISR = pdFALSE;
|
|||
*---------------------------------------------------------------------------*/
|
||||
err_t sys_mbox_new( sys_mbox_t *pxMailBox, int iSize )
|
||||
{
|
||||
err_t xReturn = ERR_MEM;
|
||||
err_t xReturn = ERR_MEM;
|
||||
|
||||
*pxMailBox = xQueueCreate( iSize, sizeof( void * ) );
|
||||
|
||||
|
@ -145,7 +153,7 @@ err_t sys_mbox_trypost( sys_mbox_t *pxMailBox, void *pxMessageToPost )
|
|||
err_t xReturn;
|
||||
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
|
||||
|
||||
if( xInsideISR != pdFALSE )
|
||||
if( is_inside_isr() != pdFALSE )
|
||||
{
|
||||
xReturn = xQueueSendFromISR( *pxMailBox, &pxMessageToPost, &xHigherPriorityTaskWoken );
|
||||
}
|
||||
|
@ -208,7 +216,7 @@ unsigned long ulReturn;
|
|||
|
||||
if( ulTimeOut != 0UL )
|
||||
{
|
||||
configASSERT( xInsideISR == ( portBASE_TYPE ) 0 );
|
||||
configASSERT( is_inside_isr() == ( portBASE_TYPE ) 0 );
|
||||
|
||||
if( pdTRUE == xQueueReceive( *pxMailBox, &( *ppvBuffer ), ulTimeOut/ portTICK_RATE_MS ) )
|
||||
{
|
||||
|
@ -267,7 +275,7 @@ portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
|
|||
ppvBuffer = &pvDummy;
|
||||
}
|
||||
|
||||
if( xInsideISR != pdFALSE )
|
||||
if( is_inside_isr() != pdFALSE )
|
||||
{
|
||||
lResult = xQueueReceiveFromISR( *pxMailBox, &( *ppvBuffer ), &xHigherPriorityTaskWoken );
|
||||
}
|
||||
|
@ -443,7 +451,7 @@ void sys_sem_signal( sys_sem_t *pxSemaphore )
|
|||
{
|
||||
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
|
||||
|
||||
if( xInsideISR != pdFALSE )
|
||||
if( is_inside_isr() != pdFALSE )
|
||||
{
|
||||
xSemaphoreGiveFromISR( *pxSemaphore, &xHigherPriorityTaskWoken );
|
||||
}
|
||||
|
@ -541,7 +549,7 @@ sys_thread_t xReturn;
|
|||
*---------------------------------------------------------------------------*/
|
||||
sys_prot_t sys_arch_protect( void )
|
||||
{
|
||||
if( xInsideISR == pdFALSE )
|
||||
if( is_inside_isr() == pdFALSE )
|
||||
{
|
||||
taskENTER_CRITICAL();
|
||||
}
|
||||
|
@ -562,7 +570,7 @@ sys_prot_t sys_arch_protect( void )
|
|||
void sys_arch_unprotect( sys_prot_t xValue )
|
||||
{
|
||||
(void) xValue;
|
||||
if( xInsideISR == pdFALSE )
|
||||
if( is_inside_isr() == pdFALSE )
|
||||
{
|
||||
taskEXIT_CRITICAL();
|
||||
}
|
||||
|
@ -582,4 +590,3 @@ void sys_assert( const char *pcMessage )
|
|||
/*-------------------------------------------------------------------------*
|
||||
* End of File: sys_arch.c
|
||||
*-------------------------------------------------------------------------*/
|
||||
|
||||
|
|
Loading…
Reference in a new issue