Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/ohci/batch.c

    rd328172 r81dce9f  
    3939
    4040#include "batch.h"
    41 #include "utils/malloc32.h"
    42 
    43 static void batch_call_in_and_dispose(batch_t *instance);
    44 static void batch_call_out_and_dispose(batch_t *instance);
    4541
    4642#define DEFAULT_ERROR_COUNT 3
    47 batch_t * batch_get(
    48     ddf_fun_t *fun,
    49                 usb_target_t target,
    50     usb_transfer_type_t transfer_type,
    51                 size_t max_packet_size,
    52     usb_speed_t speed,
    53                 char *buffer,
    54                 size_t buffer_size,
    55                 char *setup_buffer,
    56                 size_t setup_size,
    57     usbhc_iface_transfer_in_callback_t func_in,
    58     usbhc_iface_transfer_out_callback_t func_out,
    59                 void *arg,
    60                 device_keeper_t *manager
    61                 )
    62 {
    63 #define CHECK_NULL_DISPOSE_RETURN(ptr, message...) \
    64         if (ptr == NULL) { \
    65                 usb_log_error(message); \
    66                 if (instance) { \
    67                         batch_dispose(instance); \
    68                 } \
    69                 return NULL; \
    70         } else (void)0
    7143
    72         batch_t *instance = malloc(sizeof(batch_t));
    73         CHECK_NULL_DISPOSE_RETURN(instance,
    74             "Failed to allocate batch instance.\n");
    75         batch_init(instance, target, transfer_type, speed, max_packet_size,
    76             buffer, NULL, buffer_size, NULL, setup_size, func_in,
    77             func_out, arg, fun, NULL);
    78 
    79         if (buffer_size > 0) {
    80                 instance->transport_buffer = malloc32(buffer_size);
    81                 CHECK_NULL_DISPOSE_RETURN(instance->transport_buffer,
    82                     "Failed to allocate device accessible buffer.\n");
    83         }
    84 
    85         if (setup_size > 0) {
    86                 instance->setup_buffer = malloc32(setup_size);
    87                 CHECK_NULL_DISPOSE_RETURN(instance->setup_buffer,
    88                     "Failed to allocate device accessible setup buffer.\n");
    89                 memcpy(instance->setup_buffer, setup_buffer, setup_size);
    90         }
    91 
    92 
    93         return instance;
    94 }
    95 /*----------------------------------------------------------------------------*/
    96 void batch_dispose(batch_t *instance)
    97 {
    98         assert(instance);
    99         free32(instance->transport_buffer);
    100         free32(instance->setup_buffer);
    101         free(instance);
    102 }
    103 /*----------------------------------------------------------------------------*/
    104 void batch_control_write(batch_t *instance)
    105 {
    106         assert(instance);
    107         /* We are data out, we are supposed to provide data */
    108         memcpy(instance->transport_buffer, instance->buffer,
    109             instance->buffer_size);
    110         instance->next_step = batch_call_out_and_dispose;
    111         /* TODO: implement */
    112         usb_log_debug("Batch(%p) CONTROL WRITE initialized.\n", instance);
    113 }
    114 /*----------------------------------------------------------------------------*/
    115 void batch_control_read(batch_t *instance)
    116 {
    117         assert(instance);
    118         instance->next_step = batch_call_in_and_dispose;
    119         /* TODO: implement */
    120         usb_log_debug("Batch(%p) CONTROL WRITE initialized.\n", instance);
    121 }
    122 /*----------------------------------------------------------------------------*/
    123 void batch_interrupt_in(batch_t *instance)
    124 {
    125         assert(instance);
    126         instance->direction = USB_DIRECTION_IN;
    127         instance->next_step = batch_call_in_and_dispose;
    128         /* TODO: implement */
    129         usb_log_debug("Batch(%p) INTERRUPT IN initialized.\n", instance);
    130 }
    131 /*----------------------------------------------------------------------------*/
    132 void batch_interrupt_out(batch_t *instance)
    133 {
    134         assert(instance);
    135         instance->direction = USB_DIRECTION_OUT;
    136         /* We are data out, we are supposed to provide data */
    137         memcpy(instance->transport_buffer, instance->buffer,
    138             instance->buffer_size);
    139         instance->next_step = batch_call_out_and_dispose;
    140         /* TODO: implement */
    141         usb_log_debug("Batch(%p) INTERRUPT OUT initialized.\n", instance);
    142 }
    143 /*----------------------------------------------------------------------------*/
    144 void batch_bulk_in(batch_t *instance)
    145 {
    146         assert(instance);
    147         instance->direction = USB_DIRECTION_IN;
    148         instance->next_step = batch_call_in_and_dispose;
    149         /* TODO: implement */
    150         usb_log_debug("Batch(%p) BULK IN initialized.\n", instance);
    151 }
    152 /*----------------------------------------------------------------------------*/
    153 void batch_bulk_out(batch_t *instance)
    154 {
    155         assert(instance);
    156         instance->direction = USB_DIRECTION_IN;
    157         instance->next_step = batch_call_in_and_dispose;
    158         /* TODO: implement */
    159         usb_log_debug("Batch(%p) BULK IN initialized.\n", instance);
    160 }
    161 /*----------------------------------------------------------------------------*/
    162 /** Helper function calls callback and correctly disposes of batch structure.
    163  *
    164  * @param[in] instance Batch structure to use.
    165  */
    166 void batch_call_in_and_dispose(batch_t *instance)
    167 {
    168         assert(instance);
    169         batch_call_in(instance);
    170         batch_dispose(instance);
    171 }
    172 /*----------------------------------------------------------------------------*/
    173 /** Helper function calls callback and correctly disposes of batch structure.
    174  *
    175  * @param[in] instance Batch structure to use.
    176  */
    177 void batch_call_out_and_dispose(batch_t *instance)
    178 {
    179         assert(instance);
    180         batch_call_out(instance);
    181         batch_dispose(instance);
    182 }
    18344/**
    18445 * @}
Note: See TracChangeset for help on using the changeset viewer.