source: mainline/uspace/drv/uhci-hcd/callback.c@ c56dbe0

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since c56dbe0 was c56dbe0, checked in by Jan Vesely <jano.vesely@…>, 14 years ago

Added license statement to all .c files

  • Property mode set to 100644
File size: 3.2 KB
Line 
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 */
28/** @addtogroup usb
29 * @{
30 */
31/** @file
32 * @brief UHCI driver
33 */
34#include <errno.h>
35#include <mem.h>
36
37#include <usb/debug.h>
38
39#include "callback.h"
40int callback_init(callback_t *instance, device_t *dev,
41 void *buffer, size_t size, usbhc_iface_transfer_in_callback_t func_in,
42 usbhc_iface_transfer_out_callback_t func_out, void *arg)
43{
44 assert(instance);
45 assert(func_in == NULL || func_out == NULL);
46 if (size > 0) {
47 instance->new_buffer = malloc32(size);
48 if (!instance->new_buffer) {
49 usb_log_error("Failed to allocate device acessible buffer.\n");
50 return ENOMEM;
51 }
52 if (func_out)
53 memcpy(instance->new_buffer, buffer, size);
54 } else {
55 instance->new_buffer = NULL;
56 }
57
58
59 instance->callback_out = func_out;
60 instance->callback_in = func_in;
61 instance->old_buffer = buffer;
62 instance->buffer_size = size;
63 instance->dev = dev;
64 instance->arg = arg;
65 return EOK;
66}
67/*----------------------------------------------------------------------------*/
68void callback_run(
69callback_t *instance, usb_transaction_outcome_t outcome, size_t act_size)
70{
71 assert(instance);
72
73 /* update the old buffer */
74 if (instance->new_buffer &&
75 (instance->new_buffer != instance->old_buffer)) {
76 memcpy(instance->old_buffer, instance->new_buffer, instance->buffer_size);
77 free32(instance->new_buffer);
78 instance->new_buffer = NULL;
79 }
80
81 if (instance->callback_in) {
82 assert(instance->callback_out == NULL);
83 usb_log_debug("Callback in: %p %x %d.\n",
84 instance->callback_in, outcome, act_size);
85 instance->callback_in(
86 instance->dev, outcome, act_size, instance->arg);
87 } else {
88 assert(instance->callback_out);
89 assert(instance->callback_in == NULL);
90 usb_log_debug("Callback out: %p %p %x %p .\n",
91 instance->callback_out, instance->dev, outcome, instance->arg);
92 instance->callback_out(
93 instance->dev, outcome, instance->arg);
94 }
95}
96/**
97 * @}
98 */
Note: See TracBrowser for help on using the repository browser.