?? vxw_pt5.html
字號:
<!doctype html public "-//w3c//dtd html 4.0 transitional//en"><html><head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="GENERATOR" content="VIM on Unix and Win95"> <meta name="Author" content="Johan Borkhuis"> <meta name="description" content="VxWorks / Tornado II information / FAQ"> <meta name="keywords" content="VxWorks,Tornado,FAQ"> <meta name="version" content="$Id: vxw_pt5.html,v 1.34 2002/04/08 12:09:39 borkhuis Exp $"> <title>VxWorks and Tornado II FAQ</title></head><body><center><h1><strong><font size="+4">VxWorks / Tornado II FAQ</font></strong></h1></center><p><hr WIDTH="80%"><h2><a href="#5">5. VxWorks Questions</a></h2><blockquote><h3><a href="#5.1">5.1 C++ issues</a></h3></blockquote><blockquote><h3><a href="#5.2">5.2 Communication problems</a></h3></blockquote><blockquote><h3><a href="#5.3">5.3 Interrupts</a></h3></blockquote><blockquote><h3><a href="#5.4">5.4 LoadModule problems</a></h3></blockquote><blockquote><h3><a href="#5.5">5.5 pthreads</a></h3></blockquote><blockquote><h3><a href="#5.6">5.6 Reboot</a></h3></blockquote><blockquote><h3><a href="#5.7">5.7 Semaphores</a></h3></blockquote><blockquote><h3><a href="#5.8">5.8 Simulator (VxSim)</a></h3></blockquote><blockquote><h3><a href="#5.9">5.9 Task related items</a></h3></blockquote><blockquote><h3><a href="#5.10">5.10 Time related items</a></h3></blockquote><blockquote><h3><a href="#5.11">5.11 Wind Web Server related items</a></h3></blockquote><blockquote><h3><a href="#5.12">5.12 Zinc/windML related items</a></h3></blockquote><blockquote><h3><a href="#5.13">5.13 Other items</a></h3></blockquote><blockquote><h3><a href="#5.14">5.14 VxWorks AE questions</a></h3></blockquote><blockquote><h3><a href="#index">Index</a></h3></blockquote><hr WIDTH="80%"><p><h2><a NAME="5"><center>5. VxWorks Questions</center></a></h2><p><h3><a NAME="5.1"><center>5.1 C++ issues</center></a></h3><a NAME="5.1-A"></a>Q: When I download some C++ code my target crashes, even when I don't startanything.<p>A: What is probably happening is any static or global classes that you havedefined are having their constructors called. The class is actually beinginstantiated when the file is loaded into memory, thus the constructor iscalled.<br>(From: nick_nw@my-deja.com)<p><hr WIDTH="50%"><a NAME="5.1-B"></a><p>Q: What is the syntax of "taskSpawn" for spawning a method of anobject (C++) as a task.<p>A: See question <A HREF="#5.9-F">5.9-F</A>.<p><hr WIDTH="50%"><a NAME="5.1-C"></a><p>Q: How can I call a C++ function from within a C-file?<p>A: See question <A HREF="vxw_pt1.html#1.1-H">1.1-H</A>.<p><hr WIDTH="50%"><a NAME="5.1-D"></a><p>Q: What is the preferred extension for C++ files?<p>A: For C++-files you can use .C (compared to .c for C-files), .cc, .cpp or.cxx. Don't use .C (uppercase) as an extension for C++. It works ok on Unixhosts, but won't work if you develop on Windoze... for obvious reasons.<br>The ending I prefer is .cxx. Certain MS compilers don't like .cc, GCCdoesn't (or at least didn't in the past) like .cpp. Both take .cxx.<br>(From: engineer_scotty, sj@aracnet.com)<p><hr WIDTH="50%"><a NAME="5.1-E"></a><p>Q: Gotcha with C++ static constructors and GCC 2.95.x (PPC)<p>A: After several hours of debugging and pulling out my hair :), I've just found a (afaik undocumented) bug with GCC 2.95.x which may cause static constructors/destructors to NOT work when loaded onto the target using the target-based loader (the ld/loadModule) commands. Don't know if this effects the host-based shell or not.<p>Essentially, the problem is as follows: The munch script can be told to produce assembly language output (actually a bunch of __asm__ directives for the C compiler to swallow) or C output. When the latter is used, additional flags must be passed to the compiler (-fdollars-in-identifiers) to get the output of munch to compile; otherwise the presence of $ in the symbols will cause the compile to fail. For this reason, the Tornado makefiles default to using the -asm option; the assembler has no problem with dollar signs.<p>The munched file, when compiled (by either method) containts two arrays of function pointers, _ctors and _dtors; these are a NULL-terminated list of the "constructor functions" and "destructor functions" (functions, one per file that has static ctors/dtors, which call all the static ctors/dtors in the file). This seems to work fine with the 2.7.2 toolchain. But with the 2.95.x toolchain; using the assembler rather than the compiler causes a subtle change in the symbol table entry for the _ctors and _dtors symbols (one that will NOT show up with nmppc; only objdumpppc -t reveals this). The "object" bit, which I suppose didn't exist with the 2.7 binutils; is NOT set when the input to the compiler is assembly code.<p>When the output of munch is linked back in with the module; everything is fine until you try loading it on the target. For some reason; loadLib DOES NOT RECOGNIZE _ctors and _dtors as valid symbols and thus does NOT load them into the symbol table. When cplusCtors is run (either manually, or automatically if cplusXtorSet is used); it looks in the symbol table to find _ctors; cannot find it; assumes that the module has no constructors, and silently exits. (The same applies for cplusDtors and _dtors).<br>The workaround is to add the line<pre>MUNCH_FLAGS=</pre>to your makefiles. This will force munch to output C code (which must be compiled with -fdollars-in-identifiers); which will have the "object" bit set in the generated object file. loadLib will then properly generate symbol table entries for _ctors and _dtors, and all will be well.<p>Again, this affects GCC 2.95.x (using DaveK's stuff) on PowerPC. Don't know about other architectures. The 2.7.2 toolchain that ships with Tornado also seems to be unaffected.<br>(From: sj@shell1.aracnet.com, Scott Johnson)<hr WIDTH="60%"><p><h3><a NAME="5.2"><center>5.2 Communication problems</center></a></h3><a NAME="5.2-A"></a>Q: Is there any instance where msgQDelete can be blocking?<p>A: Yes, as with a lot of create and delete functions in VxWorks,<code>msgQDelete()</code> will make use of the dynamic memory management software torelease the memory that was claimed for the message queue datastructures (both the kernel's object structure and the buffer formessages in this case). <br>Since access to memory partitions is guarded by a mutex (a good idea!),it is certainly possible that any xxxCreate or xxxDelete routine couldblock. You shouldn't be using these functions in high performance blocksof code - it is generally best to keep your create and delete operationsto initialisation/shutdown regions of the code. <br>Now, in the case of message queues, an additional step is performed: thedelete function makes sure that it 'holds' all the message slots so ifthere are any messages already in the queue they will still be delivered(and your task that is trying to delete the message queue will blockuntil they are). For most people, that is the desirable behaviour sinceit makes sure that no messages are lost... <br>(From: john_94501@my-deja.com)<p><hr WIDTH="60%"><p><h3><a NAME="5.3"><center>5.3 Interrupts</center></a></h3><a NAME="5.3-A"></a>Q: In my BSP there is an intConnect, but no intDisconnect. How can I disconnect a function from a interrupt?<p>A: I have attached an "<code>intDisconnect()</code>" routine for PPC that has served mewell for many years. Just include it as an extra object when you are compilingyour kernel. It takes one argument (the interrupt vector). <blockquote><a href="intdisc.c">intdisc.c</a></blockquote><br>(From: David Abbott, abbottd@jlab.org)<p><hr WIDTH="50%"><a NAME="5.3-B"></a><p>Q: What does "workQPanic: Kernel work queue overflow" mean?<p>A: It usually means that one of your Interrupt Service Routines is notclearing the IRQ status properly, so on exiting the ISR the interrupt lineis still active and it is just called again immediately. If you can'twork out which it might help to try and get a logic analyser to look atthe interrupts that are occurring.<br>(From: Andrew Johnson, anj@aps.anl.gov)<p><hr WIDTH="50%"><a NAME="5.3-C"></a><p>Q: What does the function "__get_eh_context" do?<p>A: "__get_eh_context" is an abbreviation for "get exception handlercontext". This will be called if you have C++ code, you are executingin an objects context and you have exception handling enabled. Thecode uses the `this' pointer and can setup RTTI (run time typeidentification) and other C++ facilities.<br>You could use only Embedded C++ constructs and you will probably beok. Alternatively, don't allocate any objects, even on the stack inyour ISR. Object construction can call malloc and other routines thatyou shouldn't use. It will definitely setup an exception context sothat if an exception is thrown, the object can be deleted. <br>(From: Bill Pringlemeir, bpringlemeir@yahoo.com)<p>C++ can be used in ISRs with extreme caution, like having the ISR in aseparate module that you can build using -fno-exceptions and -fno-rtti andbeing careful not to construct any objects and watching out for temporariescaused by reference parameters and so on, but there are so many pitfallsthat my advice would be to always write such lowlevel code as ISRs and eventhe lower layers of device drivers in plain C.<br>(From: Dave Korn)<p><hr WIDTH="50%"><a NAME="5.3-D"></a><p>Q: After calling intlock it seems that the interrupts are not locked whenlooking at the interrupt control register.<p>A: Seems that people still do not understand the scope of intLock(). Itworks only for the task context that calls it. If that task blocks (orexits), then interrupts will most probably be re-enabled. If the taskonly blocked, when it resumes execution they will be locked again.<br>Why? Because the MSR (using PPC) is in the task context. You shouldnot block with interrupts locked (or, for that matter, after callingtaskLock() either). Switching to a different task, or the idle loop,will re-enable the interrupts.<br>As for the wind shell (host shell), when you execute a command there,the target agent spawns a task to call the function. So callingintLock() from the wind shell results in a task on the targetexecuting intLock() and exiting. When the task exits, the schedulerwill be invoked and when the new task is selected, its value for theMSR will be restored.<br>(From: John, john_94501@yahoo.com)<br>(Note: this is also the case on MIPS. Also when calling intEnableon MIPS the interrupt will only be enabled for the task where youcalled intEnable; Johan)<p><hr WIDTH="60%"><p><h3><a NAME="5.4"><center>5.4 LoadModule problems</center></a></h3><a NAME="5.4-A"></a><p>Q: When I try to load a module with unresolved externals the functionloadModule returns a module-ID instead of returning NULL, as described inthe manual. How do I detect if there are unresolved externals?<p>A: First set errno to 0, then execute the call to loadModule, and ifthis call returns a valid module-ID check errno again. If errno indicatesan error there probably were some unresolved externals. In this case itis better to unload the module again.<br>(From : Bob Marino, ram@mr.picker.com)<p><hr WIDTH="50%"><a NAME="5.4-B"></a><p>Q: The ld command, run from a script, is behaving differently on a UNIXand an NT box.<p>A: I've observed a difference with the behavior of startup scripts. Theld command's normal form:<pre> ld < foo</pre>worked fine with a UNIX host, but failed on NT. I eventually found thatthe terminating >CR< was being included in the file name read from thescript and passed back to the ftp server. The workaround was to use analternate form of the ld command in startup scripts:<pre> ld 1,0,"foo"</pre>This works fine with both UNIX and NT hosts.<br>(From: Jerry Hudgins, jerry@e-farm.com)<p><hr WIDTH="60%"><p><h3><a NAME="5.5"><center>5.5 pthreads</center></a></h3>(This chapter was about Network related questions. These have been moved to <a href="vxw_pt4.html">part 4</a> of this FAQ.<p><a NAME="5.5-A"></a>Q: Has anyone ported pthreads.h from Linux to VxWorks?<p>A: yeah, we've done that. The mapping from pthreads to VxWorks task_* et al.is pretty straightforward. The only thing missing is condition variables.They turned out to be kind of hard. You might also be able to useVxWorks semaphores, but we took a different approach. We used a msgQ andtaskSuspend()/taskResume(). See this file for the implementation:<A HREF="pthreads.c">pthreads.c</a><br>The rest of the implementation is very easy, so I won't bore you with thedetails.<br>(From: Craig Vanderborgh, craigv@voxware.com)<p><hr WIDTH="50%"><a NAME="5.5-B"></a><p>Q: Is there a way to implement the VxWorks API on top of pthreads, tosimulate VxWorks on a different system?<p>A: Check out<A HREF="http://www.mvista.com">http://www.mvista.com</A> - they've recentlypublished a white paper that discusses this and the problems and differencesbetween the two APIs.<br>(From: Andrew Johnson, anj@aps.anl.gov)<p><hr WIDTH="60%"><p><h3><a NAME="5.6"><center>5.6 Reboot</center></a></h3><a NAME="5.6-A"></a>Q: When I do a hard reboot the system reacts differently than when using Ctrl-X. The reason is that Ctrl-X does a reboot(0), while a hard reboot doesa reboot(2), a boot clear. How can I let Ctrl-X do a reboot(2)?<p>A: Unfortunately, the ^x functionality is hardwired to do a"reboot (BOOT_WARM_AUTOBOOT)" call when the reboot character is recognized.There isn't any way to change what type of reboot is done. Some possibleways around this (none pretty) are to:<ol TYPE=A><li>Change the sysToMonitor function that gets called as the last stepof a reboot to override the "start type" used. This function is normallyprovided in sysLib.c as part of your BSP.</li><li>Use the abort function capability of the terminal driver to do thetype of reboot you want. The abort function is normally tied to ^Cand is used to restart the "shell". If you can live without thatcapability, you could use tyAbortSet() to change the abort characterto ^X and use tyAbortFuncSet() to install a function that woulddo the proper type of reboot (i.e. call reboot(BOOT_COLD)). Youwould need to make sure OPT_ABORT option was enabled for the serialconnection.</li><li>Install your own "reboot" handler that "took over" and finished thereboot process. You could use rebootHookAdd() to put in a functionthat did what reboot does. As I remember from when I decoded theroutine it did some cache disabling and then called sysToMonitor()with the "start type" parameter. You could do those same things withyour functions; calling sysToMonitor(BOOT_COLD).</li></ol>The first option is the easiest by far.
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -