]> granicus.if.org Git - esp-idf/commitdiff
vfs: code review fixes
authorIvan Grokhotkov <ivan@espressif.com>
Thu, 27 Oct 2016 03:47:41 +0000 (11:47 +0800)
committerIvan Grokhotkov <ivan@espressif.com>
Thu, 27 Oct 2016 09:25:38 +0000 (17:25 +0800)
- fix typo in readme
- remove unneeded extern declaration
- fix header guard macro
- tabs->spaces in syscalls.c
- spaces->tabs in tasks.c

components/esp32/cpu_start.c
components/freertos/tasks.c
components/newlib/syscalls.c
components/newlib/time.c
components/vfs/README.rst
components/vfs/include/esp_vfs_dev.h

index 6998140aff287388c447e421c84f3b4bae5d0a6b..12189ccf66d12edd3c38e1b8de7113d7b865450d 100644 (file)
@@ -60,7 +60,6 @@ static bool app_cpu_started = false;
 
 static void do_global_ctors(void);
 static void main_task(void* args);
-extern void ets_setup_syscalls(void);
 extern void app_main(void);
 
 extern int _bss_start;
index 6a7eb50347169b5a7903810d17ff32541dfeabf0..64cc3a65df583495a9fc9a7b5e2384d7c0acc0a9 100644 (file)
@@ -963,8 +963,8 @@ UBaseType_t x;
 
        #if ( configUSE_NEWLIB_REENTRANT == 1 )
        {
-        /* Initialise this task's Newlib reent structure. */
-        esp_reent_init(&pxNewTCB->xNewLib_reent);
+               /* Initialise this task's Newlib reent structure. */
+               esp_reent_init(&pxNewTCB->xNewLib_reent);
        }
        #endif
 
index 4d70a39a8d801301acd06d43fc448c125c86f56f..3b2fbf62cacc22548979f9526a608a328e350e4f 100644 (file)
@@ -38,26 +38,26 @@ void* IRAM_ATTR _malloc_r(struct _reent *r, size_t size)
 
 void IRAM_ATTR _free_r(struct _reent *r, void* ptr)
 {
-    return vPortFree(ptr);
+    vPortFree(ptr);
 }
 
 void* IRAM_ATTR _realloc_r(struct _reent *r, void* ptr, size_t size)
 {
-       void* new_chunk;
-       if (size == 0) {
-               if (ptr) {
-                       vPortFree(ptr);
-               }
-               return NULL;
-       }
+    void* new_chunk;
+    if (size == 0) {
+        if (ptr) {
+            vPortFree(ptr);
+        }
+        return NULL;
+    }
 
-       new_chunk = pvPortMalloc(size);
-       if (new_chunk && ptr) {
-               memcpy(new_chunk, ptr, size);
-               vPortFree(ptr);
-       }
-       // realloc behaviour: don't free original chunk if alloc failed
-       return new_chunk;
+    new_chunk = pvPortMalloc(size);
+    if (new_chunk && ptr) {
+        memcpy(new_chunk, ptr, size);
+        vPortFree(ptr);
+    }
+    // realloc behaviour: don't free original chunk if alloc failed
+    return new_chunk;
 }
 
 void* IRAM_ATTR _calloc_r(struct _reent *r, size_t count, size_t size)
@@ -65,7 +65,7 @@ void* IRAM_ATTR _calloc_r(struct _reent *r, size_t count, size_t size)
     void* result = pvPortMalloc(count * size);
     if (result)
     {
-       memset(result, 0, count * size);
+        memset(result, 0, count * size);
     }
     return result;
 }
index cb2efb4e196f22ba857317ce9f07c8ef27ab0193..021b29545116d3fa408b0c9738ba83b0d5f3b826 100644 (file)
@@ -31,5 +31,5 @@ clock_t _times_r(struct _reent *r, struct tms *ptms)
 int _gettimeofday_r(struct _reent *r, struct timeval *tv, void *tz)
 {
     __errno_r(r) = ENOSYS;
-    return (clock_t) -1;
+    return -1;
 }
index 21b687e78eeda0857193f4efe76c6b600357e9de..c58161c900260586c4b9f159e17524dd3fea1259 100644 (file)
@@ -8,7 +8,7 @@ Virtual filesystem (VFS) component provides a unified interface for drivers whic
 
 This component allows C library functions, such as fopen and fprintf, to work with FS drivers. At high level, each FS driver is associated with some path prefix. When one of C library functions needs to open a file, VFS component searches for the FS driver associated with the file's path, and forwards the call to that driver. VFS also forwards read, write, and other calls for the given file to the same FS driver.
 
-For example, one can register a FAT filesystem driver with ``/fat`` prefix, and call ``fopen("/fat/file.txt", "w")``. VFS component will the call ``open`` function of FAT driver and pass ``/file.txt`` argument to it (and appropriate mode flags). All subsequent calls to C library functions for the returned ``FILE*`` stream will also be forwarded to the FAT driver.
+For example, one can register a FAT filesystem driver with ``/fat`` prefix, and call ``fopen("/fat/file.txt", "w")``. VFS component will then call ``open`` function of FAT driver and pass ``/file.txt`` argument to it (and appropriate mode flags). All subsequent calls to C library functions for the returned ``FILE*`` stream will also be forwarded to the FAT driver.
 
 FS registration
 ---------------
@@ -32,7 +32,7 @@ To register an FS driver, application needs to define in instance of esp_vfs_t s
 
     ESP_ERROR_CHECK(esp_vfs_register("/data", &myfs, NULL));
 
-Depending on the way FS driver declares it's APIs, either ``read``, ``write``, etc., or ``read_p``, ``write_p``, etc. should be used.
+Depending on the way FS driver declares its APIs, either ``read``, ``write``, etc., or ``read_p``, ``write_p``, etc. should be used.
 
 Case 1: API functions are declared without an extra context pointer (FS driver is a singleton)::
 
@@ -41,7 +41,7 @@ Case 1: API functions are declared without an extra context pointer (FS driver i
     // In definition of esp_vfs_t:
         .flags = ESP_VFS_FLAG_DEFAULT,
         .write = &myfs_write,
-    // ... other member initialized
+    // ... other members initialized
     
     // When registering FS, context pointer (third argument) is NULL:
     ESP_ERROR_CHECK(esp_vfs_register("/data", &myfs, NULL));
@@ -53,15 +53,15 @@ Case 2: API functions are declared with an extra context pointer (FS driver supp
     // In definition of esp_vfs_t:
         .flags = ESP_VFS_FLAG_CONTEXT_PTR,
         .write_p = &myfs_write,
-    // ... other member initialized
+    // ... other members initialized
     
     // When registering FS, pass the FS context pointer into the third argument
     // (hypothetical myfs_mount function is used for illustrative purposes)
-    myfs_t* myfs_inst1 = myfs_mount(partition1->offset, parition1->size);
+    myfs_t* myfs_inst1 = myfs_mount(partition1->offset, partition1->size);
     ESP_ERROR_CHECK(esp_vfs_register("/data1", &myfs, myfs_inst1));
 
     // Can register another instance:
-    myfs_t* myfs_inst2 = myfs_mount(partition2->offset, parition2->size);
+    myfs_t* myfs_inst2 = myfs_mount(partition2->offset, partition2->size);
     ESP_ERROR_CHECK(esp_vfs_register("/data2", &myfs, myfs_inst2));
 
 Paths
@@ -79,7 +79,12 @@ This **will not work** as expected:
 - FS 1 on /data
 - FS 2 on /data/fs2
 
-When opening files, FS driver will only be given relative path to files. If the ``myfs`` driver is registered with ``/data`` as prefix, and application calls ``fopen("/data/config.json", ...)``, VFS component will call ``myfs_open("/config.json", ...)``.
+When opening files, FS driver will only be given relative path to files. For example:
+
+- ``myfs`` driver is registered with ``/data`` as path prefix
+- and application calls ``fopen("/data/config.json", ...)``
+- then VFS component will call ``myfs_open("/config.json", ...)``.
+- ``myfs`` driver will open ``/config.json`` file
 
 VFS doesn't impose a limit on total file path length, but it does limit FS path prefix to ``ESP_VFS_PATH_MAX`` characters. Individual FS drivers may have their own filename length limitations.
 
index 6eb63d852c0de1894d8e351b7223640b914b3708..bb2579ee0a00a5c2f960e733e040b53d0ee9a843 100644 (file)
@@ -12,8 +12,8 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-#ifndef __ESP_VFS_H__
-#define __ESP_VFS_H__
+#ifndef __ESP_VFS_DEV_H__
+#define __ESP_VFS_DEV_H__
 
 #include "esp_vfs.h"
 
@@ -25,4 +25,4 @@
 void esp_vfs_dev_uart_register();
 
 
-#endif //__ESP_VFS_H__
+#endif //__ESP_VFS_DEV_H__