Changeset 6e3b9a58 in mainline for uspace/drv/uhci-hcd/batch.c


Ignore:
Timestamp:
2011-03-18T14:17:27Z (13 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
bb41b85
Parents:
a8def7d (diff), 4f66cc7b (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:

Merged changes from branch lelian/hidd

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci-hcd/batch.c

    ra8def7d r6e3b9a58  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup usb
     28/** @addtogroup drvusbuhcihc
    2929 * @{
    3030 */
    3131/** @file
    32  * @brief UHCI driver
     32 * @brief UHCI driver USB transaction structure
    3333 */
    3434#include <errno.h>
     
    4040#include "batch.h"
    4141#include "transfer_list.h"
    42 #include "uhci.h"
     42#include "uhci_hc.h"
    4343#include "utils/malloc32.h"
    4444
    4545#define DEFAULT_ERROR_COUNT 3
    46 
    47 static int batch_schedule(batch_t *instance);
    4846
    4947static void batch_control(batch_t *instance,
     
    5452static void batch_call_in_and_dispose(batch_t *instance);
    5553static void batch_call_out_and_dispose(batch_t *instance);
    56 static void batch_dispose(batch_t *instance);
    57 
    58 
    59 /** Allocates memory and initializes internal data structures.
     54
     55
     56/** Allocate memory and initialize internal data structure.
    6057 *
    6158 * @param[in] fun DDF function to pass to callback.
     
    7269 * @param[in] arg additional parameter to func_in or func_out
    7370 * @param[in] manager Pointer to toggle management structure.
    74  * @return False, if there is an active TD, true otherwise.
     71 * @return Valid pointer if all substructures were successfully created,
     72 * NULL otherwise.
     73 *
     74 * Determines the number of needed packets (TDs). Prepares a transport buffer
     75 * (that is accessible by the hardware). Initializes parameters needed for the
     76 * transaction and callback.
    7577 */
    7678batch_t * batch_get(ddf_fun_t *fun, usb_target_t target,
     
    100102        bzero(instance, sizeof(batch_t));
    101103
    102         instance->qh = malloc32(sizeof(queue_head_t));
     104        instance->qh = malloc32(sizeof(qh_t));
    103105        CHECK_NULL_DISPOSE_RETURN(instance->qh,
    104106            "Failed to allocate batch queue head.\n");
    105         queue_head_init(instance->qh);
     107        qh_init(instance->qh);
    106108
    107109        instance->packets = (size + max_packet_size - 1) / max_packet_size;
     
    114116            instance->tds, "Failed to allocate transfer descriptors.\n");
    115117        bzero(instance->tds, sizeof(td_t) * instance->packets);
    116 
    117 //      const size_t transport_size = max_packet_size * instance->packets;
    118118
    119119        if (size > 0) {
     
    143143        instance->speed = speed;
    144144        instance->manager = manager;
    145 
    146         if (func_out)
    147                 instance->callback_out = func_out;
    148         if (func_in)
    149                 instance->callback_in = func_in;
    150 
    151         queue_head_set_element_td(instance->qh, addr_to_phys(instance->tds));
     145        instance->callback_out = func_out;
     146        instance->callback_in = func_in;
     147
     148        qh_set_element_td(instance->qh, addr_to_phys(instance->tds));
    152149
    153150        usb_log_debug("Batch(%p) %d:%d memory structures ready.\n",
     
    156153}
    157154/*----------------------------------------------------------------------------*/
    158 /** Checks batch TDs for activity.
     155/** Check batch TDs for activity.
    159156 *
    160157 * @param[in] instance Batch structure to use.
    161158 * @return False, if there is an active TD, true otherwise.
     159 *
     160 * Walk all TDs. Stop with false if there is an active one (it is to be
     161 * processed). Stop with true if an error is found. Return true if the last TS
     162 * is reached.
    162163 */
    163164bool batch_is_complete(batch_t *instance)
     
    177178                        usb_log_debug("Batch(%p) found error TD(%d):%x.\n",
    178179                            instance, i, instance->tds[i].status);
     180                        td_print_status(&instance->tds[i]);
    179181
    180182                        device_keeper_set_toggle(instance->manager,
     
    197199 *
    198200 * @param[in] instance Batch structure to use.
     201 *
     202 * Uses genercir control function with pids OUT and IN.
    199203 */
    200204void batch_control_write(batch_t *instance)
    201205{
    202206        assert(instance);
    203         /* we are data out, we are supposed to provide data */
     207        /* We are data out, we are supposed to provide data */
    204208        memcpy(instance->transport_buffer, instance->buffer,
    205209            instance->buffer_size);
     
    207211        instance->next_step = batch_call_out_and_dispose;
    208212        usb_log_debug("Batch(%p) CONTROL WRITE initialized.\n", instance);
    209         batch_schedule(instance);
    210213}
    211214/*----------------------------------------------------------------------------*/
     
    213216 *
    214217 * @param[in] instance Batch structure to use.
     218 *
     219 * Uses generic control with pids IN and OUT.
    215220 */
    216221void batch_control_read(batch_t *instance)
     
    220225        instance->next_step = batch_call_in_and_dispose;
    221226        usb_log_debug("Batch(%p) CONTROL READ initialized.\n", instance);
    222         batch_schedule(instance);
    223 }
    224 /*----------------------------------------------------------------------------*/
    225 /** Prepares interrupt in transaction.
    226  *
    227  * @param[in] instance Batch structure to use.
     227}
     228/*----------------------------------------------------------------------------*/
     229/** Prepare interrupt in transaction.
     230 *
     231 * @param[in] instance Batch structure to use.
     232 *
     233 * Data transaction with PID_IN.
    228234 */
    229235void batch_interrupt_in(batch_t *instance)
     
    233239        instance->next_step = batch_call_in_and_dispose;
    234240        usb_log_debug("Batch(%p) INTERRUPT IN initialized.\n", instance);
    235         batch_schedule(instance);
    236 }
    237 /*----------------------------------------------------------------------------*/
    238 /** Prepares interrupt out transaction.
    239  *
    240  * @param[in] instance Batch structure to use.
     241}
     242/*----------------------------------------------------------------------------*/
     243/** Prepare interrupt out transaction.
     244 *
     245 * @param[in] instance Batch structure to use.
     246 *
     247 * Data transaction with PID_OUT.
    241248 */
    242249void batch_interrupt_out(batch_t *instance)
    243250{
    244251        assert(instance);
    245         /* we are data out, we are supposed to provide data */
     252        /* We are data out, we are supposed to provide data */
    246253        memcpy(instance->transport_buffer, instance->buffer, instance->buffer_size);
    247254        batch_data(instance, USB_PID_OUT);
    248255        instance->next_step = batch_call_out_and_dispose;
    249256        usb_log_debug("Batch(%p) INTERRUPT OUT initialized.\n", instance);
    250         batch_schedule(instance);
    251 }
    252 /*----------------------------------------------------------------------------*/
    253 /** Prepares bulk in transaction.
    254  *
    255  * @param[in] instance Batch structure to use.
     257}
     258/*----------------------------------------------------------------------------*/
     259/** Prepare bulk in transaction.
     260 *
     261 * @param[in] instance Batch structure to use.
     262 *
     263 * Data transaction with PID_IN.
    256264 */
    257265void batch_bulk_in(batch_t *instance)
     
    261269        instance->next_step = batch_call_in_and_dispose;
    262270        usb_log_debug("Batch(%p) BULK IN initialized.\n", instance);
    263         batch_schedule(instance);
    264 }
    265 /*----------------------------------------------------------------------------*/
    266 /** Prepares bulk out transaction.
    267  *
    268  * @param[in] instance Batch structure to use.
     271}
     272/*----------------------------------------------------------------------------*/
     273/** Prepare bulk out transaction.
     274 *
     275 * @param[in] instance Batch structure to use.
     276 *
     277 * Data transaction with PID_OUT.
    269278 */
    270279void batch_bulk_out(batch_t *instance)
    271280{
    272281        assert(instance);
     282        /* We are data out, we are supposed to provide data */
    273283        memcpy(instance->transport_buffer, instance->buffer, instance->buffer_size);
    274284        batch_data(instance, USB_PID_OUT);
    275285        instance->next_step = batch_call_out_and_dispose;
    276286        usb_log_debug("Batch(%p) BULK OUT initialized.\n", instance);
    277         batch_schedule(instance);
    278 }
    279 /*----------------------------------------------------------------------------*/
    280 /** Prepares generic data transaction
     287}
     288/*----------------------------------------------------------------------------*/
     289/** Prepare generic data transaction
    281290 *
    282291 * @param[in] instance Batch structure to use.
    283292 * @param[in] pid to use for data packets.
     293 *
     294 * Packets with alternating toggle bit and supplied pid value.
     295 * The last packet is marked with IOC flag.
    284296 */
    285297void batch_data(batch_t *instance, usb_packet_id pid)
     
    318330                ++packet;
    319331        }
     332        td_set_ioc(&instance->tds[packet - 1]);
    320333        device_keeper_set_toggle(instance->manager, instance->target, toggle);
    321334}
    322335/*----------------------------------------------------------------------------*/
    323 /** Prepares generic control transaction
     336/** Prepare generic control transaction
    324337 *
    325338 * @param[in] instance Batch structure to use.
    326339 * @param[in] data_stage to use for data packets.
    327340 * @param[in] status_stage to use for data packets.
     341 *
     342 * Setup stage with toggle 0 and USB_PID_SETUP.
     343 * Data stage with alternating toggle and pid supplied by parameter.
     344 * Status stage with toggle 1 and pid supplied by parameter.
     345 * The last packet is marked with IOC.
    328346 */
    329347void batch_control(batch_t *instance,
     
    369387            0, 1, false, low_speed, instance->target, status_stage, NULL, NULL);
    370388
    371 
    372         instance->tds[packet].status |= TD_STATUS_COMPLETE_INTERRUPT_FLAG;
     389        td_set_ioc(&instance->tds[packet]);
    373390        usb_log_debug2("Control last TD status: %x.\n",
    374391            instance->tds[packet].status);
    375392}
    376393/*----------------------------------------------------------------------------*/
    377 /** Prepares data, gets error status and calls callback in.
    378  *
    379  * @param[in] instance Batch structure to use.
     394/** Prepare data, get error status and call callback in.
     395 *
     396 * @param[in] instance Batch structure to use.
     397 * Copies data from transport buffer, and calls callback with appropriate
     398 * parameters.
    380399 */
    381400void batch_call_in(batch_t *instance)
     
    384403        assert(instance->callback_in);
    385404
    386         /* we are data in, we need data */
     405        /* We are data in, we need data */
    387406        memcpy(instance->buffer, instance->transport_buffer,
    388407            instance->buffer_size);
     
    397416}
    398417/*----------------------------------------------------------------------------*/
    399 /** Gets error status and calls callback out.
     418/** Get error status and call callback out.
    400419 *
    401420 * @param[in] instance Batch structure to use.
     
    413432}
    414433/*----------------------------------------------------------------------------*/
    415 /** Prepares data, gets error status, calls callback in and dispose.
     434/** Helper function calls callback and correctly disposes of batch structure.
    416435 *
    417436 * @param[in] instance Batch structure to use.
     
    424443}
    425444/*----------------------------------------------------------------------------*/
    426 /** Gets error status, calls callback out and dispose.
     445/** Helper function calls callback and correctly disposes of batch structure.
    427446 *
    428447 * @param[in] instance Batch structure to use.
     
    435454}
    436455/*----------------------------------------------------------------------------*/
    437 /** Correctly disposes all used data structures.
     456/** Correctly dispose all used data structures.
    438457 *
    439458 * @param[in] instance Batch structure to use.
     
    450469        free(instance);
    451470}
    452 /*----------------------------------------------------------------------------*/
    453 int batch_schedule(batch_t *instance)
    454 {
    455         assert(instance);
    456         uhci_t *hc = fun_to_uhci(instance->fun);
    457         assert(hc);
    458         return uhci_schedule(hc, instance);
    459 }
    460471/**
    461472 * @}
Note: See TracChangeset for help on using the changeset viewer.