#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)
{
BOOL RetValue = 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)
{
BOOL RetValue = 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))