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

📄 spidrv8548.h

📁 MPC8548上用GPIO口模拟的SPI控制器.包括初始化,单字节读写,多字节读写等等.调试通过
💻 H
字号:
/*=============================================================

*	Copyright (c) 2008~2010, CPIT. All Rights Reserved.
*
*	MODULE:  ecpb8548  模拟spi 
*
*	FILENAME: g_spiDrv8548.h
*
*	DESCRIPTION: 用mpc8548 的gpio 模拟spi  的初始化,读写功能
*
*
*	HISTORY:
*
*	Date           CR No      Person        Description
*	----------  ------------  ------       -------------
*	2008-12-01                litao       created.
*
=============================================================*/

#ifndef _SPIDRV8548_H_
#define _SPIDRV8548_H_

#ifdef __cplusplus
extern "C" {
#endif

/*gpio reg define*/
#define M85XX_GPIOCR(base)			(CAST(VUINT32 *)((base) + 0xE0030))
#define M85XX_GPOUTDR(base)		(CAST(VUINT32 *)((base) + 0xE0040))
#define M85XX_GPINDR(base)			(CAST(VUINT32 *)((base) + 0xE0050))
#define M85XX_DEVDISR(base)            (CAST(VUINT32 *)((base) + 0xE0070))
/*
TSEC2_TXD_06/GPOUT_01     SPI_SCLK    
TSEC2_TXD_05/GPOUT_02     SPI_MOSI
TSEC2_TXD_03/GPOUT_04     SPI_SS1#  AD9516片选
TSEC2_TXD_01/GPOUT_06     SPI_SS0#  BCM5387片选

TSEC2_RXD_00/GPIN_07         SPI_MISO
*/
#define SPI_SCLK			(1<<30)
#define SPI_MOSI			(1<<29)
#define CS_BCM5387		(1<<25)
#define CS_AD9516		(1<<27)

#define SPI_MISO			(1<<24)

#define     ETSEC2_DISABLE    (1<<6)


#define TX2OUT	(1<<25) /*Enables TSEC2_TX[7:0] for use as general-purpose output if the eTSEC2

                                 interface is disabled and eTSEC1 is not configured for 16-bit FIFO mode.*/                           

#define RX2IN	(1<<24) /*Enables TSEC2_RX[7:0] for use as general-purpose input if the eTSEC2 

                                  interface is disabled and eTSEC1 is not configured for 16-bit FIFO mode.*/

#define PCIOUT	(1<<17) /*Enables PCI2_AD[15:8] for use as general-purpose output. Note that 

                                   the PCI1 interface must be configured for 32-bit mode AND the PCI2

                                   interface must be disabled.*/                                  

#define PCIIN	(1<<16) /*Enables PCI2_AD[7:0] for use as general-purpose input. Note that the

                                PCI1 interface must be configured for 32-bit mode AND the PCI2 interface must be disabled.*/                                   

#define GPOUT	(1<<9) /*Enables GPOUT[24:31] for use as general-purpose output.*/

typedef enum
{
    SPI_SEC_BCM5387 = 0,
    SPI_SEC_AD9516,
    SPI_SEC_NONE
}SpiType;

#define AD9516_SYSC_EN		(1<<31)         /*1为调整ad9516信号有效,0 为无效*/
#define AD9516_SYS_CLK		(1<<30)         /*1:选用系统时钟0:选用本地时钟*/
#define AD9516_CLK_LOCK		(1<<29)     /*0:时钟未锁定1:时钟锁定*/

typedef struct
{
	UINT16 RegAddr;
	UINT8 RegVal;
}RegValve;



#define MAX_BYTE_CNT 8
#define AD9516_READ (1<<16)
#define AD9516_WRITE (~((1<<16)))

/*
Byte Transfer Count:
W1 W0  Bytes to Transfer
0     0    1
0     1    2
1     0    3
1     1   Streaming mode
*/

#define BYTE_CNT_ONE  0x00
#define BYTE_CNT_TWO 0x01
#define BYTE_CNT_THR  0x02
#define BYTE_CNT_STR  0x03

#define AD9516_ADDR_LEN 0x232/*ad9516的地址范围*/
#define AD9516_REG_OP 1/*寄存器操作长度*/
#define AD9516_TRANS_MOD_UNIDI (1<<24)/*unidirectional mode*/
#define AD9516_DATA_OP_LSB       (1<<25) /*lsb*/
#define AD9516_SERI_PORT_CFG_REG 0x00 /*Serial Port Configuration*/

/*PLL register*/
#define AD9516_PFD_CHARG_REG 0x10 /*PFD and Charge Pump*/
#define AD9516_R_CNT_LSB_REG 0x11
#define AD9516_R_CNT_MSB_REG 0x12
#define AD9516_A_CNT_REG 0x13
#define AD9516_B_CNT_REG 0x14
#define AD9516_PLL_CTL1_REG 0x16
#define AD9516_PLL_CTL2_REG 0x17
#define AD9516_PLL_CTL3_REG 0x18
#define AD9516_PLL_CTL4_REG 0x19
#define AD9516_PLL_CTL5_REG 0x1a
#define AD9516_PLL_CTL6_REG 0x1b
#define AD9516_PLL_CTL7_REG 0x1c
#define AD9516_PLL_CTL8_REG 0x1d
#define AD9516_PLL_CTL9_REG 0x1e
#define AD9516_PLL_R_BACK_REG 0x1f

#define BCM5387_ADDR_LEN 0xff/*bcm5387 的地址范围*/
#define NORMAL_SPI_CMD 0x60 /*Normal SPI:bit7 ~ bit5 011*/
#define BCM5387_ID 0x00
#define BMC5387_SPI_FAST_MODE 0x10
#define BCM5387_SPI_W 0x01 /*bcm5387 write*/
#define BCM5387_CTRL_READ_PACKET 0x60
#define BCM5387_CTRL_WRITE_PACKET 0x61



/*internal function */

SYS_STATUS ad9516_read(UINT16 addr, UINT8 byte_cnt, UINT8 *pbuffer);
SYS_STATUS ad9516_write(UINT16 addr, UINT8 byte_cnt, UINT8 *pdata);
SYS_STATUS ad9516_init(void);
SYS_STATUS bcm5387_write( UINT8 page, UINT8 reg_addr, UINT8 byte_cnt, UINT8 *pbuffer);
SYS_STATUS bcm5387_read( UINT8 page, UINT8 reg_addr, UINT8 byte_cnt, UINT8 *pbuffer);
SYS_STATUS spi_read(SpiType aim_type, UINT16 data_addr, UINT16 read_len, UINT8 *recv_data_ptr);
SYS_STATUS spi_write(SpiType aim_type,  UINT16 data_addr, UINT16 write_len, UINT8 *send_data_ptr);

#ifdef __cplusplus
}
#endif

#endif /*_SPIDRV8548_H_*/

⌨️ 快捷键说明

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