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

📄 bspi.h

📁 arm(str710)usb功能的实现
💻 H
📖 第 1 页 / 共 2 页
字号:
/****************************************Copyright (c)**************************************************
**                                      
**                                          STR710 development team
**                                          
**
**                                 http://www.appchip.com
**
**--------------文件信息--------------------------------------------------------------------------------
** 文 件 名: uart.h
** 创 建 人: lhl
** 创建日期: 2006年5月10日
** 描    述: 该文件包含了所有UART功能函数原型与所需要的常量
**
**--------------历史版本--------------------------------------------------------------------------------
** 创 建 人: lhl
** 版    本: V1.0
** 日   期: 2006年5月10日
** 描   述: 原始版本
**
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/

#ifndef __BSPI_H
#define __BSPI_H

#include "cpu_cfg.h"

    #ifdef __cplusplus
    extern "C" {
    #endif

#if EN_ARM_BSPI > 0									/* 决定是否编译该文件 */

/****************************************** 宏定义,常量定义 *******************************************/

//说明: 通过带参数的宏来访问不同串口的同一个名称的寄存器
#define  BSPIx_RXR(bspi)		(*((volatile unsigned short *)(0xC000A000+(bspi)*0x1000 + BSPI_RXR)))
#define  BSPIx_TXR(bspi)    	(*((volatile unsigned short *)(0xC000A000+(bspi)*0x1000 + BSPI_TXR)))
#define  BSPIx_CSR1(bspi)    	(*((volatile unsigned short *)(0xC000A000+(bspi)*0x1000 + BSPI_CSR1)))
#define  BSPIx_CSR2(bspi)    	(*((volatile unsigned short *)(0xC000A000+(bspi)*0x1000 + BSPI_CSR2)))
#define  BSPIx_CLK(bspi)    	(*((volatile unsigned short *)(0xC000A000+(bspi)*0x1000 + BSPI_CLK)))
 

#define BSPI_PESET_MASK		0x01
#define BSPI_DFIFO_MASK 	0xFFFE
#define BSPI_CPHA_MASK  	0x200
#define BSPI_CPOL_MASK  	0x100
#define BSPI_BSPI0_BASE 	0xA000
#define BSPI_BSPI1_BASE 	0xB000

#define BSPI0_MISO_PIN		0
#define BSPI0_MOSI_PIN		1
#define BSPI0_SCLK_PIN		2
#define BSPI0_SSN_PIN		3

#define BSPI1_MISO_PIN		4
#define BSPI1_MOSI_PIN		5
#define BSPI1_SCLK_PIN		6
#define BSPI1_SSN_PIN		7

/*****************************************  枚举类型定义  ********************************************/

typedef enum { BSPI0 =0, BSPI1 } BSPI_TYPES_T;

typedef enum { MASTER =0, SLAVE } BSPI_MODES_T;

typedef enum{ BSPI_BERIT = 0x80, BSPI_RCIT = 0x10, BSPI_ALL = 0x90 } BSPI_ITS_T;

typedef enum{ BSPI_RC_FNE, BSPI_RC_FF, BSPI_RC_DIS } BSPI_RC_IR_SRCS_T;

typedef enum{ BSPI_TR_FE, BSPI_TR_UFL, BSPI_TR_FF, BSPI_TR_DIS } BSPI_TR_IT_SRCS_T;

typedef enum {  BSPI_BERR = 0x004,
  				BSPI_RFNE = 0x008,
  				BSPI_RFF  = 0x010,
  				BSPI_ROFL = 0x020,
  				BSPI_TFE  = 0x040,
  				BSPI_TUFL = 0x080,
  				BSPI_TFF  = 0x100,
  				BSPI_TFNE = 0x200
			 } BSPI_FLAGS_T;
			 

/************************************** 全局外部函数原型声明 ********************************************/
			 
void BSPI_Reset(BSPI_TYPES_T bspi);									      /* 复位指定的SPI接口 			*/
                                                                    
void BSPI_TransmitItCfg(BSPI_TYPES_T bspi, BSPI_TR_IT_SRCS_T tr_it_src);  /* 配置BSPI接口传送时中断类型 */
                                                                    
void BSPI_ReceiveItCfg(BSPI_TYPES_T bspi, BSPI_RC_IR_SRCS_T rec_it_src);  /* 配置BSPI接口接收时中断类型 */
                                                                    
void BSPI_TransmitFifoCfg(BSPI_TYPES_T bspi, UWORD8 depth);			  /* 配置BSPI接口发送缓冲区长度 */
                                                                    	 
void BSPI_ReceiveFifoCfg(BSPI_TYPES_T bspi, UWORD8 depth);			  /* 配置BSPI接口接收缓冲区长度 */
                                                                    	  /* 从指定的FIFO发送数据       */
void BSPI_BufferSend(BSPI_TYPES_T bspi, UWORD8 *ptr_buffer, UWORD8 word_number);
                                                                    	  /* 从指定的FIFO接收数据 		*/
void BSPI_BufferReceive(BSPI_TYPES_T bspi, UWORD8 *ptr_buffer, UWORD8 word_number);

