如何向一个寄存器的某一位写值呢?
我在开发一个led的驱动,用2440的cpu,将这个led接在一个gpio口上,用寄存器的某一位控制led的关灭,但是没成功,希望哪位大侠能给我提点建议,小弟万分感谢!
CE下
#include "stdafx.h"
#include "KEY.h"
volatile IOPreg *s2440IOP = (IOPreg *)IOP_BASE;
HANDLE hthread;
DWORD KeyThread(LPVOID lpParameter);
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
RETAILMSG(1,(TEXT("STRINGS:DLL_PROCESS_ATTACH\n")));
return TRUE;
case DLL_THREAD_ATTACH:
RETAILMSG(1,(TEXT("STRINGS:DLL_THREAD_ATTCH\n")));
break;
case DLL_THREAD_DETACH:
RETAILMSG(1,(TEXT("STRINGS:DLL_THREAD_DETACH\n")));
break;
case DLL_PROCESS_DETACH:
RETAILMSG(1,(TEXT("STRINGS:DLL_PROCESS_DETACH\n")));
break;
}
return TRUE;
}
// This is an example of an exported variable
KEY_API int nKEY=0;
// This is an example of an exported function.
KEY_API int fnKEY(void)
{
return 42;
}
KEY_API DWORD KEY_Init(DWORD dwContext)
{
DWORD dwRet=0;
RETAILMSG(1,(TEXT("MYSTRINGS:KEY_Init********\n")));
dwRet=1;
s2440IOP->rGPFCON&=~(3<<14); //控制LED的亮灭进行初始化
s2440IOP->rGPFCON|=(1<<14);
s2440IOP->rGPFUP&=~(1<<7);
s2440IOP->rGPFUP|=1<<7;
hthread=CreateThread(NULL,NULL,KeyThread,NULL,CREATE_SUSPENDED,NULL);
//创建一个线程,并挂起,传入的地址可用this
ResumeThread(hthread); //恢复运行
return dwRet;
}
KEY_API BOOL KEY_Deinit(DWORD hDeviceContext)
{
BOOL bRet=TRUE;
RETAILMSG(1,(TEXT("MYSTRINGS:KEY_Deinit\n")));
TerminateThread(hthread,0);//线程直接终止,但不会通过return 0退出,而是直接终//止
return bRet;
}
KEY_API DWORD KEY_Open(DWORD hDeviceContext,DWORD AccessCode,DWORD ShareMode)
{
DWORD dwRet=0;
RETAILMSG(1,(TEXT("MYSTRINGS:KEY_Open\n")));
dwRet=1;
return dwRet;
}
KEY_API BOOL KEY_Close(DWORD hOpenContext)
{
BOOL bRet=TRUE;
RETAILMSG(1,(TEXT("MYSTRINGS:KEY_Close\n")));
return bRet;
}
KEY_API BOOL KEY_IOControl(DWORD hOpenContext,
DWORD dwCode,
PBYTE pBufIn,
DWORD dwLenIn,
PBYTE pBufOut,
DWORD dwLenOut,
PDWORD pdwActualOut
)
{
BOOL bRet=TRUE;
RETAILMSG(1,(TEXT("MYSTRINGS:KEY_IOControl\n")));
return bRet;
}
KEY_API void KEY_PowerDown(DWORD hDeviceContext)
{
RETAILMSG(1,(TEXT("MYSTRINGS:KEY_PowerDown\n")));
}
KEY_API void KEY_PowerUp(DWORD hDeviceContext)
{
RETAILMSG(1,(TEXT("MYSTRINGS:KEY_PowerUp\n")));
}
KEY_API DWORD KEY_Read(DWORD hOpenContext,LPVOID pBuffer,DWORD Count)
{
DWORD dwRet=0;
RETAILMSG(1,(TEXT("MYSTRINGS:KEY_Read\n")));
return dwRet;
}
KEY_API DWORD KEY_Seek(DWORD hOpenContext,long Amount,DWORD Type)
{
DWORD dwRet=0;
RETAILMSG(1,(TEXT("MYSTRINGS:KEY_Seek\n")));
return dwRet;
}
KEY_API DWORD KEY_Write(DWORD hOpenContext,LPCVOID pSourceBytes,DWORD NumberOfBytes)
{
DWORD dwRet=0;
RETAILMSG(1,(TEXT("MYSTRINGS:KEY_Write\n")));
return dwRet;
}
//key thread
DWORD KeyThread(LPVOID lpParameter)
{
BOOL bit=0;
while(1)
{
Sleep(2000);
if(bit) //LED在线跟里亮与灭交替进行
{s2440IOP->rGPFDAT|=1<<7;
RETAILMSG(1,(TEXT("test fhg\n")));
keybd_event ('4',0,0,0);
}
else
{
s2440IOP->rGPFDAT&=~(1<<7);
RETAILMSG(1,(TEXT("kill fhg\n")));
keybd_event ('6',0,0,0);
}
bit=~bit;
}
return 0;
}
// This is the constructor of a class that has been exported.
// see KEY.h for the class definition
CKEY::CKEY()
{
return;