📄 gspx-pxa.c
字号:
void pxa_gspi_deinit(PSSP_HARDWARE_CONTEXT pDC)
{
PSSP_HARDWARE_CONTEXT pHC = (PSSP_HARDWARE_CONTEXT)pDC;
EnterCriticalSection(&pHC->SSPCrit);
CloseHandle(pHC->waitqueue);
gspx_power_down(pHC);
ssp_deinit_hw(pHC);
LeaveCriticalSection(&pHC->SSPCrit);
DeleteCriticalSection(&(pHC->SSPCrit));
if (LocalFree(pHC))
{
DEBUGMSG(ZONE_ERROR, (TEXT("pxa_gspi_deinit: free pHC error!\n")));
}
return;
}
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
DEBUGREGISTER(hModule);
DEBUG_INIT();
DEBUGMSG(ZONE_INIT, (TEXT("GSPX DllMain: DLL_PROCESS_ATTACH\n")));
DEBUGMSG(ZONE_INIT, (TEXT("Build date: ")TEXT(__DATE__)TEXT(" ")TEXT(__TIME__)TEXT("\n")));
DisableThreadLibraryCalls((HMODULE) hModule);
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
DEBUGMSG(ZONE_INIT, (TEXT("GSPX DllMain: DLL_PROCESS_DETACH\n")));
DEBUG_HALT();
break;
}
return TRUE;
}
int gspx_read_intstate(PVOID hDC)
{
PSSP_HARDWARE_CONTEXT pHC;
DWORD gplr, gedr;
DWORD resval;
if (hDC == NULL) {
resval = 0;
goto funcfinal;
}
pHC = (PSSP_HARDWARE_CONTEXT) hDC;
gedr = pHC->pGPIORegs->GEDR0;
gplr = pHC->pGPIORegs->GPLR0;
GSPIMSG(1, (L"(GPLR0, GEDR): (%08xh, %08xh) \n", gplr, gedr));
resval = (gplr >> SSP_INTR)&1;
funcfinal:
return resval;
}
///////////////////////////////////////////////////////////////////////////////
// Function: gspx_read_reg8
// Description:
// Parameters:
// Return:
///////////////////////////////////////////////////////////////////////////////
BOOL gspx_read_reg8(PVOID hDC, WORD reg, BYTE *data)
{
GSPI_STATUS status;
WORD regdata;
status = ssp_read_register(hDC, ®data, reg);
///ssp_read_data_direct(ssphc, ®data, reg, 1, g_spi_dummy_clk_reg);
*data = (BYTE)regdata;
return (status == GSPI_SUCCESS);
}
#endif
/*******************************************************************************
Customer Section:
gspx_ section: user customizes following functions
fucntions are used by outside the controller
*******************************************************************************/
///////////////////////////////////////////////////////////////////////////////
// Function: gspx_init
// Description:
// Initializes a GSPI host controller so that the other required API
// functions can be implemented. The initialization typically includes
// memory mapping, interrupt, GPIO pin initialization, etc
// Parameters:
// None
// Return:
// Pointer to the OEM defined GSPI host device context on success, and
// NULL on failure. The returned device context is passed back to the DLL
// in subsequent calls to the DLL.
///////////////////////////////////////////////////////////////////////////////
PVOID gspx_init(VOID)
{
PVOID handle;
DEBUGMSG(ZONE_FUNC, (TEXT("GSPX_init(): PXA270\n")));
handle = pxa_gspi_Init();
///crlo:verion-check ++
if (handle== 0) {
handle = NULL;
goto funcFinal;
}
///crlo:verion-check --
//###xlin moveed to gspx_set_callback pxa_gspi_register_isr(handle, pSpiParam, (ISRFUNC)SPINdisInterruptCallback);
///crlo:verion-check ++
funcFinal:
return handle;
///crlo:verion-check --
}
///////////////////////////////////////////////////////////////////////////////
// Function: gspx_deinit
// Description:
// Deinitializes the GSPI controller initialized by gspx_init(). This
// typically includes unmapping memories, unallocating interrupt, freeing
// critical sections, and other resources allocated by the DLL.
// Parameters:
// pHC - Pointer to the device context returned by gspx_init().
// Return:
// None
///////////////////////////////////////////////////////////////////////////////
//BOOL pxa_gspi_Deinit(PVOID hDC)
VOID gspx_deinit(PVOID hDC)
{
BOOL result = TRUE;
PSSP_HARDWARE_CONTEXT pHC = (PSSP_HARDWARE_CONTEXT)hDC;
DEBUGMSG(ZONE_FUNC, (TEXT("GSPX_deinit(): PXA270\n")));
//ENTERFUNC();
if (pHC == NULL) {
GSPIMSG(ERRMSG, (TEXT("Allocate SSP_HARDWARE_CONTEXT FAILED")));
result = FALSE;
goto funcFinal;
}
pxa_gspi_deinit(pHC);
funcFinal:
GSPIMSG(PROGFLOW, (TEXT("Exit %s (%xh) \n"), TEXT(__FUNCTION__), result));
return; //result;
}
///////////////////////////////////////////////////////////////////////////////
// Function: gspx_set_ist_callback
// Description:
// The WLAN calls this function to setup a callback to process the WLAN
// interrupts
// Parameters:
// pHC - Pointer to the device context returned by gspx_init().
// cb - Pointer to the callback function in the WLAN driver.
// context - The WLAN driver supplied context data which is passed back
// as the function parameter
// Return:
// The ID of the system interrupt allocated by gspx_init()
///////////////////////////////////////////////////////////////////////////////
BOOL gspx_set_ist_callback(PVOID pHC, PVOID cb, PVOID context)
{
pxa_gspi_register_isr(pHC, context, cb);
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
// Function: gspx_get_clock_rate
// Description:
// Gets the current GSPI host controller clock speed
// Parameters:
// pHC - Pointer to the device context returned by gspx_init().
// Return:
// The host controller clock speed in Hz
///////////////////////////////////////////////////////////////////////////////
UINT32 gspx_get_clock_rate(PVOID pHC)
{
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
// Function: gspx_set_clock_rate
// Description:
// Sets the GSPI host controller's clock speed. If the controller does not
// support the exact speed requested, the speed shall be set to the next
// lower speed supported.
// Parameters:
// pHC - Pointer to the device context returned by gspx_init().
// rate - Clock rate to set to in Hz.
// Return:
// TRUE on success, and FALSE on failure.
///////////////////////////////////////////////////////////////////////////////
BOOL gspx_set_clock_rate(PVOID pHC, UINT32 rate)
{
if(rate != GSPI_BUS_CLK_RATE)
return FALSE;
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
// Function: gspx_set_clocking_edge
// Description:
// Sets the host to use rising or falling edge to clock data in.
// Parameters:
// pHC - Pointer to the device context returned by gspx_init().
// rise_fall - 1 for rising edge, and 0 for falling edge
// Return:
// TRUE on success, and FALSE on failure.
///////////////////////////////////////////////////////////////////////////////
BOOL gspx_set_clocking_edge(PVOID pHC, BOOL raise_fall)
{
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
// Function: gspx_set_read_delay
// Description:
// Sets register read delay in number of clocks
// Parameters:
// pHC - Pointer to the device context returned by gspx_init().
// reg - Read Register delay in multiple of 16 clocks.
// io - Port Register delay in multiple of 16 clocks.
// Return:
// TRUE on success, and FALSE on failure.
///////////////////////////////////////////////////////////////////////////////
BOOL gspx_set_read_delay(PVOID pHC, UINT16 reg, UINT16 io)
{
g_spi_dummy_clk_reg = reg;
g_spi_dummy_clk_data = io;
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
// Function: gspx_reset_module
// Description:
// Resets the WLAN module by resting the RESET pin on the WLAN module.
// Parameters:
// pHC - Pointer to the device context returned by gspx_init().
// Return:
// None
///////////////////////////////////////////////////////////////////////////////
VOID gspx_reset_module(PVOID pHC)
{
PSSP_HARDWARE_CONTEXT pContext = (PSSP_HARDWARE_CONTEXT) pHC;
DEBUGMSG(ZONE_FUNC, (TEXT("+gspx_reset_module()\n")));
EnterCriticalSection(&pContext->SSPCrit); //JKU
set_GPIO_signal(pContext->pGPIORegs, SSP_RST, SIG_UP);
udelay(pContext->pOSTRegs, 5000);
set_GPIO_signal(pContext->pGPIORegs, SSP_RST, SIG_DOWN); //JKU: pin 11 to reset
udelay(pContext->pOSTRegs, 5000);
set_GPIO_signal(pContext->pGPIORegs, SSP_RST, SIG_UP);
udelay(pContext->pOSTRegs, 10000);
LeaveCriticalSection(&pContext->SSPCrit); //JKU
DEBUGMSG(ZONE_FUNC, (TEXT("-gspx_reset_module()\n")));
}
///////////////////////////////////////////////////////////////////////////////
// Function: gspx_read_reg16
// Description:
// Reads a 16-bit value from a single register.
// Parameters:
// pHC - Pointer to the device context returned by gspx_init().
// reg - Register address to read from.
// data - A 16-bit value read from the register.
// Return:
// TRUE on success, and FALSE on failure.
///////////////////////////////////////////////////////////////////////////////
BOOL gspx_read_reg16(PVOID pHC, UINT16 reg, UINT16 *data)
{
GSPI_STATUS status;
status = ssp_read_register(pHC, data, reg);
return (status == GSPI_SUCCESS);
}
///////////////////////////////////////////////////////////////////////////////
// Function: gspx_write_reg16
// Description:
// Writes to a single register a 16-bit value.
// Parameters:
// pHC - Pointer to the device context returned by gspx_init().
// reg - Register address to write to.
// data - A 16-bit value to write.
// Return:
// TRUE on success, and FALSE on failure.
///////////////////////////////////////////////////////////////////////////////
BOOL gspx_write_reg16(PVOID pHC, UINT16 regaddr, UINT16 regdata)
{
GSPI_STATUS status;
WORD word = regdata;
status = ssp_write_register(pHC, regaddr, &word);
return (status == GSPI_SUCCESS);
}
///////////////////////////////////////////////////////////////////////////////
// Function: gspx_read_reg32
// Description:
// Reads a 32-bit value from a single register.
// Parameters:
// pHC - Pointer to the device context returned by gspx_init().
// reg - Register address to read from.
// data - A 32-bit value read from the register.
// Return:
// TRUE on success, and FALSE on failure.
///////////////////////////////////////////////////////////////////////////////
BOOL gspx_read_reg32(PVOID pHC, UINT16 reg, UINT32 *data)
{
GSPI_STATUS status;
WORD *regaddr = (WORD *)reg;
WORD *regdatPt = (WORD*)data;
status = ssp_read_register(pHC, regdatPt, (WORD)regaddr);
status = ssp_read_register(pHC, (regdatPt+1), (WORD)(regaddr+1));
return (status == GSPI_SUCCESS);
}
///////////////////////////////////////////////////////////////////////////////
// Function: gspx_write_reg32
// Description:
// Writes to a single register a 32-bit value.
// Parameters:
// pHC - Pointer to the device context returned by gspx_init().
// reg - Register address to write to.
// data - A 32-bit value to write
// Return:
// TRUE on success, and FALSE on failure.
///////////////////////////////////////////////////////////////////////////////
BOOL gspx_write_reg32(PVOID pHC, UINT16 reg, UINT32 data)
{
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
// Function: gspx_read_mem
// Description:
// Reads a buffer from the port on the WLAN module.
// Parameters:
// pHC - Pointer to the device context returned by gspx_init().
// reg - Address to read from.
// nword - Number of 16-bit values to read.
// datPt - Caller supplied buffer for storing the data read.
// Return:
// TRUE on success, and FALSE on failure.
///////////////////////////////////////////////////////////////////////////////
BOOL gspx_read_mem(PVOID pHC,UINT16 reg, UINT16 nword, UINT16* datPt)
{
GSPI_STATUS status;
status = ssp_read_data(pHC, datPt, reg, nword);
return (status == GSPI_SUCCESS);
}
///////////////////////////////////////////////////////////////////////////////
// Function: gspx_write_mem
// Description:
// Writes a buffer to the port on the WLAN module.
// Parameters:
// pHC - Pointer to the device context returned by gspx_init().
// reg - Address to write to.
// nword - Number of 16-bit values to write.
// datPt - Pointer to the data buffer to write.
// Return:
// TRUE on success, and FALSE on failure.
///////////////////////////////////////////////////////////////////////////////
BOOL gspx_write_mem(PVOID pHC, UINT16 regaddr, UINT16 nword, UINT16* datPt)
{
GSPI_STATUS status;
status = ssp_write_data(pHC,datPt,regaddr,nword);
return (status == GSPI_SUCCESS);
}
///////////////////////////////////////////////////////////////////////////////
// Function: gspx_power_up
// Description:
// Power up the WLAN module.
// Parameters:
// pHC - Pointer to the device context returned by gspx_init().
// Return:
// TRUE on success, and FALSE on failure.
///////////////////////////////////////////////////////////////////////////////
BOOL gspx_power_up(PVOID pHC)
{
PSSP_HARDWARE_CONTEXT pContext = (PSSP_HARDWARE_CONTEXT) pHC;
set_GPIO_signal(pContext->pGPIORegs, SSP_RST, SIG_UP);
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
// Function: gspx_power_down
// Description:
// Power down the WLAN module.
// Parameters:
// pHC - Pointer to the device context returned by gspx_init().
// Return:
// TRUE on success, and FALSE on failure.
///////////////////////////////////////////////////////////////////////////////
BOOL gspx_power_down(PVOID pHC)
{
PSSP_HARDWARE_CONTEXT pContext = (PSSP_HARDWARE_CONTEXT) pHC;
set_GPIO_signal(pContext->pGPIORegs, SSP_RST, SIG_DOWN);
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -