// PACSDK_PWM.cpp : 定義 DLL 應用程式的進入點。 // #include "stdafx.h" #include "RTTimerDll.h" //#include "Winreg.h" #define TTIMEOUT 1000 #define MEMSLOT 32 #pragma data_seg ("RTSHARED") bool volatile hUartStatus=false; bool volatile Sharememory_Boolean[MEMSLOT]={0}; float volatile Sharememory_Float[8192]={0}; float volatile Sharememory_Float2[8192]={0}; DWORD volatile Sharememory_UINT32[MEMSLOT]={0}; #pragma data_seg() #pragma comment(linker, "/SECTION:RTSHARED,RWS") HANDLE HMutex[3]; HANDLE HCom0=NULL; BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch (ul_reason_for_call) { int i; case DLL_PROCESS_ATTACH: HMutex[0] = CreateMutex(NULL, FALSE, TEXT("RTT_BOOL_Protect")); HMutex[1] = CreateMutex(NULL, FALSE, TEXT("RTT_FLOAT_Protect")); HMutex[2] = CreateMutex(NULL, FALSE, TEXT("RTT_DWORD_Protect")); case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: for(i=0;i<3;i++) { CloseHandle(HMutex[i]); HMutex[i]=NULL; } break; } return TRUE; } RTT_DLL_API bool RTT_WriteBOOL(int memslot,bool bvalue) { bool bRet=true; if(memslot<0 || memslot>(MEMSLOT+1)) return false; DWORD dRet= WaitForSingleObject(HMutex[0], TTIMEOUT); Sharememory_Boolean[memslot]=bvalue; ReleaseMutex(HMutex[0]); return bRet; } RTT_DLL_API bool RTT_ReadBOOL(int memslot,bool *bvalue) { if(memslot<0 || memslot>(MEMSLOT+1)) return false; *bvalue=Sharememory_Boolean[memslot]; return true; } RTT_DLL_API bool RTT_WriteFLOAT(int memslot,float fvalue) { bool bRet=true; if(memslot<0 || memslot>(MEMSLOT+1)) return false; DWORD dRet= WaitForSingleObject(HMutex[1], TTIMEOUT); Sharememory_Float[memslot]=fvalue; ReleaseMutex(HMutex[1]); return bRet; } RTT_DLL_API bool RTT_ReadFLOAT(int memslot,float *fvalue) { if(memslot<0 || memslot>(MEMSLOT+1)) return false; *fvalue=Sharememory_Float[memslot]; return true; } RTT_DLL_API bool RTT_WriteDWORD(int memslot,DWORD dwvalue) { bool bRet=true; if(memslot<0 || memslot>(MEMSLOT+1)) return false; DWORD dRet= WaitForSingleObject(HMutex[2], INFINITE); //if(dRet==WAIT_OBJECT_0) //{ Sharememory_UINT32[memslot]=dwvalue; //} ReleaseMutex(HMutex[2]); return bRet; } RTT_DLL_API bool RTT_ReadDWORD(int memslot,DWORD *dwvalue) { if(memslot<0 || memslot>(MEMSLOT+1)) return false; //printf("%x ",Sharememory_UINT32[memslot]); *dwvalue=Sharememory_UINT32[memslot]; return true; }