📄 c-bkend2.html
字号:
<dd><p class="Body"><a name="84719"> </a>The last parameter passed to the back-end initialization routine, <b class="symbol_lc">pbkendInfo</b>, is a pointer to a <b class="symbol_UC">BKEND_INFO</b> structure (defined in<b class="file"> </b><i class="textVariable">installDir</i><b class="file">/host/include/bkendlib.h</b>). This structure describes information related to the currently attached back end. The key item is the asynchronous notification method provided by the back end.</p></dl><dl class="margin"><dd><pre class="Code"><b><a name="84720">typedef struct bkEndInfo { int tgtBkInfoSize; /* size of this structure */ int tgtBkVersion; /* Version of BackEnd Hiword = Major; Loword = Minor*/ union { struct _pollingMethod { int bkEndPollingMethod, /* polling method used : * POLL_NONE_MODE * POLL_SELECT_MODE * POLL_BKROUTINE_MODE */ union _bkEndNotifMethod { int pollingFd; /* polling file desc for POLL_SELECT_MODE */ int (*bkEndSelectRtn)(int timeout) /* bkEnd select routine */ } BKEND_NOTIF_METHOD; } POLLING_METHOD; } INFO; } BKEND_INFO;</a></b></pre></dl><dl class="margin"><dd><p class="Body"><a name="88684"> </a>The target server initializes <b class="symbol_UC">BKEND_INFO</b> with the following values:</p><dl class="margin"><dd><pre class="Code2"><b><a name="88685">bkendinfo.tgtBkInfoSize = sizeof (bkend_info); bkendinfo.tgtBkVersion = BKEND_VERSION_2</a></b></pre></dl><dd><p class="Body"><a name="84744"> </a>The <b class="symbol_lc">tgtBkInfoSize</b> field is set by the target server to the size of its <b class="symbol_UC">BKEND_INFO</b> structure. The <b class="symbol_lc">tgtBkVersion</b> field is set to <b class="symbol_UC">BKEND_VERSION_2</b> (defined in <i class="textVariable">installDir</i><b class="file">/host/include/</b> <b class="file">bkendlib.h</b>) for the current version. The back end should check these values and reset <b class="symbol_lc">tgtBkVersion</b> if necessary.</p><dd><p class="Body"><a name="84750"> </a>During the initialization phase, the back end fills in the structure with its method of notifying the target server of asynchronous events. An excerpt from the WDB serial back-end initialization routine is as follows:</p><dl class="margin"><dd><pre class="Code2"><b><a name="84751">... pbkInfo->tgtBkVersion = BKEND_VERSION_2; /* Backend version 2 */ /* we'll provide our polling method ( on NT ) */ #ifdef WIN32 pbkInfo->INFO.POLLING_METHOD.bkEndPollingMethod = POLL_BKROUTINE_MODE; pbkInfo->INFO.POLLING_METHOD.BKEND_NOTIF_METHOD.bkEndSelectRtn = win32SerialSelect; #else /* on UNIX we give the tty file desc */ pbkInfo->INFO.POLLING_METHOD.bkEndPollingMethod = POLL_SELECT_MODE; pbkInfo->INFO.POLLING_METHOD.BKEND_NOTIF_METHOD.pollingFd = EventFd; #endif return (OK);</a></b></pre></dl></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="84771">2.2.2 Back-End Functions</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84773"> </a>After attaching and initializing the back end, the target server is able to perform actions on the connected board by calling back-end functions. The syntax of all back-end functions is similar. Functions usually take two pointers as arguments: the first points to a structure that contains parameters specifying the service input data; the second points to a structure that is filled in with the data returned by the service. One or both structure pointers may be omitted when a service requires no input or output data. Each function must return a WDB status code: either <b class="symbol_UC">WDB_OK</b> on success, or an appropriate WDB error code describing the error encountered during the service call. The complete error code list is located in the file <i class="textVariable">installDir</i><b class="file">/share/src/agents/wdb/wdb.h</b>.</p><dd><p class="Body"><a name="84774"> </a>Because the connection to the back-end interface is indirect, through a table of function pointers initialized when the back end is attached, there are no naming restrictions on back-end functions. Their scope is local to the back end, as all other modules access the back end through the function table. A complete description of the function interface is provided in the online reference material under <b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans">Tornado API Reference>Target Server Back End Interface</font></b>.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="84778">2.2.3 Event Notification</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84780"> </a>The target server not only sends requests and information to the target, it also needs feedback from the target about what is occurring there. When a target event (such as hitting a breakpoint or an exception) occurs, the target server must be notified. The back-end interface provides two notification methods, synchronous and asynchronous. The notification method is provided to the target server by the <b class="symbol_UC">BKEND_INFO</b> structure pointer. </p><dd><p class="Body"><a name="84781"> </a>Three methods can be provided:</p></dl><dl class="margin"><dd><div class="Item"><a name="84782"> </a><b class="symbol_UC">POLL_NONE_MODE</b>: </div><dl class="margin"><dd><div class="Indent"><a name="88719"> </a>No asynchronous mechanism is provided. The back end cannot handle asynchronous events. When this method is specified, no asynchronous events are sent to the target server. The target-server back-end thread uses synchronous requests to get events from the target. After each WTX request, it issues a <b class="routine"><i class="routine">bkendEventGet</i></b><b>( )</b><b class="routine"><i class="routine"> call </i></b>to get any events from the target. </div><br></dl><dd><div class="Item"><a name="84784"> </a><b class="symbol_UC">POLL_SELECT_MODE</b>: </div><dl class="margin"><dd><div class="Indent"><a name="88732"> </a>The back end provides a file descriptor which can be put into a <b class="routine"><i class="routine">select</i></b><b>( )</b> routine. When this method is specified, the thread handling the events waits on this descriptor using <b class="routine"><i class="routine">select</i></b><b>( )</b>. When this file descriptor becomes active because the emulator or target agent has written to it, the back-end thread gets the events.</div><br></dl><dd><div class="Item"><a name="84785"> </a><b class="symbol_UC">POLL_BKROUTINE_MODE</b>: </div><dl class="margin"><dd><div class="Indent"><a name="88742"> </a>The back end provides a routine which behaves like the <b class="routine"><i class="routine">select</i></b><b>( )</b> routine. When this method is specified, the back-end thread pends on the provided routine until the routine returns something positive. When this occurs, the back-end thread receives the pending events.</div><br></dl></dl><dl class="margin"><dd><p class="Body"><a name="84786"> </a>With the two asynchronous methods, the target server calls the back end <b class="routine"><i class="routine">bkendEventGet</i></b><b>( )</b><b class="routine"><i class="routine"> </i></b>function only to get the event information. Those methods are more efficient because no polling for events is required. </p><dd><p class="Body"><a name="84789"> </a>After issuing a <b class="routine"><i class="routine">bkendEventGet</i></b><b>( )</b><b class="routine"><i class="routine"> </i></b>command, the target server calls <b class="routine"><i class="routine">bkendEvtPending</i></b><b>( )</b> to see if other events are pending, and calls <b class="routine"><i class="routine">bkendEventGet</i></b><b>( )</b><b class="routine"><i class="routine"> </i></b>again if <b class="routine"><i class="routine">bkendEvtPending</i></b><b>( )</b> indicates that other events are available to be read. This method allows the target server to upload multiple target events without having to enter the select loop each time.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="84793">2.2.4 Designing a <b class="routine"><i class="routine">select</i></b>-like routine</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84795"> </a>The target server is a multi-threaded application. This allows a back end to export its own <b class="routine"><i class="routine">select-like</i></b> routine instead of being limited to a selectable file descriptor. This is particularly useful on WIN32 hosts where <b class="routine"><i class="routine">select</i></b><b>( )</b><b class="routine"><i class="routine"> </i></b>addresses only sockets and not other handles such as serial lines or files. The <b class="routine"><i class="routine">select-like</i></b> routine can be expanded to address such devices. It allows the target server back-end thread to sleep (thus not consuming CPU cycles) until events arrive. This routine must match the following prototype:</p><dl class="margin"><dd><pre class="Code2"><b><a name="84796">int bkendSelect (int timeout);</a></b></pre></dl><dd><p class="Body"><a name="84797"> </a>The timeout given by the target server is always <b class="symbol_UC">WAIT_FOREVER</b> (-1). </p><dd><p class="Body"><a name="84798"> </a>The return value should follow the following convention:</p></dl><dl class="margin"><dd><div class="Item"><a name="84799"> </a><i class="emphasis">Positive value</i> </div><dl class="margin"><dd><div class="Indent"><a name="87527"> </a>The target server has something to read. It calls the <b class="routine"><i class="routine">bkendEventGet</i></b><b>( )</b> and <b class="routine"><i class="routine">bkendEvtPending</i></b><b>( )</b> routines to purge all the pending events.</div><br></dl><dd><div class="Item"><a name="84803"> </a><i class="emphasis">0</i> </div><dl class="margin"><dd><div class="Indent"><a name="87530"> </a>Timeout, or another thread is taking the back end. The target server back-end thread waits until the actual thread dealing with the back end finishes its transaction, and pick up the resulting events afterward by calling <b class="routine"><i class="routine">bkendEvtPending</i></b><b>( )</b> and<b>( )</b><b class="routine"><i class="routine">bkendEventGet</i></b><b>( )</b>if events are pending.</div><br></dl><dd><div class="Item"><a name="84807"> </a><i class="emphasis">Negative value</i> </div><dl class="margin"><dd><div class="Indent"><a name="87531"> </a>An error occurred. The back-end thread terminates. </div><br></dl></dl><dl class="margin"><dd><p class="Body"><a name="84808"> </a>It is possible that two threads may use the back ends routines at the same time: a synchronous thread (the one servicing a WTX request), which can call all the routines given in the <b class="symbol_UC">TGT_OPS</b> structure, and the asynchronous thread (the one which is pending on the given <b class="routine"><i class="routine">select-like</i></b> routine). You will have to handle the race condition here. The simplest way is to make the back-end thread return from the <b class="routine"><i class="routine">select-like</i></b> routine with a 0 status. This causes the target server to wait until the other thread completes its transaction before asking if there are pending events.</p><dd><p class="Body"><a name="84809"> </a>For a discussion of how to inform the target server that a <b class="routine"><i class="routine">select-like</i></b> routine is used, see <a href="c-bkend2.html#84567"><i class="title">2.2.1 Attachment and Initialization</i></a>.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="84810">2.2.5 Handling Target-Board Reboots</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84812"> </a>To keep the target server synchronized with the target agent during a target reboot, the back end must call the routine <b class="routine"><i class="routine">targetServerRestart</i></b><b>( )</b>. A reboot detection mechanism is not optional, and the target server does not function properly if the back end fails to call this routine.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="84814">2.2.6 Cleaning Up the Tornado Registry</a></i></h4>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -