*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
/* Buffer description tables */
static union stm_usb_bdt *ao_usb_bdt;
/* USB address of end of allocated storage */
+#if AO_USB_DIRECTIO
static uint16_t ao_usb_sram_addr;
+#endif
/* Pointer to ep0 tx/rx buffers in USB memory */
static uint16_t *ao_usb_ep0_tx_buffer;
static inline uint16_t *ao_usb_packet_buffer_addr(uint16_t sram_addr)
{
- return (uint16_t *) (stm_usb_sram + sram_addr);
+ return (uint16_t *) (void *) (stm_usb_sram + sram_addr);
}
static inline uint16_t ao_usb_packet_buffer_offset(uint16_t *addr)
static void
ao_usb_alloc_buffers(void)
{
- ao_usb_sram_addr = 0;
+ uint16_t sram_addr = 0;
ao_usb_bdt = (void *) stm_usb_sram;
- ao_usb_sram_addr += 8 * STM_USB_BDT_SIZE;
+ sram_addr += 8 * STM_USB_BDT_SIZE;
- ao_usb_ep0_tx_buffer = ao_usb_packet_buffer_addr(ao_usb_sram_addr);
- ao_usb_sram_addr += AO_USB_CONTROL_SIZE;
+ ao_usb_ep0_tx_buffer = ao_usb_packet_buffer_addr(sram_addr);
+ sram_addr += AO_USB_CONTROL_SIZE;
- ao_usb_ep0_rx_buffer = ao_usb_packet_buffer_addr(ao_usb_sram_addr);
- ao_usb_sram_addr += AO_USB_CONTROL_SIZE;
+ ao_usb_ep0_rx_buffer = ao_usb_packet_buffer_addr(sram_addr);
+ sram_addr += AO_USB_CONTROL_SIZE;
#if AO_USB_HAS_INT
- ao_usb_int_tx_offset = ao_usb_sram_addr;
- ao_usb_sram_addr += AO_USB_INT_SIZE;
+ ao_usb_int_tx_offset = sram_addr;
+ sram_addr += AO_USB_INT_SIZE;
#endif
#if AO_USB_HAS_OUT
- ao_usb_out_rx_buffer = ao_usb_packet_buffer_addr(ao_usb_sram_addr);
- ao_usb_out_rx_offset = ao_usb_sram_addr;
- ao_usb_sram_addr += AO_USB_OUT_SIZE;
+ ao_usb_out_rx_buffer = ao_usb_packet_buffer_addr(sram_addr);
+ ao_usb_out_rx_offset = sram_addr;
+ sram_addr += AO_USB_OUT_SIZE;
#endif
#if AO_USB_HAS_IN
- ao_usb_in_tx_buffer = ao_usb_packet_buffer_addr(ao_usb_sram_addr);
- ao_usb_in_tx_offset = ao_usb_sram_addr;
- ao_usb_sram_addr += AO_USB_IN_SIZE;
+ ao_usb_in_tx_buffer = ao_usb_packet_buffer_addr(sram_addr);
+ ao_usb_in_tx_offset = sram_addr;
+ sram_addr += AO_USB_IN_SIZE;
#endif
#if AO_USB_HAS_IN2
- ao_usb_in2_tx_buffer = ao_usb_packet_buffer_addr(ao_usb_sram_addr);
- ao_usb_in2_tx_offset = ao_usb_sram_addr;
- ao_usb_sram_addr += AO_USB_IN_SIZE;
+ ao_usb_in2_tx_buffer = ao_usb_packet_buffer_addr(sram_addr);
+ ao_usb_in2_tx_offset = sram_addr;
+ sram_addr += AO_USB_IN_SIZE;
+#endif
+
+#if AO_USB_DIRECTIO
+ ao_usb_sram_addr = sram_addr;
#endif
}
ao_usb_set_address(0);
ao_usb_running = 0;
+
+ /* Reset our internal state
+ */
+
+ ao_usb_ep0_state = AO_USB_EP0_IDLE;
+
+ ao_usb_ep0_in_data = NULL;
+ ao_usb_ep0_in_len = 0;
+
+ ao_usb_ep0_out_data = 0;
+ ao_usb_ep0_out_len = 0;
}
static void
STM_USB_EPR_STAT_TX_NAK);
#endif
+ ao_usb_in_flushed = 0;
+ ao_usb_in_pending = 0;
+ ao_wakeup(&ao_usb_in_pending);
+#if AO_USB_HAS_IN2
+ ao_usb_in2_flushed = 0;
+ ao_usb_in2_pending = 0;
+ ao_wakeup(&ao_usb_in2_pending);
+#endif
+
+ ao_usb_out_avail = 0;
+ ao_usb_configuration = 0;
+
+ ao_wakeup(AO_USB_OUT_SLEEP_ADDR);
+
ao_usb_running = 1;
#if AO_USB_DIRECTIO
ao_wakeup(&ao_usb_running);
/* Walk through the list of descriptors and find a match
*/
static void
-ao_usb_get_descriptor(uint16_t value)
+ao_usb_get_descriptor(uint16_t value, uint16_t length)
{
const uint8_t *descriptor;
uint8_t type = value >> 8;
len = sizeof (ao_usb_serial);
}
#endif
+ if (len > length)
+ len = length;
ao_usb_ep0_in_set(descriptor, len);
break;
}
break;
case AO_USB_REQ_GET_DESCRIPTOR:
debug ("get descriptor %d\n", ao_usb_setup.value);
- ao_usb_get_descriptor(ao_usb_setup.value);
+ ao_usb_get_descriptor(ao_usb_setup.value, ao_usb_setup.length);
break;
case AO_USB_REQ_GET_CONFIGURATION:
debug ("get configuration %d\n", ao_usb_configuration);
}
#endif
-#if AO_USB_HAS_IN
+#if AO_USB_HAS_IN2
/* Queue the current IN buffer for transmission */
static void
_ao_usb_in2_send(void)
return buffer;
}
-void
-ao_usb_free(uint16_t *addr)
-{
- uint16_t offset = ao_usb_packet_buffer_offset(addr);
- if (offset < ao_usb_sram_addr)
- ao_usb_sram_addr = offset;
-}
-
void
ao_usb_write(uint16_t *buffer, uint16_t len)
{