📄 lib_at91m55800a.h
字号:
//* \brief Disable a PIO pin IT
//*----------------------------------------------------------------------------
__inline void AT91F_PIO_DisableIt (
AT91PS_PIO pPio, // \arg pointer to a PIO controller
unsigned int pin) // \arg IT to be disabled
{
//* Write to the IDR register
pPio->PIO_IDR = pin;
}
//*----------------------------------------------------------------------------
//* \fn AT91F_PIO_PioPinItStatus
//* \brief Return the PIO pin IT Enabled
//*----------------------------------------------------------------------------
__inline unsigned int AT91F_PIO_PioPinItStatus (
AT91PS_PIO pPio) // \arg pointer to a PIO controller
{
//* Read to the PIO_IMR
return (pPio->PIO_IMR) ;
}
//*----------------------------------------------------------------------------
//* \fn AT91F_PIO_IsPioPinItPending
//* \brief Test if one or more PIO pin IT are pending
//*----------------------------------------------------------------------------
__inline unsigned int AT91F_PIO_IsPioPinItPending (
AT91PS_PIO pPio) // \arg pointer to a PIO controller
{
return (pPio->PIO_ISR);
}
/* *****************************************************************************
SOFTWARE API FOR SPI
***************************************************************************** */
//*----------------------------------------------------------------------------
//* \fn AT91F_SPI_Open
//* \brief Open a SPI Port
//*----------------------------------------------------------------------------
__inline unsigned int AT91F_SPI_Open (
const unsigned int null) // \arg
{
/* NOT DEFINED AT THIS MOMENT */
return ( 0 );
}
//*----------------------------------------------------------------------------
//* \fn AT91F_SPI_EnableIt
//* \brief Enable SPI IT
//*----------------------------------------------------------------------------
__inline void AT91F_SPI_EnableIt (
AT91PS_SPI pSPI, // \arg pointer to a SPI controller
unsigned int flag) // \arg IT to be enabled
{
//* Write to the IER register
pSPI->SPI_IER = flag;
}
//*----------------------------------------------------------------------------
//* \fn AT91F_SPI_DisableIt
//* \brief Disable SPI IT
//*----------------------------------------------------------------------------
__inline void AT91F_SPI_DisableIt (
AT91PS_SPI pSPI, // \arg pointer to a SPI controller
unsigned int flag) // \arg IT to be disabled
{
//* Write to the IER register
pSPI->SPI_IDR = flag;
}
//*----------------------------------------------------------------------------
//* \fn AT91F_SPI_ReceiveFrame
//* \brief Return 1 if PDC has been initialized with Buffer, 0 if PDC is busy
//*----------------------------------------------------------------------------
__inline unsigned int AT91F_SPI_ReceiveFrame (
AT91PS_SPI pSPI,
char *pBuffer,
unsigned int szBuffer)
{
return AT91F_PDC_ReceiveFrame(
(AT91PS_PDC) &(pSPI->SPI_RPR),
pBuffer,
szBuffer);
}
//*----------------------------------------------------------------------------
//* \fn AT91F_SPI_SendFrame
//* \brief Return 1 if PDC has been initialized with Buffer, 0 if PDC is busy
//*----------------------------------------------------------------------------
__inline unsigned int AT91F_SPI_SendFrame(
AT91PS_SPI pSPI,
char *pBuffer,
unsigned int szBuffer )
{
return AT91F_PDC_SendFrame(
(AT91PS_PDC) &(pSPI->SPI_RPR),
pBuffer,
szBuffer);
}
//*----------------------------------------------------------------------------
//* \fn AT91F_SPI_Baudrate
//* \brief Caluculate baud_value according to the main clock and the baud rate
//*----------------------------------------------------------------------------
__inline unsigned int AT91F_SPI_Baudrate (
const unsigned int main_clock, // \arg peripheral clock
const unsigned int baud_rate) // \arg SPI baudrate
{
unsigned int baud_value;
if (baud_rate == 0)
baud_value = 0;
else
baud_value = ((main_clock * 10)/(baud_rate * 2));
if ((baud_value % 10) >= 5)
baud_value = (baud_value / 10) + 1;
else
baud_value /= 10;
return baud_value;
}
//*----------------------------------------------------------------------------
//* \fn AT91F_SPI_SetBaudrate
//* \brief Set the baudrate according to the CPU clock
//*----------------------------------------------------------------------------
__inline void AT91F_SPI_SetBaudrate (
AT91PS_SPI pSPI, // \arg pointer to a SPI controller
unsigned int CS_number, // Number of the chip select [0..3]
unsigned int mainClock, // \arg peripheral clock
unsigned int speed) // \arg SPI baudrate
{
//* Define the baud rate divisor register
unsigned int register_value;
register_value = (pSPI->SPI_CSR[CS_number] & ~AT91C_SPI_SCBR); //clear the field of the baud register
register_value |= (AT91F_SPI_Baudrate(mainClock, speed) << 8);
pSPI->SPI_CSR[CS_number] = register_value;
}
//*----------------------------------------------------------------------------
//* \fn AT91F_SPI_CfgCS
//* \brief Set the parameters of a Chip Select
//*----------------------------------------------------------------------------
__inline void AT91F_SPI_CfgCS (
AT91PS_SPI pSPI, // \arg pointer to a SPI controller
unsigned int CS_number, // \arg Number of the chip select [0..3]
unsigned int mainClock, // \arg peripheral clock
unsigned int baudRate, // \arg SPI baudrate
unsigned int char_length, // \arg SPI character length
unsigned int cpol, // \arg SPI CPOL
unsigned int ncpha) // \arg SPI NCPHA
{
//* Define the Communication baudrate
AT91F_SPI_SetBaudrate (pSPI, CS_number, mainClock, baudRate);
pSPI->SPI_CSR[CS_number] = (pSPI->SPI_CSR[CS_number] & 0xFFFFFF0C) | (char_length | cpol | ncpha);
}
//*----------------------------------------------------------------------------
//* \fn AT91F_SPI_Slave_Configure
//* \brief Configure SPI in Slave Mode
//*----------------------------------------------------------------------------
__inline void AT91F_SPI_Slave_Configure (
AT91PS_SPI pSPI, // \arg pointer to a SPI controller
unsigned int com_parameter ) // \arg chip_select_register value
{
//* Disable interrupts
pSPI->SPI_IDR = (unsigned int) -1;
//* Disable the SPI
pSPI->SPI_CR = AT91C_SPI_SPIDIS;
//* Reset the SPI
pSPI->SPI_CR = AT91C_SPI_SWRST;
//* Define the Communication protocole
pSPI->SPI_CSR[0] = com_parameter;
//* Clear Transmit and Receive Counters
AT91F_PDC_Open((AT91PS_PDC) &(pSPI->SPI_RPR));
//* Define the SPI in slave mode
pSPI->SPI_MR &= ~(AT91C_SPI_MSTR);
}
//*----------------------------------------------------------------------------
//* \fn AT91F_SPI_SimpleMaster_Configure
//* \brief Configure SPI in Master Mode with one chip select
//*----------------------------------------------------------------------------
__inline void AT91F_SPI_SimpleMaster_Configure (
AT91PS_SPI pSPI, // \arg pointer to a SPI controller
unsigned int mainClock, // \arg peripheral clock
unsigned int baudRate , // \arg baudrate to be programmed
unsigned int com_parameter ) // \arg chip_select_register value
{
//* Disable interrupts
pSPI->SPI_IDR = (unsigned int) -1;
//* Disable the SPI
pSPI->SPI_CR = AT91C_SPI_SPIDIS;
//* Reset the SPI
pSPI->SPI_CR = AT91C_SPI_SWRST;
//* Define the Communication protocole : character length, cpol,cpha
pSPI->SPI_CSR[0] = com_parameter;
//* Define the Communication baudrate
AT91F_SPI_SetBaudrate (pSPI, 0, mainClock, baudRate);
//* Clear Transmit and Receive Counters
AT91F_PDC_Open((AT91PS_PDC) &(pSPI->SPI_RPR));
//* Define the SPI in master mode
pSPI->SPI_MR |= AT91C_SPI_MSTR;
}
//*----------------------------------------------------------------------------
//* \fn AT91F_SPI_MultiMaster_Configure
//* \brief Configure SPI in Master Mode with many chip selects available
//*----------------------------------------------------------------------------
__inline void AT91F_SPI_MultiMaster_Configure (
AT91PS_SPI pSPI, // \arg pointer to a SPI controller
unsigned int mainClock, // \arg peripheral clock
unsigned int baudRate) // \arg baudrate to be programmed
{
//* Disable interrupts
pSPI->SPI_IDR = (unsigned int) -1;
//* Disable the SPI
pSPI->SPI_CR = AT91C_SPI_SPIDIS;
//* Reset the SPI
pSPI->SPI_CR = AT91C_SPI_SWRST;
//* Clear Transmit and Receive Counters
AT91F_PDC_Open((AT91PS_PDC) &(pSPI->SPI_RPR));
//* Define the SPI in variable master mode
pSPI->SPI_MR |= (AT91C_SPI_MSTR | AT91C_SPI_PS_VARIABLE);
}
//*----------------------------------------------------------------------------
//* \fn AT91F_SPI_EnableTransfert
//* \brief Enable the SPI transfert
//*----------------------------------------------------------------------------
__inline void AT91F_SPI_EnableTransfert (
AT91PS_SPI pSPI) // \arg pointer to a SPI controller
{
//* Enable the transfert
pSPI->SPI_CR = AT91C_SPI_SPIEN;
}
//*----------------------------------------------------------------------------
//* \fn AT91F_SPI_DisableTransfert
//* \brief Disable the SPI transfert
//*----------------------------------------------------------------------------
__inline void AT91F_SPI_DisableTransfert (
AT91PS_SPI pSPI) // \arg pointer to a SPI controller
{
//* Enable the transfert
pSPI->SPI_CR = AT91C_SPI_SPIDIS;
}
//*----------------------------------------------------------------------------
//* \fn AT91F_SPI_Close
//* \brief Close SPI: disable IT disable transfert, close PDC
//*----------------------------------------------------------------------------
__inline void AT91F_SPI_Close (
AT91PS_SPI pSPI) // \arg pointer to a SPI controller
{
//* Reset all the Chip Select register
pSPI->SPI_CSR[0] = 0 ;
pSPI->SPI_CSR[1] = 0 ;
pSPI->SPI_CSR[2] = 0 ;
pSPI->SPI_CSR[3] = 0 ;
//* Reset the SPI mode
pSPI->SPI_MR = 0 ;
//* Disable all interrupts
pSPI->SPI_IDR = 0xFFFFFFFF ;
//* Abort the Peripheral Data Transfers
AT91F_PDC_Close((AT91PS_PDC) &(pSPI->SPI_RPR));
//* Disable receiver and transmitter and stop any activity immediately
pSPI->SPI_CR = AT91C_SPI_SPIDIS;
}
//*----------------------------------------------------------------------------
//* \fn AT91F_SPI_PutChar
//* \brief Send a character,does not check if ready to send
//*----------------------------------------------------------------------------
__inline void AT91F_SPI_PutChar (
AT91PS_SPI pSPI,
unsigned int character,
unsigned int cs_number )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -