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

📄 lib_at91sam7x256.h

📁 一个开源的Modbus协议栈
💻 H
📖 第 1 页 / 共 5 页
字号:
//*----------------------------------------------------------------------------
//* \fn    AT91F_PDC_IsTxEmpty
//* \brief Test if the current transfer descriptor has been sent
//*----------------------------------------------------------------------------
static __inline int
AT91F_PDC_IsTxEmpty(            // \return return 1 if transfer is complete
                        AT91PS_PDC pPDC )       // \arg pointer to a PDC controller
{
    return !( pPDC->PDC_TCR );
}

//*----------------------------------------------------------------------------
//* \fn    AT91F_PDC_IsNextTxEmpty
//* \brief Test if the next transfer descriptor has been moved to the current td
//*----------------------------------------------------------------------------
static __inline int
AT91F_PDC_IsNextTxEmpty(        // \return return 1 if transfer is complete
                            AT91PS_PDC pPDC )   // \arg pointer to a PDC controller
{
    return !( pPDC->PDC_TNCR );
}

//*----------------------------------------------------------------------------
//* \fn    AT91F_PDC_IsRxEmpty
//* \brief Test if the current transfer descriptor has been filled
//*----------------------------------------------------------------------------
static __inline int
AT91F_PDC_IsRxEmpty(            // \return return 1 if transfer is complete
                        AT91PS_PDC pPDC )       // \arg pointer to a PDC controller
{
    return !( pPDC->PDC_RCR );
}

//*----------------------------------------------------------------------------
//* \fn    AT91F_PDC_IsNextRxEmpty
//* \brief Test if the next transfer descriptor has been moved to the current td
//*----------------------------------------------------------------------------
static __inline int
AT91F_PDC_IsNextRxEmpty(        // \return return 1 if transfer is complete
                            AT91PS_PDC pPDC )   // \arg pointer to a PDC controller
{
    return !( pPDC->PDC_RNCR );
}

//*----------------------------------------------------------------------------
//* \fn    AT91F_PDC_Open
//* \brief Open PDC: disable TX and RX reset transfer descriptors, re-enable RX and TX
//*----------------------------------------------------------------------------
static __inline void
AT91F_PDC_Open( AT91PS_PDC pPDC )       // \arg pointer to a PDC controller
{
    //* Disable the RX and TX PDC transfer requests
    AT91F_PDC_DisableRx( pPDC );
    AT91F_PDC_DisableTx( pPDC );

    //* Reset all Counter register Next buffer first
    AT91F_PDC_SetNextTx( pPDC, ( char * )0, 0 );
    AT91F_PDC_SetNextRx( pPDC, ( char * )0, 0 );
    AT91F_PDC_SetTx( pPDC, ( char * )0, 0 );
    AT91F_PDC_SetRx( pPDC, ( char * )0, 0 );

    //* Enable the RX and TX PDC transfer requests
    AT91F_PDC_EnableRx( pPDC );
    AT91F_PDC_EnableTx( pPDC );
}

//*----------------------------------------------------------------------------
//* \fn    AT91F_PDC_Close
//* \brief Close PDC: disable TX and RX reset transfer descriptors
//*----------------------------------------------------------------------------
static __inline void
AT91F_PDC_Close( AT91PS_PDC pPDC )      // \arg pointer to a PDC controller
{
    //* Disable the RX and TX PDC transfer requests
    AT91F_PDC_DisableRx( pPDC );
    AT91F_PDC_DisableTx( pPDC );

    //* Reset all Counter register Next buffer first
    AT91F_PDC_SetNextTx( pPDC, ( char * )0, 0 );
    AT91F_PDC_SetNextRx( pPDC, ( char * )0, 0 );
    AT91F_PDC_SetTx( pPDC, ( char * )0, 0 );
    AT91F_PDC_SetRx( pPDC, ( char * )0, 0 );

}

//*----------------------------------------------------------------------------
//* \fn    AT91F_PDC_SendFrame
//* \brief Close PDC: disable TX and RX reset transfer descriptors
//*----------------------------------------------------------------------------
static __inline unsigned int
AT91F_PDC_SendFrame( AT91PS_PDC pPDC,
                     char *pBuffer, unsigned int szBuffer, char *pNextBuffer, unsigned int szNextBuffer )
{
    if( AT91F_PDC_IsTxEmpty( pPDC ) )
    {
        //* Buffer and next buffer can be initialized
        AT91F_PDC_SetTx( pPDC, pBuffer, szBuffer );
        AT91F_PDC_SetNextTx( pPDC, pNextBuffer, szNextBuffer );
        return 2;
    }
    else if( AT91F_PDC_IsNextTxEmpty( pPDC ) )
    {
        //* Only one buffer can be initialized
        AT91F_PDC_SetNextTx( pPDC, pBuffer, szBuffer );
        return 1;
    }
    else
    {
        //* All buffer are in use...
        return 0;
    }
}

//*----------------------------------------------------------------------------
//* \fn    AT91F_PDC_ReceiveFrame
//* \brief Close PDC: disable TX and RX reset transfer descriptors
//*----------------------------------------------------------------------------
static __inline unsigned int
AT91F_PDC_ReceiveFrame( AT91PS_PDC pPDC,
                        char *pBuffer, unsigned int szBuffer, char *pNextBuffer, unsigned int szNextBuffer )
{
    if( AT91F_PDC_IsRxEmpty( pPDC ) )
    {
        //* Buffer and next buffer can be initialized
        AT91F_PDC_SetRx( pPDC, pBuffer, szBuffer );
        AT91F_PDC_SetNextRx( pPDC, pNextBuffer, szNextBuffer );
        return 2;
    }
    else if( AT91F_PDC_IsNextRxEmpty( pPDC ) )
    {
        //* Only one buffer can be initialized
        AT91F_PDC_SetNextRx( pPDC, pBuffer, szBuffer );
        return 1;
    }
    else
    {
        //* All buffer are in use...
        return 0;
    }
}

/* *****************************************************************************
                SOFTWARE API FOR DBGU
   ***************************************************************************** */
//*----------------------------------------------------------------------------
//* \fn    AT91F_DBGU_InterruptEnable
//* \brief Enable DBGU Interrupt
//*----------------------------------------------------------------------------
static __inline void
AT91F_DBGU_InterruptEnable( AT91PS_DBGU pDbgu,  // \arg  pointer to a DBGU controller
                            unsigned int flag ) // \arg  dbgu interrupt to be enabled
{
    pDbgu->DBGU_IER = flag;
}

//*----------------------------------------------------------------------------
//* \fn    AT91F_DBGU_InterruptDisable
//* \brief Disable DBGU Interrupt
//*----------------------------------------------------------------------------
static __inline void
AT91F_DBGU_InterruptDisable( AT91PS_DBGU pDbgu, // \arg  pointer to a DBGU controller
                             unsigned int flag )        // \arg  dbgu interrupt to be disabled
{
    pDbgu->DBGU_IDR = flag;
}

//*----------------------------------------------------------------------------
//* \fn    AT91F_DBGU_GetInterruptMaskStatus
//* \brief Return DBGU Interrupt Mask Status
//*----------------------------------------------------------------------------
static __inline unsigned int
AT91F_DBGU_GetInterruptMaskStatus(      // \return DBGU Interrupt Mask Status
                                      AT91PS_DBGU pDbgu )       // \arg  pointer to a DBGU controller
{
    return pDbgu->DBGU_IMR;
}

//*----------------------------------------------------------------------------
//* \fn    AT91F_DBGU_IsInterruptMasked
//* \brief Test if DBGU Interrupt is Masked 
//*----------------------------------------------------------------------------
static __inline int
AT91F_DBGU_IsInterruptMasked( AT91PS_DBGU pDbgu,        // \arg  pointer to a DBGU controller
                              unsigned int flag )       // \arg  flag to be tested
{
    return ( AT91F_DBGU_GetInterruptMaskStatus( pDbgu ) & flag );
}

/* *****************************************************************************
                SOFTWARE API FOR PIO
   ***************************************************************************** */
//*----------------------------------------------------------------------------
//* \fn    AT91F_PIO_CfgPeriph
//* \brief Enable pins to be drived by peripheral
//*----------------------------------------------------------------------------
static __inline void
AT91F_PIO_CfgPeriph( AT91PS_PIO pPio,   // \arg pointer to a PIO controller
                     unsigned int periphAEnable,        // \arg PERIPH A to enable
                     unsigned int periphBEnable )       // \arg PERIPH B to enable
{
    pPio->PIO_ASR = periphAEnable;
    pPio->PIO_BSR = periphBEnable;
    pPio->PIO_PDR = ( periphAEnable | periphBEnable );  // Set in Periph mode
}

