summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCástor Muñoz <cmvidal@gmail.com>2016-08-04 01:39:10 +0200
committerCástor Muñoz <cmvidal@gmail.com>2016-08-04 17:57:04 +0200
commite3c51e09d131ece29b3356cf9021065ecf7b84f3 (patch)
treeb919e4701a6c8ef391c6d11130b66c0c6e36ca28
parent838780109e9321511755e74a2bc7803b169bf389 (diff)
downloadrockbox-e3c51e09d131ece29b3356cf9021065ecf7b84f3.tar.gz
rockbox-e3c51e09d131ece29b3356cf9021065ecf7b84f3.zip
usb_serial: fix send buffer alignment
Change-Id: Ib2635c905462cd34befa3ca61e5d55c869686b48
-rw-r--r--firmware/usbstack/usb_serial.c27
1 files changed, 11 insertions, 16 deletions
diff --git a/firmware/usbstack/usb_serial.c b/firmware/usbstack/usb_serial.c
index e3ef4f5814..d879dc7c99 100644
--- a/firmware/usbstack/usb_serial.c
+++ b/firmware/usbstack/usb_serial.c
@@ -19,7 +19,6 @@
19 * 19 *
20 ****************************************************************************/ 20 ****************************************************************************/
21#include "string.h" 21#include "string.h"
22#include "config.h"
23#include "system.h" 22#include "system.h"
24#include "usb_core.h" 23#include "usb_core.h"
25#include "usb_drv.h" 24#include "usb_drv.h"
@@ -56,16 +55,19 @@ static struct usb_endpoint_descriptor __attribute__((aligned(2)))
56 .bInterval = 0 55 .bInterval = 0
57}; 56};
58 57
58/* send_buffer: local ring buffer.
59 * transit_buffer: used to store aligned data that will be sent by the USB
60 * driver. PP502x needs boost for high speed USB, but still works up to
61 * around 100 bytes without boost, we play safe and limit packet size to 32
62 * bytes, it doesn't hurt because data can be sent over several transfers.
63 */
59#define BUFFER_SIZE 512 64#define BUFFER_SIZE 512
60static unsigned char send_buffer[BUFFER_SIZE] 65#define TRANSIT_BUFFER_SIZE 32
61 USB_DEVBSS_ATTR __attribute__((aligned(32))); 66static unsigned char send_buffer[BUFFER_SIZE];
67static unsigned char transit_buffer[TRANSIT_BUFFER_SIZE]
68 USB_DEVBSS_ATTR __attribute__((aligned(4)));
62static unsigned char receive_buffer[32] 69static unsigned char receive_buffer[32]
63 USB_DEVBSS_ATTR __attribute__((aligned(32))); 70 USB_DEVBSS_ATTR __attribute__((aligned(32)));
64#if CONFIG_USBOTG == USBOTG_DESIGNWARE
65/* Aligned transit buffer */
66static unsigned char transit_buffer[32]
67 USB_DEVBSS_ATTR __attribute__((aligned(4)));
68#endif
69 71
70static void sendout(void); 72static void sendout(void);
71 73
@@ -163,19 +165,12 @@ void usb_serial_disconnect(void)
163static void sendout(void) 165static void sendout(void)
164{ 166{
165 buffer_transitlength = MIN(buffer_length,BUFFER_SIZE-buffer_start); 167 buffer_transitlength = MIN(buffer_length,BUFFER_SIZE-buffer_start);
166 /* For unknown reasons packets larger than 96 bytes are not sent. We play
167 * safe and limit to 32. TODO: find the real bug */
168 buffer_transitlength = MIN(buffer_transitlength,32);
169 if(buffer_transitlength > 0) 168 if(buffer_transitlength > 0)
170 { 169 {
170 buffer_transitlength = MIN(buffer_transitlength,TRANSIT_BUFFER_SIZE);
171 buffer_length -= buffer_transitlength; 171 buffer_length -= buffer_transitlength;
172#if CONFIG_USBOTG == USBOTG_DESIGNWARE
173 memcpy(transit_buffer,&send_buffer[buffer_start],buffer_transitlength); 172 memcpy(transit_buffer,&send_buffer[buffer_start],buffer_transitlength);
174 usb_drv_send_nonblocking(ep_in,transit_buffer,buffer_transitlength); 173 usb_drv_send_nonblocking(ep_in,transit_buffer,buffer_transitlength);
175#else
176 usb_drv_send_nonblocking(ep_in, &send_buffer[buffer_start],
177 buffer_transitlength);
178#endif
179 } 174 }
180} 175}
181 176