Changeset 643b983 in mainline for uspace/drv/uhci/callback.h


Ignore:
Timestamp:
2011-01-21T18:14:01Z (14 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
bae9e76
Parents:
9600516
Message:

Init callback structure and TD for usb in transfers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci/callback.h

    r9600516 r643b983  
    3535#define DRV_UHCI_CALLBACK_H
    3636
     37#include <mem.h>
    3738#include <usbhc_iface.h>
     39
     40#include "debug.h"
     41#include "translating_malloc.h"
    3842
    3943typedef struct callback
    4044{
    41         union {
    42                 usbhc_iface_transfer_in_callback_t callback_in;
    43                 usbhc_iface_transfer_out_callback_t callback_out;
    44         };
    45         void* buffer;
     45        usbhc_iface_transfer_in_callback_t callback_in;
     46        usbhc_iface_transfer_out_callback_t callback_out;
     47        void *old_buffer;
     48        void *new_buffer;
     49        void *arg;
     50        size_t buffer_size;
     51        device_t *dev;
    4652} callback_t;
    4753
     54
     55static inline int callback_init(callback_t *instance, device_t *dev,
     56  void *buffer, size_t size, usbhc_iface_transfer_in_callback_t func_in,
     57  usbhc_iface_transfer_out_callback_t func_out, void *arg)
     58{
     59        assert(instance);
     60        assert(func_in == NULL || func_out == NULL);
     61        instance->new_buffer = trans_malloc(size);
     62        if (!instance->new_buffer) {
     63                uhci_print_error("Failed to allocate device acessible buffer.\n");
     64                return ENOMEM;
     65        }
     66
     67        if (func_out)
     68                memcpy(instance->new_buffer, buffer, size);
     69
     70        instance->callback_out = func_out;
     71        instance->callback_in = func_in;
     72        instance->old_buffer = buffer;
     73        instance->buffer_size = size;
     74        instance->dev = dev;
     75        return EOK;
     76}
     77#define callback_in_init(instance, dev, buffer, size, func, arg) \
     78        callback_init(instance, dev, buffer, size, func, NULL, arg)
     79
     80#define callback_out_init(instance, dev, buffer, size, func, arg) \
     81        callback_init(instance, dev, buffer, size, func, NULL, arg)
     82
     83static inline void callback_fini(callback_t *instance)
     84{
     85        assert(instance);
     86        if (instance->new_buffer)
     87                trans_free(instance->new_buffer);
     88}
    4889#endif
    4990/**
Note: See TracChangeset for help on using the changeset viewer.