Commit e49f2bb1 authored by Johny Mattsson's avatar Johny Mattsson
Browse files

Remove conflicting libc, rename c_xx and os_xx to xx.

c_strtod and c_getenv are kept since strtod doesn't appear in the SDK's libc,
and we want our own c_getenv to initialize the Lua main anyway.
parent 3a3e9ee0
...@@ -501,7 +501,7 @@ static s32_t spiffs_page_consistency_check_i(spiffs *fs) { ...@@ -501,7 +501,7 @@ static s32_t spiffs_page_consistency_check_i(spiffs *fs) {
while (pix_offset < SPIFFS_PAGES_PER_BLOCK(fs) * fs->block_count) { while (pix_offset < SPIFFS_PAGES_PER_BLOCK(fs) * fs->block_count) {
// set this flag to abort all checks and rescan the page range // set this flag to abort all checks and rescan the page range
u8_t restart = 0; u8_t restart = 0;
c_memset(fs->work, 0, SPIFFS_CFG_LOG_PAGE_SZ(fs)); memset(fs->work, 0, SPIFFS_CFG_LOG_PAGE_SZ(fs));
spiffs_block_ix cur_block = 0; spiffs_block_ix cur_block = 0;
// build consistency bitmap for id range traversing all blocks // build consistency bitmap for id range traversing all blocks
...@@ -956,7 +956,7 @@ s32_t spiffs_object_index_consistency_check(spiffs *fs) { ...@@ -956,7 +956,7 @@ s32_t spiffs_object_index_consistency_check(spiffs *fs) {
// indicating whether they can be reached or not. Acting as a fifo if object ids cannot fit. // indicating whether they can be reached or not. Acting as a fifo if object ids cannot fit.
// In the temporary object index memory, SPIFFS_OBJ_ID_IX_FLAG bit is used to indicate // In the temporary object index memory, SPIFFS_OBJ_ID_IX_FLAG bit is used to indicate
// a reachable/unreachable object id. // a reachable/unreachable object id.
c_memset(fs->work, 0, SPIFFS_CFG_LOG_PAGE_SZ(fs)); memset(fs->work, 0, SPIFFS_CFG_LOG_PAGE_SZ(fs));
u32_t obj_id_log_ix = 0; u32_t obj_id_log_ix = 0;
if (fs->check_cb_f) fs->check_cb_f(SPIFFS_CHECK_INDEX, SPIFFS_CHECK_PROGRESS, 0, 0); if (fs->check_cb_f) fs->check_cb_f(SPIFFS_CHECK_INDEX, SPIFFS_CHECK_PROGRESS, 0, 0);
res = spiffs_obj_lu_find_entry_visitor(fs, 0, 0, 0, 0, spiffs_object_index_consistency_check_v, 0, &obj_id_log_ix, res = spiffs_obj_lu_find_entry_visitor(fs, 0, 0, 0, 0, spiffs_object_index_consistency_check_v, 0, &obj_id_log_ix,
......
...@@ -9,12 +9,9 @@ ...@@ -9,12 +9,9 @@
#define SPIFFS_CONFIG_H_ #define SPIFFS_CONFIG_H_
#include "user_config.h" #include "user_config.h"
#include "c_stdio.h" #include <stdio.h>
#include "c_stdint.h" #include <stdint.h>
#include "c_string.h" #include <string.h>
// For u32_t etc
#include "user_interface.h"
// compile time switches // compile time switches
...@@ -167,7 +164,7 @@ ...@@ -167,7 +164,7 @@
#endif #endif
#if SPIFFS_TEST_VISUALISATION #if SPIFFS_TEST_VISUALISATION
#ifndef spiffs_printf #ifndef spiffs_printf
#define spiffs_printf(...) c_printf(__VA_ARGS__) #define spiffs_printf(...) printf(__VA_ARGS__)
#endif #endif
// spiffs_printf argument for a free page // spiffs_printf argument for a free page
#ifndef SPIFFS_TEST_VIS_FREE_STR #ifndef SPIFFS_TEST_VIS_FREE_STR
......
...@@ -246,7 +246,7 @@ s32_t spiffs_gc_find_candidate( ...@@ -246,7 +246,7 @@ s32_t spiffs_gc_find_candidate(
// using fs->work area as sorted candidate memory, (spiffs_block_ix)cand_bix/(s32_t)score // using fs->work area as sorted candidate memory, (spiffs_block_ix)cand_bix/(s32_t)score
int max_candidates = MIN(fs->block_count, (SPIFFS_CFG_LOG_PAGE_SZ(fs)-8)/(sizeof(spiffs_block_ix) + sizeof(s32_t))); int max_candidates = MIN(fs->block_count, (SPIFFS_CFG_LOG_PAGE_SZ(fs)-8)/(sizeof(spiffs_block_ix) + sizeof(s32_t)));
*candidate_count = 0; *candidate_count = 0;
c_memset(fs->work, 0xff, SPIFFS_CFG_LOG_PAGE_SZ(fs)); memset(fs->work, 0xff, SPIFFS_CFG_LOG_PAGE_SZ(fs));
// divide up work area into block indices and scores // divide up work area into block indices and scores
// todo alignment? // todo alignment?
...@@ -385,7 +385,7 @@ s32_t spiffs_gc_clean(spiffs *fs, spiffs_block_ix bix) { ...@@ -385,7 +385,7 @@ s32_t spiffs_gc_clean(spiffs *fs, spiffs_block_ix bix) {
SPIFFS_GC_DBG("gc_clean: cleaning block %i\n", bix); SPIFFS_GC_DBG("gc_clean: cleaning block %i\n", bix);
c_memset(&gc, 0, sizeof(spiffs_gc)); memset(&gc, 0, sizeof(spiffs_gc));
gc.state = FIND_OBJ_DATA; gc.state = FIND_OBJ_DATA;
if (fs->free_cursor_block_ix == bix) { if (fs->free_cursor_block_ix == bix) {
......
...@@ -56,12 +56,12 @@ s32_t SPIFFS_mount(spiffs *fs, spiffs_config *config, u8_t *work, ...@@ -56,12 +56,12 @@ s32_t SPIFFS_mount(spiffs *fs, spiffs_config *config, u8_t *work,
void *cache, u32_t cache_size, void *cache, u32_t cache_size,
spiffs_check_callback check_cb_f) { spiffs_check_callback check_cb_f) {
SPIFFS_LOCK(fs); SPIFFS_LOCK(fs);
c_memset(fs, 0, sizeof(spiffs)); memset(fs, 0, sizeof(spiffs));
c_memcpy(&fs->cfg, config, sizeof(spiffs_config)); memcpy(&fs->cfg, config, sizeof(spiffs_config));
fs->block_count = SPIFFS_CFG_PHYS_SZ(fs) / SPIFFS_CFG_LOG_BLOCK_SZ(fs); fs->block_count = SPIFFS_CFG_PHYS_SZ(fs) / SPIFFS_CFG_LOG_BLOCK_SZ(fs);
fs->work = &work[0]; fs->work = &work[0];
fs->lu_work = &work[SPIFFS_CFG_LOG_PAGE_SZ(fs)]; fs->lu_work = &work[SPIFFS_CFG_LOG_PAGE_SZ(fs)];
c_memset(fd_space, 0, fd_space_size); memset(fd_space, 0, fd_space_size);
// align fd_space pointer to pointer size byte boundary, below is safe // align fd_space pointer to pointer size byte boundary, below is safe
u8_t ptr_size = sizeof(void*); u8_t ptr_size = sizeof(void*);
#pragma GCC diagnostic push #pragma GCC diagnostic push
...@@ -407,7 +407,7 @@ s32_t SPIFFS_write(spiffs *fs, spiffs_file fh, void *buf, s32_t len) { ...@@ -407,7 +407,7 @@ s32_t SPIFFS_write(spiffs *fs, spiffs_file fh, void *buf, s32_t len) {
offset, offset_in_cpage, len); offset, offset_in_cpage, len);
spiffs_cache *cache = spiffs_get_cache(fs); spiffs_cache *cache = spiffs_get_cache(fs);
u8_t *cpage_data = spiffs_get_cache_page(fs, cache, fd->cache_page->ix); u8_t *cpage_data = spiffs_get_cache_page(fs, cache, fd->cache_page->ix);
c_memcpy(&cpage_data[offset_in_cpage], buf, len); memcpy(&cpage_data[offset_in_cpage], buf, len);
fd->cache_page->size = MAX(fd->cache_page->size, offset_in_cpage + len); fd->cache_page->size = MAX(fd->cache_page->size, offset_in_cpage + len);
fd->fdoffset += len; fd->fdoffset += len;
SPIFFS_UNLOCK(fs); SPIFFS_UNLOCK(fs);
......
...@@ -990,8 +990,8 @@ s32_t spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) { ...@@ -990,8 +990,8 @@ s32_t spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
SPIFFS_CHECK_RES(res); SPIFFS_CHECK_RES(res);
spiffs_cb_object_event(fs, fd, SPIFFS_EV_IX_NEW, fd->obj_id, cur_objix_spix, cur_objix_pix, 0); spiffs_cb_object_event(fs, fd, SPIFFS_EV_IX_NEW, fd->obj_id, cur_objix_spix, cur_objix_pix, 0);
// quick "load" of new object index page // quick "load" of new object index page
c_memset(fs->work, 0xff, SPIFFS_CFG_LOG_PAGE_SZ(fs)); memset(fs->work, 0xff, SPIFFS_CFG_LOG_PAGE_SZ(fs));
c_memcpy(fs->work, &p_hdr, sizeof(spiffs_page_header)); memcpy(fs->work, &p_hdr, sizeof(spiffs_page_header));
SPIFFS_DBG("append: %04x create objix page, %04x:%04x, written %i\n", fd->obj_id SPIFFS_DBG("append: %04x create objix page, %04x:%04x, written %i\n", fd->obj_id
, cur_objix_pix, cur_objix_spix, written); , cur_objix_pix, cur_objix_spix, written);
} else { } else {
...@@ -1575,7 +1575,7 @@ s32_t spiffs_object_truncate( ...@@ -1575,7 +1575,7 @@ s32_t spiffs_object_truncate(
} else { } else {
// make uninitialized object // make uninitialized object
SPIFFS_DBG("truncate: reset objix_hdr page %04x\n", objix_pix); SPIFFS_DBG("truncate: reset objix_hdr page %04x\n", objix_pix);
c_memset(fs->work + sizeof(spiffs_page_object_ix_header), 0xff, memset(fs->work + sizeof(spiffs_page_object_ix_header), 0xff,
SPIFFS_CFG_LOG_PAGE_SZ(fs) - sizeof(spiffs_page_object_ix_header)); SPIFFS_CFG_LOG_PAGE_SZ(fs) - sizeof(spiffs_page_object_ix_header));
res = spiffs_object_update_index_hdr(fs, fd, fd->obj_id, res = spiffs_object_update_index_hdr(fs, fd, fd->obj_id,
objix_pix, fs->work, 0, SPIFFS_UNDEFINED_LEN, &new_objix_hdr_pix); objix_pix, fs->work, 0, SPIFFS_UNDEFINED_LEN, &new_objix_hdr_pix);
...@@ -1783,7 +1783,7 @@ s32_t spiffs_obj_lu_find_free_obj_id(spiffs *fs, spiffs_obj_id *obj_id, u8_t *co ...@@ -1783,7 +1783,7 @@ s32_t spiffs_obj_lu_find_free_obj_id(spiffs *fs, spiffs_obj_id *obj_id, u8_t *co
u32_t i, j; u32_t i, j;
SPIFFS_DBG("free_obj_id: BITM min:%04x max:%04x\n", state.min_obj_id, state.max_obj_id); SPIFFS_DBG("free_obj_id: BITM min:%04x max:%04x\n", state.min_obj_id, state.max_obj_id);
c_memset(fs->work, 0, SPIFFS_CFG_LOG_PAGE_SZ(fs)); memset(fs->work, 0, SPIFFS_CFG_LOG_PAGE_SZ(fs));
res = spiffs_obj_lu_find_entry_visitor(fs, 0, 0, 0, 0, spiffs_obj_lu_find_free_obj_id_bitmap_v, state.min_obj_id, res = spiffs_obj_lu_find_entry_visitor(fs, 0, 0, 0, 0, spiffs_obj_lu_find_free_obj_id_bitmap_v, state.min_obj_id,
conflicting_name, 0, 0); conflicting_name, 0, 0);
if (res == SPIFFS_VIS_END) res = SPIFFS_OK; if (res == SPIFFS_VIS_END) res = SPIFFS_OK;
...@@ -1848,7 +1848,7 @@ s32_t spiffs_obj_lu_find_free_obj_id(spiffs *fs, spiffs_obj_id *obj_id, u8_t *co ...@@ -1848,7 +1848,7 @@ s32_t spiffs_obj_lu_find_free_obj_id(spiffs *fs, spiffs_obj_id *obj_id, u8_t *co
state.compaction = (state.max_obj_id-state.min_obj_id) / ((SPIFFS_CFG_LOG_PAGE_SZ(fs) / sizeof(u8_t))); state.compaction = (state.max_obj_id-state.min_obj_id) / ((SPIFFS_CFG_LOG_PAGE_SZ(fs) / sizeof(u8_t)));
SPIFFS_DBG("free_obj_id: COMP min:%04x max:%04x compact:%i\n", state.min_obj_id, state.max_obj_id, state.compaction); SPIFFS_DBG("free_obj_id: COMP min:%04x max:%04x compact:%i\n", state.min_obj_id, state.max_obj_id, state.compaction);
c_memset(fs->work, 0, SPIFFS_CFG_LOG_PAGE_SZ(fs)); memset(fs->work, 0, SPIFFS_CFG_LOG_PAGE_SZ(fs));
res = spiffs_obj_lu_find_entry_visitor(fs, 0, 0, 0, 0, spiffs_obj_lu_find_free_obj_id_compact_v, 0, &state, 0, 0); res = spiffs_obj_lu_find_entry_visitor(fs, 0, 0, 0, 0, spiffs_obj_lu_find_free_obj_id_compact_v, 0, &state, 0, 0);
if (res == SPIFFS_VIS_END) res = SPIFFS_OK; if (res == SPIFFS_VIS_END) res = SPIFFS_OK;
SPIFFS_CHECK_RES(res); SPIFFS_CHECK_RES(res);
......
...@@ -6,69 +6,29 @@ ...@@ -6,69 +6,29 @@
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
#include <string.h> #include <string.h>
#define ICACHE_RODATA_ATTR #define true 1
#define TRUE 1 #define false 0
#define FALSE 0
#else #else
#include "c_stdlib.h" #include <ctype.h>
#include "c_types.h" #include <string.h>
#include "c_string.h" #include <stdbool.h>
// const char *lua_init_value = "print(\"Hello world\")";
const char *lua_init_value = "@init.lua"; const char *lua_init_value = "@init.lua";
// int c_abs(int x){
// return x>0?x:0-x;
// }
// void c_exit(int e){
// }
const char *c_getenv(const char *__string) const char *c_getenv(const char *__string)
{ {
if (c_strcmp(__string, "LUA_INIT") == 0) if (strcmp(__string, "LUA_INIT") == 0)
{ {
return lua_init_value; return lua_init_value;
} }
return NULL; return NULL;
} }
// make sure there is enough memory before real malloc, otherwise malloc will panic and reset
// void *c_malloc(size_t __size){
// if(__size>system_get_free_heap_size()){
// NODE_ERR("malloc: not enough memory\n");
// return NULL;
// }
// return (void *)os_malloc(__size);
// }
// void *c_zalloc(size_t __size){
// if(__size>system_get_free_heap_size()){
// NODE_ERR("zalloc: not enough memory\n");
// return NULL;
// }
// return (void *)os_zalloc(__size);
// }
// void c_free(void *p){
// // NODE_ERR("free1: %d\n", system_get_free_heap_size());
// os_free(p);
// // NODE_ERR("-free1: %d\n", system_get_free_heap_size());
// }c_stdlib.s
// int c_rand(void){
// }
// void c_srand(unsigned int __seed){
// }
// int c_atoi(const char *__nptr){
// }
#include <_ansi.h>
//#include <reent.h>
//#include "mprec.h"
#endif #endif
double powersOf10[] ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = /* Table giving binary powers of 10. Entry */
const double powersOf10[] = /* Table giving binary powers of 10. Entry */
{ {
10., /* is 10^2^i. Used to convert decimal */ 10., /* is 10^2^i. Used to convert decimal */
100., /* exponents into floating-point numbers. */ 100., /* exponents into floating-point numbers. */
...@@ -89,8 +49,9 @@ double c_strtod(const char *string, char **endPtr) ...@@ -89,8 +49,9 @@ double c_strtod(const char *string, char **endPtr)
* no need to worry about additional digits. * no need to worry about additional digits.
*/ */
int sign, expSign = FALSE; int sign, expSign = false;
double fraction, dblExp, *d; double fraction, dblExp;
const double *d;
register const char *p; register const char *p;
register int c; register int c;
int exp = 0; /* Exponent read from "EX" field. */ int exp = 0; /* Exponent read from "EX" field. */
...@@ -120,7 +81,7 @@ double c_strtod(const char *string, char **endPtr) ...@@ -120,7 +81,7 @@ double c_strtod(const char *string, char **endPtr)
} }
if (*p == '-') if (*p == '-')
{ {
sign = TRUE; sign = true;
p += 1; p += 1;
} }
else else
...@@ -129,7 +90,7 @@ double c_strtod(const char *string, char **endPtr) ...@@ -129,7 +90,7 @@ double c_strtod(const char *string, char **endPtr)
{ {
p += 1; p += 1;
} }
sign = FALSE; sign = false;
} }
/* /*
...@@ -224,7 +185,7 @@ double c_strtod(const char *string, char **endPtr) ...@@ -224,7 +185,7 @@ double c_strtod(const char *string, char **endPtr)
p += 1; p += 1;
if (*p == '-') if (*p == '-')
{ {
expSign = TRUE; expSign = true;
p += 1; p += 1;
} }
else else
...@@ -233,7 +194,7 @@ double c_strtod(const char *string, char **endPtr) ...@@ -233,7 +194,7 @@ double c_strtod(const char *string, char **endPtr)
{ {
p += 1; p += 1;
} }
expSign = FALSE; expSign = false;
} }
if (!isdigit((unsigned char)(*p))) if (!isdigit((unsigned char)(*p)))
{ {
...@@ -264,12 +225,12 @@ double c_strtod(const char *string, char **endPtr) ...@@ -264,12 +225,12 @@ double c_strtod(const char *string, char **endPtr)
if (exp < 0) if (exp < 0)
{ {
expSign = TRUE; expSign = true;
exp = -exp; exp = -exp;
} }
else else
{ {
expSign = FALSE; expSign = false;
} }
if (exp > maxExponent) if (exp > maxExponent)
{ {
...@@ -305,10 +266,3 @@ done: ...@@ -305,10 +266,3 @@ done:
} }
return fraction; return fraction;
} }
// long c_strtol(const char *__n, char **__end_PTR, int __base){
// }
// unsigned long c_strtoul(const char *__n, char **__end_PTR, int __base){
// }
// long long c_strtoll(const char *__n, char **__end_PTR, int __base){
// }
...@@ -10,12 +10,13 @@ ...@@ -10,12 +10,13 @@
*******************************************************************************/ *******************************************************************************/
#include "lua.h" #include "lua.h"
#include "platform.h" #include "platform.h"
#include "c_string.h" #include <string.h>
#include "c_stdlib.h" #include <stdlib.h>
#include "flash_fs.h" #include "flash_fs.h"
#include "flash_api.h" #include "flash_api.h"
#include "user_interface.h" #include "user_interface.h"
#include "user_modules.h" #include "user_modules.h"
#include "rom.h"
#include "ets_sys.h" #include "ets_sys.h"
#include "driver/uart.h" #include "driver/uart.h"
...@@ -29,9 +30,9 @@ ...@@ -29,9 +30,9 @@
#define SIG_LUA 0 #define SIG_LUA 0
#define SIG_UARTINPUT 1 #define SIG_UARTINPUT 1
#define TASK_QUEUE_LEN 4
static os_event_t *taskQueue; extern void call_user_start (void);
/* Note: the trampoline *must* be explicitly put into the .text segment, since /* Note: the trampoline *must* be explicitly put into the .text segment, since
* by the time it is invoked the irom has not yet been mapped. This naturally * by the time it is invoked the irom has not yet been mapped. This naturally
......
...@@ -5,9 +5,7 @@ ...@@ -5,9 +5,7 @@
void *pvPortZalloc (size_t sz); void *pvPortZalloc (size_t sz);
void *pvPortRealloc (void *p, size_t sz); void *pvPortRealloc (void *p, size_t sz);
#define os_zalloc pvPortZalloc #include "esp_libc.h"
#define os_free vPortFree
#define os_malloc pvPortMalloc
#include_next "lwip/mem.h" #include_next "lwip/mem.h"
......
#ifndef _SDK_OVERRIDES_STDLIB_H_
#define _SDK_OVERRIDES_STDLIB_H_
extern const char *c_getenv (const char *);
extern double c_strtod(const char *string, char **endPtr);
#include_next <stdlib.h>
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment