transfer_descriptor.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2011 Jan Vesely
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00034 #ifndef DRV_UHCI_HW_STRUCT_TRANSFER_DESCRIPTOR_H
00035 #define DRV_UHCI_HW_STRUCT_TRANSFER_DESCRIPTOR_H
00036 
00037 #include <mem.h>
00038 #include <usb/usb.h>
00039 
00040 #include "link_pointer.h"
00041 
00043 typedef struct transfer_descriptor {
00045         link_pointer_t next;
00046 
00048         volatile uint32_t status;
00049 #define TD_STATUS_RESERVED_MASK 0xc000f800
00050 #define TD_STATUS_SPD_FLAG         (1 << 29)
00051 #define TD_STATUS_ERROR_COUNT_POS 27
00052 #define TD_STATUS_ERROR_COUNT_MASK 0x3
00053 #define TD_STATUS_LOW_SPEED_FLAG   (1 << 26)
00054 #define TD_STATUS_ISOCHRONOUS_FLAG (1 << 25)
00055 #define TD_STATUS_IOC_FLAG         (1 << 24)
00056 
00057 #define TD_STATUS_ERROR_ACTIVE    (1 << 23)
00058 #define TD_STATUS_ERROR_STALLED   (1 << 22)
00059 #define TD_STATUS_ERROR_BUFFER    (1 << 21)
00060 #define TD_STATUS_ERROR_BABBLE    (1 << 20)
00061 #define TD_STATUS_ERROR_NAK       (1 << 19)
00062 #define TD_STATUS_ERROR_CRC       (1 << 18)
00063 #define TD_STATUS_ERROR_BIT_STUFF (1 << 17)
00064 #define TD_STATUS_ERROR_RESERVED  (1 << 16)
00065 #define TD_STATUS_ERROR_POS 16
00066 #define TD_STATUS_ERROR_MASK 0xff
00067 
00068 #define TD_STATUS_ACTLEN_POS 0
00069 #define TD_STATUS_ACTLEN_MASK 0x7ff
00070 
00071         /* double word with USB device specific info */
00072         volatile uint32_t device;
00073 #define TD_DEVICE_MAXLEN_POS 21
00074 #define TD_DEVICE_MAXLEN_MASK 0x7ff
00075 #define TD_DEVICE_RESERVED_FLAG        (1 << 20)
00076 #define TD_DEVICE_DATA_TOGGLE_ONE_FLAG (1 << 19)
00077 #define TD_DEVICE_ENDPOINT_POS 15
00078 #define TD_DEVICE_ENDPOINT_MASK 0xf
00079 #define TD_DEVICE_ADDRESS_POS 8
00080 #define TD_DEVICE_ADDRESS_MASK 0x7f
00081 #define TD_DEVICE_PID_POS 0
00082 #define TD_DEVICE_PID_MASK 0xff
00083 
00085         volatile uint32_t buffer_ptr;
00086 
00087         /* According to UHCI design guide, there is 16 bytes of
00088          * data available here.
00089          * According to linux kernel the hardware does not care,
00090          * it just needs to be aligned. We don't use it anyway.
00091          */
00092 } __attribute__((packed)) td_t;
00093 
00094 
00095 void td_init(td_t *instance, int error_count, size_t size, bool toggle,
00096     bool iso, bool low_speed, usb_target_t target, usb_packet_id pid,
00097     void *buffer, td_t *next);
00098 
00099 int td_status(td_t *instance);
00100 
00101 void td_print_status(td_t *instance);
00102 /*----------------------------------------------------------------------------*/
00108 static inline size_t td_act_size(td_t *instance)
00109 {
00110         assert(instance);
00111         const uint32_t s = instance->status;
00112         return ((s >> TD_STATUS_ACTLEN_POS) + 1) & TD_STATUS_ACTLEN_MASK;
00113 }
00114 /*----------------------------------------------------------------------------*/
00121 static inline bool td_is_short(td_t *instance)
00122 {
00123         const size_t act_size = td_act_size(instance);
00124         const size_t max_size =
00125             ((instance->device >> TD_DEVICE_MAXLEN_POS) + 1)
00126             & TD_DEVICE_MAXLEN_MASK;
00127         return
00128             (instance->status | TD_STATUS_SPD_FLAG) && act_size < max_size;
00129 }
00130 /*----------------------------------------------------------------------------*/
00136 static inline int td_toggle(td_t *instance)
00137 {
00138         assert(instance);
00139         return (instance->device & TD_DEVICE_DATA_TOGGLE_ONE_FLAG) ? 1 : 0;
00140 }
00141 /*----------------------------------------------------------------------------*/
00147 static inline bool td_is_active(td_t *instance)
00148 {
00149         assert(instance);
00150         return (instance->status & TD_STATUS_ERROR_ACTIVE) != 0;
00151 }
00152 /*----------------------------------------------------------------------------*/
00157 static inline void td_set_ioc(td_t *instance)
00158 {
00159         assert(instance);
00160         instance->status |= TD_STATUS_IOC_FLAG;
00161 }
00162 /*----------------------------------------------------------------------------*/
00163 #endif
00164 

Generated on Thu Jun 2 07:45:44 2011 for HelenOS/USB by  doxygen 1.4.7