X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fstmf0%2Fao_usb_stm.c;h=652b3b6ca9facebaa742a57392f542f62e4958fa;hb=d197adf353ec5503c72a4554aca2a463bb685932;hp=a67fc868f63db8e5c557a33ef0fa1e1f23686e3b;hpb=2970de9f92243b11d3beef56f3b1df3ef3579b95;p=fw%2Faltos diff --git a/src/stmf0/ao_usb_stm.c b/src/stmf0/ao_usb_stm.c index a67fc868..652b3b6c 100644 --- a/src/stmf0/ao_usb_stm.c +++ b/src/stmf0/ao_usb_stm.c @@ -3,7 +3,8 @@ * * 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 @@ -83,7 +84,9 @@ static uint8_t ao_usb_ep0_out_len; /* 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; @@ -182,7 +185,7 @@ static inline uint32_t set_toggle(uint32_t current_value, 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) @@ -362,39 +365,43 @@ ao_usb_init_ep(uint8_t ep, uint32_t addr, uint32_t type, uint32_t stat_rx, uint3 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 } @@ -683,7 +690,7 @@ ao_usb_serial_init(void) /* 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; @@ -704,6 +711,8 @@ ao_usb_get_descriptor(uint16_t value) len = sizeof (ao_usb_serial); } #endif + if (len > length) + len = length; ao_usb_ep0_in_set(descriptor, len); break; } @@ -748,7 +757,7 @@ ao_usb_ep0_setup(void) 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); @@ -1183,14 +1192,6 @@ ao_usb_alloc(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) {