📄 faqs.htm
字号:
</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>
</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. 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>.
If you use another processor, compiler or memory model, you may need to adjust the
constant. This section in the book will explain how to determine the 'magic
number' to add to the stack pointer. </font> </p>
<p align="left"><font size="4">The actual value depends on the compiler used and the compiler options.
For example, on the x86 real-mode small model, the constant can be either 4, 6, 8,
10 ... 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. The sample code in
example #1 (礐/OS V1.xx and 礐/OS-II V2.00) has a floating-point operation in
the start task. 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. If the code
works, the crash is due to the fact that:<br>
<br>
a) The Borland C/C++ floating-point library is non-reentrant.<br>
b) 礐/OS and 礐/OS-II's task stacks need to be initialized
to perform floating-point operations in a </font><big><big> reentrant way. 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. By definition, a NULL-pointer is not supposed to point to any
valid data. You could, however, 'fake' 礐/OS (or 礐/OS-II) into sending <font face="Courier New"><strong> NULL</strong></font>
pointers. You will need to 're-map' a NULL pointer to another 'invalid'
pointer. 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>
.<br>
.<br>
if (msg == (void *)0) {
/* Do I want to
send a NULL pointer ? */<br>
msg = (void *)0xFFFFFFFF;
/* Yes, remap to another 'invalid' pointer */<br>
}<br>
OSMboxPost(Mbox, msg);<br>
.<br>
.<br>
}<br>
<br>
<br>
void ReceiverTask (void *pdata)<br>
{<br>
void *msg;<br>
<br>
.<br>
.<br>
msg = OSMboxPend(Mbox, 0, &err); <br>
if (err == OS_NO_ERR) {<br>
if (msg == (void *)0xFFFFFFFF) { /* Did I
receive a NULL pointer ? */<br>
msg = (void *)0;<br>
}<br>
.<br>
.<br>
}<br>
.<br>
.<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"> </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"> </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. I am planning on making a number of ports available on this WEB site as
they become available. <br>
<br>
A port to 礐/OS can easily be ported to 礐/OS-II in about an hour or so. This
assumes that you are familiar with the target processor and it's compiler. 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. 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>. This way,
we save the PROPER pointer to the ISR stack frame in case we don't actually
return to the interrupted task. 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!
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>
Save ALL registers;<br>
OSIntNesting++;<br>
</font><font face="Courier New"> </font><font face="Courier New"><font SIZE="2">OSTCBCur->OSTCBStkPtr
= SP; <<<< NEW<br>
</font></font><font face="Courier New" size="2"> /* Handle ISR
*/<br>
OSIntExit();<br>
Restore ALL registers;<br>
Return from Interrupt;</font></p>
<p><font face="Courier New" size="2">OSIntCtxSw:<br>
OSTaskSwHook();<br>
OSTCBCur = OSTCBHighRdy;<br>
SP = OSTCBHighRdy->OSTCBStkPtr;<br>
Restore ALL registers;<br>
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>
PUSHA
; Save interrupted task's context<br>
PUSH ES<br>
PUSH DS<br>
;<br>
MOV AX, SEG(_OSIntNesting) ; Reload
DS<br>
MOV DS, AX<br>
INC BYTE PTR _OSIntNesting ; Notify
uC/OS-II of ISR<br>
;<br>
LES BX, DWORD PTR DS:_OSTCBCur ; OSTCBCur->OSTCBStkPtr =
SS:SP<br>
MOV ES:[BX+2], SS<br>
MOV ES:[BX+0], SP<br>
CALL FAR PTR _MyISRHandler ; Process
the Interrupt<br>
;<br>
CALL FAR PTR _OSIntExit
; Notify uC/OS-II of end of ISR<br>
;<br>
POP
DS
; Restore interrupted task's context<br>
POP ES<br>
POPA<br>
;<br>
IRET
; Return to interrupted task<br>
;<br>
_MyISR ENDP</font></p>
<p> </p>
<p><font face="Courier New" size="2">_OSIntCtxSw PROC FAR<br>
;<br>
CALL FAR PTR _OSTaskSwHook ;
Call user defined task switch hook<br>
;<br>
MOV AX, WORD PTR DS:_OSTCBHighRdy+2 ; OSTCBCur = OSTCBHighRdy<br>
MOV DX, WORD PTR DS:_OSTCBHighRdy <br>
MOV WORD PTR DS:_OSTCBCur+2, AX<br>
MOV WORD PTR DS:_OSTCBCur, DX <br>
;<br>
MOV AL, BYTE PTR DS:_OSPrioHighRdy ; OSPrioCur =
OSPrioHighRdy<br>
MOV BYTE PTR DS:_OSPrioCur, AL<br>
;<br>
LES BX, DWORD PTR DS:_OSTCBHighRdy ; SS:SP = OSTCBHighRdy->OSTCBStkPtr<br>
MOV SS, ES:[BX+2]<br>
MOV SP, ES:[BX]<br>
;<br>
POP
DS ;
Load new task's context<br>
POP ES<br>
POPA<br>
;<br>
IRET
; Return to new task<br>
;<br>
_OSIntCtxSw ENDP</font></p>
</font>
<p align="left"> <!--msnavigation--></td></tr><!--msnavigation--></table></body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -