⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 intc270.c

📁 dm270 source code
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
    DM270 ARM Evaluation Software

    (c)Texas Instruments 2003
*/

/**
    \file intc270.c
    \brief Interrupt Controller Related APIs
*/
#include <intc270.h>

/**
    \brief Enable or Disable interrupt



    \param intID    interrupt ID
    \param enable   \c TRUE: enable interrupt, \c FALSE: disable interrupt

    \return if success, \c E_PASS, else error code
*/
STATUS INTC_enable( INT_ID intID, BOOL enable ) {
    Uint16 eint;

    if( intID >= INT_MAX )
        return E_INVALID_INPUT;

    if(intID >=32 ) {
        eint = INTC_RGET(EINT2);

        if(enable)
            eint |= (1 << ( (Uint16)intID - 32) );
        else
            eint &= ~( 1 << ( (Uint16)intID - 32 ) );


        INTC_RSET( EINT2, eint );
    } else
    if(intID >=16 ) {
        eint = INTC_RGET(EINT1);

        if(enable)
            eint |= (1 << ( (Uint16)intID - 16) );
        else
            eint &= ~( 1 << ( (Uint16)intID - 16 ) );

        INTC_RSET( EINT1, eint );
    } else {
        eint = INTC_RGET(EINT0);

        if(enable)
            eint |= (1 << ( (Uint16)intID ) );
        else
            eint &= ~( 1 << ( (Uint16)intID ) );

        INTC_RSET( EINT0, eint );
    }
    return E_PASS;
}

/**
    \brief Clear IRQ interrupt status

    \param intID    interrupt ID

    \return if success, \c E_PASS, else error code
*/
STATUS INTC_clearIRQ( INT_ID intID) {

    if( intID >= INT_MAX )
        return E_INVALID_INPUT;

    if(intID >=32 ) {
        INTC_RSET( IRQ2, (1 << ( (Uint16)intID - 32) ) );
    } else
    if(intID >=16 ) {
        INTC_RSET( IRQ1, (1 << ( (Uint16)intID - 16) ) );
    } else {
        INTC_RSET( IRQ0, (1 << ( (Uint16)intID ) ) );
    }
    return E_PASS;

}

/**
    \brief Clear FIQ interrupt status

    \param intID    interrupt ID

    \return if success, \c E_PASS, else error code
*/
STATUS INTC_clearFIQ( INT_ID intID) {


    if( intID >= INT_MAX )
        return E_INVALID_INPUT;

    if(intID >=32 ) {
        INTC_RSET( FIQ2, (1 << ( (Uint16)intID - 32) ) );
    } else
    if(intID >=16 ) {
        INTC_RSET( FIQ1, (1 << ( (Uint16)intID - 16) ) );
    } else {
        INTC_RSET( FIQ0, (1 << ( (Uint16)intID ) ) );
    }
    return E_PASS;
}


/**
    \brief Set interrupt as IRQ

    \param intID    interrupt ID

    \return if success, \c E_PASS, else error code
*/
STATUS INTC_setIntAsIRQ( INT_ID intID ) {
    Uint16 eint;

    if( intID >= INT_MAX )
        return E_INVALID_INPUT;

    if(intID >=32 ) {
        eint = INTC_RGET(FISEL2);
        eint &= ~(1 << ( (Uint16)intID - 32) );
        INTC_RSET( FISEL2, eint );
    } else
    if(intID >=16 ) {
        eint = INTC_RGET(FISEL1);
        eint &= ~(1 << ( (Uint16)intID - 16) );
        INTC_RSET( FISEL1, eint );
    } else {
        eint = INTC_RGET(FISEL0);
        eint &= ~(1 << ( (Uint16)intID ) );
        INTC_RSET( FISEL0, eint );
    }
    return E_PASS;

}

/**
    \brief Set interrupt as FIQ

    \param intID    interrupt ID

    \return if success, \c E_PASS, else error code
*/
STATUS INTC_setIntAsFIQ( INT_ID intID ) {
    Uint16 eint;

    if( intID >= INT_MAX )
        return E_INVALID_INPUT;

    if(intID >=32 ) {
        eint = INTC_RGET(FISEL2);
        eint |= (1 << ( (Uint16)intID - 32) );
        INTC_RSET( FISEL2, eint );
    } else
    if(intID >=16 ) {
        eint = INTC_RGET(FISEL1);
        eint |= (1 << ( (Uint16)intID - 16) );
        INTC_RSET( FISEL1, eint );
    } else {
        eint = INTC_RGET(FISEL0);
        eint |= (1 << ( (Uint16)intID ) );
        INTC_RSET( FISEL0, eint );
    }
    return E_PASS;

}

/**
    \brief Check if interrupt type is IRQ or FIQ

    \param intID interrupt ID

    \return TRUE: 'intID' is IRQ, FALSE: 'intID' is FIQ
*/
BOOL INTC_isIntIRQ(INT_ID intID){
    Uint16 eint;

    if( intID >= INT_MAX )
        return FALSE;

    if(intID >=32 ) {
        if( INTC_RGET(FISEL2) & (1 << ( (Uint16)intID - 32) ) )
            eint=1;
        else
            eint=0;
    } else
    if(intID >=16 ) {
        if( INTC_RGET(FISEL1) & (1 << ( (Uint16)intID - 16) ) )
            eint=1;
        else
            eint=0;
    } else {
        if( INTC_RGET(FISEL0) & (1 << ( (Uint16)intID ) ) )
            eint=1;
        else
            eint=0;
    }

    return eint==1 ? FALSE : TRUE;

}


/**
    \brief Get FIQ interrupt source status

    \param intID interrupt ID

    \return 0: interrupt has occured and is pending, 1:interrupt has not occured
*/
Uint16 INTC_getIntFIQStatus( INT_ID intID){
    Uint16 eint;

    if( intID >= INT_MAX )
        return 1;

    if(intID >=32 ) {
        if( INTC_RGET(FIQ2) & (1 << ( (Uint16)intID - 32) ) )
            eint=1;
        else
            eint=0;
    } else
    if(intID >=16 ) {
        if( INTC_RGET(FIQ1) & (1 << ( (Uint16)intID - 16) ) )
            eint=1;
        else
            eint=0;
    } else {
        if( INTC_RGET(FIQ0) & (1 << ( (Uint16)intID ) ) )
            eint=1;
        else
            eint=0;
    }
    return eint;

}

/**
    \brief Get IRQ interrupt source status

    \param intID interrupt ID

    \return 0: interrupt has occured and is pending, 1:interrupt has not occured
*/
Uint16 INTC_getIntIRQStatus( INT_ID intID){
    Uint16 eint;

    if( intID >= INT_MAX )
        return 1;

    if(intID >=32 ) {
        if( INTC_RGET(IRQ2) & (1 << ( (Uint16)intID - 32) ) )
            eint=1;
        else
            eint=0;
    } else
    if(intID >=16 ) {
        if( INTC_RGET(IRQ1) & (1 << ( (Uint16)intID - 16) ) )
            eint=1;
        else
            eint=0;
    } else {
        if( INTC_RGET(IRQ0) & (1 << ( (Uint16)intID ) ) )
            eint=1;
        else
            eint=0;
    }
    return eint;
}


/**
    \brief  Set interrupt table address

    \param tableAddress Interrupt table address, must be 8byte aligned
    \param entrySize    Size of each entry in interrupt table in units of bytes. \n Entry size can be 4, 8, 16 or 32 byte

    \return if success, \c E_PASS, else error code
*/
STATUS INTC_setIntTableAddress( char *tableAddress, Uint16 entrySize) {
    STATUS status=E_PASS;

    if((Uint32)tableAddress & 0x7 ) {
        // 'tableAddress' must be 8 byte aligned
        status=E_INVALID_INPUT;
        return status;
    }

    INTC_FSET(EABASE0, EABL, (Uint32)tableAddress >> 3);
    INTC_RSET(EABASE1, (Uint32)tableAddress >> 16 );

    switch(entrySize) {
        case  4: INTC_FSET(EABASE0, TSIZE, 0 ); break;
        case  8: INTC_FSET(EABASE0, TSIZE, 1 ); break;
        case 16: INTC_FSET(EABASE0, TSIZE, 2 ); break;
        case 32: INTC_FSET(EABASE0, TSIZE, 3 ); break;
        default: status=E_INVALID_INPUT; break;
    }
    return status;
}

/**
    \brief  Set interrupt priority

    \param intID        interrupt ID
    \param priority     interrupt priority, 0..39 0:highest, 39:lowest priority

    \return if success, \c E_PASS, else error code
*/
STATUS INTC_setIntPriority( INT_ID intID, Uint16 priority) {

    if( intID >= INT_MAX )
        return E_INVALID_INPUT;

    if(priority > 39)
        return E_INVALID_INPUT;

    switch(priority) {
        case 0:
            INTC_FSET(INTPRI00, PRI00, intID);
            break;
        case 1:
            INTC_FSET(INTPRI00, PRI01, intID);
            break;
        case 2:
            INTC_FSET(INTPRI01, PRI02, intID);
            break;
        case 3:
            INTC_FSET(INTPRI01, PRI03, intID);
            break;
        case 4:
            INTC_FSET(INTPRI02, PRI04, intID);
            break;
        case 5:
            INTC_FSET(INTPRI02, PRI05, intID);
            break;
        case 6:
            INTC_FSET(INTPRI03, PRI06, intID);
            break;
        case 7:
            INTC_FSET(INTPRI03, PRI07, intID);
            break;
        case 8:
            INTC_FSET(INTPRI04, PRI08, intID);
            break;
        case 9:
            INTC_FSET(INTPRI04, PRI09, intID);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -