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

📄 lib_at91sam7x256.h

📁 一个开源的Modbus协议栈
💻 H
📖 第 1 页 / 共 5 页
字号:

//*----------------------------------------------------------------------------
//* \fn    AT91F_PMC_DisablePCK
//* \brief Disable Programmable Clock x Output
//*----------------------------------------------------------------------------
static __inline void
AT91F_PMC_DisablePCK( AT91PS_PMC pPMC,  // \arg pointer to PMC controller
                      unsigned int pck )        // \arg Programmable Clock x Output
{
    pPMC->PMC_SCDR = ( 1 << pck ) << 8;
}

//*----------------------------------------------------------------------------
//* \fn    AT91F_PMC_EnableIt
//* \brief Enable PMC interrupt
//*----------------------------------------------------------------------------
static __inline void
AT91F_PMC_EnableIt( AT91PS_PMC pPMC,    // pointer to a PMC controller
                    unsigned int flag ) // IT to be enabled
{
    //* Write to the IER register
    pPMC->PMC_IER = flag;
}

//*----------------------------------------------------------------------------
//* \fn    AT91F_PMC_DisableIt
//* \brief Disable PMC interrupt
//*----------------------------------------------------------------------------
static __inline void
AT91F_PMC_DisableIt( AT91PS_PMC pPMC,   // pointer to a PMC controller
                     unsigned int flag )        // IT to be disabled
{
    //* Write to the IDR register
    pPMC->PMC_IDR = flag;
}

//*----------------------------------------------------------------------------
//* \fn    AT91F_PMC_GetStatus
//* \brief Return PMC Interrupt Status
//*----------------------------------------------------------------------------
static __inline unsigned int
AT91F_PMC_GetStatus(            // \return PMC Interrupt Status
                        AT91PS_PMC pPMC )       // pointer to a PMC controller
{
    return pPMC->PMC_SR;
}

//*----------------------------------------------------------------------------
//* \fn    AT91F_PMC_GetInterruptMaskStatus
//* \brief Return PMC Interrupt Mask Status
//*----------------------------------------------------------------------------
static __inline unsigned int
AT91F_PMC_GetInterruptMaskStatus(       // \return PMC Interrupt Mask Status
                                     AT91PS_PMC pPMC )  // pointer to a PMC controller
{
    return pPMC->PMC_IMR;
}

//*----------------------------------------------------------------------------
//* \fn    AT91F_PMC_IsInterruptMasked
//* \brief Test if PMC Interrupt is Masked
//*----------------------------------------------------------------------------
static __inline unsigned int
AT91F_PMC_IsInterruptMasked( AT91PS_PMC pPMC,   // \arg  pointer to a PMC controller
                             unsigned int flag )        // \arg  flag to be tested
{
    return ( AT91F_PMC_GetInterruptMaskStatus( pPMC ) & flag );
}

//*----------------------------------------------------------------------------
//* \fn    AT91F_PMC_IsStatusSet
//* \brief Test if PMC Status is Set
//*----------------------------------------------------------------------------
static __inline unsigned int
AT91F_PMC_IsStatusSet( AT91PS_PMC pPMC, // \arg  pointer to a PMC controller
                       unsigned int flag )      // \arg  flag to be tested
{
    return ( AT91F_PMC_GetStatus( pPMC ) & flag );
}

// ----------------------------------------------------------------------------
//  \fn    AT91F_CKGR_CfgPLLReg
//  \brief Cfg the PLL Register
// ----------------------------------------------------------------------------
static __inline void
AT91F_CKGR_CfgPLLReg( AT91PS_CKGR pCKGR,        // \arg pointer to CKGR controller
                      unsigned int mode )
{
    pCKGR->CKGR_PLLR = mode;
}

// ----------------------------------------------------------------------------
//  \fn    AT91F_CKGR_GetPLLReg
//  \brief Get the PLL Register
// ----------------------------------------------------------------------------
static __inline unsigned int
AT91F_CKGR_GetPLLReg( AT91PS_CKGR pCKGR )       // \arg pointer to CKGR controller
{
    return pCKGR->CKGR_PLLR;
}


/* *****************************************************************************
                SOFTWARE API FOR RSTC
   ***************************************************************************** */
//*----------------------------------------------------------------------------
//* \fn    AT91F_RSTSoftReset
//* \brief Start Software Reset
//*----------------------------------------------------------------------------
static __inline void
AT91F_RSTSoftReset( AT91PS_RSTC pRSTC, unsigned int reset )
{
    pRSTC->RSTC_RCR = ( 0xA5000000 | reset );
}

//*----------------------------------------------------------------------------
//* \fn    AT91F_RSTSetMode
//* \brief Set Reset Mode
//*----------------------------------------------------------------------------
static __inline void
AT91F_RSTSetMode( AT91PS_RSTC pRSTC, unsigned int mode )
{
    pRSTC->RSTC_RMR = ( 0xA5000000 | mode );
}

//*----------------------------------------------------------------------------
//* \fn    AT91F_RSTGetMode
//* \brief Get Reset Mode
//*----------------------------------------------------------------------------
static __inline unsigned int
AT91F_RSTGetMode( AT91PS_RSTC pRSTC )
{
    return ( pRSTC->RSTC_RMR );
}

//*----------------------------------------------------------------------------
//* \fn    AT91F_RSTGetStatus
//* \brief Get Reset Status
//*----------------------------------------------------------------------------
static __inline unsigned int
AT91F_RSTGetStatus( AT91PS_RSTC pRSTC )
{
    return ( pRSTC->RSTC_RSR );
}

//*----------------------------------------------------------------------------
//* \fn    AT91F_RSTIsSoftRstActive
//* \brief Return !=0 if software reset is still not completed
//*----------------------------------------------------------------------------
static __inline unsigned int
AT91F_RSTIsSoftRstActive( AT91PS_RSTC pRSTC )
{
    return ( ( pRSTC->RSTC_RSR ) & AT91C_RSTC_SRCMP );
}

/* *****************************************************************************
                SOFTWARE API FOR RTTC
   ***************************************************************************** */
//*--------------------------------------------------------------------------------------
//* \fn     AT91F_SetRTT_TimeBase()
//* \brief  Set the RTT prescaler according to the TimeBase in ms
//*--------------------------------------------------------------------------------------
static __inline unsigned int
AT91F_RTTSetTimeBase( AT91PS_RTTC pRTTC, unsigned int ms )
{
    if( ms > 2000 )
        return 1;               // AT91C_TIME_OUT_OF_RANGE
    pRTTC->RTTC_RTMR &= ~0xFFFF;
    pRTTC->RTTC_RTMR |= ( ( ( ms << 15 ) / 1000 ) & 0xFFFF );
    return 0;
}

//*--------------------------------------------------------------------------------------
//* \fn     AT91F_RTTSetPrescaler()
//* \brief  Set the new prescaler value
//*--------------------------------------------------------------------------------------
static __inline unsigned int
AT91F_RTTSetPrescaler( AT91PS_RTTC pRTTC, unsigned int rtpres )
{
    pRTTC->RTTC_RTMR &= ~0xFFFF;
    pRTTC->RTTC_RTMR |= ( rtpres & 0xFFFF );
    return ( pRTTC->RTTC_RTMR );
}

//*--------------------------------------------------------------------------------------
//* \fn     AT91F_RTTRestart()
//* \brief  Restart the RTT prescaler
//*--------------------------------------------------------------------------------------
static __inline void
AT91F_RTTRestart( AT91PS_RTTC pRTTC )
{
    pRTTC->RTTC_RTMR |= AT91C_RTTC_RTTRST;
}


//*--------------------------------------------------------------------------------------
//* \fn     AT91F_RTT_SetAlarmINT()
//* \brief  Enable RTT Alarm Interrupt
//*--------------------------------------------------------------------------------------
static __inline void
AT91F_RTTSetAlarmINT( AT91PS_RTTC pRTTC )
{
    pRTTC->RTTC_RTMR |= AT91C_RTTC_ALMIEN;
}

