📄 efsl_spi.c
字号:
// 青藤门客播报站//Email: walnutcy@163.com//Index: http://blog.ednchina.com/walnutcy///#include "sd.h"#include "config.h"#include "types.h"//#include "SdHal.h"//--------------->这个是arm 的spi 底层函数
#include "spi.h" //==========================================接口
void SD_HardWareInit(void)
{
SPI_IO_INIT();
SPIMOSILow();
SPICSHigh();
//延时500mS--->内核延时
OSTimeDly(200);
SPI_Flash_RST();
SPICSLow();
//延时20mx--->内核延时
OSTimeDly(4);
SPI_IO_INIT();
}
void SPI_CS_Enable(void)
{
//cs enable
SPICSLow();
//spi start ->only one task using spi
SPIStart();
}
void SPI_CS_Disable()
{
//cs disable
SPICSHigh();
//spi end ->only one task using spi
SPIEnd();
}
void SPI_TxBYTE(euint8 outgoing)
{
uint8 error = SPIWrite((uint8)outgoing);
}
euint8 SPI_RxBYTE()
{
uint8 buff=0;
uint8 error = SPIRead(&buff);
return buff;
}
// walter 20080909esint8 if_initInterface(hwInterface* file, eint8* opts){ euint32 sc; esint8 res; if_spiInit(file); /* init hardware */ SPI_CS_Enable(); res = sd_Init(file); SPI_CS_Disable(); if(res<0) { DBG(TXT("Card failed to init, breaking up...\n")); return(-1); } SPI_CS_Enable(); res = sd_State(file); SPI_CS_Disable(); if(res<0) { DBG(TXT("Card didn't return the ready state, breaking up...\n")); return(-2); } SPI_CS_Enable(); sd_getDriveSize(file, &sc); SPI_CS_Disable(); file->sectorCount = sc/512; if( (sc%512) != 0) { file->sectorCount--; } DBG(TXT("Drive Size is %lu Bytes (%lu Sectors)\n"), sc, file->sectorCount); DBG(TXT("Init done...\n")); return(0);}/*****************************************************************************/ esint8 if_readBuf(hwInterface* file,euint32 address,euint8* buf){ esint8 res; SPI_CS_Enable(); res = sd_readSector(file,address,buf,512); SPI_CS_Disable(); return res;}/*****************************************************************************/esint8 if_writeBuf(hwInterface* file,euint32 address,euint8* buf){ esint8 res; SPI_CS_Enable(); res = sd_writeSector(file,address, buf); SPI_CS_Disable(); return res;}/*****************************************************************************/ // Utility-functions which does not toogle CS.// Only needed during card-init. During init// the automatic chip-select is disabled for SSP
void if_spiSend(hwInterface *iface,euint8 outgoing){ SPI_TxBYTE(outgoing) ;}euint8 if_spiRead(void){ return SPI_RxBYTE();}/*****************************************************************************/ void if_spiInit(hwInterface *iface){ SD_HardWareInit();}/*****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -