📄 c-smo4.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><link rel="STYLESHEET" type="text/css" href="wrs.css"><title> Shared-Memory Objects </title></head><body bgcolor="FFFFFF"><p class="navbar" align="right"><a href="index.html"><img border="0" alt="[Contents]" src="icons/contents.gif"></a><a href="GuideIX.html"><img border="0" alt="[Index]" src="icons/index.gif"></a><a href="c-smo.html"><img border="0" alt="[Top]" src="icons/top.gif"></a><a href="c-smo3.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="c-smo5.html"><img border="0" alt="[Next]" src="icons/next.gif"></a></p><font face="Helvetica, sans-serif" class="sans"><h3 class="H2"><i><a name="85343">6.4 Configuration</a></i></h3></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85345"> </a>To include shared-memory objects in VxWorks, select <b class="symbol_UC">INCLUDE_SM_OBJ</b> for inclusion in the project facility VxWorks view. Most of the configuration is already done automatically from <b class="routine"><i class="routine">usrSmObjInit</i></b><b>(</b> <b>)</b> in <b class="file">usrConfig.c</b>. However, you may also need to modify some values in the <b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans">Params</font></b> tab of the properties window to reflect your configuration; these are described in this section.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="85348">6.4.1 Shared-Memory Objects and Shared-Memory Network Driver</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85354"> </a>Shared-memory objects and the shared-memory network<sup><a href="#foot"><b class="FootnoteMarker">1</b></a></sup> use the same memory region, anchor address, and interrupt mechanism. Configuring the system to use shared-memory objects is similar to configuring the shared-memory network driver. For a more detailed description of configuring and using the shared-memory network, see <i class="title">VxWorks Network Programmer's Guide: Data Link Layer Network Components</i>. If the default value for the shared-memory anchor address is modified, the anchor must be on a 256-byte boundary.</p><dd><p class="Body"><a name="85355"> </a>One of the most important aspects of configuring shared-memory objects is computing the address of the shared-memory anchor. The shared-memory anchor is a location accessible to all CPUs on the system, and is used by both VxMP and the shared-memory network driver. The anchor stores a pointer to the shared-memory header, a pointer to the shared-memory packet header (used by the shared-memory network driver), and a pointer to the shared-memory object header. </p><dd><p class="Body"><a name="85357"> </a>The address of the anchor is defined in the <b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans">Params</font></b> tab of the Properties window with the constant <b class="symbol_UC">SM_ANCHOR_ADRS</b>. If the processor is booted with the shared-memory network driver, the anchor address is the same value as the boot device (<b class="symbol_lc">sm=</b><i class="textVariable">anchorAddress</i>). The shared-memory object initialization code uses the value from the boot line instead of the constant. If the shared-memory network driver is not used, modify the definition of <b class="symbol_UC">SM_ANCHOR_ADRS</b> as appropriate to reflect your system. </p><dd><p class="Body"><a name="85362"> </a>Two types of interrupts are supported and defined by <b class="symbol_UC">SM_INT_TYPE</b>: mailbox interrupts and bus interrupts (see <i class="title">VxWorks Network Programmer's Guide: Data Link Layer Network Components</i>). Mailbox interrupts (<b class="symbol_UC">SM_INT_MAILBOX</b>) are the preferred method, and bus interrupts (<b class="symbol_UC">SM_INT_BUS</b>) are the second choice. If interrupts cannot be used, a polling scheme can be employed (<b class="symbol_UC">SM_INT_NONE</b>), but this is much less efficient.</p><dd><p class="Body"><a name="85364"> </a>When a CPU initializes its shared-memory objects, it defines the interrupt type as well as three interrupt arguments. These describe how the CPU is notified of events. These values can be obtained for any attached CPU by calling <b class="routine"><i class="routine">smCpuInfoGet</i></b><b>(</b> <b>)</b>.</p><dd><p class="Body"><a name="85366"> </a>The default interrupt method for a target is defined by <b class="symbol_UC">SM_INT_TYPE</b>, <b class="symbol_UC">SM_INT_ARG1</b>,<b class="symbol_UC"> SM_INT_ARG2</b>,<b class="symbol_UC"> </b>and<b class="symbol_UC"> SM_INT_ARG3</b> on the <b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans">Params</font></b> tab.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="85367">6.4.2 Shared-Memory Region</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85369"> </a>Shared-memory objects rely on a shared-memory region that is visible to all processors. This region is used to store internal shared-memory object data structures and the shared-memory system partition.</p><dd><p class="Body"><a name="85370"> </a>The shared-memory region is usually in dual-ported RAM on the master, but it can also be located on a separate memory card. The shared-memory region address is defined when configuring the system as an offset from the shared-memory anchor address, <b class="symbol_UC">SM_ANCHOR_ADRS</b>, as shown in <a href="c-smo4.html#85378">Figure 6-3</a>. <div class="frame"><h4 class="EntityTitle"><a name="85378"><font face="Helvetica, sans-serif" size="-1" class="sans">Figure 6-3: Shared-Memory Layout</font></a></h4><dl class="margin"><div class="Anchor"><a name="85428"> </a><img class="figure" border="0" src="images/c-smoa2.gif"></div></dl></div></p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="85430">6.4.3 Initializing the Shared-Memory Objects Package</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85433"> </a>Shared-memory objects are initialized by default in<b class="routine"><i class="routine"> </i></b>the routine <b class="routine"><i class="routine">usrSmObjInit</i></b><b>(</b> <b>)</b> in <i class="textVariable">installDir</i><b class="file">/target/src/config/usrSmObj.c</b>. The configuration steps taken for the master CPU differ slightly from those taken for the slaves. </p><dd><p class="Body"><a name="85435"> </a>The address for the shared-memory pool must be defined. If the memory is off-board, the value must be calculated (see <a href="c-smo4.html#85485">Figure 6-5</a>).</p><dd><p class="Body"><a name="85443"> </a>The example configuration in <a href="c-smo4.html#85447">Figure 6-4</a> uses the shared memory in the master CPU's dual-ported RAM. On the <b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans">Params</font></b> tab of the properties window for the master,<b class="symbol_UC"> SM_OFF_BOARD</b> is FALSE and <b class="symbol_UC">SM_ANCHOR_ADRS</b> is 0x600. <b class="symbol_UC">SM_OBJ_MEM_ADRS</b> is set to <b class="symbol_UC">NONE</b>, because on-board memory is used (it is malloc'ed at run-time); <b class="symbol_UC">SM_OBJ_MEM_SIZE </b>is set to 0x20000. For the slave, the board maps the base of the VME bus to the address 0x1000000. <b class="symbol_UC">SM_OFF_BOARD</b> is TRUE<b class="symbol_UC"> </b>and the anchor address is 0x1800600. This is calculated by taking the VMEbus address (0x800000) and adding it to the anchor address (0x600). Many boards require further address translation, depending on where the board maps VME memory. In this example, the anchor address for the slave is 0x1800600, because the board maps the base of the VME bus to the address 0x1000000. <div class="frame"><h4 class="EntityTitle"><a name="85447"><font face="Helvetica, sans-serif" size="-1" class="sans">Figure 6-4: Example Configuration: Dual-Ported Memory</font></a></h4><dl class="margin"><div class="Anchor"><a name="85477"> </a><img class="figure" border="0" src="images/c-smoa3.gif"></div></dl></div></p><dd><p class="Body"><a name="85481"> </a>In the example configuration in <a href="c-smo4.html#85485">Figure 6-5</a>, the shared memory is on a separate memory board. On the <b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans">Params</font></b> tab for the master, <b class="symbol_UC">SM_OFF_BOARD</b> is TRUE, <b class="symbol_UC">SM_ANCHOR_ADRS</b> is 0x3000000, <b class="symbol_UC">SM_OBJ_MEM_ADRS</b> is set to <b class="symbol_UC">SM_ANCHOR_ADRS</b>, and <b class="symbol_UC">SM_OBJ_MEM_SIZE </b>is set to 0x100000. For the slave board, <b class="symbol_UC">SM_OFF_BOARD</b> is TRUE<b class="symbol_UC"> </b>and the anchor address is 0x2100000. This is calculated by taking the VMEbus address of the memory board (0x2000000) and adding it to the local VMEbus address (0x100000). <div class="frame"><h4 class="EntityTitle"><a name="85485"><font face="Helvetica, sans-serif" size="-1" class="sans">Figure 6-5: Example Configuration: an External Memory Board</font></a></h4><dl class="margin"><div class="Anchor"><a name="85519"> </a><img class="figure" border="0" src="images/c-smoa4.gif"></div></dl></div></p><dd><p class="Body"><a name="85520"> </a>Some additional configuration are sometimes required to make the shared memory non-cacheable, because the shared-memory pool is accessed by all processors on the backplane. By default, boards with an MMU have the MMU turned on. With the MMU on, memory that is off-board must be made non-cacheable. This is done using the data structure <b class="symbol_lc">sysPhysMemDesc </b>in <b class="file">sysLib.c</b>. This data structure must contain a virtual-to-physical mapping for the VME address space used for the shared-memory pool, and mark the memory as non-cacheable. (Most BSPs include this mapping by default.) See <a href="c-vm3.html#84391"><i class="title">7.3 Virtual Memory Configuration</i></a> in this manual for additional information. </p></dl></dl><dl class="margin"><dd><p class="table" callout><table border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td valign="top" width="40"><br><img border="0" alt="*" src="icons/caution.gif"></td><td><hr><div class="CalloutCell"><a name="86525"><b class="symbol_UC"><font face="Helvetica, sans-serif" size="-1" class="sans">CAUTION: </font></b></a>For the MC68030, if the MMU is off, data caching must be turned off globally; see the reference entry for <b class="library">cacheLib</b>.</div></td></tr><tr valign="top"><td></td><td><hr></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p callout><dl class="margin"><dd><p class="Body"><a name="85537"> </a>When shared-memory objects are initialized, the memory size as well as the maximum number of each object type must be specified. The master processor specifies the size of memory using the constant <b class="symbol_UC">SM_OBJ_MEM_SIZE</b>. Symbolic constants are used to set the maximum number of different objects. These constants are specified on the <b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans">Params</font></b> tab of the properties window. See <a href="c-smo4.html#87165">Table 6-5</a> for a list of these constants. <p class="table"><h4 class="EntityTitle"><a name="87165"><font face="Helvetica, sans-serif" size="-1" class="sans">Table 6-5: Configuration Constants for Shared-Memory Objects</font></a></h4><table border="0" cellpadding="0" cellspacing="0"><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="middle"><th rowspan="1" colspan="1"><div class="CellHeading"><b><a name="87171"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Symbolic Constant</font></b></div></th><th rowspan="1" colspan="1"><div class="CellHeadingC" align="center"><a name="87173"> </a><b><font face="Helvetica, sans-serif" size="-1" class="sans">Default Value</font></b></div></th><th rowspan="1" colspan="1"><div class="CellHeading"><b><a name="87175"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Description</font></b></div></th></tr><tr><td colspan="20"><hr class="tablerule2"></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="87178"> </a><b class="symbol_UC">SM_OBJ_MAX_TASK</b> </div></td><td colspan=1 rowspan=1><div class="CellBodyC" align="center"><a name="87180"> </a>40</div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="87182"> </a>Maximum number of tasks using shared-memory objects. </div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="87185"> </a><b class="symbol_UC">SM_OBJ_MAX_SEM</b> </div></td><td colspan=1 rowspan=1><div class="CellBodyC" align="center"><a name="87187"> </a>30</div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="87189"> </a>Maximum number of shared semaphores (counting and binary). </div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="87192"> </a><b class="symbol_UC">SM_OBJ_MAX_NAME</b> </div></td><td colspan=1 rowspan=1><div class="CellBodyC" align="center"><a name="87194"> </a>100</div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="87196"> </a>Maximum number of names in the name database. </div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="87199"> </a><b class="symbol_UC">SM_OBJ_MAX_MSG_Q</b> </div></td><td colspan=1 rowspan=1><div class="CellBodyC" align="center"><a name="87201"> </a>10</div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="87203"> </a>Maximum number of shared message queues. </div></td></tr>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -