Просмотр исходного кода

Keep list of pipes to be deleted when device disconnects

main
PaulStoffregen 8 лет назад
Родитель
Сommit
b4905f40ef
3 измененных файлов: 40 добавлений и 7 удалений
  1. +8
    -2
      USBHost.h
  2. +25
    -0
      ehci.cpp
  3. +7
    -5
      enumeration.cpp

+ 8
- 2
USBHost.h Просмотреть файл

// Device_t holds all the information about a USB device // Device_t holds all the information about a USB device
struct Device_struct { struct Device_struct {
Pipe_t *control_pipe; Pipe_t *control_pipe;
Pipe_t *data_pipes;
Device_t *next; Device_t *next;
USBDriver *drivers; USBDriver *drivers;
uint8_t speed; // 0=12, 1=1.5, 2=480 Mbit/sec uint8_t speed; // 0=12, 1=1.5, 2=480 Mbit/sec
uint8_t type; // 0=control, 1=isochronous, 2=bulk, 3=interrupt uint8_t type; // 0=control, 1=isochronous, 2=bulk, 3=interrupt
uint8_t direction; // 0=out, 1=in (changes for control, others fixed) uint8_t direction; // 0=out, 1=in (changes for control, others fixed)
uint8_t unusedbyte[2]; uint8_t unusedbyte[2];
USBDriver *callback_object;
Pipe_t *next;
void (*callback_function)(const Transfer_t *); void (*callback_function)(const Transfer_t *);
}; };


static bool queue_Transfer(Pipe_t *pipe, Transfer_t *transfer); static bool queue_Transfer(Pipe_t *pipe, Transfer_t *transfer);
static void init_Device_Pipe_Transfer_memory(void); static void init_Device_Pipe_Transfer_memory(void);
static Device_t * allocate_Device(void); static Device_t * allocate_Device(void);
static void delete_Pipe(Pipe_t *pipe);
static void free_Device(Device_t *q); static void free_Device(Device_t *q);
static Pipe_t * allocate_Pipe(void); static Pipe_t * allocate_Pipe(void);
static void free_Pipe(Pipe_t *q); static void free_Pipe(Pipe_t *q);
virtual void control(const Transfer_t *transfer) { } virtual void control(const Transfer_t *transfer) { }


// When a device disconnects from the USB, this function is called. // When a device disconnects from the USB, this function is called.
// The driver must free all resources it has allocated.
// The driver must free all resources it allocated and update any
// internal state necessary to deal with the possibility of user
// code continuing to call its API. However, pipes and transfers
// are the handled by lower layers, so device drivers do not free
// pipes they created or cancel transfers they had in progress.
virtual void disconnect(); virtual void disconnect();


// Drivers are managed by this single-linked list. All inactive // Drivers are managed by this single-linked list. All inactive

+ 25
- 0
ehci.cpp Просмотреть файл

} }
} }
memset(pipe, 0, sizeof(Pipe_t)); memset(pipe, 0, sizeof(Pipe_t));
if (endpoint > 0) {
// if non-control pipe, update dev->data_pipes list
Pipe_t *p = dev->data_pipes;
if (p == NULL) {
dev->data_pipes = pipe;
} else {
while (p->next) p = p->next;
p->next = pipe;
}
}
memset(halt, 0, sizeof(Transfer_t)); memset(halt, 0, sizeof(Transfer_t));
halt->qtd.next = 1; halt->qtd.next = 1;
halt->qtd.token = 0x40; halt->qtd.token = 0x40;
return true; return true;
} }



void USBHost::delete_Pipe(Pipe_t *pipe)
{
// TODO: a *LOT* of work here.....
println("delete_Pipe ", (uint32_t)pipe, HEX);

// halt pipe, find and free all Transfer_t

// remove periodic scheduled pipes

// remove async scheduled pipes

// can't free the pipe until the ECHI and all qTD referencing are done
// free_Pipe(pipe);
}

+ 7
- 5
enumeration.cpp Просмотреть файл

} }
print_driverlist("available_drivers", available_drivers); print_driverlist("available_drivers", available_drivers);


// TODO: halt all pipes, free their Transfer_t

// TODO: remove periodic scheduled pipes, free their Pipe_t

// TODO: remove async scheduled pipes, free their Pipe_t
// delete all the pipes
for (Pipe_t *p = dev->data_pipes; p; ) {
Pipe_t *next = p->next;
delete_Pipe(p);
p = next;
}
delete_Pipe(dev->control_pipe);


// remove device from devlist and free its Device_t // remove device from devlist and free its Device_t
Device_t *prev_dev = NULL; Device_t *prev_dev = NULL;

Загрузка…
Отмена
Сохранить