source: mainline/uspace/drv/uhci/callback.c@ 0b68b7c

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

Fixed: initialize arg field properly

Added callback_out call

  • Property mode set to 100644
File size: 1.6 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 instance->new_buffer = malloc32(size);
12 if (!instance->new_buffer) {
13 uhci_print_error("Failed to allocate device acessible buffer.\n");
14 return ENOMEM;
15 }
16
17 if (func_out)
18 memcpy(instance->new_buffer, buffer, size);
19
20 instance->callback_out = func_out;
21 instance->callback_in = func_in;
22 instance->old_buffer = buffer;
23 instance->buffer_size = size;
24 instance->dev = dev;
25 instance->arg = arg;
26 return EOK;
27}
28/*----------------------------------------------------------------------------*/
29void callback_run(
30callback_t *instance, usb_transaction_outcome_t outcome, size_t act_size)
31{
32 assert(instance);
33
34 /* update the old buffer */
35 if (instance->new_buffer) {
36 memcpy(instance->new_buffer, instance->old_buffer, instance->buffer_size);
37 free32(instance->new_buffer);
38 instance->new_buffer = NULL;
39 }
40
41 if (instance->callback_in) {
42 assert(instance->callback_out == NULL);
43 uhci_print_verbose("Callback in: %p %x %d.\n",
44 instance->callback_in, outcome, act_size);
45 instance->callback_in(
46 instance->dev, act_size, outcome, instance->arg);
47 } else {
48 assert(instance->callback_out);
49 assert(instance->callback_in == NULL);
50 uhci_print_verbose("Callback out: %p %p %x %p .\n",
51 instance->callback_out, instance->dev, outcome, instance->arg);
52 instance->callback_out(
53 instance->dev, outcome, instance->arg);
54 }
55}
Note: See TracBrowser for help on using the repository browser.