forked from len0rd/rockbox
Cosmetic changes only - tab, whitespace and brace policing
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14484 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
a6d52a8305
commit
03745f4ed3
13 changed files with 558 additions and 555 deletions
|
@ -39,26 +39,26 @@ static void bind_device_driver(struct usb_device_driver* driver);
|
|||
/**
|
||||
* Initialize usb stack.
|
||||
*/
|
||||
void usb_stack_init(void) {
|
||||
void usb_stack_init(void)
|
||||
{
|
||||
int i;
|
||||
logf("usb_stack_init");
|
||||
|
||||
int i;
|
||||
logf("usb_stack_init");
|
||||
|
||||
/* init datastructures */
|
||||
usbcore.controller[0] = NULL;
|
||||
usbcore.controller[1] = NULL;
|
||||
usbcore.active_controller = NULL;
|
||||
usbcore.device_driver = NULL;
|
||||
usbcore.running = false;
|
||||
|
||||
|
||||
memset(&device_driver_names, 0, USB_STACK_MAX_SETTINGS_NAME);
|
||||
|
||||
|
||||
/* init arrays */
|
||||
for (i = 0; i < NUM_DRIVERS; i++) {
|
||||
usbcore.device_drivers[i] = NULL;
|
||||
usbcore.host_drivers[i] = NULL;
|
||||
usbcore.device_drivers[i] = NULL;
|
||||
usbcore.host_drivers[i] = NULL;
|
||||
}
|
||||
|
||||
|
||||
/* init controllers */
|
||||
#if (USBSTACK_CAPS & CONTROLLER_DEVICE)
|
||||
usb_dcd_init();
|
||||
|
@ -77,31 +77,31 @@ void usb_stack_init(void) {
|
|||
* Start processing of usb stack. This function init
|
||||
* active usb controller.
|
||||
*/
|
||||
void usb_stack_start(void) {
|
||||
void usb_stack_start(void)
|
||||
{
|
||||
/* are we allready running? */
|
||||
if (usbcore.running) {
|
||||
logf("allready running!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (usbcore.active_controller == NULL) {
|
||||
logf("no active controller!");
|
||||
return;
|
||||
}
|
||||
|
||||
/* are we allready running? */
|
||||
if (usbcore.running) {
|
||||
logf("allready running!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (usbcore.active_controller == NULL) {
|
||||
logf("no active controller!");
|
||||
return;
|
||||
}
|
||||
|
||||
/* forward to controller */
|
||||
logf("starting controller");
|
||||
logf("starting controller");
|
||||
usbcore.active_controller->start();
|
||||
usbcore.running = true;
|
||||
|
||||
|
||||
/* look if started controller is a device controller
|
||||
* and if it has a device driver bind to it */
|
||||
logf("check for auto bind");
|
||||
if (usbcore.active_controller->type == DEVICE) {
|
||||
if (usbcore.active_controller->device_driver == NULL && usbcore.device_driver != NULL) {
|
||||
/* bind driver */
|
||||
logf("binding...");
|
||||
logf("binding...");
|
||||
bind_device_driver(usbcore.device_driver);
|
||||
}
|
||||
}
|
||||
|
@ -111,15 +111,15 @@ void usb_stack_start(void) {
|
|||
* Stop processing of usb stack. This function shutsdown
|
||||
* active usb controller.
|
||||
*/
|
||||
void usb_stack_stop(void) {
|
||||
void usb_stack_stop(void)
|
||||
{
|
||||
/* are we allready stopped? */
|
||||
if (usbcore.running == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* are we allready stopped? */
|
||||
if (usbcore.running == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* forward to controller */
|
||||
usbcore.active_controller->stop();
|
||||
usbcore.active_controller->stop();
|
||||
usbcore.running = false;
|
||||
}
|
||||
|
||||
|
@ -127,8 +127,8 @@ void usb_stack_stop(void) {
|
|||
* Gets called by upper layers to indicate that there is
|
||||
* an interrupt waiting for the controller.
|
||||
*/
|
||||
void usb_stack_irq(void) {
|
||||
|
||||
void usb_stack_irq(void)
|
||||
{
|
||||
/* simply notify usb controller */
|
||||
if (usbcore.active_controller != NULL && usbcore.active_controller->irq != NULL) {
|
||||
usbcore.active_controller->irq();
|
||||
|
@ -140,7 +140,8 @@ void usb_stack_irq(void) {
|
|||
* to call for maintanence. We need to check if a new device has connected,
|
||||
* find suitable drivers for new devices.
|
||||
*/
|
||||
void usb_stack_work(void) {
|
||||
void usb_stack_work(void)
|
||||
{
|
||||
/* TODO will be used with host device controllers
|
||||
* and needs to be called in a loop (thread) */
|
||||
}
|
||||
|
@ -153,8 +154,8 @@ void usb_stack_work(void) {
|
|||
* @param ctrl pointer to controller to register.
|
||||
* @return 0 on success else a defined error code.
|
||||
*/
|
||||
int usb_controller_register(struct usb_controller* ctrl) {
|
||||
|
||||
int usb_controller_register(struct usb_controller* ctrl)
|
||||
{
|
||||
if (ctrl == NULL) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
@ -220,21 +221,21 @@ int usb_controller_unregister(struct usb_controller* ctrl) {
|
|||
*
|
||||
* @param type of controller to activate.
|
||||
*/
|
||||
void usb_controller_select(int type) {
|
||||
|
||||
void usb_controller_select(int type)
|
||||
{
|
||||
struct usb_controller* new = NULL;
|
||||
|
||||
/* check if a controller of the wanted type is already loaded */
|
||||
if (usbcore.active_controller != NULL && (int)usbcore.active_controller->type == type) {
|
||||
logf("controller already set");
|
||||
return;
|
||||
logf("controller already set");
|
||||
return;
|
||||
}
|
||||
|
||||
logf("usb_controller_select");
|
||||
logf(" -> type: %d", type);
|
||||
logf("usb_controller_select");
|
||||
logf(" -> type: %d", type);
|
||||
|
||||
usbcore.mode = type;
|
||||
|
||||
usbcore.mode = type;
|
||||
|
||||
switch (type) {
|
||||
case DEVICE:
|
||||
new = usbcore.controller[0];
|
||||
|
@ -246,20 +247,20 @@ void usb_controller_select(int type) {
|
|||
|
||||
/* if there is only one controller, stop here */
|
||||
if (new == NULL) {
|
||||
logf("no suitable cntrl found");
|
||||
logf("no suitable cntrl found");
|
||||
return;
|
||||
}
|
||||
|
||||
/* shutdown current used controller */
|
||||
if (usbcore.active_controller != NULL) {
|
||||
logf("shuting down old one");
|
||||
logf("shuting down old one");
|
||||
usbcore.active_controller->shutdown();
|
||||
}
|
||||
|
||||
/* set and init new controller */
|
||||
usbcore.active_controller = new;
|
||||
logf("init controller");
|
||||
usbcore.active_controller->init();
|
||||
usbcore.active_controller->init();
|
||||
}
|
||||
|
||||
int usb_stack_get_mode(void) {
|
||||
|
@ -272,10 +273,10 @@ int usb_stack_get_mode(void) {
|
|||
* @param driver pointer to an usb_device_driver struct.
|
||||
* @return 0 on success, else a defined error code.
|
||||
*/
|
||||
int usb_device_driver_register(struct usb_device_driver* driver) {
|
||||
|
||||
int usb_device_driver_register(struct usb_device_driver* driver)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
||||
if (driver == NULL) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
@ -284,109 +285,109 @@ int usb_device_driver_register(struct usb_device_driver* driver) {
|
|||
logf("usb_stack: register usb driver");
|
||||
for (i = 0; i < NUM_DRIVERS; i++) {
|
||||
if (usbcore.device_drivers[i] == NULL) {
|
||||
usbcore.device_drivers[i] = driver;
|
||||
update_driver_names(device_driver_names);
|
||||
return 0;
|
||||
usbcore.device_drivers[i] = driver;
|
||||
update_driver_names(device_driver_names);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
update_driver_names(device_driver_names);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usb_device_driver_bind(const char* name) {
|
||||
|
||||
int i;
|
||||
struct usb_device_driver *tmp = NULL;
|
||||
struct usb_device_driver *driver = NULL;
|
||||
|
||||
int i;
|
||||
struct usb_device_driver *tmp = NULL;
|
||||
struct usb_device_driver *driver = NULL;
|
||||
|
||||
if (name == NULL) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
|
||||
/* look for driver */
|
||||
logf("looking for driver %s", name);
|
||||
for (i = 0; i < NUM_DRIVERS; i++) {
|
||||
tmp = usbcore.device_drivers[i];
|
||||
if (tmp != NULL && strcmp(name, tmp->name) == 0) {
|
||||
driver = tmp;
|
||||
}
|
||||
tmp = usbcore.device_drivers[i];
|
||||
if (tmp != NULL && strcmp(name, tmp->name) == 0) {
|
||||
driver = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
if (driver == NULL) {
|
||||
logf("no driver found");
|
||||
return ENODRIVERFOUND;
|
||||
logf("no driver found");
|
||||
return ENODRIVERFOUND;
|
||||
}
|
||||
|
||||
/* look if there is an usb controller loaded */
|
||||
|
||||
/* look if there is an usb controller loaded */
|
||||
if (usbcore.active_controller == NULL) {
|
||||
/* safe choosen driver and set it when controller starts */
|
||||
usbcore.device_driver = driver;
|
||||
|
||||
/* safe choosen driver and set it when controller starts */
|
||||
usbcore.device_driver = driver;
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
/* we need to have an active dcd controller */
|
||||
if (usbcore.active_controller->type != DEVICE) {
|
||||
logf("wrong type");
|
||||
logf("wrong type");
|
||||
return EWRONGCONTROLLERTYPE;
|
||||
}
|
||||
|
||||
|
||||
/* bind driver to controller */
|
||||
bind_device_driver(driver);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void usb_device_driver_unbind(void) {
|
||||
|
||||
logf("usb_device_driver_unbind");
|
||||
if (usbcore.active_controller->device_driver != NULL) {
|
||||
usbcore.active_controller->device_driver->unbind();
|
||||
usbcore.active_controller->device_driver = NULL;
|
||||
}
|
||||
|
||||
usbcore.device_driver = NULL;
|
||||
logf("usb_device_driver_unbind");
|
||||
if (usbcore.active_controller->device_driver != NULL) {
|
||||
usbcore.active_controller->device_driver->unbind();
|
||||
usbcore.active_controller->device_driver = NULL;
|
||||
}
|
||||
|
||||
usbcore.device_driver = NULL;
|
||||
}
|
||||
|
||||
static void update_driver_names(unsigned char* result) {
|
||||
|
||||
int i;
|
||||
int i;
|
||||
int pos = 0;
|
||||
unsigned char terminator = ',';
|
||||
unsigned char terminator = ',';
|
||||
struct usb_device_driver* dd = NULL;
|
||||
|
||||
|
||||
/* reset buffer, iterate through drivers and add to char array */
|
||||
memset(result, 0, USB_STACK_MAX_SETTINGS_NAME);
|
||||
for (i = 0; i < NUM_DRIVERS; i++) {
|
||||
int len;
|
||||
int len;
|
||||
dd = usbcore.device_drivers[i];
|
||||
|
||||
|
||||
if (dd != NULL) {
|
||||
len = strlen(dd->name);
|
||||
if (pos > 0) {
|
||||
memcpy(result + pos, &terminator, 1);
|
||||
pos++;
|
||||
}
|
||||
memcpy(result + pos, dd->name, len);
|
||||
pos += len;
|
||||
len = strlen(dd->name);
|
||||
if (pos > 0) {
|
||||
memcpy(result + pos, &terminator, 1);
|
||||
pos++;
|
||||
}
|
||||
memcpy(result + pos, dd->name, len);
|
||||
pos += len;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void bind_device_driver(struct usb_device_driver* driver) {
|
||||
|
||||
|
||||
/* look if there is an old driver */
|
||||
if (usbcore.active_controller->device_driver != NULL) {
|
||||
usbcore.active_controller->device_driver->unbind();
|
||||
}
|
||||
|
||||
|
||||
/* bind driver to controller */
|
||||
usbcore.active_controller->device_driver = driver;
|
||||
|
||||
|
||||
/* init dirver */
|
||||
driver->bind(usbcore.active_controller->controller_ops);
|
||||
driver->bind(usbcore.active_controller->controller_ops);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue