📄 c-periph.html
字号:
<dd><font color="0000a0"><pre class="Code"><a name="87392"></a>typedef struct usb_targ_callback_table { /* device management callbacks */ USB_TARG_MANAGEMENT_FUNC mngmtFunc; /* Control pipe callbacks */ USB_TARG_FEATURE_CLEAR_FUNC featureClear; USB_TARG_FEATURE_SET_FUNC featureSet; USB_TARG_CONFIGURATION_GET_FUNC configurationGet; USB_TARG_CONFIGURATION_SET_FUNC configurationSet; USB_TARG_DESCRIPTOR_GET_FUNC descriptorGet; USB_TARG_DESCRIPTOR_SET_FUNC descriptorSet; USB_TARG_INTERFACE_GET_FUNC interfaceGet; USB_TARG_INTERFACE_SET_FUNC interfaceSet; USB_TARG_STATUS_GET_FUNC statusGet; USB_TARG_ADDRESS_SET_FUNC addressSet; USB_TARG_SYNCH_FRAME_GET_FUNC synchFrameGet; USB_TARG_VENDOR_SPECIFIC_FUNC vendorSpecific; } USB_TARG_CALLBACK_TABLE, *pUSB_TARG_CALLBACK_TABLE; </pre></font></dl><dl class="margin"><dd><p class="Body"><a name="87393"></a>Before calling the <b class="routine">usbTargTcdAttach</b><b>( )</b> routine, the function pointers in this table should be set to point to corresponding entry points in the target application. As soon as <b class="routine">usbTargTcdAttach</b><b>( )</b> is called, <b class="library">usbTargLib</b> begins making asynchronous calls to the entry points in the callback table. (Some callbacks are immediate and occur during the attach process itself; others happen in response to activity on the USB.) The target application should provide pointers for each function whose requests need software processing. The <b class="library">usbTargLib</b> driver provides default handling for any functions whose corresponding entry in the callback table is NULL.</p><dd><p class="Body"><a name="87394"></a>The prototypes for each of these callbacks are defined in <b class="file">usbTargLib.h</b>. Two parameters are common to each of the callback functions:</p></dl><dl class="margin"><dd><font color="0000a0"><pre class="Code"><a name="87395"></a> pVOID param USB_TARG_CHANNEL targChannel </pre></font></dl><dl class="margin"><dd><div class="Item"><a name="87396"></a><i class="textVariable">param</i> </div><dl class="margin"><dd><div class="Follow"><a name="87397"></a>The application-defined parameter originally passed to <b class="library">usbTargLib</b> as part of the <b class="routine">usbTargTcdAttach</b><b>( )</b> function. Its value is not interpreted by <b class="library">usbTargLib</b>, and it can take on any meaning defined by the target application.</div><br></dl><dd><div class="Item"><a name="87398"></a><i class="textVariable">targChannel</i></div><dl class="margin"><dd><div class="Follow"><a name="87399"></a>The handle assigned to the TCD by <b class="library">usbTargLib</b> during attach processing. </div><br></dl></dl><dl class="margin"><dd><p class="Body"><a name="87400"></a>The following sections describe each callback in the callback table in more detail. </p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="87403"></a>mngmtFunc( ) Callback</i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="87404"></a>The target driver <b class="library">usbTargLib</b> invokes the target application's <b class="routine">mngmtFunc</b><b>( )</b> callback to inform the application of changes that broadly affect the USB's operation. This callback takes the following form:</p></dl><dl class="margin"><dd><font color="0000a0"><pre class="Code"><a name="87405"></a>typedef STATUS (*USB_TARG_MANAGEMENT_FUNC) ( pVOID param, USB_TARG_CHANNEL targChannel, UINT16 mngmtCode /* management code */ ); </pre></font></dl><dl class="margin"><dd><p class="Body"><a name="87406"></a>The <i class="textVariable">mngmtCode</i> parameter tells the target application what management event has happened. It takes the following values, as defined in <b class="file">usbTcd.h</b>:</p></dl><dl class="margin"><dd><font color="0000a0"><pre class="Code"><a name="87407"></a> TCD_MNGMT_ATTACH initial TCD attachment TCD_MNGMT_DETACH TCD detach TCD_MNGMT_VBUS_DETECT bus detected TCD_MNGMT_VBUS_LOST Vbus lost TCD_MNGMT_BUS_RESET bus reset TCD_MNGMT_SUSPEND suspend signaling detected TCD_MNGMT_RESUME resume signaling detected </pre></font></dl><dl class="margin"><dd><p class="Body"><a name="87408"></a>The target application can process or ignore these management codes as it sees fit. In most cases, <b class="library">usbTargLib</b> ignores the status returned by the <b class="routine">mngmtFunc</b><b>( )</b> callback. However, <b class="library">usbTargLib</b> does examine the <b class="routine">mngmtFunc</b><b>( )</b> return code in response to the <b class="symbol_UC">TCD_MNGMT_ATTACH</b> code. In this case, if the <b class="routine">mngmtFunc</b><b>( )</b> returns ERROR, TCD attachment is aborted.</p><dd><p class="Body"><a name="87409"></a>The target driver provides default handling for the <b class="routine">mngmtFunc</b><b>( )</b> callback. The default handler always returns OK.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="87411"></a>Control Pipe Request Callbacks</i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="87412"></a>The target driver <b class="library">usbTargLib</b> provides default processing for all standard requests received on the peripheral's default control pipe (endpoint #0). For each of the standard USB control requests, <b class="library">usbTargLib</b> provides some form of default processing. The following callbacks can be provided by the target application to modify default processing.</p></dl></dl><dl class="margin"><dd><font face="Helvetica, sans-serif" size="-1" class="sans"><h5 class="HU"><i><a name="87414"></a>featureClear( ) and featureSet( ) Callbacks</i></h5></font><dl class="margin"><dd><p class="Body"><a name="87415"></a>The target driver <b class="library">usbTargLib</b> invokes the target application's <b class="routine">featureClear</b><b>( )</b> and <b class="routine">featureSet</b><b>( )</b> callbacks in response to the USB <b class="symbol_UC">CLEAR_FEATURE</b> and <b class="symbol_UC">SET_FEATURE</b> requests, respectively. These callbacks take the following form:</p></dl><dl class="margin"><dd><font color="0000a0"><pre class="Code"><a name="87416"></a>typedef STATUS (*USB_TARG_FEATURE_CLEAR_FUNC) ( pVOID param, USB_TARG_CHANNEL targChannel, UINT8 requestType, UINT16 feature, UINT16 index );</pre></font><dd><font color="0000a0"><pre class="Code"><a name="87417"></a>typedef STATUS (*USB_TARG_FEATURE_SET_FUNC) ( pVOID param, USB_TARG_CHANNEL targChannel, UINT8 requestType, UINT16 feature, UINT16 index );</pre></font></dl><dl class="margin"><dd><p class="Body"><a name="87418"></a>If the target application supports these functions, it should clear or set the feature identified by the <i class="textVariable">requestType</i>, <i class="textVariable">feature</i>, and <i class="textVariable">index</i> parameters.</p><dd><p class="Body"><a name="87419"></a>If the target application does not provide these callbacks, then <b class="library">usbTargLib</b> returns an error in response to the corresponding requests. Similarly, if the callbacks return ERROR, <b class="library">usbTargLib</b> returns an error in response to the corresponding request.</p></dl><dd><font face="Helvetica, sans-serif" size="-1" class="sans"><h5 class="HU"><i><a name="87421"></a>configurationGet( ) and configurationSet( ) Callbacks</i></h5></font><dl class="margin"><dd><p class="Body"><a name="87422"></a>The target driver <b class="library">usbTargLib</b> invokes the target application's <b class="routine">configurationGet</b><b>( )</b> and <b class="routine">configurationSet</b><b>( )</b> callbacks in response to the USB <b class="symbol_UC">GET_CONFIGURATION</b> and <b class="symbol_UC">SET_CONFIGURATION</b> requests. These callbacks take the following form:</p></dl><dl class="margin"><dd><font color="0000a0"><pre class="Code"><a name="87423"></a>typedef STATUS (*USB_TARG_CONFIGURATION_GET_FUNC) ( pVOID param, USB_TARG_CHANNEL targChannel, pUINT8 pConfiguration ); typedef STATUS (*USB_TARG_CONFIGURATION_SET_FUNC) ( pVOID param, USB_TARG_CHANNEL targChannel, UINT8 configuration ); </pre></font></dl><dl class="margin"><dd><p class="Body"><a name="87424"></a>For the <b class="routine">configurationGet</b><b>( )</b> callback, the target application should fill the <i class="textVariable">pConfiguration</i> buffer with the UINT8 value identifying the current configuration; <b class="library">usbTargLib</b> transmits the response back to the USB host. For <b class="routine">configurationSet</b><b>( )</b>, the target application should set the current configuration to the value indicated by <i class="textVariable">configuration</i>.</p><dd><p class="Body"><a name="87425"></a>If the target application does not provide these callbacks, then <b class="library">usbTargLib</b> returns an error in response to the corresponding requests. Similarly, if the callbacks return ERROR, <b class="library">usbTargLib</b> returns an error in response to the corresponding request.</p></dl><dd><font face="Helvetica, sans-serif" size="-1" class="sans"><h5 class="HU"><i><a name="87427"></a>descriptorGet( ) and descriptorSet( ) Callbacks</i></h5></font><dl class="margin"><dd><p class="Body"><a name="87428"></a>The target driver <b class="library">usbTargLib</b> invokes the target application's <b class="routine">descriptorGet</b><b>( )</b> and <b class="routine">descriptorSet</b><b>( )</b> callbacks in response to the USB <b class="symbol_UC">GET_DESCRIPTOR</b> and <b class="symbol_UC">SET_DESCRIPTOR</b> requests. These callbacks take the following form:</p></dl><dl class="margin"><dd><font color="0000a0"><pre class="Code"><a name="87429"></a>typedef STATUS (*USB_TARG_DESCRIPTOR_GET_FUNC)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -