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

📄 sdhal.c

📁 SD卡的SPI驱动程序
💻 C
字号:
/****************************************Copyright (c)**************************************************
**                               Guangzhou ZLG-MCU Development Co.,LTD.
**                                      graduate school
**                                 http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name:			sdhal.c
** Last modified Date:	2005-1-6
** Last Version:		V1.0
** Descriptions:		Soft Packet of SD Card Driver: tool funcitons about sd card ---- crc check header file
**
**------------------------------------------------------------------------------------------------------
** Created by:			Ming Yuan Zheng
** Created date:		2005-1-6
** Version:				V1.0
** Descriptions:		The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:			Jing.Zhang
** Modified date:		2005-12-21
** Version:				
** Descriptions:		
**
**------------------------------------------------------------------------------------------------------
** Modified by: 
** Modified date:
** Version:	
** Descriptions: 
**
********************************************************************************************************/
#include "sdconfig.h"
#include "alt_types.h"
#include "priv/alt_busy_sleep.h"
#include "zlg_avalon_spi.h"
/*********************************************************************************************************
** Function name:    SD_ChkCard
**
** Descriptions:     Check whether the SD card is inserted entirely
**
** input parameters:   None
**            
** Returned value:     1: insert entirely	0: not insert entirely
**                     
**         
** Used global variables: None
** Calling modules:       
**
** Created by:        Ming Yuan Zheng
** Created Date:      2005-1-6
**-------------------------------------------------------------------------------------------------------
** Modified by:       Jing.Zhang
** Modified date:     2005-12-21
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
INT8U SD_ChkCard(void)
{
	if (SD_INSERT_STATUS() != 0)
		return 0;								/* not insert entirely */
	else
		return 1;								/* insert entirely */
}

/*********************************************************************************************************
** Function name:    SD_ChkCardWP
**
** Descriptions:     Check whether the SD card is in the Write-protection status
**
** input parameters:   None
**            
** Returned value:     1: insert write protect	0: not write protect
**                     
**         
** Used global variables: None
** Calling modules:       
**
** Created by:        Ming Yuan Zheng
** Created Date:      2005-1-6
**-------------------------------------------------------------------------------------------------------
** Modified by:       Jing.Zhang
** Modified date:     2005-12-21
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
INT8U SD_ChkCardWP(void)
{
	if (SD_WP_STATUS() != 0)
		return 1;								/* write protect */
	else
		return 0;								/* not write protect */
}

/*********************************************************************************************************
** Function name:    SD_HardWareInit
**
** Descriptions:     Initialize the hardware that related to SD card
**                   1st: Power On
**                   2nd: Delay at least 74 clocks
**                   SPI core has been initialized as CPOL = 1,CPHA = 0, 400Khz in the
**                   process of SPOC Builder
**
** input parameters:   None
**            
** Returned value:     None
**                     
**         
** Used global variables: None
** Calling modules:       
**
** Created by:        Ming Yuan Zheng
** Created Date:      2005-1-6
**-------------------------------------------------------------------------------------------------------
** Modified by:       Jing.Zhang
** Modified date:     2005-12-21
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void SD_HardWareInit(void)
{
	INT8U tmpBuf[25];
	/*   Power On   */
	SD_CTL_PIN_INIT();
    SD_POWER_OFF();
    alt_busy_sleep(100000);
    SD_POWER_ON();
    alt_busy_sleep(500000);

	/*   Delay at least 74 clocks  */
	  SPI_SS_ASSERT(); 
    zlg_avalon_spi_recv_byte(25, tmpBuf);
    SPI_SS_DEASSERT();
    alt_busy_sleep(100);
	  zlg_avalon_spi_recv_byte(2, tmpBuf);  
}

/*********************************************************************************************************
** Function name:    SPI_SendByte
**
** Descriptions:     Send a byte by SPI interface
**                   
** input parameters:   INT8U byte: the byte that will be send
**            
** Returned value:     None
**                     
**         
** Used global variables: None
** Calling modules:       
**
** Created by:        Ming Yuan Zheng
** Created Date:      2005-1-6
**-------------------------------------------------------------------------------------------------------
** Modified by:       Jing.Zhang
** Modified date:     2005-12-21
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void SPI_SendByte(INT8U byte)
{
	zlg_avalon_spi_send_byte(1,&byte);
}

/*********************************************************************************************************
** Function name:    SPI_RecByte
**
** Descriptions:     Receive a byte from SPI interface
**                   
** input parameters:   None
**            
** Returned value:     the received byte
**                     
**         
** Used global variables: None
** Calling modules:       
**
** Created by:        Ming Yuan Zheng
** Created Date:      2005-1-6
**-------------------------------------------------------------------------------------------------------
** Modified by:       Jing.Zhang
** Modified date:     2005-12-21
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
INT8U SPI_RecByte(void)
{
	INT8U tmp;

	zlg_avalon_spi_recv_byte(1, &tmp);
	return tmp;
}

/*********************************************************************************************************
** Function name:    SPI_CS_Assert
**
** Descriptions:     Select SPI slave 0
**                   
** input parameters:   None
**            
** Returned value:     None
**                     
**         
** Used global variables: None
** Calling modules:       
**
** Created by:        Ming Yuan Zheng
** Created Date:      2005-1-6
**-------------------------------------------------------------------------------------------------------
** Modified by:       Jing.Zhang
** Modified date:     2005-12-21
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
/*
ALT_INLINE void ALT_ALWAYS_INLINE SPI_CS_Assert(void)
{
	SPI_SS_ASSERT(0);  
}*/

/*********************************************************************************************************
** Function name:    SPI_CS_Deassert
**
** Descriptions:     Deselect SPI slave 0
**                   
** input parameters:   None
**            
** Returned value:     None
**                     
**         
** Used global variables: None
** Calling modules:       
**
** Created by:        Ming Yuan Zheng
** Created Date:      2005-1-6
**-------------------------------------------------------------------------------------------------------
** Modified by:       Jing.Zhang
** Modified date:     2005-12-21
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
/*
ALT_INLINE void ALT_ALWAYS_INLINE SPI_CS_Deassert(void)
{
	SPI_SS_DEASSERT(0);
}*/

⌨️ 快捷键说明

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