source: mainline/uspace/drv/uhci/callback.c@ d956aa5

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

Fixed: memcpy direction

  • Property mode set to 100644
File size: 1.7 KB
Line 
1#include <errno.h>
2#include <mem.h>
3
4#include "callback.h"
5int callback_init(callback_t *instance, device_t *dev,
6 void *buffer, size_t size, usbhc_iface_transfer_in_callback_t func_in,
7 usbhc_iface_transfer_out_callback_t func_out, void *arg)
8{
9 assert(instance);
10 assert(func_in == NULL || func_out == NULL);
11 if (size > 0) {
12 instance->new_buffer = malloc32(size);
13 if (!instance->new_buffer) {
14 uhci_print_error("Failed to allocate device acessible buffer.\n");
15 return ENOMEM;
16 }
17 if (func_out)
18 memcpy(instance->new_buffer, buffer, size);
19 } else {
20 instance->new_buffer = NULL;
21 }
22
23
24 instance->callback_out = func_out;
25 instance->callback_in = func_in;
26 instance->old_buffer = buffer;
27 instance->buffer_size = size;
28 instance->dev = dev;
29 instance->arg = arg;
30 return EOK;
31}
32/*----------------------------------------------------------------------------*/
33void callback_run(
34callback_t *instance, usb_transaction_outcome_t outcome, size_t act_size)
35{
36 assert(instance);
37
38 /* update the old buffer */
39 if (instance->new_buffer &&
40 (instance->new_buffer != instance->old_buffer)) {
41 memcpy(instance->old_buffer, instance->new_buffer, instance->buffer_size);
42 free32(instance->new_buffer);
43 instance->new_buffer = NULL;
44 }
45
46 if (instance->callback_in) {
47 assert(instance->callback_out == NULL);
48 uhci_print_verbose("Callback in: %p %x %d.\n",
49 instance->callback_in, outcome, act_size);
50 instance->callback_in(
51 instance->dev, act_size, outcome, instance->arg);
52 } else {
53 assert(instance->callback_out);
54 assert(instance->callback_in == NULL);
55 uhci_print_verbose("Callback out: %p %p %x %p .\n",
56 instance->callback_out, instance->dev, outcome, instance->arg);
57 instance->callback_out(
58 instance->dev, outcome, instance->arg);
59 }
60}
Note: See TracBrowser for help on using the repository browser.