Ignore:
Timestamp:
2011-10-30T19:50:54Z (13 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3ce78580, 48902fa
Parents:
4c3ad56 (diff), 45bf63c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/ohci/hw_struct/transfer_descriptor.h

    r4c3ad56 r20a3465  
    3737#include <bool.h>
    3838#include <stdint.h>
     39
    3940#include "../utils/malloc32.h"
    40 
    4141#include "completion_codes.h"
    4242
     
    4646#define OHCI_TD_MAX_TRANSFER (4 * 1024)
    4747
     48/**
     49 * Transfer Descriptor representation.
     50 *
     51 * See OHCI spec chapter 4.3.1 General Transfer Descriptor on page 19
     52 * (pdf page 33) for details.
     53 */
    4854typedef struct td {
     55        /** Status field. Do not touch on active TDs. */
    4956        volatile uint32_t status;
    5057#define TD_STATUS_ROUND_FLAG (1 << 18)
    51 #define TD_STATUS_DP_MASK (0x3) /* direction/PID */
     58#define TD_STATUS_DP_MASK (0x3) /* Direction/PID */
    5259#define TD_STATUS_DP_SHIFT (19)
    5360#define TD_STATUS_DP_SETUP (0x0)
    5461#define TD_STATUS_DP_OUT (0x1)
    5562#define TD_STATUS_DP_IN (0x2)
    56 #define TD_STATUS_DI_MASK (0x7) /* delay interrupt, wait DI frames before int */
     63#define TD_STATUS_DI_MASK (0x7) /* Delay interrupt, wait n frames before irq */
    5764#define TD_STATUS_DI_SHIFT (21)
    5865#define TD_STATUS_DI_NO_INTERRUPT (0x7)
    59 #define TD_STATUS_T_MASK (0x3)  /* data toggle 1x = use ED toggle carry */
    60 #define TD_STATUS_T_SHIFT (24)
    61 #define TD_STATUS_T_0 (0x2)
    62 #define TD_STATUS_T_1 (0x3)
    63 #define TD_STATUS_T_ED (0)
    64 #define TD_STATUS_EC_MASK (0x3) /* error count */
     66#define TD_STATUS_T_FLAG (1 << 24) /* Explicit toggle bit value for this TD */
     67#define TD_STATUS_T_USE_TD_FLAG (1 << 25) /* 1 = use bit 24 as toggle bit */
     68#define TD_STATUS_EC_MASK (0x3) /* Error count */
    6569#define TD_STATUS_EC_SHIFT (26)
    66 #define TD_STATUS_CC_MASK (0xf) /* condition code */
     70#define TD_STATUS_CC_MASK (0xf) /* Condition code */
    6771#define TD_STATUS_CC_SHIFT (28)
    6872
    69         volatile uint32_t cbp; /* current buffer ptr, data to be transfered */
     73        /**
     74         * Current buffer pointer.
     75         * Phys address of the first byte to be transferred. */
     76        volatile uint32_t cbp;
     77
     78        /** Pointer to the next TD in chain. 16-byte aligned. */
    7079        volatile uint32_t next;
    7180#define TD_NEXT_PTR_MASK (0xfffffff0)
    7281#define TD_NEXT_PTR_SHIFT (0)
    7382
    74         volatile uint32_t be; /* buffer end, address of the last byte */
     83        /**
     84         * Buffer end.
     85         * Phys address of the last byte of the transfer.
     86         * @note this does not have to be on the same page as cbp.
     87         */
     88        volatile uint32_t be;
    7589} __attribute__((packed)) td_t;
    7690
    77 void td_init(td_t *instance,
     91void td_init(td_t *instance, const td_t *next,
    7892    usb_direction_t dir, const void *buffer, size_t size, int toggle);
    7993
    80 inline static void td_set_next(td_t *instance, td_t *next)
     94/**
     95 * Check TD for completion.
     96 * @param instance TD structure.
     97 * @return true if the TD was accessed and processed by hw, false otherwise.
     98 */
     99inline static bool td_is_finished(const td_t *instance)
    81100{
    82101        assert(instance);
    83         instance->next = addr_to_phys(next) & TD_NEXT_PTR_MASK;
    84 }
    85 
    86 inline static bool td_is_finished(td_t *instance)
    87 {
    88         assert(instance);
    89         int cc = (instance->status >> TD_STATUS_CC_SHIFT) & TD_STATUS_CC_MASK;
    90         /* something went wrong, error code is set */
     102        const int cc =
     103            (instance->status >> TD_STATUS_CC_SHIFT) & TD_STATUS_CC_MASK;
     104        /* This value is changed on transfer completion,
     105         * either to CC_NOERROR or and error code.
     106         * See OHCI spec 4.3.1.3.5 p. 23 (pdf 37) */
    91107        if (cc != CC_NOACCESS1 && cc != CC_NOACCESS2) {
    92                 return true;
    93         }
    94         /* everything done */
    95         if (cc == CC_NOERROR && instance->cbp == 0) {
    96108                return true;
    97109        }
     
    99111}
    100112
    101 static inline int td_error(td_t *instance)
     113/**
     114 * Get error code that indicates transfer status.
     115 * @param instance TD structure.
     116 * @return Error code.
     117 */
     118static inline int td_error(const td_t *instance)
    102119{
    103120        assert(instance);
    104         int cc = (instance->status >> TD_STATUS_CC_SHIFT) & TD_STATUS_CC_MASK;
     121        const int cc =
     122            (instance->status >> TD_STATUS_CC_SHIFT) & TD_STATUS_CC_MASK;
    105123        return cc_to_rc(cc);
    106124}
    107125
     126/**
     127 * Get remaining portion of buffer to be read/written
     128 * @param instance TD structure
     129 * @return size of remaining buffer.
     130 */
    108131static inline size_t td_remain_size(td_t *instance)
    109132{
    110133        assert(instance);
     134        /* Current buffer pointer is cleared on successful transfer */
    111135        if (instance->cbp == 0)
    112136                return 0;
     137        /* Buffer end points to the last byte of transfer buffer, so add 1 */
    113138        return instance->be - instance->cbp + 1;
    114139}
Note: See TracChangeset for help on using the changeset viewer.