📄 sdhal.c
字号:
/****************************************Copyright (c)**************************************************** Guangzhou ZHIYUAN electronics Co.,LTD.** ** http://www.zyinside.com****--------------File Info-------------------------------------------------------------------------------** File Name: sdconfig.h** Last modified Date: 2006.01.09** Last Version: V1.0 ** Description: hardware abstract layer for s3c2410 SD/MMC****------------------------------------------------------------------------------------------------------** Created By: Ming Yuan Zheng 郑明远** Created date: 2006.01.09** Version: V1.0** Descriptions: The original version 初始版本****------------------------------------------------------------------------------------------------------** Modified by:** Modified date:** Version:** Description:**********************************************************************************************************/#include "config.h"/*********************************************************************************************************** Function name: SD_HardWareInit** Descriptions: initialize the hardware condiction that access sd card** 初始化访问SD卡的硬件条件 ** Input: NULL ** Output: NULL** Created by: Ming Yuan Zheng 郑明远 ** Created Date: 2006-01-09 **-------------------------------------------------------------------------------------------------------** Modified by:** Modified Date: **------------------------------------------------------------------------------------------------------********************************************************************************************************/void SD_HardWareInit(void){ set_gpio_ctrl(GPIO_SDDAT3 | GPIO_MODE_SDDAT | GPIO_PULLUP_EN); /* SDDAT3 is GPIO and pulled up */ set_gpio_ctrl(GPIO_SDDAT2 | GPIO_MODE_SDDAT | GPIO_PULLUP_EN); /* SDDAT2 is GPIO and pulled up */ set_gpio_ctrl(GPIO_SDDAT1 | GPIO_MODE_SDDAT | GPIO_PULLUP_EN); /* SDDAT1 is GPIO and pulled up */ set_gpio_ctrl(GPIO_SDDAT0 | GPIO_MODE_SDDAT | GPIO_PULLUP_EN); /* SDDAT0 is GPIO and pulled up */ set_gpio_ctrl(GPIO_SDCMD | GPIO_MODE_SDCMD | GPIO_PULLUP_EN); /* SDCMD is GPIO and pulled up */ set_gpio_ctrl(GPIO_SDCLK | GPIO_MODE_SDCLK | GPIO_PULLUP_EN); /* SDCLK is GPIO and pulled up */ SD_Powerup(); /* supply power to sd/mmc card */ SD_Clk400k(); /* set the clock(read and write sd/mmc) to 40KHz */}/*********************************************************************************************************** Function name: SD_Powerup** Descriptions: supply power to sd/mmc card** 给 sd/mmc 卡上电** Input: NULL ** Output: NULL** Created by: Ming Yuan Zheng 郑明远 ** Created Date: 2006-01-09**-------------------------------------------------------------------------------------------------------** Modified by:** Modified Date: **------------------------------------------------------------------------------------------------------********************************************************************************************************/void SD_Powerup(void){ /* Set block size to 512 bytes 设置块大小为512字节 */ SDIBSIZE = SD_BLOCKSIZE; /* Set timeout count 设置超时计数器 */ SDIDTIMER = 0xffff; /* Disable SDI interrupt 关闭SDI中断 */ SDIIMSK = 0x0; /* Type B, FIFO reset, SD clock enable 数据传输类型为B, FIFO复位, 时钟使能 */ SDICON = SDICON_LE | SDICON_FRESET | SDICON_ENCLK; /* clear all bits of SDIDSTA register 清除SDI数据状态寄存器所有的位 */ SDIDSTA = SDIDSTA_ALL; /* delay */ mdelay(125);}/*********************************************************************************************************** Function name: set_clock** Descriptions: set the clock for read and write sd/mmc card** 设置读写SD卡的频率值** Input: int rate: frequency value 频率值 ** Output: NULL** Created by: Ming Yuan Zheng 郑明远 ** Created Date: 2006-01-09**-------------------------------------------------------------------------------------------------------** Modified by:** Modified Date: **------------------------------------------------------------------------------------------------------********************************************************************************************************/static void set_clock(int rate){ unsigned long val, pclk; if (rate >= MMC_MMC_CLOCK_HIGH) rate = MMC_MMC_CLOCK_HIGH; /* 最大时钟为20MHz */ /* read s3c2410 PCLK */ pclk = s3c2410_get_bus_clk(GET_PCLK); /* 读取PCLK时钟 */ /* calculate the clock that operate sd/mmc*/ val = (pclk / 2 / (rate)); /* 计算操作sd/mmc卡的时钟 */ /* write the value to prescaler register */ SDIPRE = (SDIPRE_MSK & val); /* 将频率值写入分频寄存器 */}/*********************************************************************************************************** Function name: SD_Clk400k** Descriptions: set the clock(read or write sd/mmc) to 400KHz** 设置访问sd/mmc的速度为400KHz** Input: NULL ** Output: NULL** Created by: Ming Yuan Zheng 郑明远 ** Created Date: 2006-01-09**-------------------------------------------------------------------------------------------------------** Modified by:** Modified Date: **------------------------------------------------------------------------------------------------------********************************************************************************************************/void SD_Clk400k(void){ set_clock(400000); /* 400K Hz */}/*********************************************************************************************************** Function name: SD_ClkToMax** Descriptions: set the clock(read or write sd/mmc) to max** 设置访问sd/mmc的速度到最高** Input: NULL ** Output: NULL** Created by: Ming Yuan Zheng 郑明远 ** Created Date: 2006-01-09**-------------------------------------------------------------------------------------------------------** Modified by:** Modified Date: **------------------------------------------------------------------------------------------------------********************************************************************************************************/void SD_ClkToMax(void){ set_clock(MMC_MMC_CLOCK_HIGH); /* Max frequency */}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -