⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 windowsce_net 420串口驱动分析(2)--jesse.htm

📁 WinCE下串口编程应用实例
💻 HTM
📖 第 1 页 / 共 5 页
字号:
                  <P class=MsoNormal><SPAN lang=EN-US><SPAN 
                  style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>DWORD<SPAN 
                  style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN><SPAN 
                  style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                  </SPAN>ShareMode;<SPAN 
                  style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                  </SPAN>// @field What Share Mode was this opened with</SPAN> 
                  </P>
                  <P class=MsoNormal><SPAN lang=EN-US><SPAN 
                  style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN><SPAN 
                  style="mso-spacerun: yes">&nbsp;</SPAN>DWORD<SPAN 
                  style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                  </SPAN>StructUsers;<SPAN 
                  style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>// @field 
                  Count of threads currently using struct.</SPAN> </P>
                  <P class=MsoNormal><SPAN lang=EN-US><SPAN 
                  style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                  </SPAN>COMM_EVENTS<SPAN 
                  style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                  </SPAN>CommEvents;<SPAN 
                  style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                  </SPAN>// @field Contains all in…. handling</SPAN> </P>
                  <P class=MsoNormal><SPAN lang=EN-US><SPAN 
                  style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; 
                  </SPAN>LIST_ENTRY<SPAN 
                  style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                  </SPAN>llist;<SPAN 
                  style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                  </SPAN>// @field Linked list of OPEN_INFOs</SPAN> </P>
                  <P class=MsoNormal><SPAN lang=EN-US><SPAN 
                  style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                  </SPAN>} HW_OPEN_INFO, *PH</SPAN> </P>
                  <P class=MsoNormal><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">结构中的第一个参数指向我们前面提到的</SPAN><SPAN 
                  lang=EN-US>HW_INDEP_INFO</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">结构,第二个参数为操作权限码,也就是</SPAN><SPAN 
                  lang=EN-US>READ/WRITE</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这类的权限。第三个参数为共享模式,以确定是否支持独占。这两个参数都是与文件系统的内容对应的。而</SPAN><SPAN 
                  lang=EN-US>CommEvent</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">则对应于本实例的事件。由于驱动架构支持多个</SPAN><SPAN 
                  lang=EN-US>OPEN</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">操作实例的存在,所以这里维护了一个链表来联系这些结构。在这里由于</SPAN><SPAN 
                  lang=EN-US>IST</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的启动可以在</SPAN><SPAN 
                  lang=EN-US>COM_Init</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN 
                  lang=EN-US>COM_Open</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中进行,还有处理器启动</SPAN><SPAN 
                  lang=EN-US>IST</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的内容。准备好</SPAN><SPAN 
                  lang=EN-US>HW_OPEN_INFO</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">结构后就可以调用</SPAN><SPAN 
                  lang=EN-US>HWOpen(PDD)</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">来进行</SPAN><SPAN 
                  lang=EN-US>PDD</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所需的</SPAN><SPAN 
                  lang=EN-US>Open</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">操作了。</SPAN><SPAN 
                  lang=EN-US>Open</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">操作完成后调用</SPAN><SPAN 
                  lang=EN-US>HWPurgeComm(PDD)</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">来处理(取消或等待)当前仍在通讯状态的任务。然后重置软件</SPAN><SPAN 
                  lang=EN-US>FIFO</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">就基本完成了</SPAN><SPAN 
                  lang=EN-US>COM_Open</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的动作了。</SPAN> 
                  </P>
                  <P class=MsoNormal><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">事实上这里主要是对所需的数据结构进行处理,对于硬件的具体操作都留给</SPAN><SPAN 
                  lang=EN-US>PDD</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">去做了,</SPAN><SPAN 
                  lang=EN-US>MDD</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所维护的仅仅是一个架构性的代码。</SPAN><SPAN 
                  lang=EN-US>Open</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">操作完成后,驱动就进入了工作状态这个时候。</SPAN> 
                  </P>
                  <P class=MsoNormal><B 
                  style="mso-bidi-font-weight: normal"><SPAN 
                  lang=EN-US><O:P>&nbsp;</O:P></SPAN></B> </P>
                  <P class=MsoNormal><B 
                  style="mso-bidi-font-weight: normal"><SPAN 
                  lang=EN-US>COM_Close<O:P></O:P></SPAN></B> </P>
                  <P class=MsoNormal><SPAN lang=EN-US>COM_Close</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">为与</SPAN><SPAN 
                  lang=EN-US>COM_Open</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">相对应的操作。这期间的目的是释放</SPAN><SPAN 
                  lang=EN-US>COM_Open</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所使用的系统资源,除此以外如果在</SPAN><SPAN 
                  lang=EN-US>COM_Open</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">期间创建了相应的</SPAN><SPAN 
                  lang=EN-US>IST</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">还需要停止该线程,在最后将该</SPAN><SPAN 
                  lang=EN-US>HW_OPEN_INFO</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">脱链。这样一来驱动状态就得以恢复。当然这期间还做了一写避免线程竞争的处理,使得代码看起来不是那么简单。</SPAN> 
                  </P>
                  <P class=MsoNormal><SPAN lang=EN-US><O:P>&nbsp;</O:P></SPAN> 
                  </P>
                  <P class=MsoNormal><B 
                  style="mso-bidi-font-weight: normal"><SPAN 
                  lang=EN-US>StartDispatchThread/StopDispatchThread<O:P></O:P></SPAN></B> 
                  </P>
                  <P class=MsoNormal><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这两个函数都不是</SPAN><SPAN 
                  lang=EN-US>Stream</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所需要的标准接口,但却是中断服务程序所需的</SPAN><SPAN 
                  lang=EN-US>IST</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">启动和关闭的手段,所以在这里顺便说一下。</SPAN> 
                  </P>
                  <P class=MsoNormal><SPAN 
                  lang=EN-US>StartDispatchThread</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">函数用于启动</SPAN><SPAN 
                  lang=EN-US>IST</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">,主要的工作为调用</SPAN><SPAN 
                  lang=EN-US>InterruptInitialize</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">将系统中断与相应的事件联系起来。并启动</SPAN><SPAN 
                  lang=EN-US>SerialDispatchThread</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">作为</SPAN><SPAN 
                  lang=EN-US>IST.</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">其中调用了叫做</SPAN><SPAN 
                  lang=EN-US> InterruptDone</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的函数,该函数会调用</SPAN><SPAN 
                  lang=EN-US>OAL</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中的</SPAN><SPAN 
                  lang=EN-US><A href="javascript:hhobj_1.Click()"><SPAN 
                  style="COLOR: windowtext; TEXT-DECORATION: none; text-underline: none">OEMInterruptDone</SPAN></A></SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">来完成中断的响应。</SPAN> 
                  </P>
                  <P class=MsoNormal><SPAN 
                  lang=EN-US>StopDispatchThread</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">用于与</SPAN><SPAN 
                  lang=EN-US>StartDispatchThread</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">相反的操作。停止的过程相对要复杂一些,该函数首先设定当前线程的优先级与分发线程相同,以便于在停止该线程的动作不会比释放内存的动作快以避免出错。停止的动作是让线程主动完成的,具体的方法是提交表示位</SPAN><SPAN 
                  lang=EN-US>KillRxThread</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">然后通过</SPAN><SPAN 
                  lang=EN-US>Sleep</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">请求调度</SPAN><SPAN 
                  lang=EN-US>,</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">待到</SPAN><SPAN 
                  lang=EN-US>IST</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">自己停止。这个时候由于</SPAN><SPAN 
                  lang=EN-US>IST</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">已经停止所以在程序的最后调用</SPAN><SPAN 
                  lang=EN-US>InterruptDisable</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">来屏蔽中断。</SPAN> 
                  </P>
                  <P class=MsoNormal><SPAN lang=EN-US><O:P>&nbsp;</O:P></SPAN> 
                  </P>
                  <P class=MsoNormal><B 
                  style="mso-bidi-font-weight: normal"><SPAN 
                  lang=EN-US><O:P>&nbsp;</O:P></SPAN></B> </P>
                  <P class=MsoNormal><B 
                  style="mso-bidi-font-weight: normal"><SPAN 
                  lang=EN-US>SerialDispatchThread/ 
                  SerialEventHandler<O:P></O:P></SPAN></B> </P>
                  <P class=MsoNormal><SPAN lang=EN-US>SerialDispatchThread/ 
                  SerialEventHandler</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">就是串口驱动的中断分发程序</SPAN><SPAN 
                  lang=EN-US>(</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">也就是</SPAN><SPAN 
                  lang=EN-US>IST</SPAN><SPAN 
                  style="FONT-FAMILY: 宋体; mso-asci

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -