📄 zlg_avalon_spi.h
字号:
/****************************************Copyright (c)**************************************************
** Guangzou ZLG-MCU Development Co.,LTD.
** Research centre
** http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name: zlg_avalon_spi.h
** Latest modified Date: 2005-12-19
** Latest Version: 1.0
** Descriptions: SPI operations declared here
**
**------------------------------------------------------------------------------------------------------
** Created by: Jing.Zhang
** Created date: 2005-12-19
** Version: 1.0
** Descriptions: The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
********************************************************************************************************/
#ifndef __ZLG_AVALON_SPI_H__
#define __ZLG_AVALON_SPI_H__
#include <stddef.h>
#include "system.h"
#include "alt_types.h"
#include "altera_avalon_spi_regs.h"
#include "altera_avalon_pio_regs.h"
#ifdef __SPI_GLOBAL__
#define __SPI_EXT__
#else
#define __SPI_EXT__ extern
#endif
/*
* User should modify SPI_BASE as the real base address of SPI core
*/
#ifndef SD_SPI_BASE //modified by zsw 2006.3.20
#define SD_SPI_BASE 0xffffffff //define your base address of SPI core here
#endif
#ifndef SD_CS_BASE //PIO for force the slave select pin
#define SD_CS_BASE 0xffffffff //user's modification here
#endif
#if SD_SPI_BASE == 0xffffffff
#error "No SPI core for sd card..."
#endif
#if SD_CS_BASE == 0xffffffff
#error "No SD CS pio..."
#endif
/*
* Macro definition of Error information
*/
#define ROE (-1)
#define TOE (-2)
#define ERR (-3)
/*
* SPI slave select signal operated Macro, No more modification below...
*/
// Assert SS signal
#define SPI_SS_ASSERT() do{ \
IOWR_ALTERA_AVALON_PIO_DATA(SD_CS_BASE,0);\
IOWR_ALTERA_AVALON_SPI_SLAVE_SEL(SD_SPI_BASE, 1);\
IOWR_ALTERA_AVALON_SPI_CONTROL(SD_SPI_BASE, ALTERA_AVALON_SPI_CONTROL_SSO_MSK);\
}while(0)
//De-assert SS signal
#define SPI_SS_DEASSERT() do{ \
IOWR_ALTERA_AVALON_PIO_DATA(SD_CS_BASE,1);\
IOWR_ALTERA_AVALON_SPI_SLAVE_SEL(SD_SPI_BASE, 1);\
IOWR_ALTERA_AVALON_SPI_CONTROL(SD_SPI_BASE, 0);\
}while(0)
/* User's application functions for SPI operation
* Use this function to perform one SPI access on your target. 'slave' indicates which
* bit in the slave select register should be set. Negative return value indicates some
* errors occur.
*/
__SPI_EXT__ int zlg_avalon_spi_send_byte(alt_u32 write_length, const alt_u8* write_data);
__SPI_EXT__ int zlg_avalon_spi_recv_byte(alt_u32 read_length, alt_u8* read_data);
#endif /* __ZLG_AVALON_SPI_H__ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -