From b25785ee0afebaf516b8a1b8d08d36fbdadd74ca Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 9 May 2016 11:33:48 -0700 Subject: altos/cc1111: Use SW to drive UART RTS pin Can't get the hw to work. Signed-off-by: Keith Packard --- src/cc1111/ao_serial.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/cc1111/ao_serial.c b/src/cc1111/ao_serial.c index 81727836..b4f57908 100644 --- a/src/cc1111/ao_serial.c +++ b/src/cc1111/ao_serial.c @@ -42,6 +42,18 @@ const __code struct ao_serial_speed ao_serial_speeds[] = { #define AO_SERIAL_SPEED_MAX AO_SERIAL_SPEED_115200 +#if HAS_SERIAL_1_ALT_1 +#define SERIAL_1_RTS P0_3 +#else +#define SERIAL_1_RTS P1_5 +#endif + +#if HAS_SERIAL_0_ALT_1 +#define SERIAL_0_RTS P0_5 +#else +#define SERIAL_0_RTS P1_3 +#endif + #if HAS_SERIAL_0 volatile __xdata struct ao_fifo ao_serial0_rx_fifo; @@ -56,6 +68,10 @@ ao_serial0_rx_isr(void) __interrupt 2 #if USE_SERIAL_0_STDIN ao_wakeup(&ao_stdin_ready); #endif +#if HAS_SERIAL_0_HW_FLOW + if (ao_fifo_mostly(ao_serial0_rx_fifo)) + SERIAL_0_RTS = 1; +#endif } static __xdata uint8_t ao_serial0_tx_started; @@ -87,6 +103,10 @@ ao_serial0_getchar(void) __critical while (ao_fifo_empty(ao_serial0_rx_fifo)) ao_sleep(&ao_serial0_rx_fifo); ao_fifo_remove(ao_serial0_rx_fifo, c); +#if HAS_SERIAL_0_HW_FLOW + if (ao_fifo_barely(ao_serial0_rx_fifo)) + SERIAL_0_RTS = 0; +#endif return c; } @@ -98,6 +118,10 @@ _ao_serial0_pollchar(void) if (ao_fifo_empty(ao_serial0_rx_fifo)) return AO_READ_AGAIN; ao_fifo_remove(ao_serial0_rx_fifo,c); +#if HAS_SERIAL_0_HW_FLOW + if (ao_fifo_barely(ao_serial0_rx_fifo)) + SERIAL_0_RTS = 0; +#endif return c; } #endif @@ -144,6 +168,10 @@ ao_serial1_rx_isr(void) __interrupt 3 #if USE_SERIAL_1_STDIN ao_wakeup(&ao_stdin_ready); #endif +#if HAS_SERIAL_1_HW_FLOW + if (ao_fifo_mostly(ao_serial1_rx_fifo)) + SERIAL_1_RTS = 1; +#endif } static __xdata uint8_t ao_serial1_tx_started; @@ -175,6 +203,10 @@ ao_serial1_getchar(void) __critical while (ao_fifo_empty(ao_serial1_rx_fifo)) ao_sleep(&ao_serial1_rx_fifo); ao_fifo_remove(ao_serial1_rx_fifo, c); +#if HAS_SERIAL_1_HW_FLOW + if (ao_fifo_barely(ao_serial1_rx_fifo)) + SERIAL_1_RTS = 0; +#endif return c; } @@ -186,6 +218,10 @@ _ao_serial1_pollchar(void) if (ao_fifo_empty(ao_serial1_rx_fifo)) return AO_READ_AGAIN; ao_fifo_remove(ao_serial1_rx_fifo,c); +#if HAS_SERIAL_1_HW_FLOW + if (ao_fifo_barely(ao_serial1_rx_fifo)) + SERIAL_1_RTS = 0; +#endif return c; } #endif @@ -232,7 +268,11 @@ ao_serial_init(void) /* Make the USART pins be controlled by the USART */ P0SEL |= (1 << 2) | (1 << 3); #if HAS_SERIAL_0_HW_FLOW - P0SEL |= (1 << 4) | (1 << 5); + SERIAL_0_RTS = 0; + P0DIR |= (1 << 5); + + P0SEL |= (1 << 4); + P0INP |= (1 << 4); #endif #else /* Set up the USART pin assignment */ @@ -244,7 +284,11 @@ ao_serial_init(void) /* Make the USART pins be controlled by the USART */ P1SEL |= (1 << 5) | (1 << 4); #if HAS_SERIAL_0_HW_FLOW - P1SEL |= (1 << 3) | (1 << 2); + SERIAL_0_RTS = 0; + P1DIR |= (1 << 3); + + P1SEL |= (1 << 2); + P1INP |= (1 << 2); #endif #endif @@ -287,7 +331,13 @@ ao_serial_init(void) /* Make the USART pins be controlled by the USART */ P0SEL |= (1 << 5) | (1 << 4); #if HAS_SERIAL_1_HW_FLOW - P0SEL |= (1 << 3) | (1 << 2); + /* SW RTS control (hw doesn't work) */ + SERIAL_1_RTS = 0; + P0DIR |= 1 << 3; + + /* HW CTS. Maybe this works? */ + P0SEL |= 1 << 2; + P0INP |= 1 << 2; #endif #else /* Set up the USART pin assignment */ @@ -299,7 +349,13 @@ ao_serial_init(void) /* Make the USART pins be controlled by the USART */ P1SEL |= (1 << 6) | (1 << 7); #if HAS_SERIAL_1_HW_FLOW - P1SEL |= (1 << 5) | (1 << 4); + /* SW RTS control (hw doesn't work) */ + SERIAL_1_RTS = 0; + P1DIR |= (1 << 5); + + /* HW CTS. Maybe this works? */ + P1SEL |= (1 << 4); + P1INP |= (1 << 4); #endif #endif -- cgit v1.2.3 From f982248573c1b646ac53fde980a60ada5404f6aa Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 27 May 2016 20:30:18 -0700 Subject: altosuilib: Fill preload map on site or lat/lon change This loads the map view with the selected area when the site entry is changed or the user hits return in the lat/lon fields. This lets you see the target launch site without having to load the whole preload set. Signed-off-by: Keith Packard --- altosuilib/AltosUIMapPreload.java | 40 ++++++++++++++++++++++++++++++--------- src/drivers/ao_trng_send.c | 10 +++++++++- 2 files changed, 40 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/altosuilib/AltosUIMapPreload.java b/altosuilib/AltosUIMapPreload.java index 42fdd301..32690037 100644 --- a/altosuilib/AltosUIMapPreload.java +++ b/altosuilib/AltosUIMapPreload.java @@ -28,7 +28,8 @@ import java.net.URL; import java.net.URLConnection; import org.altusmetrum.altoslib_11.*; -class AltosUIMapPos extends Box { +class AltosUIMapPos extends Box implements ActionListener { + AltosUIMapPreload preload; AltosUIFrame owner; JLabel label; JComboBox hemi; @@ -37,6 +38,11 @@ class AltosUIMapPos extends Box { JTextField min; JLabel min_label; + /* ActionListener interface */ + public void actionPerformed(ActionEvent e) { + preload.center_map(); + } + public void set_value(double new_value) { double d, m; int h; @@ -88,19 +94,23 @@ class AltosUIMapPos extends Box { } public AltosUIMapPos(AltosUIFrame in_owner, - String label_value, - String[] hemi_names, - double default_value) { + AltosUIMapPreload preload, + String label_value, + String[] hemi_names, + double default_value) { super(BoxLayout.X_AXIS); owner = in_owner; + this.preload = preload; label = new JLabel(label_value); hemi = new JComboBox(hemi_names); hemi.setEditable(false); deg = new JTextField(5); + deg.addActionListener(this); deg.setMinimumSize(deg.getPreferredSize()); deg.setHorizontalAlignment(JTextField.RIGHT); deg_label = new JLabel("°"); min = new JTextField(9); + min.addActionListener(this); min.setMinimumSize(min.getPreferredSize()); min_label = new JLabel("'"); set_value(default_value); @@ -166,8 +176,6 @@ public class AltosUIMapPreload extends AltosUIFrame implements ActionListener, I pbar.setMaximum(max); pbar.setValue(0); pbar.setString(""); - map.clear_marks(); - map.add_mark(latitude, longitude, AltosLib.ao_flight_boost); } }); } @@ -213,6 +221,19 @@ public class AltosUIMapPreload extends AltosUIFrame implements ActionListener, I return all_types; } + void center_map(double latitude, double longitude) { + map.map.centre(new AltosLatLon(latitude, longitude)); + map.clear_marks(); + map.add_mark(latitude, longitude, AltosLib.ao_flight_boost); + } + + void center_map() { + try { + center_map(lat.get_value(), lon.get_value()); + } catch (ParseException pe) { + } + } + public void itemStateChanged(ItemEvent e) { int state = e.getStateChange(); @@ -222,6 +243,7 @@ public class AltosUIMapPreload extends AltosUIFrame implements ActionListener, I AltosLaunchSite site = (AltosLaunchSite) o; lat.set_value(site.latitude); lon.set_value(site.longitude); + center_map(site.latitude, site.longitude); } } } @@ -251,7 +273,7 @@ public class AltosUIMapPreload extends AltosUIFrame implements ActionListener, I else r = r * 1000; - map.map.centre(new AltosLatLon(latitude, longitude)); + center_map(latitude, longitude); loader = new AltosMapLoader(this, latitude, longitude, @@ -393,7 +415,7 @@ public class AltosUIMapPreload extends AltosUIFrame implements ActionListener, I pane.add(site_list, c); - lat = new AltosUIMapPos(owner, + lat = new AltosUIMapPos(owner, this, "Latitude:", lat_hemi_names, 37.167833333); @@ -410,7 +432,7 @@ public class AltosUIMapPreload extends AltosUIFrame implements ActionListener, I pane.add(lat, c); - lon = new AltosUIMapPos(owner, + lon = new AltosUIMapPos(owner, this, "Longitude:", lon_hemi_names, -97.73975); diff --git a/src/drivers/ao_trng_send.c b/src/drivers/ao_trng_send.c index 171a345f..4ac6ee5e 100644 --- a/src/drivers/ao_trng_send.c +++ b/src/drivers/ao_trng_send.c @@ -22,7 +22,7 @@ #include #include -static struct ao_task ao_trng_send_task, ao_trng_send_raw_task; +static struct ao_task ao_trng_send_task; static uint8_t trng_running; static AO_TICK_TYPE trng_power_time; @@ -30,6 +30,10 @@ static AO_TICK_TYPE trng_power_time; static uint8_t random_mutex; +#if AO_USB_HAS_IN2 + +static struct ao_task ao_trng_send_raw_task; + static void ao_trng_get_raw(uint16_t *buf) { @@ -90,6 +94,8 @@ ao_trng_send_raw(void) } } +#endif + /* Make sure there's at least 8 bits of variance in the samples */ #define MIN_VARIANCE (128 * 128) @@ -181,7 +187,9 @@ ao_trng_send(void) if (failed > AO_TRNG_START_CHECK / 4) ao_panic(AO_PANIC_DMA); +#if AO_USB_HAS_IN2 ao_add_task(&ao_trng_send_raw_task, ao_trng_send_raw, "trng_send_raw"); +#endif #ifdef AO_USB_START_DISABLED ao_usb_enable(); -- cgit v1.2.3 From 55c8e5aff2cc7b941503a04970f7d368261af52a Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 9 Jun 2016 22:03:45 -0700 Subject: telegps-v1.0: Document how SN 1959 was fixed SN1959 was fixed by jumpering pin 8 to pin 10 so that the DONE_INT_PIN could be switched from PIO 2 to PIO 4 as pin 8 appeared to have failed. Signed-off-by: Keith Packard --- src/telegps-v1.0/ao_pins.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src') diff --git a/src/telegps-v1.0/ao_pins.h b/src/telegps-v1.0/ao_pins.h index d2382a56..eb1033da 100644 --- a/src/telegps-v1.0/ao_pins.h +++ b/src/telegps-v1.0/ao_pins.h @@ -105,6 +105,16 @@ #define AO_CC115L_DONE_INT_PORT 0 #define AO_CC115L_DONE_INT_PIN 2 +/* SN 1959, owned by J. Patrick Bowers, had a hard landing and appears to have broken the + * internal connection between pin 8 and the chip. This board + * has been fixed by jumpering pin 8 to pin 10, which means that + * the DONE_INT_PIN is now 4 instead of 2. When building custom firmware for + * this board, just adjust the ao_pins.h value before compiling + + #define AO_CC115L_DONE_INT_PIN_SN_1959 4 + + */ + /* * Flash (M25) */ -- cgit v1.2.3 From 2970de9f92243b11d3beef56f3b1df3ef3579b95 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 9 Jun 2016 22:05:24 -0700 Subject: stmf0: Clear all USB state when resetting chip. Wakeup all sleepers When USB is reset, but the board is not power cycled, all of the internal USB state needs to be reset, and any tasks blocked on sending or receiving packets need to be awoken so they can go wait for USB to start running again. Signed-off-by: Keith Packard --- src/stmf0/ao_usb_stm.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src') diff --git a/src/stmf0/ao_usb_stm.c b/src/stmf0/ao_usb_stm.c index 253506d5..a67fc868 100644 --- a/src/stmf0/ao_usb_stm.c +++ b/src/stmf0/ao_usb_stm.c @@ -437,6 +437,17 @@ ao_usb_set_ep0(void) 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 @@ -493,6 +504,20 @@ ao_usb_set_configuration(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); -- cgit v1.2.3 From 36ba97fabbed2f2a4a89da5be221c630ea3ff66f Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 9 Jun 2016 22:06:30 -0700 Subject: stmf0: Do not send more data than requested for GET_DESCRIPTOR When Linux boots, it asks for only the first 8 bytes of the device descriptor; we must limit the amount of data sent back to that amount or USB will get wedged. Signed-off-by: Keith Packard --- src/stmf0/ao_usb_stm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/stmf0/ao_usb_stm.c b/src/stmf0/ao_usb_stm.c index a67fc868..63b35b24 100644 --- a/src/stmf0/ao_usb_stm.c +++ b/src/stmf0/ao_usb_stm.c @@ -683,7 +683,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 +704,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 +750,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); -- cgit v1.2.3 From 54f8d53584d0a902676b441cd122c01cd54f2283 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 10 Jun 2016 14:33:50 -0700 Subject: altos/lpc: Handle USB reset by resetting internal state Just like stmf0, this clears internal state at USB reset time so the driver can survive host OS reboots. Signed-off-by: Keith Packard --- src/lpc/ao_usb_lpc.c | 72 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/lpc/ao_usb_lpc.c b/src/lpc/ao_usb_lpc.c index 0dfaece4..3b3226ad 100644 --- a/src/lpc/ao_usb_lpc.c +++ b/src/lpc/ao_usb_lpc.c @@ -269,13 +269,10 @@ ao_usb_epn_in_count(uint8_t n) return ao_usb_ep_count(ao_usb_epn_in(n, 0)); } -static uint8_t * -ao_usb_enable_ep(vuint32_t *ep, uint16_t nbytes, uint16_t set_nbytes) +static void +ao_usb_enable_ep(vuint32_t *ep, uint8_t *addr, uint16_t set_nbytes) { - uint8_t *addr = ao_usb_alloc_sram(nbytes); - ao_usb_set_ep(ep, addr, set_nbytes); - return addr; } static void @@ -293,23 +290,13 @@ ao_usb_disable_ep(vuint32_t *ep) static void ao_usb_enable_epn(uint8_t n, - uint16_t out_bytes, uint8_t *out_addrs[2], - uint16_t in_bytes, uint8_t *in_addrs[2]) + uint16_t out_bytes, uint8_t *out_addr, + uint8_t *in_addr) { - uint8_t *addr; - - addr = ao_usb_enable_ep(ao_usb_epn_out(n, 0), out_bytes * 2, out_bytes); - if (out_addrs) { - out_addrs[0] = addr; - out_addrs[1] = addr + out_bytes; - } + ao_usb_enable_ep(ao_usb_epn_out(n, 0), out_addr, out_bytes); ao_usb_disable_ep(ao_usb_epn_out(n, 1)); - addr = ao_usb_enable_ep(ao_usb_epn_in(n, 0), in_bytes * 2, 0); - if (in_addrs) { - in_addrs[0] = addr; - in_addrs[1] = addr + in_bytes; - } + ao_usb_enable_ep(ao_usb_epn_in(n, 0), in_addr, 0); ao_usb_disable_ep(ao_usb_epn_in(n, 1)); } @@ -327,6 +314,14 @@ ao_usb_reset(void) { ao_usb_set_address(0); ao_usb_configuration = 0; + + ao_usb_ep0_state = AO_USB_EP0_IDLE; + ao_usb_ep0_in_data = NULL; + ao_usb_ep0_in_len = 0; + ao_usb_ep0_in_max = 0; + + ao_usb_ep0_out_data = NULL; + ao_usb_ep0_out_len = 0; } static void @@ -341,17 +336,14 @@ ao_usb_set_ep0(void) lpc_usb.intstat = 0xc00003ff; - ao_usb_sram = lpc_usb_sram; - lpc_usb.epliststart = (uint32_t) (intptr_t) &lpc_usb_endpoint; lpc_usb.databufstart = ((uint32_t) (intptr_t) ao_usb_sram) & 0xffc00000; /* Set up EP 0 - a Control end point with 32 bytes of in and out buffers */ - ao_usb_ep0_rx_buffer = ao_usb_enable_ep(ao_usb_ep0_out(), AO_USB_CONTROL_SIZE, AO_USB_CONTROL_SIZE); - ao_usb_ep0_setup_buffer = ao_usb_alloc_sram(AO_USB_CONTROL_SIZE); + ao_usb_enable_ep(ao_usb_ep0_out(), ao_usb_ep0_rx_buffer, AO_USB_CONTROL_SIZE); lpc_usb_endpoint.setup = ao_usb_sram_offset(ao_usb_ep0_setup_buffer); - ao_usb_ep0_tx_buffer = ao_usb_enable_ep(ao_usb_ep0_in(), AO_USB_CONTROL_SIZE, 0); + ao_usb_enable_ep(ao_usb_ep0_in(), ao_usb_ep0_tx_buffer, 0); /* Clear all of the other endpoints */ for (e = 1; e <= 4; e++) @@ -365,10 +357,10 @@ ao_usb_set_configuration(void) debug ("ao_usb_set_configuration\n"); /* Set up the INT end point */ - ao_usb_enable_epn(AO_USB_INT_EP, 0, NULL, 0, NULL); + ao_usb_enable_epn(AO_USB_INT_EP, 0, NULL, NULL); /* Set up the OUT end point */ - ao_usb_enable_epn(AO_USB_OUT_EP, AO_USB_OUT_SIZE, ao_usb_out_rx_buffer, 0, NULL); + ao_usb_enable_epn(AO_USB_OUT_EP, AO_USB_OUT_SIZE, ao_usb_out_rx_buffer[0], NULL); /* Set the current RX pointer to the *other* buffer so that when buffer 0 gets * data, we'll switch to it and pull bytes from there @@ -376,10 +368,18 @@ ao_usb_set_configuration(void) ao_usb_out_rx_cur = 1; /* Set up the IN end point */ - ao_usb_enable_epn(AO_USB_IN_EP, 0, NULL, AO_USB_IN_SIZE, ao_usb_in_tx_buffer); + ao_usb_enable_epn(AO_USB_IN_EP, 0, NULL, ao_usb_in_tx_buffer[0]); ao_usb_in_tx_cur = 0; + ao_usb_in_flushed = 0; + ao_usb_in_pending = 0; + ao_wakeup(&ao_usb_in_pending); + + ao_usb_out_avail = 0; + ao_usb_configuration = 0; + ao_usb_running = 1; + ao_wakeup(&ao_usb_running); } /* Send an IN data packet */ @@ -481,7 +481,7 @@ static struct ao_usb_line_coding ao_usb_line_coding = {115200, 0, 0, 8}; /* 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; @@ -495,6 +495,8 @@ ao_usb_get_descriptor(uint16_t value) len = descriptor[2]; else len = descriptor[0]; + if (len > length) + len = length; ao_usb_ep0_in_set(descriptor, len); break; } @@ -539,7 +541,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); @@ -958,6 +960,17 @@ ao_usb_enable(void) for (t = 0; t < 1000; t++) ao_arch_nop(); + ao_usb_sram = lpc_usb_sram; + + ao_usb_ep0_rx_buffer = ao_usb_alloc_sram(AO_USB_CONTROL_SIZE); + ao_usb_ep0_tx_buffer = ao_usb_alloc_sram(AO_USB_CONTROL_SIZE); + ao_usb_ep0_setup_buffer = ao_usb_alloc_sram(AO_USB_CONTROL_SIZE); + + ao_usb_out_rx_buffer[0] = ao_usb_alloc_sram(AO_USB_OUT_SIZE); + ao_usb_out_rx_buffer[1] = ao_usb_alloc_sram(AO_USB_OUT_SIZE); + ao_usb_in_tx_buffer[0] = ao_usb_alloc_sram(AO_USB_IN_SIZE); + ao_usb_in_tx_buffer[1] = ao_usb_alloc_sram(AO_USB_IN_SIZE); + ao_usb_set_ep0(); #if HAS_USB_PULLUP @@ -1001,7 +1014,6 @@ ao_usb_init(void) #if HAS_USB_PULLUP ao_enable_output(AO_USB_PULLUP_PORT, AO_USB_PULLUP_PIN, AO_USB_PULLUP, 0); #endif - ao_usb_enable(); debug ("ao_usb_init\n"); -- cgit v1.2.3 From 7d21ff641a7bc35318f0f637589eabb5bb6c5152 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 10 Jun 2016 14:39:25 -0700 Subject: altos/stm: Handle USB reset in STM32L usb driver Just like lpc and stmf0, deal with the host resetting the bus while rebooting by restoring all usb-related data to the initial values. Signed-off-by: Keith Packard --- src/stm/ao_usb_stm.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/stm/ao_usb_stm.c b/src/stm/ao_usb_stm.c index 4e9d1f14..3d26466b 100644 --- a/src/stm/ao_usb_stm.c +++ b/src/stm/ao_usb_stm.c @@ -349,6 +349,19 @@ ao_usb_set_ep0(void) } 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 @@ -393,7 +406,15 @@ ao_usb_set_configuration(void) STM_USB_EPR_STAT_RX_DISABLED, STM_USB_EPR_STAT_TX_NAK); + ao_usb_in_flushed = 0; + ao_usb_in_pending = 0; + ao_wakeup(&ao_usb_in_pending); + + ao_usb_out_avail = 0; + ao_usb_configuration = 0; + ao_usb_running = 1; + ao_wakeup(&ao_usb_running); } static uint16_t control_count; @@ -581,7 +602,7 @@ static struct ao_usb_line_coding ao_usb_line_coding = {115200, 0, 0, 8}; /* 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; @@ -595,6 +616,8 @@ ao_usb_get_descriptor(uint16_t value) len = descriptor[2]; else len = descriptor[0]; + if (len > length) + len = length; ao_usb_ep0_in_set(descriptor, len); break; } @@ -639,7 +662,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); -- cgit v1.2.3 From 36a08dc89ece6e2a2f0f69e3b31da17d66ceb2e2 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 10 Jun 2016 14:40:26 -0700 Subject: altos/cc1115l: Reduce trace buffer size A 32-element trace buffer is all the larger we can fit in teledongle. Signed-off-by: Keith Packard --- src/drivers/ao_cc115l.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/drivers/ao_cc115l.c b/src/drivers/ao_cc115l.c index 0246ba02..24180f34 100644 --- a/src/drivers/ao_cc115l.c +++ b/src/drivers/ao_cc115l.c @@ -70,7 +70,7 @@ struct ao_cc115l_trace { const char *comment; }; -#define NUM_TRACE 256 +#define NUM_TRACE 32 static struct ao_cc115l_trace trace[NUM_TRACE]; static int trace_i; -- cgit v1.2.3 From 1704d27248f1845c545ec61cf1bad58bf41189af Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 11 Jun 2016 22:16:12 -0700 Subject: altos/stmf0: Rework the sram allocation to save a few text bytes Boot loaders were going over 4096 bytes of ROM. I suspect we'll need more serious work soon. Signed-off-by: Keith Packard --- src/stmf0/ao_usb_stm.c | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/stmf0/ao_usb_stm.c b/src/stmf0/ao_usb_stm.c index 63b35b24..6393ee44 100644 --- a/src/stmf0/ao_usb_stm.c +++ b/src/stmf0/ao_usb_stm.c @@ -83,7 +83,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; @@ -362,39 +364,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 } -- cgit v1.2.3 From eee7fa303fb0d80ac5d7b9c5a86af60333f61951 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 11 Jun 2016 22:17:01 -0700 Subject: altos/stmf0: Remove ao_usb_free This can't work without a lot more effort. Signed-off-by: Keith Packard --- src/stmf0/ao_arch_funcs.h | 3 --- src/stmf0/ao_usb_stm.c | 8 -------- 2 files changed, 11 deletions(-) (limited to 'src') diff --git a/src/stmf0/ao_arch_funcs.h b/src/stmf0/ao_arch_funcs.h index ccfa3fc7..64311b23 100644 --- a/src/stmf0/ao_arch_funcs.h +++ b/src/stmf0/ao_arch_funcs.h @@ -408,9 +408,6 @@ static inline void ao_arch_start_scheduler(void) { uint16_t * ao_usb_alloc(void); -void -ao_usb_free(uint16_t *buffer); - void ao_usb_write(uint16_t *buffer, uint16_t len); diff --git a/src/stmf0/ao_usb_stm.c b/src/stmf0/ao_usb_stm.c index 6393ee44..fb3d8c85 100644 --- a/src/stmf0/ao_usb_stm.c +++ b/src/stmf0/ao_usb_stm.c @@ -1191,14 +1191,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) { -- cgit v1.2.3