void BSPI_Init(BSPI_TYPES_T bspi, BSPI_MODES_T mode);                     /* 初始化指定SPI接口 			*/

			 			 
/*********************************************************************************************************
;** 函数名称: BSPI_BSPI0Config
;** 功能描述: 选择P0.0~P0.3为SPI0还是IC1还是UART3或者GPIO 
;** 
;** 参    数: new_state: 控制状态(ENABLE, DISABLE)
;**          
;** 返 回 值: None
;**         
;** 作   者: lhl
;** 日   期: 2006年5月23日
;**-------------------------------------------------------------------------------------------------------
;** 修 改 人: 
;** 日   期: 
;**------------------------------------------------------------------------------------------------------
;********************************************************************************************************/
inline void BSPI_BSPI0Config(CONFIG_STATUS_T new_state)
{
	if(new_state == ENABLE) 
		PCU_BOOTCR |= 0x04; 
	else 
		PCU_BOOTCR &= ~0x04;
}

/*********************************************************************************************************
;** 函数名称: BSPI_Enable
;** 功能描述: 禁止或者允许指定的SPI设备 
;** 
;** 参    数: bspi:     指定的SPI类型(BSPI0, BSPI1)
;**           new_state:控制状态(ENABLE, DISABLE)
;**          
;** 返 回 值: None
;**         
;** 作   者: lhl
;** 日   期: 2006年5月23日
;**-------------------------------------------------------------------------------------------------------
;** 修 改 人: 
;** 日   期: 
;**------------------------------------------------------------------------------------------------------
;********************************************************************************************************/
inline void BSPI_Enable(BSPI_TYPES_T bspi, CONFIG_STATUS_T new_state)
{
	if(new_state == ENABLE) 
		BSPIx_CSR1(bspi) |= BSPI_PESET_MASK;
    else 
    	BSPIx_CSR1(bspi) &= ~BSPI_PESET_MASK;
}

/*********************************************************************************************************
;** 函数名称: BSPI_MasterEnable
;** 功能描述: 配置BSPI的主模式或者从模式 
;** 
;** 参    数: bspi:     指定的SPI类型(BSPI0, BSPI1)
;**           new_state:ENABLE--主模式, DISABLE--从模式
;**          
;** 返 回 值: None
;**         
;** 作   者: lhl
;** 日   期: 2006年5月23日
;**-------------------------------------------------------------------------------------------------------
;** 修 改 人: 
;** 日   期: 
;**------------------------------------------------------------------------------------------------------
;********************************************************************************************************/
inline void BSPI_MasterEnable(BSPI_TYPES_T bspi, CONFIG_STATUS_T new_state)
{
	if(new_state == ENABLE) 
		BSPIx_CSR1(bspi) |= 0x02; 
	else 
		BSPIx_CSR1(bspi) &= ~0x02;
}

/*********************************************************************************************************
;** 函数名称: BSPI_8bLEn
;** 功能描述: 配置BSPI接收FIFO和发送数据寄存器为8位还是16位
;** 
;** 参    数: bspi:     指定的SPI类型(BSPI0, BSPI1)
;**           new_state:ENABLE--8位长度, DISABLE--16位长度
;**          
;** 返 回 值: None
;**         
;** 作   者: lhl
;** 日   期: 2006年5月23日
;**-------------------------------------------------------------------------------------------------------
;** 修 改 人: 
;** 日   期: 
;**------------------------------------------------------------------------------------------------------
;********************************************************************************************************/
inline void BSPI_8bLEn(BSPI_TYPES_T bspi, CONFIG_STATUS_T new_state)
{
	if(new_state == DISABLE)
		BSPIx_CSR1(bspi) |= 0x0400; 
	else 
		BSPIx_CSR1(bspi) &= ~0x0C00;
}

/*********************************************************************************************************
;** 函数名称: BSPI_ClkFEdge
;** 功能描述: 设置允许BSPI捕捉到的第一个数据是在第一个SCK的边沿还是第二个SCK的边沿
;** 
;** 参    数: bspi:     指定的SPI类型(BSPI0, BSPI1)
;**           new_state:ENABLE--第一个SCK的边沿, DISABLE--第二个SCK的边沿
;**          
;** 返 回 值: None
;**         
;** 作   者: lhl
;** 日   期: 2006年5月23日
;**-------------------------------------------------------------------------------------------------------
;** 修 改 人: 
;** 日   期: 
;**------------------------------------------------------------------------------------------------------
;********************************************************************************************************/
inline void BSPI_ClkFEdge(BSPI_TYPES_T bspi, CONFIG_STATUS_T new_state)
{
	if(new_state == ENABLE) 
		BSPIx_CSR1(bspi) |= BSPI_CPHA_MASK;
  	else 
  		BSPIx_CSR1(bspi) &= ~BSPI_CPHA_MASK;
}
/*********************************************************************************************************
;** 函数名称: BSPI_ClkActiveHigh
;** 功能描述: 设置BSP时钟是高激活还是低激活
;** 
;** 参    数: bspi:     指定的SPI类型(BSPI0, BSPI1)
;**           new_state:ENABLE--高激活, DISABLE--第激活
;**          

⌨️ 快捷键说明

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