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

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

Used usbmem allocator

  • Property mode set to 100644
File size: 1.2 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 return EOK;
26}
27/*----------------------------------------------------------------------------*/
28void callback_run(
29callback_t *instance, usb_transaction_outcome_t outcome, size_t act_size)
30{
31 assert(instance);
32
33 /* update the old buffer */
34 if (instance->new_buffer) {
35 memcpy(instance->new_buffer, instance->old_buffer, instance->buffer_size);
36 free32(instance->new_buffer);
37 instance->new_buffer = NULL;
38 }
39
40 if (instance->callback_in) {
41 assert(instance->callback_out == NULL);
42 instance->callback_in(
43 instance->dev, act_size, outcome, instance->arg);
44 }
45}
Note: See TracBrowser for help on using the repository browser.