You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/04/28 02:14:43 UTC
[44/50] [abbrv] incubator-mynewt-core git commit: native uart;
workaround the problem of console TX buffer filling up when OS is not
running.
native uart; workaround the problem of console TX buffer filling
up when OS is not running.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/01879020
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/01879020
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/01879020
Branch: refs/heads/master
Commit: 01879020418094a8e1e18a726a54b390084862f9
Parents: 470262a
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Apr 26 10:25:43 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Apr 26 10:25:43 2016 -0700
----------------------------------------------------------------------
hw/mcu/native/src/hal_uart.c | 62 ++++++++++++++++++++++++---------------
1 file changed, 39 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/01879020/hw/mcu/native/src/hal_uart.c
----------------------------------------------------------------------
diff --git a/hw/mcu/native/src/hal_uart.c b/hw/mcu/native/src/hal_uart.c
index dae24c7..c30a414 100644
--- a/hw/mcu/native/src/hal_uart.c
+++ b/hw/mcu/native/src/hal_uart.c
@@ -6,7 +6,7 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
@@ -128,6 +128,37 @@ uart_log_data(struct uart *u, int istx, uint8_t data)
}
}
+static int
+uart_transmit_char(struct uart *uart)
+{
+ int sr;
+ int rc;
+ char ch;
+
+ OS_ENTER_CRITICAL(sr);
+ rc = uart->u_tx_func(uart->u_func_arg);
+ if (rc < 0) {
+ /*
+ * No more data to send.
+ */
+ uart->u_tx_run = 0;
+ if (uart->u_tx_done) {
+ uart->u_tx_done(uart->u_func_arg);
+ }
+ OS_EXIT_CRITICAL(sr);
+ return 0;
+ }
+ uart_log_data(uart, 1, ch);
+ OS_EXIT_CRITICAL(sr);
+ ch = rc;
+ rc = write(uart->u_fd, &ch, 1);
+ if (rc <= 0) {
+ /* XXX EOF/error, what now? */
+ return -1;
+ }
+ return 0;
+}
+
static void
uart_poller(void *arg)
{
@@ -147,28 +178,7 @@ uart_poller(void *arg)
for (bytes = 0; bytes < UART_MAX_BYTES_PER_POLL; bytes++) {
if (uart->u_tx_run) {
- OS_ENTER_CRITICAL(sr);
- rc = uart->u_tx_func(uart->u_func_arg);
- if (rc < 0) {
- /*
- * No more data to send.
- */
- uart->u_tx_run = 0;
- if (uart->u_tx_done) {
- uart->u_tx_done(uart->u_func_arg);
- }
- OS_EXIT_CRITICAL(sr);
- break;
- }
- uart_log_data(uart, 1, ch);
- OS_EXIT_CRITICAL(sr);
- ch = rc;
- rc = write(uart->u_fd, &ch, 1);
- if (rc <= 0) {
- /* XXX EOF/error, what now? */
- assert(0);
- break;
- }
+ uart_transmit_char(uart);
}
}
for (bytes = 0; bytes < UART_MAX_BYTES_PER_POLL; bytes++) {
@@ -279,6 +289,12 @@ hal_uart_start_tx(int port)
}
OS_ENTER_CRITICAL(sr);
uarts[port].u_tx_run = 1;
+ if (!os_started()) {
+ /*
+ * XXX this is a hack.
+ */
+ uart_transmit_char(&uarts[port]);
+ }
OS_EXIT_CRITICAL(sr);
}