写了个2440下的wince SPI驱动,请高手看下有什么问题
#include <windows.h>
#include <types.h>
#include <tchar.h>
#include <cardserv.h>
#include <cardapi.h>
#include <tuple.h>
#include <devload.h>
#include <diskio.h>
#include <nkintr.h>
//#include <oalintr.h>
#include <windev.h>
#include <S3c2440a_intr.h>
#include <s3c2440a_base_regs.h>
#include "s2440.h"
//#include "SPI.h"
HANDLE g_hInstance;
volatile IOPreg * v_pIOPregs;
volatile CLKPWRreg * v_pclkpwrregs;
volatile SSPreg *v_pSSPregs;
BOOL SPI_InitAddrIO(void);
BOOL SPI_InitAddrSPI(void);
BOOL SPI_InitAddrPwr(void);
void SPI_SendData(unsigned char);
/*******************************************************************************************
函数名称: DllEntry
描 述: 驱动程序动态库入口
输入参数:
输出参数:
返 回:
*******************************************************************************************/
BOOL WINAPI DllEntry(HANDLE hInstDll, DWORD dwReason, LPVOID lpvReserved)
{
switch ( dwReason )
{
case DLL_PROCESS_ATTACH:
RETAILMSG(1, (TEXT("SPI: DLL_PROCESS_ATTACH.\r\n")));/* 提示动态库加载 */
DisableThreadLibraryCalls((HMODULE) hInstDll);
break;
case DLL_PROCESS_DETACH:
RETAILMSG(1, (TEXT("SPI: DLL_PROCESS_DETACH.\r\n")));/* 提示动态库卸载 */
break;
}
return (TRUE);
}
void InitSPI(void) //init uart2
{
unsigned int pclk = S2440PCLK;
RETAILMSG (1, (TEXT("SPI_Initialize \r\n") ));
/* enable pclk for spiclk */
v_pclkpwrregs->rCLKCON |= (1<<18);
//spi1 init
/*
v_pIOPregs->rGPGCON &= ~(0x3F << 10);
v_pIOPregs->rGPGCON |= (0x3F << 10);
v_pIOPregs->rGPGUP |=(0X7<<5);
v_pSSPregs->rSPPRE1 = 0x18;
v_pSSPregs->rSPCON1 = 0x1e;
v_pSSPregs->rSPPIN1 = 0x02;
*/
//spi0 init
v_pIOPregs->rGPECON &= ~(0x3F << 22);
v_pIOPregs->rGPECON |= (0x2A << 22);
v_pIOPregs->rGPEUP |=(0X7<<11);
v_pSSPregs->rSPPRE0 = 0x18;
v_pSSPregs->rSPCON0 = 0x1e;
v_pSSPregs->rSPPIN0 = 0x02;
RETAILMSG (1, (TEXT("SPI_Initialize OK\r\n") ));
}BOOL
SPI_InitAddrIO(void)
{
BOOLRetValue = TRUE;
v_pIOPregs = (volatile IOPreg *)VirtualAlloc(0, sizeof(IOPreg), MEM_RESERVE, PAGE_NOACCESS);
if (v_pIOPregs == NULL)
{
ERRORMSG(1,(TEXT("For SPI_IOPregs : VirtualAlloc failed!\r\n")));
RetValue = FALSE;
}
else
{
if (!VirtualCopy((PVOID)v_pIOPregs, (PVOID)(IOP_BASE), sizeof(IOPreg), PAGE_READWRITE | PAGE_NOCACHE))
{
ERRORMSG(1,(TEXT("For SPI_IOPregs: VirtualCopy failed!\r\n")));
RetValue = FALSE;
}
}
if (!RetValue)
{
RETAILMSG (1, (TEXT("::: SPI_InitializeAddresses - Fail!!\r\n") ));
if (v_pIOPregs)
{
VirtualFree((PVOID) v_pIOPregs, 0, MEM_RELEASE);
}
v_pIOPregs = NULL;
}
else
{
;
RETAILMSG (1, (TEXT("::: SPI_InitializeAddresses - Success\r\n") ));
}
return(RetValue);
}
BOOL
SPI_InitPwr(void)
{
BOOLRetValue = TRUE;
v_pclkpwrregs = (volatile CLKPWRreg *)VirtualAlloc(0, sizeof(CLKPWRreg), MEM_RESERVE, PAGE_NOACCESS);
if (v_pclkpwrregs == NULL)
{
ERRORMSG(1,(TEXT("For SPI_Pwr : VirtualAlloc failed!\r\n")));
RetValue = FALSE;
}
else
{
if (!VirtualCopy((PVOID)v_pclkpwrregs, (PVOID)(IOP_BASE), sizeof(CLKPWRreg), PAGE_READWRITE | PAGE_NOCACHE))
{
ERRORMSG(1,(TEXT("For SPI_Pwr: VirtualCopy failed!\r\n")));
RetValue = FALSE;
}
}
if (!RetValue)
{
RETAILMSG (1, (TEXT("::: SPI_Pwr - Fail!!\r\n") ));
if (v_pIOPregs)
{
VirtualFree((PVOID)v_pclkpwrregs, 0, MEM_RELEASE);
}
v_pIOPregs = NULL;
}
else
{
RETAILMSG (1, (TEXT("::: SPI_Pwr - Success\r\n") ));
}
return(RetValue);
}
BOOL
SPI_InitAddrSPI(void)
{
BOOLRetValue = TRUE;
v_pSSPregs = (volatile SSPreg *)VirtualAlloc(0, sizeof(UART2reg), MEM_RESERVE, PAGE_NOACCESS);
if (v_pSSPregs == NULL)
{
ERRORMSG(1,(TEXT("For SPI_UART2regs : VirtualAlloc failed!\r\n")));
RetValue = FALSE;
}
else
{
if (!VirtualCopy((PVOID)v_pSSPregs, (PVOID)(UART2_BASE), sizeof(UART2reg), PAGE_READWRITE | PAGE_NOCACHE))
{
ERRORMSG(1,(TEXT("For SPI_UART2regs: VirtualCopy failed!\r\n")));
RetValue = FALSE;
}
}
if (!RetValue)
{
RETAILMSG (1, (TEXT("::: SPI_InitializeAddresses - Fail!!\r\n") ));
if (v_pSSPregs)
{
VirtualFree((PVOID) v_pSSPregs, 0, MEM_RELEASE);
}
v_pSSPregs = NULL;
}
else
{
;
RETAILMSG (1, (TEXT("SPI_InitializeAddresses - Success\r\n") ));
}
return(RetValue);
}
DWORD
SPI_Init(DWORD dwContext)
{
RETAILMSG(1,(TEXT("SPI: SPI_ INIT\n")));
SPI_InitAddrIO();
SPI_InitAddrSPI();
SPI_InitPwr();
InitSPI();
return 1;
}
DWORD
SPI_Close(DWORD Handle)
{
return TRUE;
}
DWORD SPI_Deinit(
DWORD dwContext // future: pointer to the per disk structure
)
{
return TRUE;
}
DWORD SPI_Open(
DWORD dwData,
DWORD dwAccess,
DWORD dwShareMode
)
{
return 1;
}
DWORD SPI_IOControl(
DWORD Handle,
DWORD dwIoControlCode,
PBYTE pInBuf,
DWORD nInBufSize,
PBYTE pOutBuf,
DWORD nOutBufSize,
PDWORD pBytesReturned
)
{
return 1;
}
DWORD SPI_Read(DWORD Handle, LPVOID pBuffer, DWORD dwNumBytes)
{
RETAILMSG (1, (TEXT("SPI_Read---ing\r\n") ));
return 0;
}
DWORD SPI_Write(DWORD Handle, LPCVOID pBuffer, DWORD dwNumBytes)
{
PUCHAR temp = (PUCHAR) pBuffer;
while(1)
{
if(v_pSSPregs->rSPSTA0 && 0x01)
{
v_pSSPregs->rSPTDAT0 = *temp;
RETAILMSG (1, (TEXT("write \r\n") ));
RETAILMSG (1, (TEXT("pBuffer=%d \r\n"),*temp ));
return 1;
}
}
return 1;
}DWORD SPI_Seek(DWORD Handle, long lDistance, DWORD dwMoveMethod)
{
return 0;
}
void SPI_PowerUp(void)
{
return;
}
void SPI_PowerDown(void)
{
return;
}
[解决办法]
你只把驱动写了,没有进行调用
[解决办法]
仔细看看register的设置,应该是没设置好。
[解决办法]
对啊,不调用,怎么可能有波形。如果没有SPI从设备,可以只写不读!