Skip to content

Commit e19ed4f

Browse files
brianjjonesgrgustaf
authored andcommitted
[ashell] Fix for ashell boot (zephyrproject-rtos#1615)
Currently ashell boot doesn't work with javascript with callbacks or timers. This is because once the boot.cfg JS gets called, it goes into an infinite loop waiting for uart. Until it gets the connection, it won't return. This means the main loop doesn't get control back, meaning callbacks are not processed. This breaks the code up a bit so that it checks if the connection is ready when uart_process gets called, if not try to connect. If the connection fails, just return and go through the main loop again. Continue until a connection is made. Fixes zephyrproject-rtos#1561 Signed-off-by: Brian J Jones <brian.j.jones@intel.com>
1 parent c836c62 commit e19ed4f

File tree

1 file changed

+49
-43
lines changed

1 file changed

+49
-43
lines changed

src/ashell/term-uart.c

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ u32_t free_count = 0;
9090
static struct uart_input *isr_data = NULL;
9191
static u32_t tail = 0;
9292
static char *buf;
93+
static u32_t dtr = 0;
9394

9495
struct uart_input *fifo_get_isr_buffer()
9596
{
@@ -316,7 +317,6 @@ static int uart_out(int c)
316317
return 1;
317318
}
318319

319-
#ifdef CONFIG_UART_LINE_CTRL
320320
u32_t uart_get_baudrate(void)
321321
{
322322
u32_t baudrate;
@@ -329,13 +329,60 @@ u32_t uart_get_baudrate(void)
329329

330330
return baudrate;
331331
}
332-
#endif
332+
333+
static void uart_ready()
334+
{
335+
// Need a short wait after uart_line_ctrl_get success
336+
k_sleep(1000);
337+
338+
uart_irq_rx_disable(dev_upload);
339+
uart_irq_tx_disable(dev_upload);
340+
341+
uart_irq_callback_set(dev_upload, uart_interrupt_handler);
342+
terminal->send(banner, sizeof(banner));
343+
344+
/* Enable rx interrupts */
345+
uart_irq_rx_enable(dev_upload);
346+
DBG("[Listening]\n");
347+
348+
__stdout_hook_install(uart_out);
349+
350+
// Disable buffering on stdout since some parts write directly to uart fifo
351+
setbuf(stdout, NULL);
352+
353+
ashell_help("");
354+
comms_print(comms_get_prompt());
355+
process_state = 0;
356+
357+
atomic_set(&uart_state, UART_INIT);
358+
359+
DBG("[Init]\n");
360+
terminal->init();
361+
}
362+
363+
static bool check_uart_connection()
364+
{
365+
// Try to connect to the device
366+
uart_line_ctrl_get(dev_upload, LINE_CTRL_DTR, &dtr);
367+
if (dtr) {
368+
uart_ready();
369+
return true;
370+
}
371+
return false;
372+
}
333373

334374
/*
335375
* Process user input
336376
*/
337377
void uart_process()
338378
{
379+
if (!dtr) {
380+
if (!check_uart_connection()) {
381+
// No connection yet, bail out
382+
return;
383+
}
384+
}
385+
339386
static struct uart_input *data = NULL;
340387
char *buf = NULL;
341388
u32_t len = 0;
@@ -416,47 +463,6 @@ void uart_init()
416463
k_fifo_init(&avail_queue);
417464

418465
ashell_run_boot_cfg();
419-
420-
#ifdef CONFIG_UART_LINE_CTRL
421-
u32_t dtr = 0;
422-
423-
while (1) {
424-
uart_line_ctrl_get(dev_upload, LINE_CTRL_DTR, &dtr);
425-
if (dtr)
426-
break;
427-
// Sleep is needed to allow the javascript in boot.cfg to run
428-
// while we wait for the connection.
429-
k_sleep(1000);
430-
}
431-
432-
/* 1000 msec = 1 sec */
433-
k_sleep(1000);
434-
435-
#endif
436-
437-
uart_irq_rx_disable(dev_upload);
438-
uart_irq_tx_disable(dev_upload);
439-
440-
uart_irq_callback_set(dev_upload, uart_interrupt_handler);
441-
terminal->send(banner, sizeof(banner));
442-
443-
/* Enable rx interrupts */
444-
uart_irq_rx_enable(dev_upload);
445-
DBG("[Listening]\n");
446-
447-
__stdout_hook_install(uart_out);
448-
449-
// Disable buffering on stdout since some parts write directly to uart fifo
450-
setbuf(stdout, NULL);
451-
452-
ashell_help("");
453-
comms_print(comms_get_prompt());
454-
process_state = 0;
455-
456-
atomic_set(&uart_state, UART_INIT);
457-
458-
DBG("[Init]\n");
459-
terminal->init();
460466
}
461467

462468
void zjs_ashell_init()

0 commit comments

Comments
 (0)