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

📄 faqs.htm

📁 uCosII原装光盘,包括uCosII源代码和uCos移植到各种常见处理器的代码.
💻 HTM
📖 第 1 页 / 共 2 页
字号:
</strong></big><strong><big><big><br>
</big></big> <a href="#FAQ-06"><big>FAQ-05</big></a><big>: </big> </strong>
<big><strong>Are there other ports available
for 礐/OS and 礐/OS-II?</strong></big>

</p>

<p align="left"> 
<strong> <a href="#FAQ-06"><big>FAQ-06</big></a><big>: Is there a better way to
implement OSIntCtxSw() and ISRs?<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</big> </strong>
<big><font color="#0000FF">(Added 2001/01/26)</font></big>
</p>

<p align="left"> 
<big><big>
</p>

<table border="1" width="100%">
  <tr>
    <td width="100%" bgcolor="#C0C0C0"><p align="left"><big><strong>FAQ-01: My
    computer/processor 'hangs' when I run 礐/OS or 礐/OS-II!</strong></big><a name="FAQ-01"></a></td>
  </tr>
</table>

</big></big>

<p align="left"><font size="4">DOS executables for 礐/OS and 礐/OS-II are provided on the diskette. If
礐/OS (or 礐/OS-II) still hangs with the executable provided on the floppy, try to
contact me at <a href="mailto:Jean.Labrosse@uCOS-II.com">Jean.Labrosse@uCOS-II.com</a>. If
礐/OS (or 礐/OS-II) does not hang with the executable provided on the floppy then
there are two possible reasons your computer could crash:</font> </p>

<p align="left"><font size="4"><font color="#FF0000"><b>1) </b></font>You
need to look at <font face="Courier New"><strong>OSIntCtxSw</strong></font> (pages 62, 63
and 67 in the 礐/OS book or pages 200 and 201 in 礐/OS-II) which is processor and
compiler specific.&nbsp; The very first instruction in <strong><font face="Courier New">OSIntCtxSw()</font></strong>
may need some adjustment, i.e. <font face="Courier New"><strong>ADD SP,8</strong></font>.&nbsp;
If you use another processor, compiler or memory model, you may need to adjust the
constant.&nbsp;&nbsp; This section in the book will explain how to determine the 'magic
number' to add to the stack pointer.&nbsp;&nbsp;</font> </p>

<p align="left"><font size="4">The actual value depends on the compiler used and the compiler options.
&nbsp; For example, on the x86 real-mode small model, the constant can be either 4, 6, 8,
10 ...&nbsp; For the x86 real-mode, large model, the constant can be either 8, 10, 12, 14,
16 ...</font></p>

<p align="left"><font size="4"><font color="#FF0000"><b>2)</b></font> You may want to try
removing ANY (and ALL) floating-point operation.&nbsp; The sample code in
example #1 (礐/OS V1.xx and 礐/OS-II V2.00) has a floating-point operation in
the start task.&nbsp; Comment it out (by putting <font face="Courier New"><strong> #if 0</strong></font> /
<font face="Courier New"><strong> #endif</strong></font> around the <font face="Courier New"><strong>sprintf()</strong>
</font>statement) and try compiling and running the code.&nbsp; If the code
works, the crash is due to the fact that:<br>
<br>
&nbsp;&nbsp;&nbsp; a) The Borland C/C++ floating-point library is non-reentrant.<br>
&nbsp;&nbsp;&nbsp; b) 礐/OS and 礐/OS-II's task stacks need to be initialized
to perform floating-point operations in a </font><big><big> reentrant way.&nbsp; Refer to <b><font color="#FF0000">AN-1001</font></b>
for details (See <a href="app_notes.htm" tppabs="http://www.ucos-ii.com/app_notes.htm">AppNotes</a>).

</big></big>

</p>

<p align="left"><font color="#FF0000" size="4"><b>3</b></font><font size="4"><font color="#FF0000"><b>)</b></font> 
See </font><a href="#FAQ-06"><b><font color="#FF0000" size="5">FAQ-06</font></b></a><font size="4">.<br>
 </font>

</p>

<p align="left">

