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

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

Added callback_run

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