莫的繁体字多少笔画:WINCE 驱动中断 相关函数详解 - MING的日志 - 网易博客
来源:百度文库 编辑:九乡新闻网 时间:2024/04/29 12:36:18
WINCE 驱动中断 相关函数详解
嵌入式Wince 2009-10-22 16:05:30 阅读356 评论0 字号:大中小 订阅
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
参数
dwIoControlCode
[in] I/O control co
【输入】IO控制代码,支持OAL级的IO控制
IOCTL_HAL_RELEASE_SYSINTR
IOCTL_HAL_REQUEST_SYSINTR
IOCTL_HAL_TRANSLATE_IRQ
lpInBuf
[in] Pointer to a buffer that contains the da
Set to NULL if the dwIoControlCode parameter specifies an operation that does not require input da
【输入】指向一个缓冲区,其包含执行操作所必须的数据。设置dwIOControlCode参数为NULL指定操作为不需要输入数据。
nInBufSize
[in] Size, in bytes, of the buffer pointed to by lpInBuf.
【输入】lpInBuf参数指定的缓冲区的大小,以字节为单位。
lpOutBuf
[out] Pointer to a buffer that receives the output da
Set to NULL if the dwIoControlCode parameter specifies an operation that does not produce output da
【输出】指向输出缓冲区,用来接收操作数据
如果指定操作没有输出数据,则设置该参数为NULL
nOutBufSize
[in] Size, in bytes, of the buffer pointed to by lpOutBuf.
【输入】lpOutBuf参数指定输出缓冲区的大小,以字节为单位。
lpBytesReturned
[in] Long pointer to a variable that receives the size, in bytes, of the da
【输入】指向一个变量,该变量用于存储由lpOutBuf指向的缓冲区存储数据的大小,已字节为单位。即使一个操作没有产生输出数据,lpOutBuf是NULL,kerneliocontrol函数使用lpBytesReturned参数指向的这个变量。这中操作后,这个变量的值没有任何意义。
Return Value
TRUE indicates success. FALSE indicates failure.
TRUE表示成功,FALSE表示失败。
Remarks
备注
An IOCTL call has this prototype:
BOOL KernelIOControl(UINT32 co
Assuming the caller passes a valid pOutSize pointer:
1. If an IOCTL will never return da
如果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.
Syntax
BOOL InterruptInitialize( DWORD idInt, HANDLE hEvent, LPVOID pvData, DWORD cbData );
Parameters
- idInt
[in] Interrupt identifier to be associated with this interrupt service thread (IST).
- hEvent
[in] Event to be signaled when the interrupt is triggered.
- pvData
[in] This parameter can be used as a pointer to a block of da
ta that is passed to OEMInterruptEnable. The block of da ta can be initialization da ta, scratch space, and so on.
- cbData
[in] Size of da
ta pointed to by pvData.
Return Value
TRUE indicates success; FALSE indicates failure.
Remarks
This 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 on
A WaitForMultipleObjects call with hEvent will fail.
If you use hEvent in a call to WaitForSingleObject before you call InterruptInitialize, InterruptInitialize will fail.
Requirements
OS Versions: Windows CE 2.10 and later.
Header: Pkfuncs.h.
Link Library: Coredll.lib
WaitForSingleObject()用法
WaitForSingleObject的用法
DWORD WaitForSingleObject(
HANDLE hHandle,
DWORD dwMilliseconds
);
参数hHandle是一个事件的句柄,第二个参数dwMilliseconds是时间间隔。如果时间是有信号状态返回WAIT_OBJECT_0,如果时间超过dwMilliseconds值但时间事件还是无信号状态则返回WAIT_TIMEOUT。
hHandle可以是下列对象的句柄:
Change notification
Console input
Event
Job
Memory resource notification
Mutex
Process
Semaphore
Thread
Waitable timer
WaitForSingleObject函数用来检测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 );
Parameters
- hEvent
- [in] Handle to the event object. The CreateEvent function returns this handle.
Return Values
Nonzero indicates success. Zero indicates failure. To get extended error information, call GetLastError.
Remarks
The state of a manual-reset event object remains signaled until it is set explicitly to the nonsignaled state by the ResetEvent function. Any number of waiting threads, or threads that subsequently begin wait operations for the specified event object by calling on
The state of an auto-reset event object remains signaled until a single waiting thread is released, at which time the system automatically sets the state to nonsignaled. If no threads are waiting, the event object's state remains signaled.
Requirements
OS Versions: Windows CE 1.0 and later.
Header: Kfuncs.h.
Link Library: Coredll.lib.
InterruptDone()函数标识中断处理完成