<a href="#TOP"><img border="0" src="back_top.gif" tppabs="http://www.ucos-ii.com/images/back_top.gif" width="67" height="30"></a><big><big> <br>
</p>

<table border="1" width="100%">
  <tr>
    <td width="100%" bgcolor="#C0C0C0"><p align="left"><big><strong>FAQ-02: Are you allowed
    to send a NULL-pointer through a Mailbox or a Queue?</strong></big><a name="FAQ-02"></a></td>
  </tr>
</table>

</big></big>

<p align="left"><font size="4">No.&nbsp; By definition, a NULL-pointer is not supposed to point to any
valid data.&nbsp; You could, however, 'fake' 礐/OS (or 礐/OS-II) into sending <font face="Courier New"><strong> NULL</strong></font>
pointers.&nbsp; You will need to 're-map' a NULL pointer to another 'invalid'
pointer.&nbsp; For example, if you want to send a <font face="Courier New"><strong> NULL</strong></font> through a message mailbox, you can
do the following:</font></p>

<p align="left"><font face="Courier New" size="2">void SenderTask (void *pdata)<br>
{<br>
&nbsp;&nbsp;&nbsp; .<br>
&nbsp;&nbsp;&nbsp; .<br>
&nbsp;&nbsp;&nbsp; if (msg == (void *)0) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* Do I want to
send a NULL pointer ?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; msg = (void *)0xFFFFFFFF;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* Yes, remap to another 'invalid' pointer */<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; OSMboxPost(Mbox, msg);<br>
&nbsp;&nbsp;&nbsp; .<br>
&nbsp;&nbsp;&nbsp; .<br>
}<br>
<br>
<br>
void ReceiverTask (void *pdata)<br>
{<br>
&nbsp;&nbsp;&nbsp; void *msg;<br>
<br>
&nbsp;&nbsp;&nbsp; .<br>
&nbsp;&nbsp;&nbsp; .<br>
&nbsp;&nbsp;&nbsp; msg = OSMboxPend(Mbox, 0, &amp;err); <br>
&nbsp;&nbsp;&nbsp; if (err == OS_NO_ERR) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (msg == (void *)0xFFFFFFFF) { /* Did I
receive a NULL pointer ? */<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; msg = (void *)0;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; .<br>
&nbsp;&nbsp;&nbsp; .<br>
}
</font></p>

<p align="left"><a href="#TOP"><img border="0" src="back_top.gif" tppabs="http://www.ucos-ii.com/images/back_top.gif" width="67" height="30"></a></p>

<big><big>

<table border="1" width="100%">
  <tr>
    <td width="100%" bgcolor="#C0C0C0"><p align="left"><big><strong>FAQ-03: Where should I
    enable the 'tick' interrupt?</strong></big><a name="FAQ-03"></a></td>
  </tr>
</table>

</big></big>

<p align="left"><font size="4">You should enable the tick interrupt AFTER you have started 礐/OS (or
礐/OS-II) in a 'startup' task as shown in the example code provided with the book. This
way, the OS is in a state ready to accept interrupts and can thus process interrupts.</font></p>

<p align="left"><a href="#TOP"><img border="0" src="back_top.gif" tppabs="http://www.ucos-ii.com/images/back_top.gif" width="67" height="30"></a></p>

<p align="left">&nbsp;</p>

<big><big>

<table border="1" width="100%">
  <tr>
    <td width="100%" bgcolor="#C0C0C0"><p align="left"><strong><big>FAQ-04: Does 礐/OS and
    礐/OS-II work with Microsoft C/C++?<a name="FAQ-04"></a></big></strong></td>
  </tr>
</table>

</big></big>

<p align="left"><font size="4">Yes, you will have to adjust the SP offset constant (see item 1)) and
disable stack checking. Others have used the Microsoft compiler without too many problems.</font></p>

<p align="left"><font size="4">See also </font><a href="#FAQ-06"><b><font color="#FF0000" size="5">FAQ-06</font></b></a><font size="4">.<br>
 </font>

</p>

<p align="left"><a href="#TOP"><img border="0" src="back_top.gif" tppabs="http://www.ucos-ii.com/images/back_top.gif" width="67" height="30"></a></p>

<p align="left">&nbsp;</p>

<big><big>

<table border="1" width="100%">
  <tr>
    <td width="100%" bgcolor="#C0C0C0"><p align="left"><strong><big>FAQ-05: Are there other
    ports available for 礐/OS and 礐/OS-II?<a name="FAQ-05"></a></big></strong></td>
  </tr>
</table>

</big></big>

<p align="left"><font size="4">There are currently a large number of ports available for 礐/OS and
礐/OS-II.&nbsp; I am planning on making a number of ports available on this WEB site as
they become available.&nbsp; <br>
<br>
A port to 礐/OS can easily be ported to 礐/OS-II in about an hour or so.&nbsp; This
assumes that you are familiar with the target processor and it's compiler.&nbsp; This
means that if a port for 礐/OS-II is not currently available but a port for 礐/OS exist
then you could modify the 礐/OS port to work with 礐/OS-II.&nbsp; Chapter 10 in the book
(礐/OS-II) describes the steps.
</font>

<p align="left"><a href="#TOP"><img border="0" src="back_top.gif" tppabs="http://www.ucos-ii.com/images/back_top.gif" width="67" height="30"></a>

<p align="left"><a href="#TOP"><br>
</a>

<big><big>

<table border="1" width="100%">
  <tr>
    <td width="100%" bgcolor="#C0C0C0"><p align="left"><strong><big>FAQ-06: Is
      there a better way to implement OSIntCtxSw() and ISRs?<a name="FAQ-06"></a></big></strong></td>
  </tr>
</table>

