30.11.2012 Views

Embedded USB Host Stack - Thesycon Systemsoftware ...

Embedded USB Host Stack - Thesycon Systemsoftware ...

Embedded USB Host Stack - Thesycon Systemsoftware ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Embedded</strong> <strong>USB</strong> <strong>Host</strong> <strong>Stack</strong><br />

for <strong>Embedded</strong> Devices<br />

Reference Manual<br />

Version: 2.10.0<br />

Date: 09 December 2011<br />

Authors: Steffen Weiss<br />

Guenter Hildebrandt<br />

<strong>Thesycon</strong> <strong>Systemsoftware</strong> & Consulting GmbH<br />

Werner-von-Siemens-Str. 2<br />

D-98693 Ilmenau<br />

Germany<br />

Tel: +49 3677 8462 0<br />

Fax: +49 3677 8462 18<br />

http://www.thesycon.de<br />

® <strong>Thesycon</strong> <strong>Systemsoftware</strong>&ConsultingGmbH


Copyright (c) 2011 by <strong>Thesycon</strong> <strong>Systemsoftware</strong> & Consulting GmbH<br />

All Rights Reserved<br />

Disclaimer<br />

The information in this document is subject to change without notice. No part of this manual<br />

may be reproduced, stored in a retrieval system, or transmitted in any form or by any means<br />

electronic or mechanical, including photocopying and recording for any purpose other than the<br />

purchaser’s personal use, without prior written permission from <strong>Thesycon</strong> <strong>Systemsoftware</strong> & Consulting<br />

GmbH. The software described in this document is furnished under the software license<br />

agreement distributed with the product. The software may be used or copied only in accordance<br />

with the terms of the license.<br />

Trademarks<br />

The following trade names are referenced within this manual:<br />

Microsoft, Windows, Win32, Windows NT, Windows XP, and Visual C++ are either trademarks<br />

or registered trademarks of Microsoft Corporation.<br />

Other brand and product names are trademarks or registered trademarks of their respective holders.<br />

<strong>USB</strong> Bus Driver Reference Manual 3


Contents<br />

Contents<br />

Table of contents 14<br />

1 Introduction 17<br />

2 Overview 18<br />

2.1 Features of the <strong>Embedded</strong> <strong>USB</strong> <strong>Host</strong> <strong>Stack</strong> . . . . . . . . . . . . . . . . . . . . 18<br />

2.2 Features of the <strong>USB</strong> Bus Driver . . . . . . . . . . . . . . . . . . . . . . . . . . 18<br />

2.3 Supported <strong>Host</strong> Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19<br />

2.4 Supported Platforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19<br />

3 Architecture 20<br />

3.1 Register Abstraction Layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21<br />

3.2 <strong>Thesycon</strong> Abstraction Layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22<br />

3.3 <strong>USB</strong> Bus Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23<br />

3.3.1 <strong>USB</strong> Bus Driver Core . . . . . . . . . . . . . . . . . . . . . . . . . . . 23<br />

3.3.2 <strong>USB</strong> <strong>Host</strong> Controller Driver . . . . . . . . . . . . . . . . . . . . . . . . 24<br />

3.4 <strong>USB</strong> Class Drivers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24<br />

4 Configuration 25<br />

4.1 Compile Time Configuration - <strong>USB</strong> Bus Driver . . . . . . . . . . . . . . . . . . 25<br />

5 Usage 26<br />

5.1 Initial Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26<br />

5.2 Debug Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26<br />

5.2.1 Trace Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27<br />

5.2.2 Assert Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27<br />

5.2.3 Configuration of Traces . . . . . . . . . . . . . . . . . . . . . . . . . . 27<br />

5.3 Memory Abstraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29<br />

5.4 Enumeration of <strong>USB</strong> devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30<br />

5.5 <strong>USB</strong> Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30<br />

5.6 Additional Device Information . . . . . . . . . . . . . . . . . . . . . . . . . . . 30<br />

5.7 Data Transfer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31<br />

5.8 Closing the Handles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31<br />

5.9 External Hub Support1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31<br />

5.10 Synchronization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31<br />

<strong>USB</strong> Bus Driver Reference Manual 5


Contents<br />

5.11 Callbacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32<br />

6 Management Reference 33<br />

6.1 <strong>USB</strong> Bus Driver Core . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33<br />

<strong>USB</strong>H_Init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33<br />

<strong>USB</strong>H_Exit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34<br />

<strong>USB</strong>H_ServiceISR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35<br />

<strong>USB</strong>H_ProcessInterrupt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36<br />

<strong>USB</strong>H_Remove<strong>Host</strong>Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . 37<br />

<strong>USB</strong>H_EnumerateDevices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38<br />

7 <strong>Host</strong> Controller Creation Reference 39<br />

7.1 Open <strong>Host</strong> Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39<br />

<strong>USB</strong>H_CreateOhcController . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39<br />

<strong>USB</strong>H_CreateEhcController . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40<br />

8 <strong>USB</strong> Bus Driver Reference 41<br />

8.1 Application programming interface . . . . . . . . . . . . . . . . . . . . . . . . . 41<br />

<strong>USB</strong>H_CreateInterfaceList . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41<br />

<strong>USB</strong>H_DestroyInterfaceList . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42<br />

<strong>USB</strong>H_GetInterfaceID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43<br />

<strong>USB</strong>H_GetInterfaceInfo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44<br />

<strong>USB</strong>H_WaitForIdle<strong>Stack</strong> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45<br />

<strong>USB</strong>H_PnpNotification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46<br />

<strong>USB</strong>H_RegisterPnPNotification . . . . . . . . . . . . . . . . . . . . . . . . . . 47<br />

<strong>USB</strong>H_UnregisterPnPNotification . . . . . . . . . . . . . . . . . . . . . . . . . 48<br />

<strong>USB</strong>H_EnumErrorNotification . . . . . . . . . . . . . . . . . . . . . . . . . . . 49<br />

<strong>USB</strong>H_RegisterEnumErrorNotification . . . . . . . . . . . . . . . . . . . . . . 50<br />

<strong>USB</strong>H_UnregisterEnumErrorNotification . . . . . . . . . . . . . . . . . . . . . 51<br />

<strong>USB</strong>H_RestartEnumError . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52<br />

<strong>USB</strong>H_OpenInterface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53<br />

<strong>USB</strong>H_CloseInterface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54<br />

<strong>USB</strong>H_GetDeviceDescriptor . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55<br />

<strong>USB</strong>H_GetCurrentConfigurationDescriptor . . . . . . . . . . . . . . . . . . . . 56<br />

<strong>USB</strong>H_GetInterfaceDescriptor . . . . . . . . . . . . . . . . . . . . . . . . . . . 58<br />

<strong>USB</strong>H_GetClassDescriptor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60<br />

6 <strong>USB</strong> Bus Driver Reference Manual


Contents<br />

<strong>USB</strong>H_GetEndpointDescriptor . . . . . . . . . . . . . . . . . . . . . . . . . . . 62<br />

<strong>USB</strong>H_GetSerialNumber . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64<br />

<strong>USB</strong>H_GetSpeed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66<br />

<strong>USB</strong>H_GetFrameNumber . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67<br />

<strong>USB</strong>H_GetInterfaceIDByHandle . . . . . . . . . . . . . . . . . . . . . . . . . . 68<br />

<strong>USB</strong>H_GetHubPortHandlebyInterface . . . . . . . . . . . . . . . . . . . . . . . 69<br />

<strong>USB</strong>H_GetHubPortHandlebyTopology . . . . . . . . . . . . . . . . . . . . . . . 70<br />

<strong>USB</strong>H_SetPortPowerState . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71<br />

<strong>USB</strong>H_GetPortPowerState . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72<br />

URB_COMPLETION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73<br />

<strong>USB</strong>H_SubmitUrb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74<br />

<strong>USB</strong>H_GetStatusStr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75<br />

<strong>USB</strong>H_AbortEndpointAndWait . . . . . . . . . . . . . . . . . . . . . . . . . . 76<br />

<strong>USB</strong>H_SubmitUrbAndWait . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78<br />

<strong>USB</strong>H_ResetEndpointAndWait . . . . . . . . . . . . . . . . . . . . . . . . . . . 80<br />

<strong>USB</strong>H_ResetDeviceAndWait . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82<br />

<strong>USB</strong>H_SetConfigurationAndWait . . . . . . . . . . . . . . . . . . . . . . . . . 84<br />

<strong>USB</strong>H_SetInterfaceAndWait . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86<br />

<strong>USB</strong>H_SetupRequestAndWait . . . . . . . . . . . . . . . . . . . . . . . . . . . 88<br />

8.2 Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90<br />

<strong>USB</strong>H_INTERFACE_MASK . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90<br />

<strong>USB</strong>H_INTERFACE_INFO . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92<br />

<strong>USB</strong>H_ENUM_ERROR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94<br />

<strong>USB</strong>H_EP_MASK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96<br />

URB_CONTROL_REQUEST . . . . . . . . . . . . . . . . . . . . . . . . . . . 98<br />

URB_BULK_INT_REQUEST . . . . . . . . . . . . . . . . . . . . . . . . . . . 100<br />

URB_ISO_FRAME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101<br />

URB_ISO_REQUEST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102<br />

URB_ENDPOINT_REQUEST . . . . . . . . . . . . . . . . . . . . . . . . . . . 104<br />

URB_SET_CONFIGURATION . . . . . . . . . . . . . . . . . . . . . . . . . . 105<br />

URB_SET_INTERFACE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106<br />

URB_SET_SUSPEND_STATE . . . . . . . . . . . . . . . . . . . . . . . . . . . 107<br />

URB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108<br />

<strong>USB</strong>H_PNP_NOTIFICATION . . . . . . . . . . . . . . . . . . . . . . . . . . . 110<br />

URB_HEADER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111<br />

<strong>USB</strong> Bus Driver Reference Manual 7


Contents<br />

<strong>USB</strong>H_SPEED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113<br />

<strong>USB</strong>H_PNP_EVENT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114<br />

<strong>USB</strong>H_POWER_STATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115<br />

URB_FUNCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116<br />

<strong>USB</strong>H_SUSPEND_STATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119<br />

8.3 Status Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120<br />

8.4 Status Codes Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121<br />

<strong>USB</strong>H_STATUS_SUCCESS (0x0000L) . . . . . . . . . . . . . . . . . . . . 121<br />

<strong>USB</strong>H_STATUS_CRC (0x0001L) . . . . . . . . . . . . . . . . . . . . . . . 121<br />

<strong>USB</strong>H_STATUS_BITSTUFFING (0x0002L) . . . . . . . . . . . . . . . . . 121<br />

<strong>USB</strong>H_STATUS_DATATOGGLE (0x0003L) . . . . . . . . . . . . . . . . . 121<br />

<strong>USB</strong>H_STATUS_STALL (0x0004L) . . . . . . . . . . . . . . . . . . . . . . 121<br />

<strong>USB</strong>H_STATUS_NOTRESPONDING (0x0005L) . . . . . . . . . . . . . . . 121<br />

<strong>USB</strong>H_STATUS_PID_CHECK (0x0006L) . . . . . . . . . . . . . . . . . . . 121<br />

<strong>USB</strong>H_STATUS_UNEXPECTED_PID (0x0007L) . . . . . . . . . . . . . . 121<br />

<strong>USB</strong>H_STATUS_DATA_OVERRUN (0x0008L) . . . . . . . . . . . . . . . . 121<br />

<strong>USB</strong>H_STATUS_DATA_UNDERRUN (0x0009L) . . . . . . . . . . . . . . . 122<br />

<strong>USB</strong>H_STATUS_BUFFER_OVERRUN (0x000CL) . . . . . . . . . . . . . . 122<br />

<strong>USB</strong>H_STATUS_BUFFER_UNDERRUN (0x000DL) . . . . . . . . . . . . . 122<br />

<strong>USB</strong>H_STATUS_NOT_ACCESSED (0x000FL) . . . . . . . . . . . . . . . . 122<br />

<strong>USB</strong>H_STATUS_ERROR (0x0101L) . . . . . . . . . . . . . . . . . . . . . . 122<br />

<strong>USB</strong>H_STATUS_BUFFER_OVERFLOW (0x0102L) . . . . . . . . . . . . . 122<br />

<strong>USB</strong>H_STATUS_INVALID_PARAM (0x0103L) . . . . . . . . . . . . . . . 122<br />

<strong>USB</strong>H_STATUS_PENDING (0x0104L) . . . . . . . . . . . . . . . . . . . . 122<br />

<strong>USB</strong>H_STATUS_DEVICE_REMOVED (0x0105L) . . . . . . . . . . . . . . 123<br />

<strong>USB</strong>H_STATUS_CANCELED (0x0106L) . . . . . . . . . . . . . . . . . . . 123<br />

<strong>USB</strong>H_STATUS_BUSY (0x0109L) . . . . . . . . . . . . . . . . . . . . . . 123<br />

<strong>USB</strong>H_STATUS_INVALID_DESCRIPTOR (0x0110L) . . . . . . . . . . . . 123<br />

<strong>USB</strong>H_STATUS_ENDPOINT_HALTED (0x0111L) . . . . . . . . . . . . . 123<br />

<strong>USB</strong>H_STATUS_TIMEOUT (0x0112L) . . . . . . . . . . . . . . . . . . . . 123<br />

<strong>USB</strong>H_STATUS_PORT (0x0113L) . . . . . . . . . . . . . . . . . . . . . . . 123<br />

<strong>USB</strong>H_POWER_SWITCHING_NOT_SUPPORTED (0x0114L) . . . . . . . 123<br />

<strong>USB</strong>H_STATUS_INVALID_ALIGNMENT (0x0115L) . . . . . . . . . . . . 124<br />

<strong>USB</strong>H_STATUS_NO_MEMORY (0x0116L) . . . . . . . . . . . . . . . . . 124<br />

<strong>USB</strong>H_STATUS_NO_RESOURCES (0x0117L) . . . . . . . . . . . . . . . . 124<br />

8 <strong>USB</strong> Bus Driver Reference Manual


Contents<br />

<strong>USB</strong>H_STATUS_USER (0x8000L) . . . . . . . . . . . . . . . . . . . . . . . 124<br />

9 Register Access Abstraction Layer 125<br />

9.1 Open <strong>Host</strong> Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125<br />

HcohcWriteReg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125<br />

HcohcReadReg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126<br />

10 Abstraction Layer Reference 127<br />

10.1 API Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127<br />

10.2 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127<br />

10.3 Initialization and Deinitialization . . . . . . . . . . . . . . . . . . . . . . . . . . 128<br />

TAL_Init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128<br />

TAL_Exit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129<br />

10.4 Dynamically Memory Allocation . . . . . . . . . . . . . . . . . . . . . . . . . . 130<br />

TAL_Malloc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130<br />

TAL_Free . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131<br />

10.5 Descriptor Memory Allocation . . . . . . . . . . . . . . . . . . . . . . . . . . . 132<br />

TAL_AllocateDmaDescMemory . . . . . . . . . . . . . . . . . . . . . . . . . . 132<br />

TAL_FreeDmaDescMemory . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133<br />

10.6 DMA Memory Allocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134<br />

TAL_GetCacheLineSize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134<br />

TAL_AllocateDmaMemory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135<br />

TAL_FreeDmaMemory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136<br />

TAL_InvalidateCache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137<br />

TAL_FlushCache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138<br />

TAL_WriteSync . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139<br />

TAL_BuildDmaMd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140<br />

10.7 Timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141<br />

TAL_TimerCallbackRoutine . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141<br />

TAL_AllocTimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142<br />

TAL_FreeTimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143<br />

TAL_StartTimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144<br />

TAL_CancelTimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145<br />

TAL_GetTime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146<br />

TAL_Sleep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147<br />

10.8 Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148<br />

<strong>USB</strong> Bus Driver Reference Manual 9


Contents<br />

TAL_AllocEvent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148<br />

TAL_FreeEvent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149<br />

TAL_SetEvent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150<br />

TAL_ResetEvent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151<br />

TAL_WaitEvent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152<br />

10.9 Mutex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153<br />

TAL_AllocMutex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153<br />

TAL_FreeMutex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154<br />

TAL_EnterMutex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155<br />

TAL_LeaveMutex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156<br />

10.10Task . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157<br />

TAL_CreateTask . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157<br />

TAL_DeleteTask . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158<br />

TAL_WaitTask . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159<br />

10.11Data Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160<br />

TAL_MD_HEADER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160<br />

TAL_MD_PAGE_ENTRY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161<br />

TAL_MD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162<br />

TAL_TIMER_HANDLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163<br />

11 CDC/ACM Class Driver Reference 164<br />

11.1 Application programming interface . . . . . . . . . . . . . . . . . . . . . . . . . 164<br />

HCLS_ACM_Init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164<br />

HCLS_ACM_Exit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165<br />

HCLS_ACM_DeviceConnected . . . . . . . . . . . . . . . . . . . . . . . . . . 166<br />

HCLS_ACM_RegisterConnectHandler . . . . . . . . . . . . . . . . . . . . . . . 167<br />

HCLS_ACM_CreateInterfaceList . . . . . . . . . . . . . . . . . . . . . . . . . 168<br />

HCLS_ACM_DestroyInterfaceList . . . . . . . . . . . . . . . . . . . . . . . . . 169<br />

HCLS_ACM_GetInterfaceID . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170<br />

HCLS_ACM_GetInterfaceInfo . . . . . . . . . . . . . . . . . . . . . . . . . . . 171<br />

HCLS_ACM_DeviceRemoved . . . . . . . . . . . . . . . . . . . . . . . . . . . 172<br />

HCLS_ACM_Open . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173<br />

HCLS_ACM_Close . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175<br />

HCLS_ACM_IsDevicePresent . . . . . . . . . . . . . . . . . . . . . . . . . . . 176<br />

HCLS_ACM_GetDeviceStatus . . . . . . . . . . . . . . . . . . . . . . . . . . . 177<br />

10 <strong>USB</strong> Bus Driver Reference Manual


Contents<br />

HCLS_ACM_DeviceStatusChanged . . . . . . . . . . . . . . . . . . . . . . . . 179<br />

HCLS_ACM_RegisterStatusChangeHandler . . . . . . . . . . . . . . . . . . . . 180<br />

HCLS_ACM_SetLineCoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181<br />

HCLS_ACM_SetControlLineState . . . . . . . . . . . . . . . . . . . . . . . . . 182<br />

HCLS_ACM_SendBreak . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183<br />

HCLS_ACM_GetWriteFifoSize . . . . . . . . . . . . . . . . . . . . . . . . . . 184<br />

HCLS_ACM_Write . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185<br />

HCLS_ACM_AbortWrite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187<br />

HCLS_ACM_ResetWritePipe . . . . . . . . . . . . . . . . . . . . . . . . . . . 188<br />

HCLS_ACM_GetReadFifoSize . . . . . . . . . . . . . . . . . . . . . . . . . . . 189<br />

HCLS_ACM_Read . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190<br />

HCLS_ACM_AbortRead . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192<br />

HCLS_ACM_ResetReadPipe . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193<br />

11.2 Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194<br />

HCLS_ACM_LineCoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194<br />

12 HID Class Driver Reference 196<br />

12.1 Application programming interface . . . . . . . . . . . . . . . . . . . . . . . . . 196<br />

HCLS_HID_Init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196<br />

HCLS_HID_Exit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197<br />

HCLS_HID_DeviceConnected . . . . . . . . . . . . . . . . . . . . . . . . . . . 198<br />

HCLS_HID_RegisterConnectHandler . . . . . . . . . . . . . . . . . . . . . . . 199<br />

HCLS_HID_CreateInterfaceList . . . . . . . . . . . . . . . . . . . . . . . . . . 200<br />

HCLS_HID_DestroyInterfaceList . . . . . . . . . . . . . . . . . . . . . . . . . 201<br />

HCLS_HID_GetInterfaceID . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202<br />

HCLS_HID_GetInterfaceInfo . . . . . . . . . . . . . . . . . . . . . . . . . . . 203<br />

HCLS_HID_DeviceRemoved . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204<br />

HCLS_HID_Open . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205<br />

HCLS_HID_Close . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207<br />

HCLS_HID_IsDevicePresent . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208<br />

HCLS_HID_GetHidDescriptor . . . . . . . . . . . . . . . . . . . . . . . . . . . 209<br />

HCLS_HID_GetNumDescriptors . . . . . . . . . . . . . . . . . . . . . . . . . . 210<br />

HCLS_HID_GetReportDescriptorSize . . . . . . . . . . . . . . . . . . . . . . . 211<br />

HCLS_HID_GetReportDescriptor . . . . . . . . . . . . . . . . . . . . . . . . . 212<br />

HCLS_HID_GetReportRequest . . . . . . . . . . . . . . . . . . . . . . . . . . 214<br />

<strong>USB</strong> Bus Driver Reference Manual 11


Contents<br />

HCLS_HID_SetReportRequest . . . . . . . . . . . . . . . . . . . . . . . . . . . 216<br />

HCLS_HID_GetProtocolRequest . . . . . . . . . . . . . . . . . . . . . . . . . . 218<br />

HCLS_HID_SetProtocolRequest . . . . . . . . . . . . . . . . . . . . . . . . . . 219<br />

HCLS_HID_GetIdleRequest . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220<br />

HCLS_HID_SetIdleRequest . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221<br />

HCLS_HID_GetWriteFifoSize . . . . . . . . . . . . . . . . . . . . . . . . . . . 222<br />

HCLS_HID_GetReadFifoSize . . . . . . . . . . . . . . . . . . . . . . . . . . . 223<br />

HCLS_HID_WriteReport . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224<br />

HCLS_HID_AbortWrite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226<br />

HCLS_HID_ResetWritePipe . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227<br />

HCLS_HID_ReadReport . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228<br />

HCLS_HID_AbortRead . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230<br />

HCLS_HID_ResetReadPipe . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231<br />

13 Printer Class Driver Reference 232<br />

13.1 Application programming interface . . . . . . . . . . . . . . . . . . . . . . . . . 232<br />

HCLS_PRN_Init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232<br />

HCLS_PRN_Exit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233<br />

HCLS_PRN_PrinterConnected . . . . . . . . . . . . . . . . . . . . . . . . . . . 234<br />

HCLS_PRN_RegisterConnectHandler . . . . . . . . . . . . . . . . . . . . . . . 235<br />

HCLS_PRN_CreateInterfaceList . . . . . . . . . . . . . . . . . . . . . . . . . . 236<br />

HCLS_PRN_DestroyInterfaceList . . . . . . . . . . . . . . . . . . . . . . . . . 237<br />

HCLS_PRN_GetInterfaceID . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238<br />

HCLS_PRN_GetInterfaceInfo . . . . . . . . . . . . . . . . . . . . . . . . . . . 239<br />

HCLS_PRN_PrinterRemove . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240<br />

HCLS_PRN_Open . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241<br />

HCLS_PRN_Close . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243<br />

HCLS_PRN_IsPrinterPresent . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244<br />

HCLS_PRN_GetAvailableInterfaces . . . . . . . . . . . . . . . . . . . . . . . . 245<br />

HCLS_PRN_GetCurrentInterface . . . . . . . . . . . . . . . . . . . . . . . . . 246<br />

HCLS_PRN_SetInterface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247<br />

HCLS_PRN_GetDeviceId . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248<br />

HCLS_PRN_GetPortStatus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249<br />

HCLS_PRN_SoftReset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250<br />

HCLS_PRN_Write . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251<br />

12 <strong>USB</strong> Bus Driver Reference Manual


Contents<br />

HCLS_PRN_WriteSync . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253<br />

HCLS_PRN_AbortWrite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255<br />

HCLS_PRN_ResetWritePipe . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256<br />

HCLS_PRN_Read . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257<br />

HCLS_PRN_ReadSync . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259<br />

HCLS_PRN_AbortRead . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261<br />

HCLS_PRN_ResetReadPipe . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262<br />

14 Mass Storage Class Driver Reference 263<br />

14.1 Application programming interface . . . . . . . . . . . . . . . . . . . . . . . . . 263<br />

HCLS_MS_Init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263<br />

HCLS_MS_Exit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264<br />

HCLS_MS_DeviceConnected . . . . . . . . . . . . . . . . . . . . . . . . . . . 265<br />

HCLS_MS_RegisterConnectHandler . . . . . . . . . . . . . . . . . . . . . . . . 266<br />

HCLS_MS_CreateInterfaceList . . . . . . . . . . . . . . . . . . . . . . . . . . 267<br />

HCLS_MS_DestroyInterfaceList . . . . . . . . . . . . . . . . . . . . . . . . . . 268<br />

HCLS_MS_GetInterfaceInfo . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269<br />

HCLS_MS_GetInterfaceID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270<br />

HCLS_MS_DeviceRemove . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271<br />

HCLS_MS_Open . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272<br />

HCLS_MS_Close . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274<br />

HCLS_MS_GetLuns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275<br />

HCLS_MS_OpenLun . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276<br />

HCLS_MS_CloseLun . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277<br />

HCLS_MS_InitLun . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278<br />

HCLS_MS_ReadCapacity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279<br />

HCLS_MS_ModeSenseAllPages . . . . . . . . . . . . . . . . . . . . . . . . . . 280<br />

HCLS_MS_ReadModeSenseRawPage . . . . . . . . . . . . . . . . . . . . . . . 282<br />

HCLS_MS_IsMediumReady . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284<br />

HCLS_MS_ReadSectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285<br />

HCLS_MS_WriteSectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287<br />

14.2 Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289<br />

T_UNIT_INFO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289<br />

14.3 Status Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290<br />

14.4 Status Codes Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291<br />

<strong>USB</strong> Bus Driver Reference Manual 13


Contents<br />

HCLS_MS_STATUS_LENGTH (0x1000L) . . . . . . . . . . . . . . . . . . 291<br />

HCLS_MS_STATUS_COMMAND_FAILED (0x1002L) . . . . . . . . . . . 291<br />

HCLS_MS_STATUS_INTERFACE_PROTOCOL (0x1003L) . . . . . . . . . 291<br />

HCLS_MS_STATUS_INTERFACE_SUB_CLASS (0x1004L) . . . . . . . . 291<br />

HCLS_MS_STATUS_SENSE_REPEAT (0x1006L) . . . . . . . . . . . . . . 291<br />

HCLS_MS_STATUS_WRITE_PROTECT (0x1007L) . . . . . . . . . . . . . 291<br />

HCLS_MS_STATUS_NOT_READY (0x1008L) . . . . . . . . . . . . . . . . 291<br />

Index 293<br />

14 <strong>USB</strong> Bus Driver Reference Manual


References<br />

[1] Universal Serial Bus Specification, Revision 2.0,<br />

http://www.usb.org<br />

[2] <strong>USB</strong> device class specifications (Audio, HID, Printer, etc.),<br />

http://www.usb.org<br />

References<br />

<strong>USB</strong> Bus Driver Reference Manual 15


1 Introduction<br />

1 Introduction<br />

This document describes the <strong>USB</strong> <strong>Host</strong> <strong>Stack</strong> for embedded devices. The reader should be familiar<br />

with the concepts of embedded operating systems, the programming language C and the <strong>USB</strong><br />

specification.<br />

The document describes the architecture, the installation and the API of the <strong>Embedded</strong> <strong>USB</strong> <strong>Host</strong><br />

<strong>Stack</strong>. The document should be read by developers that integrates the driver stack into a project or<br />

that implements an application that uses the API of the <strong>Embedded</strong> <strong>USB</strong> <strong>Host</strong> <strong>Stack</strong>.<br />

The complete <strong>Embedded</strong> <strong>USB</strong> <strong>Host</strong> <strong>Stack</strong> consists of the <strong>USB</strong> Bus Driver, <strong>Host</strong> Controller Drivers<br />

and Class Drivers. A <strong>Host</strong> Controller (HC) Driver implements the access to a specific hardware<br />

controller and a Class Driver implements the <strong>USB</strong> protocol for a specific class. The Class Driver<br />

has a separate section in this document that describes the usage, the integration and the configuration<br />

of the module.<br />

<strong>USB</strong> Bus Driver Reference Manual 17


2 Overview<br />

2 Overview<br />

2.1 Features of the <strong>Embedded</strong> <strong>USB</strong> <strong>Host</strong> <strong>Stack</strong><br />

The <strong>Embedded</strong> <strong>USB</strong> <strong>Host</strong> <strong>Stack</strong> is designed to cover a <strong>USB</strong> host controller in an embedded environment.<br />

It consists of different modules which can be adjusted and combined to satisfy your<br />

requirements. This modular concept can easily be enhanced by your own implementations or by<br />

prepackaged components provided by <strong>Thesycon</strong> R○ <strong>Systemsoftware</strong> & Consulting GmbH.<br />

The <strong>Embedded</strong> <strong>USB</strong> <strong>Host</strong> <strong>Stack</strong> provides the following features:<br />

• Implemented in ANSI C<br />

• Works in either endian mode<br />

• Simple register abstraction layer<br />

• Simple abstraction layer of the operating system (TAL)<br />

• Can be used stand-alone or with an operating system, but it is recommended to use an<br />

operating system, classes require an operating system<br />

• Supporting of class drivers<br />

• Asynchronously implemented driver stack core<br />

• Asynchronous data transfer operations<br />

2.2 Features of the <strong>USB</strong> Bus Driver<br />

The <strong>USB</strong> Bus Driver consists of the <strong>USB</strong> Bus Driver Core and contains one or more <strong>USB</strong> <strong>Host</strong><br />

Controller Driver. The user interface to the <strong>USB</strong> Bus Driver is the <strong>USB</strong> Bus Driver API.<br />

The <strong>USB</strong> Bus Driver provides the following features:<br />

• Control, bulk and interrupt transfers<br />

• Hot plug and hot removal detection<br />

• Generation of plug and removal events<br />

• Presentation of devices at <strong>USB</strong> interface level<br />

• Enumeration of <strong>USB</strong> devices, at the end of the enumeration the device is configured<br />

• <strong>USB</strong> operation speed detection<br />

• Support of the root hub<br />

• Support for external <strong>USB</strong> hub devices<br />

• Support for devices with alternate settings<br />

• Support for multi-interface devices<br />

18 <strong>USB</strong> Bus Driver Reference Manual


• Support for multi-configuration devices<br />

• Implementing of an extended error recovery during device enumeration<br />

• Dynamical attachment/removal of a <strong>USB</strong> <strong>Host</strong> Controller Driver<br />

2.3 Supported <strong>Host</strong> Controllers<br />

2 Overview<br />

<strong>Thesycon</strong>’s <strong>Embedded</strong> <strong>USB</strong> <strong>Host</strong> <strong>Stack</strong> currently supports the Enhanced <strong>Host</strong> Controller (EHC)<br />

and the Open <strong>Host</strong> Controller (OHC). Both controllers are PCI bus DMA controllers. The stack<br />

can be used on each embedded sytsem that has such a host controller integrated.<br />

2.4 Supported Platforms<br />

The following platforms are supported:<br />

• EmBos from Segger GmbH<br />

• Windows PC environment based on PCIdacc<br />

The PC environment uses a special kernel driver that enables the access to the standard <strong>USB</strong><br />

controllers UHC, OHC and EHC. This platform is for testing of the stack and may be used to<br />

develop class driver or applications as long as the hardware is not yet available. A new platform<br />

can be added by implementing the TAL abstraction layer.<br />

<strong>USB</strong> Bus Driver Reference Manual 19


3 Architecture<br />

3 Architecture<br />

Operating System or<br />

<strong>Embedded</strong> Environment<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

T<br />

A<br />

L<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

L<br />

a<br />

y<br />

e<br />

r<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢<br />

¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢<br />

¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢<br />

¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢<br />

¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢<br />

¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢<br />

¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢<br />

¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢<br />

<strong>USB</strong> Class<br />

Drivers<br />

<strong>Embedded</strong> Applications<br />

Vendor Specific<br />

Device Driver<br />

<strong>USB</strong> Bus Driver<br />

<strong>USB</strong> Bus Driver Core<br />

<strong>USB</strong> <strong>Host</strong><br />

Controller Driver<br />

Hardware-specifc<br />

Register Abstraction Layer<br />

Hub Driver<br />

Hardware-independent<br />

<strong>USB</strong> <strong>Host</strong><br />

Controller Driver<br />

Hardware-specifc<br />

¡ ¡ ¡ ¡ £¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£<br />

£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡ £¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£<br />

£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£<br />

¡ ¡ ¡ ¡<br />

<strong>USB</strong> <strong>Host</strong><br />

Controller<br />

Hardware<br />

Figure 1: Components of the <strong>Embedded</strong> <strong>USB</strong> <strong>Host</strong> <strong>Stack</strong><br />

The <strong>Embedded</strong> <strong>USB</strong> <strong>Host</strong> <strong>Stack</strong> consists of the following components:<br />

<strong>USB</strong> <strong>Host</strong><br />

Controller<br />

Hardware<br />

• <strong>USB</strong> <strong>Host</strong> Controller Driver - This component is part of the <strong>USB</strong> Bus Driver and encapsulates<br />

the host controller specific <strong>USB</strong> implementation. Refer to section 3.3 for more<br />

information.<br />

• <strong>USB</strong> Bus Driver Core - This component is part of the <strong>USB</strong> Bus Driver and provides the<br />

generic <strong>USB</strong> <strong>Host</strong> functionality. This module also includes a <strong>USB</strong> hub driver for external<br />

<strong>USB</strong> hub support. Refer to section 3.3 for more information.<br />

• <strong>USB</strong> Class Drivers - This component is optional to the <strong>USB</strong> Bus Driver. It could be the<br />

implementation of a defined <strong>USB</strong> class driver or represent a vendor specific device driver.<br />

Refer to section 3.4 for more information about <strong>USB</strong> class drivers.<br />

20 <strong>USB</strong> Bus Driver Reference Manual


3 Architecture<br />

The following software layers are required for the integration of the <strong>Embedded</strong> <strong>USB</strong> <strong>Host</strong> <strong>Stack</strong>:<br />

• <strong>Thesycon</strong> Abstraction Layer (TAL) - This component provides the abstraction to the operating<br />

system or embedded environment. Refer to section 3.2 for more information.<br />

• Register Abstraction Layer - This component provides the abstraction of the register access.<br />

Refer to section 3.1 for more information.<br />

Figure 2 shows the interfaces between the modules and the appropriate header files containing the<br />

definition of the interfaces.<br />

T<br />

A<br />

L<br />

L<br />

a<br />

y<br />

e<br />

r<br />

tal_api.h<br />

Tal_xxx()<br />

Application<br />

<strong>USB</strong> <strong>Host</strong> Controller Driver<br />

<strong>USB</strong> <strong>Host</strong> Controller<br />

Application<br />

hcls_printer_api.h<br />

HCLS_PRN_xxx()<br />

Printer<br />

Device Driver<br />

<strong>USB</strong> Bus Driver<br />

<strong>USB</strong> Bus Driver Core<br />

¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡<br />

¡ ¡<br />

¡ ¡ ¡ ¡ ¡ ¡ ¡<br />

¡ ¡ ¡<br />

¡ ¡ ¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡<br />

¡ ¡ ¡ ¡ ¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡ ¡ ¡<br />

¡<br />

¡ ¡ ¡<br />

¡<br />

¡ ¡ ¡<br />

¡ ¡ ¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡ ¡ ¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡ ¡ ¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡ ¡ ¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡ ¡ ¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡ ¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡ ¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡ ¡ ¡ ¡<br />

¡<br />

¡<br />

¡<br />

¡ ¡ ¡ ¡<br />

¡<br />

¡<br />

¡<br />

¡ ¡ ¡ ¡<br />

¡<br />

¡<br />

¡<br />

¡ ¡ ¡ ¡<br />

¡<br />

¡<br />

¡<br />

¡ ¡ ¡ ¡<br />

¡<br />

¡<br />

¡<br />

¡ ¡ ¡ ¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡ ¡ ¡<br />

¡<br />

¡ ¡ ¡ ¡ ¡<br />

¡<br />

¡ ¡ ¡ ¡ ¡<br />

¡<br />

¡ ¡ ¡<br />

Register Abstraction ¡ Layer<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡<br />

3.1 Register Abstraction Layer<br />

Application<br />

hcls_ms_api.h<br />

HCLS_MS_xxx()<br />

Mass Storage<br />

Device Driver<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

usb_hc.h<br />

<strong>USB</strong>H_xxx()<br />

<strong>USB</strong> <strong>Host</strong> Controller Driver<br />

¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡<br />

¡<br />

¡ ¡<br />

¡<br />

¡ ¡<br />

<strong>USB</strong> <strong>Host</strong> Controller<br />

Figure 2: Architecture of the <strong>Embedded</strong> <strong>USB</strong> <strong>Host</strong> <strong>Stack</strong><br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

¡<br />

usbh_api.h<br />

usbh_status.h<br />

UBBH_xxx()<br />

usbh_manage.h<br />

hcohc_reg_api.h<br />

hcehc_reg_api.h<br />

HcohcReadReg()<br />

The Register Abstraction Layer provides the abstraction of the access to the registers of the HC. It<br />

encapsulates the access to the registers of the host controller with the appropriate functions defined<br />

<strong>USB</strong> Bus Driver Reference Manual 21


3 Architecture<br />

in the register API. These functions are host controller specific and have to be implemented by the<br />

application designer according to the used host controller and its environment.<br />

The Register Abstraction Layer interface is defined in header files:<br />

hcohc_reg_api.h<br />

hcehc_reg_api.h<br />

3.2 <strong>Thesycon</strong> Abstraction Layer<br />

The <strong>Thesycon</strong> Abstraction Layer (TAL) provides the abstraction of the application environment.<br />

Because the <strong>Embedded</strong> <strong>USB</strong> <strong>Host</strong> <strong>Stack</strong> has no dependencies from the C-runtime or from other<br />

operating system specific functions in the <strong>Thesycon</strong> Abstraction Layer are required.<br />

The TAL provides common functions for memory, timer and synchronization handling which are<br />

defined in the file tal_api.h. These functions have to be implemented by the application designer<br />

according to the used operating system or embedded environment. Furthermore the abstraction<br />

layer provides definitions of basic data types in the file tbase_types.h. It is possible that<br />

the application designer has to change these defines according to the deployed micro processor.<br />

Refer to section 10 on page 127 for the API reference of the abstraction layer.<br />

22 <strong>USB</strong> Bus Driver Reference Manual


3.3 <strong>USB</strong> Bus Driver<br />

3 Architecture<br />

The <strong>USB</strong> Bus Driver is the central part of the <strong>Embedded</strong> <strong>USB</strong> <strong>Host</strong> <strong>Stack</strong>. It consists of the <strong>USB</strong><br />

Bus Driver Core and at least one <strong>USB</strong> <strong>Host</strong> Controller Driver. There is exactly one instance of the<br />

<strong>USB</strong> Bus Driver module. The <strong>USB</strong> Bus Driver can handle any number of <strong>USB</strong> <strong>Host</strong> Controller<br />

Drivers. It is not important whether the <strong>USB</strong> <strong>Host</strong> Controller Drivers control hardware of the<br />

same type or of different types nor if the host controllers support high or full speed. The <strong>USB</strong><br />

<strong>Host</strong> Controller Drivers can be dynamically attached and removed from the <strong>USB</strong> Bus Driver at<br />

runtime.<br />

The interface of the bus driver is declared in the files and . The<br />

functions of the <strong>USB</strong> bus driver can be grouped in three parts:<br />

• Connect and removal detection<br />

• Device information<br />

• Device communication<br />

3.3.1 <strong>USB</strong> Bus Driver Core<br />

The <strong>USB</strong> Bus Driver Core module contains the generic <strong>USB</strong> host functionality which is common<br />

to all <strong>USB</strong> host controllers. It is responsible for the enumeration of connected devices and handles<br />

all kinds of standard requests. The <strong>USB</strong> Bus Driver Core is independent from the <strong>USB</strong> <strong>Host</strong><br />

Controller Driver implementation and has no access to any host controller hardware.<br />

Additionally there is a <strong>USB</strong> hub driver for the <strong>USB</strong> Bus Driver Core module available. This is<br />

optional and only required if external <strong>USB</strong> hubs should be supported by the <strong>Embedded</strong> <strong>USB</strong> <strong>Host</strong><br />

<strong>Stack</strong>.<br />

The <strong>USB</strong> Bus Driver Core detects the connection and removal of the device. It enumerates the<br />

devices, assigns <strong>USB</strong> device address and maintain the <strong>USB</strong> devices and the related <strong>USB</strong> interfaces<br />

in lists. It collects information about the device by requesting the related <strong>USB</strong> descriptors. It<br />

enables the access to the descriptor information. It provides PnP event notifications for class<br />

drivers and applications. The devices can be found by an application with the help of enumeration<br />

functions or with PnP notifications. The enumeration function generates a list of available <strong>USB</strong><br />

interfaces that fulfill the requirements of a filter mask. The application can enumerate in this list<br />

with an index. The relation between the index and the <strong>USB</strong> interfaces in a list are constant. It can<br />

happen that a device that is still in the list is not longer connected to the bus. In this case the open<br />

function will fail.<br />

The bus driver assigns each device and each interface a unique ID when the device is enumerated.<br />

If the device is removed and reconnected the device gets a new ID. This ID is the unique identification<br />

of a connected <strong>USB</strong> device or a <strong>USB</strong> interface. The <strong>USB</strong> Interface can be opened with the<br />

help of the ID. With the help of the device ID the application can detect which interfaces belong<br />

to the same <strong>USB</strong> device.<br />

A lot of information about the device can be requested synchronously. This includes the standard<br />

descriptors and some additional values. The communication with the device is based on the data<br />

structure URB (<strong>USB</strong> Request Block). All communication requests with an URB are handled<br />

asynchronously. The submit function returns immediately and independent from the state of the<br />

<strong>USB</strong> Bus Driver Reference Manual 23


3 Architecture<br />

operation. It signals <strong>USB</strong>H_STATUS_PENDING to indicate the operation is in progress and the<br />

callback function will inform the caller when the operation has been finished. In this case the<br />

owner ship of the URB is passed to the <strong>USB</strong> bus driver and the structure must not modified or<br />

freed by the application until the completion routine is called. In the case of a submission error<br />

the completion routine is not called. The caller has to take care on the returned status value of the<br />

submit function.<br />

3.3.2 <strong>USB</strong> <strong>Host</strong> Controller Driver<br />

The <strong>USB</strong> <strong>Host</strong> Controller Driver implements the access to a specific <strong>USB</strong> host controller. It<br />

is responsible for initializations, register based access and interrupt handling of the chosen host<br />

controller hardware. The <strong>USB</strong> <strong>Host</strong> Controller Driver has an interface to attach or remove it from<br />

the <strong>USB</strong> Bus Driver Core. The <strong>USB</strong> Bus Driver Core can handle host controller of different types.<br />

A host controller implementation may have restrictions. See the source code for details.<br />

3.4 <strong>USB</strong> Class Drivers<br />

<strong>USB</strong> Class Drivers can be attached on top of the <strong>USB</strong> Bus Driver API. They can represent generic<br />

<strong>USB</strong> class drivers like printer, mass storage or HID. It is also possible to implement an own vendor<br />

specific device driver on top of the <strong>USB</strong> Bus Driver API. The current implementation supports the<br />

following classes:<br />

• HUB class<br />

• Human Interface Device Class (HID)<br />

• Mass Storage Device Class<br />

• Communication Device Class/Abstract Control Model (UART emulation)<br />

• Printer Device Class<br />

The class drivers use a synchronous API. This makes the application programming easier. But the<br />

TAL layer must support wait functions. A more detailed description of each implemented class<br />

can be found in the reference part of this documentation.<br />

24 <strong>USB</strong> Bus Driver Reference Manual


4 Configuration<br />

4 Configuration<br />

The application designer has to customize some settings in order to use the <strong>USB</strong> <strong>Host</strong> <strong>Stack</strong> in an<br />

own application. Every software module in the <strong>USB</strong> <strong>Host</strong> <strong>Stack</strong> contains a header file with default<br />

configuration settings. It is typically named as _config.h. Please have a look to<br />

these header files to get an overview of possible configuration options. Every configuration file<br />

includes . can be used to overwrite the default settings.<br />

The host controller drivers use some pre-allocated memory pools to avoid memory allocation in<br />

the data transfer path. The dimension of these buffers has a strong influence to the memory usage<br />

and the option to use a number of <strong>USB</strong> devices at the same time. E.g. for the <strong>USB</strong> OHC controller<br />

these pools are configured with the following parameters:<br />

#define HCOHC_DEVICE_MAX_<strong>USB</strong>_DEVICES 1<br />

#define HCOHC_MAX_INTERRUPT_ENDPOINTS 0<br />

#define HCOHC_MAX_BULK_ENDPOINTS 2<br />

This is a minimal configuration that allows the usage of one memory stick. Please note that <strong>USB</strong><br />

hubs are also devices that need resources.<br />

4.1 Compile Time Configuration - <strong>USB</strong> Bus Driver<br />

The compile time configuration has to be customized to meet the requirements of the application<br />

and to adjust the <strong>USB</strong> Bus Driver to the appropriate environment. The <strong>USB</strong> Bus Driver default<br />

settings are in . Only in rare case these settings must be changed. If the<br />

external hub support is not licensed the files and are not part<br />

of the delivery.<br />

<strong>USB</strong> Bus Driver Reference Manual 25


5 Usage<br />

5 Usage<br />

5.1 Initial Steps<br />

The following initial steps have to be done before using the <strong>USB</strong> Bus Driver API. Some hints<br />

are given for the usage of a <strong>USB</strong> class driver. To ensure proper behavior the return status of the<br />

functions has to be checked. The included demo applications provide a good starting point for<br />

implementing you own application.<br />

1. Configure the <strong>USB</strong> Bus Driver to meet your requirements. You have to adjust the appropriate<br />

settings for the <strong>USB</strong> Bus Driver in the file usbh_config.h. Each parameter from the<br />

default configuration file can be copied to the usbh_config.h file and modified.<br />

2. Basic data types are defined in the tbase_types.h. Depending on the compiler and<br />

CPU type it may be required to change the settings. It is important that the size in the name<br />

of the variable is correct. E.g. T_UINT32 variable must have a size of 32 bit.<br />

3. The OS abstraction layer defined in tal_api.h must be implemented. This implementation<br />

can be tested with the module usbh_tal_test.c and the function UsbhTalTest().<br />

When this function does not return with T_BOOL the implementation of the TAL layer<br />

should be checked.<br />

4. Initialize the abstraction Layer TAL with a call to TAL_Init. Call the TAL test function<br />

UsbhTalTest in the debug version and check the return value.<br />

5. Initialize the <strong>USB</strong> Bus Driver Core by a call to <strong>USB</strong>H_Init.<br />

6. Prepare the interrupt handling for the host controller.<br />

7. Create a <strong>Host</strong> controller with <strong>USB</strong>H_CreateOhcController or<br />

<strong>USB</strong>H_CreateEhcController and enable the interrupts for it.<br />

8. Start the enumeration of the devices with <strong>USB</strong>H_EnumerateDevices.<br />

9. Start further applications or class drivers if required. Register PnP notification handler or<br />

poll the available devices periodically.<br />

5.2 Debug Support<br />

The library can be compiled as a release or a debug version. The debug version is compiled<br />

when the define TB_DEBUG is set to 1, e.g. -DTB_DEBUG=1. The debug version has the same<br />

properties as the release version with the following enhancements:<br />

• The code can generate text messages (traces) on a terminal.<br />

• The code performs additional checks and parameter validation.<br />

• The code activates asserts that check assumptions about parameters.<br />

The debug version has a larger memory foot print and runs slightly slower than the release version.<br />

But it is strongly recommended to use the debug version during the integration phase. The traces<br />

of the stack are the base for qualified support from <strong>Thesycon</strong>.<br />

26 <strong>USB</strong> Bus Driver Reference Manual


5.2.1 Trace Support<br />

5 Usage<br />

The possibilities to communicate text messages to a terminal may be different on each system.<br />

For that reason the trace module must be implemented in the platform. The trace system uses the<br />

following functions and macros:<br />

void TbTrace(const char* format, ...);<br />

void TbDumpBytesEx(const void* ptr, size_t byteCount, size_t bytesPerLine);<br />

TbAssertionFailed(condition)<br />

The high level functions TbDumpBytesEx and the macro TbAssertionFailed uses the<br />

TbTrace function. Each of these functions has a default implementation in the files<br />

tbase_func_TbAssertionFailed.inc<br />

tbase_func_TbDumpBytesEx.inc<br />

tbase_func_TbTrace.inc<br />

When these include files are added to the project the default implementation is active.<br />

When the runtime environment of the system provides a vprintf() function, it is easy to implement<br />

the TbTrace similar to the implementation in tbase_func_TbTrace.inc. In this<br />

case it must be checked that the system provided vprintf() function can handle all formatter<br />

as described in tbase_trace.h.<br />

If this function is not available the vprintf function from tbase_func_TbTraceVPrintf.inc<br />

can be used. This module uses the TbTraceOutputChar function to send a single character to<br />

a terminal port. This function can be used to put the character to a COM port or any other trace<br />

interface.<br />

5.2.2 Assert Support<br />

The interface of the <strong>USB</strong> driver API is designed as trusted interface. That means that the host<br />

driver drust the calling application. It expects that handles are valid and parameters are in the<br />

correct range. This is a design decision to make the software effective.<br />

In the debug version of the driver stack the handles and some other parameters are checked with<br />

the TB_ASSERT macro. It is recommended to use the implemented assert structure during the<br />

integration to detect possible problems in the usage of the <strong>USB</strong> host API. Our default implementation<br />

runs into an endless loop. This enables an easy debugging because the call stack and all<br />

local variables can be investigated in a debugger. In the release version the TB_ASSERT macros<br />

are defined void.<br />

5.2.3 Configuration of Traces<br />

The traces of the driver stack are groupped into categories. Each category uses a special macro<br />

that is either implemented or void. The macros can be configured by defines.<br />

The file trace_config.h contains the defines that enables or disables all trace groups. By<br />

default the trace macros<br />

TB_TRACE_ERR,<br />

<strong>USB</strong> Bus Driver Reference Manual 27


5 Usage<br />

TB_TRACE_WRN and<br />

TB_TRACE_INF<br />

are enabled. To investigate special problems more macros can be enabled.<br />

28 <strong>USB</strong> Bus Driver Reference Manual


5.3 Memory Abstraction<br />

5 Usage<br />

The CPU that executes the driver stack may support different features for the memory access. This<br />

can be<br />

• A MMU with virtual to physical address translation<br />

• Memory cache for performance optimization<br />

• Memory regions that can be accessed by the host controller<br />

• Cache lines with a given size that are updated in one step<br />

While the CPU accesses the virtual addresses with all the caching mechanism the host controller<br />

uses a direct access to the memory with physical addresses.<br />

The TAL layer provides with the functions TAL_AllocateDmaMemory and<br />

TAL_AllocateDmaDescMemory an abstraction for the memory access.<br />

The function TAL_AllocateDmaDescMemory allocates memory with the following properties:<br />

• The CPU does not use any cache for this memory. Each read and write access is immediately<br />

executed on the physical memory. The sequence of the memory write accesses is not<br />

changed by the compiler or CPU.<br />

• The memory is in a memory range that can be accessed efficient by the host controller. This<br />

memory is frequently accessed by the host controller.<br />

• The CPU can use address translation for this memory.<br />

This kind of memory is used to allocate DMA descriptor memory for the host controller.<br />

The function TAL_AllocateDmaMemory allocates memory with the following properties:<br />

• The CPU can use cache to access the memory.<br />

• The stack uses the functions TAL_InvalidateCache and TAL_FlushCache to update<br />

the CPU memory cache.<br />

• The memory is aligned to a cache line size and it has always a size that can be divided by the<br />

cache line size without rest. This means the buffer may be up to one cache line size minus<br />

one larger than the requested size during the allocation. This prevents the overwriting of<br />

memory that follows immediately at the end of the buffer when the cache line is updated.<br />

• The memory is in a memory range that can be accessed by the host controller.<br />

• The CPU can use address translation for this memory.<br />

This kind of memory is used for all data transfers with the host controller. For data transfers on<br />

the control endpoint the driver stack allocates internal buffers with these properties. The caller can<br />

use any memory to start a data transfer on the control endpoint. The data transfer buffer for all<br />

other transfer types must have the properties described above. The caller can either use the TAL<br />

function TAL_AllocateDmaMemory to get the required memory or it can make sure that the<br />

memory that is used has the right properties.<br />

<strong>USB</strong> Bus Driver Reference Manual 29


5 Usage<br />

5.4 Enumeration of <strong>USB</strong> devices<br />

The <strong>Embedded</strong> <strong>USB</strong> <strong>Host</strong> <strong>Stack</strong> supports hot plug and hot removal of <strong>USB</strong> devices. Each detected<br />

device is enumerated by the bus driver according to the following steps:<br />

• Sending a <strong>USB</strong> reset<br />

• Assigning a <strong>USB</strong> address<br />

• Requesting the device and the configuration descriptors<br />

• Activating the configuration with the descriptor index 0<br />

• Creating internal <strong>USB</strong> interface objects for each <strong>USB</strong> interface<br />

• Inform the registered software modules about the connect events<br />

5.5 <strong>USB</strong> Interfaces<br />

To communicate with a connected <strong>USB</strong> device a interface object created in the <strong>USB</strong> Bus Driver<br />

must be opened. The input parameter for the <strong>USB</strong>H_OpenInterface function is the interface ID.<br />

This ID can be obtained by two different ways.<br />

The first method enumerates all <strong>USB</strong> interfaces of all <strong>USB</strong> devices and opens the interfaces of interest.<br />

A interface list is created with <strong>USB</strong>H_CreateInterfaceList. This internal interface list contains<br />

all <strong>USB</strong> interfaces matching the criteria defined with the mask <strong>USB</strong>H_INTERFACE_MASK<br />

at the point of time where the function is called. This mask includes the VID, PID, Class, Subclass<br />

and some other values. The interfaces in a list can be enumerated with a zero based index<br />

the functions <strong>USB</strong>H_GetInterfaceInfo and <strong>USB</strong>H_GetInterfaceID.<br />

While <strong>USB</strong>H_GetInterfaceInfo returns some information about the found <strong>USB</strong> interface<br />

the function <strong>USB</strong>H_GetInterfaceID returns the required interface ID.<br />

The second method uses the function <strong>USB</strong>H_RegisterPnPNotification to install a PnP handler.<br />

This handler is called each time a <strong>USB</strong> interface that meets the criteria defined with the<br />

<strong>USB</strong>H_INTERFACE_MASK is connected or removed to the host controller. The notification function<br />

gets the interface ID as a parameter. When the notification function is registered while <strong>USB</strong><br />

interfaces that meet the mask criteria are already connected to the stack the bus driver calls the notification<br />

function for each interface. When the programmer decides to use the PnP notifications it<br />

is not required to enumerate the available devices first.<br />

This handle that is returned by <strong>USB</strong>H_OpenInterface is required for all other interface related<br />

functions.<br />

Typically one software module on top of the <strong>USB</strong> Bus Driver API controls one or more interfaces,<br />

but one interface is only controlled by one software module. To prevent usage of the same interface<br />

by different software module the interface should be opened exclusively.<br />

5.6 Additional Device Information<br />

The <strong>USB</strong> Bus Driver has captured some descriptors from the device during the enumeration<br />

process. The descriptor information can be requested with the <strong>USB</strong>H_GetXXX functions, like<br />

30 <strong>USB</strong> Bus Driver Reference Manual


5 Usage<br />

<strong>USB</strong>H_GetDeviceDescriptor or <strong>USB</strong>H_GetInterfaceDescriptor. These functions do not perform<br />

data transfers on the <strong>USB</strong> bus and therefore return immediately.<br />

5.7 Data Transfer<br />

To communicate with the device or perform data transfer the function <strong>USB</strong>H_SubmitUrb is used,<br />

where the information is transferred within the data structure URB. The URB determines which<br />

device operation is used. For a detailed description of the API see section 8 on page 41.<br />

5.8 Closing the Handles<br />

Each handle that is returned by the API has an associated resource inside the bus driver. The<br />

internal resource is kept valid until the handle is closed. For that reason it is important that every<br />

handle that is obtained from the bus driver API is closed exactly one time. After a handle is closed<br />

it must not be used again. A violation of this rule will break the operation of the code.<br />

5.9 External Hub Support1<br />

The driver stack supports external <strong>USB</strong> hubs. The support for external hubs is an option and must<br />

be licensed separately. The external hubs are transparent to the bus API. The interface of the hubs<br />

do not appear in the list of available <strong>USB</strong> interfaces and cannot be controlled from the bus driver<br />

API. The bus driver takes care on the power management and the bandwidth in the bus topology.<br />

The hub driver does not support dynamically switching of the hubs power supply, this means if<br />

the hub is switched to self power or bus power mode during hub operation the hub driver does not<br />

recognize this. This software version supports <strong>USB</strong> 1.1 and <strong>USB</strong> 2.0 compliant hubs.<br />

The implementation if the external hub module is in the files usbh_exthub.h and<br />

usbh_exthub.c. If the external hub support is not license these files are not part of the delivery.<br />

The files must be removed from the build environment.<br />

5.10 Synchronization<br />

The <strong>USB</strong> <strong>Host</strong> Driver Core and the <strong>Host</strong> Controller Driver are implemented asynchronously.<br />

That means these software parts work event driver and does not use wait functions in the normal<br />

data processing. The software modules can be protected with an internally implemented<br />

TAL_MutexObject object. Whether the mutex object should be used or not can be configured<br />

with the configuration parameter <strong>USB</strong>H_SYNCHRONIZE. If this define is set to 1 the Core and the<br />

<strong>Host</strong> Controller Driver are protected with a mutex. It must be used when the class implementation<br />

are used.<br />

The driver stack releases the mutex before the callback functions are called. This enables the<br />

application and the class driver to call non blocking function directly in the context of callback<br />

functions.<br />

Some API function of the Driver Core can wait. These are function like<br />

<strong>USB</strong>H_WaitForIdle<strong>Stack</strong>()<br />

<strong>USB</strong>H_Exit()<br />

<strong>USB</strong> Bus Driver Reference Manual 31


5 Usage<br />

<strong>USB</strong>H_Remove<strong>Host</strong>Controller()<br />

The interrupt handling is divided in a <strong>USB</strong>H_ServiceISR and in a <strong>USB</strong>H_ProcessInterrupt<br />

function. The function <strong>USB</strong>H_ServiceISR disables only the interrupt of the host controller. For<br />

that reason this function can be called at each point of time without any synchronization. It can<br />

be called directly in the context of the system ISR. No callback is performed in the context of this<br />

function. The function <strong>USB</strong>H_ServiceISR returns T_TRUE if the interrupt was generated by<br />

the host controller.<br />

The function <strong>USB</strong>H_ProcessInterrupt service the interrupt and re-enables the interrupt on<br />

the host controller. This function enters the mutex and can call notification functions. This function<br />

is typically called in a task of the operating system that belongs to the <strong>USB</strong> host stack.<br />

The class driver protects its data structures with its own mutex objects.<br />

5.11 Callbacks<br />

The callback functions are called in a arbitrary context. This means either in a timer context or<br />

in the context of the function <strong>USB</strong>H_ProcessInterrupt. The code in a callback function<br />

must not wait and must not call API functions that are marked as blocking. When the code in the<br />

callback function needs a mutex object to protect variables the other code that is executed under<br />

the same mutex must not call non blocking function or wait for something. When this rule is<br />

violated the stack can deadlock. The stack does not detect the deadlock situation by asserts or<br />

different methods. The stack becomes not functional.<br />

For complex tasks, like the handling of a device remove event, the code in the callback routine<br />

should wakeup a different task by setting an event.<br />

When the application re-submits data buffers in the context of the callback function it should check<br />

the return status. On error the code should start an error recovery and should not submit the buffer<br />

in the context of the callback function. The error recovery must be either implemented as a state<br />

machine with asynchronous functions or should wake the application task to do this job.<br />

A special problem occurs, when a callback function is unregistered at the stack. Because of<br />

the design rule that the callback functions are called without mutex there is the risk that a callback<br />

function is called a short time after it was unregistered. This can cause problems when<br />

the resources that are used in the callback function are freed. To avoid the problem the function<br />

<strong>USB</strong>H_WaitForIdle<strong>Stack</strong> must be called each time a callback function is unregistered from<br />

the stack .<br />

Note: The function <strong>USB</strong>H_WaitForIdle<strong>Stack</strong> does not ensure that a timer callback function<br />

is not called after the timer has been cancelled with TAL_CancelTimer.<br />

32 <strong>USB</strong> Bus Driver Reference Manual


6 Management Reference<br />

6.1 <strong>USB</strong> Bus Driver Core<br />

<strong>USB</strong>H_Init<br />

This function is called for the basic initialization of the <strong>USB</strong> Bus Driver.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

<strong>USB</strong>H_Init();<br />

Return Value<br />

6 Management Reference<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

This function has to be called one time during startup before any other function is called. The<br />

<strong>USB</strong> Bus Driver initializes or allocates global resources within this function. The host<br />

controller must be created and added to the bus driver at a later time.<br />

This function is non blocking.<br />

See Also<br />

<strong>USB</strong>H_Exit (page 34)<br />

<strong>USB</strong> Bus Driver Reference Manual 33


6 Management Reference<br />

<strong>USB</strong>H_Exit<br />

This function is called on exit of the <strong>USB</strong> Bus Driver.<br />

Definition<br />

void<br />

<strong>USB</strong>H_Exit();<br />

Comments<br />

This function has to be called on exit of the <strong>USB</strong> Bus Driver. The <strong>USB</strong> Bus Driver may free<br />

global resources within this function. This includes also the removing and deleting of added<br />

host controllers. After this function was called, no other function of the <strong>USB</strong> Bus Driver<br />

should be called.<br />

This function is blocking.<br />

See Also<br />

<strong>USB</strong>H_Init (page 33)<br />

34 <strong>USB</strong> Bus Driver Reference Manual


<strong>USB</strong>H_ServiceISR<br />

This function must be called in the interrupt service routine of the OHCI controller.<br />

Definition<br />

T_BOOL<br />

<strong>USB</strong>H_ServiceISR(<br />

<strong>USB</strong>H_HC_HANDLE HcHandle<br />

);<br />

Parameter<br />

HcHandle<br />

This parameter is a handle to the host controller driver.<br />

Return Value<br />

6 Management Reference<br />

The function returns T_TRUE if the interrupt was caused by the controller that is identified by<br />

the handle otherwise T_FALSE.<br />

Comments<br />

This function must be called if an interrupt occurs. It should be called in the context of the<br />

interrupt routine. This function disables the interrupt in the controller if the interrupt was<br />

caused by the controller.<br />

This function is non blocking.<br />

See Also<br />

<strong>USB</strong>H_ProcessInterrupt (page 36)<br />

<strong>USB</strong> Bus Driver Reference Manual 35


6 Management Reference<br />

<strong>USB</strong>H_ProcessInterrupt<br />

Process an interrupt.<br />

Definition<br />

void<br />

<strong>USB</strong>H_ProcessInterrupt(<br />

<strong>USB</strong>H_HC_HANDLE HcHandle<br />

);<br />

Parameter<br />

HcHandle<br />

This handle is the context of the host controller driver.<br />

Comments<br />

This routine processes an interrupt from a controller. Callback functions may be called in the<br />

the context of this function. The function enables the interrupts of the controller. It enters a<br />

mutex to protect the code.<br />

This function is non blocking. But in the context of this function other callback functions may<br />

be called. Therefor no blocking functions must be called in this context. An invalid<br />

implementation in a callback function that block this function and cause a deadlock.<br />

See Also<br />

<strong>USB</strong>H_ServiceISR (page 35)<br />

36 <strong>USB</strong> Bus Driver Reference Manual


<strong>USB</strong>H_Remove<strong>Host</strong>Controller<br />

6 Management Reference<br />

This function must be called by the application to remove the host controller from the <strong>USB</strong> Bus<br />

Driver.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

<strong>USB</strong>H_Remove<strong>Host</strong>Controller(<br />

<strong>USB</strong>H_HC_HANDLE HcHandle<br />

);<br />

Parameter<br />

HcHandle<br />

Valid Handle to the host controller.<br />

Comments<br />

This removes a host controller from the library.<br />

This function is blocking.<br />

<strong>USB</strong> Bus Driver Reference Manual 37


6 Management Reference<br />

<strong>USB</strong>H_EnumerateDevices<br />

This function adds default endpoints for enumeration, sets the host controller into running state<br />

and starts the enumeration of the complete bus.<br />

Definition<br />

void<br />

<strong>USB</strong>H_EnumerateDevices(<br />

<strong>USB</strong>H_HC_HANDLE HcHandle<br />

);<br />

Parameter<br />

HcHandle<br />

A valid handle to a host controller.<br />

Comments<br />

After this function returns the host controller is up and running and can detect <strong>USB</strong> devices.<br />

The enumeration of <strong>USB</strong> devices can still be in progress when this function returns.<br />

This function is non blocking.<br />

See Also<br />

<strong>USB</strong>H_Init (page 33)<br />

38 <strong>USB</strong> Bus Driver Reference Manual


7 <strong>Host</strong> Controller Creation Reference<br />

7.1 Open <strong>Host</strong> Controller<br />

<strong>USB</strong>H_CreateOhcController<br />

7 <strong>Host</strong> Controller Creation Reference<br />

This function allocates all resources that are required for the host controller object of the <strong>USB</strong><br />

<strong>Host</strong> Controller Driver. Furthermore it initializes the host controller and attach it to the <strong>USB</strong> bus<br />

driver core.<br />

Definition<br />

<strong>USB</strong>H_HC_HANDLE<br />

<strong>USB</strong>H_CreateOhcController(<br />

void* BaseAddress<br />

);<br />

Parameter<br />

BaseAddress<br />

This is the virtual base address of the OHC or any other hardware resource information.<br />

Return Value<br />

The function returns a handle to the created host controller object on success. If creation of the<br />

host controller fails the function returns NULL which is an invalid handle value.<br />

Comments<br />

This function is non blocking.<br />

<strong>USB</strong> Bus Driver Reference Manual 39


7 <strong>Host</strong> Controller Creation Reference<br />

<strong>USB</strong>H_CreateEhcController<br />

This function allocates all resources that are required for the host controller object of the <strong>USB</strong><br />

<strong>Host</strong> Controller Driver. Furthermore it initializes the host controller and attach it to the <strong>USB</strong> bus<br />

driver core.<br />

Definition<br />

<strong>USB</strong>H_HC_HANDLE<br />

<strong>USB</strong>H_CreateEhcController(<br />

void* BaseAddress<br />

);<br />

Parameter<br />

BaseAddress<br />

This is the virtual base address of the EHC capabilities registers.<br />

Return Value<br />

The function returns a handle to the created host controller object on success. If creation of the<br />

host controller fails the function returns NULL which is an invalid handle value.<br />

Comments<br />

This function is non blocking.<br />

40 <strong>USB</strong> Bus Driver Reference Manual


8 <strong>USB</strong> Bus Driver Reference<br />

8.1 Application programming interface<br />

<strong>USB</strong>H_CreateInterfaceList<br />

This function generates a list of available interfaces.<br />

Definition<br />

<strong>USB</strong>H_INTERFACE_LIST_HANDLE<br />

<strong>USB</strong>H_CreateInterfaceList(<br />

const <strong>USB</strong>H_INTERFACE_MASK* InterfaceMask,<br />

T_UINT32* InterfaceCount<br />

);<br />

Parameters<br />

8 <strong>USB</strong> Bus Driver Reference<br />

InterfaceMask<br />

This is an input parameter of type <strong>USB</strong>H_INTERFACE_MASK and specifies a mask for the<br />

interfaces which should be listed.<br />

InterfaceCount<br />

This parameter returns the number of available interfaces.<br />

Return Value<br />

This function returns a handle to an interface list on success or NULL which is an invalid<br />

handle value.<br />

Comments<br />

The generated interface list is stored in the bus driver and must be deleted by a call to<br />

<strong>USB</strong>H_DestroyInterfaceList. The list contains a snapshot of interfaces available at<br />

the point of time where the function is called. This enables the application to have a fixed<br />

relation between the index and a <strong>USB</strong> interface in a list. The list is not updated if a device is<br />

removed or connected. A new list must be created to capture the current available interfaces.<br />

This function is non blocking.<br />

See Also<br />

<strong>USB</strong>H_DestroyInterfaceList (page 42)<br />

<strong>USB</strong>H_GetInterfaceID (page 43)<br />

<strong>USB</strong>H_GetInterfaceInfo (page 44)<br />

<strong>USB</strong>H_INTERFACE_MASK (page 90)<br />

<strong>USB</strong> Bus Driver Reference Manual 41


8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong>H_DestroyInterfaceList<br />

This function deletes a previously generated interface list.<br />

Definition<br />

void<br />

<strong>USB</strong>H_DestroyInterfaceList(<br />

<strong>USB</strong>H_INTERFACE_LIST_HANDLE InterfaceListHandle<br />

);<br />

Parameter<br />

InterfaceListHandle<br />

This parameter contains the handle for the interface list and must not be NULL.<br />

Comments<br />

This function deletes an interface list generated by a previous call to<br />

<strong>USB</strong>H_CreateInterfaceList. If an interface list is not deleted the <strong>USB</strong> Bus Driver<br />

Core has a memory leak.<br />

This function is non blocking.<br />

See Also<br />

<strong>USB</strong>H_CreateInterfaceList (page 41)<br />

42 <strong>USB</strong> Bus Driver Reference Manual


<strong>USB</strong>H_GetInterfaceID<br />

This function returns the interface ID for a specified interface.<br />

Definition<br />

<strong>USB</strong>H_INTERFACE_ID<br />

<strong>USB</strong>H_GetInterfaceID(<br />

<strong>USB</strong>H_INTERFACE_LIST_HANDLE InterfaceListHandle,<br />

T_UINT32 Index<br />

);<br />

Parameters<br />

InterfaceListHandle<br />

This parameter contains the handle for an interface list generated by a call to<br />

<strong>USB</strong>H_CreateInterfaceList.<br />

8 <strong>USB</strong> Bus Driver Reference<br />

Index<br />

This parameter specifies the zero based index for a specific interface in the list.<br />

Return Value<br />

On success the interface ID for the interface specified by Index is returned. If the interface<br />

index does not exist the function returns 0.<br />

Comments<br />

The interface ID identifies a <strong>USB</strong> interface as long as the device is connected to the host. If<br />

the device is removed and re-connected a new interface ID is assigned. The interface ID is<br />

even valid if the interface list is deleted. The function can return an interface ID even if the<br />

device is removed between the call to the function <strong>USB</strong>H_CreateInterfaceList and the<br />

call to this function. In this case a call to the function <strong>USB</strong>H_OpenInterface using this<br />

interface ID will fail.<br />

This function is non blocking.<br />

See Also<br />

<strong>USB</strong>H_CreateInterfaceList (page 41)<br />

<strong>USB</strong>H_OpenInterface (page 53)<br />

<strong>USB</strong> Bus Driver Reference Manual 43


8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong>H_GetInterfaceInfo<br />

This function obtains information about a specified interface.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

<strong>USB</strong>H_GetInterfaceInfo(<br />

<strong>USB</strong>H_INTERFACE_ID InterfaceID,<br />

<strong>USB</strong>H_INTERFACE_INFO* InterfaceInfo<br />

);<br />

Parameters<br />

InterfaceID<br />

This parameter specifies the interface by its interface ID.<br />

InterfaceInfo<br />

This parameter points to a caller provided data structure <strong>USB</strong>H_INTERFACE_INFO and<br />

retrieves the information about the interface.<br />

Return Value<br />

The function returns <strong>USB</strong>H_STATUS_SUCCESS on success or<br />

<strong>USB</strong>H_STATUS_DEVICE_REMOVED if the specified interface is removed.<br />

Comments<br />

This function can be used to identify a <strong>USB</strong> interface without open it. More detailed<br />

information can be requests after the <strong>USB</strong> interface is opened.<br />

This function is non blocking.<br />

See Also<br />

<strong>USB</strong>H_INTERFACE_INFO (page 92)<br />

<strong>USB</strong>H_GetInterfaceID (page 43)<br />

<strong>USB</strong>H_OpenInterface (page 53)<br />

44 <strong>USB</strong> Bus Driver Reference Manual


<strong>USB</strong>H_WaitForIdle<strong>Stack</strong><br />

Call this function to make sure de-installed callback functions are not called.<br />

Definition<br />

int<br />

<strong>USB</strong>H_WaitForIdle<strong>Stack</strong>(<br />

T_UINT32 TimeoutMS<br />

);<br />

Parameter<br />

8 <strong>USB</strong> Bus Driver Reference<br />

TimeoutMS<br />

This parameter can be either a timeout in milliseconds or the constant TAL_WAIT_INFINITE.<br />

Return Value<br />

The function returns the following status codes:<br />

TAL_WAIT_TIMEOUT - The timeout interval elapsed, the stack is busy. Call the function<br />

later again.<br />

TAL_WAIT_SIGNALED - The stack was idle. The memory that is used by the callback<br />

function can be freed.<br />

Comments<br />

The callback functions are not called under the Mutex of the host stack. This allows the user<br />

to call non blocking functions directly from the callback functions. On the other hand the<br />

un-registering of a callback function is not an atomic operation. The callback function may be<br />

called from the host stack after it was unregistered by the application. This situation is difficult<br />

to handle when the application wants to free the resources that are used in the callback<br />

function. When a callback function is un-registered this function should be called afterwards.<br />

When this function returns with TAL_WAIT_SIGNALED the unregistered callback function<br />

is no more called by the host stack. It is safe to free the related resources.<br />

When this function blocks for a longer time, maybe a deadlock has been occurred. To detect<br />

such a situation the timeout option can be used.<br />

This function is blocking.<br />

See Also<br />

<strong>USB</strong>H_UnregisterPnPNotification (page 48)<br />

<strong>USB</strong> Bus Driver Reference Manual 45


8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong>H_PnpNotification<br />

Prototype for a callback that is called by the <strong>USB</strong> Bus Driver Core if a PnP event occurs and if a<br />

PnP notification was registered.<br />

Definition<br />

typedef<br />

void<br />

<strong>USB</strong>H_PnpNotification(<br />

void* Context,<br />

<strong>USB</strong>H_PNP_EVENT Event,<br />

<strong>USB</strong>H_INTERFACE_ID InterfaceID<br />

);<br />

Parameters<br />

Context<br />

This parameter is the user defined pointer that was passed to<br />

<strong>USB</strong>H_RegisterPnPNotification. The <strong>USB</strong> Bus Driver Core does not modify this<br />

parameter.<br />

Event<br />

This parameter is of type <strong>USB</strong>H_PNP_EVENT and specifies the PnP event.<br />

InterfaceID<br />

This member contains the interface ID of the removed or added interface.<br />

Comments<br />

This function is called in the context of a TAL timer. In the context of this function all other<br />

non-blocking API functions of the bus driver can be called. The removed or added interface<br />

can be identified by the interface ID. The client can use this information to find the related<br />

<strong>USB</strong> Interface to close all handles if it was in use, to open it or to collect information about the<br />

interface.<br />

In the context of this function blocking functions must not be called.<br />

See Also<br />

<strong>USB</strong>H_PNP_EVENT (page 114)<br />

<strong>USB</strong>H_RegisterPnPNotification (page 47)<br />

<strong>USB</strong>H_GetInterfaceInfo (page 44)<br />

<strong>USB</strong>H_OpenInterface (page 53)<br />

46 <strong>USB</strong> Bus Driver Reference Manual


<strong>USB</strong>H_RegisterPnPNotification<br />

This function registers a notification function for PnP events.<br />

Definition<br />

<strong>USB</strong>H_NOTIFICATION_HANDLE<br />

<strong>USB</strong>H_RegisterPnPNotification(<br />

<strong>USB</strong>H_PNP_NOTIFICATION* PnPNotification<br />

);<br />

Parameter<br />

PnPNotification<br />

This parameter contains a pointer to a caller provided structure<br />

<strong>USB</strong>H_PNP_NOTIFICATION. This structure must be filled in by the caller.<br />

Return Value<br />

8 <strong>USB</strong> Bus Driver Reference<br />

On success a valid handle is returned. If the function fails it returns NULL which is an invalid<br />

handle value.<br />

Comments<br />

If a valid handle is returned, the function <strong>USB</strong>H_UnregisterPnPNotification must<br />

be called to release the notification. An application can register any number of notifications.<br />

The user notification routine is called in the context of a notify timer that is global for all <strong>USB</strong><br />

bus PnP notifications.<br />

If this function is called while the bus driver has already enumerated devices that match the<br />

<strong>USB</strong>H_INTERFACE_MASK the function <strong>USB</strong>H_PnpNotification is called for each<br />

matching interface.<br />

The mask can be set to 0. In this case all devices causes a PnP notification.<br />

This function is non blocking.<br />

See Also<br />

<strong>USB</strong>H_PNP_NOTIFICATION (page 110)<br />

<strong>USB</strong>H_INTERFACE_MASK (page 90)<br />

<strong>USB</strong>H_UnregisterPnPNotification (page 48)<br />

<strong>USB</strong>H_PnpNotification (page 46)<br />

<strong>USB</strong> Bus Driver Reference Manual 47


8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong>H_UnregisterPnPNotification<br />

This function unregister a previously registered notification for PnP events.<br />

Definition<br />

void<br />

<strong>USB</strong>H_UnregisterPnPNotification(<br />

<strong>USB</strong>H_NOTIFICATION_HANDLE Handle<br />

);<br />

Parameter<br />

Handle<br />

This parameter contains the valid handle for a PnP notification previously registered by a call<br />

to <strong>USB</strong>H_RegisterPnPNotification.<br />

Comments<br />

This function has to be called for each PnP notification that was successfully registered by a<br />

call to <strong>USB</strong>H_RegisterPnPNotification.<br />

A callback can be scheduled when this function returns. To make sure that the unregistered<br />

callback function is not called, call the function <strong>USB</strong>H_WaitForIdle<strong>Stack</strong>.<br />

The function is non blocking.<br />

See Also<br />

<strong>USB</strong>H_RegisterPnPNotification (page 47)<br />

<strong>USB</strong>H_WaitForIdle<strong>Stack</strong> (page 45)<br />

48 <strong>USB</strong> Bus Driver Reference Manual


<strong>USB</strong>H_EnumErrorNotification<br />

8 <strong>USB</strong> Bus Driver Reference<br />

Prototype for a callback that is called by the <strong>USB</strong> Bus Driver Core if an error occurs during port<br />

or device initialization.<br />

Definition<br />

typedef<br />

void<br />

<strong>USB</strong>H_EnumErrorNotification(<br />

void* Context,<br />

const <strong>USB</strong>H_ENUM_ERROR* EnumError<br />

);<br />

Parameters<br />

Context<br />

This parameter is a user defined pointer that was passed to<br />

<strong>USB</strong>H_RegisterEnumErrorNotification.<br />

EnumError<br />

This parameter is of type <strong>USB</strong>H_ENUM_ERROR and specifies the enumeration error. This<br />

pointer is temporary and must not be accessed after the function returns.<br />

Comments<br />

This function is called in the context of a TAL timer or ProcessInterrupt function of a host<br />

controller. Before this function is called it must be registered with<br />

<strong>USB</strong>H_RegisterEnumErrorNotification. If a device is not successfully enumerated<br />

the function <strong>USB</strong>H_RestartEnumError can be called to restart a new enumeration in the<br />

context of this function.<br />

This callback mechanism is part of the enhanced error recovery. In an embedded system with<br />

internal components connected with <strong>USB</strong> a central application may turn off the power supply<br />

for some device to force a reboot or to create an alert.<br />

In the context of this function no blocking function must be called.<br />

See Also<br />

<strong>USB</strong>H_ENUM_ERROR (page 94)<br />

<strong>USB</strong>H_RegisterEnumErrorNotification (page 50)<br />

<strong>USB</strong>H_UnregisterEnumErrorNotification (page 51)<br />

<strong>USB</strong>H_RestartEnumError (page 52)<br />

<strong>USB</strong> Bus Driver Reference Manual 49


8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong>H_RegisterEnumErrorNotification<br />

This function registers a port error enumeration notification.<br />

Definition<br />

<strong>USB</strong>H_ENUM_ERROR_HANDLE<br />

<strong>USB</strong>H_RegisterEnumErrorNotification(<br />

void* Context,<br />

<strong>USB</strong>H_EnumErrorNotification* EnumErrorCallback<br />

);<br />

Parameters<br />

Context<br />

This parameter is a user defined pointer that is passed unchanged to the notification callback<br />

function <strong>USB</strong>H_EnumErrorNotification.<br />

EnumErrorCallback<br />

This parameter contains the notification function that is called from the <strong>USB</strong> Bus Driver Core<br />

if a port enumeration error occurs.<br />

Return Value<br />

On success a valid handle is returned. If the function fails this function returns NULL which is<br />

an invalid handle value.<br />

Comments<br />

If a valid handle is returned, the function <strong>USB</strong>H_RegisterEnumErrorNotification<br />

must be called to release the notification. The EnumErrorCallback callback routine is<br />

called in the context of the process where the interrupt status of a host controller is processed<br />

(e.g. <strong>USB</strong>H_ProcessInterrupt). It is forbidden to wait in that context.<br />

This function is non blocking.<br />

See Also<br />

<strong>USB</strong>H_RegisterEnumErrorNotification (page 50)<br />

50 <strong>USB</strong> Bus Driver Reference Manual


<strong>USB</strong>H_UnregisterEnumErrorNotification<br />

8 <strong>USB</strong> Bus Driver Reference<br />

This function unregister a previously registered port error enumeration notification.<br />

Definition<br />

void<br />

<strong>USB</strong>H_UnregisterEnumErrorNotification(<br />

<strong>USB</strong>H_ENUM_ERROR_HANDLE Handle<br />

);<br />

Parameter<br />

Handle<br />

This parameter contains the valid handle for the notification returned by a previous call to<br />

<strong>USB</strong>H_RegisterEnumErrorNotification.<br />

Comments<br />

This function has to be called for each port enumeration error notification that was<br />

successfully registered by a call to <strong>USB</strong>H_RegisterEnumErrorNotification.<br />

A callback can be scheduled when this function returns. To make sure that the unregistered<br />

callback function is not called, call the function <strong>USB</strong>H_WaitForIdle<strong>Stack</strong>.<br />

This function is non blocking.<br />

See Also<br />

<strong>USB</strong>H_RegisterEnumErrorNotification (page 50)<br />

<strong>USB</strong>H_WaitForIdle<strong>Stack</strong> (page 45)<br />

<strong>USB</strong> Bus Driver Reference Manual 51


8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong>H_RestartEnumError<br />

Restart the enumeration for all devices that have failed in the enumeration process.<br />

Definition<br />

void<br />

<strong>USB</strong>H_RestartEnumError();<br />

Comments<br />

The bus driver retries each enumeration again until the default retry count is reached.<br />

This function is non blocking.<br />

See Also<br />

<strong>USB</strong>H_EnumErrorNotification (page 49)<br />

52 <strong>USB</strong> Bus Driver Reference Manual


<strong>USB</strong>H_OpenInterface<br />

This function opens the specified interface.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

<strong>USB</strong>H_OpenInterface(<br />

<strong>USB</strong>H_INTERFACE_ID InterfaceID,<br />

T_BOOL Exclusive,<br />

<strong>USB</strong>H_INTERFACE_HANDLE* InterfaceHandle<br />

);<br />

Parameters<br />

8 <strong>USB</strong> Bus Driver Reference<br />

InterfaceID<br />

This parameter specifies the interface to open by its interface ID. The interface ID can be<br />

obtained by a call to <strong>USB</strong>H_PnpNotification or <strong>USB</strong>H_GetInterfaceID.<br />

Exclusive<br />

This parameter specifies if the interface should be opened exclusive or not. If the value is<br />

T_TRUE the interface is opened exclusive.<br />

InterfaceHandle<br />

This parameter returns the handle for the opened interface on success.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise. The function can fail if the device was removed or the device is opened<br />

exclusive by another application. The function returns with an error if the exclusive flag is set<br />

or another application has an open handle to the interface.<br />

Comments<br />

The handle returned by this function is used by all other functions that perform data transfer.<br />

The returned handle must be closed with <strong>USB</strong>H_CloseInterface if it is no longer<br />

required.<br />

This function is non blocking.<br />

See Also<br />

<strong>USB</strong>H_CloseInterface (page 54)<br />

<strong>USB</strong>H_PnpNotification (page 46)<br />

<strong>USB</strong>H_GetInterfaceID (page 43)<br />

<strong>USB</strong> Bus Driver Reference Manual 53


8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong>H_CloseInterface<br />

This function closes a previously opened interface.<br />

Definition<br />

void<br />

<strong>USB</strong>H_CloseInterface(<br />

<strong>USB</strong>H_INTERFACE_HANDLE Handle<br />

);<br />

Parameter<br />

Handle<br />

This parameter contains the handle for an interface opened by a previous call to<br />

<strong>USB</strong>H_OpenInterface. The handle must not be NULL.<br />

Comments<br />

Each handle must be closed exactly one time. The <strong>USB</strong> Bus Driver Core accesses invalid<br />

memory if this function is called with an invalid handle.<br />

This function is non blocking.<br />

See Also<br />

<strong>USB</strong>H_OpenInterface (page 53)<br />

54 <strong>USB</strong> Bus Driver Reference Manual


<strong>USB</strong>H_GetDeviceDescriptor<br />

This function retrieves the device descriptor.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

<strong>USB</strong>H_GetDeviceDescriptor(<br />

<strong>USB</strong>H_INTERFACE_HANDLE Handle,<br />

T_UINT8* Descriptor,<br />

T_UINT32 Size,<br />

T_UINT32* Count<br />

);<br />

Parameters<br />

Handle<br />

This parameter specifies the interface by its interface handle.<br />

8 <strong>USB</strong> Bus Driver Reference<br />

Descriptor<br />

This parameter points to a caller provided buffer that retrieves the device descriptor on success.<br />

Size<br />

This parameter specifies the size of the caller provided buffer.<br />

Count<br />

This parameter returns the length of the returned descriptor.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or<br />

<strong>USB</strong>H_STATUS_DEVICE_REMOVED if the device is removed.<br />

Comments<br />

This function returns a copy of the device descriptor and does not access the device. If the user<br />

provided buffer is smaller than the device descriptor the function returns the first part of it.<br />

This function is non blocking.<br />

See Also<br />

<strong>USB</strong>H_OpenInterface (page 53)<br />

<strong>USB</strong>H_GetCurrentConfigurationDescriptor (page 56)<br />

<strong>USB</strong> Bus Driver Reference Manual 55


8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong>H_GetCurrentConfigurationDescriptor<br />

This function retrieves the current configuration descriptor.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

<strong>USB</strong>H_GetCurrentConfigurationDescriptor(<br />

<strong>USB</strong>H_INTERFACE_HANDLE Handle,<br />

T_UINT8* Descriptor,<br />

T_UINT32 Size,<br />

T_UINT32* Count<br />

);<br />

Parameters<br />

Handle<br />

This parameter specifies the interface by its interface handle.<br />

Descriptor<br />

This parameter points to a caller provided buffer that retrieves the current configuration<br />

descriptor on success.<br />

Size<br />

This parameter specifies the size of the caller provided buffer.<br />

Count<br />

This parameter returns the number of valid bytes.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or<br />

<strong>USB</strong>H_STATUS_DEVICE_REMOVED if the device is removed.<br />

Comments<br />

This function returns a copy of the current configuration descriptor. The descriptor is a copy<br />

that was stored during the device enumeration. The function returns the first part of the<br />

descriptor if the user provided buffer is smaller than the descriptor. This descriptor contains all<br />

interface, endpoint, and possible class descriptors. The size is variable. The current<br />

configuration descriptor is the descriptor return to the request with the index 0 if the device<br />

was enumerated the first time. It changes if the configuration is switch with<br />

URB_SET_CONFIGURATION. Other configuration descriptors of a multi-configuration<br />

device can be requested with URB_FUNCTION_CONTROL_REQUEST.<br />

This function is non blocking.<br />

56 <strong>USB</strong> Bus Driver Reference Manual


See Also<br />

<strong>USB</strong>H_OpenInterface (page 53)<br />

<strong>USB</strong>H_GetDeviceDescriptor (page 55)<br />

URB_SET_CONFIGURATION (page 105)<br />

8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong> Bus Driver Reference Manual 57


8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong>H_GetInterfaceDescriptor<br />

This function retrieves the interface descriptor.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

<strong>USB</strong>H_GetInterfaceDescriptor(<br />

<strong>USB</strong>H_INTERFACE_HANDLE Handle,<br />

T_UINT8 AlternateSetting,<br />

T_UINT8* Descriptor,<br />

T_UINT32 Size,<br />

T_UINT32* Count<br />

);<br />

Parameters<br />

Handle<br />

This parameter specifies the interface by its interface handle.<br />

AlternateSetting<br />

This parameter specifies the alternate setting for this interface.<br />

Descriptor<br />

This parameter points to a caller provided buffer that retrieves the interface descriptor on<br />

success.<br />

Size<br />

This parameter specifies the size of the caller provided buffer.<br />

Count<br />

This parameter returns the number of valid bytes in the descriptor.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or<br />

<strong>USB</strong>H_STATUS_DEVICE_REMOVED if the device is removed. The status<br />

<strong>USB</strong>H_STATUS_INVALID_PARAM is returned when the parameter AlternateSetting<br />

specifies an alternate setting that does not exists.<br />

Comments<br />

This function returns a copy of an interface descriptor. The interface descriptor belongs to the<br />

interface that is identified by the <strong>USB</strong>H_INTERFACE_HANDLE. If the interface has different<br />

alternate settings the interface descriptors of each alternate setting can be requested. The<br />

function returns a copy of this descriptor that was requested during the enumeration process.<br />

The interface descriptor is part of the configuration descriptor.<br />

This function is non blocking.<br />

58 <strong>USB</strong> Bus Driver Reference Manual


See Also<br />

<strong>USB</strong>H_OpenInterface (page 53)<br />

<strong>USB</strong>H_GetCurrentConfigurationDescriptor (page 56)<br />

8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong> Bus Driver Reference Manual 59


8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong>H_GetClassDescriptor<br />

This function searches a class descriptor for the related interface and returns a copy if it is<br />

successful.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

<strong>USB</strong>H_GetClassDescriptor(<br />

<strong>USB</strong>H_INTERFACE_HANDLE Handle,<br />

T_UINT8 AlternateSetting,<br />

T_INT16 Type,<br />

T_INT16 SubType,<br />

T_UINT8* Descriptor,<br />

T_UINT32 Size,<br />

T_UINT32* Count<br />

);<br />

Parameters<br />

Handle<br />

The interface handle.<br />

AlternateSetting<br />

The alternate setting where the class descriptor is searched.<br />

Type<br />

The type of the descriptor or -1 for don’t care.<br />

SubType<br />

The sub-type of the descriptor or -1 for don’t care.<br />

Descriptor<br />

A caller provided memory that receives the copy of the descriptor.<br />

Size<br />

The size of the descriptor memory in bytes.<br />

Count<br />

Returns the byte count of the returned descriptor.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

The function is useful to find class information. When the descriptor is larger than the<br />

descriptor size the first part is returned. Some descriptors my not have a sub-type. In this case<br />

60 <strong>USB</strong> Bus Driver Reference Manual


set the sub-type parameter to -1.<br />

This function is non blocking.<br />

See Also<br />

<strong>USB</strong>H_OpenInterface (page 53)<br />

8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong> Bus Driver Reference Manual 61


8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong>H_GetEndpointDescriptor<br />

This function retrieves an endpoint descriptor.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

<strong>USB</strong>H_GetEndpointDescriptor(<br />

<strong>USB</strong>H_INTERFACE_HANDLE Handle,<br />

T_UINT8 AlternateSetting,<br />

const <strong>USB</strong>H_EP_MASK* Mask,<br />

T_UINT8* Descriptor,<br />

T_UINT32 Size,<br />

T_UINT32* Count<br />

);<br />

Parameters<br />

Handle<br />

This parameter specifies the interface by its interface handle.<br />

AlternateSetting<br />

This parameter specifies the alternate setting for the interface. The function returns the<br />

endpoint descriptors that are inside the specified alternate setting.<br />

Mask<br />

This parameter is of type <strong>USB</strong>H_EP_MASK and specifies a mask to select the endpoint.<br />

Descriptor<br />

This parameter specifies a pointer to the caller provided buffer that contains the endpoint<br />

descriptor on success.<br />

Size<br />

This parameter specifies the size of the caller provided buffer.<br />

Count<br />

This parameter returns the valid number of bytes written to the buffer.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise. The function fails if the endpoint can not be found or if the device is removed.<br />

Comments<br />

This function returns a copy of the endpoint descriptor that was captured during the<br />

enumeration process. The endpoint descriptor is part of the configuration descriptor.<br />

This function is non blocking.<br />

62 <strong>USB</strong> Bus Driver Reference Manual


See Also<br />

<strong>USB</strong>H_EP_MASK (page 96)<br />

<strong>USB</strong>H_OpenInterface (page 53)<br />

<strong>USB</strong>H_GetCurrentConfigurationDescriptor (page 56)<br />

8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong> Bus Driver Reference Manual 63


8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong>H_GetSerialNumber<br />

This function retrieves the serial number.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

<strong>USB</strong>H_GetSerialNumber(<br />

<strong>USB</strong>H_INTERFACE_HANDLE Handle,<br />

T_UINT8* Descriptor,<br />

T_UINT32 Size,<br />

T_UINT32* Count<br />

);<br />

Parameters<br />

Handle<br />

This parameter specifies the interface by its interface handle.<br />

Descriptor<br />

This parameter is a pointer to a caller provided buffer. It returns the serial number on success.<br />

Size<br />

This parameter specifies the size of the caller provided buffer in bytes.<br />

Count<br />

This parameter returns the number of bytes written to the buffer.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or<br />

<strong>USB</strong>H_STATUS_DEVICE_REMOVED if the device is removed.<br />

Comments<br />

It returns the serial number as a UNICODE string in <strong>USB</strong> little endian format. Count returns<br />

the number of valid bytes. The string is not zero terminated. The returned data does not<br />

contain a <strong>USB</strong> descriptor header. The descriptor is requested with the first language ID. This<br />

string is a copy of the serial number string that was requested during the enumeration process.<br />

To request other string descriptors use <strong>USB</strong>H_SubmitUrb.<br />

If the device does not support a <strong>USB</strong> serial number string the function returns success and<br />

Count is set to 0.<br />

This function is non blocking.<br />

64 <strong>USB</strong> Bus Driver Reference Manual


See Also<br />

<strong>USB</strong>H_OpenInterface (page 53)<br />

<strong>USB</strong>H_SubmitUrb (page 74)<br />

8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong> Bus Driver Reference Manual 65


8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong>H_GetSpeed<br />

This function retrieves the operation speed of the device.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

<strong>USB</strong>H_GetSpeed(<br />

<strong>USB</strong>H_INTERFACE_HANDLE Handle,<br />

<strong>USB</strong>H_SPEED* Speed<br />

);<br />

Parameters<br />

Handle<br />

This parameter specifies the interface by its interface handle.<br />

Speed<br />

This parameter returns the device operating speed of type <strong>USB</strong>H_SPEED.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or<br />

<strong>USB</strong>H_STATUS_DEVICE_REMOVED if the device is removed.<br />

Comments<br />

A high speed device can operate in full or high speed mode.<br />

This function is non blocking.<br />

See Also<br />

<strong>USB</strong>H_OpenInterface (page 53)<br />

<strong>USB</strong>H_SPEED (page 113)<br />

66 <strong>USB</strong> Bus Driver Reference Manual


<strong>USB</strong>H_GetFrameNumber<br />

This function retrieves the current frame number.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

<strong>USB</strong>H_GetFrameNumber(<br />

<strong>USB</strong>H_INTERFACE_HANDLE Handle,<br />

T_UINT32* FrameNumber<br />

);<br />

Parameters<br />

Handle<br />

This parameter specifies the interface by its interface handle.<br />

FrameNumber<br />

This parameter contains the current frame number on success.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or<br />

<strong>USB</strong>H_STATUS_DEVICE_REMOVED if the device is removed.<br />

Comments<br />

8 <strong>USB</strong> Bus Driver Reference<br />

The frame number is transferred on the bus with 11 bits. This frame number is returned as a<br />

16 or 32 bit number related to the implementation of the host controller. The last 11 bits are<br />

equal to the current frame. The frame number is increased each ms. This is the case for high<br />

speed, too. The returned frame number is related to the bus where the device is connected.<br />

The frame numbers can differ between different host controllers.<br />

This function is non blocking.<br />

See Also<br />

<strong>USB</strong>H_OpenInterface (page 53)<br />

<strong>USB</strong> Bus Driver Reference Manual 67


8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong>H_GetInterfaceIDByHandle<br />

This function retrieves the interface ID for a given interface.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

<strong>USB</strong>H_GetInterfaceIDByHandle(<br />

<strong>USB</strong>H_INTERFACE_HANDLE Handle,<br />

<strong>USB</strong>H_INTERFACE_ID* InterfaceID<br />

);<br />

Parameters<br />

Handle<br />

This parameter specifies the interface by its interface handle.<br />

InterfaceID<br />

This parameter contains the interface ID on success.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or<br />

<strong>USB</strong>H_STATUS_DEVICE_REMOVED if the device is removed.<br />

Comments<br />

This function returns the interface ID if the handle to the interface is available. This may be<br />

useful if a Plug and Play notification is received and the application checks if it is related to a<br />

given handle. The application can avoid calls to this function if the interface ID is stored in the<br />

device context of the application.<br />

This function is non blocking.<br />

See Also<br />

<strong>USB</strong>H_OpenInterface (page 53)<br />

<strong>USB</strong>H_GetInterfaceID (page 43)<br />

68 <strong>USB</strong> Bus Driver Reference Manual


<strong>USB</strong>H_GetHubPortHandlebyInterface<br />

This function retrieves the hub port handle for a given interface.<br />

Definition<br />

<strong>USB</strong>H_HUB_PORT_HANDLE<br />

<strong>USB</strong>H_GetHubPortHandlebyInterface(<br />

<strong>USB</strong>H_INTERFACE_HANDLE interfaceHandle<br />

);<br />

Parameter<br />

interfaceHandle<br />

This parameter specifies the interface by its interface handle.<br />

Return Value<br />

8 <strong>USB</strong> Bus Driver Reference<br />

This function returns a handle to a hub port or NULL which is an invalid handle value.<br />

Comments<br />

This function returns a hub port handle if the parent port of the device interface is a hub port.<br />

This function is non blocking.<br />

See Also<br />

<strong>USB</strong>H_GetHubPortHandlebyTopology (page 70)<br />

<strong>USB</strong>H_SetPortPowerState (page 71)<br />

<strong>USB</strong> Bus Driver Reference Manual 69


8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong>H_GetHubPortHandlebyTopology<br />

This function retrieves the hub port handle for a given port number array.<br />

Definition<br />

<strong>USB</strong>H_HUB_PORT_HANDLE<br />

<strong>USB</strong>H_GetHubPortHandlebyTopology(<br />

<strong>USB</strong>H_HC_HANDLE hcHandle,<br />

T_UINT32 portNumberItems,<br />

const T_UINT8* portNumber<br />

);<br />

Parameters<br />

hcHandle<br />

This handle was returned by the function <strong>USB</strong>H_CreateXXXController.<br />

portNumberItems<br />

Number of valid port numbers in the portNumber array.<br />

portNumber<br />

This pointer points to an array of port numbers. Each valid number is one based.<br />

Return Value<br />

This function returns a handle to a hub port or NULL which is an invalid handle value.<br />

Comments<br />

All values in the port Number array must be in the range from 1 to 127. The first element in<br />

the array is the root hub port number. All other port numbers are external hub ports.<br />

To address the second port of a external hub that is connected with the first root hub port the<br />

first port number in the portNumbers array is 1 and the second one is 2.<br />

This function is non blocking.<br />

See Also<br />

<strong>USB</strong>H_GetHubPortHandlebyInterface (page 69)<br />

<strong>USB</strong>H_SetPortPowerState (page 71)<br />

70 <strong>USB</strong> Bus Driver Reference Manual


<strong>USB</strong>H_SetPortPowerState<br />

This function set the port power.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

<strong>USB</strong>H_SetPortPowerState(<br />

<strong>USB</strong>H_HUB_PORT_HANDLE hubPortHandle,<br />

<strong>USB</strong>H_POWER_STATE powerState<br />

);<br />

Parameters<br />

hubPortHandle<br />

Hub port handle.<br />

8 <strong>USB</strong> Bus Driver Reference<br />

powerState<br />

This parameter is of type <strong>USB</strong>H_POWER_STATE and specifies the power state.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise. Now details of important errors:<br />

<strong>USB</strong>H_STATUS_INVALID_PARAM<br />

Invalid port handle or invalid power state.<br />

<strong>USB</strong>H_STATUS_BUSY<br />

Previous external hub URB power request not completed. Try it later.<br />

<strong>USB</strong>H_STATUS_RESOURCES<br />

No memory resources.<br />

Comments<br />

If the hub port is set to power state <strong>USB</strong>H_POWER_OFF a connected <strong>USB</strong> device is not<br />

recognized until the port power is switched on. If port power is changed the application should<br />

wait for a minimum time of about 100ms. Normally the user waits for adding of a device on<br />

this port and switch the port power off if the device is not needed. In that case it must wait a<br />

minimum time before the port power is switched on.<br />

This function is non blocking.<br />

See Also<br />

<strong>USB</strong>H_GetHubPortHandlebyInterface (page 69)<br />

<strong>USB</strong>H_GetHubPortHandlebyTopology (page 70)<br />

<strong>USB</strong> Bus Driver Reference Manual 71


8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong>H_GetPortPowerState<br />

This function set the port power.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

<strong>USB</strong>H_GetPortPowerState(<br />

<strong>USB</strong>H_HUB_PORT_HANDLE hubPortHandle,<br />

<strong>USB</strong>H_POWER_STATE* powerState<br />

);<br />

Parameters<br />

hubPortHandle<br />

Hub port handle.<br />

powerState<br />

This parameter is of type <strong>USB</strong>H_POWER_STATE and specifies the power state.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise. A reason for failure is that the port handle is invalid (removing of the hub<br />

device).<br />

Comments<br />

After the port power is switched off with <strong>USB</strong>H_SetPortPowerState the function returns<br />

<strong>USB</strong>H_POWER_OFF independent of the real port power status. If the port power is switched<br />

the function checks the real port power state until return.<br />

This function is non blocking.<br />

See Also<br />

<strong>USB</strong>H_GetHubPortHandlebyInterface (page 69)<br />

<strong>USB</strong>H_GetHubPortHandlebyTopology (page 70)<br />

72 <strong>USB</strong> Bus Driver Reference Manual


URB_COMPLETION<br />

Prototype for a callback function that is called if an URB is completed.<br />

Definition<br />

typedef<br />

void<br />

URB_COMPLETION(<br />

URB* Urb<br />

);<br />

Parameter<br />

Urb<br />

A pointer to the completed URB.<br />

Comments<br />

8 <strong>USB</strong> Bus Driver Reference<br />

The application can define a completion function for each URB. The pointer to this<br />

completion function is passed to the <strong>USB</strong> Bus Driver Core with the URB.<br />

The completion function is called in the context of a ProcessInterrupt function of the host<br />

controller or in a TAL timer function. The completion function can call API functions to<br />

submit URB’s (<strong>USB</strong>H_SubmitUrb) or get information from the device. The function must<br />

not close the interface handle with a call to <strong>USB</strong>H_CloseInterface. The function should<br />

not perform lengthy operations, because this may influence the performance of other <strong>USB</strong><br />

devices. A better solution is to set an event and perform these operations in a separate task.<br />

Do not call blocking function in the context of this callback function.<br />

See Also<br />

URB (page 108)<br />

URB_FUNCTION (page 116)<br />

URB_HEADER (page 111)<br />

<strong>USB</strong>H_CloseInterface (page 54)<br />

<strong>USB</strong> Bus Driver Reference Manual 73


8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong>H_SubmitUrb<br />

This function is used to submit an URB.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

<strong>USB</strong>H_SubmitUrb(<br />

<strong>USB</strong>H_INTERFACE_HANDLE Handle,<br />

URB* Urb<br />

);<br />

Parameters<br />

Handle<br />

This parameter specifies the interface by its interface handle.<br />

Urb<br />

This is an input and output parameter. On input it contains the URB which should be<br />

submitted. On output it contains the submitted URB with the appropriate status and the<br />

received data if any. The storage for the URB must be permanent as long as the request is<br />

pending. There can be special requirements for the data transfer buffers. For control transfers<br />

any memory can be used. For all other transfers the data transfer buffer must be DMA<br />

memory. For more information about this memory please see section 5.3 at page 29.<br />

Return Value<br />

If the function returns <strong>USB</strong>H_STATUS_PENDING the completion function will be called<br />

later. In all other cases the completion routine is never called. If the function returns success,<br />

the request was processed immediately. On error the request fail and can not be processed.<br />

Comments<br />

All URBs that are submitted with this function are handled asynchronously. If the status<br />

<strong>USB</strong>H_STATUS_PENDING is returned the ownership of the URB is passed to the bus driver.<br />

The storage of the URB must neither be freed nor modified as long as the ownership remains<br />

at the bus driver. The bus driver passes the URB back to the application by calling the<br />

completion routine. An URB that transfers data can remain pending for a long time.<br />

This function is non blocking.<br />

See Also<br />

URB_HEADER (page 111)<br />

URB_FUNCTION (page 116)<br />

URB (page 108)<br />

74 <strong>USB</strong> Bus Driver Reference Manual


<strong>USB</strong>H_GetStatusStr<br />

This function returns the status as a string constants.<br />

Definition<br />

const char*<br />

<strong>USB</strong>H_GetStatusStr(<br />

<strong>USB</strong>H_STATUS x<br />

);<br />

Parameter<br />

x<br />

This parameter specifies the status.<br />

Return Value<br />

An error string is returned.<br />

Comments<br />

8 <strong>USB</strong> Bus Driver Reference<br />

This function returns only an error string if the debug version of the <strong>USB</strong> Bus Driver Core is<br />

used (TB_DEBUG=1).<br />

This function is non blocking.<br />

<strong>USB</strong> Bus Driver Reference Manual 75


8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong>H_AbortEndpointAndWait<br />

This function issue an abort request to abort all pending requests on an endpoint and waits until<br />

the URB with the abort request is completed.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

<strong>USB</strong>H_AbortEndpointAndWait(<br />

<strong>USB</strong>H_INTERFACE_HANDLE interfaceHandle,<br />

unsigned char endpoint,<br />

TAL_EventObject waitEvent<br />

);<br />

Parameters<br />

interfaceHandle<br />

This parameter specifies the interface by its interface handle.<br />

endpoint<br />

The endpoint number including the direction bit. Use 0 for the default endpoint.<br />

waitEvent<br />

An event object used to wait for the completion of the request. This parameter is optional and<br />

can be NULL. If the parameter is NULL the function allocates an event object on its own and<br />

frees it before the function returns. With this parameter the caller can optimize the number of<br />

event allocations.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

When this function returns the URB with the abort request is completed. But the data URB’s<br />

can be completed delayed. The caller may wait until all pending URB’s are completed. It can<br />

be used for all endpoint types including endpoint 0.<br />

After aborting all pending requests the data toggle bit of the endpoint can get the wrong value.<br />

Therefor the function <strong>USB</strong>H_ResetEndpointAndWait must be called before a new data<br />

transfer is started on the endpoint.<br />

This is a blocking function.<br />

See Also<br />

<strong>USB</strong>H_OpenInterface (page 53)<br />

76 <strong>USB</strong> Bus Driver Reference Manual


<strong>USB</strong>H_SubmitUrb (page 74)<br />

<strong>USB</strong>H_ResetEndpointAndWait (page 80)<br />

8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong> Bus Driver Reference Manual 77


8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong>H_SubmitUrbAndWait<br />

This function submits an initialized URB and waits until the operation is finished or a timeout<br />

error has been occurred.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

<strong>USB</strong>H_SubmitUrbAndWait(<br />

<strong>USB</strong>H_INTERFACE_HANDLE interfaceHandle,<br />

URB* urb,<br />

unsigned long timeout,<br />

TAL_EventObject waitEvent<br />

);<br />

Parameters<br />

interfaceHandle<br />

This parameter specifies the interface by its interface handle.<br />

urb<br />

The caller provided initialized URB.<br />

timeout<br />

The timeout for the request in milliseconds.<br />

waitEvent<br />

An event object used to wait for the completion of the submitted URB. This parameter is<br />

optional and can be NULL. If the parameter is NULL the function allocates an event object on<br />

its own and frees it before the function returns. With this parameter the caller can optimize the<br />

number of event allocations.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise. When the timeout expires before the request is completed the request is<br />

aborted and the function returns <strong>USB</strong>H_STATUS_TIMEOUT.<br />

Comments<br />

In case of a timeout the caller cannot determine whether the request has been executed<br />

partially. An incomplete data transfer may cause a data lost. Do not use this function to poll an<br />

endpoint for data.<br />

This is a blocking function.<br />

78 <strong>USB</strong> Bus Driver Reference Manual


See Also<br />

<strong>USB</strong>H_OpenInterface (page 53)<br />

<strong>USB</strong>H_SubmitUrb (page 74)<br />

8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong> Bus Driver Reference Manual 79


8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong>H_ResetEndpointAndWait<br />

This function issue a request to reset the specified endpoint and waits until the URB with the<br />

reset request is completed or a timeout error has been occurred.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

<strong>USB</strong>H_ResetEndpointAndWait(<br />

<strong>USB</strong>H_INTERFACE_HANDLE interfaceHandle,<br />

unsigned char endpoint,<br />

unsigned long timeout,<br />

TAL_EventObject waitEvent<br />

);<br />

Parameters<br />

interfaceHandle<br />

This parameter specifies the interface by its interface handle.<br />

endpoint<br />

The endpoint number including the direction bit. Use 0 for the default endpoint.<br />

timeout<br />

The timeout for the request in milliseconds.<br />

waitEvent<br />

An event object used to wait for the completion of the request. This parameter is optional and<br />

can be NULL. If the parameter is NULL the function allocates an event object on its own and<br />

frees it before the function returns. With this parameter the caller can optimize the number of<br />

event allocations.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise. When the timeout expires before the request is completed the request is<br />

aborted and the function returns <strong>USB</strong>H_STATUS_TIMEOUT.<br />

Comments<br />

To reset the endpoint a Clear Feature Endpoint stall is sent to the device. Also the data toggle<br />

bit of the endpoint is reseted by the bus driver. Therefor the next data transfer on the endpoint<br />

will start with a DATA0 packet.<br />

The caller of this function must make sure that no pending request is on the endpoint. Call<br />

<strong>USB</strong>H_AbortEndpointAndWait to abort all pending requests on the endpoint.<br />

This is a blocking function.<br />

80 <strong>USB</strong> Bus Driver Reference Manual


See Also<br />

<strong>USB</strong>H_AbortEndpointAndWait (page 76)<br />

8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong> Bus Driver Reference Manual 81


8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong>H_ResetDeviceAndWait<br />

This function issue a request to reset the device that corresponds to the specified interface and<br />

waits until URB with the reset request is completed or a timeout error has been occurred.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

<strong>USB</strong>H_ResetDeviceAndWait(<br />

<strong>USB</strong>H_INTERFACE_HANDLE interfaceHandle,<br />

unsigned long timeout,<br />

TAL_EventObject waitEvent<br />

);<br />

Parameters<br />

interfaceHandle<br />

This parameter specifies the interface by its interface handle.<br />

timeout<br />

The timeout for the request in milliseconds.<br />

waitEvent<br />

An event object used to wait for the completion of the request. This parameter is optional and<br />

can be NULL. If the parameter is NULL the function allocates an event object on its own and<br />

frees it before the function returns. With this parameter the caller can optimize the number of<br />

event allocations.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise. When the timeout expires before the request is completed the request is<br />

aborted and the function returns <strong>USB</strong>H_STATUS_TIMEOUT.<br />

Comments<br />

When a device is reseted the device is freshly enumerated. This causes a remove event for all<br />

interfaces of the device. All handles to an interface of the device and their corresponding<br />

interface IDs will become invalid. The caller should abort all pending requests and close all<br />

handles to the interfaces of the reseted device.<br />

After enumeration all interfaces of the reseted device get new interface IDs. If the caller has<br />

registered for PnP notification for the interfaces of the device he will get an arrival event for<br />

each interface. To register for PnP notification use the function<br />

<strong>USB</strong>H_RegisterPnPNotification.<br />

This is a blocking function.<br />

82 <strong>USB</strong> Bus Driver Reference Manual


See Also<br />

<strong>USB</strong>H_AbortEndpointAndWait (page 76)<br />

<strong>USB</strong>H_CloseInterface (page 54)<br />

<strong>USB</strong>H_RegisterPnPNotification (page 47)<br />

8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong> Bus Driver Reference Manual 83


8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong>H_SetConfigurationAndWait<br />

This function issue a request to set the configuration with given configuration index and waits<br />

until the URB with the set configuration request is completed or a timeout error has been<br />

occurred.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

<strong>USB</strong>H_SetConfigurationAndWait(<br />

<strong>USB</strong>H_INTERFACE_HANDLE interfaceHandle,<br />

unsigned char configurationIndex,<br />

unsigned long timeout,<br />

TAL_EventObject waitEvent<br />

);<br />

Parameters<br />

interfaceHandle<br />

This parameter specifies the interface by its interface handle.<br />

configurationIndex<br />

The index of the configuration to set.<br />

timeout<br />

The timeout for the request in milliseconds.<br />

waitEvent<br />

An event object used to wait for the completion of the request. This parameter is optional and<br />

can be NULL. If the parameter is NULL the function allocates an event object on its own and<br />

frees it before the function returns. With this parameter the caller can optimize the number of<br />

event allocations.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise. When the timeout expires before the request is completed the request is<br />

aborted and the function returns <strong>USB</strong>H_STATUS_TIMEOUT.<br />

Comments<br />

On default the bus driver selects the configuration defined by the configuration descriptor with<br />

the index 0 during the enumeration. As long as the application uses this configuration there is<br />

no need to call this function.<br />

When a new configuration is set the bus driver performs a complete new enumeration with the<br />

device. This causes a remove event for all interfaces of the device. All handles to an interface<br />

84 <strong>USB</strong> Bus Driver Reference Manual


8 <strong>USB</strong> Bus Driver Reference<br />

of the device and their corresponding interface IDs will become invalid. The caller should<br />

abort all pending requests and close all handles to the interfaces of the device.<br />

After enumeration with the new configuration all interfaces of the device get new interface<br />

IDs. If the caller has registered for PnP notification for the interfaces of the device he will get<br />

an arrival event for each interface. To register for PnP notification use the function<br />

<strong>USB</strong>H_RegisterPnPNotification.<br />

This is a blocking function.<br />

See Also<br />

<strong>USB</strong>H_AbortEndpointAndWait (page 76)<br />

<strong>USB</strong>H_CloseInterface (page 54)<br />

<strong>USB</strong>H_RegisterPnPNotification (page 47)<br />

<strong>USB</strong> Bus Driver Reference Manual 85


8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong>H_SetInterfaceAndWait<br />

This function issue a set interface request to set the given alternate setting and waits until the<br />

URB with the set interface request is completed or a timeout error has been occurred.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

<strong>USB</strong>H_SetInterfaceAndWait(<br />

<strong>USB</strong>H_INTERFACE_HANDLE interfaceHandle,<br />

unsigned char alternateSetting,<br />

unsigned long timeout,<br />

TAL_EventObject waitEvent<br />

);<br />

Parameters<br />

interfaceHandle<br />

This parameter specifies the interface by its interface handle.<br />

alternateSetting<br />

The alternate setting to set.<br />

timeout<br />

The timeout for the request in milliseconds.<br />

waitEvent<br />

An event object used to wait for the completion of the request. This parameter is optional and<br />

can be NULL. If the parameter is NULL the function allocates an event object on its own and<br />

frees it before the function returns. With this parameter the caller can optimize the number of<br />

event allocations.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise. When the timeout expires before the request is completed the request is<br />

aborted and the function returns <strong>USB</strong>H_STATUS_TIMEOUT.<br />

Comments<br />

To set a new alternate setting for the specified interface there must be no pending requests on<br />

any endpoint of this interface. Call <strong>USB</strong>H_AbortEndpointAndWait to abort all pending<br />

requests on an endpoint.<br />

The interface handle does not becomes invalid during this operation. The number of endpoints<br />

may be changed.<br />

86 <strong>USB</strong> Bus Driver Reference Manual


See Also<br />

<strong>USB</strong>H_AbortEndpointAndWait (page 76)<br />

8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong> Bus Driver Reference Manual 87


8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong>H_SetupRequestAndWait<br />

This function sends a setup request to the device and waits until the URB with the setup request<br />

is completed or a timeout error has been occurred.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

<strong>USB</strong>H_SetupRequestAndWait(<br />

<strong>USB</strong>H_INTERFACE_HANDLE interfaceHandle,<br />

T_UsbSetupPacket* setup,<br />

void* buffer,<br />

T_UINT16* length,<br />

unsigned long timeout,<br />

TAL_EventObject waitEvent<br />

);<br />

Parameters<br />

interfaceHandle<br />

This parameter specifies the interface by its interface handle.<br />

setup<br />

The setup packet for the request. The setup packet need not be allocated as DMA capable<br />

memory. The driver takes care to use DMA capable memory if necessary.<br />

buffer<br />

Pointer to a caller provided buffer that is used in the data phase to transfer data. This<br />

parameter is optional and can be NULL. The direction of the data transfer depends on the<br />

bmRequestType fiel in the setup packet. See the <strong>USB</strong> specification for detailed<br />

information. The memory of the buffer need not be allocated as DMA capable memory. The<br />

driver takes care to use DMA capable memory if necessary.<br />

length<br />

Pointer to a caller provided variable. This is an input and output parameter. On input it<br />

contains the size of the buffer. On output the number of bytes transferred during the data phase<br />

are returned. The parameter can be NULL if buffer is NULL.<br />

timeout<br />

The timeout for the request in milliseconds.<br />

waitEvent<br />

An event object used to wait for the completion of the request. This parameter is optional and<br />

can be NULL. If the parameter is NULL the function allocates an event object on its own and<br />

frees it before the function returns. With this parameter the caller can optimize the number of<br />

event allocations.<br />

88 <strong>USB</strong> Bus Driver Reference Manual


Return Value<br />

8 <strong>USB</strong> Bus Driver Reference<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise. When the timeout expires before the request is completed the request is<br />

aborted and the function returns <strong>USB</strong>H_STATUS_TIMEOUT.<br />

Comments<br />

A setup request consists of a setup phase, an optional data phase and a handshake phase. The<br />

data phase is limited to a length of 4096 bytes. The Setup structure must be filled in<br />

properly. The wLength field in the Setup must contain the size of the buffer.<br />

This function can be used to send any standard, class or vendor specific request to the device.<br />

Even standard requests like SetAddress can be send but would destroy the multiplexing of the<br />

bus driver. It is not allowed to send the following standard requests:<br />

SetAddress<br />

This is assigned by the bus driver during enumeration or <strong>USB</strong> reset.<br />

Clear Feature Endpoint Halt<br />

Use <strong>USB</strong>H_ResetEndpointAndWait instead.<br />

SetConfiguration<br />

Use <strong>USB</strong>H_SetConfigurationAndWait instead. The bus driver has to take care on<br />

the interfaces and endpoints of a configuration. The function<br />

<strong>USB</strong>H_SetConfigurationAndWait updates the internal structures of the driver.<br />

See Also<br />

<strong>USB</strong>H_ResetEndpointAndWait (page 80)<br />

<strong>USB</strong>H_SetConfigurationAndWait (page 84)<br />

<strong>USB</strong> Bus Driver Reference Manual 89


8 <strong>USB</strong> Bus Driver Reference<br />

8.2 Structures<br />

<strong>USB</strong>H_INTERFACE_MASK<br />

This data structure is used to describe a device.<br />

Definition<br />

typedef struct tag_<strong>USB</strong>H_INTERFACE_MASK{<br />

unsigned short Mask;<br />

unsigned short VID;<br />

unsigned short PID;<br />

unsigned short bcdDevice;<br />

T_UINT8 Interface;<br />

T_UINT8 AlternateSetting;<br />

T_UINT8 Class;<br />

T_UINT8 SubClass;<br />

T_UINT8 Protocol;<br />

<strong>USB</strong>H_DEVICE_ID DeviceID;<br />

} <strong>USB</strong>H_INTERFACE_MASK;<br />

Members<br />

Mask<br />

This member contains an or’ ed selection of the following flags. If the flag is set the related<br />

member of this structure is compared to the properties of the <strong>USB</strong> interface.<br />

<strong>USB</strong>H_INFO_MASK_VID<br />

Compare the vendor ID (VID) of the device.<br />

<strong>USB</strong>H_INFO_MASK_PID<br />

Compare the product ID (PID) of the device.<br />

<strong>USB</strong>H_INFO_MASK_DEVICE<br />

Compare the bcdDevice value of the device.<br />

<strong>USB</strong>H_INFO_MASK_INTERFACE<br />

Compare the interface number.<br />

<strong>USB</strong>H_INFO_MASK_ALTERNATE<br />

Compare the alternate setting.<br />

<strong>USB</strong>H_INFO_MASK_CLASS<br />

Compare the class of the interface.<br />

<strong>USB</strong>H_INFO_MASK_SUBCLASS<br />

Compare the sub class of the interface.<br />

<strong>USB</strong>H_INFO_MASK_PROTOCOL<br />

Compare the protocol of the interface.<br />

<strong>USB</strong>H_INFO_MASK_DEVICE_ID<br />

Compare the device ID.<br />

<strong>USB</strong>H_INFO_MASK_DEFAULT<br />

The notification handler is called when a new device is plugged in and no other registered<br />

info mask do match.<br />

90 <strong>USB</strong> Bus Driver Reference Manual


VID<br />

This member contains the vendor ID to be compared.<br />

PID<br />

This member contains the product ID to be compared.<br />

bcdDevice<br />

This member contains the BCD coded device version to be compared.<br />

Interface<br />

This member contains the interface number to be compared.<br />

AlternateSetting<br />

This member contains the alternate setting to be compared.<br />

Class<br />

This member describes the class code stored in the interface.<br />

SubClass<br />

This member describes the sub class code stored in the interface.<br />

Protocol<br />

This member describes the protocol stored in the interface.<br />

DeviceID<br />

The member contains the device ID to be compared.<br />

Comments<br />

8 <strong>USB</strong> Bus Driver Reference<br />

This data structure is an input parameter to create an interface list or to register a PnP<br />

notification. The comparison with the mask is true if each member that is marked as valid by a<br />

flag in the Mask member is equal to the value stored in the corresponding value in the device<br />

(the device match the description defined with this structure).<br />

When creating an interface list only devices that match the description defined with this<br />

structure will be in the list. Similarly when used for registering of a PnP notification only<br />

devices that match the description defined with the structure will get a notification.<br />

See Also<br />

<strong>USB</strong>H_CreateInterfaceList (page 41)<br />

<strong>USB</strong>H_RegisterPnPNotification (page 47)<br />

<strong>USB</strong> Bus Driver Reference Manual 91


8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong>H_INTERFACE_INFO<br />

This structure contains information about a <strong>USB</strong> interface and the related device.<br />

Definition<br />

typedef struct tag_<strong>USB</strong>H_INTERFACE_INFO{<br />

<strong>USB</strong>H_INTERFACE_ID InterfaceID;<br />

<strong>USB</strong>_DEVICE_ID DeviceID;<br />

T_UINT16 VID;<br />

T_UINT16 PID;<br />

T_UINT16 bcdDevice;<br />

T_UINT8 Interface;<br />

T_UINT8 Class;<br />

T_UINT8 SubClass;<br />

T_UINT8 Protocol;<br />

T_UINT32 OpenCount;<br />

T_UINT8 ExclusiveUsed;<br />

<strong>USB</strong>_SPEED Speed;<br />

T_UINT8 SerialNumber[256];<br />

T_UINT8 SerialNumberSize;<br />

} <strong>USB</strong>H_INTERFACE_INFO;<br />

Members<br />

InterfaceID<br />

This member contains the unique interface ID. This ID is assigned if the <strong>USB</strong> device has been<br />

successfully enumerated. It is valid until the device is removed from the host. If the device is<br />

reconnected a different interface ID is assigned to each interface.<br />

DeviceID<br />

This member contains the unique device ID. This ID is assigned if the <strong>USB</strong> device has been<br />

successfully enumerated. It is valid until the device is removed from the host. If the device is<br />

reconnected a different device ID is assigned. The relation between the device ID and the<br />

interface ID can be used by an application to detect which <strong>USB</strong> interfaces belong to a device.<br />

VID<br />

This member contains the vendor ID.<br />

PID<br />

This member contains the product ID.<br />

bcdDevice<br />

This member contains the BCD coded device version.<br />

Interface<br />

This member contains the <strong>USB</strong> interface number.<br />

Class<br />

This member specifies the interface class.<br />

92 <strong>USB</strong> Bus Driver Reference Manual


SubClass<br />

This member specifies the interface sub class.<br />

Protocol<br />

This member specifies the interface protocol.<br />

OpenCount<br />

This member specifies the number of open handles for this interface.<br />

ExclusiveUsed<br />

This member determines if this interface is used exclusive.<br />

8 <strong>USB</strong> Bus Driver Reference<br />

Speed<br />

This member is of type <strong>USB</strong>H_SPEED and specifies the operation speed of this interface.<br />

SerialNumber[256]<br />

This member contains the serial number as a counted UNICODE string.<br />

SerialNumberSize<br />

This member contains the length of the serial number in bytes.<br />

Comments<br />

This structure is used to get information about a device with the function<br />

<strong>USB</strong>H_GetInterfaceInfo.<br />

See Also<br />

<strong>USB</strong>H_SPEED (page 113)<br />

<strong>USB</strong>H_GetInterfaceInfo (page 44)<br />

<strong>USB</strong> Bus Driver Reference Manual 93


8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong>H_ENUM_ERROR<br />

This structure contains information about an enumeration error.<br />

Definition<br />

typedef struct tag_<strong>USB</strong>H_ENUM_ERROR{<br />

int Flags;<br />

int PortNumber;<br />

<strong>USB</strong>H_STATUS Status;<br />

int ExtendedErrorInformation;<br />

} <strong>USB</strong>H_ENUM_ERROR;<br />

Members<br />

Flags<br />

Additional flags to determine the location and the type of the error.<br />

UDB_ENUM_ERROR_EXTHUBPORT_FLAG<br />

means the device is connected to an external hub.<br />

<strong>USB</strong>H_ENUM_ERROR_RETRY_FLAG<br />

the bus driver retries the enumeration of this device automatically.<br />

<strong>USB</strong>H_ENUM_ERROR_STOP_ENUM_FLAG<br />

the bus driver does not restart the enumeration for this device because all retries have<br />

failed. The application can force the bus driver to restart the enumeration by calling the<br />

function <strong>USB</strong>H_RestartEnumError.<br />

<strong>USB</strong>H_ENUM_ERROR_DISCONNECT_FLAG<br />

means the device has been disconnected during the enumeration. If the hub port reports a<br />

disconnect state the device cannot be re-enumerated by the bus driver automatically. Also<br />

the function <strong>USB</strong>H_RestartEnumError cannot re-enumerate the device.<br />

<strong>USB</strong>H_ENUM_ERROR_ROOT_PORT_RESET<br />

means an error during the <strong>USB</strong> reset of a root hub port occurs.<br />

<strong>USB</strong>H_ENUM_ERROR_HUB_PORT_RESET<br />

means an error during a reset of an external hub port occurs.<br />

UDB_ENUM_ERROR_INIT_DEVICE<br />

means an error during the device initialization (e.g. no answer to a descriptor request or<br />

failed standard request).<br />

UDB_ENUM_ERROR_INIT_HUB<br />

means the enumeration of an external hub fails.<br />

PortNumber<br />

This is the port number of the parent port where the <strong>USB</strong> device is connected. A flag in the<br />

Flags field determine if this is an external hub port.<br />

Status<br />

The status of the failed operation.<br />

ExtendedErrorInformation<br />

This is an internal information used for debugging.<br />

94 <strong>USB</strong> Bus Driver Reference Manual


Comments<br />

8 <strong>USB</strong> Bus Driver Reference<br />

This data structure is used as a notification parameter for the<br />

<strong>USB</strong>H_EnumErrorNotification function. This data structure does not contain detailed<br />

information about the device that fails the enumeration because this information is not<br />

available in all phases of the enumeration.<br />

See Also<br />

<strong>USB</strong>H_EnumErrorNotification (page 49)<br />

<strong>USB</strong>H_RestartEnumError (page 52)<br />

<strong>USB</strong> Bus Driver Reference Manual 95


8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong>H_EP_MASK<br />

This structure is used to describe an endpoint.<br />

Definition<br />

typedef struct tag_<strong>USB</strong>H_EP_MASK{<br />

T_UINT32 Mask;<br />

T_UINT8 Index;<br />

T_UINT8 Address;<br />

T_UINT8 Type;<br />

T_UINT8 Direction;<br />

} <strong>USB</strong>H_EP_MASK;<br />

Members<br />

Mask<br />

This member contains the information which fields are valid. It is an or’ ed combination of the<br />

following flags:<br />

<strong>USB</strong>H_EP_MASK_INDEX<br />

The Index is used for comparison.<br />

<strong>USB</strong>H_EP_MASK_ADDRESS<br />

The Address field is used for comparison.<br />

<strong>USB</strong>H_EP_MASK_TYPE<br />

The Type field is used for comparison.<br />

<strong>USB</strong>H_EP_MASK_DIRECTION<br />

The Direction field is used for comparison.<br />

Index<br />

If valid, this member contains the zero based index of the endpoint in the interface.<br />

Address<br />

If valid, this member contains an endpoint address with direction bit.<br />

Type<br />

If valid, this member contains a type.<br />

Direction<br />

If valid, this member specifies a direction. It is one of the following values:<br />

<strong>USB</strong>_IN_DIRECTION<br />

<strong>USB</strong>_OUT_DIRECTION<br />

Comments<br />

This data structure is used as an input parameter to get an endpoint descriptor due a call to<br />

<strong>USB</strong>H_GetEndpointDescriptor. The comparison with the mask is true if each member<br />

96 <strong>USB</strong> Bus Driver Reference Manual


8 <strong>USB</strong> Bus Driver Reference<br />

that is marked as valid by a flag in the Mask member is equal to the value stored in the<br />

endpoint. E.g. if the Mask is 0 the first endpoint is returned. If the Mask is set to<br />

<strong>USB</strong>H_EP_MASK_INDEX the zero based index can be used to address all endpoints.<br />

See Also<br />

<strong>USB</strong>H_GetEndpointDescriptor (page 62)<br />

<strong>USB</strong> Bus Driver Reference Manual 97


8 <strong>USB</strong> Bus Driver Reference<br />

URB_CONTROL_REQUEST<br />

This structure is used to submit a control request.<br />

Definition<br />

typedef struct tag_URB_FUNCTION_CONTROL_REQUEST{<br />

T_UsbSetupPacket Setup;<br />

T_UINT8 Endpoint;<br />

void* Buffer;<br />

T_UINT32 Length;<br />

T_UINT32 Timeout;<br />

void* DMASetupBuffer;<br />

void* DMATransferBuffer;<br />

} URB_CONTROL_REQUEST;<br />

Members<br />

Setup<br />

This member specifies the setup packet. The setup packet need not be allocated as DMA<br />

capable memory. The driver takes care to use DMA capable memory if necessary.<br />

Endpoint<br />

This member specifies the endpoint address with direction bit. Use 0 for default endpoint.<br />

Buffer<br />

Pointer to a caller provided buffer that is used in the data phase to transfer data. This<br />

parameter is optional and can be NULL. The direction of the data transfer depends on the<br />

bmRequestType fiel in the setup packet. See the <strong>USB</strong> specification for detailed<br />

information. The memory of the buffer need not be allocated as DMA capable memory. The<br />

driver takes care to use DMA capable memory if necessary.<br />

Length<br />

This is an input and output parameter. On input it contains the size of the buffer. On output the<br />

number of bytes transferred during the data phase are returned.<br />

Timeout<br />

This member contains a timeout value in milliseconds. The stack aborts the operation if the<br />

timeout expires. A value of 0 means the timeout is inactive.<br />

DMASetupBuffer<br />

Do not use this member. It is used for internal purposes.<br />

DMATransferBuffer<br />

Do not use this member. It is used for internal purposes.<br />

Comments<br />

A setup request consists of a setup phase, an optional data phase and a handshake phase. The<br />

data phase is limited to a length of 4096 bytes. The Setup structure must be filled in<br />

98 <strong>USB</strong> Bus Driver Reference Manual


8 <strong>USB</strong> Bus Driver Reference<br />

properly. The wLength field in the Setup must contain the size of the buffer.<br />

With this request each setup packet can be submitted. Even standard requests like SetAddress<br />

can be send but would destroy the multiplexing of the bus driver. It is not allowed to set the<br />

following standard requests:<br />

SetAddress<br />

This is assigned by the bus driver during enumeration or <strong>USB</strong> reset.<br />

Clear Feature Endpoint Halt<br />

Use URB_FUNCTION_RESET_ENDPOINT instead. The function<br />

URB_FUNCTION_RESET_ENDPOINT resets the data toggle bit in the host controller<br />

structures.<br />

SetConfiguration<br />

Use URB_SET_CONFIGURATION instead. The bus driver has to take care on the<br />

interfaces and endpoints of a configuration. The function URB_SET_CONFIGURATION<br />

updates the internal structures of the driver.<br />

This request can be used to send any class or vendor specific request.<br />

See Also<br />

URB (page 108)<br />

URB_FUNCTION (page 116)<br />

<strong>USB</strong> Bus Driver Reference Manual 99


8 <strong>USB</strong> Bus Driver Reference<br />

URB_BULK_INT_REQUEST<br />

This data structure is used to transfer data from or to a bulk or interrupt endpoint.<br />

Definition<br />

typedef struct tag_URB_BULK_INT_REQUEST{<br />

T_UINT8 Endpoint;<br />

void* Buffer;<br />

T_UINT32 Length;<br />

} URB_BULK_INT_REQUEST;<br />

Members<br />

Endpoint<br />

This member specifies the endpoint address with direction bit.<br />

Buffer<br />

This member is a pointer to a caller provided buffer. The buffer must be DMA memory. For<br />

more information about this memory please see section 5.3 at page 29.<br />

Length<br />

This member contains the size of the buffer and returns the number of bytes transferred. The<br />

size can be set to 0 for write operations to send a zero length packet.<br />

Comments<br />

The buffer size can be larger than the FIFO size but a host controller implementation can<br />

define a maximum size for a buffer that can be handled with one URB. To get a good<br />

performance the application should use two or more buffers.<br />

See Also<br />

URB (page 108)<br />

URB_FUNCTION (page 116)<br />

TAL_AllocateDmaMemory (page 135)<br />

100 <strong>USB</strong> Bus Driver Reference Manual


URB_ISO_FRAME<br />

This structure is used to define ISO transfer buffers.<br />

Definition<br />

typedef struct tag_URB_ISO_FRAME{<br />

T_UINT32 Offset;<br />

T_UINT32 Length;<br />

<strong>USB</strong>H_STATUS Status;<br />

} URB_ISO_FRAME;<br />

Members<br />

8 <strong>USB</strong> Bus Driver Reference<br />

Offset<br />

This member specifies the offset in bytes relative to the beginning of the transfer buffer.<br />

Length<br />

This member contains the length that should be transferred in one frame.<br />

Status<br />

This member contains the status of the operation in this frame. For an OUT endpoint this<br />

status is always success. For an IN endpoint a CRC or Data Toggle error can be reported.<br />

Comments<br />

This data structure is part of URB_ISO_REQUEST. It describes the amount of data that is<br />

transferred in one frame.<br />

See Also<br />

URB_ISO_REQUEST (page 102)<br />

<strong>USB</strong> Bus Driver Reference Manual 101


8 <strong>USB</strong> Bus Driver Reference<br />

URB_ISO_REQUEST<br />

This data structure is used to transfer data to an ISO endpoint.<br />

Definition<br />

typedef struct tag_URB_ISO_REQUEST{<br />

T_UINT8 Endpoint;<br />

void* Buffer;<br />

T_UINT32 Length;<br />

T_UINT32 Flags;<br />

T_UINT32 StartFrame;<br />

T_UINT32 Frames;<br />

} URB_ISO_REQUEST;<br />

Members<br />

Endpoint<br />

This member specifies the endpoint address with direction bit.<br />

Buffer<br />

This member is a pointer to a caller provided buffer. The buffer must be DMA memory. For<br />

more information about this memory please see section 5.3 at page 29.<br />

Length<br />

On input this member specifies the size of the user provided buffer. On output it contains the<br />

number of bytes transferred.<br />

Flags<br />

This parameter contains 0 or the following flag:<br />

<strong>USB</strong>H_ISO_ASAP<br />

If this flag is set the transfer starts as soon as possible and the parameter StartFrame is<br />

ignored.<br />

StartFrame<br />

If the flag <strong>USB</strong>H_ISO_ASAP is not set this parameter defines the start frame of the transfer.<br />

The StartFrame must be in the future. Use <strong>USB</strong>H_GetFrameNumber to get the current<br />

frame number and add some time to the current frame number.<br />

Frames<br />

This parameter contains the number of frames that are described with this structure.<br />

Comments<br />

The data structure is defined incompletely. That means the data structure consists of this data<br />

structure of type URB_ISO_REQUEST and an array of data structures of type<br />

URB_ISO_FRAME. The size of the array is defined by the parameter Frames. Use the macro<br />

URB_GET_ISO_URB_SIZE to get the size for an ISO URB.<br />

102 <strong>USB</strong> Bus Driver Reference Manual


Note that ISO transfer is optional and must be supported by the host controller<br />

implementation.<br />

See Also<br />

URB (page 108)<br />

URB_FUNCTION (page 116)<br />

URB_ISO_FRAME (page 101)<br />

8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong> Bus Driver Reference Manual 103


8 <strong>USB</strong> Bus Driver Reference<br />

URB_ENDPOINT_REQUEST<br />

This structure is used with the requests URB_FUNCTION_RESET_ENDPOINT and<br />

URB_FUNCTION_ABORT_ENDPOINT to specify the endpoint that should be reseted or aborted.<br />

Definition<br />

typedef struct tag_URB_ENDPOINT_REQUEST{<br />

T_UINT8 Endpoint;<br />

} URB_ENDPOINT_REQUEST;<br />

Member<br />

Endpoint<br />

This member specifies the endpoint address.<br />

See Also<br />

URB (page 108)<br />

URB_FUNCTION (page 116)<br />

104 <strong>USB</strong> Bus Driver Reference Manual


URB_SET_CONFIGURATION<br />

8 <strong>USB</strong> Bus Driver Reference<br />

This structure is used with the request URB_FUNCTION_SET_CONFIGURATION to specify the<br />

index of the configuration to set.<br />

Definition<br />

typedef struct tag_URB_SET_CONFIGURATION{<br />

T_UINT8 ConfigurationDescriptorIndex;<br />

} URB_SET_CONFIGURATION;<br />

Member<br />

ConfigurationDescriptorIndex<br />

This member specifies the index in the configuration descriptor.<br />

See Also<br />

URB (page 108)<br />

URB_FUNCTION (page 116)<br />

<strong>USB</strong> Bus Driver Reference Manual 105


8 <strong>USB</strong> Bus Driver Reference<br />

URB_SET_INTERFACE<br />

This structure is used with the request URB_FUNCTION_SET_INTERFACE to specify the<br />

alternate setting to set.<br />

Definition<br />

typedef struct tag_URB_SET_INTERFACE{<br />

T_UINT8 AlternateSetting;<br />

} URB_SET_INTERFACE;<br />

Member<br />

AlternateSetting<br />

This member specifies the alternate setting.<br />

See Also<br />

URB (page 108)<br />

URB_FUNCTION (page 116)<br />

106 <strong>USB</strong> Bus Driver Reference Manual


URB_SET_SUSPEND_STATE<br />

This data structure is used to set a power state.<br />

Definition<br />

typedef struct tag_URB_SET_POWER_STATE{<br />

<strong>USB</strong>H_SUSPEND_STATE PowerState;<br />

} URB_SET_SUSPEND_STATE;<br />

Member<br />

8 <strong>USB</strong> Bus Driver Reference<br />

PowerState<br />

This member is of type <strong>USB</strong>H_SUSPEND_STATE and specifies the power state.<br />

Comments<br />

If the device is switched to suspend, there must be no pending requests on the device.<br />

See Also<br />

URB (page 108)<br />

<strong>USB</strong>H_SUSPEND_STATE (page 119)<br />

URB_FUNCTION (page 116)<br />

<strong>USB</strong> Bus Driver Reference Manual 107


8 <strong>USB</strong> Bus Driver Reference<br />

URB<br />

The URB is the basic structure for all asynchronous operations on the bus driver.<br />

Definition<br />

typedef struct tag_URB{<br />

URB_HEADER Header;<br />

union Request;<br />

} URB;<br />

Members<br />

Header<br />

This member contains the URB header of type URB_HEADER. The most important<br />

parameters are the function code stored in the member Function and the callback function<br />

stored in the member Completion.<br />

Request<br />

This member is an union and contains information depending on the specific request type of<br />

the URB_HEADER. The request type of the URB_HEADER is specified with the Function<br />

member in the URB_HEADER. See comments section for further details to this member.<br />

Comments<br />

The following table lists the possible request types, their corresponding URB Function Types<br />

and associated structures that should be used for the Request member of this structure:<br />

Request Type URB Function Type Associated Structure<br />

ControlRequest URB_FUNCTION_CONTROL_REQUEST URB_CONTROL_REQUEST<br />

BulkRequest URB_FUNCTION_BULK_REQUEST URB_BULK_INT_REQUEST<br />

InterruptRequest URB_FUNCTION_INT_REQUEST URB_BULK_INT_REQUEST<br />

IsoRequest URB_FUNCTION_ISO_REQUEST URB_ISO_REQUEST<br />

EndpointRequest URB_FUNCTION_RESET_ENDPOINT URB_ENDPOINT_REQUEST<br />

SetConfiguration URB_FUNCTION_SET_CONFIGURATION URB_SET_CONFIGURATION<br />

SetInterface URB_FUNCTION_SET_INTERFACE URB_SET_INTERFACE<br />

SetSuspendState URB_FUNCTION_SET_POWER_STATE URB_SET_SUSPEND_STATE<br />

All requests that exchange data with the device are using the URB data structure. The caller<br />

has to provide the memory for this structure. There are no special requirements for the<br />

memory of an URB structure. Anyhow there are maybe special requiremts for the memory of<br />

a data transfer buffer within one of the structures used for the Request member. See the<br />

documentation of the structures that can be used for the Request member. The memory of<br />

the URB must be permanent until the completion function is called. This data structure is used<br />

to submit an URB.<br />

See Also<br />

URB_HEADER (page 111)<br />

URB_FUNCTION (page 116)<br />

108 <strong>USB</strong> Bus Driver Reference Manual


URB_CONTROL_REQUEST (page 98)<br />

URB_BULK_INT_REQUEST (page 100)<br />

URB_ISO_REQUEST (page 102)<br />

URB_ENDPOINT_REQUEST (page 104)<br />

URB_SET_CONFIGURATION (page 105)<br />

URB_SET_INTERFACE (page 106)<br />

URB_SET_SUSPEND_STATE (page 107)<br />

8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong> Bus Driver Reference Manual 109


8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong>H_PNP_NOTIFICATION<br />

This structure defines a PnP notification.<br />

Definition<br />

typedef struct tag_<strong>USB</strong>H_PNP_NOTIFICATION{<br />

<strong>USB</strong>H_PnpNotification* PnpNotification;<br />

void* Context;<br />

<strong>USB</strong>H_INTERFACE_MASK InterfaceMask;<br />

} <strong>USB</strong>H_PNP_NOTIFICATION;<br />

Members<br />

PnpNotification<br />

This member contains the notification function that is called from the <strong>USB</strong> Bus Driver Core if<br />

a PnP event occurs.<br />

Context<br />

This member contains the notification context that is passed unchanged to the notification<br />

function.<br />

InterfaceMask<br />

This member is of type <strong>USB</strong>H_INTERFACE_MASK and contains a mask describing the<br />

interfaces for which the PnP notification should be called.<br />

Comments<br />

This data structure is used as an input parameter for the<br />

<strong>USB</strong>H_RegisterPnPNotification function.<br />

See Also<br />

<strong>USB</strong>H_INTERFACE_MASK (page 90)<br />

<strong>USB</strong>H_RegisterPnPNotification (page 47)<br />

110 <strong>USB</strong> Bus Driver Reference Manual


URB_HEADER<br />

This data structure defines a URB header.<br />

Definition<br />

typedef struct tag_URB_HEADER{<br />

URB_FUNCTION Function;<br />

<strong>USB</strong>H_STATUS Status;<br />

URB_COMPLETION* Completion;<br />

void* Context;<br />

DLIST ListEntry;<br />

} URB_HEADER;<br />

Members<br />

8 <strong>USB</strong> Bus Driver Reference<br />

Function<br />

This member is of type URB_FUNCTION and describes the type of the request.<br />

Status<br />

After completion of the corresponding URB this member contains the status for the request.<br />

Completion<br />

This is a pointer to the caller provided completion function which will be called if the function<br />

<strong>USB</strong>H_SubmitUrb returns <strong>USB</strong>H_STATUS_PENDING. If a different status code is returned<br />

the completion function is never called.<br />

Context<br />

This member can be used by the caller to store a context for the completion routine. This<br />

context is passed unchanged to the completion routine.<br />

ListEntry<br />

This member is a list entry and can be used to keep the URB in a list. The owner of the URB<br />

can use this list entry. If the URB is passed to the <strong>USB</strong> Bus Driver Core the <strong>USB</strong> Bus Driver<br />

Core takes ownership of the URB and this member is changed and in use until the URB is<br />

completed. Therefor this member must not be in use when the URB is passed to the <strong>USB</strong> Bus<br />

Driver Core (e.g. the URB must not be linked in a list). You may get corrupted data structures<br />

if this member is in use when passing the URB to the <strong>USB</strong> Bus Driver Core.<br />

Comments<br />

There are additional members which are for internal use only and therefore not described here.<br />

A caller is not allowed to use these members. A caller must only provide the members<br />

Function, Completion, and if required Context.<br />

See Also<br />

URB_COMPLETION (page 73)<br />

<strong>USB</strong> Bus Driver Reference Manual 111


8 <strong>USB</strong> Bus Driver Reference<br />

URB_FUNCTION (page 116)<br />

URB (page 108)<br />

<strong>USB</strong>H_SubmitUrb (page 74)<br />

<strong>USB</strong>H_STATUS_PENDING (page 123)<br />

112 <strong>USB</strong> Bus Driver Reference Manual


<strong>USB</strong>H_SPEED<br />

8 <strong>USB</strong> Bus Driver Reference<br />

This enumeration defines some constants that represents the speed at which a device is operating.<br />

Definition<br />

typedef enum tag_<strong>USB</strong>H_SPEED{<br />

<strong>USB</strong>H_SPEED_UNKNOWN,<br />

<strong>USB</strong>H_LOW_SPEED,<br />

<strong>USB</strong>H_FULL_SPEED,<br />

<strong>USB</strong>H_HIGH_SPEED<br />

} <strong>USB</strong>H_SPEED;<br />

Entries<br />

<strong>USB</strong>H_SPEED_UNKNOWN<br />

The speed is unknown.<br />

<strong>USB</strong>H_LOW_SPEED<br />

The device operates at low speed.<br />

<strong>USB</strong>H_FULL_SPEED<br />

The device operates at full speed.<br />

<strong>USB</strong>H_HIGH_SPEED<br />

The device operates at high speed.<br />

Comments<br />

This structure is used as a member in the <strong>USB</strong>H_INTERFACE_INFO data structure and as a<br />

parameter for the <strong>USB</strong>H_GetSpeed function.<br />

See Also<br />

<strong>USB</strong>H_INTERFACE_INFO (page 92)<br />

<strong>USB</strong>H_GetSpeed (page 66)<br />

<strong>USB</strong> Bus Driver Reference Manual 113


8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong>H_PNP_EVENT<br />

This enumeration defines the events that are used with PnP notifications.<br />

Definition<br />

typedef enum tag_<strong>USB</strong>H_PNP_EVENT{<br />

<strong>USB</strong>H_AddDevice,<br />

<strong>USB</strong>H_RemoveDevice<br />

} <strong>USB</strong>H_PNP_EVENT;<br />

Entries<br />

<strong>USB</strong>H_AddDevice<br />

This event indicates that a device was connected to the host and a new interface is available.<br />

<strong>USB</strong>H_RemoveDevice<br />

This events indicates that a device has been removed.<br />

Comments<br />

This enumeration type is used as a parameter for the PnP notification.<br />

See Also<br />

<strong>USB</strong>H_PnpNotification (page 46)<br />

114 <strong>USB</strong> Bus Driver Reference Manual


<strong>USB</strong>H_POWER_STATE<br />

This enumeration type specifies some hub port power states.<br />

Definition<br />

typedef enum tag_<strong>USB</strong>H_POWER_STATE{<br />

<strong>USB</strong>H_POWER_OFF,<br />

<strong>USB</strong>H_POWER_ON<br />

} <strong>USB</strong>H_POWER_STATE;<br />

Entries<br />

<strong>USB</strong>H_POWER_OFF<br />

The hub port power is switched off.<br />

<strong>USB</strong>H_POWER_ON<br />

The hub port power is switched on.<br />

Comments<br />

8 <strong>USB</strong> Bus Driver Reference<br />

This enumeration type is used as a parameter in the <strong>USB</strong>H_SetPortPowerState function.<br />

See Also<br />

<strong>USB</strong>H_SetPortPowerState (page 71)<br />

<strong>USB</strong> Bus Driver Reference Manual 115


8 <strong>USB</strong> Bus Driver Reference<br />

URB_FUNCTION<br />

This enumeration defines the possible request types for an URB.<br />

Definition<br />

typedef enum tag_URB_FUNCTION{<br />

URB_FUNCTION_CONTROL_REQUEST,<br />

URB_FUNCTION_BULK_REQUEST,<br />

URB_FUNCTION_INT_REQUEST,<br />

URB_FUNCTION_ISO_REQUEST,<br />

URB_FUNCTION_RESET_DEVICE,<br />

URB_FUNCTION_RESET_ENDPOINT,<br />

URB_FUNCTION_ABORT_ENDPOINT,<br />

URB_FUNCTION_SET_CONFIGURATION,<br />

URB_FUNCTION_SET_INTERFACE,<br />

URB_FUNCTION_SET_POWER_STATE<br />

} URB_FUNCTION;<br />

Entries<br />

URB_FUNCTION_CONTROL_REQUEST<br />

This request is used to send a URB with a control request. It uses the data structure<br />

URB_CONTROL_REQUEST. A control request includes standard, class and vendor defined<br />

requests. The standard requests SetConfiguration, SetAddress and SetInterface can not be<br />

submitted by this request. These requests require a special handling in the driver. See<br />

URB_FUNCTION_SET_CONFIGURATION and URB_FUNCTION_SET_INTERFACE for<br />

details.<br />

URB_FUNCTION_BULK_REQUEST<br />

This request is used to transfer data to or from a bulk endpoint. It uses the data structure<br />

URB_BULK_INT_REQUEST.<br />

URB_FUNCTION_INT_REQUEST<br />

This request is used to transfer data to or from an interrupt endpoint. It uses the data structure<br />

URB_BULK_INT_REQUEST. The interval is defined by the endpoint descriptor.<br />

URB_FUNCTION_ISO_REQUEST<br />

This request is used to transfer data to or from an ISO endpoint. It uses the data structure<br />

URB_ISO_FRAME. ISO transfer may not be supported by all host controllers.<br />

URB_FUNCTION_RESET_DEVICE<br />

This request sends a <strong>USB</strong> reset to the device. This causes a remove event for all interfaces of<br />

the device. After the device is successfully enumerated an arrival event is indicated. All<br />

interfaces get new interface ID’s. This request uses only the URB header, i.e. no special data<br />

structure is required for the request type.<br />

If the driver indicates a device arrival event the device is in a defined state because it is reset<br />

and enumerated by the bus driver. This request can be part of an error recovery or part of<br />

special class protocols like DFU.<br />

116 <strong>USB</strong> Bus Driver Reference Manual


8 <strong>USB</strong> Bus Driver Reference<br />

The application should abort all pending requests and close all handles to this device. All<br />

handles become invalid.<br />

URB_FUNCTION_RESET_ENDPOINT<br />

This request clears an error condition on a special endpoint. If a data transfer error occurs that<br />

can not be handled in hardware the bus driver stops the endpoint and does not allow further<br />

data transfers before the endpoint is reset with this function. On a bulk or interrupt endpoint<br />

the host driver sends a Clear Feature Endpoint Halt request. This informs the device about the<br />

hardware error. The driver resets the data toggle bit for this endpoint. This request expects that<br />

no pending URB’s are scheduled on this endpoint. Pending URB’s must be aborted with the<br />

URB based function URB_FUNCTION_ABORT_ENDPOINT. This function uses the data<br />

structure URB_ENDPOINT_REQUEST.<br />

URB_FUNCTION_ABORT_ENDPOINT<br />

This request aborts all pending requests on an endpoint. The host controller calls the<br />

completion function with a status code <strong>USB</strong>H_STATUS_CANCELED. The completion of the<br />

URB’s may be delayed. The application should wait until all pending requests has been<br />

returned by the driver before the handle is closed or URB_FUNCTION_RESET_ENDPOINT<br />

is called. When this function is called the data toggle bit of the endpoint can get the wrong<br />

value. For that reason the function URB_FUNCTION_RESET_ENDPOINT must be called<br />

before a new data transfer can be started on this endpoint.<br />

This request uses the the data structure URB_ENDPOINT_REQUEST.<br />

URB_FUNCTION_SET_CONFIGURATION<br />

The driver selects the configuration defined by the configuration descriptor with the index 0<br />

during the enumeration. If the application uses this configuration there is no need to call this<br />

function. If the application wants to activate a different configuration this function has to be<br />

called.<br />

The driver performs a complete new enumeration with the device. That means a removal event<br />

is indicated, the enumeration is performed with the new configuration, all interface handles<br />

becomes invalid, all interfaces get a new interface ID and the device is enumerated with the<br />

new configuration. The application should close all interface handles and wait for a new<br />

arrival event.<br />

This request uses the data structure URB_SET_CONFIGURATION.<br />

URB_FUNCTION_SET_INTERFACE<br />

This request selects a new alternate setting for the interface. There must be no pending<br />

requests on any endpoint of this interface. The interface handle does not becomes invalid<br />

during this operation. The number of endpoints may be changed. This request uses the data<br />

structure URB_SET_INTERFACE.<br />

URB_FUNCTION_SET_POWER_STATE<br />

This function is used to set the power state for a device. There must be no pending requests for<br />

this device if the device is set to the suspended state. The request uses the data structure<br />

URB_SET_SUSPEND_STATE. After the enumeration the device is in normal power state.<br />

<strong>USB</strong> Bus Driver Reference Manual 117


8 <strong>USB</strong> Bus Driver Reference<br />

Comments<br />

This enumeration type is used with the Function member within the URB_HEADER data<br />

structure.<br />

See Also<br />

URB_HEADER (page 111)<br />

URB_CONTROL_REQUEST (page 98)<br />

URB_BULK_INT_REQUEST (page 100)<br />

URB_ENDPOINT_REQUEST (page 104)<br />

URB_SET_CONFIGURATION (page 105)<br />

URB_SET_INTERFACE (page 106)<br />

URB_SET_SUSPEND_STATE (page 107)<br />

<strong>USB</strong>H_SubmitUrb (page 74)<br />

118 <strong>USB</strong> Bus Driver Reference Manual


<strong>USB</strong>H_SUSPEND_STATE<br />

This enumeration type specifies some power states.<br />

Definition<br />

typedef enum tag_<strong>USB</strong>H_POWER_STATE{<br />

<strong>USB</strong>H_NORMAL_POWER,<br />

<strong>USB</strong>H_SUSPEND<br />

} <strong>USB</strong>H_SUSPEND_STATE;<br />

Entries<br />

<strong>USB</strong>H_NORMAL_POWER<br />

The device is switched to normal operation.<br />

<strong>USB</strong>H_SUSPEND<br />

The device is switched to <strong>USB</strong> Suspend mode.<br />

Comments<br />

8 <strong>USB</strong> Bus Driver Reference<br />

This enumeration type is used as a member in the URB_SET_SUSPEND_STATE data<br />

structure.<br />

See Also<br />

URB_SET_SUSPEND_STATE (page 107)<br />

<strong>USB</strong> Bus Driver Reference Manual 119


8 <strong>USB</strong> Bus Driver Reference<br />

8.3 Status Codes<br />

Table 1 lists the error codes returned by the <strong>USB</strong> Bus Driver. A detailed description can be found<br />

in section 8.4 at page 121.<br />

Table 1: Error codes<br />

Error Code Numerical Value<br />

<strong>USB</strong>H_STATUS_SUCCESS 0x0000<br />

<strong>USB</strong>H_STATUS_CRC 0x0001<br />

<strong>USB</strong>H_STATUS_BITSTUFFING 0x0002<br />

<strong>USB</strong>H_STATUS_DATATOGGLE 0x0003<br />

<strong>USB</strong>H_STATUS_STALL 0x0004<br />

<strong>USB</strong>H_STATUS_NOTRESPONDING 0x0005<br />

<strong>USB</strong>H_STATUS_PID_CHECK 0x0006<br />

<strong>USB</strong>H_STATUS_UNEXPECTED_PID 0x0007<br />

<strong>USB</strong>H_STATUS_DATA_OVERRUN 0x0008<br />

<strong>USB</strong>H_STATUS_DATA_UNDERRUN 0x0009<br />

<strong>USB</strong>H_STATUS_BUFFER_OVERRUN 0x000C<br />

<strong>USB</strong>H_STATUS_BUFFER_UNDERRUN 0x000D<br />

<strong>USB</strong>H_STATUS_NOT_ACCESSED 0x000F<br />

<strong>USB</strong>H_STATUS_ERROR 0x0101<br />

<strong>USB</strong>H_STATUS_BUFFER_OVERFLOW 0x0102<br />

<strong>USB</strong>H_STATUS_INVALID_PARAM 0x0103<br />

<strong>USB</strong>H_STATUS_PENDING 0x0104<br />

<strong>USB</strong>H_STATUS_DEVICE_REMOVED 0x0105<br />

<strong>USB</strong>H_STATUS_CANCELED 0x0106<br />

<strong>USB</strong>H_STATUS_BUSY 0x0109<br />

<strong>USB</strong>H_STATUS_INVALID_DESCRIPTOR 0x0110<br />

<strong>USB</strong>H_STATUS_ENDPOINT_HALTED 0x0111<br />

<strong>USB</strong>H_STATUS_TIMEOUT 0x0112<br />

<strong>USB</strong>H_STATUS_PORT 0x0113<br />

<strong>USB</strong>H_POWER_SWITCHING_NOT_SUPPORTED 0x0114<br />

<strong>USB</strong>H_STATUS_INVALID_ALIGNMENT 0x0115<br />

<strong>USB</strong>H_STATUS_NO_MEMORY 0x0116<br />

<strong>USB</strong>H_STATUS_NO_RESOURCES 0x0117<br />

<strong>USB</strong>H_STATUS_USER 0x8000<br />

120 <strong>USB</strong> Bus Driver Reference Manual


8.4 Status Codes Description<br />

<strong>USB</strong>H_STATUS_SUCCESS (0x0000L)<br />

The operation has been successfully completed.<br />

<strong>USB</strong>H_STATUS_CRC (0x0001L)<br />

Returned by the hardware. A CRC error occurred.<br />

<strong>USB</strong>H_STATUS_BITSTUFFING (0x0002L)<br />

Returned by the hardware. A bit stuffing error is occurred.<br />

<strong>USB</strong>H_STATUS_DATATOGGLE (0x0003L)<br />

Returned by the hardware. A data toggle error is occurred.<br />

<strong>USB</strong>H_STATUS_STALL (0x0004L)<br />

The device has answered a request with the STALL PID.<br />

<strong>USB</strong>H_STATUS_NOTRESPONDING (0x0005L)<br />

8 <strong>USB</strong> Bus Driver Reference<br />

The device has not answered to a request for 3 times. This can happen if the device has disabled<br />

the endpoint (e.g. a watch dog timer has restarted the device) or if there are transmission errors<br />

between the device and the host.<br />

<strong>USB</strong>H_STATUS_PID_CHECK (0x0006L)<br />

Returned by the hardware. An invalid PID has been received.<br />

<strong>USB</strong>H_STATUS_UNEXPECTED_PID (0x0007L)<br />

Returned by the hardware. An unexpected PID has been received.<br />

<strong>USB</strong>H_STATUS_DATA_OVERRUN (0x0008L)<br />

The device has send more data than expected. Possible reasons are:<br />

A device sends more data than defined in the endpoint descriptor.<br />

<strong>USB</strong> Bus Driver Reference Manual 121


8 <strong>USB</strong> Bus Driver Reference<br />

The application uses a data buffer with a size that is not a multiple of the FIFO size.<br />

Electrical noise destroys the End Of Packet (EOP) signal and the host does not detect the end<br />

of the data transmission.<br />

<strong>USB</strong>H_STATUS_DATA_UNDERRUN (0x0009L)<br />

Is used internally, not returned to an application.<br />

<strong>USB</strong>H_STATUS_BUFFER_OVERRUN (0x000CL)<br />

The device has send more data than expected. Possible reasons are:<br />

A device sends more data than defined in the endpoint descriptor.<br />

The application uses a data buffer with a size that is not a multiple of the FIFO size.<br />

Electrical noise destroys the End Of Packet (EOP) signal and the host does not detect the end<br />

of the data transmission.<br />

<strong>USB</strong>H_STATUS_BUFFER_UNDERRUN (0x000DL)<br />

Is used internally, not returned to the application.<br />

<strong>USB</strong>H_STATUS_NOT_ACCESSED (0x000FL)<br />

The <strong>USB</strong> was not accessed by the host controller.<br />

<strong>USB</strong>H_STATUS_ERROR (0x0101L)<br />

A generic error code returned by the <strong>USB</strong> host driver.<br />

<strong>USB</strong>H_STATUS_BUFFER_OVERFLOW (0x0102L)<br />

The amount of data was larger than the buffer size or the buffer size was not a multiple of the FIFO<br />

size.<br />

<strong>USB</strong>H_STATUS_INVALID_PARAM (0x0103L)<br />

A parameter passed to the function was invalid.<br />

122 <strong>USB</strong> Bus Driver Reference Manual


<strong>USB</strong>H_STATUS_PENDING (0x0104L)<br />

8 <strong>USB</strong> Bus Driver Reference<br />

The request has been accept by the driver and is now pending. If the operation completes the<br />

completion routine is called and the final status of the operation is returned to the completion<br />

routine.<br />

<strong>USB</strong>H_STATUS_DEVICE_REMOVED (0x0105L)<br />

The device was removed. All handles to this device are invalid even if the device is connected<br />

again.<br />

<strong>USB</strong>H_STATUS_CANCELED (0x0106L)<br />

The operation was canceled by the API. This can happen if a handle is closed, the device is<br />

removed or if a request is aborted.<br />

<strong>USB</strong>H_STATUS_BUSY (0x0109L)<br />

If there are pending requests some operations like SetInterface, returns this error.<br />

<strong>USB</strong>H_STATUS_INVALID_DESCRIPTOR (0x0110L)<br />

This error can be returned if the device reports descriptors that are not compliant to the <strong>USB</strong><br />

specification.<br />

<strong>USB</strong>H_STATUS_ENDPOINT_HALTED (0x0111L)<br />

An endpoint with bulk or interrupt transfer is halted if a hardware error occurs. Each request that<br />

is send to this endpoint is returned with this status. To enable the endpoint again a reset endpoint<br />

request must be sent.<br />

<strong>USB</strong>H_STATUS_TIMEOUT (0x0112L)<br />

The operation has been timed out. This is an internal state for enumeration of <strong>USB</strong> devices.<br />

<strong>USB</strong>H_STATUS_PORT (0x0113L)<br />

An error on a root hub or hub port. This error occurs if an enabled and connected port changes to<br />

a disabled port status during operation or if an overcurrent on a port occurs.<br />

<strong>USB</strong> Bus Driver Reference Manual 123


8 <strong>USB</strong> Bus Driver Reference<br />

<strong>USB</strong>H_POWER_SWITCHING_NOT_SUPPORTED (0x0114L)<br />

Individually port power switching is not supported from the root hub or hub port.<br />

<strong>USB</strong>H_STATUS_INVALID_ALIGNMENT (0x0115L)<br />

This is an internal error.<br />

<strong>USB</strong>H_STATUS_NO_MEMORY (0x0116L)<br />

The operation could not be performed because no memory was available.<br />

<strong>USB</strong>H_STATUS_NO_RESOURCES (0x0117L)<br />

Not enough resources are available. Examples for resources are events, timers and tasks.<br />

If not enough memory resources are available <strong>USB</strong>H_STATUS_NO_MEMORY is returned.<br />

<strong>USB</strong>H_STATUS_USER (0x8000L)<br />

This status code can be used to define user defined status codes. The status codes should be defined<br />

in the form <strong>USB</strong>H_STATUS_USER + X, where X is an unsigned integer value.<br />

124 <strong>USB</strong> Bus Driver Reference Manual


9 Register Access Abstraction Layer<br />

9.1 Open <strong>Host</strong> Controller<br />

HcohcWriteReg<br />

This function write a 32-bit value to a specified register.<br />

Definition<br />

void<br />

HcohcWriteReg(<br />

T_UINT8* base,<br />

T_UINT32 Offset,<br />

T_UINT32 Value<br />

);<br />

Parameters<br />

base<br />

This field specifies the base address of the register space.<br />

Offset<br />

This field specifies the offset of the register.<br />

Value<br />

This field specifies the value that is written.<br />

Comments<br />

This is an abstraction for the OHC register access.<br />

See Also<br />

HcohcReadReg (page 126)<br />

9 Register Access Abstraction Layer<br />

<strong>USB</strong> Bus Driver Reference Manual 125


9 Register Access Abstraction Layer<br />

HcohcReadReg<br />

This function reads a 32-bit value from a specified register.<br />

Definition<br />

T_UINT32<br />

HcohcReadReg(<br />

T_UINT8* base,<br />

T_UINT32 Offset<br />

);<br />

Parameters<br />

base<br />

This field specifies the base address of the register space.<br />

Offset<br />

This field specifies the offset of the register.<br />

Return Value<br />

This function returns the 32-bit value read from the specified register.<br />

Comments<br />

This is an abstraction for the OHC register access.<br />

See Also<br />

HcohcWriteReg (page 125)<br />

126 <strong>USB</strong> Bus Driver Reference Manual


10 Abstraction Layer Reference<br />

10.1 API Functions<br />

10 Abstraction Layer Reference<br />

The following functions define the interface of the abstraction layer. They are defined in the file<br />

tal_api.h and must be implemented for your application. The TAL interface is based on ANSI-<br />

C functions. The TAL functions that must be implemented are defined in the file . Each<br />

function can be implemented as a macro in the file or in a C module like .<br />

The TAL interface contains functions in different categories. Each category is described in one of<br />

the following subsections.<br />

10.2 General<br />

Depending from the platform not all functions must be implemented. E.g. TAL_InvalidateCache<br />

must only implemented if a host controller is used that has direct access to the memory (most<br />

host controller) and that memory is cached within the CPU. If not needed a empty macro can be<br />

defined.<br />

<strong>USB</strong> Bus Driver Reference Manual 127


10 Abstraction Layer Reference<br />

10.3 Initialization and Deinitialization<br />

TAL_Init<br />

This function is used to initialize the TAL layer.<br />

Definition<br />

T_BOOL<br />

TAL_Init();<br />

Return Value<br />

The function returns T_TRUE on success or T_FALSE on error.<br />

Comments<br />

This function must be called one time before any other function of the TAL API is called.<br />

This function is non blocking.<br />

See Also<br />

TAL_Exit (page 129)<br />

128 <strong>USB</strong> Bus Driver Reference Manual


TAL_Exit<br />

This function is used to free the resources of the TAL layer.<br />

Definition<br />

void<br />

TAL_Exit();<br />

Comments<br />

10 Abstraction Layer Reference<br />

This function frees resources of the TAL layer. All allocated TAL objects like timers, events,<br />

tasks, etc. must be stopped and freed before this function is called.<br />

The function is non blocking.<br />

See Also<br />

TAL_Init (page 128)<br />

<strong>USB</strong> Bus Driver Reference Manual 129


10 Abstraction Layer Reference<br />

10.4 Dynamically Memory Allocation<br />

TAL_Malloc<br />

This functions allocates the specified size of memory.<br />

Definition<br />

void*<br />

TAL_Malloc(<br />

unsigned long Size<br />

);<br />

Parameter<br />

Size<br />

Number of bytes to allocate. This parameter must be greater than 0.<br />

Return Value<br />

The function returns a void pointer to the allocated memory or NULL if there is not enough<br />

memory available.<br />

Comments<br />

The malloc function allocates a memory block of at least size bytes. The returned pointer is<br />

aligned to the size of a unsigned int variable. The memory is accessible in all context’s the<br />

<strong>Embedded</strong> <strong>USB</strong> <strong>Host</strong> <strong>Stack</strong> is called. If the memory is no longer used it should be freed with<br />

the function TAL_Free.<br />

This function is non blocking.<br />

See Also<br />

TAL_Free (page 131)<br />

TAL_BuildDmaMd (page 140)<br />

130 <strong>USB</strong> Bus Driver Reference Manual


TAL_Free<br />

This function frees a memory block.<br />

Definition<br />

void<br />

TAL_Free(<br />

void* MemBlock<br />

);<br />

Parameter<br />

10 Abstraction Layer Reference<br />

MemBlock<br />

Pointer to a previously allocated memory block return by the function TAL_Malloc. The<br />

pointer must not be NULL.<br />

Comments<br />

A memory block must be freed exactly one time.<br />

This function is non blocking.<br />

See Also<br />

TAL_Malloc (page 130)<br />

<strong>USB</strong> Bus Driver Reference Manual 131


10 Abstraction Layer Reference<br />

10.5 Descriptor Memory Allocation<br />

TAL_AllocateDmaDescMemory<br />

Allocating of physical contiguous non-paged memory.<br />

Definition<br />

void*<br />

TAL_AllocateDmaDescMemory(<br />

unsigned long Size,<br />

unsigned long Alignment,<br />

unsigned long* PhysicalAddress<br />

);<br />

Parameters<br />

Size<br />

Bytes to allocate.<br />

Alignment<br />

Specifies the alignment of the returned memory pointer in bytes.<br />

PhysicalAddress<br />

Returns the physical address of the memory.<br />

Return Value<br />

The function returns a void pointer to the allocated virtual address space or NULL if there is<br />

no memory with the requested properties available.<br />

Comments<br />

This function is used to allocate memory that is used for DMA descriptors. The memory is<br />

physically contiguous and non-cached. The requested memory must be freed with the function<br />

TAL_FreeDmaDescMemory if it is not longer used.<br />

This function is non blocking.<br />

See Also<br />

TAL_FreeDmaDescMemory (page 133)<br />

132 <strong>USB</strong> Bus Driver Reference Manual


TAL_FreeDmaDescMemory<br />

This function frees a memory block.<br />

Definition<br />

void<br />

TAL_FreeDmaDescMemory(<br />

void* VirtualAddress<br />

);<br />

Parameter<br />

10 Abstraction Layer Reference<br />

VirtualAddress<br />

Points to a virtual address previously allocated by a call to TAL_AllocateDmaDescMemory.<br />

Comments<br />

This function is non blocking.<br />

See Also<br />

TAL_AllocateDmaDescMemory (page 132)<br />

<strong>USB</strong> Bus Driver Reference Manual 133


10 Abstraction Layer Reference<br />

10.6 DMA Memory Allocation<br />

TAL_GetCacheLineSize<br />

The TAL_GetCacheLineSize routine returns the cache line size.<br />

Definition<br />

unsigned long<br />

TAL_GetCacheLineSize();<br />

Return Value<br />

Is the cache line size or 1 if a cache is not used.<br />

Comments<br />

The cache line size is used to allocate memory that starts at a cache line and has a size of<br />

multiple cache lines.<br />

This function is non blocking.<br />

See Also<br />

TAL_AllocateDmaMemory (page 135)<br />

TAL_Malloc (page 130)<br />

134 <strong>USB</strong> Bus Driver Reference Manual


TAL_AllocateDmaMemory<br />

10 Abstraction Layer Reference<br />

This function allocates memory that can be used for data transfers with DMA capable controllers.<br />

Definition<br />

void*<br />

TAL_AllocateDmaMemory(<br />

unsigned long Size<br />

);<br />

Parameter<br />

Size<br />

Number of bytes to allocate.<br />

Return Value<br />

The function returns a void pointer to the allocated virtual address space or NULL if there is<br />

no memory available.<br />

Comments<br />

The returned memory block is cache line size aligned and the size is a multiple of the cache<br />

line sizes. The memory can be cached and must not be physically contiguously. For more<br />

information about this memory please see section 5.3 at page 29.<br />

The functions TAL_InvalidateCache and TAL_FlushCache can be applied to this<br />

memory. The function TAL_BuildDmaMd can be used to get a memory description list.<br />

This function is non blocking.<br />

See Also<br />

TAL_FreeDmaMemory (page 136)<br />

TAL_InvalidateCache (page 137)<br />

TAL_FlushCache (page 138)<br />

TAL_BuildDmaMd (page 140)<br />

<strong>USB</strong> Bus Driver Reference Manual 135


10 Abstraction Layer Reference<br />

TAL_FreeDmaMemory<br />

This function frees a memory block that was allocated with TAL_AllocateDmaMemory.<br />

Definition<br />

void<br />

TAL_FreeDmaMemory(<br />

void* VirtualAddress<br />

);<br />

Parameter<br />

VirtualAddress<br />

Points to a virtual address previously allocated by a call to TAL_AllocateDmaMemory.<br />

Comments<br />

This function is non blocking.<br />

See Also<br />

TAL_AllocateDmaMemory (page 135)<br />

136 <strong>USB</strong> Bus Driver Reference Manual


TAL_InvalidateCache<br />

10 Abstraction Layer Reference<br />

This function invalidates cached memory. The next access to the invalidated memory address<br />

forces the CPU to read the physical memory into the cache.<br />

Definition<br />

void<br />

TAL_InvalidateCache(<br />

void* Address,<br />

unsigned long Length<br />

);<br />

Parameters<br />

Address<br />

Virtual address of the memory that should be invalidated.<br />

Length<br />

Specifies the length in bytes.<br />

Comments<br />

This function is called by the <strong>Embedded</strong> <strong>USB</strong> <strong>Host</strong> <strong>Stack</strong> before memory is accessed that was<br />

modified by a DMA capable hardware.<br />

If the architecture does not use cached memory this function can be implemented as a void<br />

macro. The cache is typically organized in cache lines. This function must invalidate all cache<br />

lines that are overlapping with the given memory area. The <strong>Embedded</strong> <strong>USB</strong> <strong>Host</strong> <strong>Stack</strong> takes<br />

care that no other variables are destroyed by invalidating the cache line. The cache line size is<br />

returned by the function TAL_GetCacheLineSize.<br />

This function is non blocking.<br />

See Also<br />

TAL_FlushCache (page 138)<br />

TAL_GetCacheLineSize (page 134)<br />

TAL_AllocateDmaMemory (page 135)<br />

<strong>USB</strong> Bus Driver Reference Manual 137


10 Abstraction Layer Reference<br />

TAL_FlushCache<br />

This function forces the MMU to write cached memory to the physical memory.<br />

Definition<br />

void<br />

TAL_FlushCache(<br />

void* Address,<br />

unsigned long Length<br />

);<br />

Parameters<br />

Address<br />

Virtual address of the cached memory.<br />

Length<br />

Specifies the length in bytes.<br />

Comments<br />

This function is called before data are transferred with DMA. This makes sure that the DMA<br />

engine find the correct data in the physical memory. If the architecture does not use cached<br />

memory this function can be implemented as a void macro.<br />

This function is non blocking.<br />

See Also<br />

TAL_InvalidateCache (page 137)<br />

TAL_AllocateDmaMemory (page 135)<br />

138 <strong>USB</strong> Bus Driver Reference Manual


TAL_WriteSync<br />

This function forces the CPU to write the write cache to the memory.<br />

Definition<br />

void<br />

TAL_WriteSync(<br />

void* Address,<br />

unsigned long Length<br />

);<br />

Parameters<br />

Address<br />

Virtual address of the cached memory.<br />

Length<br />

Specifies the length in bytes.<br />

Comments<br />

10 Abstraction Layer Reference<br />

The implementation of this function is required, when the CPU has a write cache. When the<br />

CPU does not use this feature make an empty define for this function. The stack call this<br />

function when ever it is required.<br />

This function is non blocking.<br />

See Also<br />

TAL_InvalidateCache (page 137)<br />

<strong>USB</strong> Bus Driver Reference Manual 139


10 Abstraction Layer Reference<br />

TAL_BuildDmaMd<br />

The TAL_BuildDmaMd routine builds a memory descriptor list from a given memory buffer.<br />

This list describes the underlying physical pages in the buffer.<br />

Definition<br />

void<br />

TAL_BuildDmaMd(<br />

TAL_MD* MemoryDescriptor<br />

);<br />

Parameter<br />

MemoryDescriptor<br />

Pointer memory descriptor that is used as an input and output parameter. On input the<br />

parameters TAL_MD.Header.VirtAddr and TAL_MD.Header.Length describe the virtual<br />

memory. On output all other parameters are valid.<br />

Comments<br />

The maximum number of physical page entries is equal TAL_TRANSFER_PAGES. The size<br />

of one physical page is TAL_PHYMEM_PAGE_SIZE. The function can be used with<br />

memory that was allocated with TAL_Malloc or TAL_AllocateDmaDescMemory. On error<br />

the returned number of memory pages is zero.<br />

The function is non blocking.<br />

See Also<br />

TAL_MD (page 162)<br />

TAL_Malloc (page 130)<br />

TAL_AllocateDmaDescMemory (page 132)<br />

140 <strong>USB</strong> Bus Driver Reference Manual


10.7 Timer<br />

Timers are required for the most host controller drivers.<br />

TAL_TimerCallbackRoutine<br />

10 Abstraction Layer Reference<br />

This function is the prototype for a timer callback function which is called if a timeout on a TAL<br />

timer function occurs.<br />

Definition<br />

typedef<br />

void<br />

TAL_TimerCallbackRoutine(<br />

void* Context<br />

);<br />

Parameter<br />

Context<br />

This parameter is the context of the callback routine.<br />

Comments<br />

In the context of this callback function blocking functions must not be called.<br />

See Also<br />

TAL_AllocTimer (page 142)<br />

TAL_StartTimer (page 144)<br />

<strong>USB</strong> Bus Driver Reference Manual 141


10 Abstraction Layer Reference<br />

TAL_AllocTimer<br />

This routine allocates a timer and returns a handle to this timer.<br />

Definition<br />

TAL_TIMER_HANDLE<br />

TAL_AllocTimer(<br />

TAL_TimerCallbackRoutine* TimerCallbackRoutine,<br />

void* Context<br />

);<br />

Parameters<br />

TimerCallbackRoutine<br />

Pointer to the notification function that is called from the timer.<br />

Context<br />

Context pointer for user information. This pointer is passed unchanged to the notification<br />

function.<br />

Comments<br />

This is needed to synchronize accesses in the <strong>Embedded</strong> <strong>USB</strong> <strong>Host</strong> <strong>Stack</strong>. Other timers may<br />

be blocked until the notification function returns. For that reason the notification function<br />

should not be blocked for a long time. It is not allowed to call TAL_FreeTimer from the<br />

context of the notification function.<br />

This function is non blocking.<br />

See Also<br />

TAL_FreeTimer (page 143)<br />

TAL_StartTimer (page 144)<br />

TAL_WaitEvent (page 152)<br />

142 <strong>USB</strong> Bus Driver Reference Manual


TAL_FreeTimer<br />

This routine frees all resources of a timer.<br />

Definition<br />

void<br />

TAL_FreeTimer(<br />

TAL_TIMER_HANDLE TimerHandle<br />

);<br />

Parameter<br />

TimerHandle<br />

Handle to a timer previously allocated by a call to TAL_AllocTimer.<br />

Comments<br />

When this function is called the timer is implicitly canceled.<br />

10 Abstraction Layer Reference<br />

After the timer is canceled the function waits until a pending timer callback associated with<br />

this timer is finished. So after this function returns there is a guarantee that the timer callback<br />

for this timer will not run.<br />

This function is blocking.<br />

Be careful about potential deadlocks. Do not call TAL_FreeTimer while holding a mutex<br />

that is acquired by your timer callback as well.<br />

See Also<br />

TAL_AllocTimer (page 142)<br />

TAL_CancelTimer (page 145)<br />

<strong>USB</strong> Bus Driver Reference Manual 143


10 Abstraction Layer Reference<br />

TAL_StartTimer<br />

This routine starts a timer.<br />

Definition<br />

void<br />

TAL_StartTimer(<br />

TAL_TIMER_HANDLE TimerHandle,<br />

unsigned long Time<br />

);<br />

Parameters<br />

TimerHandle<br />

Valid TAL timer handle.<br />

Time<br />

Timeout in milliseconds.<br />

Return Value<br />

The function returns T_TRUE if a new timer is started. The function returns T_FALSE when<br />

the timer was running and is restarted.<br />

Comments<br />

The timer is a single shot timer, i.e. the notification function of the timer is called one time<br />

after the Time period has been elapsed. The timer can be started again in the context of the<br />

timer notification function. The TAL_StartTimer function can be called regardless if the<br />

current timer is still active or not. The parameter Time is set as the current timeout value.<br />

The function is non blocking.<br />

See Also<br />

TAL_CancelTimer (page 145)<br />

144 <strong>USB</strong> Bus Driver Reference Manual


TAL_CancelTimer<br />

This routine stops a timer. It can be called regardless if the timer is active or not.<br />

Definition<br />

void<br />

TAL_CancelTimer(<br />

TAL_TIMER_HANDLE TimerHandle<br />

);<br />

Parameter<br />

TimerHandle<br />

Valid TAL timer handle.<br />

Return Value<br />

10 Abstraction Layer Reference<br />

The function returns T_TRUE if the timer was removed from the timer list. In this case the<br />

timer callback function is not called. The function returns T_FALSE when the timer was not<br />

in the timer list. In this case the timer callback function may be called.<br />

Comments<br />

At the end of the timeout period there is a racing condition between the canceling process and<br />

the notification function. This means the notification function can be started when this<br />

function is called. Since the timer callbacks are not called from the <strong>USB</strong> Bus Driver Core you<br />

can not use the function <strong>USB</strong>H_WaitForIdle<strong>Stack</strong> to wait until no timer callbacks will<br />

be called.<br />

The function is non blocking.<br />

See Also<br />

TAL_StartTimer (page 144)<br />

<strong>USB</strong> Bus Driver Reference Manual 145


10 Abstraction Layer Reference<br />

TAL_GetTime<br />

This function returns a relative time stamp in units of one microsecond.<br />

Definition<br />

unsigned long<br />

TAL_GetTime();<br />

Return Value<br />

The returned time stamp in microseconds.<br />

Comments<br />

A hardware timer should be used to measure the time. The time runs over from 0xffffffff to 0<br />

after 1.1 hours. The timestamp should be used to determine time differences.<br />

The function is non blocking.<br />

146 <strong>USB</strong> Bus Driver Reference Manual


TAL_Sleep<br />

10 Abstraction Layer Reference<br />

This function suspends the execution of the current thread for a specified interval.<br />

Definition<br />

void<br />

TAL_Sleep(<br />

unsigned int Milliseconds<br />

);<br />

Parameter<br />

Milliseconds<br />

Specifies the time, in milliseconds, for which to suspend execution.<br />

Comments<br />

This function should perform a task switch if possible or call a idle loop function to see if<br />

other work can be done. It must not return until the requested time has been elapsed. But it<br />

can return later.<br />

This function is blocking.<br />

<strong>USB</strong> Bus Driver Reference Manual 147


10 Abstraction Layer Reference<br />

10.8 Events<br />

The following events are required if a <strong>USB</strong> class driver is used that implements a synchronous<br />

data transfer. The following class drivers provided by <strong>Thesycon</strong> implement a synchronous data<br />

transfer and therefor need event objects:<br />

• CDC/ACM Class Driver<br />

• HID Class Driver<br />

• Printer Class Driver<br />

• Mass Storage Class Driver<br />

TAL_AllocEvent<br />

This function creates an event object.<br />

Definition<br />

TAL_EventObject<br />

TAL_AllocEvent();<br />

Return Value<br />

The function returns either a pointer to the event object on success or a NULL pointer if the<br />

creation of the event object failed.<br />

Comments<br />

The initial state of the event object is not signaled. The event object can be a manual or an<br />

auto reset event. The user should not make assumptions about the behavior. This tolerant<br />

definition of the event makes it easier to implement the TAL Layer on different platforms.<br />

The user defined data structure TAL_EventObject can contain any information that is required<br />

to handle the event.<br />

This function is non blocking.<br />

See Also<br />

TAL_FreeEvent (page 149)<br />

TAL_SetEvent (page 150)<br />

148 <strong>USB</strong> Bus Driver Reference Manual


TAL_FreeEvent<br />

This function releases an event object and frees all associated resources.<br />

Definition<br />

void<br />

TAL_FreeEvent(<br />

TAL_EventObject Event<br />

);<br />

Parameter<br />

Event<br />

Specifies an event previously allocated by a call to TAL_AllocEvent.<br />

Comments<br />

The function must not be called if the event is in use.<br />

This function is non blocking.<br />

See Also<br />

TAL_AllocEvent (page 148)<br />

10 Abstraction Layer Reference<br />

<strong>USB</strong> Bus Driver Reference Manual 149


10 Abstraction Layer Reference<br />

TAL_SetEvent<br />

This function sets the state of the specified event object to signaled.<br />

Definition<br />

void<br />

TAL_SetEvent(<br />

TAL_EventObject Event<br />

);<br />

Parameter<br />

Event<br />

Pointer to the event object.<br />

Comments<br />

When a event is signaled a task that waits on the event can continue the execution.<br />

This function is non blocking.<br />

See Also<br />

TAL_ResetEvent (page 151)<br />

150 <strong>USB</strong> Bus Driver Reference Manual


TAL_ResetEvent<br />

This function sets the state of the specified event object to not signaled.<br />

Definition<br />

void<br />

TAL_ResetEvent(<br />

TAL_EventObject Event<br />

);<br />

Parameter<br />

Event<br />

Pointer to the event object.<br />

Comments<br />

The event must be reseted manually.<br />

This function is non blocking.<br />

See Also<br />

TAL_SetEvent (page 150)<br />

10 Abstraction Layer Reference<br />

<strong>USB</strong> Bus Driver Reference Manual 151


10 Abstraction Layer Reference<br />

TAL_WaitEvent<br />

This function returns when the specified object is in the signaled state or when the timeout<br />

interval has been elapsed.<br />

Definition<br />

unsigned int<br />

TAL_WaitEvent(<br />

TAL_EventObject Event,<br />

unsigned long milliSeconds<br />

);<br />

Parameters<br />

Event<br />

Pointer to the event object.<br />

milliSeconds<br />

Specifies the timeout interval, in milliseconds. If this parameter is TAL_WAIT_INFINITE the<br />

function’s timeout interval never elapses. If TAL_WAIT_INFINITE is set this function returns<br />

only if the event is set to the signaled state.<br />

Return Value<br />

The function returns the following status codes:<br />

TAL_WAIT_TIMEOUT - The timeout interval elapsed and the state of the event object is not<br />

signaled.<br />

TAL_WAIT_SIGNALED - The state of the specified event object is signaled.<br />

Comments<br />

The TAL_WaitEvent function suspends the current task until the event is signaled or the<br />

timeout elapses. If the timeout is 0 the state of the event is immediately returned.<br />

TAL_WaitEvent for one event object instance will never be called by more than one thread<br />

at any given point in time. The caller should not make assumptions about the state of the event<br />

after the TAL_WaitEvent function has been returned. When the function returns with<br />

TAL_WAIT_TIMEOUT the event is not signaled and the caller can wait again on the event.<br />

This function is blocking.<br />

See Also<br />

TAL_SetEvent (page 150)<br />

TAL_ResetEvent (page 151)<br />

152 <strong>USB</strong> Bus Driver Reference Manual


10.9 Mutex<br />

TAL_AllocMutex<br />

This function creates a mutex object.<br />

Definition<br />

TAL_MutexObject<br />

TAL_AllocMutex();<br />

Return Value<br />

10 Abstraction Layer Reference<br />

The function returns either a pointer to the mutex object on success or a NULL pointer if the<br />

creation of the mutex object failed.<br />

Comments<br />

The initial state of the mutex object is not entered. The mutex object can be entered one time<br />

by a task.<br />

This function is non blocking.<br />

See Also<br />

TAL_FreeMutex (page 154)<br />

TAL_EnterMutex (page 155)<br />

TAL_LeaveMutex (page 156)<br />

<strong>USB</strong> Bus Driver Reference Manual 153


10 Abstraction Layer Reference<br />

TAL_FreeMutex<br />

This function frees the memory of a valid mutex object.<br />

Definition<br />

void<br />

TAL_FreeMutex(<br />

TAL_MutexObject Mutex<br />

);<br />

Parameter<br />

Mutex<br />

Pointer to the mutex object.<br />

Comments<br />

The function must called with a valid mutex object. The object must not be accessed after it is<br />

freed.<br />

This function is non blocking.<br />

See Also<br />

TAL_AllocMutex (page 153)<br />

TAL_EnterMutex (page 155)<br />

TAL_LeaveMutex (page 156)<br />

154 <strong>USB</strong> Bus Driver Reference Manual


TAL_EnterMutex<br />

This function enters a mutex to access code that is protected by this object.<br />

Definition<br />

void<br />

TAL_EnterMutex(<br />

TAL_MutexObject Mutex<br />

);<br />

Parameter<br />

Mutex<br />

Pointer to the mutex object.<br />

Comments<br />

10 Abstraction Layer Reference<br />

The function may suspend the calling task when the mutex is used by a different task.<br />

When the mutex is held in any execution path while a blocking function is called this function<br />

must be considered as blocking. It can be considered as non blocking when no blocking<br />

function is called under this mutex.<br />

This function is blocking or non blocking depending on the usage.<br />

See Also<br />

TAL_AllocMutex (page 153)<br />

TAL_FreeMutex (page 154)<br />

TAL_LeaveMutex (page 156)<br />

<strong>USB</strong> Bus Driver Reference Manual 155


10 Abstraction Layer Reference<br />

TAL_LeaveMutex<br />

This function leaves a code section that is protected by this mutex and allows other tasks to<br />

access this code area.<br />

Definition<br />

void<br />

TAL_LeaveMutex(<br />

TAL_MutexObject Mutex<br />

);<br />

Parameter<br />

Mutex<br />

Pointer to the mutex object.<br />

Comments<br />

The calling task must enter the mutex before it calls this function to leave it. It is not allowed<br />

to call this function without a call to the function TAL_EnterMutex before.<br />

This function is non blocking.<br />

See Also<br />

TAL_AllocMutex (page 153)<br />

TAL_FreeMutex (page 154)<br />

TAL_EnterMutex (page 155)<br />

156 <strong>USB</strong> Bus Driver Reference Manual


10.10 Task<br />

TAL_CreateTask<br />

This function creates a task.<br />

Definition<br />

TAL_TaskObject<br />

TAL_CreateTask(<br />

TAL_TASK_FUNCTION* taskFunction,<br />

void* context,<br />

unsigned int stackSize,<br />

const char* taskName<br />

);<br />

Parameters<br />

taskFunction<br />

Pointer to the task function.<br />

context<br />

Pointer to the context that is passed to the task function.<br />

stackSize<br />

<strong>Stack</strong> size in bytes. The value must be larger than zero.<br />

taskName<br />

Pointer to the task name string. Set to NULL if no name is provided.<br />

Return Value<br />

10 Abstraction Layer Reference<br />

The function returns either a pointer to the task object on success or a NULL pointer if<br />

creation of the task failed.<br />

Comments<br />

The task is terminated when the task routine returns. There is no way to kill the task.<br />

This function is non blocking.<br />

See Also<br />

TAL_DeleteTask (page 158)<br />

TAL_WaitTask (page 159)<br />

<strong>USB</strong> Bus Driver Reference Manual 157


10 Abstraction Layer Reference<br />

TAL_DeleteTask<br />

This function waits until the task function has returned and deletes the task object.<br />

Definition<br />

void<br />

TAL_DeleteTask(<br />

TAL_TaskObject taskObject<br />

);<br />

Parameter<br />

taskObject<br />

Pointer to the task object that was returned by TAL_CreateTask.<br />

Comments<br />

When this function is called by the task it self a dead lock occurs. The function waits infinite<br />

until the task function has returned and than it deletes the task object. See also<br />

TAL_WaitTask.<br />

This function is blocking.<br />

See Also<br />

TAL_CreateTask (page 157)<br />

TAL_WaitTask (page 159)<br />

158 <strong>USB</strong> Bus Driver Reference Manual


TAL_WaitTask<br />

10 Abstraction Layer Reference<br />

This function waits until the task function has returned, i.e. the task is terminated.<br />

Definition<br />

unsigned int<br />

TAL_WaitTask(<br />

TAL_TaskObject task,<br />

unsigned long timeoutMs<br />

);<br />

Parameters<br />

task<br />

Pointer to the task object that was returned by TAL_CreateTask.<br />

timeoutMs<br />

Timeout value in milliseconds. The function returns after this timeout, when the task function<br />

is not yet returned.<br />

Return Value<br />

The function returns either a TAL_WAIT_SIGNALED or TAL_WAIT_TIMEOUT.<br />

TAL_WAIT_SIGNALED indicates that the task function has returned.<br />

Comments<br />

This function can be used to wait on the completion of a task with timeout. After this function<br />

has returned with TAL_WAIT_SIGNALED the function TAL_DeleteTask must be called<br />

to delete the task object.<br />

This function is blocking.<br />

See Also<br />

TAL_CreateTask (page 157)<br />

TAL_DeleteTask (page 158)<br />

<strong>USB</strong> Bus Driver Reference Manual 159


10 Abstraction Layer Reference<br />

10.11 Data Structures<br />

TAL_MD_HEADER<br />

The structure represents the memory descriptor header.<br />

Definition<br />

typedef struct T_TAL_MD_HEADER{<br />

void* VirtAddr;<br />

unsigned long Length;<br />

unsigned long NumberOfPages;<br />

} TAL_MD_HEADER;<br />

Members<br />

VirtAddr<br />

Pointer to the base virtual address of the buffer the MDL describes.<br />

Length<br />

Specifies the length in bytes of the buffer the MDL describes.<br />

NumberOfPages<br />

Specifies the number of valid page entries in the memory descriptor TAL_MD.<br />

See Also<br />

TAL_MD_PAGE_ENTRY (page 161)<br />

TAL_MD (page 162)<br />

160 <strong>USB</strong> Bus Driver Reference Manual


TAL_MD_PAGE_ENTRY<br />

The structure describes one entry of a memory page.<br />

Definition<br />

typedef struct T_TAL_MD_PAGE_ENTRY{<br />

void* VirtAddr;<br />

unsigned long PhyAddr;<br />

unsigned long Length;<br />

} TAL_MD_PAGE_ENTRY;<br />

Members<br />

VirtAddr<br />

Pointer to the virtual address of the page entry.<br />

PhyAddr<br />

Pointer to the physical address of the page entry.<br />

Length<br />

Length in bytes of the page.<br />

See Also<br />

TAL_MD_HEADER (page 160)<br />

TAL_MD (page 162)<br />

10 Abstraction Layer Reference<br />

<strong>USB</strong> Bus Driver Reference Manual 161


10 Abstraction Layer Reference<br />

TAL_MD<br />

The structure describes a memory descriptor with a fixed memory location list.<br />

Definition<br />

typedef struct T_TAL_MD{<br />

TAL_MD_HEADER Header;<br />

TAL_MD_PAGE_ENTRY Entries[TAL_TRANSFER_PAGES];<br />

} TAL_MD;<br />

Members<br />

Header<br />

This field contains the header of the memory descriptor.<br />

Entries[TAL_TRANSFER_PAGES]<br />

This field contains the memory description list with a maximum number of entries.<br />

Comments<br />

The maximum size of the memory descriptor list limits the size of transfer descriptors that can<br />

be used. The default value defined in usbh_default_config.h should be used.<br />

See Also<br />

TAL_BuildDmaMd (page 140)<br />

162 <strong>USB</strong> Bus Driver Reference Manual


TAL_TIMER_HANDLE<br />

The type TAL_TIMER_HANDLE is a pointer to the TAL timer object.<br />

Definition<br />

typedef void*{ } TAL_TIMER_HANDLE;<br />

Member<br />

See Also<br />

TAL_AllocTimer (page 142)<br />

TAL_FreeTimer (page 143)<br />

TAL_StartTimer (page 144)<br />

TAL_CancelTimer (page 145)<br />

10 Abstraction Layer Reference<br />

<strong>USB</strong> Bus Driver Reference Manual 163


11 CDC/ACM Class Driver Reference<br />

11 CDC/ACM Class Driver Reference<br />

11.1 Application programming interface<br />

HCLS_ACM_Init<br />

The function initializes this class.<br />

Definition<br />

T_BOOL<br />

HCLS_ACM_Init();<br />

Return Value<br />

It returns T_TRUE on success or T_FALSE if some resources are not available.<br />

Comments<br />

The function must be called one time before any other API functions of this class driver can be<br />

called. When the class driver is no longer required HCLS_ACM_Exit must be called. If<br />

HCLS_ACM_Exit is not called the class driver has a memory leak.<br />

This function is non blocking.<br />

See Also<br />

HCLS_ACM_Exit (page 165)<br />

164 <strong>USB</strong> Bus Driver Reference Manual


HCLS_ACM_Exit<br />

The exit function de-registers PnP handler and frees the allocated resources.<br />

Definition<br />

void<br />

HCLS_ACM_Exit();<br />

Comments<br />

11 CDC/ACM Class Driver Reference<br />

This function should be called one time when the class is not longer required. After the<br />

function was called no callbacks are called from this class driver.<br />

This function is blocking.<br />

See Also<br />

HCLS_ACM_Init (page 164)<br />

<strong>USB</strong> Bus Driver Reference Manual 165


11 CDC/ACM Class Driver Reference<br />

HCLS_ACM_DeviceConnected<br />

Prototype for a callback function that can be called when a device with a CDC ACM interface is<br />

connected to the <strong>USB</strong> host.<br />

Definition<br />

typedef<br />

void<br />

HCLS_ACM_DeviceConnected(<br />

void* context,<br />

<strong>USB</strong>H_INTERFACE_ID interfaceID<br />

);<br />

Parameters<br />

context<br />

This is the unchanged context pointer that was passed to the function call<br />

HCLS_ACM_RegisterConnectHandler. It can be used by the application.<br />

interfaceID<br />

The interface ID is an unique identifier for the interface. This identifier can be used to get<br />

more information about the interface. When the device with this interface is disconnected and<br />

reconnected the host stack assigned a different interface ID.<br />

Comments<br />

Do not call any blocking functions in this context. See also the comments in<br />

HCLS_ACM_RegisterConnectHandler.<br />

See Also<br />

HCLS_ACM_RegisterConnectHandler (page 167)<br />

166 <strong>USB</strong> Bus Driver Reference Manual


HCLS_ACM_RegisterConnectHandler<br />

This function registers a callback function for device connect events.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_ACM_RegisterConnectHandler(<br />

HCLS_ACM_DeviceConnected* connectNotification,<br />

void* context<br />

);<br />

Parameters<br />

connectNotification<br />

The address of the callback function that should be called.<br />

11 CDC/ACM Class Driver Reference<br />

context<br />

The context that is passed to the callback function. This can be any user defined pointer or<br />

NULL.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

This function allows event based notifications for connected class interfaces. When this<br />

function is called the stack calls the callback function immediately for all currently connected<br />

class compliant interfaces. An alternative method to be informed about new devices is the<br />

polling of the available devices with HCLS_ACM_CreateInterfaceList.<br />

To unregister the callback call this function with connectNotification set to NULL.<br />

This function is non blocking.<br />

See Also<br />

HCLS_ACM_CreateInterfaceList (page 168)<br />

HCLS_ACM_DeviceConnected (page 166)<br />

<strong>USB</strong> Bus Driver Reference Manual 167


11 CDC/ACM Class Driver Reference<br />

HCLS_ACM_CreateInterfaceList<br />

Creates an internal list with interfaces that expose a CDC ACM compliant interface.<br />

Definition<br />

<strong>USB</strong>H_INTERFACE_LIST_HANDLE<br />

HCLS_ACM_CreateInterfaceList(<br />

unsigned int* InterfaceCount<br />

);<br />

Parameter<br />

InterfaceCount<br />

This parameter returns the number of available interface.<br />

Return Value<br />

It returns a valid list handle on success or NULL if no resources are available.<br />

Comments<br />

The internal list contains a snap shot of the CDC ACM interfaces that were available at the<br />

calling time. The returned handle must be freed with<br />

HCLS_ACM_DestroyInterfaceList. The devices in the list can be enumerated with<br />

HCLS_ACM_GetInterfaceID. The relation of the index and the interface ID in a list is<br />

constant.<br />

This function is non blocking.<br />

See Also<br />

HCLS_ACM_DestroyInterfaceList (page 169)<br />

HCLS_ACM_GetInterfaceID (page 170)<br />

168 <strong>USB</strong> Bus Driver Reference Manual


HCLS_ACM_DestroyInterfaceList<br />

The function frees the resources that are used for the internal interface list.<br />

Definition<br />

void<br />

HCLS_ACM_DestroyInterfaceList(<br />

<strong>USB</strong>H_INTERFACE_LIST_HANDLE InterfaceListHandle<br />

);<br />

Parameter<br />

InterfaceListHandle<br />

A list handle that was returned by a successful call to the function<br />

HCLS_ACM_CreateInterfaceList.<br />

Comments<br />

This function should be called when the list is not longer needed.<br />

This function is non blocking.<br />

See Also<br />

HCLS_ACM_CreateInterfaceList (page 168)<br />

11 CDC/ACM Class Driver Reference<br />

<strong>USB</strong> Bus Driver Reference Manual 169


11 CDC/ACM Class Driver Reference<br />

HCLS_ACM_GetInterfaceID<br />

This function can be used to get the unique interface ID in an interface list.<br />

Definition<br />

<strong>USB</strong>H_INTERFACE_ID<br />

HCLS_ACM_GetInterfaceID(<br />

<strong>USB</strong>H_INTERFACE_LIST_HANDLE InterfaceListHandle,<br />

unsigned int Index<br />

);<br />

Parameters<br />

InterfaceListHandle<br />

A list handle that was returned by a successful call to the function<br />

HCLS_ACM_CreateInterfaceList.<br />

Index<br />

Is a number between 0 and InterfaceCount-1. The InterfaceCount is returned by<br />

the function HCLS_ACM_CreateInterfaceList.<br />

Return Value<br />

The function returns the unique interface ID that is stored at the position of index in the list.<br />

Comments<br />

The interface list has a constant relation between the index and interface IDs and it is a snap<br />

shoot of the available interface at the point of time when the list was created. When a device is<br />

disconnected and reconnected it gets new interface IDs. A list can contain interface IDs that<br />

are not longer available on the bus.<br />

This function is non blocking.<br />

See Also<br />

HCLS_ACM_CreateInterfaceList (page 168)<br />

170 <strong>USB</strong> Bus Driver Reference Manual


HCLS_ACM_GetInterfaceInfo<br />

The function returns additional information to a known interface ID.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_ACM_GetInterfaceInfo(<br />

<strong>USB</strong>H_INTERFACE_ID InterfaceID,<br />

<strong>USB</strong>H_INTERFACE_INFO* InterfaceInfo<br />

);<br />

Parameters<br />

11 CDC/ACM Class Driver Reference<br />

InterfaceID<br />

The unique interface ID specifies the interface for which additional information should be<br />

returned. The interface ID is returned either by HCLS_ACM_GetInterfaceID or<br />

HCLS_ACM_DeviceConnected.<br />

InterfaceInfo<br />

The caller provides the storage for this structure and retrieves information about the specified<br />

interface.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

The additional information can be used to identify the device more exactly e.g. with the PID<br />

or the serial number.<br />

This function is non blocking.<br />

See Also<br />

HCLS_ACM_GetInterfaceID (page 170)<br />

HCLS_ACM_DeviceConnected (page 166)<br />

<strong>USB</strong>H_INTERFACE_INFO (page 92)<br />

<strong>USB</strong> Bus Driver Reference Manual 171


11 CDC/ACM Class Driver Reference<br />

HCLS_ACM_DeviceRemoved<br />

Prototype for a callback that is called when a the device with the CDC ACM interface is removed.<br />

Definition<br />

typedef<br />

void<br />

HCLS_ACM_DeviceRemoved(<br />

void* context<br />

);<br />

Parameter<br />

context<br />

The context for the function that was passed to the function call HCLS_ACM_Open.<br />

Comments<br />

A callback of this function can be registered with HCLS_ACM_Open to see when the<br />

corresponding opened interface is removed.<br />

Do not call other blocking functions in this context.<br />

See Also<br />

HCLS_ACM_Open (page 173)<br />

172 <strong>USB</strong> Bus Driver Reference Manual


HCLS_ACM_Open<br />

11 CDC/ACM Class Driver Reference<br />

This function opens an interface exclusively and optionally registers a remove notification<br />

function.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_ACM_Open(<br />

<strong>USB</strong>H_INTERFACE_ID InterfaceID,<br />

HCLS_ACM_DeviceRemoved* removeNotification,<br />

void* context,<br />

HCLS_ACM_Handle* handle<br />

);<br />

Parameters<br />

InterfaceID<br />

The unique interface ID specifies the interface which should be opened. The interface ID is<br />

returned either by HCLS_ACM_GetInterfaceID or HCLS_ACM_DeviceConnected.<br />

The device with this interface ID may be removed in the meantime. For that reason the open<br />

function can fail with <strong>USB</strong>H_STATUS_DEVICE_REMOVED.<br />

removeNotification<br />

This parameter is optional. The caller provides the address of a function prototype<br />

HCLS_ACM_DeviceRemoved or NULL. When the caller provides this function pointer and<br />

the open function returns with success, the remove notification function is called when the<br />

device is removed. The function is de-registered and not longer called when the interface is<br />

closed.<br />

context<br />

A user provided context for the remove notification function HCLS_ACM_DeviceRemoved<br />

or NULL.<br />

handle<br />

On success the function returns a handle to the interface that is used for the operational access.<br />

If opening of the specified interface fails the handle will be NULL which is an invalid handle<br />

value.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

When the remove notification function is not used the application can poll the presence of the<br />

device with HCLS_ACM_IsDevicePresent. The returned handle must be closed with<br />

<strong>USB</strong> Bus Driver Reference Manual 173


11 CDC/ACM Class Driver Reference<br />

HCLS_ACM_Close when it is not longer required. This class does not implement an internal<br />

buffer circulation for the data endpoints. To create IN tokens on the bulk IN endpoint the<br />

application has to pass a buffer with the function HCLS_ACM_Read to the class. After this<br />

function returns with success the class driver service the notification pipe and creates IN<br />

tokens on it.<br />

This function is blocking.<br />

See Also<br />

HCLS_ACM_GetInterfaceID (page 170)<br />

HCLS_ACM_DeviceConnected (page 166)<br />

HCLS_ACM_DeviceRemoved (page 172)<br />

HCLS_ACM_IsDevicePresent (page 176)<br />

HCLS_ACM_Close (page 175)<br />

HCLS_ACM_Read (page 190)<br />

174 <strong>USB</strong> Bus Driver Reference Manual


HCLS_ACM_Close<br />

The function closes an interface and releases the exclusive use.<br />

Definition<br />

void<br />

HCLS_ACM_Close(<br />

HCLS_ACM_Handle handle<br />

);<br />

Parameter<br />

handle<br />

The handle returned by HCLS_ACM_Open.<br />

Comments<br />

11 CDC/ACM Class Driver Reference<br />

The caller has to make sure that all URB buffers that has been passed with HCLS_ACM_Read<br />

and HCLS_ACM_Write has been returned before this function is called. The caller can use<br />

HCLS_ACM_AbortRead and HCLS_ACM_AbortWrite to archive this.<br />

This function is blocking.<br />

See Also<br />

HCLS_ACM_Open (page 173)<br />

HCLS_ACM_Read (page 190)<br />

HCLS_ACM_Write (page 185)<br />

HCLS_ACM_AbortRead (page 192)<br />

HCLS_ACM_AbortWrite (page 187)<br />

<strong>USB</strong> Bus Driver Reference Manual 175


11 CDC/ACM Class Driver Reference<br />

HCLS_ACM_IsDevicePresent<br />

The function indicates if the device is present or not.<br />

Definition<br />

T_BOOL<br />

HCLS_ACM_IsDevicePresent(<br />

HCLS_ACM_Handle handle<br />

);<br />

Parameter<br />

handle<br />

The handle returned by HCLS_ACM_Open.<br />

Return Value<br />

The function returns T_TRUE when the device is present or T_FALSE when the device is<br />

removed.<br />

Comments<br />

This function is non blocking.<br />

See Also<br />

HCLS_ACM_Open (page 173)<br />

176 <strong>USB</strong> Bus Driver Reference Manual


HCLS_ACM_GetDeviceStatus<br />

This function returns the device status.<br />

Definition<br />

T_UINT16<br />

HCLS_ACM_GetDeviceStatus(<br />

HCLS_ACM_Handle handle<br />

);<br />

Parameter<br />

handle<br />

The handle returned by HCLS_ACM_Open.<br />

Return Value<br />

The function returns a or’ed combination of the following flags:<br />

11 CDC/ACM Class Driver Reference<br />

T<strong>USB</strong>_CLS_CDC_NOTIFY_SERIAL_STATE_DCD<br />

The line Data Carrier Detected is signaled.<br />

T<strong>USB</strong>_CLS_CDC_NOTIFY_SERIAL_STATE_DSR<br />

The line Data Send Ready is signaled.<br />

T<strong>USB</strong>_CLS_CDC_NOTIFY_SERIAL_STATE_BREAK<br />

The device signals a Break.<br />

T<strong>USB</strong>_CLS_CDC_NOTIFY_SERIAL_STATE_RING_SIGNAL<br />

The line Ring is signaled.<br />

T<strong>USB</strong>_CLS_CDC_NOTIFY_SERIAL_STATE_FRAMING<br />

A framing error in the device has been occurred.<br />

T<strong>USB</strong>_CLS_CDC_NOTIFY_SERIAL_STATE_PARITY<br />

A parity error in the device has been occurred.<br />

T<strong>USB</strong>_CLS_CDC_NOTIFY_SERIAL_STATE_OVERRUN<br />

A overrun error in the device has been occurred.<br />

HCLS_ACM_SERIAL_STATE_CONNECTED<br />

The device signals T<strong>USB</strong>_CLS_CDC_NOTIFY_NETWORK_CONNECTION.<br />

Comments<br />

The information that is returned by this function is stored inside the class driver. The<br />

information is updated internally with the notification endpoint of the class. To get an event<br />

when the status information is changed use the function<br />

HCLS_ACM_RegisterStatusChangeHandler.<br />

This function is non blocking.<br />

<strong>USB</strong> Bus Driver Reference Manual 177


11 CDC/ACM Class Driver Reference<br />

See Also<br />

HCLS_ACM_Open (page 173)<br />

HCLS_ACM_RegisterStatusChangeHandler (page 180)<br />

178 <strong>USB</strong> Bus Driver Reference Manual


HCLS_ACM_DeviceStatusChanged<br />

11 CDC/ACM Class Driver Reference<br />

Prototype of a callback that is called by the class driver when the device status has been changed.<br />

Definition<br />

typedef<br />

void<br />

HCLS_ACM_DeviceStatusChanged(<br />

void* context,<br />

T_UINT16 state<br />

);<br />

Parameters<br />

context<br />

The context that was passed to HCLS_ACM_RegisterStatusChangeHandler.<br />

state<br />

This parameter contains the or’ed combination of the device status. See<br />

HCLS_ACM_GetDeviceStatus for a definition of the bits.<br />

Comments<br />

This function prototype can be registered with<br />

HCLS_ACM_RegisterStatusChangeHandler to receive notifications when the device<br />

status changes. It is not allowed to call blocking functions of the stack in the context of this<br />

call back function.<br />

See Also<br />

HCLS_ACM_RegisterStatusChangeHandler (page 180)<br />

HCLS_ACM_GetDeviceStatus (page 177)<br />

<strong>USB</strong> Bus Driver Reference Manual 179


11 CDC/ACM Class Driver Reference<br />

HCLS_ACM_RegisterStatusChangeHandler<br />

This function registers or unregisters a status change notification handler.<br />

Definition<br />

void<br />

HCLS_ACM_RegisterStatusChangeHandler(<br />

HCLS_ACM_Handle handle,<br />

HCLS_ACM_DeviceStatusChanged* statusNotification,<br />

void* context<br />

);<br />

Parameters<br />

handle<br />

The handle returned by HCLS_ACM_Open.<br />

statusNotification<br />

A pointer to a function with the prototype of HCLS_ACM_DeviceStatusChanged to<br />

register a notification call back function or NULL to unregister it.<br />

context<br />

A user defined context that is passed to the notification call back function or NULL if not used.<br />

Comments<br />

When a notification function was registered it must be unregistered before that interface is<br />

closed. The application can register one notification function per interface.<br />

This function is non blocking.<br />

See Also<br />

HCLS_ACM_Open (page 173)<br />

HCLS_ACM_DeviceStatusChanged (page 179)<br />

180 <strong>USB</strong> Bus Driver Reference Manual


HCLS_ACM_SetLineCoding<br />

This function sets the line coding in the device.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_ACM_SetLineCoding(<br />

HCLS_ACM_Handle handle,<br />

HCLS_ACM_LineCoding* lineCoding<br />

);<br />

Parameters<br />

handle<br />

The handle returned by HCLS_ACM_Open.<br />

11 CDC/ACM Class Driver Reference<br />

lineCoding<br />

A pointer to a caller provided and initialized data structure that contains the line coding to be<br />

set.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

The function sends the class request T<strong>USB</strong>_CLS_CDC_REQ_SET_LINE_CODING to the<br />

device. When the device fails the operation the function returns an error. The application may<br />

decide to ignore the error and avoid the sending of this request.<br />

This function is blocking.<br />

See Also<br />

HCLS_ACM_Open (page 173)<br />

HCLS_ACM_LineCoding (page 194)<br />

HCLS_ACM_SetControlLineState (page 182)<br />

<strong>USB</strong> Bus Driver Reference Manual 181


11 CDC/ACM Class Driver Reference<br />

HCLS_ACM_SetControlLineState<br />

This function sets the control lines of the host.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_ACM_SetControlLineState(<br />

HCLS_ACM_Handle handle,<br />

T_UINT16 lineState<br />

);<br />

Parameters<br />

handle<br />

The handle returned by HCLS_ACM_Open.<br />

lineState<br />

This parameter contains a or’ed combination of the following flags:<br />

T<strong>USB</strong>_CLS_CDC_SET_CONTROL_LINE_STATE_DTR<br />

Set this to signal Data Terminal Ready.<br />

T<strong>USB</strong>_CLS_CDC_SET_CONTROL_LINE_STATE_RTS<br />

Set this to signal Request To Send.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

The function sends the class request<br />

T<strong>USB</strong>_CLS_CDC_REQ_SET_CONTROL_LINE_STATE to the device. When the device<br />

fails the operation the function returns an error. The application may decide to ignore the error<br />

and avoid the sending of this request.<br />

This function is blocking.<br />

See Also<br />

HCLS_ACM_Open (page 173)<br />

HCLS_ACM_SendBreak (page 183)<br />

HCLS_ACM_SetLineCoding (page 181)<br />

182 <strong>USB</strong> Bus Driver Reference Manual


HCLS_ACM_SendBreak<br />

This function sends a Break signal to the device.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_ACM_SendBreak(<br />

HCLS_ACM_Handle handle,<br />

T_UINT16 breakSignal<br />

);<br />

Parameters<br />

handle<br />

The handle returned by HCLS_ACM_Open.<br />

11 CDC/ACM Class Driver Reference<br />

breakSignal<br />

A parameter between 1 and 0xfffe describes the duration of the break signal in milliseconds.<br />

A value of 0xffff turns the break signal on. A value of 0 turns the break signal off.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

The function sends the class request T<strong>USB</strong>_CLS_CDC_REQ_SEND_BREAK to the device.<br />

When the device fails the operation the function returns an error. The application may decide<br />

to ignore the error and avoid the sending of this request.<br />

This function is blocking.<br />

See Also<br />

HCLS_ACM_Open (page 173)<br />

HCLS_ACM_SetControlLineState (page 182)<br />

HCLS_ACM_SetLineCoding (page 181)<br />

<strong>USB</strong> Bus Driver Reference Manual 183


11 CDC/ACM Class Driver Reference<br />

HCLS_ACM_GetWriteFifoSize<br />

This function returns the FIFO size in bytes of the write endpoint.<br />

Definition<br />

T_UINT16<br />

HCLS_ACM_GetWriteFifoSize(<br />

HCLS_ACM_Handle handle<br />

);<br />

Parameter<br />

handle<br />

The handle returned by HCLS_ACM_Open.<br />

Return Value<br />

The write FIFO size of the bulk OUT endpoint.<br />

Comments<br />

The returned value can be used to calculate whether a zero length packet must be sent.<br />

The function is non blocking.<br />

See Also<br />

HCLS_ACM_Open (page 173)<br />

HCLS_ACM_Read (page 190)<br />

184 <strong>USB</strong> Bus Driver Reference Manual


HCLS_ACM_Write<br />

This function submits an URB with a transfer buffer to the stack.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_ACM_Write(<br />

HCLS_ACM_Handle handle,<br />

URB* urb<br />

);<br />

Parameters<br />

handle<br />

The handle returned by HCLS_ACM_Open.<br />

11 CDC/ACM Class Driver Reference<br />

urb<br />

A pointer to a caller provided and initialized URB structure. The caller provides the header<br />

and the URB_BULK_INT_REQUEST information. The class driver adds the endpoint to the<br />

request.<br />

Return Value<br />

The function returns <strong>USB</strong>H_STATUS_PENDING on success or an appropriate error code<br />

otherwise.<br />

Comments<br />

The submitted URB and the related data transfer buffer is passed to the driver stack with this<br />

function call. When the function returns the status <strong>USB</strong>H_STATUS_PENDING the URB is<br />

queued for processing in the stack. The caller must neither free the buffer or the URB nor<br />

access it as long as the ownership is at the stack. It has to wait until the callback function<br />

provided in the URB header is called. The write operation can be delayed for an infinite time<br />

by the device. The application can abort the operation with HCLS_ACM_AbortWrite.<br />

After this function is called the application has to wait until the completion routine is called.<br />

The buffer memory that is passed in URB.Request.BulkIntRequest.Buffer must be<br />

DMA memory. For more information about this memory please see section 5.3 at page 29.<br />

If the device expects a short packet termination of data chunks, the caller must take care on<br />

this. When the size of the data chunk can be divided by the FIFO size without rest the caller<br />

has to send a zero length packet.<br />

The function is non blocking. It can be called in the context of the completion routine of the<br />

URB. But the caller should check the status value of the returned request. When the request<br />

fails the caller should not re-submit the URB to the stack to avoid endless loops.<br />

<strong>USB</strong> Bus Driver Reference Manual 185


11 CDC/ACM Class Driver Reference<br />

See Also<br />

HCLS_ACM_Open (page 173)<br />

HCLS_ACM_GetWriteFifoSize (page 184)<br />

URB (page 108)<br />

HCLS_ACM_AbortWrite (page 187)<br />

TAL_AllocateDmaMemory (page 135)<br />

186 <strong>USB</strong> Bus Driver Reference Manual


HCLS_ACM_AbortWrite<br />

The function aborts all write requests on the specified interface.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_ACM_AbortWrite(<br />

HCLS_ACM_Handle handle<br />

);<br />

Parameter<br />

handle<br />

The handle returned by HCLS_ACM_Open.<br />

Return Value<br />

11 CDC/ACM Class Driver Reference<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

The function starts the abort process for all pending write requests. Typically the abort process<br />

is delayed. The caller has to wait until the completion routine for all pending URBs is called.<br />

The stack sets the status in the canceled URBs to <strong>USB</strong>H_STATUS_CANCELED.<br />

After a write operation has been canceled it cannot be determined how many data has been<br />

transferred to the device. Furthermore the data toggle mechanism to the device may be out of<br />

order. For that reason the caller should used the function HCLS_ACM_ResetWritePipe to<br />

clear all error conditions before the next write operation is started.<br />

This function is blocking.<br />

See Also<br />

HCLS_ACM_Open (page 173)<br />

HCLS_ACM_Write (page 185)<br />

HCLS_ACM_ResetWritePipe (page 188)<br />

<strong>USB</strong> Bus Driver Reference Manual 187


11 CDC/ACM Class Driver Reference<br />

HCLS_ACM_ResetWritePipe<br />

The functions resets the write pipe.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_ACM_ResetWritePipe(<br />

HCLS_ACM_Handle handle<br />

);<br />

Parameter<br />

handle<br />

The handle returned by HCLS_ACM_Open.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

This function resets the write endpoint. It sends a Clear Feature Endpoint Halt request for the<br />

write endpoint to the device. It resets the data toggle bits and clears any other error state in the<br />

driver stack and in possibly connected external hubs.<br />

When the function is called no pending requests on this endpoint are allowed.<br />

The function is blocking.<br />

See Also<br />

HCLS_ACM_Open (page 173)<br />

HCLS_ACM_Write (page 185)<br />

HCLS_ACM_AbortWrite (page 187)<br />

188 <strong>USB</strong> Bus Driver Reference Manual


HCLS_ACM_GetReadFifoSize<br />

This function returns the FIFO size in bytes of the read endpoint.<br />

Definition<br />

T_UINT16<br />

HCLS_ACM_GetReadFifoSize(<br />

HCLS_ACM_Handle handle<br />

);<br />

Parameter<br />

handle<br />

The handle returned by HCLS_ACM_Open.<br />

Return Value<br />

The read FIFO size of the bulk IN endpoint.<br />

Comments<br />

11 CDC/ACM Class Driver Reference<br />

The returned value can be used to calculate a valid buffer size for the read operation.<br />

The function is non blocking.<br />

See Also<br />

HCLS_ACM_Open (page 173)<br />

HCLS_ACM_Read (page 190)<br />

<strong>USB</strong> Bus Driver Reference Manual 189


11 CDC/ACM Class Driver Reference<br />

HCLS_ACM_Read<br />

This function submits an URB with a transfer buffer to the stack.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_ACM_Read(<br />

HCLS_ACM_Handle handle,<br />

URB* urb<br />

);<br />

Parameters<br />

handle<br />

The handle returned by HCLS_ACM_Open.<br />

urb<br />

A pointer to a caller provided and initialized URB structure. The caller provides the header<br />

and the URB_BULK_INT_REQUEST information. The class driver adds the endpoint to the<br />

request.<br />

Return Value<br />

The function returns <strong>USB</strong>H_STATUS_PENDING on success or an appropriate error code<br />

otherwise.<br />

Comments<br />

The submitted URB and the related data transfer buffer is passed to the driver stack with this<br />

function call. When the function returns the status <strong>USB</strong>H_STATUS_PENDING the URB is<br />

queued for processing in the stack. The caller must neither free the buffer or the URB nor<br />

access it as long as the ownership is at the stack. It has to wait until the callback function<br />

provided in the URB header is called.<br />

When the first read buffer is submitted to the stack the driver starts to send IN tokens to the<br />

bulk IN endpoint of the CDC/ACM interface. When no buffer for this endpoint is pending the<br />

driver does not send IN tokens to it. The buffer size should be a multiple of the FIFO size.<br />

This avoids buffer overrun errors. The device should terminate each data chunk with a short<br />

packet. When the device is not able to terminate each data chunk with a short packet the<br />

application should use buffers with the FIFO size of the bulk IN endpoint. But note: We<br />

recommend to use larger buffer to archive a good performance.<br />

The application can call HCLS_ACM_AbortRead to abort all pending buffers. After this<br />

function is called the application has to wait until the completion routine of the aborted buffers<br />

is called.<br />

The buffer memory that is passed in URB.Request.BulkIntRequest.Buffer must be<br />

DMA memory. For more information about this memory please see section 5.3 at page 29.<br />

190 <strong>USB</strong> Bus Driver Reference Manual


11 CDC/ACM Class Driver Reference<br />

The function is non blocking. It can be called in the context of the completion routine of the<br />

URB. But the caller should check the status value of the returned request. When the request<br />

fails the caller should not re-submit the URB to the stack to avoid endless loops.<br />

See Also<br />

HCLS_ACM_Open (page 173)<br />

HCLS_ACM_GetReadFifoSize (page 189)<br />

URB (page 108)<br />

HCLS_ACM_AbortRead (page 192)<br />

TAL_AllocateDmaMemory (page 135)<br />

<strong>USB</strong> Bus Driver Reference Manual 191


11 CDC/ACM Class Driver Reference<br />

HCLS_ACM_AbortRead<br />

The function aborts all read requests on the specified interface.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_ACM_AbortRead(<br />

HCLS_ACM_Handle handle<br />

);<br />

Parameter<br />

handle<br />

The handle returned by HCLS_ACM_Open.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

The function starts the abort process for all pending read requests. Typically the abort process<br />

is delayed. The caller has to wait until the completion routine for all pending URBs is called.<br />

The stack sets the status in the canceled URBs to <strong>USB</strong>H_STATUS_CANCELED.<br />

After a read operation has been canceled it cannot be determined how many data has been<br />

transferred from the device. Furthermore the data toggle mechanism to the device may be out<br />

of order. For that reason the caller should used the function HCLS_ACM_ResetReadPipe<br />

to clear all error conditions before the next read operation is started.<br />

This function is blocking.<br />

See Also<br />

HCLS_ACM_Open (page 173)<br />

HCLS_ACM_Read (page 190)<br />

HCLS_ACM_ResetReadPipe (page 193)<br />

192 <strong>USB</strong> Bus Driver Reference Manual


HCLS_ACM_ResetReadPipe<br />

The functions resets the read pipe.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_ACM_ResetReadPipe(<br />

HCLS_ACM_Handle handle<br />

);<br />

Parameter<br />

handle<br />

The handle returned by HCLS_ACM_Open.<br />

Return Value<br />

11 CDC/ACM Class Driver Reference<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

This function resets the read endpoint. It sends a Clear Feature Endpoint Halt request for the<br />

read endpoint to the device. It resets the data toggle bits and clears any other error state in the<br />

driver stack and in possibly connected external hubs.<br />

When the function is called no pending requests on this endpoint are allowed.<br />

The function is blocking.<br />

See Also<br />

HCLS_ACM_Open (page 173)<br />

HCLS_ACM_Read (page 190)<br />

HCLS_ACM_AbortRead (page 192)<br />

<strong>USB</strong> Bus Driver Reference Manual 193


11 CDC/ACM Class Driver Reference<br />

11.2 Structures<br />

HCLS_ACM_LineCoding<br />

This structure describes the line coding of the serial port.<br />

Definition<br />

typedef struct tagHCLS_ACM_LineCoding{<br />

T_UINT32 dwDTERate;<br />

T_UINT8 bCharFormat;<br />

T_UINT8 bParityType;<br />

T_UINT8 bDataBits;<br />

} HCLS_ACM_LineCoding;<br />

Members<br />

dwDTERate<br />

Data terminal rate in bits per second.<br />

bCharFormat<br />

The format of the characters. It means the number of stop bits.<br />

T<strong>USB</strong>_CLS_CDC_SET_LINE_CODING_STOP_1<br />

One stop bit.<br />

T<strong>USB</strong>_CLS_CDC_SET_LINE_CODING_STOP_1_5<br />

One and a half stop bit.<br />

T<strong>USB</strong>_CLS_CDC_SET_LINE_CODING_STOP_2<br />

Two stop bits.<br />

bParityType<br />

The parity of the transfer.<br />

T<strong>USB</strong>_CLS_CDC_SET_LINE_CODING_PARITY_NONE<br />

Use no parity.<br />

T<strong>USB</strong>_CLS_CDC_SET_LINE_CODING_PARITY_ODD<br />

Use odd parity.<br />

T<strong>USB</strong>_CLS_CDC_SET_LINE_CODING_PARITY_EVEN<br />

Use even parity.<br />

T<strong>USB</strong>_CLS_CDC_SET_LINE_CODING_PARITY_MARK<br />

Use mark parity.<br />

T<strong>USB</strong>_CLS_CDC_SET_LINE_CODING_PARITY_SPACE<br />

Use space parity.<br />

bDataBits<br />

This parameter describes the number of data bits on the physical interface and can be 5,6,7,8,<br />

or 16.<br />

194 <strong>USB</strong> Bus Driver Reference Manual


Comments<br />

11 CDC/ACM Class Driver Reference<br />

The data structure is used to set the line coding on the physical serial interface. The function<br />

HCLS_ACM_SetLineCoding is used to set the parameter.<br />

See Also<br />

HCLS_ACM_SetLineCoding (page 181)<br />

<strong>USB</strong> Bus Driver Reference Manual 195


12 HID Class Driver Reference<br />

12 HID Class Driver Reference<br />

12.1 Application programming interface<br />

HCLS_HID_Init<br />

The function initializes this class.<br />

Definition<br />

T_BOOL<br />

HCLS_HID_Init();<br />

Return Value<br />

It returns T_TRUE on success or T_FALSE if some resources are not available.<br />

Comments<br />

The function must be called one time before any other API functions of this class driver can be<br />

called. When the class driver is no longer required HCLS_HID_Exit must be called. If<br />

HCLS_HID_Exit is not called the class driver has a memory leak.<br />

This function is non blocking.<br />

See Also<br />

HCLS_HID_Exit (page 197)<br />

196 <strong>USB</strong> Bus Driver Reference Manual


HCLS_HID_Exit<br />

The exit function de-registers PnP handler and frees the allocated resources.<br />

Definition<br />

void<br />

HCLS_HID_Exit();<br />

Comments<br />

12 HID Class Driver Reference<br />

This function should be called one time when the class is not longer required. After the<br />

function was called no callbacks are called from this class driver.<br />

This function is blocking.<br />

See Also<br />

HCLS_HID_Init (page 196)<br />

<strong>USB</strong> Bus Driver Reference Manual 197


12 HID Class Driver Reference<br />

HCLS_HID_DeviceConnected<br />

Prototype for a callback function that can be called when a device with a HID interface is<br />

connected to the <strong>USB</strong> host.<br />

Definition<br />

typedef<br />

void<br />

HCLS_HID_DeviceConnected(<br />

void* context,<br />

<strong>USB</strong>H_INTERFACE_ID interfaceID<br />

);<br />

Parameters<br />

context<br />

This is the unchanged context pointer that was passed to the function call<br />

HCLS_HID_RegisterConnectHandler. It can be used by the application.<br />

interfaceID<br />

The interface ID is an unique identifier for the interface. This identifier can be used to get<br />

more information about the interface. When the device with this interface is disconnected and<br />

reconnected the host stack assigned a different interface ID.<br />

Comments<br />

Do not call any blocking functions in this context. See also the comments in<br />

HCLS_HID_RegisterConnectHandler.<br />

See Also<br />

HCLS_HID_RegisterConnectHandler (page 199)<br />

198 <strong>USB</strong> Bus Driver Reference Manual


HCLS_HID_RegisterConnectHandler<br />

This function registers a callback function for device connect events.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_HID_RegisterConnectHandler(<br />

HCLS_HID_DeviceConnected* connectNotification,<br />

void* context<br />

);<br />

Parameters<br />

connectNotification<br />

The address of the callback function that should be called.<br />

12 HID Class Driver Reference<br />

context<br />

The context that is passed to the callback function. This can be any user defined pointer or<br />

NULL.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

This function allows event based notifications for connected class interfaces. When this<br />

function is called the stack calls the callback function immediately for all currently connected<br />

class compliant interfaces. An alternative method to be informed about new devices is the<br />

polling of the available devices with HCLS_HID_CreateInterfaceList.<br />

To unregister the callback call this function with connectNotification set to NULL.<br />

This function is non blocking.<br />

See Also<br />

HCLS_HID_CreateInterfaceList (page 200)<br />

HCLS_HID_DeviceConnected (page 198)<br />

<strong>USB</strong> Bus Driver Reference Manual 199


12 HID Class Driver Reference<br />

HCLS_HID_CreateInterfaceList<br />

Creates an internal list with interfaces that expose a HID compliant interface.<br />

Definition<br />

<strong>USB</strong>H_INTERFACE_LIST_HANDLE<br />

HCLS_HID_CreateInterfaceList(<br />

unsigned int* InterfaceCount<br />

);<br />

Parameter<br />

InterfaceCount<br />

This parameter returns the number of available interfaces.<br />

Return Value<br />

It returns a valid list handle on success or NULL if no resources are available.<br />

Comments<br />

The internal list contains a snap shot of the HID interfaces that were available at the calling<br />

time. The returned handle must be freed with HCLS_HID_DestroyInterfaceList.<br />

The devices in the list can be enumerated with HCLS_HID_GetInterfaceID. The<br />

relation of the index and the interface ID in a list is constant.<br />

This function is non blocking.<br />

See Also<br />

HCLS_HID_DestroyInterfaceList (page 201)<br />

HCLS_HID_GetInterfaceID (page 202)<br />

200 <strong>USB</strong> Bus Driver Reference Manual


HCLS_HID_DestroyInterfaceList<br />

The function frees the resources that are used for the internal interface list.<br />

Definition<br />

void<br />

HCLS_HID_DestroyInterfaceList(<br />

<strong>USB</strong>H_INTERFACE_LIST_HANDLE InterfaceListHandle<br />

);<br />

Parameter<br />

InterfaceListHandle<br />

A list handle that was returned by a successful call to the function<br />

HCLS_HID_CreateInterfaceList.<br />

Comments<br />

This function should be called when the list is not longer needed.<br />

This function is non blocking.<br />

See Also<br />

HCLS_HID_CreateInterfaceList (page 200)<br />

12 HID Class Driver Reference<br />

<strong>USB</strong> Bus Driver Reference Manual 201


12 HID Class Driver Reference<br />

HCLS_HID_GetInterfaceID<br />

This function can be used to get the unique interface ID in an interface list.<br />

Definition<br />

<strong>USB</strong>H_INTERFACE_ID<br />

HCLS_HID_GetInterfaceID(<br />

<strong>USB</strong>H_INTERFACE_LIST_HANDLE InterfaceListHandle,<br />

unsigned int Index<br />

);<br />

Parameters<br />

InterfaceListHandle<br />

A list handle that was returned by a successful call to the function<br />

HCLS_HID_CreateInterfaceList.<br />

Index<br />

Is a number between 0 and InterfaceCount-1. The InterfaceCount is returned by<br />

the function HCLS_HID_CreateInterfaceList.<br />

Return Value<br />

The function returns the unique interface ID that is stored at the position of index in the list.<br />

Comments<br />

The interface list has a constant relation between the index and interface IDs and it is a snap<br />

shoot of the available interface at the point of time when the list was created. When a device is<br />

disconnected and reconnected it gets new interface IDs. A list can contain interface IDs that<br />

are not longer available on the bus.<br />

This function is non blocking.<br />

See Also<br />

HCLS_HID_CreateInterfaceList (page 200)<br />

202 <strong>USB</strong> Bus Driver Reference Manual


HCLS_HID_GetInterfaceInfo<br />

The function returns additional information to a known interface ID.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_HID_GetInterfaceInfo(<br />

<strong>USB</strong>H_INTERFACE_ID InterfaceID,<br />

<strong>USB</strong>H_INTERFACE_INFO* InterfaceInfo<br />

);<br />

Parameters<br />

12 HID Class Driver Reference<br />

InterfaceID<br />

The unique interface ID specifies the interface for which additional information should be<br />

returned. The interface ID is returned either by HCLS_HID_GetInterfaceID or<br />

HCLS_HID_DeviceConnected.<br />

InterfaceInfo<br />

The caller provides the storage for this structure and retrieves information about the specified<br />

interface.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

The additional information can be used to identify the device more exactly e.g. with the PID<br />

or the serial number.<br />

This function is non blocking.<br />

See Also<br />

HCLS_HID_GetInterfaceID (page 202)<br />

HCLS_HID_DeviceConnected (page 198)<br />

<strong>USB</strong>H_INTERFACE_INFO (page 92)<br />

<strong>USB</strong> Bus Driver Reference Manual 203


12 HID Class Driver Reference<br />

HCLS_HID_DeviceRemoved<br />

Prototype for a callback that is called when a the device with the HID interface is removed.<br />

Definition<br />

typedef<br />

void<br />

HCLS_HID_DeviceRemoved(<br />

void* context<br />

);<br />

Parameter<br />

context<br />

The context for the function that was passed to the function call HCLS_HID_Open.<br />

Comments<br />

A callback of this function can be registered with HCLS_HID_Open to see when the<br />

corresponding opened interface is removed.<br />

Do not call other blocking functions in this context.<br />

See Also<br />

HCLS_HID_Open (page 205)<br />

204 <strong>USB</strong> Bus Driver Reference Manual


HCLS_HID_Open<br />

12 HID Class Driver Reference<br />

This function opens an interface exclusively and optionally registers a remove notification<br />

function.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_HID_Open(<br />

<strong>USB</strong>H_INTERFACE_ID InterfaceID,<br />

HCLS_HID_DeviceRemoved* removeNotification,<br />

void* context,<br />

HCLS_HID_Handle* handle<br />

);<br />

Parameters<br />

InterfaceID<br />

The unique interface ID specifies the interface which should be opened. The interface ID is<br />

returned either by HCLS_HID_GetInterfaceID or HCLS_HID_DeviceConnected.<br />

The device with this interface ID may be removed in the meantime. For that reason the open<br />

function can fail with <strong>USB</strong>H_STATUS_DEVICE_REMOVED.<br />

removeNotification<br />

This parameter is optional. The caller provides the address of a function prototype<br />

HCLS_HID_DeviceRemoved or NULL. When the caller provides this function pointer and<br />

the open function returns with success, the remove notification function is called when the<br />

device is removed. The function is de-registered and not longer called when the interface is<br />

closed.<br />

context<br />

A user provided context for the remove notification function HCLS_HID_DeviceRemoved<br />

or NULL.<br />

handle<br />

On success the function returns a handle to the interface that is used for the operational access.<br />

If opening of the specified interface fails the handle will be NULL which is an invalid handle<br />

value.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

When the remove notification function is not used the application can poll the presence of the<br />

device with HCLS_HID_IsDevicePresent. The returned handle must be closed with<br />

<strong>USB</strong> Bus Driver Reference Manual 205


12 HID Class Driver Reference<br />

HCLS_HID_Close when it is not longer required.<br />

This class does not implement an internal buffer circulation for the interrupt endpoint. To<br />

create IN tokens on the endpoint the application has to pass a buffer with the function<br />

HCLS_HID_ReadReport to the class.<br />

This function is blocking.<br />

See Also<br />

HCLS_HID_GetInterfaceID (page 202)<br />

HCLS_HID_DeviceConnected (page 198)<br />

HCLS_HID_DeviceRemoved (page 204)<br />

HCLS_HID_IsDevicePresent (page 208)<br />

HCLS_HID_Close (page 207)<br />

HCLS_HID_ReadReport (page 228)<br />

206 <strong>USB</strong> Bus Driver Reference Manual


HCLS_HID_Close<br />

The function closes an interface and releases the exclusive use.<br />

Definition<br />

void<br />

HCLS_HID_Close(<br />

HCLS_HID_Handle handle<br />

);<br />

Parameter<br />

handle<br />

The handle returned by HCLS_HID_Open.<br />

Comments<br />

12 HID Class Driver Reference<br />

The caller has to make sure that all URB buffers that has been passed with<br />

HCLS_HID_ReadReport and HCLS_HID_WriteReport has been returned before this<br />

function is called. The caller can use HCLS_HID_AbortRead and<br />

HCLS_HID_AbortWrite to archive this.<br />

This function is blocking.<br />

See Also<br />

HCLS_HID_Open (page 205)<br />

HCLS_HID_ReadReport (page 228)<br />

HCLS_HID_WriteReport (page 224)<br />

HCLS_HID_AbortRead (page 230)<br />

HCLS_HID_AbortWrite (page 226)<br />

<strong>USB</strong> Bus Driver Reference Manual 207


12 HID Class Driver Reference<br />

HCLS_HID_IsDevicePresent<br />

The function indicates if the device is present or not.<br />

Definition<br />

T_BOOL<br />

HCLS_HID_IsDevicePresent(<br />

HCLS_HID_Handle handle<br />

);<br />

Parameter<br />

handle<br />

The handle returned by HCLS_HID_Open.<br />

Return Value<br />

The function returns T_TRUE when the device is present or T_FALSE when the device is<br />

removed.<br />

Comments<br />

This function is non blocking.<br />

See Also<br />

HCLS_HID_Open (page 205)<br />

208 <strong>USB</strong> Bus Driver Reference Manual


HCLS_HID_GetHidDescriptor<br />

Retrieves the variable sized HID descriptor of the specified interface.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_HID_GetHidDescriptor(<br />

HCLS_HID_Handle handle,<br />

void* buffer,<br />

T_UINT8 size,<br />

T_UINT8* bytesReturned<br />

);<br />

Parameters<br />

handle<br />

The handle returned by HCLS_HID_Open.<br />

12 HID Class Driver Reference<br />

buffer<br />

Pointer to a caller provided buffer that receives the HID descriptor. The caller provides the<br />

storage of the buffer. The argument must not be NULL.<br />

size<br />

The size in bytes of the buffer given with buffer.<br />

bytesReturned<br />

Caller provided variable that receives the number of bytes that were written to the buffer.<br />

The caller provides the storage of the variable. The argument must not be NULL.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

The function is non blocking.<br />

See Also<br />

HCLS_HID_Open (page 205)<br />

<strong>USB</strong> Bus Driver Reference Manual 209


12 HID Class Driver Reference<br />

HCLS_HID_GetNumDescriptors<br />

Returns the number of report and physical descriptors for the specified interface.<br />

Definition<br />

T_UINT8<br />

HCLS_HID_GetNumDescriptors(<br />

HCLS_HID_Handle handle<br />

);<br />

Parameter<br />

handle<br />

The handle returned by HCLS_HID_Open.<br />

Return Value<br />

The number of report and physical descriptors of the interface.<br />

Comments<br />

Since a HID device must have at least 1 report descriptor the returned number is equal or<br />

greater to 1. The returned value is extracted from the HID descriptor.<br />

The function is non blocking.<br />

See Also<br />

HCLS_HID_Open (page 205)<br />

210 <strong>USB</strong> Bus Driver Reference Manual


HCLS_HID_GetReportDescriptorSize<br />

Returns the size in bytes of the report descriptor identified with the given index.<br />

Definition<br />

T_UINT16<br />

HCLS_HID_GetReportDescriptorSize(<br />

HCLS_HID_Handle handle,<br />

T_UINT8 index<br />

);<br />

Parameters<br />

handle<br />

The handle returned by HCLS_HID_Open.<br />

12 HID Class Driver Reference<br />

index<br />

A zero based index that identifies the report descriptor. The index ranges from 0 to<br />

number of the descriptors-1. Call HCLS_HID_GetNumDescriptors to get<br />

the number of the descriptors.<br />

Return Value<br />

The size in bytes of the report descriptor identified by index.<br />

Comments<br />

The function is non blocking.<br />

See Also<br />

HCLS_HID_Open (page 205)<br />

HCLS_HID_GetNumDescriptors (page 210)<br />

<strong>USB</strong> Bus Driver Reference Manual 211


12 HID Class Driver Reference<br />

HCLS_HID_GetReportDescriptor<br />

The function issues a request to retrieve the specified report descriptor and waits until the request<br />

is completed.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_HID_GetReportDescriptor(<br />

HCLS_HID_Handle handle,<br />

T_UINT8 index,<br />

void* buffer,<br />

T_UINT16 size,<br />

T_UINT16* bytesReturned<br />

);<br />

Parameters<br />

handle<br />

The handle returned by HCLS_HID_Open.<br />

index<br />

A zero based index that identifies the report descriptor. The index ranges from 0 to<br />

number of the descriptors-1. Call HCLS_HID_GetNumDescriptors to get<br />

the number of the descriptors.<br />

buffer<br />

Pointer to a caller provided buffer that receives the report descriptor. The caller provides the<br />

storage of the buffer. The argument must not be NULL.<br />

size<br />

The size in bytes of the buffer given with buffer.<br />

bytesReturned<br />

Caller provided variable that receives the number of bytes that were written to the buffer.<br />

The caller provides the storage of the variable. The argument must not be NULL.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

The function is blocking.<br />

212 <strong>USB</strong> Bus Driver Reference Manual


See Also<br />

HCLS_HID_Open (page 205)<br />

HCLS_HID_GetNumDescriptors (page 210)<br />

12 HID Class Driver Reference<br />

<strong>USB</strong> Bus Driver Reference Manual 213


12 HID Class Driver Reference<br />

HCLS_HID_GetReportRequest<br />

This function sends a Get_Report request to the specified interface and waits until the request is<br />

completed.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_HID_GetReportRequest(<br />

HCLS_HID_Handle handle,<br />

T_UINT8 type,<br />

T_UINT8 reportID,<br />

void* buffer,<br />

T_UINT16 size,<br />

T_UINT16* bytesReturned<br />

);<br />

Parameters<br />

handle<br />

The handle returned by HCLS_HID_Open.<br />

type<br />

The type of the report to get. This must be one of the following:<br />

T<strong>USB</strong>_CLS_HID_REPORT_TYPE_INPUT<br />

Get an Input report.<br />

T<strong>USB</strong>_CLS_HID_REPORT_TYPE_OUTPUT<br />

Get an Output report.<br />

T<strong>USB</strong>_CLS_HID_REPORT_TYPE_FEATURE<br />

Get a Feature report.<br />

reportID<br />

The ID of the report to get.<br />

buffer<br />

Pointer to a caller provided buffer that receives the requested report. The caller provides the<br />

storage of the buffer. The argument must not be NULL.<br />

size<br />

The size in bytes of the buffer given with buffer.<br />

bytesReturned<br />

Caller provided variable that receives the number of bytes that were written to the buffer.<br />

The caller provides the storage of the variable. The argument must not be NULL.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

214 <strong>USB</strong> Bus Driver Reference Manual


Comments<br />

12 HID Class Driver Reference<br />

This function can be used to request Input and Feature reports over the control pipe (endpoint<br />

0). It should not be used to poll for Input reports. Use HCLS_HID_ReadReport to poll for<br />

Input reports.<br />

When the device returns a report ID in the data of the report it is part of the returned data.<br />

The function is blocking.<br />

See Also<br />

HCLS_HID_Open (page 205)<br />

HCLS_HID_ReadReport (page 228)<br />

<strong>USB</strong> Bus Driver Reference Manual 215


12 HID Class Driver Reference<br />

HCLS_HID_SetReportRequest<br />

This function sends a Set_Report request to the specified interface and waits until the request is<br />

completed.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_HID_SetReportRequest(<br />

HCLS_HID_Handle handle,<br />

T_UINT8 type,<br />

T_UINT8 reportID,<br />

void* buffer,<br />

T_UINT16 size<br />

);<br />

Parameters<br />

handle<br />

The handle returned by HCLS_HID_Open.<br />

type<br />

The type of the report to set. This must be one of the following:<br />

T<strong>USB</strong>_CLS_HID_REPORT_TYPE_INPUT<br />

Set an Input report.<br />

T<strong>USB</strong>_CLS_HID_REPORT_TYPE_OUTPUT<br />

Set an Output report.<br />

T<strong>USB</strong>_CLS_HID_REPORT_TYPE_FEATURE<br />

Set a Feature report.<br />

reportID<br />

The ID of the report to set.<br />

buffer<br />

Caller provided buffer that contains the report to set. The caller provides the storage and the<br />

content of the buffer. The argument must not be NULL.<br />

size<br />

The size in bytes of the buffer given with buffer.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

216 <strong>USB</strong> Bus Driver Reference Manual


Comments<br />

12 HID Class Driver Reference<br />

This function can be used tzo send Feature or Output reports over the control pipe (endpoint<br />

0). To send Output reports with low lateny over an interrupt OUT pipe use<br />

HCLS_HID_WriteReport.<br />

You have to add the report ID to the buffer if this is required.<br />

The function is blocking.<br />

See Also<br />

HCLS_HID_Open (page 205)<br />

<strong>USB</strong> Bus Driver Reference Manual 217


12 HID Class Driver Reference<br />

HCLS_HID_GetProtocolRequest<br />

This function sends a Get_Protocol request that receives the currently active protocol of the<br />

specified HID interface. The function waits until the request is completed.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_HID_GetProtocolRequest(<br />

HCLS_HID_Handle handle,<br />

T_UINT8* protocol<br />

);<br />

Parameters<br />

handle<br />

The handle returned by HCLS_HID_Open.<br />

protocol<br />

Caller provided variable that receives the currently active protocol. This can be one of the<br />

following:<br />

T<strong>USB</strong>_CLS_HID_BOOT_PROTOCOL<br />

The boot protocol is active.<br />

T<strong>USB</strong>_CLS_HID_REPORT_PROTOCOL<br />

The report protocol is active.<br />

The caller provides the storage of the variable. The argument must not be NULL.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

The function is blocking.<br />

See Also<br />

HCLS_HID_Open (page 205)<br />

218 <strong>USB</strong> Bus Driver Reference Manual


HCLS_HID_SetProtocolRequest<br />

12 HID Class Driver Reference<br />

This function sends a Set_Protocol request that sets the active protocol for the specified HID<br />

interface. The function waits until the request is completed.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_HID_SetProtocolRequest(<br />

HCLS_HID_Handle handle,<br />

T_UINT8 protocol<br />

);<br />

Parameters<br />

handle<br />

The handle returned by HCLS_HID_Open.<br />

protocol<br />

A value that indicates the protocol that should be activated. This can be one of the following:<br />

T<strong>USB</strong>_CLS_HID_BOOT_PROTOCOL<br />

Activate the boot protocol.<br />

T<strong>USB</strong>_CLS_HID_REPORT_PROTOCOL<br />

Activate the report protocol.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

The function is blocking.<br />

See Also<br />

HCLS_HID_Open (page 205)<br />

<strong>USB</strong> Bus Driver Reference Manual 219


12 HID Class Driver Reference<br />

HCLS_HID_GetIdleRequest<br />

This functions sends a Get_Idle request to the specified interface and waits until the request is<br />

completed.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_HID_GetIdleRequest(<br />

HCLS_HID_Handle handle,<br />

T_UINT8 reportID,<br />

T_UINT8* idleTime<br />

);<br />

Parameters<br />

handle<br />

The handle returned by HCLS_HID_Open.<br />

reportID<br />

The ID of the report for which to get the idle rate.<br />

idleTime<br />

Caller provided variable that receives the idle time for the specified report. The idle rate is<br />

provided with a 4 milliseconds resolution, i.e. a value of 1 means an idle rate 0 4 milliseconds.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

The function can be used to read the current idle rate for a particular Input report.<br />

The function is blocking.<br />

See Also<br />

HCLS_HID_Open (page 205)<br />

220 <strong>USB</strong> Bus Driver Reference Manual


HCLS_HID_SetIdleRequest<br />

12 HID Class Driver Reference<br />

This functions sends a Set_Idle request to the specified interface and waits until the request is<br />

completed.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_HID_SetIdleRequest(<br />

HCLS_HID_Handle handle,<br />

T_UINT8 reportID,<br />

T_UINT8 idleTime<br />

);<br />

Parameters<br />

handle<br />

The handle returned by HCLS_HID_Open.<br />

reportID<br />

The ID of the report for which to set the idle rate. Set this to zero if you want to set the idle<br />

rate for all reports that are send by the interface.<br />

idleTime<br />

The idle rate to set in a resolution of 4 milliseconds. I.e. a value of 1 specifies an idle rate of 4<br />

milliseconds.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

This function can be used to set the idle rate for either all or a particular report that is sent by<br />

the interrupt IN endpoint. This is usefull to limit the reporting frequency of the interrupt IN<br />

endpoit of the interface.<br />

The function is blocking.<br />

See Also<br />

HCLS_HID_Open (page 205)<br />

<strong>USB</strong> Bus Driver Reference Manual 221


12 HID Class Driver Reference<br />

HCLS_HID_GetWriteFifoSize<br />

This function returns the FIFO size in bytes of the write endpoint.<br />

Definition<br />

T_UINT16<br />

HCLS_HID_GetWriteFifoSize(<br />

HCLS_HID_Handle handle<br />

);<br />

Parameter<br />

handle<br />

The handle returned by HCLS_HID_Open.<br />

Return Value<br />

The FIFO size in bytes of the interrupt OUT endpoint. If the interface does not have an<br />

interrupt OUT endpoint the function returns 0.<br />

Comments<br />

The returned value can be used to calculate whether a zero length packet must be sent.<br />

This function is non blocking.<br />

See Also<br />

HCLS_HID_Open (page 205)<br />

222 <strong>USB</strong> Bus Driver Reference Manual


HCLS_HID_GetReadFifoSize<br />

This function returns the FIFO size in bytes of the read endpoint.<br />

Definition<br />

T_UINT16<br />

HCLS_HID_GetReadFifoSize(<br />

HCLS_HID_Handle handle<br />

);<br />

Parameter<br />

handle<br />

The handle returned by HCLS_HID_Open.<br />

Return Value<br />

The FIFO size in bytes of the interrupt IN endpoint.<br />

Comments<br />

12 HID Class Driver Reference<br />

The returned value can be used to calculate a valid buffer size for the read operation.<br />

This function is non blocking.<br />

See Also<br />

HCLS_HID_Open (page 205)<br />

<strong>USB</strong> Bus Driver Reference Manual 223


12 HID Class Driver Reference<br />

HCLS_HID_WriteReport<br />

This function asynchronously sends a report to the interrupt OUT endpoint of the specified<br />

interface.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_HID_WriteReport(<br />

HCLS_HID_Handle handle,<br />

URB* urb,<br />

T_UINT8 reportID<br />

);<br />

Parameters<br />

handle<br />

The handle returned by HCLS_HID_Open.<br />

urb<br />

A pointer to a caller provided and initialized URB structure. The caller provides the header<br />

and the URB_BULK_INT_REQUEST information. The class driver adds the endpoint to the<br />

request.<br />

reportID<br />

The ID of the report that should be written. This argument is only be used if the report is sent<br />

over the control pipe (endpoint 0). If the report is sent over the interrupt OUT pipe this<br />

argument is ignored.<br />

Return Value<br />

The function returns <strong>USB</strong>H_STATUS_PENDING on success or an appropriate error code<br />

otherwise.<br />

Comments<br />

If the interface have an interrupt OUT endpoint the report is sent on this endpoint. Otherwise<br />

the report is sent as a setup request on endpoint 0. Anyhow the URB must be filled in as<br />

URB_BULK_INT_REQUEST.<br />

The submitted URB and the related data transfer buffer is passed to the driver stack with this<br />

function call. When the function returns the status <strong>USB</strong>H_STATUS_PENDING the URB is<br />

queued for processing in the stack. The caller must neither free the buffer or the URB nor<br />

access it as long as the ownership is at the stack. It has to wait until the callback function<br />

provided in the URB header is called. The write operation can be delayed for an infinite time<br />

by the device. The application can abort the operation with HCLS_HID_AbortWrite.<br />

After this function is called the application has to wait until the completion routine is called.<br />

224 <strong>USB</strong> Bus Driver Reference Manual


12 HID Class Driver Reference<br />

If the interrupt OUT pipe is used to sent the report the buffer memory that is passed in<br />

URB.Request.BulkIntRequest.Buffer must be DMA memory. For more<br />

information about this memory please see section 5.3 at page 29.<br />

If the device expects a short packet termination of data chunks, the caller must take care on<br />

this. When the size of the data chunk can be divided by the FIFO size without rest the caller<br />

has to send a zero length packet.<br />

The function is non blocking. It can be called in the context of the completion routine of the<br />

URB. But the caller should check the status value of the returned request. When the request<br />

fails the caller should not re-submit the URB to the stack to avoid endless loops.<br />

See Also<br />

HCLS_HID_Open (page 205)<br />

HCLS_HID_GetWriteFifoSize (page 222)<br />

URB (page 108)<br />

HCLS_HID_AbortWrite (page 226)<br />

TAL_AllocateDmaMemory (page 135)<br />

<strong>USB</strong> Bus Driver Reference Manual 225


12 HID Class Driver Reference<br />

HCLS_HID_AbortWrite<br />

The function aborts all write requests on the specified interface.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_HID_AbortWrite(<br />

HCLS_HID_Handle handle<br />

);<br />

Parameter<br />

handle<br />

The handle returned by HCLS_HID_Open.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

The function starts the abort process for all pending write requests. Typically the abort process<br />

is delayed. The caller has to wait until the completion routine for all pending URBs is called.<br />

The stack sets the status in the canceled URBs to <strong>USB</strong>H_STATUS_CANCELED.<br />

After a write operation has been canceled it cannot be determined how many data has been<br />

transferred to the device. Furthermore the data toggle mechanism to the device may be out of<br />

order. For that reason the caller should used the function HCLS_HID_ResetWritePipe to<br />

clear all error conditions before the next write operation is started.<br />

The function is blocking.<br />

See Also<br />

HCLS_HID_Open (page 205)<br />

HCLS_HID_WriteReport (page 224)<br />

HCLS_HID_ResetWritePipe (page 227)<br />

226 <strong>USB</strong> Bus Driver Reference Manual


HCLS_HID_ResetWritePipe<br />

The functions resets the write pipe.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_HID_ResetWritePipe(<br />

HCLS_HID_Handle handle<br />

);<br />

Parameter<br />

handle<br />

The handle returned by HCLS_HID_Open.<br />

Return Value<br />

12 HID Class Driver Reference<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

This function resets the write endpoint. It sends a Clear Feature Endpoint Halt request for the<br />

write endpoint to the device. It resets the data toggle bits and clears any other error state in the<br />

driver stack and in possibly connected external hubs.<br />

When the function is called no pending requests on this endpoint are allowed.<br />

The function is blocking.<br />

See Also<br />

HCLS_HID_Open (page 205)<br />

HCLS_HID_WriteReport (page 224)<br />

HCLS_HID_AbortWrite (page 226)<br />

<strong>USB</strong> Bus Driver Reference Manual 227


12 HID Class Driver Reference<br />

HCLS_HID_ReadReport<br />

This function asynchronously reads a report from the interrupt IN endpoint of the specified<br />

interface.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_HID_ReadReport(<br />

HCLS_HID_Handle handle,<br />

URB* urb<br />

);<br />

Parameters<br />

handle<br />

The handle returned by HCLS_HID_Open.<br />

urb<br />

A pointer to a caller provided and initialized URB structure. The caller provides the header<br />

and the URB_BULK_INT_REQUEST information. The class driver adds the endpoint to the<br />

request.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_PENDING in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

The submitted URB and the related data transfer buffer is passed to the driver stack with this<br />

function call. When the function returns the status <strong>USB</strong>H_STATUS_PENDING the URB is<br />

queued for processing in the stack. The caller must neither free the buffer or the URB nor<br />

access it as long as the ownership is at the stack. It has to wait until the callback function<br />

provided in the URB header is called.<br />

When the first read buffer is submitted to the stack the driver starts to send IN tokens to the<br />

interrupt IN endpoint of the HID interface. When no buffer for this endpoint is pending the<br />

driver does not send IN tokens to it. I.e. to allow the device to send data at least one buffer<br />

must be pending. The buffer size should be a multiple of the FIFO size. This avoids buffer<br />

overrun errors. The device should terminate each data chunk with a short packet. When the<br />

device is not able to terminate each data chunk with a short packet the application should use<br />

buffers with the FIFO size of the interrupt IN endpoint. But note: We recommend to use larger<br />

buffer to archive a good performance.<br />

The application can call HCLS_HID_AbortRead to abort all pending buffers. After this<br />

function is called the application has to wait until the completion routine of the aborted buffers<br />

is called.<br />

228 <strong>USB</strong> Bus Driver Reference Manual


12 HID Class Driver Reference<br />

The buffer memory that is passed in URB.Request.BulkIntRequest.Buffer must be<br />

DMA memory. For more information about this memory please see section 5.3 at page 29.<br />

The function is non blocking. It can be called in the context of the completion routine of the<br />

URB. But the caller should check the status value of the returned request. When the request<br />

fails the caller should not re-submit the URB to the stack to avoid endless loops.<br />

See Also<br />

HCLS_HID_Open (page 205)<br />

HCLS_HID_GetReadFifoSize (page 223)<br />

URB (page 108)<br />

HCLS_HID_AbortRead (page 230)<br />

TAL_AllocateDmaMemory (page 135)<br />

<strong>USB</strong> Bus Driver Reference Manual 229


12 HID Class Driver Reference<br />

HCLS_HID_AbortRead<br />

The function aborts all read requests on the specified interface.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_HID_AbortRead(<br />

HCLS_HID_Handle handle<br />

);<br />

Parameter<br />

handle<br />

The handle returned by HCLS_HID_Open.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

The function starts the abort process for all pending read requests. Typically the abort process<br />

is delayed. The caller has to wait until the completion routine for all pending URBs is called.<br />

The stack sets the status in the canceled URBs to <strong>USB</strong>H_STATUS_CANCELED.<br />

After a read operation has been canceled it cannot be determined how many data has been<br />

transferred from the device. Furthermore the data toggle mechanism to the device may be out<br />

of order. For that reason the caller should used the function HCLS_HID_ResetReadPipe<br />

to clear all error conditions before the next read operation is started.<br />

This function is blocking.<br />

See Also<br />

HCLS_HID_Open (page 205)<br />

HCLS_HID_ReadReport (page 228)<br />

HCLS_HID_ResetReadPipe (page 231)<br />

230 <strong>USB</strong> Bus Driver Reference Manual


HCLS_HID_ResetReadPipe<br />

The functions resets the read pipe.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_HID_ResetReadPipe(<br />

HCLS_HID_Handle handle<br />

);<br />

Parameter<br />

handle<br />

The handle returned by HCLS_HID_Open.<br />

Return Value<br />

12 HID Class Driver Reference<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

This function resets the read endpoint. It sends a Clear Feature Endpoint Halt request for the<br />

read endpoint to the device. It resets the data toggle bits and clears any other error state in the<br />

driver stack and in possibly connected external hubs.<br />

When the function is called no pending requests on this endpoint are allowed.<br />

The function is blocking.<br />

See Also<br />

HCLS_HID_Open (page 205)<br />

HCLS_HID_ReadReport (page 228)<br />

HCLS_HID_AbortRead (page 230)<br />

<strong>USB</strong> Bus Driver Reference Manual 231


13 Printer Class Driver Reference<br />

13 Printer Class Driver Reference<br />

13.1 Application programming interface<br />

HCLS_PRN_Init<br />

The function initializes this class.<br />

Definition<br />

T_BOOL<br />

HCLS_PRN_Init();<br />

Return Value<br />

It returns T_TRUE on success or T_FALSE if some resources are not available.<br />

Comments<br />

The function must be called one time before any other API functions of this class driver can be<br />

called. When the class driver is no longer required HCLS_PRN_Exit must be called. If<br />

HCLS_PRN_Exit is not called the class driver has a memory leak.<br />

This function is non blocking.<br />

See Also<br />

HCLS_PRN_Exit (page 233)<br />

232 <strong>USB</strong> Bus Driver Reference Manual


HCLS_PRN_Exit<br />

The exit function de-registers PnP handler and frees the allocated resources.<br />

Definition<br />

void<br />

HCLS_PRN_Exit();<br />

Comments<br />

13 Printer Class Driver Reference<br />

This function should be called one time when the class is not longer required. After the<br />

function was called no callbacks are called from this class driver.<br />

This function is blocking.<br />

See Also<br />

HCLS_PRN_Init (page 232)<br />

<strong>USB</strong> Bus Driver Reference Manual 233


13 Printer Class Driver Reference<br />

HCLS_PRN_PrinterConnected<br />

Prototype for a callback function that can be called when a device with a printer interface is<br />

connected to the <strong>USB</strong> host.<br />

Definition<br />

typedef<br />

void<br />

HCLS_PRN_PrinterConnected(<br />

void* context,<br />

<strong>USB</strong>H_INTERFACE_ID interfaceID<br />

);<br />

Parameters<br />

context<br />

This is the unchanged context pointer that was passed to the function call<br />

HCLS_PRN_RegisterConnectHandler. It can be used by the application.<br />

interfaceID<br />

The interface ID is an unique identifier for the interface. This identifier can be used to get<br />

more information about the interface. When the device with this interface is disconnected and<br />

reconnected the host stack assigned a different interface ID.<br />

Comments<br />

Do not call any blocking functions in this context. See also the comments in<br />

HCLS_PRN_RegisterConnectHandler.<br />

See Also<br />

HCLS_PRN_RegisterConnectHandler (page 235)<br />

234 <strong>USB</strong> Bus Driver Reference Manual


HCLS_PRN_RegisterConnectHandler<br />

This function registers a callback function for device connect events.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_PRN_RegisterConnectHandler(<br />

HCLS_PRN_PrinterConnected* connectNotification,<br />

void* context<br />

);<br />

Parameters<br />

connectNotification<br />

The address of the callback function that should be called.<br />

13 Printer Class Driver Reference<br />

context<br />

The context that is passed to the callback function. This can be any user defined pointer or<br />

NULL.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

This function allows event based notifications for connected class interfaces. When this<br />

function is called the stack calls the callback function immediately for all currently connected<br />

class compliant interfaces. An alternative method to be informed about new devices is the<br />

polling of the available devices with HCLS_PRN_CreateInterfaceList.<br />

To unregister the callback call this function with connectNotification set to NULL.<br />

This function is non blocking.<br />

See Also<br />

HCLS_PRN_CreateInterfaceList (page 236)<br />

HCLS_PRN_PrinterConnected (page 234)<br />

<strong>USB</strong> Bus Driver Reference Manual 235


13 Printer Class Driver Reference<br />

HCLS_PRN_CreateInterfaceList<br />

Creates an internal list with interfaces that expose a printer compliant interface.<br />

Definition<br />

<strong>USB</strong>H_INTERFACE_LIST_HANDLE<br />

HCLS_PRN_CreateInterfaceList(<br />

unsigned int* InterfaceCount<br />

);<br />

Parameter<br />

InterfaceCount<br />

This parameter returns the number of available interface.<br />

Return Value<br />

It returns a valid list handle on success or NULL if no resources are available.<br />

Comments<br />

The internal list contains a snap shot of the printer interfaces that were available at the calling<br />

time. The returned handle must be freed with HCLS_PRN_DestroyInterfaceList.<br />

The devices in the list can be enumerated with HCLS_PRN_GetInterfaceID. The<br />

relation of the index and the interface ID in a list is constant.<br />

This function is non blocking.<br />

See Also<br />

HCLS_PRN_DestroyInterfaceList (page 237)<br />

HCLS_PRN_GetInterfaceID (page 238)<br />

236 <strong>USB</strong> Bus Driver Reference Manual


HCLS_PRN_DestroyInterfaceList<br />

The function frees the resources that are used for the internal interface list.<br />

Definition<br />

void<br />

HCLS_PRN_DestroyInterfaceList(<br />

<strong>USB</strong>H_INTERFACE_LIST_HANDLE InterfaceListHandle<br />

);<br />

Parameter<br />

InterfaceListHandle<br />

A list handle that was returned by a successful call to the function<br />

HCLS_PRN_CreateInterfaceList.<br />

Comments<br />

This function should be called when the list is not longer needed.<br />

This function is non blocking.<br />

See Also<br />

HCLS_PRN_CreateInterfaceList (page 236)<br />

13 Printer Class Driver Reference<br />

<strong>USB</strong> Bus Driver Reference Manual 237


13 Printer Class Driver Reference<br />

HCLS_PRN_GetInterfaceID<br />

This function can be used to get the unique interface ID in an interface list.<br />

Definition<br />

<strong>USB</strong>H_INTERFACE_ID<br />

HCLS_PRN_GetInterfaceID(<br />

<strong>USB</strong>H_INTERFACE_LIST_HANDLE InterfaceListHandle,<br />

unsigned int Index<br />

);<br />

Parameters<br />

InterfaceListHandle<br />

A list handle that was returned by a successful call to the function<br />

HCLS_PRN_CreateInterfaceList.<br />

Index<br />

Is a number between 0 and InterfaceCount-1. The InterfaceCount is returned by<br />

the function HCLS_PRN_CreateInterfaceList.<br />

Return Value<br />

The function returns the unique interface ID that is stored at the position of index in the list.<br />

Comments<br />

The interface list has a constant relation between the index and interface IDs and it is a snap<br />

shoot of the available interface at the point of time when the list was created. When a device is<br />

disconnected and reconnected it gets new interface IDs. A list can contain interface IDs that<br />

are not longer available on the bus.<br />

This function is non blocking.<br />

See Also<br />

HCLS_PRN_CreateInterfaceList (page 236)<br />

238 <strong>USB</strong> Bus Driver Reference Manual


HCLS_PRN_GetInterfaceInfo<br />

The function returns additional information to a known interface ID.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_PRN_GetInterfaceInfo(<br />

<strong>USB</strong>H_INTERFACE_ID InterfaceID,<br />

<strong>USB</strong>H_INTERFACE_INFO* InterfaceInfo<br />

);<br />

Parameters<br />

13 Printer Class Driver Reference<br />

InterfaceID<br />

The unique interface ID specifies the interface for which additional information should be<br />

returned. The interface ID is returned either by HCLS_PRN_GetInterfaceID or<br />

HCLS_PRN_PrinterConnected.<br />

InterfaceInfo<br />

The caller provides the storage for this structure and retrieves information about the specified<br />

interface.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

The additional information can be used to identify the device more exactly e.g. with the PID<br />

or the serial number.<br />

This function is non blocking.<br />

See Also<br />

HCLS_PRN_GetInterfaceID (page 238)<br />

HCLS_PRN_PrinterConnected (page 234)<br />

<strong>USB</strong>H_INTERFACE_INFO (page 92)<br />

<strong>USB</strong> Bus Driver Reference Manual 239


13 Printer Class Driver Reference<br />

HCLS_PRN_PrinterRemove<br />

Prototype for a callback that is called when a the device with the printer interface is removed.<br />

Definition<br />

typedef<br />

void<br />

HCLS_PRN_PrinterRemove(<br />

void* context<br />

);<br />

Parameter<br />

context<br />

The context for the function that was passed to the function call HCLS_PRN_Open.<br />

Comments<br />

A callback of this function can be registered with HCLS_PRN_Open to see when the<br />

corresponding opened interface is removed.<br />

Do not call other blocking functions in this context.<br />

See Also<br />

HCLS_PRN_Open (page 241)<br />

240 <strong>USB</strong> Bus Driver Reference Manual


HCLS_PRN_Open<br />

13 Printer Class Driver Reference<br />

This function opens an interface exclusively and optionally registers a remove notification<br />

function.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_PRN_Open(<br />

<strong>USB</strong>H_INTERFACE_ID InterfaceID,<br />

HCLS_PRN_PrinterRemove* removeNotification,<br />

void* context,<br />

HCLS_PRN_Handle* handle<br />

);<br />

Parameters<br />

InterfaceID<br />

The unique interface ID specifies the interface which should be opened. The interface ID is<br />

returned either by HCLS_PRN_GetInterfaceID or HCLS_PRN_PrinterConnected.<br />

The device with this interface ID may be removed in the meantime. For that reason the open<br />

function can fail with <strong>USB</strong>H_STATUS_DEVICE_REMOVED.<br />

removeNotification<br />

This parameter is optional. The caller provides the address of a function prototype<br />

HCLS_PRN_PrinterRemove or NULL. When the caller provides this function pointer and<br />

the open function returns with success, the remove notification function is called when the<br />

device is removed. The function is de-registered and not longer called when the interface is<br />

closed.<br />

context<br />

A user provided context for the remove notification function HCLS_PRN_PrinterRemove<br />

or NULL.<br />

handle<br />

On success the function returns a handle to the interface that is used for the operational access.<br />

If opening of the specified interface fails the handle will be NULL which is an invalid handle<br />

value.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

When the remove notification function is not used the application can poll the presence of the<br />

device with HCLS_PRN_IsPrinterPresent. The returned handle must be closed with<br />

<strong>USB</strong> Bus Driver Reference Manual 241


13 Printer Class Driver Reference<br />

HCLS_PRN_Close when it is not longer required.<br />

This function is blocking.<br />

See Also<br />

HCLS_PRN_GetInterfaceID (page 238)<br />

HCLS_PRN_PrinterConnected (page 234)<br />

HCLS_PRN_PrinterRemove (page 240)<br />

HCLS_PRN_IsPrinterPresent (page 244)<br />

HCLS_PRN_Close (page 243)<br />

242 <strong>USB</strong> Bus Driver Reference Manual


HCLS_PRN_Close<br />

The function closes an interface and releases the exclusive use.<br />

Definition<br />

void<br />

HCLS_PRN_Close(<br />

HCLS_PRN_Handle handle<br />

);<br />

Parameter<br />

handle<br />

The handle returned by HCLS_PRN_Open.<br />

Comments<br />

13 Printer Class Driver Reference<br />

The caller has to make sure that all URB buffers that has been passed with HCLS_PRN_Read<br />

and HCLS_PRN_Write has been returned before this function is called. The caller can use<br />

HCLS_PRN_AbortRead and HCLS_PRN_AbortWrite to archive this.<br />

This function is blocking.<br />

See Also<br />

HCLS_PRN_Open (page 241)<br />

HCLS_PRN_Read (page 257)<br />

HCLS_PRN_Write (page 251)<br />

HCLS_PRN_AbortRead (page 261)<br />

HCLS_PRN_AbortWrite (page 255)<br />

<strong>USB</strong> Bus Driver Reference Manual 243


13 Printer Class Driver Reference<br />

HCLS_PRN_IsPrinterPresent<br />

The function indicates if the printer is present or not.<br />

Definition<br />

T_BOOL<br />

HCLS_PRN_IsPrinterPresent(<br />

HCLS_PRN_Handle Handle<br />

);<br />

Parameter<br />

Handle<br />

The handle returned by HCLS_PRN_Open.<br />

Return Value<br />

The function returns T_TRUE when the printer is present or T_FALSE when the printer is<br />

removed.<br />

Comments<br />

This function is non blocking.<br />

See Also<br />

HCLS_PRN_Open (page 241)<br />

244 <strong>USB</strong> Bus Driver Reference Manual


HCLS_PRN_GetAvailableInterfaces<br />

13 Printer Class Driver Reference<br />

This function returns an or’ed combination of the possible interfaces that the printer implements.<br />

Definition<br />

T_UINT8<br />

HCLS_PRN_GetAvailableInterfaces(<br />

HCLS_PRN_Handle handle<br />

);<br />

Parameter<br />

handle<br />

The handle returned by HCLS_PRN_Open.<br />

Return Value<br />

The function returns an or’ed combination of the following flags:<br />

CLS_PRINTER_INTERFACE_UNIDIRECTIONAL<br />

The printer implements a uni-directional interface.<br />

CLS_PRINTER_INTERFACE_BIDIRECTIONAL<br />

The printer implements a bi-directional interface.<br />

CLS_PRINTER_INTERFACE_1284_BIDIRECTIONAL<br />

The printer implements a IEEE 1284 compatible bi-directional interface.<br />

Comments<br />

The function is non blocking.<br />

See Also<br />

HCLS_PRN_Open (page 241)<br />

<strong>USB</strong> Bus Driver Reference Manual 245


13 Printer Class Driver Reference<br />

HCLS_PRN_GetCurrentInterface<br />

This function returns the currently selected interface of the specified printer.<br />

Definition<br />

T_UINT8<br />

HCLS_PRN_GetCurrentInterface(<br />

HCLS_PRN_Handle handle<br />

);<br />

Parameter<br />

handle<br />

The handle returned by HCLS_PRN_Open.<br />

Return Value<br />

The function returns the currently selected interface of the specified printer. The return value<br />

can be one of the following:<br />

CLS_PRINTER_INTERFACE_UNIDIRECTIONAL<br />

The uni-directional interface is currently selected.<br />

CLS_PRINTER_INTERFACE_BIDIRECTIONAL<br />

The bi-directional interface is currently selected.<br />

CLS_PRINTER_INTERFACE_1284_BIDIRECTIONAL<br />

The IEEE 1284 compatible bi-directional interface is currently selected.<br />

Comments<br />

The returned interface is the first selected interface after the printer was enumerated.<br />

The function is non blocking.<br />

See Also<br />

HCLS_PRN_Open (page 241)<br />

246 <strong>USB</strong> Bus Driver Reference Manual


HCLS_PRN_SetInterface<br />

13 Printer Class Driver Reference<br />

This function issues a request to set the specified printer interface and waits until the request is<br />

completed.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_PRN_SetInterface(<br />

HCLS_PRN_Handle handle,<br />

T_UINT8 printerInterface<br />

);<br />

Parameters<br />

handle<br />

The handle returned by HCLS_PRN_Open.<br />

printerInterface<br />

The printer interface that should be set. This can be one of the following:<br />

CLS_PRINTER_INTERFACE_UNIDIRECTIONAL<br />

Set the uni-directional interface.<br />

CLS_PRINTER_INTERFACE_BIDIRECTIONAL<br />

Set the bi-directional interface.<br />

CLS_PRINTER_INTERFACE_1284_BIDIRECTIONAL<br />

Set the IEEE 1284 compatible bi-directional interface.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

This function can be used to select a printer interface. It should be called before the<br />

communication with the printer starts.<br />

The function is blocking.<br />

See Also<br />

HCLS_PRN_Open (page 241)<br />

<strong>USB</strong> Bus Driver Reference Manual 247


13 Printer Class Driver Reference<br />

HCLS_PRN_GetDeviceId<br />

This function issues a request to receive the device ID string and waits until the request is<br />

completed.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_PRN_GetDeviceId(<br />

HCLS_PRN_Handle handle,<br />

T_UINT8* buffer,<br />

T_UINT16 bufferSize,<br />

T_UINT16* bytesReturned<br />

);<br />

Parameters<br />

handle<br />

The handle returned by HCLS_PRN_Open.<br />

buffer<br />

Pointer to a caller provided buffer that receives the device ID string. The caller provides the<br />

storage of the buffer. The argument must not be NULL.<br />

bufferSize<br />

The size in bytes of the buffer given with buffer.<br />

bytesReturned<br />

Caller provided variable that receives the number of bytes that were written to the buffer.<br />

The caller provides the storage of the variable. The argument must not be NULL.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

The requested device ID string is read from the device. When the given buffer is smaller as<br />

the device ID string only the first part of the device ID string is transferred.<br />

The function does not process or test the device ID string in anyway. Therefor the caller<br />

should consists that the string may is inconsistent.<br />

The function is blocking.<br />

See Also<br />

HCLS_PRN_Open (page 241)<br />

248 <strong>USB</strong> Bus Driver Reference Manual


HCLS_PRN_GetPortStatus<br />

13 Printer Class Driver Reference<br />

This function issues a request to receive the current port status from the specified printer and<br />

waits until the request is completed.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_PRN_GetPortStatus(<br />

HCLS_PRN_Handle handle,<br />

T_UINT8* portStatus<br />

);<br />

Parameters<br />

handle<br />

The handle returned by HCLS_PRN_Open.<br />

portStatus<br />

Caller provided variable that receives the current port status. The caller provides the storage of<br />

the variable. The argument must not be NULL.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

The received port status is an or’ed combination of the following flags:<br />

T<strong>USB</strong>_CLS_PRINTER_STATUS_NOT_ERROR<br />

A value of 1 indicates that the printer has no error, 0 means the printer has an error.<br />

T<strong>USB</strong>_CLS_PRINTER_STATUS_SELECT<br />

A value of 1 inidcates that the printer is selected, 0 means not selected.<br />

T<strong>USB</strong>_CLS_PRINTER_STATUS_PAPER_EMPTY<br />

A value of 1 indicates that teh printer is out of paper, 0 means the paper is not empty.<br />

Refer to the <strong>USB</strong> Device Class Definition for Printing Devices for further information about<br />

the port status.<br />

The function is blocking.<br />

See Also<br />

HCLS_PRN_Open (page 241)<br />

<strong>USB</strong> Bus Driver Reference Manual 249


13 Printer Class Driver Reference<br />

HCLS_PRN_SoftReset<br />

This function issue a request that performs a soft reset on the specified printer and waits until the<br />

request is completed.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_PRN_SoftReset(<br />

HCLS_PRN_Handle handle,<br />

T_BOOL recipientInterface<br />

);<br />

Parameters<br />

handle<br />

The handle returned by HCLS_PRN_Open.<br />

recipientInterface<br />

If this argument is set to T_TRUE the recipient of the request is set to interface so the request<br />

is compliant to version 1.1 of the <strong>USB</strong> Device Class Definition for Printing Devices. If it is set<br />

to T_FALSE the recipient is set to other which is compliant to version 1.0 of the <strong>USB</strong> Device<br />

Class Definition for Printing Devices.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

The function is blocking.<br />

See Also<br />

HCLS_PRN_Open (page 241)<br />

250 <strong>USB</strong> Bus Driver Reference Manual


HCLS_PRN_Write<br />

This function submits an URB with a transfer buffer to the stack.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_PRN_Write(<br />

HCLS_PRN_Handle handle,<br />

URB* urb<br />

);<br />

Parameters<br />

handle<br />

The handle returned by HCLS_PRN_Open.<br />

13 Printer Class Driver Reference<br />

urb<br />

A pointer to a caller provided and initialized URB structure. The caller provides the header<br />

and the URB_BULK_INT_REQUEST information. The class driver adds the endpoint to the<br />

request.<br />

Return Value<br />

The function returns <strong>USB</strong>H_STATUS_PENDING on success or an appropriate error code<br />

otherwise.<br />

Comments<br />

The submitted URB and the related data transfer buffer is passed to the driver stack with this<br />

function call. When the function returns the status <strong>USB</strong>H_STATUS_PENDING the URB is<br />

queued for processing in the stack. The caller must neither free the buffer or the URB nor<br />

access it as long as the ownership is at the stack. It has to wait until the callback function<br />

provided in the URB header is called. The write operation can be delayed for an infinite time<br />

by the device. The application can abort the operation with HCLS_PRN_AbortWrite.<br />

After this function is called the application has to wait until the completion routine is called.<br />

This function is supported on each interface that is supported by the printer.<br />

The buffer memory that is passed in URB.Request.BulkIntRequest.Buffer must be<br />

DMA memory. For more information about this memory please see section 5.3 at page 29.<br />

If the device expects a short packet termination of data chunks, the caller must take care on<br />

this. When the size of the data chunk can be divided by the FIFO size without rest the caller<br />

has to send a zero length packet.<br />

The function is non blocking. It can be called in the context of the completion routine of the<br />

URB. But the caller should check the status value of the returned request. When the request<br />

fails the caller should not re-submit the URB to the stack to avoid endless loops.<br />

<strong>USB</strong> Bus Driver Reference Manual 251


13 Printer Class Driver Reference<br />

See Also<br />

HCLS_PRN_Open (page 241)<br />

URB (page 108)<br />

HCLS_PRN_AbortWrite (page 255)<br />

TAL_AllocateDmaMemory (page 135)<br />

252 <strong>USB</strong> Bus Driver Reference Manual


HCLS_PRN_WriteSync<br />

13 Printer Class Driver Reference<br />

This function performs a synchronous write request to send the given data to the specified printer<br />

interface.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_PRN_WriteSync(<br />

HCLS_PRN_Handle handle,<br />

void* buffer,<br />

T_UINT32 size,<br />

T_UINT32 timeout<br />

);<br />

Parameters<br />

handle<br />

The handle returned by HCLS_PRN_Open.<br />

buffer<br />

Pointer to a caller provided buffer that contains the data. The caller provides the storage of the<br />

buffer. The argument must not be NULL.<br />

size<br />

The size in bytes of the buffer given with buffer.<br />

timeout<br />

The timeout for the write request in milliseconds. Specify TAL_WAIT_INFINITE to wait<br />

infinite for the completion of the write request.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise. When the timeout value given with timeout is expired before the write<br />

request is completed the function fails with <strong>USB</strong>H_STATUS_TIMEOUT.<br />

Comments<br />

This function issue a write operation with the given data and waits until the operation is<br />

completed or the given timeout interval elapse, i.e. it behaves in a synchronous manner.<br />

When the function returns with an error it can not be determined how much data has been<br />

transferred.<br />

The function is blocking.<br />

<strong>USB</strong> Bus Driver Reference Manual 253


13 Printer Class Driver Reference<br />

See Also<br />

HCLS_PRN_Open (page 241)<br />

254 <strong>USB</strong> Bus Driver Reference Manual


HCLS_PRN_AbortWrite<br />

The function aborts all write requests on the specified interface.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_PRN_AbortWrite(<br />

HCLS_PRN_Handle handle<br />

);<br />

Parameter<br />

handle<br />

The handle returned by HCLS_ACM_Open.<br />

Return Value<br />

13 Printer Class Driver Reference<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

The function starts the abort process for all pending write requests. Typically the abort process<br />

is delayed. The caller has to wait until the completion routine for all pending URBs is called.<br />

The stack sets the status in the canceled URBs to <strong>USB</strong>H_STATUS_CANCELED.<br />

After a write operation has been canceled it cannot be determined how many data has been<br />

transferred to the device. Furthermore the data toggle mechanism to the device may be out of<br />

order. For that reason the caller should used the function HCLS_PRN_ResetWritePipe to<br />

clear all error conditions before the next write operation is started.<br />

This function is blocking.<br />

See Also<br />

HCLS_ACM_Open (page 173)<br />

HCLS_PRN_Write (page 251)<br />

HCLS_PRN_ResetWritePipe (page 256)<br />

<strong>USB</strong> Bus Driver Reference Manual 255


13 Printer Class Driver Reference<br />

HCLS_PRN_ResetWritePipe<br />

The functions resets the write pipe.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_PRN_ResetWritePipe(<br />

HCLS_PRN_Handle handle<br />

);<br />

Parameter<br />

handle<br />

The handle returned by HCLS_ACM_Open.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

This function resets the write endpoint. It sends a Clear Feature Endpoint Halt request for the<br />

write endpoint to the device. It resets the data toggle bits and clears any other error state in the<br />

driver stack and in possibly connected external hubs.<br />

When the function is called no pending requests on this endpoint are allowed.<br />

The function is blocking.<br />

See Also<br />

HCLS_ACM_Open (page 173)<br />

HCLS_PRN_Write (page 251)<br />

HCLS_PRN_AbortWrite (page 255)<br />

256 <strong>USB</strong> Bus Driver Reference Manual


HCLS_PRN_Read<br />

This function submits an URB with a transfer buffer to the stack.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_PRN_Read(<br />

HCLS_PRN_Handle handle,<br />

URB* urb<br />

);<br />

Parameters<br />

handle<br />

The handle returned by HCLS_PRN_Open.<br />

13 Printer Class Driver Reference<br />

urb<br />

A pointer to a caller provided and initialized URB structure. The caller provides the header<br />

and the URB_BULK_INT_REQUEST information. The class driver adds the endpoint to the<br />

request.<br />

Return Value<br />

The function returns <strong>USB</strong>H_STATUS_PENDING on success or an appropriate error code<br />

otherwise.<br />

Comments<br />

The submitted URB and the related data transfer buffer is passed to the driver stack with this<br />

function call. When the function returns the status <strong>USB</strong>H_STATUS_PENDING the URB is<br />

queued for processing in the stack. The caller must neither free the buffer or the URB nor<br />

access it as long as the ownership is at the stack. It has to wait until the callback function<br />

provided in the URB header is called.<br />

This function is not supported on unidirectional interfaces of the printer.<br />

When the first read buffer is submitted to the stack the driver starts to send IN tokens to the<br />

bulk IN endpoint of the printer interface. When no buffer for this endpoint is pending the<br />

driver does not send IN tokens to it. The buffer size should be a multiple of the FIFO size.<br />

This avoids buffer overrun errors. The device should terminate each data chunk with a short<br />

packet. When the device is not able to terminate each data chunk with a short packet the<br />

application should use buffers with the FIFO size of the bulk IN endpoint. But note: We<br />

recommend to use larger buffer to archive a good performance.<br />

The application can call HCLS_PRN_AbortRead to abort all pending buffers. After this<br />

function is called the application has to wait until the completion routine of the aborted buffers<br />

is called.<br />

<strong>USB</strong> Bus Driver Reference Manual 257


13 Printer Class Driver Reference<br />

The buffer memory that is passed in URB.Request.BulkIntRequest.Buffer must be<br />

DMA memory. See section 5.3 for further information about DMA memory.<br />

The function is non blocking. It can be called in the context of the completion routine of the<br />

URB. But the caller should check the status value of the returned request. When the request<br />

fails the caller should not re-submit the URB to the stack to avoid endless loops.<br />

See Also<br />

HCLS_PRN_Open (page 241)<br />

URB (page 108)<br />

HCLS_PRN_AbortRead (page 261)<br />

TAL_AllocateDmaMemory (page 135)<br />

258 <strong>USB</strong> Bus Driver Reference Manual


HCLS_PRN_ReadSync<br />

13 Printer Class Driver Reference<br />

This function performs a synchronous read request to read data from the specified printer<br />

interface.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_PRN_ReadSync(<br />

HCLS_PRN_Handle handle,<br />

void* buffer,<br />

T_UINT32 size,<br />

T_UINT32* transferred,<br />

T_UINT32 timeout<br />

);<br />

Parameters<br />

handle<br />

The handle returned by HCLS_PRN_Open.<br />

buffer<br />

Pointer to a caller provided buffer that receives the data read from the printer interface. The<br />

caller provides the storage of the buffer. The argument must not be NULL.<br />

size<br />

The size in bytes of the buffer given with buffer.<br />

transferred<br />

Caller provided variable that receives the number of bytes that were written to the buffer.<br />

The caller provides the storage of the variable. The argument must not be NULL.<br />

timeout<br />

The timeout for the read request in milliseconds. Specify TAL_WAIT_INFINITE to wait<br />

infinite for the completion of the read request.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise. When the timeout value given with timeout is expired before the write<br />

request is completed the function fails with <strong>USB</strong>H_STATUS_TIMEOUT.<br />

Comments<br />

This function issue a read operation and waits until the operation is completed or the given<br />

timeout interval elapse, i.e. it behaves in a synchronous manner.<br />

The function HCLS_PRN_AbortRead can be used to abort pending read operations.<br />

The function is blocking.<br />

<strong>USB</strong> Bus Driver Reference Manual 259


13 Printer Class Driver Reference<br />

See Also<br />

HCLS_PRN_Open (page 241)<br />

HCLS_PRN_AbortRead (page 261)<br />

260 <strong>USB</strong> Bus Driver Reference Manual


HCLS_PRN_AbortRead<br />

The function aborts all read requests on the specified interface.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_PRN_AbortRead(<br />

HCLS_PRN_Handle handle<br />

);<br />

Parameter<br />

handle<br />

The handle returned by HCLS_PRN_Open.<br />

Return Value<br />

13 Printer Class Driver Reference<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

The function starts the abort process for all pending read requests. Typically the abort process<br />

is delayed. The caller has to wait until the completion routine for all pending URBs is called.<br />

The stack sets the status in the canceled URBs to <strong>USB</strong>H_STATUS_CANCELED.<br />

After a read operation has been canceled it cannot be determined how many data has been<br />

transferred from the device. Furthermore the data toggle mechanism to the device may be out<br />

of order. For that reason the caller should used the function HCLS_PRN_ResetReadPipe<br />

to clear all error conditions before the next read operation is started.<br />

This function is blocking.<br />

See Also<br />

HCLS_PRN_Open (page 241)<br />

HCLS_PRN_Read (page 257)<br />

HCLS_PRN_ResetReadPipe (page 262)<br />

<strong>USB</strong> Bus Driver Reference Manual 261


13 Printer Class Driver Reference<br />

HCLS_PRN_ResetReadPipe<br />

The functions resets the read pipe.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_PRN_ResetReadPipe(<br />

HCLS_PRN_Handle handle<br />

);<br />

Parameter<br />

handle<br />

The handle returned by HCLS_PRN_Open.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

This function resets the read endpoint. It sends a Clear Feature Endpoint Halt request for the<br />

read endpoint to the device. It resets the data toggle bits and clears any other error state in the<br />

driver stack and in possibly connected external hubs.<br />

When the function is called no pending requests on this endpoint are allowed.<br />

The function is blocking.<br />

See Also<br />

HCLS_PRN_Open (page 241)<br />

HCLS_PRN_Read (page 257)<br />

HCLS_PRN_AbortRead (page 261)<br />

262 <strong>USB</strong> Bus Driver Reference Manual


14 Mass Storage Class Driver Reference<br />

14.1 Application programming interface<br />

HCLS_MS_Init<br />

The function initializes this class.<br />

Definition<br />

T_BOOL<br />

HCLS_MS_Init();<br />

Return Value<br />

14 Mass Storage Class Driver Reference<br />

It returns T_TRUE on success or T_FALSE if some resources are not available.<br />

Comments<br />

The function must be called one time before any other API functions of this class driver can be<br />

called. When the class driver is no longer required HCLS_MS_Exit must be called. If<br />

HCLS_MS_Exit is not called the class driver has a memory leak.<br />

This function is non blocking.<br />

See Also<br />

HCLS_MS_Exit (page 264)<br />

<strong>USB</strong> Bus Driver Reference Manual 263


14 Mass Storage Class Driver Reference<br />

HCLS_MS_Exit<br />

The exit function de-registers PnP handler and frees the allocated resources.<br />

Definition<br />

void<br />

HCLS_MS_Exit();<br />

Comments<br />

This function should be called one time when the class is not longer required. After the<br />

function was called no callbacks are called from this class driver.<br />

This function is blocking.<br />

See Also<br />

HCLS_MS_Init (page 263)<br />

264 <strong>USB</strong> Bus Driver Reference Manual


HCLS_MS_DeviceConnected<br />

14 Mass Storage Class Driver Reference<br />

Prototype for a callback function that can be called when a device with a mass storage interface is<br />

connected to the <strong>USB</strong> host.<br />

Definition<br />

typedef<br />

void<br />

HCLS_MS_DeviceConnected(<br />

void* context,<br />

<strong>USB</strong>H_INTERFACE_ID interfaceID<br />

);<br />

Parameters<br />

context<br />

This is the unchanged context pointer that was passed to the function call<br />

HCLS_MS_RegisterConnectHandler. It can be used by the application.<br />

interfaceID<br />

The interface ID is an unique identifier for the interface. This identifier can be used to get<br />

more information about the interface. When the device with this interface is disconnected and<br />

reconnected the host stack assigned a different interface ID.<br />

Comments<br />

Do not call any blocking functions in this context. See also the comments in<br />

HCLS_MS_RegisterConnectHandler.<br />

See Also<br />

HCLS_MS_RegisterConnectHandler (page 266)<br />

<strong>USB</strong> Bus Driver Reference Manual 265


14 Mass Storage Class Driver Reference<br />

HCLS_MS_RegisterConnectHandler<br />

This function registers a callback function for device connect events.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_MS_RegisterConnectHandler(<br />

HCLS_MS_DeviceConnected* connectNotification,<br />

void* context<br />

);<br />

Parameters<br />

connectNotification<br />

The address of the callback function that should be called.<br />

context<br />

The context that is passed to the callback function. This can be any user defined pointer or<br />

NULL.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

This function allows event based notifications for connected class interfaces. When this<br />

function is called the stack calls the callback function immediately for all currently connected<br />

class compliant interfaces. An alternative method to be informed about new devices is the<br />

polling of the available devices with HCLS_MS_CreateInterfaceList.<br />

To unregister the callback call this function with connectNotification set to NULL.<br />

This function is non blocking.<br />

See Also<br />

HCLS_MS_CreateInterfaceList (page 267)<br />

HCLS_MS_DeviceConnected (page 265)<br />

266 <strong>USB</strong> Bus Driver Reference Manual


HCLS_MS_CreateInterfaceList<br />

14 Mass Storage Class Driver Reference<br />

Creates an internal list with interfaces that expose a mass storage compliant interface.<br />

Definition<br />

<strong>USB</strong>H_INTERFACE_LIST_HANDLE<br />

HCLS_MS_CreateInterfaceList(<br />

unsigned int* InterfaceCount<br />

);<br />

Parameter<br />

InterfaceCount<br />

This parameter returns the number of available interfaces.<br />

Return Value<br />

It returns a valid list handle on success or NULL if no resources are available.<br />

Comments<br />

The internal list contains a snap shot of the mass storage interfaces that were available at the<br />

calling time. The returned handle must be freed with<br />

HCLS_MS_DestroyInterfaceList. The devices in the list can be enumerated with<br />

HCLS_MS_GetInterfaceID. The relation of the index and the interface ID in a list is<br />

constant.<br />

This function is non blocking.<br />

See Also<br />

HCLS_MS_DestroyInterfaceList (page 268)<br />

HCLS_MS_GetInterfaceID (page 270)<br />

<strong>USB</strong> Bus Driver Reference Manual 267


14 Mass Storage Class Driver Reference<br />

HCLS_MS_DestroyInterfaceList<br />

The function frees the resources that are used for the internal interface list.<br />

Definition<br />

void<br />

HCLS_MS_DestroyInterfaceList(<br />

<strong>USB</strong>H_INTERFACE_LIST_HANDLE InterfaceListHandle<br />

);<br />

Parameter<br />

InterfaceListHandle<br />

A list handle that was returned by a successful call to the function<br />

HCLS_MS_CreateInterfaceList.<br />

Comments<br />

This function should be called when the list is not longer needed.<br />

This function is non blocking.<br />

See Also<br />

HCLS_MS_CreateInterfaceList (page 267)<br />

268 <strong>USB</strong> Bus Driver Reference Manual


HCLS_MS_GetInterfaceInfo<br />

The function returns additional information to a known interface ID.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_MS_GetInterfaceInfo(<br />

<strong>USB</strong>H_INTERFACE_ID InterfaceID,<br />

<strong>USB</strong>H_INTERFACE_INFO* InterfaceInfo<br />

);<br />

Parameters<br />

14 Mass Storage Class Driver Reference<br />

InterfaceID<br />

The unique interface ID specifies the interface for which additional information should be<br />

returned. The interface ID is returned either by HCLS_MS_GetInterfaceID or<br />

HCLS_MS_DeviceConnected.<br />

InterfaceInfo<br />

The caller provides the storage for this structure and retrieves information about the specified<br />

interface.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

The additional information can be used to identify the device more exactly e.g. with the PID<br />

or the serial number.<br />

This function is non blocking.<br />

See Also<br />

HCLS_MS_GetInterfaceID (page 270)<br />

HCLS_MS_DeviceConnected (page 265)<br />

<strong>USB</strong>H_INTERFACE_INFO (page 92)<br />

<strong>USB</strong> Bus Driver Reference Manual 269


14 Mass Storage Class Driver Reference<br />

HCLS_MS_GetInterfaceID<br />

This function can be used to get the unique interface ID in an interface list.<br />

Definition<br />

<strong>USB</strong>H_INTERFACE_ID<br />

HCLS_MS_GetInterfaceID(<br />

<strong>USB</strong>H_INTERFACE_LIST_HANDLE InterfaceListHandle,<br />

unsigned int Index<br />

);<br />

Parameters<br />

InterfaceListHandle<br />

A list handle that was returned by a successful call to the function<br />

HCLS_MS_CreateInterfaceList.<br />

Index<br />

Is a number between 0 and InterfaceCount-1. The InterfaceCount is returned by<br />

the function HCLS_MS_CreateInterfaceList.<br />

Return Value<br />

The function returns the unique interface ID that is stored at the position of index in the list.<br />

Comments<br />

The interface list has a constant relation between the index and interface IDs and it is a snap<br />

shoot of the available interface at the point of time when the list was created. When a device is<br />

disconnected and reconnected it gets new interface IDs. A list can contain interface IDs that<br />

are not longer available on the bus.<br />

This function is non blocking.<br />

See Also<br />

HCLS_MS_CreateInterfaceList (page 267)<br />

270 <strong>USB</strong> Bus Driver Reference Manual


HCLS_MS_DeviceRemove<br />

14 Mass Storage Class Driver Reference<br />

Prototype for a callback that is called when a the device with the mass storage interface is<br />

removed.<br />

Definition<br />

typedef<br />

void<br />

HCLS_MS_DeviceRemove(<br />

void* context<br />

);<br />

Parameter<br />

context<br />

The context for the function that was passed to the function call HCLS_MS_Open.<br />

Comments<br />

A callback of this function can be registered with HCLS_MS_Open to see when the<br />

corresponding opened interface is removed.<br />

Do not call other blocking functions in this context.<br />

See Also<br />

HCLS_MS_Open (page 272)<br />

<strong>USB</strong> Bus Driver Reference Manual 271


14 Mass Storage Class Driver Reference<br />

HCLS_MS_Open<br />

This function opens an interface exclusively and optionally registers a remove notification<br />

function.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_MS_Open(<br />

<strong>USB</strong>H_INTERFACE_ID InterfaceID,<br />

HCLS_MS_DeviceRemove* removeNotification,<br />

void* context,<br />

HCLS_MS_Handle* msHandle<br />

);<br />

Parameters<br />

InterfaceID<br />

The unique interface ID specifies the interface which should be opened. The interface ID is<br />

returned either by HCLS_MS_GetInterfaceID or HCLS_MS_DeviceConnected. The<br />

device with this interface ID may be removed in the meantime. For that reason the open<br />

function can fail with <strong>USB</strong>H_STATUS_DEVICE_REMOVED.<br />

removeNotification<br />

This parameter is optional. The caller provides the address of a function prototype<br />

HCLS_MS_DeviceRemove or NULL. When the caller provides this function pointer and<br />

the open function returns with success, the remove notification function is called when the<br />

device is removed. The function is de-registered and not longer called when the interface is<br />

closed.<br />

context<br />

A user provided context for the remove notification function HCLS_MS_DeviceRemove or<br />

NULL.<br />

msHandle<br />

On success the function returns a handle to the interface that is used for the operational access.<br />

If opening of the specified interface fails the handle will be NULL which is an invalid handle<br />

value.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

The returned handle must be closed with HCLS_MS_Close when it is not longer required.<br />

This function is blocking.<br />

272 <strong>USB</strong> Bus Driver Reference Manual


See Also<br />

HCLS_MS_GetInterfaceID (page 270)<br />

HCLS_MS_DeviceConnected (page 265)<br />

HCLS_MS_DeviceRemove (page 271)<br />

HCLS_MS_Close (page 274)<br />

14 Mass Storage Class Driver Reference<br />

<strong>USB</strong> Bus Driver Reference Manual 273


14 Mass Storage Class Driver Reference<br />

HCLS_MS_Close<br />

The function closes an interface and releases the exclusive use.<br />

Definition<br />

void<br />

HCLS_MS_Close(<br />

HCLS_MS_Handle* handle<br />

);<br />

Parameter<br />

handle<br />

The handle returned by HCLS_MS_Open.<br />

Comments<br />

This function is blocking.<br />

See Also<br />

HCLS_MS_Open (page 272)<br />

274 <strong>USB</strong> Bus Driver Reference Manual


HCLS_MS_GetLuns<br />

14 Mass Storage Class Driver Reference<br />

This function returns the number of logical units (LUN) of a mass storage interface.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_MS_GetLuns(<br />

HCLS_MS_Handle msHandle,<br />

unsigned int* Luns<br />

);<br />

Parameters<br />

msHandle<br />

The handle returned by HCLS_MS_Open.<br />

Luns<br />

Returns the number of LUNs. HCLS_MS_OpenLun opens a LUN.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

This function is blocking.<br />

See Also<br />

HCLS_MS_Open (page 272)<br />

HCLS_MS_OpenLun (page 276)<br />

<strong>USB</strong> Bus Driver Reference Manual 275


14 Mass Storage Class Driver Reference<br />

HCLS_MS_OpenLun<br />

This function opens a LUN and returns a LUN handle.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_MS_OpenLun(<br />

HCLS_MS_Handle msHandle,<br />

unsigned int lun,<br />

HCLS_MS_LUN_HANDLE* unitHandle<br />

);<br />

Parameters<br />

msHandle<br />

The handle returned by HCLS_MS_Open.<br />

lun<br />

This is the zero based physical LUN number in the range from zero to Lun numbers - 1.<br />

The Lun number can be received due a call to HCLS_MS_GetLuns.<br />

unitHandle<br />

On success the function returns a handle to the LUN that is used for the operational access. If<br />

opening of the specified LUN fails the handle will be NULL which is an invalid handle value.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

The returned handle must be closed with HCLS_MS_CloseLun if it is no longer required.<br />

This function is blocking.<br />

See Also<br />

HCLS_MS_Open (page 272)<br />

HCLS_MS_CloseLun (page 277)<br />

HCLS_MS_ReadSectors (page 285)<br />

276 <strong>USB</strong> Bus Driver Reference Manual


HCLS_MS_CloseLun<br />

This function closes a previously opened interface.<br />

Definition<br />

void<br />

HCLS_MS_CloseLun(<br />

HCLS_MS_LUN_HANDLE Handle<br />

);<br />

Parameter<br />

Handle<br />

This parameter is the LUN handle returned by HCLS_MS_OpenLun.<br />

Comments<br />

14 Mass Storage Class Driver Reference<br />

Each handle must be closed one time. The parameter Handle must be a valid handle.<br />

The function is blocking.<br />

See Also<br />

HCLS_MS_OpenLun (page 276)<br />

<strong>USB</strong> Bus Driver Reference Manual 277


14 Mass Storage Class Driver Reference<br />

HCLS_MS_InitLun<br />

This function retrieves some informations from the unit.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_MS_InitLun(<br />

HCLS_MS_LUN_HANDLE Handle,<br />

T_UNIT_INFO* Info<br />

);<br />

Parameters<br />

Handle<br />

This parameter is the LUN handle returned by HCLS_MS_OpenLun.<br />

Info<br />

The caller provides the storage for this structure and receives some additional informations of<br />

the logical unit.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

If the function fails with an error the logical unit is not supported by the mass storage class<br />

driver and should be closed.<br />

The function is blocking.<br />

See Also<br />

HCLS_MS_OpenLun (page 276)<br />

HCLS_MS_CloseLun (page 277)<br />

278 <strong>USB</strong> Bus Driver Reference Manual


HCLS_MS_ReadCapacity<br />

This function reads the capacity of the medium.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_MS_ReadCapacity(<br />

HCLS_MS_LUN_HANDLE Handle,<br />

T_UINT32* totalSectors,<br />

T_UINT16* bytesPerSector<br />

);<br />

Parameters<br />

Handle<br />

This parameter is the LUN handle returned by HCLS_MS_OpenLun.<br />

totalSectors<br />

This parameter returns the total sector numbers.<br />

bytesPerSector<br />

This parameter returns the number of bytes per sector.<br />

Return Value<br />

14 Mass Storage Class Driver Reference<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

The function fails if the medium is not ready. Call HCLS_MS_IsMediumReady to see if the<br />

medium is ready.<br />

The function is blocking.<br />

See Also<br />

HCLS_MS_OpenLun (page 276)<br />

HCLS_MS_IsMediumReady (page 284)<br />

<strong>USB</strong> Bus Driver Reference Manual 279


14 Mass Storage Class Driver Reference<br />

HCLS_MS_ModeSenseAllPages<br />

This function returns some fields of the mode parameter header if the SCSI mode sense<br />

command is executed to return all available mode pages. It is a optional command.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_MS_ModeSenseAllPages(<br />

HCLS_MS_LUN_HANDLE Handle,<br />

T_UINT8* ParamHeaderMediumType,<br />

T_UINT8* ParamHeaderDeviceParameter,<br />

T_BOOL* IsWriteProtectFlag<br />

);<br />

Parameters<br />

Handle<br />

This parameter is the LUN handle returned by HCLS_MS_OpenLun.<br />

ParamHeaderMediumType<br />

Caller provided variable that receives the medium type field. The value is device specific, for<br />

more information see also the SCSI-2 specification.<br />

ParamHeaderDeviceParameter<br />

Caller provided variable that receives the device parameter field. The value is device specifc,<br />

for more information see also the SCSI-2 specification.<br />

IsWriteProtectFlag<br />

Caller provoded variable that recieves the extracted write protect flag of the medium type field.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

This function fails if the device is not ready, see also HCLS_MS_IsMediumReady. This<br />

function does not return any page information, see also<br />

HCLS_MS_ReadModeSenseRawPage. The mode sense command is a optional SCSI<br />

command but is implemented in <strong>USB</strong> mass storage devices.<br />

The function is blocking.<br />

See Also<br />

HCLS_MS_OpenLun (page 276)<br />

280 <strong>USB</strong> Bus Driver Reference Manual


HCLS_MS_IsMediumReady (page 284)<br />

HCLS_MS_ReadModeSenseRawPage (page 282)<br />

14 Mass Storage Class Driver Reference<br />

<strong>USB</strong> Bus Driver Reference Manual 281


14 Mass Storage Class Driver Reference<br />

HCLS_MS_ReadModeSenseRawPage<br />

This function returns the mode parameter in raw format. It is a optional command and it is not<br />

always needed.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_MS_ReadModeSenseRawPage(<br />

HCLS_MS_LUN_HANDLE Handle,<br />

T_UINT8 pageCode,<br />

T_UINT8* buffer,<br />

T_UINT32 size,<br />

T_UINT32* length,<br />

T_BOOL* modeHeader8ByteFlag<br />

);<br />

Parameters<br />

Handle<br />

This parameter is the LUN handle returned by HCLS_MS_OpenLun.<br />

pageCode<br />

Page code of the Mode parameter that is returned. The page code is value of type<br />

TSCSI_XXX_MODE_PAGE (xxx represent the page), see also tscsi.h. It can be combined<br />

through an OR operator with a value of type TSCSI_PAGE_CONTROL_XXX.<br />

buffer<br />

Pointer to a caller provided buffer that receives the mode parameter in raw format. The caller<br />

provides the storage of the buffer. The argument must not be NULL.<br />

size<br />

The size in bytes of the buffer given with buffer.<br />

length<br />

Caller provided variable that receives the number of bytes that were written to the buffer.<br />

The caller provides the storage of the variable. The argument must not be NULL.<br />

modeHeader8ByteFlag<br />

Caller provided variable that receives T_TRUE or T_FALSE depending on the type of the<br />

header. The caller provides the storage of the variable. The argument must not be NULL. This<br />

parameter is needed to detect the mode parameter header type. If the parameter receives<br />

T_TRUE the header has a size of 8 byte, otherwise if T_FALSE is received the header has a<br />

size of 4 byte. For more information see SCSI-2 specification.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

282 <strong>USB</strong> Bus Driver Reference Manual


Comments<br />

14 Mass Storage Class Driver Reference<br />

If the device is not ready the function fails, see also HCLS_MS_IsMediumReady.<br />

The function is blocking.<br />

See Also<br />

HCLS_MS_OpenLun (page 276)<br />

HCLS_MS_IsMediumReady (page 284)<br />

<strong>USB</strong> Bus Driver Reference Manual 283


14 Mass Storage Class Driver Reference<br />

HCLS_MS_IsMediumReady<br />

Send a Test Unit Ready SCSI command to the device.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_MS_IsMediumReady(<br />

HCLS_MS_LUN_HANDLE Handle<br />

);<br />

Parameter<br />

Handle<br />

This parameter is the LUN handle returned by HCLS_MS_OpenLun.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

It is useful for Detection of a medium, e.g. to detect a SD card in the medium. Before any file<br />

operation the device and the medium should be ready.<br />

The function is blocking.<br />

284 <strong>USB</strong> Bus Driver Reference Manual


HCLS_MS_ReadSectors<br />

This function reads sectors from a <strong>USB</strong> Mass Storage device.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_MS_ReadSectors(<br />

HCLS_MS_LUN_HANDLE Handle,<br />

T_UINT32 SectorAddress,<br />

T_UINT32 NumSectors,<br />

T_UINT8* Buffer<br />

);<br />

Parameters<br />

Handle<br />

This parameter is the LUN handle returned by HCLS_MS_OpenLun.<br />

SectorAddress<br />

This parameter describes the first sector to read.<br />

NumSectors<br />

This parameter determines the number of sectors to read.<br />

14 Mass Storage Class Driver Reference<br />

Buffer<br />

Pointer to a caller provided buffer that receives the data read from the sectors. The caller<br />

provides the storage of the buffer. The argument must not be NULL. The buffer memory that<br />

is passed to this function must be DMA memory. For more information about this memory<br />

please see section 5.3 at page 29.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise.<br />

Comments<br />

A valid LUN has to be requested by a call to HCLS_MS_GetLuns before you are able to<br />

successfully call HCLS_MS_ReadSectors.<br />

If the LUN is not ready it returns an error, see also HCLS_MS_IsMediumReady.<br />

The function is blocking.<br />

See Also<br />

HCLS_MS_OpenLun (page 276)<br />

HCLS_MS_WriteSectors (page 287)<br />

<strong>USB</strong> Bus Driver Reference Manual 285


14 Mass Storage Class Driver Reference<br />

HCLS_MS_GetLuns (page 275)<br />

HCLS_MS_IsMediumReady (page 284)<br />

286 <strong>USB</strong> Bus Driver Reference Manual


HCLS_MS_WriteSectors<br />

This function writes sectors to a <strong>USB</strong> Mass Storage device.<br />

Definition<br />

<strong>USB</strong>H_STATUS<br />

HCLS_MS_WriteSectors(<br />

HCLS_MS_LUN_HANDLE Handle,<br />

T_UINT32 SectorAddress,<br />

T_UINT32 NumSectors,<br />

T_UINT8* Buffer<br />

);<br />

Parameters<br />

Handle<br />

This parameter is the LUN handle returned by HCLS_MS_OpenLun.<br />

SectorAddress<br />

This parameter describes the first sector to write.<br />

NumSectors<br />

This parameter determines the number of sectors to write.<br />

14 Mass Storage Class Driver Reference<br />

Buffer<br />

Pointer to a caller provided buffer that contains the data to write to the sectors. The caller<br />

provides the storage of the buffer. The argument must not be NULL. The buffer memory that<br />

is passed to this function must be DMA memory. For more information about this memory<br />

please see section 5.3 at page 29.<br />

Return Value<br />

This function returns <strong>USB</strong>H_STATUS_SUCCESS in case of success or an appropriate error<br />

code otherwise. If the medium is write protected the function returns<br />

HCLS_MS_STATUS_WRITE_PROTECT.<br />

Comments<br />

HCLS_MS_WriteSectors can be called after a valid LUN was requested by a call to<br />

HCLS_MS_GetLuns.<br />

If the LUN is not ready it returns an error, see also HCLS_MS_IsMediumReady.<br />

The function is blocking.<br />

<strong>USB</strong> Bus Driver Reference Manual 287


14 Mass Storage Class Driver Reference<br />

See Also<br />

HCLS_MS_OpenLun (page 276)<br />

HCLS_MS_ReadSectors (page 285)<br />

HCLS_MS_GetLuns (page 275)<br />

HCLS_MS_IsMediumReady (page 284)<br />

288 <strong>USB</strong> Bus Driver Reference Manual


14.2 Structures<br />

T_UNIT_INFO<br />

This structure contains information of a logical unit.<br />

Definition<br />

typedef struct _T_UNIT_INFO{<br />

T_UINT8 InquiryDeviceType;<br />

unsigned int physLun;<br />

} T_UNIT_INFO;<br />

Members<br />

14 Mass Storage Class Driver Reference<br />

InquiryDeviceType<br />

This field contains the device type returned from the SCSI INQUIRY command, see also<br />

define TSCSI_INQUIRY_xxx_DEVICE_TYPE in tscsi.h.<br />

physLun<br />

This specify the zero indexed based LUN.<br />

<strong>USB</strong> Bus Driver Reference Manual 289


14 Mass Storage Class Driver Reference<br />

14.3 Status Codes<br />

Table 2 lists the error codes returned by the Mass Storage Class Driver. A detailed description can<br />

be found in section 14.4 at page 291.<br />

Table 2: Error codes<br />

Error Code Numerical Value<br />

HCLS_MS_STATUS_LENGTH 0x1000<br />

HCLS_MS_STATUS_COMMAND_FAILED 0x1002<br />

HCLS_MS_STATUS_INTERFACE_PROTOCOL 0x1003<br />

HCLS_MS_STATUS_INTERFACE_SUB_CLASS 0x1004<br />

HCLS_MS_STATUS_SENSE_REPEAT 0x1006<br />

HCLS_MS_STATUS_WRITE_PROTECT 0x1007<br />

HCLS_MS_STATUS_NOT_READY 0x1008<br />

290 <strong>USB</strong> Bus Driver Reference Manual


14.4 Status Codes Description<br />

HCLS_MS_STATUS_LENGTH (0x1000L)<br />

The operation detected a length error.<br />

HCLS_MS_STATUS_COMMAND_FAILED (0x1002L)<br />

14 Mass Storage Class Driver Reference<br />

This error is reported if the command code was sent successfully but the status returned from the<br />

device indicates a command error.<br />

HCLS_MS_STATUS_INTERFACE_PROTOCOL (0x1003L)<br />

The used interface protocol is not supported. The interface protocol is defined by the interface<br />

descriptor.<br />

HCLS_MS_STATUS_INTERFACE_SUB_CLASS (0x1004L)<br />

The used interface sub class is not supported. The interface sub class is defined by the interface<br />

descriptor.<br />

HCLS_MS_STATUS_SENSE_REPEAT (0x1006L)<br />

The command is repeated again because the device has aborted the command or at the time the<br />

command is send the device has been reset.<br />

HCLS_MS_STATUS_WRITE_PROTECT (0x1007L)<br />

This error indicates that the medium is write protected. It is returned by HCLS_MS_WriteSectors.<br />

HCLS_MS_STATUS_NOT_READY (0x1008L)<br />

This error indicates the logical unit addressed cannot be accessed. Operator intervention may be<br />

required to correct this condition, e.g. insert the medium.<br />

<strong>USB</strong> Bus Driver Reference Manual 291


Index<br />

HCLS_ACM_AbortRead, 192<br />

HCLS_ACM_AbortWrite, 187<br />

HCLS_ACM_Close, 175<br />

HCLS_ACM_CreateInterfaceList, 168<br />

HCLS_ACM_DestroyInterfaceList, 169<br />

HCLS_ACM_DeviceConnected, 166<br />

HCLS_ACM_DeviceRemoved, 172<br />

HCLS_ACM_DeviceStatusChanged, 179<br />

HCLS_ACM_Exit, 165<br />

HCLS_ACM_GetDeviceStatus, 177<br />

HCLS_ACM_GetInterfaceID, 170<br />

HCLS_ACM_GetInterfaceInfo, 171<br />

HCLS_ACM_GetReadFifoSize, 189<br />

HCLS_ACM_GetWriteFifoSize, 184<br />

HCLS_ACM_Init, 164<br />

HCLS_ACM_IsDevicePresent, 176<br />

HCLS_ACM_LineCoding, 194<br />

HCLS_ACM_Open, 173<br />

HCLS_ACM_Read, 190<br />

HCLS_ACM_RegisterConnectHandler, 167<br />

HCLS_ACM_RegisterStatusChangeHandler, 180<br />

HCLS_ACM_ResetReadPipe, 193<br />

HCLS_ACM_ResetWritePipe, 188<br />

HCLS_ACM_SendBreak, 183<br />

HCLS_ACM_SetControlLineState, 182<br />

HCLS_ACM_SetLineCoding, 181<br />

HCLS_ACM_Write, 185<br />

HCLS_HID_AbortRead, 230<br />

HCLS_HID_AbortWrite, 226<br />

HCLS_HID_Close, 207<br />

HCLS_HID_CreateInterfaceList, 200<br />

HCLS_HID_DestroyInterfaceList, 201<br />

HCLS_HID_DeviceConnected, 198<br />

HCLS_HID_DeviceRemoved, 204<br />

HCLS_HID_Exit, 197<br />

HCLS_HID_GetHidDescriptor, 209<br />

HCLS_HID_GetIdleRequest, 220<br />

HCLS_HID_GetInterfaceID, 202<br />

HCLS_HID_GetInterfaceInfo, 203<br />

HCLS_HID_GetNumDescriptors, 210<br />

HCLS_HID_GetProtocolRequest, 218<br />

HCLS_HID_GetReadFifoSize, 223<br />

HCLS_HID_GetReportDescriptorSize, 211<br />

HCLS_HID_GetReportDescriptor, 212<br />

HCLS_HID_GetReportRequest, 214<br />

HCLS_HID_GetWriteFifoSize, 222<br />

293


HCLS_HID_Init, 196<br />

HCLS_HID_IsDevicePresent, 208<br />

HCLS_HID_Open, 205<br />

HCLS_HID_ReadReport, 228<br />

HCLS_HID_RegisterConnectHandler, 199<br />

HCLS_HID_ResetReadPipe, 231<br />

HCLS_HID_ResetWritePipe, 227<br />

HCLS_HID_SetIdleRequest, 221<br />

HCLS_HID_SetProtocolRequest, 219<br />

HCLS_HID_SetReportRequest, 216<br />

HCLS_HID_WriteReport, 224<br />

HCLS_MS_CloseLun, 277<br />

HCLS_MS_Close, 274<br />

HCLS_MS_CreateInterfaceList, 267<br />

HCLS_MS_DestroyInterfaceList, 268<br />

HCLS_MS_DeviceConnected, 265<br />

HCLS_MS_DeviceRemove, 271<br />

HCLS_MS_Exit, 264<br />

HCLS_MS_GetInterfaceID, 270<br />

HCLS_MS_GetInterfaceInfo, 269<br />

HCLS_MS_GetLuns, 275<br />

HCLS_MS_InitLun, 278<br />

HCLS_MS_Init, 263<br />

HCLS_MS_IsMediumReady, 284<br />

HCLS_MS_ModeSenseAllPages, 280<br />

HCLS_MS_OpenLun, 276<br />

HCLS_MS_Open, 272<br />

HCLS_MS_ReadCapacity, 279<br />

HCLS_MS_ReadModeSenseRawPage, 282<br />

HCLS_MS_ReadSectors, 285<br />

HCLS_MS_RegisterConnectHandler, 266<br />

HCLS_MS_STATUS_COMMAND_FAILED, 291<br />

HCLS_MS_STATUS_INTERFACE_PROTOCOL, 291<br />

HCLS_MS_STATUS_INTERFACE_SUB_CLASS, 291<br />

HCLS_MS_STATUS_LENGTH, 291<br />

HCLS_MS_STATUS_NOT_READY, 291<br />

HCLS_MS_STATUS_SENSE_REPEAT, 291<br />

HCLS_MS_STATUS_WRITE_PROTECT, 291<br />

HCLS_MS_WriteSectors, 287<br />

HCLS_PRN_AbortRead, 261<br />

HCLS_PRN_AbortWrite, 255<br />

HCLS_PRN_Close, 243<br />

HCLS_PRN_CreateInterfaceList, 236<br />

HCLS_PRN_DestroyInterfaceList, 237<br />

HCLS_PRN_Exit, 233<br />

HCLS_PRN_GetAvailableInterfaces, 245<br />

HCLS_PRN_GetCurrentInterface, 246<br />

HCLS_PRN_GetDeviceId, 248<br />

294


HCLS_PRN_GetInterfaceID, 238<br />

HCLS_PRN_GetInterfaceInfo, 239<br />

HCLS_PRN_GetPortStatus, 249<br />

HCLS_PRN_Init, 232<br />

HCLS_PRN_IsPrinterPresent, 244<br />

HCLS_PRN_Open, 241<br />

HCLS_PRN_PrinterConnected, 234<br />

HCLS_PRN_PrinterRemove, 240<br />

HCLS_PRN_ReadSync, 259<br />

HCLS_PRN_Read, 257<br />

HCLS_PRN_RegisterConnectHandler, 235<br />

HCLS_PRN_ResetReadPipe, 262<br />

HCLS_PRN_ResetWritePipe, 256<br />

HCLS_PRN_SetInterface, 247<br />

HCLS_PRN_SoftReset, 250<br />

HCLS_PRN_WriteSync, 253<br />

HCLS_PRN_Write, 251<br />

HcohcReadReg, 126<br />

HcohcWriteReg, 125<br />

T_UNIT_INFO, 289<br />

TAL_AllocateDmaDescMemory, 132<br />

TAL_AllocateDmaMemory, 135<br />

TAL_AllocEvent, 148<br />

TAL_AllocMutex, 153<br />

TAL_AllocTimer, 142<br />

TAL_BuildDmaMd, 140<br />

TAL_CancelTimer, 145<br />

TAL_CreateTask, 157<br />

TAL_DeleteTask, 158<br />

TAL_EnterMutex, 155<br />

TAL_Exit, 129<br />

TAL_FlushCache, 138<br />

TAL_FreeDmaDescMemory, 133<br />

TAL_FreeDmaMemory, 136<br />

TAL_FreeEvent, 149<br />

TAL_FreeMutex, 154<br />

TAL_FreeTimer, 143<br />

TAL_Free, 131<br />

TAL_GetCacheLineSize, 134<br />

TAL_GetTime, 146<br />

TAL_Init, 128<br />

TAL_InvalidateCache, 137<br />

TAL_LeaveMutex, 156<br />

TAL_Malloc, 130<br />

TAL_MD_HEADER, 160<br />

TAL_MD_PAGE_ENTRY, 161<br />

TAL_MD, 162<br />

295


TAL_ResetEvent, 151<br />

TAL_SetEvent, 150<br />

TAL_Sleep, 147<br />

TAL_StartTimer, 144<br />

TAL_TIMER_HANDLE, 163<br />

TAL_TimerCallbackRoutine, 141<br />

TAL_WaitEvent, 152<br />

TAL_WaitTask, 159<br />

TAL_WriteSync, 139<br />

URB_BULK_INT_REQUEST, 100<br />

URB_COMPLETION, 73<br />

URB_CONTROL_REQUEST, 98<br />

URB_ENDPOINT_REQUEST, 104<br />

URB_FUNCTION, 116<br />

URB_HEADER, 111<br />

URB_ISO_FRAME, 101<br />

URB_ISO_REQUEST, 102<br />

URB_SET_CONFIGURATION, 105<br />

URB_SET_INTERFACE, 106<br />

URB_SET_SUSPEND_STATE, 107<br />

URB, 108<br />

<strong>USB</strong>H_AbortEndpointAndWait, 76<br />

<strong>USB</strong>H_CloseInterface, 54<br />

<strong>USB</strong>H_CreateEhcController, 40<br />

<strong>USB</strong>H_CreateInterfaceList, 41<br />

<strong>USB</strong>H_CreateOhcController, 39<br />

<strong>USB</strong>H_DestroyInterfaceList, 42<br />

<strong>USB</strong>H_ENUM_ERROR, 94<br />

<strong>USB</strong>H_EnumerateDevices, 38<br />

<strong>USB</strong>H_EnumErrorNotification, 49<br />

<strong>USB</strong>H_EP_MASK, 96<br />

<strong>USB</strong>H_Exit, 34<br />

<strong>USB</strong>H_GetClassDescriptor, 60<br />

<strong>USB</strong>H_GetCurrentConfigurationDescriptor, 56<br />

<strong>USB</strong>H_GetDeviceDescriptor, 55<br />

<strong>USB</strong>H_GetEndpointDescriptor, 62<br />

<strong>USB</strong>H_GetFrameNumber, 67<br />

<strong>USB</strong>H_GetHubPortHandlebyInterface, 69<br />

<strong>USB</strong>H_GetHubPortHandlebyTopology, 70<br />

<strong>USB</strong>H_GetInterfaceDescriptor, 58<br />

<strong>USB</strong>H_GetInterfaceIDByHandle, 68<br />

<strong>USB</strong>H_GetInterfaceID, 43<br />

<strong>USB</strong>H_GetInterfaceInfo, 44<br />

<strong>USB</strong>H_GetPortPowerState, 72<br />

<strong>USB</strong>H_GetSerialNumber, 64<br />

<strong>USB</strong>H_GetSpeed, 66<br />

<strong>USB</strong>H_GetStatusStr, 75<br />

296


<strong>USB</strong>H_Init, 33<br />

<strong>USB</strong>H_INTERFACE_INFO, 92<br />

<strong>USB</strong>H_INTERFACE_MASK, 90<br />

<strong>USB</strong>H_OpenInterface, 53<br />

<strong>USB</strong>H_PNP_EVENT, 114<br />

<strong>USB</strong>H_PNP_NOTIFICATION, 110<br />

<strong>USB</strong>H_PnpNotification, 46<br />

<strong>USB</strong>H_POWER_STATE, 115<br />

<strong>USB</strong>H_POWER_SWITCHING_NOT_SUPPORTED, 124<br />

<strong>USB</strong>H_ProcessInterrupt, 36<br />

<strong>USB</strong>H_RegisterEnumErrorNotification, 50<br />

<strong>USB</strong>H_RegisterPnPNotification, 47<br />

<strong>USB</strong>H_Remove<strong>Host</strong>Controller, 37<br />

<strong>USB</strong>H_ResetDeviceAndWait, 82<br />

<strong>USB</strong>H_ResetEndpointAndWait, 80<br />

<strong>USB</strong>H_RestartEnumError, 52<br />

<strong>USB</strong>H_ServiceISR, 35<br />

<strong>USB</strong>H_SetConfigurationAndWait, 84<br />

<strong>USB</strong>H_SetInterfaceAndWait, 86<br />

<strong>USB</strong>H_SetPortPowerState, 71<br />

<strong>USB</strong>H_SetupRequestAndWait, 88<br />

<strong>USB</strong>H_SPEED, 113<br />

<strong>USB</strong>H_STATUS_BITSTUFFING, 121<br />

<strong>USB</strong>H_STATUS_BUFFER_OVERFLOW, 122<br />

<strong>USB</strong>H_STATUS_BUFFER_OVERRUN, 122<br />

<strong>USB</strong>H_STATUS_BUFFER_UNDERRUN, 122<br />

<strong>USB</strong>H_STATUS_BUSY, 123<br />

<strong>USB</strong>H_STATUS_CANCELED, 123<br />

<strong>USB</strong>H_STATUS_CRC, 121<br />

<strong>USB</strong>H_STATUS_DATA_OVERRUN, 121<br />

<strong>USB</strong>H_STATUS_DATA_UNDERRUN, 122<br />

<strong>USB</strong>H_STATUS_DATATOGGLE, 121<br />

<strong>USB</strong>H_STATUS_DEVICE_REMOVED, 123<br />

<strong>USB</strong>H_STATUS_ENDPOINT_HALTED, 123<br />

<strong>USB</strong>H_STATUS_ERROR, 122<br />

<strong>USB</strong>H_STATUS_INVALID_ALIGNMENT, 124<br />

<strong>USB</strong>H_STATUS_INVALID_DESCRIPTOR, 123<br />

<strong>USB</strong>H_STATUS_INVALID_PARAM, 122<br />

<strong>USB</strong>H_STATUS_NO_MEMORY, 124<br />

<strong>USB</strong>H_STATUS_NO_RESOURCES, 124<br />

<strong>USB</strong>H_STATUS_NOT_ACCESSED, 122<br />

<strong>USB</strong>H_STATUS_NOTRESPONDING, 121<br />

<strong>USB</strong>H_STATUS_PENDING, 123<br />

<strong>USB</strong>H_STATUS_PID_CHECK, 121<br />

<strong>USB</strong>H_STATUS_PORT, 123<br />

<strong>USB</strong>H_STATUS_STALL, 121<br />

<strong>USB</strong>H_STATUS_SUCCESS, 121<br />

<strong>USB</strong>H_STATUS_TIMEOUT, 123<br />

297


<strong>USB</strong>H_STATUS_UNEXPECTED_PID, 121<br />

<strong>USB</strong>H_STATUS_USER, 124<br />

<strong>USB</strong>H_SubmitUrbAndWait, 78<br />

<strong>USB</strong>H_SubmitUrb, 74<br />

<strong>USB</strong>H_SUSPEND_STATE, 119<br />

<strong>USB</strong>H_UnregisterEnumErrorNotification, 51<br />

<strong>USB</strong>H_UnregisterPnPNotification, 48<br />

<strong>USB</strong>H_WaitForIdle<strong>Stack</strong>, 45<br />

298

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!