diff options
Diffstat (limited to 'uisimulator')
-rw-r--r-- | uisimulator/common/sim_tasks.c | 90 | ||||
-rw-r--r-- | uisimulator/common/sim_tasks.h | 7 |
2 files changed, 97 insertions, 0 deletions
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 | ||
29 | static void sim_thread(void); | 32 | static void sim_thread(void); |
30 | static long sim_thread_stack[DEFAULT_STACK_SIZE/sizeof(long)]; | 33 | static 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 */ |
36 | enum { | 39 | enum { |
37 | SIM_SCREENDUMP, | 40 | SIM_SCREENDUMP, |
41 | SIM_USB_INSERTED, | ||
42 | SIM_USB_EXTRACTED, | ||
38 | }; | 43 | }; |
39 | 44 | ||
40 | void sim_thread(void) | 45 | void 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 | |||
118 | static bool is_usb_inserted; | ||
119 | void 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 | |||
128 | int usb_detect(void) | ||
129 | { | ||
130 | return is_usb_inserted ? USB_INSERTED : USB_EXTRACTED; | ||
131 | } | ||
132 | |||
133 | void usb_init(void) | ||
134 | { | ||
135 | } | ||
136 | |||
137 | void usb_start_monitoring(void) | ||
138 | { | ||
139 | } | ||
140 | |||
141 | void usb_acknowledge(long id) | ||
142 | { | ||
143 | queue_post(&sim_queue, id, 0); | ||
144 | } | ||
145 | |||
146 | void 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 | |||
24 | void sim_tasks_init(void); | 28 | void sim_tasks_init(void); |
25 | void sim_trigger_screendump(void); | 29 | void sim_trigger_screendump(void); |
30 | void sim_trigger_usb(bool inserted); | ||
31 | |||
32 | #endif | ||