</big></big>
<p align="left"><font size="4">As you probably know, 礐/OS-II has a function
that is dependent on compiler options (<font face="Courier New">OSIntCtxSw()</font>)
and, the port designer HAS to adjust the Stack Pointer based on the code
generation of the compiler. </font></p>
<p align="left"><font size="4">On certain processors (e.g. 80x86) you can </font><font size="4">simply
write ISRs so that you SAVE the Stack Pointer (<font face="Courier New">SS:SP</font>
for the 80x86) into the current task's <font face="Courier New">OS_TCB</font>
after incrementing <font face="Courier New">OSIntNesting</font>.&nbsp; This way,
we save the PROPER pointer to the ISR stack frame in case we don't actually
return to the interrupted task.&nbsp; If we DO return to the interrupted task
then, there is no harm and all we did was waste a little bit of CPU time!&nbsp;
Of course, we eliminate the code at the beginning of <font face="Courier New">OSIntCtxSw()</font>
to adjust the Stack Pointer (<font face="Courier New">SP</font> for the 80x86)
and the code to save the Stack Pointer into the <font face="Courier New">OS_TCB</font>!</font></p>
<p align="left"><font size="4">The new pseudo code for an ISR and <font face="Courier New">OSIntCtxSw()</font>
is now:</font></p>
<p><font face="Courier New" size="2">MyISR:<br>
&nbsp;&nbsp;&nbsp; Save ALL registers;<br>
&nbsp;&nbsp;&nbsp; OSIntNesting++;<br>
</font><font face="Courier New">&nbsp;&nbsp; </font><font face="Courier New"><font SIZE="2">OSTCBCur-&gt;OSTCBStkPtr
= SP;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;&lt;&lt;&lt; NEW<br>
</font></font><font face="Courier New" size="2">&nbsp;&nbsp;&nbsp; /* Handle ISR
*/<br>
&nbsp;&nbsp;&nbsp; OSIntExit();<br>
&nbsp;&nbsp;&nbsp; Restore ALL registers;<br>
&nbsp;&nbsp;&nbsp; Return from Interrupt;</font></p>
<p><font face="Courier New" size="2">OSIntCtxSw:<br>
&nbsp;&nbsp;&nbsp; OSTaskSwHook();<br>
&nbsp;&nbsp;&nbsp; OSTCBCur = OSTCBHighRdy;<br>
&nbsp;&nbsp;&nbsp; SP = OSTCBHighRdy-&gt;OSTCBStkPtr;<br>
&nbsp;&nbsp;&nbsp; Restore ALL registers;<br>
&nbsp;&nbsp;&nbsp; Return from Interrupt;</font></p>
<p align="left"><font size="4">In assembly language for the 80x86 (Large model),
this becomes:</font></p>
<font SIZE="2">
<p><font face="Courier New">_MyISR PROC FAR<br>
;<br>
&nbsp;&nbsp;&nbsp; PUSHA&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
; Save interrupted task's context<br>
&nbsp;&nbsp;&nbsp; PUSH ES<br>
&nbsp;&nbsp;&nbsp; PUSH DS<br>
;<br>
&nbsp;&nbsp;&nbsp; MOV AX, SEG(_OSIntNesting)&nbsp;&nbsp;&nbsp;&nbsp; ; Reload
DS<br>
&nbsp;&nbsp;&nbsp; MOV DS, AX<br>
&nbsp;&nbsp;&nbsp; INC BYTE PTR _OSIntNesting&nbsp;&nbsp;&nbsp;&nbsp; ; Notify
uC/OS-II of ISR<br>
;<br>
&nbsp;&nbsp;&nbsp; LES BX, DWORD PTR DS:_OSTCBCur ; OSTCBCur-&gt;OSTCBStkPtr =
SS:SP<br>
&nbsp;&nbsp;&nbsp; MOV ES:[BX+2], SS<br>
&nbsp;&nbsp;&nbsp; MOV ES:[BX+0], SP<br>
&nbsp;&nbsp;&nbsp; CALL FAR PTR _MyISRHandler&nbsp;&nbsp;&nbsp;&nbsp; ; Process
the Interrupt<br>
;<br>
&nbsp;&nbsp;&nbsp; CALL FAR PTR _OSIntExit&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
; Notify uC/OS-II of end of ISR<br>
;<br>
&nbsp;&nbsp;&nbsp; POP
DS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
; Restore interrupted task's context<br>
&nbsp;&nbsp;&nbsp; POP ES<br>
&nbsp;&nbsp;&nbsp; POPA<br>
;<br>
&nbsp;&nbsp;&nbsp; IRET&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
; Return to interrupted task<br>
;<br>
_MyISR ENDP</font></p>
<p>&nbsp;</p>
<p><font face="Courier New" size="2">_OSIntCtxSw PROC FAR<br>
;<br>
&nbsp;&nbsp;&nbsp; CALL FAR PTR _OSTaskSwHook&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;
Call user defined task switch hook<br>
;<br>
&nbsp;&nbsp;&nbsp; MOV AX, WORD PTR DS:_OSTCBHighRdy+2 ; OSTCBCur = OSTCBHighRdy<br>
&nbsp;&nbsp;&nbsp; MOV DX, WORD PTR DS:_OSTCBHighRdy <br>
&nbsp;&nbsp;&nbsp; MOV WORD PTR DS:_OSTCBCur+2, AX<br>
&nbsp;&nbsp;&nbsp; MOV WORD PTR DS:_OSTCBCur, DX <br>
;<br>
&nbsp;&nbsp;&nbsp; MOV AL, BYTE PTR DS:_OSPrioHighRdy ; OSPrioCur =
OSPrioHighRdy<br>
&nbsp;&nbsp;&nbsp; MOV BYTE PTR DS:_OSPrioCur, AL<br>
;<br>
&nbsp;&nbsp;&nbsp; LES BX, DWORD PTR DS:_OSTCBHighRdy ; SS:SP = OSTCBHighRdy-&gt;OSTCBStkPtr<br>
&nbsp;&nbsp;&nbsp; MOV SS, ES:[BX+2]<br>
&nbsp;&nbsp;&nbsp; MOV SP, ES:[BX]<br>
;<br>
&nbsp;&nbsp;&nbsp; POP
DS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;
Load new task's context<br>
&nbsp;&nbsp;&nbsp; POP ES<br>
&nbsp;&nbsp;&nbsp; POPA<br>
;<br>
&nbsp;&nbsp;&nbsp; IRET&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
; Return to new task<br>
;<br>
_OSIntCtxSw ENDP</font></p>
</font>

<p align="left">&nbsp;<!--msnavigation--></td></tr><!--msnavigation--></table></body>
</html>

⌨️ 快捷键说明

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