📄 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 "sd_extr.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){ int i;#if 0 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 */ #endif GPEUP = 0xf83f; // SDCMD, SDDAT[3:0] => PU En. GPECON = 0xaaaaaaaa; //SDCMD, SDDAT[3:0] //SD_Powerup(); /* supply power to sd/mmc card */ //SD_Clk400k(); /* set the clock(read and write sd/mmc) to 40KHz */ //SD_ClkToMax(); SDIIMSK = 0x0; /* Type B, SD clock enable 数据传输类型为B, 时钟使能 */ //SDICON = SDICON_LE | SDICON_FRESET | SDICON_ENCLK; SDICON = 0; SDICON = (1<<4)|1; SDIFSTA= SDIFSTA|(1<<16); //FIFO reset,FIFO复位, /* clear all bits of SDIDSTA register 清除SDI数据状态寄存器所有的位 */ //SDIDSTA = SDIDSTA_ALL; //SDIBSIZE =0x200; // 512byte(128word) //SDIDTIMER=0x7fffff; // Set timeout count /* delay */ //mdelay(125); SD_ClkToMax(); for(i=0;i<0x1000;i++); // Wait 74SDCLK for MMC card }/*********************************************************************************************************** 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: **------------------------------------------------------------------------------------------------------********************************************************************************************************///1. Set SDICON to configure properly with clock & interrupt enable//2. Set SDIPRE to configure with a proper value.//3. Wait 74 SDCLK clock cycle in order to initialize the card.void SD_Powerup(void){ int i; /* Set block size to 512 bytes 设置块大小为512字节 */ //SDIBSIZE = SD_BLOCKSIZE; /* Set timeout count 设置超时计数器 */ //SDIDTIMER = 0xffff; /* Disable SDI interrupt 关闭SDI中断 */ SDIIMSK = 0x0; /* Type B, SD clock enable 数据传输类型为B, 时钟使能 */ //SDICON = SDICON_LE | SDICON_FRESET | SDICON_ENCLK; SDICON = 0; SDICON = (1<<4)|1; SDIFSTA= SDIFSTA|(1<<16); //FIFO reset,FIFO复位, /* clear all bits of SDIDSTA register 清除SDI数据状态寄存器所有的位 */ //SDIDSTA = SDIDSTA_ALL; //SDIBSIZE =0x200; // 512byte(128word) //SDIDTIMER=0x7fffff; // Set timeout count /* delay */ //mdelay(125); SD_ClkToMax(); for(i=0;i<0x1000;i++); // Wait 74SDCLK for MMC card}/*********************************************************************************************************** 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时钟 */ pclk = 296352000; /* calculate the clock that operate sd/mmc*/ //val = (pclk / 2 / (rate)); /* 计算操作sd/mmc卡的时钟 */ val = pclk / rate -1; /* write the value to prescaler register */ //SDIPRE = (SDIPRE_MSK & val); /* 将频率值写入分频寄存器 */ SDIPRE = 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(4000000); /* 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 + -