source: mainline/uspace/lib/usbhost/src/usb_transfer_batch.c@ 1814b4ae

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 1814b4ae was d42ba37, checked in by Ondřej Hlavatý <aearsis@…>, 8 years ago

usbhost: usb transfer batch shall be zero-initialized

  • Property mode set to 100644
File size: 4.1 KB
RevLine 
[81dce9f]1/*
2 * Copyright (c) 2011 Jan Vesely
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
[160b75e]28/** @addtogroup libusbhost
[81dce9f]29 * @{
30 */
31/** @file
[c92c13f]32 * USB transfer transaction structures (implementation).
[81dce9f]33 */
34
[8d2e251]35#include <assert.h>
36#include <errno.h>
[64fea02]37#include <stdlib.h>
[2b61945]38#include <str_error.h>
[64fea02]39#include <usb/debug.h>
40
41#include "endpoint.h"
42#include "bus.h"
[5fd9c30]43
[64fea02]44#include "usb_transfer_batch.h"
[5fd9c30]45
46/** Create a batch on given endpoint.
[549ff23]47 */
[5fd9c30]48usb_transfer_batch_t *usb_transfer_batch_create(endpoint_t *ep)
[81dce9f]49{
[5fd9c30]50 assert(ep);
51 assert(ep->bus);
52
53 usb_transfer_batch_t *batch;
54 if (ep->bus->ops.create_batch)
55 batch = ep->bus->ops.create_batch(ep->bus, ep);
56 else
[d42ba37]57 batch = calloc(1, sizeof(usb_transfer_batch_t));
[5fd9c30]58
59 return batch;
[2cc6e97]60}
[a76b01b4]61
[5fd9c30]62/** Initialize given batch structure.
63 */
64void usb_transfer_batch_init(usb_transfer_batch_t *batch, endpoint_t *ep)
65{
66 batch->ep = ep;
67}
68
[17873ac7]69/** Resolve resetting toggle.
[2cc6e97]70 *
[5fd9c30]71 * @param[in] batch Batch structure to use.
[2cc6e97]72 */
[17873ac7]73int usb_transfer_batch_reset_toggle(usb_transfer_batch_t *batch)
[2cc6e97]74{
[5fd9c30]75 assert(batch);
76
[17873ac7]77 if (batch->error != EOK || batch->toggle_reset_mode == RESET_NONE)
78 return EOK;
[5fd9c30]79
[17873ac7]80 usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT " resets %s",
81 batch, USB_TRANSFER_BATCH_ARGS(*batch),
82 batch->toggle_reset_mode == RESET_ALL ? "all EPs toggle" : "EP toggle");
[5fd9c30]83
[17873ac7]84 return bus_reset_toggle(batch->ep->bus, batch->target, batch->toggle_reset_mode);
[2cc6e97]85}
[a76b01b4]86
[5fd9c30]87/** Destroy the batch.
[549ff23]88 *
[5fd9c30]89 * @param[in] batch Batch structure to use.
[549ff23]90 */
[5fd9c30]91void usb_transfer_batch_destroy(usb_transfer_batch_t *batch)
[549ff23]92{
[5fd9c30]93 assert(batch);
94 assert(batch->ep);
95 assert(batch->ep->bus);
[549ff23]96
[5fd9c30]97 bus_t *bus = batch->ep->bus;
[2b61945]98 if (bus->ops.destroy_batch) {
99 usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT " destroying.\n",
100 batch, USB_TRANSFER_BATCH_ARGS(*batch));
[5fd9c30]101 bus->ops.destroy_batch(batch);
[2b61945]102 }
103 else {
104 usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT " disposing.\n",
105 batch, USB_TRANSFER_BATCH_ARGS(*batch));
[5fd9c30]106 free(batch);
[2b61945]107 }
[5fd9c30]108}
109
110/** Finish a transfer batch: call handler, destroy batch, release endpoint.
111 *
112 * Call only after the batch have been scheduled && completed!
113 *
114 * @param[in] batch Batch structure to use.
115 */
116void usb_transfer_batch_finish(usb_transfer_batch_t *batch)
117{
[17873ac7]118 assert(batch);
119 assert(batch->ep);
120
121 usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT " finishing.\n",
122 batch, USB_TRANSFER_BATCH_ARGS(*batch));
123
124 if (batch->on_complete) {
[f9d0a86]125 const int err = batch->on_complete(batch->on_complete_data, batch->error, batch->transfered_size);
[17873ac7]126 if (err)
127 usb_log_warning("batch %p failed to complete: %s",
128 batch, str_error(err));
129 }
[5fd9c30]130
131 usb_transfer_batch_destroy(batch);
132}
133
[17873ac7]134/** Finish a transfer batch as an aborted one.
135 *
136 * @param[in] batch Batch structure to use.
137 */
138void usb_transfer_batch_abort(usb_transfer_batch_t *batch)
139{
140 assert(batch);
141 assert(batch->ep);
142
143 batch->error = EAGAIN;
144 usb_transfer_batch_finish(batch);
145}
146
[81dce9f]147/**
148 * @}
149 */
Note: See TracBrowser for help on using the repository browser.