Fix some compilation warnings and add esp-idf platform for experiment (#454)

And fix some code indent issues.
This commit is contained in:
Wenyong Huang
2020-11-30 16:03:51 +08:00
committed by GitHub
parent 7d8b79a7a7
commit 282831eba5
35 changed files with 342 additions and 363 deletions

View File

@ -0,0 +1,122 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "platform_api_vmcore.h"
#include "platform_api_extension.h"
int errno = 0;
int
os_thread_sys_init();
void
os_thread_sys_destroy();
int
bh_platform_init()
{
return os_thread_sys_init();
}
void
bh_platform_destroy()
{
os_thread_sys_destroy();
}
int os_printf(const char *format, ...)
{
int ret = 0;
va_list ap;
va_start(ap, format);
ret += vprintf(format, ap);
va_end(ap);
return ret;
}
int
os_vprintf(const char *format, va_list ap)
{
return vprintf(format, ap);
}
void *
os_mmap(void *hint, size_t size, int prot, int flags)
{
return BH_MALLOC(size);
}
void
os_munmap(void *addr, size_t size)
{
BH_FREE(addr);
}
int
os_mprotect(void *addr, size_t size, int prot)
{
return 0;
}
void
os_dcache_flush()
{
}
int
atoi(const char *nptr)
{
bool is_negative = false;
int total = 0;
const char *p = nptr;
char temp = '0';
if (NULL == p) {
os_printf("invlaid atoi input\n");
return 0;
}
if (*p == '-') {
is_negative = true;
p++;
}
while ((temp = *p++) != '\0') {
if (temp > '9' || temp < '0') {
continue;
}
total = total * 10 + (int)(temp - '0');
}
if (is_negative)
total = 0 - total;
return total;
}
void *
memmove(void *dest, const void *src, size_t n)
{
char *d = dest;
const char *s = src;
if (d < s) {
while (n--)
*d++ = *s++;
}
else {
const char *lasts = s + (n-1);
char *lastd = d + (n-1);
while (n--)
*lastd-- = *lasts--;
}
return dest;
}

View File

@ -0,0 +1,14 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "platform_api_vmcore.h"
#include "platform_api_extension.h"
uint8 *os_thread_get_stack_boundary()
{
/* TODO: implement os_thread_get_stack_boundary */
return NULL;
}

View File

@ -0,0 +1,97 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _PLATFORM_INTERNAL_H
#define _PLATFORM_INTERNAL_H
#include <stdint.h>
#include <stdarg.h>
#include <stdbool.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <FreeRTOS.h>
#include <semphr.h>
#include <task.h>
#include <os_api.h>
#ifndef BH_PLATFORM_ESP_IDF
#define BH_PLATFORM_ESP_IDF
#endif
#define BH_APPLET_PRESERVED_STACK_SIZE (2 * BH_KB)
/* Default thread priority */
#define BH_THREAD_DEFAULT_PRIORITY 5
extern int errno;
typedef TaskHandle_t korp_thread;
typedef korp_thread korp_tid;
typedef struct {
bool is_recursive;
SemaphoreHandle_t sem;
} korp_mutex;
struct os_thread_wait_node;
typedef struct os_thread_wait_node *os_thread_wait_list;
typedef struct korp_cond {
SemaphoreHandle_t wait_list_lock;
os_thread_wait_list thread_wait_list;
} korp_cond;
int os_printf(const char *format, ...);
int os_vprintf(const char *format, va_list ap);
/* math functions which are not provided by os */
double sqrt(double x);
double floor(double x);
double ceil(double x);
double fmin(double x, double y);
double fmax(double x, double y);
double rint(double x);
double fabs(double x);
double trunc(double x);
float floorf(float x);
float ceilf(float x);
float fminf(float x, float y);
float fmaxf(float x, float y);
float rintf(float x);
float truncf(float x);
int signbit(double x);
int isnan(double x);
int atoi(const char *s);
int strncasecmp(const char *s1, const char *s2, size_t n);
long int strtol(const char *str, char **endptr, int base);
unsigned long int strtoul(const char *str, char **endptr, int base);
unsigned long long int strtoull(const char *nptr, char **endptr, int base);
double strtod(const char *nptr, char **endptr);
float strtof(const char *nptr, char **endptr);
char *strstr(const char *haystack, const char *needle);
size_t strspn(const char *s, const char *accept);
size_t strcspn(const char *s, const char *reject);
void *memchr(const void *s, int c, size_t n);
int isalnum(int c);
int isxdigit(int c);
int isdigit(int c);
int isprint(int c);
int isgraph(int c);
int isspace(int c);
int isalpha(int c);
int isupper(int c);
int toupper(int c);
int tolower(int c);
void *memmove(void *dest, const void *src, size_t n);
uint32_t htonl(uint32_t hostlong);
uint16_t htons(uint16_t hostshort);
uint32_t ntohl(uint32_t netlong);
uint16_t ntohs(uint16_t netshort);
#endif

View File

@ -0,0 +1,19 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
set (PLATFORM_SHARED_DIR ${CMAKE_CURRENT_LIST_DIR})
add_definitions(-DBH_PLATFORM_ESP_IDF)
include_directories(${PLATFORM_SHARED_DIR})
include_directories(${PLATFORM_SHARED_DIR}/../include)
include (${CMAKE_CURRENT_LIST_DIR}/../common/freertos/platform_api_freertos.cmake)
include (${CMAKE_CURRENT_LIST_DIR}/../common/math/platform_api_math.cmake)
file (GLOB_RECURSE source_all ${PLATFORM_SHARED_DIR}/*.c)
set (PLATFORM_SHARED_SOURCE ${source_all}
${PLATFORM_COMMON_MATH_SOURCE}
${PLATFORM_COMMON_FREERTOS_SOURCE})