feat(vfs): Modify for esp8266

This commit is contained in:
dongheng
2019-03-07 14:58:44 +08:00
parent e36706d776
commit d11543400e
25 changed files with 225 additions and 51 deletions

View File

@ -1,3 +1,6 @@
#pragma once
#include <sys/socket.h>
#undef fcntl

View File

@ -1,13 +0,0 @@
/* <dirent.h> includes <sys/dirent.h>, which is this file. On a
system which supports <dirent.h>, this file is overridden by
dirent.h in the libc/sys/.../sys directory. On a system which does
not support <dirent.h>, we will get this file which uses #error to force
an error. */
#ifdef __cplusplus
extern "C" {
#endif
//#error "<dirent.h> not supported"
#ifdef __cplusplus
}
#endif

View File

@ -12,11 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "sdkconfig.h"
#include <reent.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#ifdef CONFIG_USING_ESP_VFS
#include "esp_vfs_dev.h"
#endif
/*
* @brief Initialize global and thread's private reent object data. We add this instead of
@ -47,15 +51,19 @@ int esp_newlib_init(void)
{
esp_reent_init(_global_impure_ptr);
_GLOBAL_REENT->_stdout = fopen("uart/0", "w");
#ifdef CONFIG_USING_ESP_VFS
esp_vfs_dev_uart_register();
#endif
_GLOBAL_REENT->_stdout = fopen("/dev/uart/0", "w");
if (!_GLOBAL_REENT->_stdout)
goto err;
_GLOBAL_REENT->_stderr = fopen("uart/0", "w");
_GLOBAL_REENT->_stderr = fopen("/dev/uart/0", "w");
if (!_GLOBAL_REENT->_stderr)
goto err_fail;
_GLOBAL_REENT->_stdin = fopen("uart/0", "r");
_GLOBAL_REENT->_stdin = fopen("/dev/uart/0", "r");
if (!_GLOBAL_REENT->_stdin)
goto err_in;

View File

@ -0,0 +1,42 @@
// Copyright 2018 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.
#ifndef __ESP_SYS_SELECT_H__
#define __ESP_SYS_SELECT_H__
#include "sdkconfig.h"
#ifdef CONFIG_USING_ESP_VFS
#include <sys/types.h>
#include <sys/time.h>
#ifdef __cplusplus
extern "C" {
#endif
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *timeout);
#ifdef __cplusplus
} // extern "C"
#endif
#else
#include "lwip/sockets.h"
#endif
#endif //__ESP_SYS_SELECT_H__

View File

@ -16,6 +16,7 @@
#include "esp_vfs.h"
#include "sdkconfig.h"
#ifdef CONFIG_USING_ESP_VFS
#ifdef CONFIG_USE_ONLY_LWIP_SELECT
#include "lwip/sockets.h"
@ -62,3 +63,4 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct
return esp_vfs_select(nfds, readfds, writefds, errorfds, timeout);
#endif
}
#endif /* CONFIG_USING_ESP_VFS */

View File

@ -22,6 +22,57 @@
#include "FreeRTOS.h"
#include "esp_log.h"
#ifdef CONFIG_USING_ESP_VFS
#include "esp_vfs.h"
int _open_r(struct _reent *r, const char *filename, int flags, int mode)
{
return esp_vfs_open(r, filename, flags, mode);
}
_ssize_t _read_r(struct _reent *r, int fd, void *buf, size_t len)
{
return esp_vfs_read(r, fd, buf, len);
}
_ssize_t _write_r(struct _reent *r, int fd, const void *buf, size_t len)
{
return esp_vfs_write(r, fd, buf, len);
}
_off_t _lseek_r(struct _reent *r, int fd, _off_t where, int whence)
{
return esp_vfs_lseek(r, fd, where, whence);
}
int _close_r(struct _reent *r, int fd)
{
return esp_vfs_close(r, fd);
}
int _rename_r(struct _reent *r, const char *from, const char *to)
{
return esp_vfs_rename(r, from, to);
}
int _unlink_r(struct _reent *r, const char *filename)
{
return esp_vfs_unlink(r, filename);
}
int _fstat_r(struct _reent *r, int fd, struct stat *s)
{
return esp_vfs_fstat(r, fd, s);
}
int _stat_r(struct _reent *r, const char *path, struct stat *st)
{
return esp_vfs_stat(r, path, st);
}
#else
int _open_r(struct _reent *r, const char *filename, int flags, int mode)
{
return 0;
@ -70,11 +121,13 @@ int _fstat_r(struct _reent *r, int fd, struct stat *s)
return 0;
}
void *_sbrk_r(struct _reent *r, ptrdiff_t incr)
int _stat_r(struct _reent *r, const char *path, struct stat *st)
{
return NULL;
return 0;
}
#endif /* CONFIG_USING_ESP_VFS */
void *_malloc_r(struct _reent *r, size_t n)
{
void *return_addr = (void *)__builtin_return_address(0);
@ -103,11 +156,6 @@ void _free_r(struct _reent *r, void *ptr)
_heap_caps_free(ptr, return_addr, 0);
}
void _exit(int status)
{
while (1);
}
void abort(void)
{
ESP_LOGE("ABORT","Error found and abort!");
@ -116,4 +164,14 @@ void abort(void)
while (1) {
*((int *)NULL) = 0;
}
}
}
void _exit(int status)
{
abort();
}
void *_sbrk_r(struct _reent *r, ptrdiff_t incr)
{
abort();
}