Support Isochronous transfer additionally

Dependents:   USBHostC270_example_GR-PEACH USBHostDac_example USBHostDac_Audio_in_out

Fork of USBHost_custom by Renesas

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers USBEndpoint.h Source File

USBEndpoint.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 USBENDPOINT_H
00018 #define USBENDPOINT_H
00019 
00020 #include "FunctionPointer.h"
00021 #include "USBHostTypes.h"
00022 #include "rtos.h"
00023 
00024 class USBDeviceConnected;
00025 
00026 /**
00027 * USBEndpoint class
00028 */
00029 class USBEndpoint
00030 {
00031 public:
00032     /**
00033     * Constructor
00034     */
00035     USBEndpoint() {
00036         state = USB_TYPE_FREE;
00037         nextEp = NULL;
00038     };
00039 
00040     /**
00041     * Initialize an endpoint
00042     *
00043     * @param hced hced associated to the endpoint
00044     * @param type endpoint type
00045     * @param dir endpoint direction
00046     * @param size endpoint size
00047     * @param ep_number endpoint number
00048     * @param td_list array of two allocated transfer descriptors
00049     */
00050     void init(HCED * hced, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint32_t size, uint8_t ep_number, HCTD* td_list[2]);
00051 
00052     /**
00053     * Set next token. Warning: only useful for the control endpoint
00054     *
00055     * @param token IN, OUT or SETUP token
00056     */
00057     void setNextToken(uint32_t token);
00058 
00059     /**
00060     * Queue an endpoint
00061     *
00062     * @param endpoint endpoint which will be queued in the linked list
00063     */
00064     void queueEndpoint(USBEndpoint * endpoint);
00065 
00066 
00067     /**
00068     * Queue a transfer on the endpoint
00069     */
00070     void queueTransfer();
00071 
00072     /**
00073     * Unqueue a transfer from the endpoint
00074     *
00075     * @param td hctd which will be unqueued
00076     */
00077     void unqueueTransfer(volatile HCTD * td);
00078 
00079     /**
00080      *  Attach a member function to call when a transfer is finished
00081      *
00082      *  @param tptr pointer to the object to call the member function on
00083      *  @param mptr pointer to the member function to be called
00084      */
00085     template<typename T>
00086     inline void attach(T* tptr, void (T::*mptr)(void)) {
00087         if((mptr != NULL) && (tptr != NULL)) {
00088             rx.attach(tptr, mptr);
00089         }
00090     }
00091 
00092     /**
00093      * Attach a callback called when a transfer is finished
00094      *
00095      * @param fptr function pointer
00096      */
00097     inline void attach(void (*fptr)(void)) {
00098             rx.attach(fptr);
00099     }
00100 
00101     /**
00102     * Call the handler associted to the end of a transfer
00103     */
00104     inline void call() {
00105         rx.call();
00106     };
00107 
00108 
00109     // setters
00110     inline void setState(USB_TYPE st) { state = st; }
00111     void setState(uint8_t st);
00112     void setDeviceAddress(uint8_t addr);
00113     inline void setLengthTransferred(int len) { transferred = len; };
00114     void setSpeed(uint8_t speed);
00115     void setSize(uint32_t size);
00116     inline void setDir(ENDPOINT_DIRECTION d) { dir = d; }
00117     inline void setIntfNb(uint8_t intf_nb_) { intf_nb = intf_nb_; };
00118 
00119     // getters
00120     const char *                getStateString();
00121     inline USB_TYPE             getState() { return state; }
00122     inline ENDPOINT_TYPE        getType() { return type; };
00123     inline uint8_t              getDeviceAddress() { return hced->control & 0x7f; };
00124     inline int                  getLengthTransferred() { return transferred; }
00125     inline uint8_t *            getBufStart() { return buf_start; }
00126     inline uint8_t              getAddress(){ return address; };
00127     inline uint32_t             getSize() { return (hced->control >> 16) & 0x3ff; };
00128     inline volatile HCTD *      getHeadTD() { return (volatile HCTD*) ((uint32_t)hced->headTD & ~0xF); };
00129     inline volatile HCTD**      getTDList() { return td_list; };
00130     inline volatile HCED *      getHCED() { return hced; };
00131     inline ENDPOINT_DIRECTION   getDir() { return dir; }
00132     inline volatile HCTD *      getProcessedTD() { return td_current; };
00133     inline volatile HCTD*       getNextTD() { return td_current; };
00134     inline bool                 isSetup() { return setup; }
00135     inline USBEndpoint *        nextEndpoint() { return (USBEndpoint*)nextEp; };
00136     inline uint8_t              getIntfNb() { return intf_nb; };
00137 
00138     USBDeviceConnected * dev;
00139 
00140     Queue<uint8_t, 1> ep_queue;
00141 
00142 private:
00143     ENDPOINT_TYPE type;
00144     volatile USB_TYPE state;
00145     ENDPOINT_DIRECTION dir;
00146     bool setup;
00147 
00148     uint8_t address;
00149 
00150     int transfer_len;
00151     int transferred;
00152     uint8_t * buf_start;
00153 
00154     FunctionPointer rx;
00155 
00156     USBEndpoint* nextEp;
00157 
00158     // USBEndpoint descriptor
00159     volatile HCED * hced;
00160 
00161     volatile HCTD * td_list[2];
00162     volatile HCTD * td_current;
00163     volatile HCTD * td_next;
00164 
00165     uint8_t intf_nb;
00166 
00167 };
00168 
00169 #endif