USBHOST lib for STM

Dependents:   door-access-controller-dev

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers USBHALHost.h Source File

USBHALHost.h

00001 /* mbed USBHost Library
00002  * Copyright (c) 2006-2013 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef USBHALHOST_H
00018 #define USBHALHOST_H
00019 
00020 #include "USBHostTypes.h"
00021 #include "USBHostConf.h"
00022 
00023 class USBHostHub;
00024 
00025 /**
00026 * USBHALHost class
00027 */
00028 class USBHALHost {
00029 protected:
00030 
00031     /**
00032     * Constructor
00033     * init variables and memory where will be stored HCCA, ED and TD
00034     */
00035     USBHALHost();
00036 
00037     /**
00038     * Initialize host controller. Enable USB interrupts. This part is not in the constructor because,
00039     * this function calls a virtual method if a device is already connected
00040     */
00041     void init();
00042 
00043     /**
00044     * reset the root hub
00045     */
00046     void resetRootHub();
00047 
00048     /**
00049     * return the value contained in the control HEAD ED register
00050     *
00051     * @returns address of the control Head ED
00052     */
00053     uint32_t controlHeadED();
00054 
00055     /**
00056     * return the value contained in the bulk HEAD ED register
00057     *
00058     * @returns address of the bulk head ED
00059     */
00060     uint32_t bulkHeadED();
00061 
00062     /**
00063     * return the value of the head interrupt ED contained in the HCCA
00064     *
00065     * @returns address of the head interrupt ED contained in the HCCA
00066     */
00067     uint32_t interruptHeadED();
00068 
00069     /**
00070     * Update the head ED for control transfers
00071     */
00072     void updateControlHeadED(uint32_t addr);
00073 
00074     /**
00075     * Update the head ED for bulk transfers
00076     */
00077     void updateBulkHeadED(uint32_t addr);
00078 
00079     /**
00080     * Update the head ED for interrupt transfers
00081     */
00082     void updateInterruptHeadED(uint32_t addr);
00083 
00084     /**
00085     * Enable List for the specified endpoint type
00086     *
00087     * @param type enable the list of ENDPOINT_TYPE type
00088     */
00089     void enableList(ENDPOINT_TYPE type);
00090 
00091     /**
00092     * Disable List for the specified endpoint type
00093     *
00094     * @param type disable the list of ENDPOINT_TYPE type
00095     */
00096     bool disableList(ENDPOINT_TYPE type);
00097 
00098     /**
00099     * Virtual method called when a device has been connected
00100     *
00101     * @param hub hub number of the device
00102     * @param port port number of the device
00103     * @param lowSpeed 1 if low speed, 0 otherwise
00104     * @param hub_parent reference to the hub where the device is connected (NULL if the hub parent is the root hub)
00105     */
00106     virtual void deviceConnected(int hub, int port, bool lowSpeed, USBHostHub * hub_parent = NULL) = 0;
00107 
00108     /**
00109     * Virtual method called when a device has been disconnected
00110     *
00111     * @param hub hub number of the device
00112     * @param port port number of the device
00113     * @param hub_parent reference to the hub where the device is connected (NULL if the hub parent is the root hub)
00114     * @param addr list of the TDs which have been completed to dequeue freed TDs
00115     */
00116     virtual void deviceDisconnected(int hub, int port, USBHostHub * hub_parent, volatile uint32_t addr) = 0;
00117 
00118     /**
00119     * Virtual method called when a transfer has been completed
00120     *
00121     * @param addr list of the TDs which have been completed
00122     */
00123     virtual void transferCompleted(volatile uint32_t addr) = 0;
00124 
00125     /**
00126     * Find a memory section for a new ED
00127     *
00128     * @returns the address of the new ED
00129     */
00130     volatile uint8_t * getED();
00131 
00132     /**
00133     * Find a memory section for a new TD
00134     *
00135     * @returns the address of the new TD
00136     */
00137     volatile uint8_t * getTD();
00138 
00139     /**
00140     * Release a previous memory section reserved for an ED
00141     *
00142     * @param ed address of the ED
00143     */
00144     void freeED(volatile uint8_t * ed);
00145 
00146     /**
00147     * Release a previous memory section reserved for an TD
00148     *
00149     * @param td address of the TD
00150     */
00151     void freeTD(volatile uint8_t * td);
00152 
00153 private:
00154     static void _usbisr(void);
00155     void UsbIrqhandler();
00156 
00157     void memInit();
00158 
00159     HCCA volatile * usb_hcca;           //256 bytes aligned
00160     uint8_t volatile  * usb_edBuf;      //4 bytes aligned
00161     uint8_t volatile  * usb_tdBuf;      //4 bytes aligned
00162 
00163     static USBHALHost * instHost;
00164 
00165     bool volatile  edBufAlloc[MAX_ENDPOINT];
00166     bool volatile tdBufAlloc[MAX_TD];
00167 #ifdef USBHOST_OTHER
00168     int control_disable;
00169 #endif
00170 
00171 };
00172 
00173 #endif