]> granicus.if.org Git - esp-idf/commitdiff
vfs and newlib: small fixes
authorIvan Grokhotkov <ivan@espressif.com>
Wed, 26 Oct 2016 06:05:56 +0000 (14:05 +0800)
committerIvan Grokhotkov <ivan@espressif.com>
Thu, 27 Oct 2016 09:22:18 +0000 (17:22 +0800)
- spaces->tabs in tasks.c
- update vfs_uart.c to use per-UART locks
- add license to vfs_uart.c
- allocate separate streams for stdout, stdin, stderr, so that they can be independently reassigned
- fix build system test failure
- use posix off_t instead of newlib internal _off_t

components/esp32/cpu_start.c
components/vfs/include/esp_vfs.h
components/vfs/vfs.c
components/vfs/vfs_uart.c
make/test_build_system.sh

index 769bd3eaf335baa9125b1782697511fc3f7d9418..6998140aff287388c447e421c84f3b4bae5d0a6b 100644 (file)
@@ -164,9 +164,10 @@ void start_cpu0_default(void)
     esp_setup_syscalls();
     esp_vfs_dev_uart_register();
     esp_reent_init(_GLOBAL_REENT);
-    _GLOBAL_REENT->_stdout = fopen("/dev/uart/0", "w"); // use fdopen here?
-    _GLOBAL_REENT->_stderr = _GLOBAL_REENT->_stdout;
-    _GLOBAL_REENT->_stdin  = _GLOBAL_REENT->_stdout;
+    const char* default_uart_dev = "/dev/uart/0";
+    _GLOBAL_REENT->_stdout = fopen(default_uart_dev, "w");
+    _GLOBAL_REENT->_stderr = fopen(default_uart_dev, "w");
+    _GLOBAL_REENT->_stdin  = fopen(default_uart_dev, "r");
     do_global_ctors();
     esp_ipc_init();
     spi_flash_init();
index 0d1c3d1479fc83a0c0ccaeb957a1b9d094bbe9d9..2d9e52c5afd36655fefe57ad520510f66c7e83a2 100644 (file)
@@ -71,8 +71,8 @@ typedef struct
         size_t (*write)(int fd, const void * data, size_t size);
     };
     union {
-        _off_t (*lseek_p)(void* p, int fd, _off_t size, int mode);
-        _off_t (*lseek)(int fd, _off_t size, int mode);
+        off_t (*lseek_p)(void* p, int fd, off_t size, int mode);
+        off_t (*lseek)(int fd, off_t size, int mode);
     };
     union {
         ssize_t (*read_p)(void* ctx, int fd, void * dst, size_t size);
@@ -137,7 +137,7 @@ esp_err_t esp_vfs_register(const char* base_path, const esp_vfs_t* vfs, void* ct
  */
 
 ssize_t esp_vfs_write(struct _reent *r, int fd, const void * data, size_t size);
-_off_t esp_vfs_lseek(struct _reent *r, int fd, _off_t size, int mode);
+off_t esp_vfs_lseek(struct _reent *r, int fd, off_t size, int mode);
 ssize_t esp_vfs_read(struct _reent *r, int fd, void * dst, size_t size);
 int esp_vfs_open(struct _reent *r, const char * path, int flags, int mode);
 int esp_vfs_close(struct _reent *r, int fd);
index afc7149bad7cac8d70502ab56895f1311dbc205b..bf26968ff7f72a6ccbfcd73fea1a4ab242618a0f 100644 (file)
@@ -167,7 +167,7 @@ ssize_t esp_vfs_write(struct _reent *r, int fd, const void * data, size_t size)
     return ret;
 }
 
-_off_t esp_vfs_lseek(struct _reent *r, int fd, _off_t size, int mode)
+off_t esp_vfs_lseek(struct _reent *r, int fd, off_t size, int mode)
 {
     const vfs_entry_t* vfs = get_vfs_for_fd(fd);
     if (vfs == NULL) {
index 179c5e2585cb61e9595b0ebc3654db5efaaabe20..6b6fad8e4bf865bb03eaf8e63e14432c7aa68892 100644 (file)
@@ -1,3 +1,17 @@
+// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
+//
+// Licensed 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, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
 #include <string.h>
 #include "esp_vfs.h"
 #include "esp_attr.h"
@@ -6,6 +20,7 @@
 #include "soc/uart_struct.h"
 
 static uart_dev_t* s_uarts[3] = {&UART0, &UART1, &UART2};
+static _lock_t s_uart_locks[3]; // per-UART locks, lazily initialized
 
 static int IRAM_ATTR uart_open(const char * path, int flags, int mode)
 {
@@ -36,21 +51,12 @@ static size_t IRAM_ATTR uart_write(int fd, const void * data, size_t size)
     assert(fd >=0 && fd < 3);
     const char *data_c = (const char *)data;
     uart_dev_t* uart = s_uarts[fd];
-    static _lock_t stdout_lock; /* lazily initialised */
-    /* Even though newlib does stream locking on stdout, we need
-       a dedicated stdout UART lock...
-
-       This is because each task has its own _reent structure with
-       unique FILEs for stdin/stdout/stderr, so these are
-       per-thread (lazily initialised by __sinit the first time a
-       stdio function is used, see findfp.c:235.
-
-       It seems like overkill to allocate a FILE-per-task and lock
-       a thread-local stream, but I see no easy way to fix this
-       (pre-__sinit_, tasks have "fake" FILEs ie __sf_fake_stdout
-       which aren't fully valid.)
-    */
-    _lock_acquire_recursive(&stdout_lock);
+    /*
+     *  Even though newlib does stream locking on each individual stream, we need
+     *  a dedicated UART lock if two streams (stdout and stderr) point to the
+     *  same UART.
+     */
+    _lock_acquire_recursive(&s_uart_locks[fd]);
     for (size_t i = 0; i < size; i++) {
 #if CONFIG_NEWLIB_STDOUT_ADDCR
         if (data_c[i]=='\n') {
@@ -59,7 +65,7 @@ static size_t IRAM_ATTR uart_write(int fd, const void * data, size_t size)
 #endif
         uart_tx_char(uart, data_c[i]);
     }
-    _lock_release_recursive(&stdout_lock);
+    _lock_release_recursive(&s_uart_locks[fd]);
     return size;
 }
 
index 7c8cbc1f1eba8e74c563f4e3ecdf92d7108a8a3c..d08ae6c8a2662903b2c800e1f75d0f49d6f31200 100755 (executable)
@@ -59,9 +59,9 @@ function run_tests()
     print_status "Updating component source file rebuilds component"
     # touch a file & do a build
     take_build_snapshot
-    touch ${IDF_PATH}/components/esp32/syscalls.c
+    touch ${IDF_PATH}/components/esp32/cpu_start.c
     make || failure "Failed to partial build"
-    assert_rebuilt ${APP_BINS} esp32/libesp32.a esp32/syscalls.o
+    assert_rebuilt ${APP_BINS} esp32/libesp32.a esp32/cpu_start.o
     assert_not_rebuilt lwip/liblwip.a freertos/libfreertos.a ${BOOTLOADER_BINS} partitions_singleapp.bin
 
     print_status "Bootloader source file rebuilds bootloader"