📄 71x_bspi.c
字号:
/******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
* File Name : 71x_bspi.c
* Author : MCD Application Team
* Version : V4.0
* Date : 10/09/2007
* Description : This file provides all the BSPI firmware functions.
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "71x_bspi.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name : BSPI_BSPI0Conf
* Description : Configure BSPI0 to be available on GPIO0.0 to GPIO0.3 pins.
* Input : - NewState: specifies the status of the BSPI0.
* it can be ENABLE or DISABLE.
* Output : None.
* Return : None.
*******************************************************************************/
void BSPI_BSPI0Conf(FunctionalState NewState)
{
if (NewState == ENABLE)
{
PCU->BOOTCR |= 0x04;
}
else
{
PCU->BOOTCR &= ~0x04;
}
}
/*******************************************************************************
* Function Name : BSPI_Init
* Description : Initializes the BSPI peripheral control and registers to
* their default reset values.
* Input : - BSPIx: selects the BSPI peripheral to be initialized where
* x can be 0 or 1.
* Output : None.
* Return : None.
*******************************************************************************/
void BSPI_Init(BSPI_TypeDef *BSPIx)
{
BSPIx->CSR1 = 0x00;
BSPIx->CSR2 = 0x41;
BSPIx->CLK = 0x06;
}
/*******************************************************************************
* Function Name : BSPI_Enable
* Description : Enables/disables the specified BSPI peripheral.
* Input : - BSPIx: selects the BSPI peripheral to be enabled or
* disabled where x can be 0 or 1.
* - NewState: specifies the status of the BSPI
* it can be ENABLE or DISABLE.
* Output : None.
* Return : None.
*******************************************************************************/
void BSPI_Enable(BSPI_TypeDef *BSPIx, FunctionalState NewState)
{
if (NewState == ENABLE)
{
BSPIx->CSR1 |= BSPI_BSPE_Mask;
}
else
{
BSPIx->CSR1 &= ~BSPI_BSPE_Mask;
}
}
/*******************************************************************************
* Function Name : BSPI_MasterEnable
* Description : Configures the BSPI as a Master or a Slave.
* Input : - BSPIx: selects the BSPI peripheral to be configured as
* master or slave where x can be 0 or 1.
* - NewState: specifies whether configuring BSPI as master or
* slave.
* ENABLE the specified BSPI will be configured as a master.
* DISABLE the specified BSPI will be configured as a slave.
* Output : None.
* Return : None.
*******************************************************************************/
void BSPI_MasterEnable(BSPI_TypeDef *BSPIx, FunctionalState NewState)
{
if (NewState == ENABLE)
{
BSPIx->CSR1 |= BSPI_MSTR_Mask;
}
else
{
BSPIx->CSR1 &= ~BSPI_MSTR_Mask;
}
}
/*******************************************************************************
* Function Name : BSPI_TrItSrc
* Description : Configures the transmit interrupt source.
* Input : - BSPIx: selects the BSPI peripheral to be configured where
* x can be 0 or 1.
* - TrItSrc: specifies the transmit interrupt source.
* Output : None.
* Return : None.
*******************************************************************************/
void BSPI_TrItSrc(BSPI_TypeDef *BSPIx, BSPI_IT_TR TrItSrc)
{
/* Clear all TIE bits */
BSPIx->CSR2 &= ~0xC000;
switch (TrItSrc)
{
/* Transmit FIFO Empty interrupt selected */
case BSPI_TR_FE:
BSPIx->CSR2 |= 0x4000;
break;
/* Transmit FIFO Underflow interrupt selected */
case BSPI_TR_UFL:
BSPIx->CSR2 |= 0x8000;
break;
/* Transmit FIFO Full interrupt selected */
case BSPI_TR_FF:
BSPIx->CSR2 |= 0xC000;
break;
default: break;
}
}
/*******************************************************************************
* Function Name : BSPI_RcItSrc
* Description : Configures the receive interrupt source.
* Input : - BSPIx: selects the BSPI peripheral to be configured where
* x can be 0 or 1.
* - RcItSrc: specifies the source for the receive interrupt.
* Output : None.
* Return : None.
*******************************************************************************/
void BSPI_RcItSrc(BSPI_TypeDef *BSPIx, BSPI_IT_RC RcItSrc)
{
/* Clear all RIE bits */
BSPIx->CSR1 &= ~0x000C;
switch (RcItSrc)
{
/* Receive FIFO Not Empty interrupt selected */
case BSPI_RC_FNE:
BSPIx->CSR1 |= 0x0004;
break;
/* Receive FIFO Full interrupt selected */
case BSPI_RC_FF:
BSPIx->CSR1 |= 0x000C;
break;
default: break;
}
}
/*******************************************************************************
* Function Name : BSPI_TrFifoDepth
* Description : Configures the depth of the BSPI transmission FIFO.
* Input : - BSPIx: selects the BSPI peripheral to be configured
* where x can be 0 or 1.
* - TDepth: specifies the depth of the transmit FIFO.
* Output : None.
* Return : None.
*******************************************************************************/
void BSPI_TrFifoDepth(BSPI_TypeDef *BSPIx, u8 TDepth)
{
if ((TDepth > 0) && (TDepth < 11))
{
TDepth--;
/* Clear all Depth field bits */
BSPIx->CSR2 &= ~0x3C00;
/* Update the Depth field with new value */
BSPIx->CSR2 |= TDepth * 0x400;
}
else
{
BSPIx->CSR2 &= ~0x3C00;
}
}
/*******************************************************************************
* Function Name : BSPI_RcFifoDepth
* Description : Configures the depth of the BSPI reception FIFO.
* Input : - BSPIx: selects BSPI peripheral to be configured
* where x can be 0 or 1.
* - RDepth: specifies the depth of the receive FIFO.
* Output : None.
* Return : None.
*******************************************************************************/
void BSPI_RcFifoDepth(BSPI_TypeDef *BSPIx, u8 RDepth)
{
if ((RDepth > 0) && (RDepth < 11))
{
RDepth--;
/* Clear all Depth field bits */
BSPIx->CSR1 &= ~0xF000;
/* Update the Depth field with new value */
BSPIx->CSR1 |= RDepth * 0x1000;
}
else
{
BSPIx->CSR1 &= ~0xF000;
}
}
/*******************************************************************************
* Function Name : BSPI_8bLEn
* Description : Sets the word length of the receive FIFO and transmit data
* registers to either 8 or 16 bits.
* Input : - BSPIx: selects BSPI peripheral to be configured
* where x can be 0 or 1.
* - NewState: specifies if the word length is 8 or 16 bits.
* ENABLE: enable setting the word length to 8 bits.
* DISABLE: disable setting the word length to 8 bits: the
* wordlength will be set to 16 bits.
* Output : None.
* Return : None.
*******************************************************************************/
void BSPI_8bLEn(BSPI_TypeDef *BSPIx, FunctionalState NewState)
{
/* Wordlength = 16 bits */
if (NewState == DISABLE)
{
BSPIx->CSR1 |= 0x0400;
}
/* Wordlength = 8 bits */
else
{
BSPIx->CSR1 &= ~0x0C00;
}
}
/*******************************************************************************
* Function Name : BSPI_ClkFEdge
* Description : Enables capturing the first data sample on the first edge of
* SCK or on the second edge.
* Input : - BSPIx: selects BSPI peripheral to be configured
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -