This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RM57L843: RM57L843: Questions for LwIP example - #2

Part Number: RM57L843

Hi,

My customer refers to below LwIP demo example.
http://git.ti.com/hercules_examples/hercules_examples/trees/master/Application/LwIP

He wants to implement LwIP code in his system and has a few questions.
In below file, 
\hercules_examples-master\Application\ActiveWebserver\1.1.0\example\hdk\src\lwip_main.c

At line#500 and after, there are IRQ interrupt handlers.
He wants to use FIQ instead of IRQ to handle these functions.

/*
** Interrupt Handler for Core 0 Receive interrupt
*/
volatile int countEMACCore0RxIsr = 0;
#pragma INTERRUPT(EMACCore0RxIsr, IRQ)
void EMACCore0RxIsr(void)
{
		countEMACCore0RxIsr++;
		lwIPRxIntHandler(0);
}

/*
** Interrupt Handler for Core 0 Transmit interrupt
*/
volatile int countEMACCore0TxIsr = 0;
#pragma INTERRUPT(EMACCore0TxIsr, IRQ)
void EMACCore0TxIsr(void)
{
	countEMACCore0TxIsr++;
    lwIPTxIntHandler(0);
}

void IntMasterIRQEnable(void)
{
	_enable_IRQ();
	return;
}

void IntMasterIRQDisable(void)
{
	_disable_IRQ();
	return;
}

Quetions
1) There are IntMasterIRQEnable() and IntMasterIRQDisable() functions.
According to customer, it seems they are called within IRQ ISR.
What is a reason why IRQ is enabled / disabled inside ISR?

2) Customer wants to use FIQ, so enabling / disabling IRQ inside FIQ ISR are not good.
How these code should be modified to use FIQ instead of IRQ?

Thanks and reagrds,
Koichiro Tashiro

  • Hi Koichiro-san,

    IntMasterIRQEnable() and IntMasterIRQDisable() are not called in ISR. Can you point me which ISR call those two functions? Thanks

  • Hi QJ,

    According to customer, these functions are called in below file.
    \hercules_examples-master\Application\LwIP\v00.04.00\lwip-1.4.1\ports\hdk\sys_arch.c

    sys_prot_t
    sys_arch_protect(void)
    {
      sys_prot_t status;
      status = (IntMasterStatusGet() & 0xFF);
    
      IntMasterIRQDisable();
      return status;
    }
    
    /**
     * This function is used to unlock access to critical sections when lwipopt.h
     * defines SYS_LIGHTWEIGHT_PROT. It enables interrupts if the value of the lev
     * parameter indicates that they were enabled when the matching call to
     * sys_arch_protect() was made.
     *
     * @param lev is the interrupt level when the matching protect function was
     * called
     */
    void
    sys_arch_unprotect(sys_prot_t lev)
    {
      /* Only turn interrupts back on if they were originally on when the matching
         sys_arch_protect() call was made. */
      if((lev & 0x80) == 0) {
        IntMasterIRQEnable();
      }
    }
    

    IntMasterIRQEnable() and IntMasterIRQDisable() are not called in ISR.

    Do you mean these functions are called outside of ISR, so they can be left untouched even FIQ is used?

    Thanks and regards,
    Koichiro Tashiro

  • Hi QJ,

    Could you answer this item?

    Thanks and regards,
    Koichiro Tashiro

  • sys_arch_unprotect()

    sys_arch_protect()

    Those two functions (sys_arch_unprotect(), and sys_arch_protect()) is only called during very short critical regions, and is only required if your port is supporting an operating system.

    The sys_arch_unprotect() should not be called inside the IRQ ISR. If called inside an IRQ ISR, the ISR is forced to be enabled before the end of ISR. The ARM Cortex-R4/5 core does not support more than one IRQ to be taken at a time. This is mainly because it has only one Saved Program Status Register (SPSR) and one Link Register (LR) register. If an IRQ is interrupted by another IRQ, these CPU registers would get overwritten (corrupted) and a later restoring of the processor state would not be possible anymore.

  • Hi Koichiro-san,

    The region protection is not required in interrupt ISR since the IRQ has been already disabled. You don't need to call those two functions in IRQ ISR.

    In FIQ ISR, both FIQ and IQ are disabled automatically, so the region protection is not required. 

  • Hi QJ,

    Do you mean in case the customer wants to use FIQ instead of IRQ, both sys_arch_unprotect() and sys_arch_protect() are simply commented out?

    Thanks and regards,
    Koichiro Tashiro

  • Yes, as I said that both FIQ and IRQ are disabled in FIQ ISR automatically, so the region protection is not required.