#include <windows.h>
#include <stdio.h>
#define MSG_TRANSMITRS232 WM_USER+0x01
HANDLE hRs232Task;
LONG hRs232TaskId;
LONG lInterruptSimTaskId=0;
HANDLE hInterruptSimTask=NULL;
LONG lDummyThreadId=0;
HANDLE hDummyThread=NULL;
//****************************************
DWORD interruptSimTask(LPVOID lpParameter) {
MSG msg;
while( GetMessage(&msg,NULL,0,0) ){
if(msg.message!=MSG_TRANSMITRS232)continue;
printf("GetMessage\n" );
printf("currenttaskId=%d\n",GetCurrentThreadId());
SuspendThread(hRs232Task);
printf("OS_EnterInterrupt\n" );
printf("transmitRS232SimTask Interrupt\n" );
printf("OS_LeaveInterrupt\n" );
ResumeThread(hRs232Task);
}
return 0;
}
//****************************************
DWORD dummyTask(LPVOID lpParameter) {
printf("Dummy still alive!\n" );
while(TRUE){
printf("Dummy still alive!\n" );
Sleep(1000);
}
return 0;
}
//****************************************
DWORD rs232Task(LPVOID lpvParameter){
Sleep(1000);
while(TRUE){
Sleep(0);
printf("Wait Message ...\n" );
PostThreadMessage(lInterruptSimTaskId,MSG_TRANSMITRS232,0,0);
printf("PostThreadMessage ok!\n" );
printf("PostThreadMessage ok!\n" );
printf("PostThreadMessage ok!\n" );
printf("PostThreadMessage ok!\n" );
printf("PostThreadMessage ok!\n" );
printf("PostThreadMessage ok!\n" );
printf("PostThreadMessage ok!\n" );
printf("PostThreadMessage ok!\n" );
printf("PostThreadMessage ok!\n" );
printf("PostThreadMessage ok!\n" );
printf("PostThreadMessage ok!\n" );
printf("PostThreadMessage ok!\n" );
printf("PostThreadMessage ok!\n" );
printf("PostThreadMessage ok!\n" );
printf("PostThreadMessage ok!\n" );
printf("PostThreadMessage ok!\n" );
printf("PostThreadMessage ok!\n" );
printf("PostThreadMessage ok!\n" );
}
return 0;
}
//****************************************
void main(void){
hInterruptSimTask = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)interruptSimTask, NULL, 0, &lInterruptSimTaskId );
hDummyThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)dummyTask, NULL, 0, &lDummyThreadId );
Sleep(2000);
hRs232Task = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)rs232Task, NULL, 0, &hRs232TaskId );
while(TRUE)Sleep(100);
}