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

📄 sd_user_api.c

📁 STM32的SD卡驱动及液晶驱动源代码资料
💻 C
字号:
/*****************************************************\
*河南工业大学Freescale MCU&DSP联合实验室
*文 件 名:SD_User_API.c
*C  P  U :STM32VBT6
*调试环境:IAR4.22 
*作    者:曾 滔
*描    述: SD卡驱动
*日    期:2008年9月12日
\*****************************************************/

/* Includes ------------------------------------------------------------------*/
#include "SD_User_API.h"
#include "sddriver.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
u32 Mass_Memory_Size;
u32 Mass_Block_Size;
u32 Mass_Block_Count;
/* Private function prototypes -----------------------------------------------*/

/* Private functions ---------------------------------------------------------*/
 
/*******************************************************************************
* Function Name  : MSD_Init
* Description    : Initializes the MSD/SD communication.
* Input          : None
* Output         : None
* Return         : The MSD Response: - MSD_RESPONSE_FAILURE: Sequence failed
*                                    - MSD_RESPONSE_NO_ERROR: Sequence succeed 
*******************************************************************************/
u8 MSD_Init(void)
{
  u8 ret = MSD_RESPONSE_FAILURE;

  /* MSD initialized and set to SPI mode properly */
  ret = SD_Initialize();
  
  return (ret);
}

/*******************************************************************************
* Function Name  : MSD_EarseBlock
* Description    : Earse the MSD/SD .
* Input          : None
* Output         : None
* Return         : The MSD Response: - MSD_RESPONSE_FAILURE: Sequence failed
*                                    - MSD_RESPONSE_NO_ERROR: Sequence succeed 
*******************************************************************************/
u8 MSD_EarseBlock(u32 startaddr, u32 blocknum)
{
	u8 ret = MSD_RESPONSE_FAILURE;

	ret = SD_EraseBlock(startaddr, blocknum);

	return (ret);
}
/*******************************************************************************
* Function Name  : MSD_WriteBlock
* Description    : Writes a block on the MSD
* Input          : - pBuffer : pointer to the buffer containing the data to be
*                    written on the MSD.
*                  - WriteAddr : address to write on.
*                  - NumByteToWrite: number of data to write
* Output         : None
* Return         : The MSD Response: - MSD_RESPONSE_FAILURE: Sequence failed
*                                    - MSD_RESPONSE_NO_ERROR: Sequence succeed 
*******************************************************************************/
u8 MSD_WriteBlock(u8* pBuffer, u32 WriteAddr, u16 NumByteToWrite)
{
  u8 ret = MSD_RESPONSE_FAILURE;

  ret = SD_WriteBlock(WriteAddr, NumByteToWrite, pBuffer);
 
  /* Returns the reponse */
  return ret;
}

/*******************************************************************************
* Function Name  : MSD_ReadBlock
* Description    : Reads a block of data from the MSD.
* Input          : - pBuffer : pointer to the buffer that receives the data read
*                    from the MSD.
*                  - ReadAddr : MSD's internal address to read from.
*                  - NumByteToRead : number of bytes to read from the MSD.
* Output         : None
* Return         : The MSD Response: - MSD_RESPONSE_FAILURE: Sequence failed
*                                    - MSD_RESPONSE_NO_ERROR: Sequence succeed 
*******************************************************************************/
u8 MSD_ReadBlock(u8* pBuffer, u32 ReadAddr, u16 NumByteToRead)
{
  u8 ret = MSD_RESPONSE_FAILURE;

  ret = SD_ReadBlock(ReadAddr,NumByteToRead, pBuffer);
     
  return ret;
}

/*******************************************************************************
* Function Name  : MSD_WriteBuffer
* Description    : Writes many blocks on the MSD
* Input          : - pBuffer : pointer to the buffer containing the data to be
*                    written on the MSD.
*                  - WriteAddr : address to write on.
*                  - NumByteToWrite: number of data to write
* Output         : None
* Return         : The MSD Response: - MSD_RESPONSE_FAILURE: Sequence failed
*                                    - MSD_RESPONSE_NO_ERROR: Sequence succeed 
*******************************************************************************/
u8 MSD_WriteBuffer(u8* pBuffer, u32 WriteAddr, u32 NumByteToWrite)
{
  u32 NbrOfBlock = 0;
  u8 ret = MSD_RESPONSE_FAILURE;

  /* Calculate number of blocks to write */
  NbrOfBlock = NumByteToWrite / BLOCK_SIZE;

  ret = SD_WriteMultiBlock(WriteAddr, NbrOfBlock, pBuffer);
  
  return ret;
}

/*******************************************************************************
* Function Name  : MSD_ReadBuffer
* Description    : Reads multiple block of data from the MSD.
* Input          : - pBuffer : pointer to the buffer that receives the data read
*                    from the MSD.
*                  - ReadAddr : MSD's internal address to read from.
*                  - NumByteToRead : number of bytes to read from the MSD.
* Output         : None
* Return         : The MSD Response: - MSD_RESPONSE_FAILURE: Sequence failed
*                                    - MSD_RESPONSE_NO_ERROR: Sequence succeed 
*******************************************************************************/
u8 MSD_ReadBuffer(u8* pBuffer, u32 ReadAddr, u32 NumByteToRead)
{
  u32 NbrOfBlock = 0;

  u8 ret = MSD_RESPONSE_FAILURE;

  /* Calculate number of blocks to write */
  NbrOfBlock = NumByteToRead / BLOCK_SIZE;

  ret = SD_ReadMultiBlock(ReadAddr, NbrOfBlock, pBuffer);
  
  return ret;
}
/*******************************************************************************
* Function Name  : MSD_GetMediumCharacteristics.
* Description    : Get the microSD card size.
* Input          : None.
* Output         : None.
* Return         : card type.
*******************************************************************************/
u32 MSD_GetMediumCharacteristics(void)
{
  u32 temp1 = 0;

  temp1 = sds.card_type;
  Mass_Block_Size = sds.block_len;
  Mass_Block_Count = sds.block_num;
  Mass_Memory_Size = Mass_Block_Size *  Mass_Block_Count;
 
   return temp1;
}

/******************************END OF FILE*************************************/

⌨️ 快捷键说明

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