阅读:2453回复:19
实时中断的源代码大放送!
我写了一个RTC中断的程序,很想传到网上去,只是比较大,需要的和我联系吧。
|
|
最新喜欢:peliso... |
沙发#
发布于:2002-10-11 22:36
有啥用
|
|
|
板凳#
发布于:2002-10-12 15:01
工业实时控制的很多领域都要用的呀!
|
|
地板#
发布于:2002-10-14 10:15
我想要!麻
|
|
|
地下室#
发布于:2002-10-14 16:43
能给我一份吗?
xr_wdm@msn.com |
|
|
5楼#
发布于:2002-10-14 20:50
我也要
gordonmain@163.com |
|
6楼#
发布于:2002-10-14 23:41
可以给我一份吗?
91MING@163.COM |
|
|
7楼#
发布于:2002-10-16 13:23
还有我!谢谢!
zhusqi@sohu.com |
|
|
8楼#
发布于:2002-10-16 20:30
老乔,我猜到就是你,也给我发一份。
szzy75@yahoo.com.cn |
|
9楼#
发布于:2002-10-17 15:37
给我一份,非常感谢!
zuowei8@163.net |
|
10楼#
发布于:2002-10-18 07:48
好的,我马上给大家送出去。这两天我一直忙于验收别人的产品,没有及时来,不好意思的啦!
|
|
11楼#
发布于:2002-10-18 07:50
我用的是CMOS RTC时钟中断,中断频率可以自己设定,很方便使用的。
|
|
12楼#
发布于:2002-10-18 08:02
// Irqtest - main module for VxD IRQTEST
/*************************************************************** This is a programme which can generate two pulses to stimulate the moving of the electric watch and check the pulses sent by PIC. Copyright(C) 2002-2006 QiaoZongLi,ZhouLieXing All rights reserved. Writen by QiaoZongLi,ZhouLieXing 2002.9.23 ***************************************************************/ #define DEVICE_MAIN #include \"irqtest.h\" #include\"winioctl.h\" Declare_Virtual_Device(IRQTEST) VPICD_HWInt_THUNK RTCInt_Thunk;//handler,中断Thunk IRQHANDLE RTCIRQHandle;//Handle for virtual IRQ BYTE SavedStatusRegisterA; BYTE SavedStatusRegisterB;//保存RTC设置寄存器 static DWORD TickCounter;//中断计数器 static DWORD count; HANDLE hEventToNotifyApp;//定义唤醒Ring3程序的事件句柄 PulseResult ReturnedPulse;//脉冲检查结果结构体 TPulsePara *PulsePara=NULL;//定义一个结构体指针,以存放从Ring3传递过来的脉冲参数 DWORD *PostMsghWnd;//Ring3层应用程序的hWnd HANDLE hWnd; #undef DEVICE_MAIN IrqtestVM::IrqtestVM(VMHANDLE hVM) : VVirtualMachine(hVM) {} IrqtestThread::IrqtestThread(THREADHANDLE hThread) : VThread(hThread) {} /*************************************************************** Prototype: BOOL IrqtestDevice::OnSysDynamicDeviceInit() Description: the initialization of device driver,the entry point of VxD.In the process,you should do some work about the initailization of VxD. ***************************************************************/ BOOL IrqtestDevice::OnSysDynamicDeviceInit() { VMHANDLE hVM; hVM=Get_Cur_VM_Handle(); BYTE statreg; DWORD status; DWORD RTClockFreqIndex; SetInitValues();//初始化脉冲计数运行所需要的参数 struct VPICD_IRQ_Descriptor IRQdesc; IRQdesc.VID_IRQ_Number=RTC_IRQ; IRQdesc.VID_Options=0;//保留 IRQdesc.VID_Hw_Int_Proc=(DWORD)VPICD_Thunk_HWInt(RTCInt_Handler,&RTCInt_Thunk); IRQdesc.VID_IRET_Time_Out=500; RTCIRQHandle=VPICD_Virtualize_IRQ(&IRQdesc); if(RTCIRQHandle==0) { return FALSE;//虚拟化失败 dout<<\"虚拟化失败!\"<<endl; } hEventToNotifyApp=0;//唤醒Ring3程序的事件句柄 LPT1_Pulse = 0x03;//0X03 并行控制口初始化字 _outp(LPT1_Address+2,LPT1_Pulse); //保存初始RTC状态寄存器以便退出时恢复现场 Ra=26,Rb=2 SavedStatusRegisterA=ReadCMOS(STATREG_A); SavedStatusRegisterB=ReadCMOS(STATREG_B); RTClockFreqIndex=6;//设置中断频率 1024Hz // RTClockFreqIndex=5;//设置中断频率 2048Hz statreg=(SavedStatusRegisterA&~0xf)|(RTClockFreqIndex&0xf); WriteCMOS(STATREG_A,statreg); //设置RTC状态寄存器使得status register flags to enable it to assert its IRQ statreg=ReadCMOS(STATREG_B); statreg|=ENABLE_INTERRUPT; WriteCMOS(STATREG_B,statreg); //读C状态寄存器后,所有的标志位清零 ReadCMOS(STATREG_C); TickCounter=0;//初始化中断计数器 VPICD_Physically_Unmask(RTCIRQHandle);//保证IRQ在PIC中未被屏蔽 // initialisation to preform global events if (!VEvent::initEvents()) { dout<<\"事件堆初始化失败!\"<<endl; return FALSE; } else { dout<<\"事件堆初始化成功!\"<<endl; return TRUE; } } BOOL IrqtestDevice::OnSysDynamicDeviceExit() { // Dispose of the event handle by calling VWIN32_CloseVxDHandle // this is important! if (hEventToNotifyApp) _VWIN32_CloseVxDHandle(hEventToNotifyApp); //恢复现场; // Cancel_Global_Event(hEvent); WriteCMOS(STATREG_A,SavedStatusRegisterA); WriteCMOS(STATREG_B,SavedStatusRegisterB); VPICD_Physically_Mask(RTCIRQHandle); VPICD_Force_Default_Behavior(RTCIRQHandle); return TRUE; } /*************************************************************** Prototype: DWORD IrqtestDevice::OnW32DeviceIoControl (PIOCTLPARAMS pDIOCParams) Description: Receive the Message sent by Ring3 application.In Ring3,when you call DeviceIoControl(),VMM will give vxd the message,then vxd will call the function ***************************************************************/ DWORD IrqtestDevice::OnW32DeviceIoControl(PIOCTLPARAMS pDIOCParams) { switch(pDIOCParams->dioc_IOCtlCode) { case DIOC_OPEN://CreateFile hWnd =0;//Ring 3层应用程序主窗口句柄初始化 return 0; break; case DIOC_CLOSEHANDLE: return 0; break; case 111: //消息代码: 试验启动 VPICD_Physically_Unmask(RTCIRQHandle);//保证IRQ在PIC中未被屏蔽 PulsePara=(TPulsePara *)(pDIOCParams->dioc_InBuf); hWnd=PulsePara->hWnd; // hEventToNotifyApp=PulsePara->hEventToNotifyApp;//待唤醒的Ring3事件句柄 hEventToNotifyApp=NULL;//待唤醒的Ring3事件句柄 // pDIOCParams->dioc_OutBuf=&ReturnedPulse;//返回脉冲采集存储变量的地址 // *(DWORD *)pDIOCParams->dioc_OutBuf=(DWORD)&ReturnedPulse;//返回VXD中存放数据的变量地址 m_long_width_0=PulsePara->LowLevelWidth*1024/1000; // 低电平宽度,中断频率是2048Hz m_long_width_1=PulsePara->HighLevelWidth*1024/1000; // 高电平宽度 m_int_interval=PulsePara->DelayTime*1024/1000 ;// 后到脉冲滞后 m_int_timePulseOutEnable=PulsePara->m_int_timePulseOutEnable;// 双脉冲输出允许 StopBitBtnPressed=PulsePara->StopBitBtnPressed;//判断停止按钮是否按下,以便VXD进行相应处理 StepTime=PulsePara->StepTime;// 步进时间 WhiteBlackRate=PulsePara->WhiteBlackRate;//白黑比例 DelayRate=PulsePara->DelayRate;//滞后比例 IORate=PulsePara->IORate;//I/O比例 1 or 4 //如果停止按钮按下,则全部变量清零 if(StopBitBtnPressed==TRUE) { SetInitValues();//设置脉冲参数初时值 } return 0; break; case 222: //消息代码: 试验暂停,所有变量保持不变 m_int_timePulseOutEnable=false;// 双脉冲输出允许 //向Ring3传递VXD中数据 ReturnedPulse.pulse_1a0_max=pulse_1a0_max; ReturnedPulse.pulse_1a0_min=pulse_1a0_min; ReturnedPulse.pulse_1a1_max=pulse_1a1_max; ReturnedPulse.pulse_1a1_min=pulse_1a1_min; ReturnedPulse.pulse_1a_count=pulse_1a_count; ReturnedPulse.pulse_1b0_max=pulse_1b0_max; ReturnedPulse.pulse_1b0_min=pulse_1b0_min; ReturnedPulse.pulse_1b1_max=pulse_1b1_max; ReturnedPulse.pulse_1b1_min=pulse_1b1_min; ReturnedPulse.pulse_1b_count=pulse_1b_count; ReturnedPulse.pulse_1c0_max=pulse_1c0_max; ReturnedPulse.pulse_1c0_min=pulse_1c0_min; ReturnedPulse.pulse_1c1_max=pulse_1c1_max; ReturnedPulse.pulse_1c1_min=pulse_1c1_min; ReturnedPulse.pulse_1c_count=pulse_1c_count; ReturnedPulse.pulse_2a0_max=pulse_2a0_max; ReturnedPulse.pulse_2a0_min=pulse_2a0_min; ReturnedPulse.pulse_2a1_max=pulse_2a1_max; ReturnedPulse.pulse_2a1_min=pulse_2a1_min; ReturnedPulse.pulse_2a_count=pulse_2a_count; ReturnedPulse.pulse_2b0_max=pulse_2b0_max; ReturnedPulse.pulse_2b0_min=pulse_2b0_min; ReturnedPulse.pulse_2b1_max=pulse_2b1_max; ReturnedPulse.pulse_2b1_min=pulse_2b1_min; ReturnedPulse.pulse_2b_count=pulse_2b_count; ReturnedPulse.m_long_timePulseTotal=m_long_timePulseTotal; // 双脉冲输出计数器 *(DWORD *)pDIOCParams->dioc_OutBuf=(DWORD)&ReturnedPulse;//返回VXD中存放数据的变量地址 *pDIOCParams->dioc_bytesret=sizeof(PulseResult); return 0; break; case 333: //消息代码: 试验停止,所有变量清零 VPICD_Physically_Mask(RTCIRQHandle);//屏蔽RTC中断 m_int_timePulseOutEnable=false;// 双脉冲输出允许:false hWnd=0; hEventToNotifyApp=0;//待唤醒的Ring3事件句柄 m_long_width_0=0; // 低电平宽度,中断频率是2048Hz m_long_width_1=0; // 高电平宽度 m_int_interval=0 ;// 后到脉冲滞后 m_int_timePulseOutEnable=false;// 双脉冲输出允许 StepTime=0;// 步进时间 WhiteBlackRate=0;//白黑比例 DelayRate=0;//滞后比例 IORate=1;//I/O比例 1 or 4 m_int_timePulse_B_DelayInterval=0; // 脉冲前后滞后计时器 m_long_timePulseCount=0; // 双脉冲周期计时器 m_long_timePulse_A_width=0; // 前脉冲低电平宽度计时器 m_long_timePulse_B_width=0; // 后脉冲低电平宽度计时器 m_long_timePulseTotal=0; // 双脉冲输出计数器 return 0; break; case 444: //消息代码: 试验退出时,先屏蔽RTC时钟中断,停止输出脉冲 VPICD_Physically_Mask(RTCIRQHandle); m_int_timePulseOutEnable=false;// 双脉冲输出允许:false return 0; break; case 555: //消息代码: 向Ring3发送数据 //向Ring3传递VXD中数据 ReturnedPulse.pulse_1a0_max=pulse_1a0_max; ReturnedPulse.pulse_1a0_min=pulse_1a0_min; ReturnedPulse.pulse_1a1_max=pulse_1a1_max; ReturnedPulse.pulse_1a1_min=pulse_1a1_min; ReturnedPulse.pulse_1a_count=pulse_1a_count; ReturnedPulse.pulse_1b0_max=pulse_1b0_max; ReturnedPulse.pulse_1b0_min=pulse_1b0_min; ReturnedPulse.pulse_1b1_max=pulse_1b1_max; ReturnedPulse.pulse_1b1_min=pulse_1b1_min; ReturnedPulse.pulse_1b_count=pulse_1b_count; ReturnedPulse.pulse_1c0_max=pulse_1c0_max; ReturnedPulse.pulse_1c0_min=pulse_1c0_min; ReturnedPulse.pulse_1c1_max=pulse_1c1_max; ReturnedPulse.pulse_1c1_min=pulse_1c1_min; ReturnedPulse.pulse_1c_count=pulse_1c_count; ReturnedPulse.pulse_2a0_max=pulse_2a0_max; ReturnedPulse.pulse_2a0_min=pulse_2a0_min; ReturnedPulse.pulse_2a1_max=pulse_2a1_max; ReturnedPulse.pulse_2a1_min=pulse_2a1_min; ReturnedPulse.pulse_2a_count=pulse_2a_count; ReturnedPulse.pulse_2b0_max=pulse_2b0_max; ReturnedPulse.pulse_2b0_min=pulse_2b0_min; ReturnedPulse.pulse_2b1_max=pulse_2b1_max; ReturnedPulse.pulse_2b1_min=pulse_2b1_min; ReturnedPulse.pulse_2b_count=pulse_2b_count; ReturnedPulse.m_long_timePulseTotal=m_long_timePulseTotal; // 双脉冲输出计数器 *(DWORD *)pDIOCParams->dioc_OutBuf=(DWORD)&ReturnedPulse;//返回VXD中存放数据的变量地址 *pDIOCParams->dioc_bytesret=sizeof(PulseResult); return 0; break; default: return -1; } return 0; } /********************************************************************** 设置VxD启动所需要的初时值 ***********************************************************************/ static VOID SetInitValues() { //m_old_in: 上一次端口读入状态 //m_in: 端口消抖后的稳定状态 m_in = m_old_in = _inp(LPT1_Address + 1) ^ 0x80; delay_array[ms_pulse_1a][0] = delay_array[ms_pulse_1b][0] = delay_array[ms_pulse_1c][0] = delay_array[ms_pulse_2a][0] = delay_array[ms_pulse_2b][0] = // 脉宽极值单元 pulse_1a0_min = pulse_1a1_min = pulse_1b0_min = pulse_1b1_min = pulse_1c0_min = pulse_1c1_min = pulse_2a0_min = pulse_2a1_min = pulse_2b0_min = pulse_2b1_min = 0xffff; // 消抖计时器 pulse_1a_n = pulse_1b_n = pulse_1c_n = pulse_2a_n = pulse_2b_n = pulse_1a0_max = pulse_1a1_max = pulse_1b0_max = pulse_1b1_max = pulse_1c0_max = pulse_1c1_max = pulse_2a0_max = pulse_2a1_max = pulse_2b0_max = pulse_2b1_max = 0; pulse_1a_count = pulse_1b_count = pulse_1c_count = pulse_2a_count = pulse_2b_count = 0; aa= // 最近一次端口读入状态 cc= // 端口跳变状态 pulse=0; // 暂存变量 Pulse_A=1; // 前脉冲输出位 Pulse_B=2; // 后脉冲输出位 } /********************************************************************** 双脉冲输出控制函数,按照Ring3层应用程序设定的要求产生脉冲波形,所 需要的参数由Ring3传递给VxD 在中断服务例程中,对中断计数器计数并向Ring 3层应用程序发送自定义消息; ***********************************************************************/ BOOL _stdcall RTCInt_Handler(VMHANDLE hVM,IRQHANDLE hIRQ) { //你的中断服务程序 return r; } static VOID Outportb(unsigned short int port,unsigned char value) { _asm { mov dx,port mov al,value out dx,al } } //异步事件类构造函数和服务函数 EOC_GlobalEvent::EOC_GlobalEvent() : VGlobalEvent() {} VOID EOC_GlobalEvent::handler(VMHANDLE hVM, CLIENT_STRUCT* pRegs, PVOID refData) { ; //空函数 /* if(hEventToNotifyApp) { // VWIN32_SetWin32Event(hEventToNotifyApp); // _VWIN32_SetWin32Event(hEventToNotifyApp); // dout<<\"异步事件处理函数\"<<endl; } */ } |
|
13楼#
发布于:2002-10-23 20:58
好象就是VTOOLSD里 的例子程序
我有个更简洁的, |
|
14楼#
发布于:2002-10-31 20:06
楼上的朋友,您能把您的更好的方法给大家贴出来吗?让大家都开开眼界。我是参考咱们站上的这篇文章:“
Windows 9X硬件中断设备驱动程序的开发 作者: 姜山 程君实 ”,但是把他的一些文字错误都修改了一下。 能说说您的想法吗? |
|
15楼#
发布于:2002-11-19 10:16
我写了一个RTC中断的程序,很想传到网上去,只是比较大,需要的和我联系吧。 我也想要 xyge@eastcom.com |
|
|
16楼#
发布于:2002-12-03 11:29
我也想要,我的mail是:shapi1975@sohu.com
|
|
17楼#
发布于:2002-12-03 12:12
还有我:
unix1998@sina.com |
|
18楼#
发布于:2002-12-08 18:14
我也要。
wjin99@21cn.com |
|
19楼#
发布于:2002-12-11 22:25
我也要!
谢谢 xiaodai78@sina.com 十分感谢! |
|
|