]> granicus.if.org Git - esp-idf/commitdiff
vfs: code review fixes
authorIvan Grokhotkov <ivan@espressif.com>
Tue, 25 Oct 2016 14:16:08 +0000 (22:16 +0800)
committerIvan Grokhotkov <ivan@espressif.com>
Thu, 27 Oct 2016 09:21:17 +0000 (17:21 +0800)
- fix typo in readme
- remove unneeded extern declaration
- fix header guard macro
- tabs->spaces in syscalls.c (+1 squashed commit)
- fix minor typos

components/esp32/cpu_start.c
components/freertos/tasks.c
components/newlib/platform_include/esp_newlib.h
components/newlib/reent_init.c [new file with mode: 0644]

index cbac54d7c3b875621725c3a62962cc9a9c64ea68..769bd3eaf335baa9125b1782697511fc3f7d9418 100644 (file)
@@ -42,6 +42,7 @@
 #include "esp_spi_flash.h"
 #include "esp_ipc.h"
 #include "esp_log.h"
+#include "esp_vfs_dev.h"
 #include "esp_newlib.h"
 #include "esp_brownout.h"
 #include "esp_int_wdt.h"
@@ -161,6 +162,11 @@ void start_cpu0_default(void)
     esp_task_wdt_init();
 #endif
     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;
     do_global_ctors();
     esp_ipc_init();
     spi_flash_init();
index 9f004002c5db3ba6fd63b00df1c2089659b0387c..6a7eb50347169b5a7903810d17ff32541dfeabf0 100644 (file)
@@ -77,6 +77,7 @@ task.h is included from an application file. */
 #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE
 
 #include "rom/ets_sys.h"
+#include "esp_newlib.h"
 
 /* FreeRTOS includes. */
 #include "FreeRTOS.h"
@@ -962,8 +963,8 @@ UBaseType_t x;
 
        #if ( configUSE_NEWLIB_REENTRANT == 1 )
        {
-               /* Initialise this task's Newlib reent structure. */
-               _REENT_INIT_PTR( ( &( pxNewTCB->xNewLib_reent ) ) );
+        /* Initialise this task's Newlib reent structure. */
+        esp_reent_init(&pxNewTCB->xNewLib_reent);
        }
        #endif
 
@@ -3643,8 +3644,6 @@ BaseType_t xTaskGetAffinity( TaskHandle_t xTask )
 
 #if ( INCLUDE_vTaskDelete == 1 )
 
-       // TODO: move this to newlib component and provide a header file
-       extern void _extra_cleanup_r(struct _reent* r);
 
        static void prvDeleteTCB( TCB_t *pxTCB )
        {
@@ -3657,7 +3656,6 @@ BaseType_t xTaskGetAffinity( TaskHandle_t xTask )
                to the task to free any memory allocated at the application level. */
                #if ( configUSE_NEWLIB_REENTRANT == 1 )
                {
-                       pxTCB->xNewLib_reent.__cleanup = &_extra_cleanup_r;
                        _reclaim_reent( &( pxTCB->xNewLib_reent ) );
                }
                #endif /* configUSE_NEWLIB_REENTRANT */
index 74d0cc5e5e5c6ed951dc98caf77bd9bf79d03948..468f2ae34feacd2a1ca3fd1bdd9647e9753561ed 100644 (file)
 #ifndef __ESP_NEWLIB_H__
 #define __ESP_NEWLIB_H__
 
+#include <sys/reent.h>
+
+/**
+ * Replacement for newlib's _REENT_INIT_PTR and __sinit.
+ *
+ * Called from startup code and FreeRTOS, not intended to be called from
+ * application code.
+ */
+void esp_reent_init(struct _reent* r);
+
 /**
  * Function which sets up syscall table used by newlib functions in ROM.
  *
diff --git a/components/newlib/reent_init.c b/components/newlib/reent_init.c
new file mode 100644 (file)
index 0000000..5c29e89
--- /dev/null
@@ -0,0 +1,45 @@
+// 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 <sys/reent.h>
+#include "esp_attr.h"
+
+/* This function is not part on newlib API, it is defined in libc/stdio/local.h
+ * There is no nice way to get __cleanup member populated while avoiding __sinit,
+ * so extern declaration is used here.
+ */
+extern void _cleanup_r(struct _reent* r);
+
+/**
+ * This is the replacement for newlib's _REENT_INIT_PTR and __sinit.
+ * The problem with __sinit is that it allocates three FILE structures
+ * (stdin, stdout, stderr). Having individual standard streams for each task
+ * is a bit too much on a small embedded system. So we point streams
+ * to the streams of the global struct _reent, which are initialized in
+ * startup code.
+ */
+void IRAM_ATTR esp_reent_init(struct _reent* r)
+{
+    memset(r, 0, sizeof(*r));
+    r->_stdout = _GLOBAL_REENT->_stdout;
+    r->_stderr = _GLOBAL_REENT->_stderr;
+    r->_stdin  = _GLOBAL_REENT->_stdin;
+    r->__cleanup = &_cleanup_r;
+    r->__sdidinit = 1;
+    r->__sglue._next = NULL;
+    r->__sglue._niobs = 0;
+    r->__sglue._iobs = NULL;
+    r->_current_locale = "C";
+}