summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/gui/usb_screen.c2
-rw-r--r--apps/playback.c4
-rw-r--r--apps/playlist.c2
-rw-r--r--apps/tagcache.c2
-rw-r--r--firmware/common/dircache.c2
-rw-r--r--firmware/target/hosted/sdl/button-sdl.c5
-rw-r--r--firmware/usb.c8
-rw-r--r--uisimulator/common/sim_tasks.c90
-rw-r--r--uisimulator/common/sim_tasks.h7
9 files changed, 101 insertions, 21 deletions
diff --git a/apps/gui/usb_screen.c b/apps/gui/usb_screen.c
index 80b24c150c..32c0773ed6 100644
--- a/apps/gui/usb_screen.c
+++ b/apps/gui/usb_screen.c
@@ -251,9 +251,7 @@ void gui_usb_screen_run(bool early_usb)
251 touchscreen_set_mode(TOUCHSCREEN_BUTTON); 251 touchscreen_set_mode(TOUCHSCREEN_BUTTON);
252#endif 252#endif
253 253
254#ifndef SIMULATOR
255 usb_acknowledge(SYS_USB_CONNECTED_ACK); 254 usb_acknowledge(SYS_USB_CONNECTED_ACK);
256#endif
257 255
258#ifdef USB_ENABLE_HID 256#ifdef USB_ENABLE_HID
259 usb_hid = global_settings.usb_hid; 257 usb_hid = global_settings.usb_hid;
diff --git a/apps/playback.c b/apps/playback.c
index d591998bec..b20237cc7c 100644
--- a/apps/playback.c
+++ b/apps/playback.c
@@ -190,9 +190,7 @@ static enum filling_state
190 STATE_FINISHED, /* all remaining tracks are fully buffered */ 190 STATE_FINISHED, /* all remaining tracks are fully buffered */
191 STATE_ENDING, /* audio playback is ending */ 191 STATE_ENDING, /* audio playback is ending */
192 STATE_ENDED, /* audio playback is done */ 192 STATE_ENDED, /* audio playback is done */
193#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
194 STATE_USB, /* USB mode, ignore most messages */ 193 STATE_USB, /* USB mode, ignore most messages */
195#endif
196} filling = STATE_IDLE; 194} filling = STATE_IDLE;
197 195
198/* Track info - holds information about each track in the buffer */ 196/* Track info - holds information about each track in the buffer */
@@ -3129,7 +3127,6 @@ static void audio_thread(void)
3129 break; 3127 break;
3130#endif /* AUDIO_HAVE_RECORDING */ 3128#endif /* AUDIO_HAVE_RECORDING */
3131 3129
3132#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
3133 case SYS_USB_CONNECTED: 3130 case SYS_USB_CONNECTED:
3134 LOGFQUEUE("audio < SYS_USB_CONNECTED"); 3131 LOGFQUEUE("audio < SYS_USB_CONNECTED");
3135 audio_stop_playback(); 3132 audio_stop_playback();
@@ -3139,7 +3136,6 @@ static void audio_thread(void)
3139 filling = STATE_USB; 3136 filling = STATE_USB;
3140 usb_acknowledge(SYS_USB_CONNECTED_ACK); 3137 usb_acknowledge(SYS_USB_CONNECTED_ACK);
3141 break; 3138 break;
3142#endif /* (CONFIG_PLATFORM & PLATFORM_NATIVE) */
3143 3139
3144 case SYS_TIMEOUT: 3140 case SYS_TIMEOUT:
3145 LOGFQUEUE_SYS_TIMEOUT("audio < SYS_TIMEOUT"); 3141 LOGFQUEUE_SYS_TIMEOUT("audio < SYS_TIMEOUT");
diff --git a/apps/playlist.c b/apps/playlist.c
index 61432eb851..4588548d54 100644
--- a/apps/playlist.c
+++ b/apps/playlist.c
@@ -1337,12 +1337,10 @@ static void playlist_thread(void)
1337 break ; 1337 break ;
1338 } 1338 }
1339 1339
1340#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
1341 case SYS_USB_CONNECTED: 1340 case SYS_USB_CONNECTED:
1342 usb_acknowledge(SYS_USB_CONNECTED_ACK); 1341 usb_acknowledge(SYS_USB_CONNECTED_ACK);
1343 usb_wait_for_disconnect(&playlist_queue); 1342 usb_wait_for_disconnect(&playlist_queue);
1344 break ; 1343 break ;
1345#endif
1346 } 1344 }
1347 } 1345 }
1348} 1346}
diff --git a/apps/tagcache.c b/apps/tagcache.c
index 8d522b1536..058ab85f16 100644
--- a/apps/tagcache.c
+++ b/apps/tagcache.c
@@ -4705,13 +4705,11 @@ static void tagcache_thread(void)
4705 case SYS_POWEROFF: 4705 case SYS_POWEROFF:
4706 break ; 4706 break ;
4707 4707
4708#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
4709 case SYS_USB_CONNECTED: 4708 case SYS_USB_CONNECTED:
4710 logf("USB: TagCache"); 4709 logf("USB: TagCache");
4711 usb_acknowledge(SYS_USB_CONNECTED_ACK); 4710 usb_acknowledge(SYS_USB_CONNECTED_ACK);
4712 usb_wait_for_disconnect(&tagcache_queue); 4711 usb_wait_for_disconnect(&tagcache_queue);
4713 break ; 4712 break ;
4714#endif
4715 } 4713 }
4716 } 4714 }
4717} 4715}
diff --git a/firmware/common/dircache.c b/firmware/common/dircache.c
index 3d7fbd520d..8d264a3e7c 100644
--- a/firmware/common/dircache.c
+++ b/firmware/common/dircache.c
@@ -864,12 +864,10 @@ static void dircache_thread(void)
864 dircache_initialized = false; 864 dircache_initialized = false;
865 break ; 865 break ;
866 866
867#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
868 case SYS_USB_CONNECTED: 867 case SYS_USB_CONNECTED:
869 usb_acknowledge(SYS_USB_CONNECTED_ACK); 868 usb_acknowledge(SYS_USB_CONNECTED_ACK);
870 usb_wait_for_disconnect(&dircache_queue); 869 usb_wait_for_disconnect(&dircache_queue);
871 break ; 870 break ;
872#endif
873 } 871 }
874 } 872 }
875} 873}
diff --git a/firmware/target/hosted/sdl/button-sdl.c b/firmware/target/hosted/sdl/button-sdl.c
index ca1f2e5eb1..837cba4dc4 100644
--- a/firmware/target/hosted/sdl/button-sdl.c
+++ b/firmware/target/hosted/sdl/button-sdl.c
@@ -317,10 +317,7 @@ static void button_event(int key, bool pressed)
317 if (!pressed) 317 if (!pressed)
318 { 318 {
319 usb_connected = !usb_connected; 319 usb_connected = !usb_connected;
320 if (usb_connected) 320 sim_trigger_usb(usb_connected);
321 queue_post(&button_queue, SYS_USB_CONNECTED, 0);
322 else
323 queue_post(&button_queue, SYS_USB_DISCONNECTED, 0);
324 } 321 }
325 return; 322 return;
326 323
diff --git a/firmware/usb.c b/firmware/usb.c
index 4e71c06119..59462b952e 100644
--- a/firmware/usb.c
+++ b/firmware/usb.c
@@ -782,16 +782,14 @@ void usb_set_hid(bool enable)
782} 782}
783#endif /* USB_ENABLE_HID */ 783#endif /* USB_ENABLE_HID */
784 784
785#else /* SIMULATOR || USB_NONE */ 785#elif defined(USB_NONE)
786/* Dummy functions for USB_NONE */
786 787
787#ifdef USB_NONE
788bool usb_inserted(void) 788bool usb_inserted(void)
789{ 789{
790 return false; 790 return false;
791} 791}
792#endif /* USB_NONE */
793 792
794/* Dummy simulator functions */
795void usb_acknowledge(long id) 793void usb_acknowledge(long id)
796{ 794{
797 id = id; 795 id = id;
@@ -814,5 +812,5 @@ void usb_wait_for_disconnect(struct event_queue *q)
814{ 812{
815 (void)q; 813 (void)q;
816} 814}
815#endif /* USB_NONE */
817 816
818#endif /* !USB_NONE && !SIMULATOR */
diff --git a/uisimulator/common/sim_tasks.c b/uisimulator/common/sim_tasks.c
index 2fc887cc37..f154dacce6 100644
--- a/uisimulator/common/sim_tasks.c
+++ b/uisimulator/common/sim_tasks.c
@@ -8,6 +8,7 @@
8 * $Id$ 8 * $Id$
9 * 9 *
10 * Copyright (C) 2009 by Jens Arnold 10 * Copyright (C) 2009 by Jens Arnold
11 * Copyright (C) 2011 by Thomas Martitz
11 * 12 *
12 * Rockbox simulator specific tasks 13 * Rockbox simulator specific tasks
13 * 14 *
@@ -25,6 +26,8 @@
25#include "kernel.h" 26#include "kernel.h"
26#include "screendump.h" 27#include "screendump.h"
27#include "thread.h" 28#include "thread.h"
29#include "debug.h"
30#include "usb.h"
28 31
29static void sim_thread(void); 32static void sim_thread(void);
30static long sim_thread_stack[DEFAULT_STACK_SIZE/sizeof(long)]; 33static long sim_thread_stack[DEFAULT_STACK_SIZE/sizeof(long)];
@@ -35,11 +38,15 @@ static struct event_queue sim_queue;
35/* possible events for the sim thread */ 38/* possible events for the sim thread */
36enum { 39enum {
37 SIM_SCREENDUMP, 40 SIM_SCREENDUMP,
41 SIM_USB_INSERTED,
42 SIM_USB_EXTRACTED,
38}; 43};
39 44
40void sim_thread(void) 45void sim_thread(void)
41{ 46{
42 struct queue_event ev; 47 struct queue_event ev;
48 long last_broadcast_tick = current_tick;
49 int num_acks_to_expect;
43 50
44 while (1) 51 while (1)
45 { 52 {
@@ -52,6 +59,45 @@ void sim_thread(void)
52 remote_screen_dump(); 59 remote_screen_dump();
53#endif 60#endif
54 break; 61 break;
62 case SIM_USB_INSERTED:
63 /* from firmware/usb.c: */
64 /* Tell all threads that they have to back off the storage.
65 We subtract one for our own thread. Expect an ACK for every
66 listener for each broadcast they received. If it has been too
67 long, the user might have entered a screen that didn't ACK
68 when inserting the cable, such as a debugging screen. In that
69 case, reset the count or else USB would be locked out until
70 rebooting because it most likely won't ever come. Simply
71 resetting to the most recent broadcast count is racy. */
72 if(TIME_AFTER(current_tick, last_broadcast_tick + HZ*5))
73 {
74 num_acks_to_expect = 0;
75 last_broadcast_tick = current_tick;
76 }
77
78 num_acks_to_expect += queue_broadcast(SYS_USB_CONNECTED, 0) - 1;
79 DEBUGF("USB inserted. Waiting for %d acks...\n",
80 num_acks_to_expect);
81 break;
82 case SYS_USB_CONNECTED_ACK:
83 if(num_acks_to_expect > 0 && --num_acks_to_expect == 0)
84 {
85 DEBUGF("All threads have acknowledged the connect.\n");
86 }
87 else
88 {
89 DEBUGF("usb: got ack, %d to go...\n",
90 num_acks_to_expect);
91 }
92 break;
93 case SIM_USB_EXTRACTED:
94 /* in usb.c, this is only done for exclusive storage
95 * do it here anyway but don't depend on the acks */
96 queue_broadcast(SYS_USB_DISCONNECTED, 0);
97 break;
98 default:
99 DEBUGF("sim_tasks: unhandled event: %ld\n", ev.id);
100 break;
55 } 101 }
56 } 102 }
57} 103}
@@ -68,3 +114,47 @@ void sim_trigger_screendump(void)
68{ 114{
69 queue_post(&sim_queue, SIM_SCREENDUMP, 0); 115 queue_post(&sim_queue, SIM_SCREENDUMP, 0);
70} 116}
117
118static bool is_usb_inserted;
119void sim_trigger_usb(bool inserted)
120{
121 if (inserted)
122 queue_post(&sim_queue, SIM_USB_INSERTED, 0);
123 else
124 queue_post(&sim_queue, SIM_USB_EXTRACTED, 0);
125 is_usb_inserted = inserted;
126}
127
128int usb_detect(void)
129{
130 return is_usb_inserted ? USB_INSERTED : USB_EXTRACTED;
131}
132
133void usb_init(void)
134{
135}
136
137void usb_start_monitoring(void)
138{
139}
140
141void usb_acknowledge(long id)
142{
143 queue_post(&sim_queue, id, 0);
144}
145
146void usb_wait_for_disconnect(struct event_queue *q)
147{
148#ifdef USB_FULL_INIT
149 struct queue_event ev;
150
151 /* Don't return until we get SYS_USB_DISCONNECTED */
152 while(1)
153 {
154 queue_wait(q, &ev);
155 if(ev.id == SYS_USB_DISCONNECTED)
156 return;
157 }
158#endif /* USB_FULL_INIT */
159 (void)q;
160}
diff --git a/uisimulator/common/sim_tasks.h b/uisimulator/common/sim_tasks.h
index fe42deeb97..dfecd4448e 100644
--- a/uisimulator/common/sim_tasks.h
+++ b/uisimulator/common/sim_tasks.h
@@ -21,5 +21,12 @@
21 * 21 *
22 ****************************************************************************/ 22 ****************************************************************************/
23 23
24
25#ifndef __SIM_TASKS_H__
26#define __SIM_TASKS_H__
27
24void sim_tasks_init(void); 28void sim_tasks_init(void);
25void sim_trigger_screendump(void); 29void sim_trigger_screendump(void);
30void sim_trigger_usb(bool inserted);
31
32#endif