//*----------------------------------------------------------------------------
//* \fn    AT91F_PIO_CfgOutput
//* \brief Enable PIO in output mode
//*----------------------------------------------------------------------------
static __inline void
AT91F_PIO_CfgOutput( AT91PS_PIO pPio,   // \arg pointer to a PIO controller
                     unsigned int pioEnable )   // \arg PIO to be enabled
{
    pPio->PIO_PER = pioEnable;  // Set in PIO mode
    pPio->PIO_OER = pioEnable;  // Configure in Output
}

//*----------------------------------------------------------------------------
//* \fn    AT91F_PIO_CfgInput
//* \brief Enable PIO in input mode
//*----------------------------------------------------------------------------
static __inline void
AT91F_PIO_CfgInput( AT91PS_PIO pPio,    // \arg pointer to a PIO controller
                    unsigned int inputEnable )  // \arg PIO to be enabled
{
    // Disable output
    pPio->PIO_ODR = inputEnable;
    pPio->PIO_PER = inputEnable;
}

//*----------------------------------------------------------------------------
//* \fn    AT91F_PIO_CfgOpendrain
//* \brief Configure PIO in open drain
//*----------------------------------------------------------------------------
static __inline void
AT91F_PIO_CfgOpendrain( AT91PS_PIO pPio,        // \arg pointer to a PIO controller
                        unsigned int multiDrvEnable )   // \arg pio to be configured in open drain
{
    // Configure the multi-drive option
    pPio->PIO_MDDR = ~multiDrvEnable;
    pPio->PIO_MDER = multiDrvEnable;
}

//*----------------------------------------------------------------------------
//* \fn    AT91F_PIO_CfgPullup
//* \brief Enable pullup on PIO
//*----------------------------------------------------------------------------
static __inline void
AT91F_PIO_CfgPullup( AT91PS_PIO pPio,   // \arg pointer to a PIO controller
                     unsigned int pullupEnable )        // \arg enable pullup on PIO
{
    // Connect or not Pullup
    pPio->PIO_PPUDR = ~pullupEnable;
    pPio->PIO_PPUER = pullupEnable;
}

//*----------------------------------------------------------------------------
//* \fn    AT91F_PIO_CfgDirectDrive
//* \brief Enable direct drive on PIO
//*----------------------------------------------------------------------------
static __inline void
AT91F_PIO_CfgDirectDrive( AT91PS_PIO pPio,      // \arg pointer to a PIO controller
                          unsigned int directDrive )    // \arg PIO to be configured with direct drive
{
    // Configure the Direct Drive
    pPio->PIO_OWDR = ~directDrive;
    pPio->PIO_OWER = directDrive;
}

//*----------------------------------------------------------------------------
//* \fn    AT91F_PIO_CfgInputFilter
//* \brief Enable input filter on input PIO
//*----------------------------------------------------------------------------
static __inline void
AT91F_PIO_CfgInputFilter( AT91PS_PIO pPio,      // \arg pointer to a PIO controller
                          unsigned int inputFilter )    // \arg PIO to be configured with input filter
{
    // Configure the Direct Drive
    pPio->PIO_IFDR = ~inputFilter;
    pPio->PIO_IFER = inputFilter;
}

//*----------------------------------------------------------------------------
//* \fn    AT91F_PIO_GetInput
//* \brief Return PIO input value
//*----------------------------------------------------------------------------
static __inline unsigned int
AT91F_PIO_GetInput(             // \return PIO input
                       AT91PS_PIO pPio )        // \arg  pointer to a PIO controller
{
    return pPio->PIO_PDSR;
}

//*----------------------------------------------------------------------------
//* \fn    AT91F_PIO_IsInputSet
//* \brief Test if PIO is input flag is active
//*----------------------------------------------------------------------------
static __inline int
AT91F_PIO_IsInputSet( AT91PS_PIO pPio,  // \arg  pointer to a PIO controller
                      unsigned int flag )       // \arg  flag to be tested
{
    return ( AT91F_PIO_GetInput( pPio ) & flag );
}


//*----------------------------------------------------------------------------

⌨️ 快捷键说明

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