//*--------------------------------------------------------------------------------------
//* \fn     AT91F_RTT_ClearAlarmINT()
//* \brief  Disable RTT Alarm Interrupt
//*--------------------------------------------------------------------------------------
static __inline void
AT91F_RTTClearAlarmINT( AT91PS_RTTC pRTTC )
{
    pRTTC->RTTC_RTMR &= ~AT91C_RTTC_ALMIEN;
}

//*--------------------------------------------------------------------------------------
//* \fn     AT91F_RTT_SetRttIncINT()
//* \brief  Enable RTT INC Interrupt
//*--------------------------------------------------------------------------------------
static __inline void
AT91F_RTTSetRttIncINT( AT91PS_RTTC pRTTC )
{
    pRTTC->RTTC_RTMR |= AT91C_RTTC_RTTINCIEN;
}

//*--------------------------------------------------------------------------------------
//* \fn     AT91F_RTT_ClearRttIncINT()
//* \brief  Disable RTT INC Interrupt
//*--------------------------------------------------------------------------------------
static __inline void
AT91F_RTTClearRttIncINT( AT91PS_RTTC pRTTC )
{
    pRTTC->RTTC_RTMR &= ~AT91C_RTTC_RTTINCIEN;
}

//*--------------------------------------------------------------------------------------
//* \fn     AT91F_RTT_SetAlarmValue()
//* \brief  Set RTT Alarm Value
//*--------------------------------------------------------------------------------------
static __inline void
AT91F_RTTSetAlarmValue( AT91PS_RTTC pRTTC, unsigned int alarm )
{
    pRTTC->RTTC_RTAR = alarm;
}

//*--------------------------------------------------------------------------------------
//* \fn     AT91F_RTT_GetAlarmValue()
//* \brief  Get RTT Alarm Value
//*--------------------------------------------------------------------------------------
static __inline unsigned int
AT91F_RTTGetAlarmValue( AT91PS_RTTC pRTTC )
{
    return ( pRTTC->RTTC_RTAR );
}

//*--------------------------------------------------------------------------------------
//* \fn     AT91F_RTTGetStatus()
//* \brief  Read the RTT status
//*--------------------------------------------------------------------------------------
static __inline unsigned int
AT91F_RTTGetStatus( AT91PS_RTTC pRTTC )
{
    return ( pRTTC->RTTC_RTSR );
}

//*--------------------------------------------------------------------------------------
//* \fn     AT91F_RTT_ReadValue()
//* \brief  Read the RTT value
//*--------------------------------------------------------------------------------------
static __inline unsigned int
AT91F_RTTReadValue( AT91PS_RTTC pRTTC )
{
    register volatile unsigned int val1, val2;

    do
    {
        val1 = pRTTC->RTTC_RTVR;
        val2 = pRTTC->RTTC_RTVR;
    }
    while( val1 != val2 );
    return ( val1 );
}

/* *****************************************************************************
                SOFTWARE API FOR PITC
   ***************************************************************************** */
//*----------------------------------------------------------------------------
//* \fn    AT91F_PITInit
//* \brief System timer init : period in 祍econd, system clock freq in MHz
//*----------------------------------------------------------------------------
static __inline void
AT91F_PITInit( AT91PS_PITC pPITC, unsigned int period, unsigned int pit_frequency )
{
    pPITC->PITC_PIMR = period ? ( period * pit_frequency + 8 ) >> 4 : 0;        // +8 to avoid %10 and /10
    pPITC->PITC_PIMR |= AT91C_PITC_PITEN;
}

//*----------------------------------------------------------------------------
//* \fn    AT91F_PITSetPIV
//* \brief Set the PIT Periodic Interval Value 
//*----------------------------------------------------------------------------
static __inline void
AT91F_PITSetPIV( AT91PS_PITC pPITC, unsigned int piv )
{
    pPITC->PITC_PIMR = piv | ( pPITC->

⌨️ 快捷键说明

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