Steve Janisch

MQX 4.0 BSP Bug: twr-mcf54418 (_mcf5441_int_init - _bsp_int_init)

Discussion created by Steve Janisch on Apr 26, 2013
Latest reply on May 15, 2013 by Martin Kojtal

I have discovered a bug in the _mcf5441_int_init routine (aka _bsp_int_init via macro definition).  In fact I note the _bsp_int_init macro just in case it carries over to other BSPs.

 

The issue is with the incoming argument PSP_INTERRUPT_TABLE_INDEX irq.

 

When I called the routine from my application, the passed in irq was being interpreted as a signed 8-bit number, so any irq > 127 (the mcf5441x has interrupt vectors up to 255) was being interpreted as a negative number.  The function would fail with the return code MQX_INVALID_PARAMETER.

 

My quick fix was to change the name of the argument from irq to irq_in and then add the line

uchar irq = irq_in ;

 

Header 1

/*FUNCTION*-----------------------------------------------------------------

*

* Function Name   : _mcf5441_int_init

* Returned Value  : uint_32

* Comments        :

*   Initialize a specific interrupt in the proper interrupt controller

*   SEJ 26-APR-2013 : Revised to quick fix incoming irq as unsigned char.

*

*END*---------------------------------------------------------------------*/

 

 

uint_32 _mcf5441_int_init

   (

      // [IN} Interrupt number

    //PSP_INTERRUPT_TABLE_INDEX irq,

      PSP_INTERRUPT_TABLE_INDEX irq_in, // SEJ - this is being case as signed 8-bit

 

 

      // [IN} Interrupt priority level

      _int_level                level,

 

 

      // [IN} Unmask the interrupt now?

      boolean                   unmask

   )

{

    _mqx_int idx;

    uint_32 temp;

 

 

    /* This function had some issues... at least when called from an external application.

     * The passed PSP_INTERRUPT_TABLE_INDEX irq was interpreted as a signed 8-bit number,

     * so any irq > 127 came in as a negative number.  Perhaps this issue is deeper than

     * this, but to quick fix I changed the passed in argument 'irq' to 'irq_in' and then

     * declare the local uchar irq here.

    **/

    uchar irq = irq_in ;


 

 

 

 

    if (irq >= PSP_INT_FIRST_EXTERNAL) {

        idx = irq - PSP_INT_FIRST_EXTERNAL;

  

        temp = _psp_get_sr();

        _psp_set_sr(temp | 0x0700);

       

        if (idx < 64) {

            PSP_GET_ICTRL0_BASE()->ICR[idx] = level & 7;

           

            if (unmask)

                PSP_GET_ICTRL0_BASE()->CIMR = MCF54XX_ICTRL_IMR_N(idx);

            else

                PSP_GET_ICTRL0_BASE()->SIMR = MCF54XX_ICTRL_IMR_N(idx);

        }

        else if (idx < 128) {

            idx -= 64;

            PSP_GET_ICTRL1_BASE()->ICR[idx] = level & 7;

           

            if (unmask)

                PSP_GET_ICTRL1_BASE()->CIMR = MCF54XX_ICTRL_IMR_N(idx);

            else

                PSP_GET_ICTRL1_BASE()->SIMR = MCF54XX_ICTRL_IMR_N(idx);

        }

        else {

            idx -= 128;

            PSP_GET_ICTRL2_BASE()->ICR[idx] = level & 7;

           

            if (unmask)

                PSP_GET_ICTRL2_BASE()->CIMR = MCF54XX_ICTRL_IMR_N(idx);

            else

                PSP_GET_ICTRL2_BASE()->SIMR = MCF54XX_ICTRL_IMR_N(idx);

        }

       

        _psp_set_sr(temp);

   

        return MQX_OK;

    }

   

    return MQX_INVALID_PARAMETER;

}

 

Outcomes