| Line 86... |
Line 86... |
| 86 |
static int dbgconrecvreadidx IBSS_ATTR;
|
86 |
static int dbgconrecvreadidx IBSS_ATTR;
|
| 87 |
static int dbgconrecvwriteidx IBSS_ATTR;
|
87 |
static int dbgconrecvwriteidx IBSS_ATTR;
|
| 88 |
static struct wakeup dbgconsendwakeup IBSS_ATTR;
|
88 |
static struct wakeup dbgconsendwakeup IBSS_ATTR;
|
| 89 |
static struct wakeup dbgconrecvwakeup IBSS_ATTR;
|
89 |
static struct wakeup dbgconrecvwakeup IBSS_ATTR;
|
| 90 |
static bool dbgconsoleattached IBSS_ATTR;
|
90 |
static bool dbgconsoleattached IBSS_ATTR;
|
| - |
|
91 |
static int maxpacket IBSS_ATTR;
|
| - |
|
92 |
static struct bulk_state
|
| - |
|
93 |
{
|
| - |
|
94 |
void* addr;
|
| - |
|
95 |
int size;
|
| - |
|
96 |
} bulk_state[2] IBSS_ATTR;
|
| - |
|
97 |
static int bulk_ctrlreq_ep IBSS_ATTR;
|
| 91 |
|
98 |
|
| 92 |
static const char dbgconoverflowstr[] = "\n\n[overflowed]\n\n";
|
99 |
static const char dbgconoverflowstr[] = "\n\n[overflowed]\n\n";
|
| 93 |
|
100 |
|
| 94 |
extern int _poolstart; // These aren't ints at all, but gcc complains about void types being
|
101 |
extern int _poolstart; // These aren't ints at all, but gcc complains about void types being
|
| 95 |
extern int _poolend; // used here, and we only need the address, so just make it happy...
|
102 |
extern int _poolend; // used here, and we only need the address, so just make it happy...
|
| Line 108... |
Line 115... |
| 108 |
{
|
115 |
{
|
| 109 |
dbgenabled = false;
|
116 |
dbgenabled = false;
|
| 110 |
dbgstate = DBGSTATE_IDLE;
|
117 |
dbgstate = DBGSTATE_IDLE;
|
| 111 |
}
|
118 |
}
|
| 112 |
|
119 |
|
| - |
|
120 |
void usbdebug_bus_reset(const struct usb_instance* data, int highspeed)
|
| - |
|
121 |
{
|
| - |
|
122 |
maxpacket = highspeed ? 512 : 64;
|
| - |
|
123 |
}
|
| - |
|
124 |
|
| - |
|
125 |
void usbdebug_bulk_enable(const struct usb_instance* data, int interface, int altsetting)
|
| - |
|
126 |
{
|
| - |
|
127 |
usbdebug_enable(data, interface, altsetting);
|
| - |
|
128 |
union usb_endpoint_number outep = { .number = USBDEBUG_ENDPOINT_OUT, .direction = USB_ENDPOINT_DIRECTION_OUT };
|
| - |
|
129 |
union usb_endpoint_number inep = { .number = USBDEBUG_ENDPOINT_IN, .direction = USB_ENDPOINT_DIRECTION_IN };
|
| - |
|
130 |
usb_configure_ep(data, outep, USB_ENDPOINT_TYPE_BULK, maxpacket);
|
| - |
|
131 |
usb_configure_ep(data, inep, USB_ENDPOINT_TYPE_BULK, maxpacket);
|
| - |
|
132 |
}
|
| - |
|
133 |
|
| - |
|
134 |
void usbdebug_bulk_disable(const struct usb_instance* data, int interface, int altsetting)
|
| - |
|
135 |
{
|
| - |
|
136 |
union usb_endpoint_number outep = { .number = USBDEBUG_ENDPOINT_OUT, .direction = USB_ENDPOINT_DIRECTION_OUT };
|
| - |
|
137 |
union usb_endpoint_number inep = { .number = USBDEBUG_ENDPOINT_IN, .direction = USB_ENDPOINT_DIRECTION_IN };
|
| - |
|
138 |
usb_unconfigure_ep(data, outep);
|
| - |
|
139 |
usb_unconfigure_ep(data, inep);
|
| - |
|
140 |
usbdebug_disable(data, interface, altsetting);
|
| - |
|
141 |
}
|
| - |
|
142 |
|
| - |
|
143 |
void usbdebug_bulk_xfer_complete(const struct usb_instance* data, int interface, int endpoint, int bytesleft)
|
| - |
|
144 |
{
|
| - |
|
145 |
struct bulk_state* state = &bulk_state[endpoint];
|
| - |
|
146 |
if (!bytesleft && state->size)
|
| - |
|
147 |
{
|
| - |
|
148 |
int size;
|
| - |
|
149 |
if (endpoint)
|
| - |
|
150 |
{
|
| - |
|
151 |
union usb_endpoint_number ep = { .number = USBDEBUG_ENDPOINT_IN, .direction = USB_ENDPOINT_DIRECTION_IN };
|
| - |
|
152 |
size = MIN(state->size, maxpacket * usb_get_max_transfer_size(data, ep));
|
| - |
|
153 |
usb_start_rx(data, ep, state->addr, size);
|
| - |
|
154 |
}
|
| - |
|
155 |
else
|
| - |
|
156 |
{
|
| - |
|
157 |
union usb_endpoint_number ep = { .number = USBDEBUG_ENDPOINT_OUT, .direction = USB_ENDPOINT_DIRECTION_OUT };
|
| - |
|
158 |
size = MIN(state->size, maxpacket * usb_get_max_transfer_size(data, ep));
|
| - |
|
159 |
usb_start_tx(data, ep, state->addr, size);
|
| - |
|
160 |
}
|
| - |
|
161 |
state->addr += size;
|
| - |
|
162 |
state->size -= size;
|
| - |
|
163 |
}
|
| - |
|
164 |
}
|
| - |
|
165 |
|
| - |
|
166 |
bool usbdebug_bulk_handle_data(const struct usb_instance* data, union usb_endpoint_number epnum, int bytesleft)
|
| - |
|
167 |
{
|
| - |
|
168 |
uint32_t* buf = (uint32_t*)data->buffer->raw;
|
| - |
|
169 |
int len = 64 - bytesleft;
|
| - |
|
170 |
union usb_endpoint_number ep0out = { .number = 0, .direction = USB_ENDPOINT_DIRECTION_OUT };
|
| - |
|
171 |
union usb_endpoint_number ep0in = { .number = 0, .direction = USB_ENDPOINT_DIRECTION_IN };
|
| - |
|
172 |
usb_ep0_start_rx(data, false, 0, NULL);
|
| - |
|
173 |
switch (buf[0])
|
| - |
|
174 |
{
|
| - |
|
175 |
case 1: // START MEMORY TRANSFER
|
| - |
|
176 |
if (len == 12)
|
| - |
|
177 |
{
|
| - |
|
178 |
bulk_state[bulk_ctrlreq_ep].addr = (void*)buf[1];
|
| - |
|
179 |
bulk_state[bulk_ctrlreq_ep].size = buf[2];
|
| - |
|
180 |
usbdebug_bulk_xfer_complete(data, 0, bulk_ctrlreq_ep, 0); // Convenient way to start a transfer.
|
| - |
|
181 |
usb_set_stall(data, ep0out, true);
|
| - |
|
182 |
usb_ep0_start_tx(data, NULL, 0, NULL);
|
| - |
|
183 |
break;
|
| - |
|
184 |
}
|
| - |
|
185 |
default:
|
| - |
|
186 |
usb_set_stall(data, ep0out, true);
|
| - |
|
187 |
usb_set_stall(data, ep0in, true);
|
| - |
|
188 |
break;
|
| - |
|
189 |
}
|
| - |
|
190 |
return true;
|
| - |
|
191 |
}
|
| - |
|
192 |
|
| - |
|
193 |
int usbdebug_bulk_ctrl_request(const struct usb_instance* data, int interface, int endpoint, union usb_ep0_buffer* request, const void** response)
|
| - |
|
194 |
{
|
| - |
|
195 |
int size = -1;
|
| - |
|
196 |
union usb_endpoint_number ep0out = { .number = 0, .direction = USB_ENDPOINT_DIRECTION_OUT };
|
| - |
|
197 |
switch (request->setup.bmRequestType.type)
|
| - |
|
198 |
{
|
| - |
|
199 |
case USB_SETUP_BMREQUESTTYPE_TYPE_VENDOR:
|
| - |
|
200 |
switch (request->setup.bRequest.raw)
|
| - |
|
201 |
{
|
| - |
|
202 |
case 0x00:
|
| - |
|
203 |
switch (data->buffer->setup.bmRequestType.direction)
|
| - |
|
204 |
{
|
| - |
|
205 |
case USB_SETUP_BMREQUESTTYPE_DIRECTION_OUT:
|
| - |
|
206 |
bulk_ctrlreq_ep = endpoint;
|
| - |
|
207 |
usb_ep0_start_rx(data, true, 64, usbdebug_bulk_handle_data);
|
| - |
|
208 |
return -3;
|
| - |
|
209 |
case USB_SETUP_BMREQUESTTYPE_DIRECTION_IN:
|
| - |
|
210 |
return -2;
|
| - |
|
211 |
}
|
| - |
|
212 |
break;
|
| - |
|
213 |
default: break;
|
| - |
|
214 |
}
|
| - |
|
215 |
break;
|
| - |
|
216 |
default: break;
|
| - |
|
217 |
}
|
| - |
|
218 |
return size;
|
| - |
|
219 |
}
|
| - |
|
220 |
|
| 113 |
bool usbdebug_handle_data(const struct usb_instance* data, union usb_endpoint_number epnum, int bytesleft)
|
221 |
bool usbdebug_handle_data(const struct usb_instance* data, union usb_endpoint_number epnum, int bytesleft)
|
| 114 |
{
|
222 |
{
|
| 115 |
union usb_endpoint_number ep0in = { .number = 0, .direction = USB_ENDPOINT_DIRECTION_IN };
|
223 |
union usb_endpoint_number ep0in = { .number = 0, .direction = USB_ENDPOINT_DIRECTION_IN };
|
| 116 |
union usb_endpoint_number ep0out = { .number = 0, .direction = USB_ENDPOINT_DIRECTION_OUT };
|
224 |
union usb_endpoint_number ep0out = { .number = 0, .direction = USB_ENDPOINT_DIRECTION_OUT };
|
| 117 |
uint32_t* buf = (uint32_t*)data->buffer->raw;
|
225 |
uint32_t* buf = (uint32_t*)data->buffer->raw;
|