?? gspi_bus_2440.c
字號:
g_pHwInfo->dmaRxBuf[19]
));
//*/
prepare_for_spibus(data, g_pHwInfo->dmaRxBuf + 2, size);
GspiBusReleaseIO();
return GSPI_OK;
}
int gspi_read_data(UINT16 *data, UINT16 size)
{
GspiBusAcquireIO();
GspiHostSetSCSHigh();
GspiHostSetSCSLow();
GspiBusSetTransmitter_nodma();
gspi_write_for_read(data[0], 1 + g_spi_dummy_clk_reg);
GspiBusResetTransmitter();
GspiBusSetReceiver();
GspiBusStartRxDMA(0, size * 2 + 2);
GspiBusWaitForRxDMA();
GSPI_WAIT_FOR_BUS_RDY();
// GspiHostSetSCSHigh();
GspiBusResetReceiver();
// if (((volatile)(g_pHwInfo->pSPIRegs->rSPSTA0) & BIT0))
{ // read the last byte
g_pHwInfo->dmaRxBuf[size * 2] = g_pHwInfo->pSPIRegs->rSPRDAT0 & 0xff;
}
/*
DBG_PRINT(gDbgInfo,("rbuffer: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
g_pHwInfo->dmaRxBuf[0],
g_pHwInfo->dmaRxBuf[1],
g_pHwInfo->dmaRxBuf[2],
g_pHwInfo->dmaRxBuf[3],
g_pHwInfo->dmaRxBuf[4],
g_pHwInfo->dmaRxBuf[5],
g_pHwInfo->dmaRxBuf[6],
g_pHwInfo->dmaRxBuf[7],
g_pHwInfo->dmaRxBuf[8],
g_pHwInfo->dmaRxBuf[9],
g_pHwInfo->dmaRxBuf[10],
g_pHwInfo->dmaRxBuf[11],
g_pHwInfo->dmaRxBuf[12],
g_pHwInfo->dmaRxBuf[13],
g_pHwInfo->dmaRxBuf[14],
g_pHwInfo->dmaRxBuf[15],
g_pHwInfo->dmaRxBuf[16],
g_pHwInfo->dmaRxBuf[17],
g_pHwInfo->dmaRxBuf[18],
g_pHwInfo->dmaRxBuf[19]
));
//*/
// endian swap
prepare_for_spibus((UINT8 *)data, g_pHwInfo->dmaRxBuf + 2, size);
GspiBusReleaseIO();
return GSPI_OK;
}
int gspi_bus_write_data(UINT16 *data, UINT16 size)
{
UINT16 sizeInBytes = size << 1;
GspiBusAcquireIO();
GspiHostSetSCSHigh();
GspiHostSetSCSLow();
GspiBusSetTransmitter();
data[0] |= BYTE_STREAM(GSPI_WRITE);
//DBG_PRINT(gDbgInfo,("buffer: %02x %02x %02x %02x\n", pData[0], pData[1], pData[2], pData[3]));
prepare_for_spibus((unsigned char *)g_pHwInfo->dmaTxBuf, (UCHAR*)data, size);
// endian swap
/*
DBG_PRINT(gDbgInfo,("%02x %02x %02x %02x %02x %02x %02x %02x\n",
g_pHwInfo->dmaTxBuf[0],
g_pHwInfo->dmaTxBuf[1],
g_pHwInfo->dmaTxBuf[2],
g_pHwInfo->dmaTxBuf[3],
g_pHwInfo->dmaTxBuf[4],
g_pHwInfo->dmaTxBuf[5],
g_pHwInfo->dmaTxBuf[6],
g_pHwInfo->dmaTxBuf[7]
));
//*/
GspiBusStartTxDMA(0, size * 2);
GspiBusWaitForTxDMA();
GSPI_WAIT_FOR_BUS_RDY();
// while (!((volatile)(g_pHwInfo->pSPIRegs->rSPSTA0) & BIT0));
// GSPI_WAIT_FOR_BUS_RDY();
// gspi_delay(10);
GspiBusResetTransmitter();
// GspiHostSetSCSHigh();
GspiBusReleaseIO();
return GSPI_OK;
}
int gspi_bus_write_data_direct(UCHAR *data, UINT16 reg, UINT16 size)
{
GspiBusAcquireIO();
GspiHostSetSCSHigh();
GspiHostSetSCSLow();
GspiBusSetTransmitter();
reg |= BYTE_STREAM(GSPI_WRITE);
// endian swap
prepare_for_spibus(g_pHwInfo->dmaTxBuf, (UCHAR*)®, 1);
prepare_for_spibus(g_pHwInfo->dmaTxBuf + 2, data, (size-1));
/*
DBG_PRINT(gDbgInfo,("%02x %02x %02x %02x %02x %02x %02x %02x\n",
g_pHwInfo->dmaTxBuf[0],
g_pHwInfo->dmaTxBuf[1],
g_pHwInfo->dmaTxBuf[2],
g_pHwInfo->dmaTxBuf[3],
g_pHwInfo->dmaTxBuf[4],
g_pHwInfo->dmaTxBuf[5],
g_pHwInfo->dmaTxBuf[6],
g_pHwInfo->dmaTxBuf[7]
));
//*/
GspiBusStartTxDMA(0, size * 2);
GspiBusWaitForTxDMA();
GSPI_WAIT_FOR_BUS_RDY();
//gspi_delay(20);
GspiBusResetTransmitter();
// GspiHostSetSCSHigh();
GspiBusReleaseIO();
return GSPI_OK;
}
/*--------------------------------------------------*/
int gspi_read_data_direct_nodma(UCHAR *data, UINT16 reg, UINT16 size)
{
UINT8 dummy = 0xff;
GspiBusAcquireIO();
GspiHostSetSCSHigh();
GspiHostSetSCSLow();
GspiBusSetTransmitter_nodma();
gspi_write_for_read(reg, 1 + g_spi_dummy_clk_data);
gspi_recv_data((UINT16*)data,size);
// gspi_delay(500);
// GspiHostSetSCSHigh();
GspiBusResetReceiver();
GspiBusReleaseIO();
return GSPI_OK;
}
int gspi_read_data_nodma(UINT16 *data, UINT16 size)
{
GspiBusAcquireIO();
GspiHostSetSCSHigh();
GspiHostSetSCSLow();
GspiBusSetTransmitter_nodma();
gspi_write_for_read(data[0], 1 + g_spi_dummy_clk_reg);
gspi_recv_data((UINT16*)data,size);
// gspi_delay(500);
// GspiHostSetSCSHigh();
GspiBusResetReceiver();
GspiBusReleaseIO();
return GSPI_OK;
}
int gspi_write_data_nodma(UINT16 *data, UINT16 size)
{
GspiBusAcquireIO();
GspiHostSetSCSHigh();
GspiHostSetSCSLow();
GspiBusSetTransmitter_nodma();
data[0] |= BYTE_STREAM(GSPI_WRITE);
//DBG_PRINT(gDbgInfo,("buffer: %02x %02x %02x %02x\n", pData[0], pData[1], pData[2], pData[3]));
gspi_xmt_data(data,size);
// gspi_delay(500);
//GSPI_WAIT_FOR_BUS_RDY();
GspiBusResetTransmitter();
// GspiHostSetSCSHigh();
GspiBusReleaseIO();
return GSPI_OK;
}
int gspi_write_data_direct_nodma(UCHAR *data, UINT16 reg, UINT16 size)
{
GspiBusAcquireIO();
GspiHostSetSCSHigh();
GspiHostSetSCSLow();
GspiBusSetTransmitter_nodma();
reg |= BYTE_STREAM(GSPI_WRITE);
gspi_xmt_data((UINT16*)®,1);
gspi_xmt_data((UINT16*)data, size);
// gspi_delay(500);
// GSPI_WAIT_FOR_BUS_RDY();
GspiBusResetTransmitter();
// GspiHostSetSCSHigh();
GspiBusReleaseIO();
return GSPI_OK;
}
/*-------------------------*/
BOOL VirtualCopy(
LPVOID lpvDest,
LPVOID lpvSrc,
DWORD cbSize,
DWORD fdwProtect
);
unsigned long GspiBusGetBSPIntID()
{
return SYSINTR_WLAN;
}
unsigned long GspiBusGetBSPDMAIntID()
{
return SYSINTR_DMA1;
}
//
// Map a physical region of memory to a virtual region of memory
//
void* MapIOSpace(void* pPhysAddr,
DWORD dwSize,
DWORD dwFlags) // PAGE_READONLY, PAGE_READWRITE, PAGE_NOCACHE
{
void* pPhysBase;
DWORD dwOffset;
void* pVirtBase;
void* pVirtAddr = NULL;
/*** Everything must be aligned on page boundaries ***/
// Determine the system page size (only once)
if(!si.dwPageSize)
{
GetSystemInfo(&si);
}
// Determine how much beyond a page boundary the requested memory is
dwOffset = (DWORD)pPhysAddr % si.dwPageSize;
// Get the nearest page boundary
pPhysBase = (void*)((DWORD)pPhysAddr - dwOffset);
// If the requested address is not page aligned, adjust the size
dwSize += dwOffset;
// Adjust the size to a multiple of pages
dwSize = dwSize + si.dwPageSize - 1;
dwSize -= dwSize % si.dwPageSize;
// Allocate some virtual memory
pVirtBase = VirtualAlloc(NULL,
dwSize,
MEM_RESERVE,
PAGE_NOACCESS);
if(pVirtBase)
{
// If the starting physical address is <= 512MB, we must divide it by
// 256 and set the PAGE_PHYSICAL bit to make VirtualCopy() happy. This
// is exactly the opposite of the documentation...
//#ifndef BUILT_FOR_WCE500
// if((DWORD)pPhysBase < 0x20000000)
//#endif
{
pPhysBase = (void*)((DWORD)pPhysBase / 256);
dwFlags |= PAGE_PHYSICAL;
}
// Map the physical memory into the virtual memory
if(!VirtualCopy(pVirtBase,
pPhysBase,
dwSize,
dwFlags))
{
VirtualFree(pVirtBase, 0, MEM_RELEASE);
}
else
{
pVirtAddr = (void*)((DWORD)pVirtBase + dwOffset);
}
}
return(pVirtAddr);
}
void UnmapIOSpace(void* pVirtAddr)
{
DWORD dwOffset;
void* pVirtBase;
// Determine how much beyond a page boundary the requested memory is
dwOffset = (DWORD)pVirtAddr % si.dwPageSize;
// Get the nearest page boundary
pVirtBase = (void*)((DWORD)pVirtAddr - dwOffset);
// Release the virtual pointer
VirtualFree(pVirtBase, 0, MEM_RELEASE);
}
int gspi_delay_loop;
void gspi_delay(int loop)
{
int i;
for (i = 0; i < loop; i++)
gspi_delay_loop=loop;
}
//gli wake up config 這個函數主要是用來把中斷的pin配置成wakeupsource功能用
VOID gspx_config_wakeup(PVOID pHD)
{
DWORD ttt;
GSPIMSG(1, (TEXT("GSPI: gspx_config_wakeup\r\n")));
#if 0
// Configure the interrupt pin
g_pHwInfo->pGPIORegs->rGPGCON &= ~(3<<8);
g_pHwInfo->pGPIORegs->rGPGCON |= (2<<8);
g_pHwInfo->pGPIORegs->rGPGUP |= (1<<4);
ttt = (g_pHwInfo->pGPIORegs->rEXTINT1 & (~(0xf<<16))) | (0x2<<16);
g_pHwInfo->pGPIORegs->rEXTINT1 = ttt;
#endif
return GSPI_OK;
}
// gli this function will be called for wake up so need not power up and reset module
//這個函數主要實現當cpu被wakeup起來后要重新對gpio口進行配置特別是被配置成wakeup source功能的pin 重新配置成中斷功能,和初始化配置一樣。千萬不要進行powerdown的超作
VOID gspx_reinit_hw(PVOID pHC)
{
DWORD ttt;
GSPIMSG(1, (TEXT("GSPI: gspx_reinit_hw\r\n")));
g_pHwInfo->pGPIORegs->rGPGCON &= ~((0x03 << 10) | (0x03 << 12) | (0x03 << 14)); // clear
g_pHwInfo->pGPIORegs->rGPGCON |= (0x03 << 10) | (0x03 << 12) | (0x03 << 14); // set
g_pHwInfo->pGPIORegs->rGPGUP |= (0x01 << 5)|(0x01 << 6);
// to config SPI_CS:GPE11 as general io pin
g_pHwInfo->pGPIORegs->rGPECON &= ~(0x03 << 22); // clear
g_pHwInfo->pGPIORegs->rGPECON |= 0x01 << 22; // set
g_pHwInfo->pGPIORegs->rGPEUP |= (0x01 << 11);
//Reset:GPG12 as output
//g_pHwInfo->pGPIORegs->rGPGCON &= ~(0x03 << 24); // clear
//g_pHwInfo->pGPIORegs->rGPGCON |= 0x01 << 24; // set
//g_pHwInfo->pGPIORegs->rGPGUP |= (0x01 << 12);
//PowerDown:GPA12 as output
g_pHwInfo->pGPIORegs->rGPACON &= ~(0x01 << 12); // set GPA12 to 0
// Configure the interrupt pin
g_pHwInfo->pGPIORegs->rGPGCON &= ~(3<<8);
g_pHwInfo->pGPIORegs->rGPGCON |= (2<<8);
g_pHwInfo->pGPIORegs->rGPGUP |= (1<<4);
ttt = (g_pHwInfo->pGPIORegs->rEXTINT1 & (~(0xf<<16))) | (0x2<<16);
g_pHwInfo->pGPIORegs->rEXTINT1 = ttt;
//GspiHostSetRSTHigh();
//GspiHostSetPDHigh();
//GspiHostSetSCSHigh();
}
//這個函數主要是對gpio重新進行初始化,不過你可以需要對模塊進行一個powerdown and reset module的動作,就在你昨天那個問題點擊power按鈕系統再次起來 scan不到ap的愿意可能是你們需要對gpio口在次進行一次初始化動作
VOID gspx_reinit(PVOID pHC)
{
DWORD ttt;
GSPIMSG(1, (TEXT("GSPI: gspx_reinit\r\n")));
g_pHwInfo->pGPIORegs->rGPGCON &= ~((0x03 << 10) | (0x03 << 12) | (0x03 << 14)); // clear
g_pHwInfo->pGPIORegs->rGPGCON |= (0x03 << 10) | (0x03 << 12) | (0x03 << 14); // set
g_pHwInfo->pGPIORegs->rGPGUP |= (0x01 << 5)|(0x01 << 6);
// to config SPI_CS:GPE11 as general io pin
g_pHwInfo->pGPIORegs->rGPECON &= ~(0x03 << 22); // clear
g_pHwInfo->pGPIORegs->rGPECON |= 0x01 << 22; // set
g_pHwInfo->pGPIORegs->rGPEUP |= (0x01 << 11);
//Reset:GPG12 as output
//g_pHwInfo->pGPIORegs->rGPGCON &= ~(0x03 << 24); // clear
//g_pHwInfo->pGPIORegs->rGPGCON |= 0x01 << 24; // set
//g_pHwInfo->pGPIORegs->rGPGUP |= (0x01 << 12);
//PowerDown:GPA12 as output
g_pHwInfo->pGPIORegs->rGPACON &= ~(0x01 << 12); // set GPA12 to 0
// Configure the interrupt pin
g_pHwInfo->pGPIORegs->rGPGCON &= ~(3<<8);
g_pHwInfo->pGPIORegs->rGPGCON |= (2<<8);
g_pHwInfo->pGPIORegs->rGPGUP |= (1<<4);
ttt = (g_pHwInfo->pGPIORegs->rEXTINT1 & (~(0xf<<16))) | (0x2<<16);
g_pHwInfo->pGPIORegs->rEXTINT1 = ttt;
// take the card out of reset
GspiHostSetRSTHigh();
//NdisMSleep(1000);
Sleep(1);
GspiHostSetRSTLow();
Sleep(10);
GspiHostSetRSTHigh();
GspiHostSetPDHigh();
GspiHostSetSCSHigh();
Sleep(1);
}
#endif
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -