summaryrefslogtreecommitdiff
path: root/firmware/usb.c
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2002-06-29 22:41:39 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2002-06-29 22:41:39 +0000
commit65c42d56ac58e19f41bc575efd5180eab82110f0 (patch)
treeaf764db57e5c09b62f0db4e0745d3c4f40adc2e4 /firmware/usb.c
parent270274ae5b5e808e8892859ee20deaef5075d35a (diff)
downloadrockbox-65c42d56ac58e19f41bc575efd5180eab82110f0.tar.gz
rockbox-65c42d56ac58e19f41bc575efd5180eab82110f0.zip
First version
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1257 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/usb.c')
-rw-r--r--firmware/usb.c125
1 files changed, 125 insertions, 0 deletions
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 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "config.h"
20#include "sh7034.h"
21#include "kernel.h"
22#include "thread.h"
23#include "system.h"
24#include "debug.h"
25
26#ifndef SIMULATOR
27
28#define USB_INSERTED 1
29#define USB_EXTRACTED 2
30
31static char usb_stack[0x100];
32static struct event_queue usb_queue;
33static bool usb_connected;
34
35static void usb_thread(void)
36{
37 int num_acks_to_expect = -1;
38 bool waiting_for_ack;
39 struct event ev;
40
41 waiting_for_ack = false;
42
43 while(1)
44 {
45 queue_wait(&usb_queue, &ev);
46 switch(ev.id)
47 {
48 case USB_INSERTED:
49 /* Tell all threads that they have to back off the ATA.
50 We subtract one for our own thread. */
51 num_acks_to_expect = queue_broadcast(SYS_USB_CONNECTED, NULL) - 1;
52 waiting_for_ack = true;
53 DEBUGF("USB inserted. Waiting for ack from %d threads...\n");
54 break;
55
56 case SYS_USB_CONNECTED_ACK:
57 if(waiting_for_ack)
58 {
59 num_acks_to_expect--;
60 if(num_acks_to_expect == 0)
61 {
62 /* This is where we are supposed to be cool and keep
63 the Rockbox firmware running while the USB is enabled,
64 maybe even play some games and stuff. However, the
65 current firmware isn't quite ready for this yet.
66 Let's just chicken out and reboot. */
67 DEBUGF("All threads have acknowledged. Rebooting...\n");
68 system_reboot();
69 }
70 else
71 {
72 DEBUGF("usb: got ack, %d to go...\n", num_acks_to_expect);
73 }
74 }
75 }
76 }
77}
78
79static void usb_tick(void)
80{
81 int current_status;
82
83#ifdef ARCHOS_RECORDER
84 current_status = PCDR & 0x04;
85#else
86 current_status = PADR & 0x8000;
87#endif
88
89 if(current_status && !usb_connected)
90 {
91 usb_connected = true;
92 queue_post(&usb_queue, USB_INSERTED, NULL);
93 }
94}
95
96void usb_acknowledge(int id)
97{
98 queue_post(&usb_queue, id, NULL);
99}
100
101void usb_init(void)
102{
103 int rc;
104
105 usb_connected = false;
106
107 queue_init(&usb_queue);
108 create_thread(usb_thread, usb_stack, sizeof(usb_stack));
109
110 rc = tick_add_task(usb_tick);
111}
112
113#else
114
115/* Dummy simulator functions */
116void usb_acknowledge(int id)
117{
118 id = id;
119}
120
121void usb_init(void)
122{
123}
124
125#endif