Changeset 89a0485a in mainline


Ignore:
Timestamp:
2011-01-25T20:44:28Z (14 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b00163f
Parents:
7977fa1
Message:

Move function implementations to .c files

Unify error reporting in uhci_in()

Location:
uspace/drv/uhci
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci/Makefile

    r7977fa1 r89a0485a  
    3333
    3434SOURCES = \
     35        callback.c \
    3536        iface.c \
    3637        main.c \
     
    3839        root_hub/port_status.c \
    3940        root_hub/root_hub.c \
     41        transfer_list.c \
    4042        uhci.c
    4143
  • uspace/drv/uhci/callback.h

    r7977fa1 r89a0485a  
    5353
    5454
    55 static inline int callback_init(callback_t *instance, device_t *dev,
     55int callback_init(callback_t *instance, device_t *dev,
    5656  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         }
     57  usbhc_iface_transfer_out_callback_t func_out, void *arg);
    6658
    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 }
    7759#define callback_in_init(instance, dev, buffer, size, func, arg) \
    7860        callback_init(instance, dev, buffer, size, func, NULL, arg)
  • uspace/drv/uhci/transfer_list.h

    r7977fa1 r89a0485a  
    4848} transfer_list_t;
    4949
    50 static inline int transfer_list_init(
    51   transfer_list_t *instance, transfer_list_t *next)
    52 {
    53         assert(instance);
    54         instance->first = NULL;
    55         instance->last = NULL;
    56         instance->queue_head = trans_malloc(sizeof(queue_head_t));
    57         if (!instance->queue_head) {
    58                 uhci_print_error("Failed to allocate queue head.\n");
    59                 return ENOMEM;
    60         }
    61         instance->queue_head_pa = (uintptr_t)addr_to_phys(instance->queue_head);
    62 
    63         uint32_t next_pa = next ? next->queue_head_pa : 0;
    64         queue_head_init(instance->queue_head, next_pa);
    65         return EOK;
    66 }
     50int transfer_list_init(transfer_list_t *instance, transfer_list_t *next);
    6751
    6852static inline void transfer_list_fini(transfer_list_t *instance)
     
    7357}
    7458
     59int transfer_list_append(
     60  transfer_list_t *instance, transfer_descriptor_t *transfer);
     61
    7562#endif
    7663/**
  • uspace/drv/uhci/uhci.c

    r7977fa1 r89a0485a  
    2222        if (!instance)
    2323                { return ENOMEM; }
    24         memset( instance, 0, sizeof(uhci_t) );
     24        bzero( instance, sizeof(uhci_t) );
    2525
    2626        /* init address keeper(libusb) */
     
    8686                return ENOTSUP;
    8787
    88         callback_t *job = malloc(sizeof(callback_t));
    89         if (job == NULL) {
    90                 uhci_print_error("Failed to allocate callback structure.\n");
    91                 return ENOMEM;
    92         }
     88        transfer_descriptor_t *td = NULL;
     89        callback_t *job = NULL;
     90        int ret = EOK;
    9391
    94 #define CHECK_RET_FREE_JOB(r, message) \
    95         if (r != EOK) { \
     92#define CHECK_RET_TRANS_FREE_JOB_TD(message) \
     93        if (ret != EOK) { \
    9694                uhci_print_error(message); \
    97                 callback_fini(job); \
    98                 trans_free(job); \
    99                 return r; \
     95                if (job) { \
     96                        callback_fini(job); \
     97                        trans_free(job); \
     98                } \
     99                if (td) { trans_free(td); } \
     100                return ret; \
    100101        } else (void) 0
    101102
    102         int ret = callback_in_init(job, dev, buffer, size, callback, arg);
    103         CHECK_RET_FREE_JOB(ret, "Failed to initialize callback structure.\n");
    104103
    105         transfer_descriptor_t *td = trans_malloc(sizeof(transfer_descriptor_t));
    106         ret = (td == NULL) ? ENOMEM : EOK;
    107         CHECK_RET_FREE_JOB(ret, "Failed to allocate tranfer descriptor.\n");
     104        job = malloc(sizeof(callback_t));
     105        ret= job ? EOK : ENOMEM;
     106        CHECK_RET_TRANS_FREE_JOB_TD("Failed to allocate callback structure.\n");
     107
     108        ret = callback_in_init(job, dev, buffer, size, callback, arg);
     109        CHECK_RET_TRANS_FREE_JOB_TD("Failed to initialize callback structure.\n");
     110
     111        td = trans_malloc(sizeof(transfer_descriptor_t));
     112        ret = td ? ENOMEM : EOK;
     113        CHECK_RET_TRANS_FREE_JOB_TD("Failed to allocate tranfer descriptor.\n");
    108114
    109115        ret = transfer_descriptor_init(td, 3, size, false, target, USB_PID_IN);
    110         if (ret != EOK) {
    111                 uhci_print_error("Failed to initialize transfer descriptor.\n");
    112                 trans_free(td);
    113                 trans_free(job);
    114                 return ret;
    115         }
     116        CHECK_RET_TRANS_FREE_JOB_TD("Failed to initialize transfer descriptor.\n");
     117
    116118        td->callback = job;
    117119
     120        assert(dev);
     121        uhci_t *instance = (uhci_t*)dev->driver_data;
     122        assert(instance);
    118123
    119         // TODO: add to list
    120 //      callback(dev, USB_OUTCOME_OK, size, arg);
     124        ret = transfer_list_append(&instance->transfers[transfer_type], td);
     125        CHECK_RET_TRANS_FREE_JOB_TD("Failed to append transfer descriptor.\n");
    121126
    122127        return EOK;
Note: See TracChangeset for help on using the changeset viewer.