WINCE 驱动中断 相关函数详解.doc_第1页
WINCE 驱动中断 相关函数详解.doc_第2页
WINCE 驱动中断 相关函数详解.doc_第3页
WINCE 驱动中断 相关函数详解.doc_第4页
WINCE 驱动中断 相关函数详解.doc_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

/blog/static/11855667620099224530829/CreateEvent的用法HANDLE CreateEvent( LPSECURITY_ATTRIBUTES lpEventAttributes, / SD BOOL bManualReset, / reset type BOOL bInitialState, / initial state LPCTSTR lpName / object name ); 该函数创建一个Event同步对象,并返回该对象的Handle lpEventAttributes 一般为NULL bManualReset 创建的Event是自动复位还是人工复位 ,如果true,人工复位, 一旦该Event被设置为有信号,则它一直会等到ResetEvent()API被调用时才会恢复 为无信号. 如果为false,Event被设置为有信号,则当有一个wait到它的Thread时, 该Event就会自动复位,变成无信号. bInitialState 初始状态,true,有信号,false无信号 lpName Event对象名 一个Event被创建以后,可以用OpenEvent()API来获得它的Handle,用CloseHandle() 来关闭它,用SetEvent()或PulseEvent()来设置它使其有信号,用ResetEvent() 来使其无信号,用WaitForSingleObject()或WaitForMultipleObjects()来等待 其变为有信号. PulseEvent()是一个比较有意思的使用方法,正如这个API的名字,它使一个Event 对象的状态发生一次脉冲变化,从无信号变成有信号再变成无信号,而整个操作是原子的. 对自动复位的Event对象,它仅释放第一个等到该事件的thread(如果有),而对于 人工复位的Event对象,它释放所有等待的thread. kerneliocontrol()函数This function provides the kernel with a generic I/O control for carrying out I/O operations.该函数为内核提供执行IO操作的通用IO控制 Syntax BOOL KernelIoControl( DWORD dwIoControlCode, LPVOID lpInBuf, DWORD nInBufSize, LPVOID lpOutBuf, DWORD nOutBufSize, LPDWORD lpBytesReturned); Parameters参数dwIoControlCodein I/O control code, which should support the OAL I/O controls【1输入】IO控制代码,支持OAL级的IO控制IOCTL_HAL_RELEASE_SYSINTRIOCTL_HAL_REQUEST_SYSINTRIOCTL_HAL_TRANSLATE_IRQ lpInBufin Pointer to a buffer that contains the data required to perform the operation.Set to NULL if the dwIoControlCode parameter specifies an operation that does not require input data.【2输入】指向一个缓冲区,其包含执行操作所必须的数据。设置dwIOControlCode参数为NULL指定操作为不需要输入数据。nInBufSizein Size, in bytes, of the buffer pointed to by lpInBuf.【3输入】参数指定的缓冲区的大小,以字节为单位。lpOutBufout Pointer to a buffer that receives the output data for the operation.Set to NULL if the dwIoControlCode parameter specifies an operation that does not produce output data.【4输出】指向输出缓冲区,用来接收操作数据如果指定操作没有输出数据,则设置该参数为NULLnOutBufSizein Size, in bytes, of the buffer pointed to by lpOutBuf.【5输入】lpOutBuf参数指定输出缓冲区的大小,以字节为单位。lpBytesReturnedin Long pointer to a variable that receives the size, in bytes, of the data stored in the buffer pointed to by lpOutBuf. Even when an operation produces no output data, and lpOutBuf is NULL, the KernelIoControl function uses the variable pointed to by lpBytesReturned. After such an operation, the value of the variable has no meaning.【6输入】指向一个变量,该变量用于存储由lpOutBuf指向的缓冲区存储数据的大小,已字节为单位。即使一个操作没有产生输出数据,lpOutBuf是NULL,kerneliocontrol函数使用lpBytesReturned参数指向的这个变量。这中操作后,这个变量的值没有任何意义。 Return ValueTRUE indicates success. FALSE indicates failure.TRUE表示成功,FALSE表示失败。 Remarks备注An IOCTL call has this prototype:BOOL KernelIOControl(UINT32 code, VOID* pInpBuffer, UINT32 inpSize, VOID* pOutBuffer, UINT32 outSize, UINT32 *pOutSize);Assuming the caller passes a valid pOutSize pointer:1. If an IOCTL will never return data in *pOutBuffer, then set *pOutSize = 0 regardless of success or failure.如果IOCTL不返回数据,无论成功或者失败将pOutSize设为0.2. If an IOCTL caller passes in otherwise correct parameters with a buffer that is too small (as determined by examining nOutSize), we will fail with ERROR_INSUFFICIENT_BUFFER and return *pOutSize = minimum buffer size necessary for success. 不太好翻译3. If an IOCTL caller passes in correct parameters with a sufficient buffer (nOutSize = necessary size), we will return *pOutSize = # of bytes in the buffer that we actually filled upon completion (regardless of success or failure). InterruptInitialize()函数 该函数会自动调用OEMInterrupEnable() 函数,如果关联失败,从以下几个方面招原因:1,SYSINTR_XXX 的值是否映射到具体的物理IRQ。2,查看OALINTR.H文件的函数,看你自定义的中断是否在该范围内(4.2smdk2410为例)MapIrq2SysIntr(DWORD _Irq) if( _Irq=20 ) return ( SYSINTR_FIRMWARE + _Irq ); else return (0xffffffff);3,查看创建的事件是否成功,最好将IST挂起。 This function initializes a hardware interrupt with the kernel. This initialization allows the device driver to register an event and enable the interrupt. This function is callable from kernel-mode drivers and user-mode drivers.SyntaxBOOL InterruptInitialize( DWORD idInt, /SYSINTR中断号 HANDLE hEvent, /与该中断相关联的事件句柄 LPVOID pvData, /给OEMInterruptEnable函数缓冲区指针 DWORD cbData /缓冲区大小 );ParametersidIntin Interrupt identifier to be associated with this interrupt service thread (IST).hEventin Event to be signaled when the interrupt is triggered.pvDatain This parameter can be used as a pointer to a block of data that is passed to OEMInterruptEnable. The block of data can be initialization data, scratch space, and so on.cbDatain Size of data pointed to by pvData.Return ValueTRUE indicates success; FALSE indicates failure.RemarksThis function must be called before using the hEvent parameter, which provides a link between the idInt parameter and the SYSINTR value returned by an ISR.The hEvent parameter can only be used in a WaitForSingleObject call to wait for the event to be triggered by the kernel.A WaitForMultipleObjects call with hEvent will fail.If you use hEvent in a call to WaitForSingleObject before you call InterruptInitialize, InterruptInitialize will fail.RequirementsOS Versions: Windows CE 2.10 and later.Header: Pkfuncs.h.Link Library: Coredll.lib WaitForSingleObject()用法 WaitForSingleObject的用法DWORDWaitForSingleObject( HANDLE hHandle, DWORDdwMilliseconds);参数hHandle是一个事件的句柄,第二个参数dwMilliseconds是时间间隔。如果时间是有信号状态返回WAIT_OBJECT_0,如果时间超过dwMilliseconds值但时间事件还是无信号状态则返回WAIT_TIMEOUT。hHandle可以是下列对象的句柄: Change notification Console input Event Job Memory resource notification Mutex Process Semaphore Thread Waitable timerWaitForSingleObject函数用来检测hHandle事件的信号状态,当函数的执行时间超过dwMilliseconds就返回,但如果参数dwMilliseconds为INFINITE时函数将直到相应时间事件变成有信号状态才返回,否则就一直等待下去,直到WaitForSingleObject有返回直才执行后面的代码。在这里举个例子:先创建一个全局Event对象g_event: CEvent g_event;在程序中可以通过调用CEvent:SetEvent设置事件为有信号状态。下面是一个线程函数MyThreadPro()UINT CFlushDlg:MyThreadProc( LPVOID pParam ) WaitForSingleObject(g_event,INFINITE); For(;) . return 0;在这个线程函数中只有设置g_event为有信号状态时才执行下面的for循环,因为g_event是全局变量,所以我们可以在别的线程中通过g_event. SetEvent控制这个线程。还有一种用法就是我们可以通过WaitForSingleObject函数来间隔的执行一个线程函数的函数体 UINT CFlushDlg:MyThreadProc( LPVOID pParam ) while(WaitForSingleObject(g_event,MT_INTERVAL)!=WAIT_OBJECT_0) return 0;在这个线程函数中可以可以通过设置MT_INTERVAL来控制这个线程的函数体多久执行一次,当事件为无信号状态时函数体隔MT_INTERVAL执行一次,当设置事件为有信号状态时,线程就执行完毕了。 SetEvent() This function sets the state of the specified event object to signaled.BOOL SetEvent( HANDLE hEvent);ParametershEventin Handle to the event object. TheCreateEvent function returns this handle.Return ValuesNonzero indicates success. Zero indicates failure. To get extended error information, callGetLast

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论