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_OHCI_HW_STRUCT_TRANSFER_DESCRIPTOR_H
00035 #define DRV_OHCI_HW_STRUCT_TRANSFER_DESCRIPTOR_H
00036 
00037 #include <bool.h>
00038 #include <stdint.h>
00039 #include "../utils/malloc32.h"
00040 
00041 #include "completion_codes.h"
00042 
00043 /* OHCI TDs can handle up to 8KB buffers, however, it can use max 2 pages.
00044  * Using 4KB buffers guarantees the page count condition.
00045  * (OHCI assumes 4KB pages) */
00046 #define OHCI_TD_MAX_TRANSFER (4 * 1024)
00047 
00048 typedef struct td {
00049         volatile uint32_t status;
00050 #define TD_STATUS_ROUND_FLAG (1 << 18)
00051 #define TD_STATUS_DP_MASK (0x3) /* direction/PID */
00052 #define TD_STATUS_DP_SHIFT (19)
00053 #define TD_STATUS_DP_SETUP (0x0)
00054 #define TD_STATUS_DP_OUT (0x1)
00055 #define TD_STATUS_DP_IN (0x2)
00056 #define TD_STATUS_DI_MASK (0x7) /* delay interrupt, wait DI frames before int */
00057 #define TD_STATUS_DI_SHIFT (21)
00058 #define TD_STATUS_DI_NO_INTERRUPT (0x7)
00059 #define TD_STATUS_T_MASK (0x3)  /* data toggle 1x = use ED toggle carry */
00060 #define TD_STATUS_T_SHIFT (24)
00061 #define TD_STATUS_T_0 (0x2)
00062 #define TD_STATUS_T_1 (0x3)
00063 #define TD_STATUS_T_ED (0)
00064 #define TD_STATUS_EC_MASK (0x3) /* error count */
00065 #define TD_STATUS_EC_SHIFT (26)
00066 #define TD_STATUS_CC_MASK (0xf) /* condition code */
00067 #define TD_STATUS_CC_SHIFT (28)
00068 
00069         volatile uint32_t cbp; /* current buffer ptr, data to be transfered */
00070         volatile uint32_t next;
00071 #define TD_NEXT_PTR_MASK (0xfffffff0)
00072 #define TD_NEXT_PTR_SHIFT (0)
00073 
00074         volatile uint32_t be; /* buffer end, address of the last byte */
00075 } __attribute__((packed)) td_t;
00076 
00077 void td_init(
00078     td_t *instance, usb_direction_t dir, void *buffer, size_t size, int toggle);
00079 
00080 inline static void td_set_next(td_t *instance, td_t *next)
00081 {
00082         assert(instance);
00083         instance->next = addr_to_phys(next) & TD_NEXT_PTR_MASK;
00084 }
00085 
00086 inline static bool td_is_finished(td_t *instance)
00087 {
00088         assert(instance);
00089         int cc = (instance->status >> TD_STATUS_CC_SHIFT) & TD_STATUS_CC_MASK;
00090         /* something went wrong, error code is set */
00091         if (cc != CC_NOACCESS1 && cc != CC_NOACCESS2) {
00092                 return true;
00093         }
00094         /* everything done */
00095         if (cc == CC_NOERROR && instance->cbp == 0) {
00096                 return true;
00097         }
00098         return false;
00099 }
00100 
00101 static inline int td_error(td_t *instance)
00102 {
00103         assert(instance);
00104         int cc = (instance->status >> TD_STATUS_CC_SHIFT) & TD_STATUS_CC_MASK;
00105         return cc_to_rc(cc);
00106 }
00107 
00108 static inline size_t td_remain_size(td_t *instance)
00109 {
00110         assert(instance);
00111         if (instance->cbp == 0)
00112                 return 0;
00113         return instance->be - instance->cbp + 1;
00114 }
00115 #endif
00116 

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