From 65c42d56ac58e19f41bc575efd5180eab82110f0 Mon Sep 17 00:00:00 2001 From: Linus Nielsen Feltzing Date: Sat, 29 Jun 2002 22:41:39 +0000 Subject: First version git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1257 a1c6a512-1295-4272-9138-f99709370657 --- firmware/usb.c | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ firmware/usb.h | 25 ++++++++++++ 2 files changed, 150 insertions(+) create mode 100644 firmware/usb.c create mode 100644 firmware/usb.h diff --git a/firmware/usb.c b/firmware/usb.c new file mode 100644 index 0000000000..a9df5ee57a --- /dev/null +++ b/firmware/usb.c @@ -0,0 +1,125 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2002 by Linus Nielsen Feltzing + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include "config.h" +#include "sh7034.h" +#include "kernel.h" +#include "thread.h" +#include "system.h" +#include "debug.h" + +#ifndef SIMULATOR + +#define USB_INSERTED 1 +#define USB_EXTRACTED 2 + +static char usb_stack[0x100]; +static struct event_queue usb_queue; +static bool usb_connected; + +static void usb_thread(void) +{ + int num_acks_to_expect = -1; + bool waiting_for_ack; + struct event ev; + + waiting_for_ack = false; + + while(1) + { + queue_wait(&usb_queue, &ev); + switch(ev.id) + { + case USB_INSERTED: + /* Tell all threads that they have to back off the ATA. + We subtract one for our own thread. */ + num_acks_to_expect = queue_broadcast(SYS_USB_CONNECTED, NULL) - 1; + waiting_for_ack = true; + DEBUGF("USB inserted. Waiting for ack from %d threads...\n"); + break; + + case SYS_USB_CONNECTED_ACK: + if(waiting_for_ack) + { + num_acks_to_expect--; + if(num_acks_to_expect == 0) + { + /* This is where we are supposed to be cool and keep + the Rockbox firmware running while the USB is enabled, + maybe even play some games and stuff. However, the + current firmware isn't quite ready for this yet. + Let's just chicken out and reboot. */ + DEBUGF("All threads have acknowledged. Rebooting...\n"); + system_reboot(); + } + else + { + DEBUGF("usb: got ack, %d to go...\n", num_acks_to_expect); + } + } + } + } +} + +static void usb_tick(void) +{ + int current_status; + +#ifdef ARCHOS_RECORDER + current_status = PCDR & 0x04; +#else + current_status = PADR & 0x8000; +#endif + + if(current_status && !usb_connected) + { + usb_connected = true; + queue_post(&usb_queue, USB_INSERTED, NULL); + } +} + +void usb_acknowledge(int id) +{ + queue_post(&usb_queue, id, NULL); +} + +void usb_init(void) +{ + int rc; + + usb_connected = false; + + queue_init(&usb_queue); + create_thread(usb_thread, usb_stack, sizeof(usb_stack)); + + rc = tick_add_task(usb_tick); +} + +#else + +/* Dummy simulator functions */ +void usb_acknowledge(int id) +{ + id = id; +} + +void usb_init(void) +{ +} + +#endif diff --git a/firmware/usb.h b/firmware/usb.h new file mode 100644 index 0000000000..de13f829c1 --- /dev/null +++ b/firmware/usb.h @@ -0,0 +1,25 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2002 by Linus Nielsen Feltzing + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#ifndef _USB_H_ +#define _USB_H_ + +void usb_init(void); +void usb_acknowledge(int id); + +#endif -- cgit v1.2.3