[update][utils] update api

This commit is contained in:
jzlv 2022-10-29 16:12:43 +08:00
parent 011ffb8821
commit b53a02f2c9
11 changed files with 457 additions and 146 deletions

View File

@ -28,7 +28,7 @@
#include "bflog.h"
/*!< param check enable */
#define BFLOG_DEBUG_ENABLE
#define CONFIG_BFLOG_DEBUG
/*!< log enable */
#define BFLOG_ENABLE

View File

@ -64,12 +64,12 @@ void bflog_restart(void)
void *direct0 = (void *)&bflog_direct_filetime;
void *direct1 = (void *)&bflog_direct_filesize;
bflog_direct_create(direct0, BFLOG_DIRECT_TYPE_FILE_TIME, BFLOG_DIRECT_COLOR_DISABLE);
bflog_direct_init_file_time(direct0, "sd:/log/common", 60, 42, NULL, NULL);
bflog_direct_create(direct0, BFLOG_DIRECT_TYPE_FILE_TIME, BFLOG_DIRECT_COLOR_DISABLE, NULL, NULL);
bflog_direct_init_file_time_s(direct0, "sd:/log/common", 60, 42);
bflog_direct_create(direct1, BFLOG_DIRECT_TYPE_FILE_SIZE, BFLOG_DIRECT_COLOR_DISABLE);
bflog_direct_init_file_size(direct1, "sd:/log/error", 128 * 1024, 16, NULL, NULL);
bflog_direct_control(direct1, BFLOG_DIRECT_CMD_LEVEL, BFLOG_LEVEL_WARN);
bflog_direct_create(direct1, BFLOG_DIRECT_TYPE_FILE_SIZE, BFLOG_DIRECT_COLOR_DISABLE, NULL, NULL);
bflog_direct_init_file_size_s(direct1, "sd:/log/error", 128 * 1024, 16);
bflog_direct_control_s(direct1, BFLOG_DIRECT_CMD_LEVEL, BFLOG_LEVEL_WARN);
/*!< suspend record */
bflog_suspend_s(record);

View File

@ -1,58 +1,91 @@
sdk_generate_library()
if(CONFIG_LOG_DISABLE)
sdk_add_compile_definitions(-DCONFIG_LOG_DISABLE)
sdk_add_compile_definitions(-DCONFIG_LOG_DISABLE)
endif()
if(CONFIG_ASSERT_DISABLE)
sdk_add_compile_definitions(-DCONFIG_ASSERT_DISABLE)
sdk_add_compile_definitions(-DCONFIG_ASSERT_DISABLE)
endif()
if(DEFINED CONFIG_LOG_LEVEL)
sdk_add_compile_definitions(-DCONFIG_LOG_LEVEL=${CONFIG_LOG_LEVEL})
sdk_add_compile_definitions(-DCONFIG_LOG_LEVEL=${CONFIG_LOG_LEVEL})
else()
sdk_add_compile_definitions(-DCONFIG_LOG_LEVEL=3)
sdk_add_compile_definitions(-DCONFIG_LOG_LEVEL=3)
endif()
# vsnprintf config
if(CONFIG_VSNPRINTF_FLOAT)
sdk_add_compile_definitions(-DVLIBC_FLOAT=${CONFIG_VSNPRINTF_FLOAT})
sdk_add_compile_definitions(-DPRINTF_SUPPORT_DECIMAL_SPECIFIERS=${CONFIG_VSNPRINTF_FLOAT})
endif()
if(CONFIG_VSNPRINTF_FLOAT_EX)
sdk_add_compile_definitions(-DVLIBC_FLOAT_EX=${CONFIG_VSNPRINTF_FLOAT_EX})
sdk_add_compile_definitions(-DPRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS=${CONFIG_VSNPRINTF_FLOAT_EX})
endif()
if(CONFIG_VSNPRINTF_LONG_LONG)
sdk_add_compile_definitions(-DVLIBC_LONG_LONG=${CONFIG_VSNPRINTF_LONG_LONG})
sdk_add_compile_definitions(-DPRINTF_SUPPORT_LONG_LONG=${CONFIG_VSNPRINTF_LONG_LONG})
endif()
if(CONFIG_VSNPRINTF_WRITEBACK)
sdk_add_compile_definitions(-DVLIBC_WRITEBACK=${CONFIG_VSNPRINTF_WRITEBACK})
endif()
if(CONFIG_VLIBC)
if(CONFIG_VLIBC_FATFS)
sdk_add_compile_definitions(-DVLIBC_PORT_FATFS)
endif()
sdk_add_compile_definitions(-DVLIBC_DEBUG)
sdk_add_compile_definitions(-Dprintf=vlibc_printf)
sdk_library_add_sources(vlibc/printf.c)
sdk_library_add_sources(vlibc/syscalls.c)
sdk_library_add_sources(vlibc/vlibc_stdio.c)
sdk_library_add_sources(vlibc/vlibc_vsnprintf.c)
sdk_add_include_directories(vlibc)
else()
sdk_add_compile_definitions(-Dprintf=bflb_printf)
sdk_library_add_sources(libc/vsnprintf.c)
sdk_library_add_sources(libc/syscalls.c)
sdk_library_add_sources(libc/printf.c)
endif()
sdk_library_add_sources(mmheap/mmheap.c)
sdk_add_include_directories(mmheap)
# log
sdk_library_add_sources(log/log.c)
sdk_add_include_directories(log)
# vsnprintf config
if(CONFIG_VSNPRINTF_FLOAT)
sdk_add_compile_definitions(-DCONFIG_VLIBC_FLOAT=${CONFIG_VSNPRINTF_FLOAT})
sdk_add_compile_definitions(-DCONFIG_LIBC_FLOAT=${CONFIG_VSNPRINTF_FLOAT})
endif()
if(CONFIG_VSNPRINTF_FLOAT_EX)
sdk_add_compile_definitions(-DCONFIG_VLIBC_FLOAT_EX=${CONFIG_VSNPRINTF_FLOAT_EX})
sdk_add_compile_definitions(-DCONFIG_LIBC_FLOAT_EX=${CONFIG_VSNPRINTF_FLOAT_EX})
endif()
if(CONFIG_VSNPRINTF_LONG_LONG)
sdk_add_compile_definitions(-DCONFIG_VLIBC_LONG_LONG=${CONFIG_VSNPRINTF_LONG_LONG})
sdk_add_compile_definitions(-DCONFIG_LIBC_LONG_LONG=${CONFIG_VSNPRINTF_LONG_LONG})
endif()
if(CONFIG_VSNPRINTF_WRITEBACK)
sdk_add_compile_definitions(-DCONFIG_VLIBC_WRITEBACK=${CONFIG_VSNPRINTF_WRITEBACK})
endif()
# libc or vlibc select
if(CONFIG_VLIBC)
# vlibc debug enable
if (CONFIG_VLIBC_DEBUG)
sdk_add_compile_definitions(-DCONFIG_VLIBC_DEBUG)
endif()
# vlibc fatfs port enable
if(CONFIG_VLIBC_FATFS)
sdk_add_compile_definitions(-DCONFIG_VLIBC_FATFS)
endif()
sdk_add_compile_definitions(-Dprintf=vlibc_printf)
sdk_library_add_sources(vlibc/printf.c)
sdk_library_add_sources(vlibc/syscalls.c)
sdk_library_add_sources(vlibc/vlibc_stdio.c)
sdk_library_add_sources(vlibc/vlibc_vsnprintf.c)
sdk_add_include_directories(vlibc)
else()
sdk_add_compile_definitions(-Dprintf=bflb_printf)
sdk_library_add_sources(libc/vsnprintf.c)
sdk_library_add_sources(libc/syscalls.c)
sdk_library_add_sources(libc/printf.c)
endif()
# memheap
sdk_library_add_sources(mmheap/mmheap.c)
sdk_add_include_directories(mmheap)
# bflb block pool debug enable
if (CONFIG_BFLB_BLOCK_POOL_DEBUG)
sdk_add_compile_definitions(-DCONFIG_BFLB_BLOCK_POOL_DEBUG)
endif()
# bflb block pool multithread enable
if (CONFIG_BFLB_BLOCK_POOL_MULTITHREAD)
sdk_add_compile_definitions(-DCONFIG_BFLB_BLOCK_POOL_MULTITHREAD=1)
sdk_library_add_sources(bflb_block_pool/bflb_block_pool_port_freertos.c)
if (CONFIG_BFLB_BLOCK_POOL_MUTEX_TIMEOUT)
sdk_add_compile_definitions(-DCONFIG_BFLB_BLOCK_POOL_MUTEX_TIMEOUT=${CONFIG_BFLB_BLOCK_POOL_MUTEX_TIMEOUT})
endif()
endif()
# bflb block pool
sdk_library_add_sources(bflb_block_pool/bflb_block_pool.c)
sdk_add_include_directories(bflb_block_pool)
# soft crc
sdk_library_add_sources(soft_crc/soft_crc.c)
sdk_add_include_directories(soft_crc)
sdk_add_link_options(-u_malloc_r -u_vsnprintf)

View File

@ -33,11 +33,66 @@ int bflb_printf(const char *fmt, ...)
return 0;
}
#define __is_print(ch) ((unsigned int)((ch) - ' ') < 127u - ' ')
void bflb_dump_hex(const void *ptr, uint32_t buflen)
{
unsigned char *buf = (unsigned char *)ptr;
int i, j;
for (i = 0; i < buflen; i += 16) {
printf("%08X:", i);
for (j = 0; j < 16; j++)
if (i + j < buflen) {
if ((j % 8) == 0) {
printf(" ");
}
printf("%02X ", buf[i + j]);
} else
printf(" ");
printf(" ");
for (j = 0; j < 16; j++)
if (i + j < buflen)
printf("%c", __is_print(buf[i + j]) ? buf[i + j] : '.');
printf("\n");
}
}
// void bflb_dump_hex(uint8_t *data, uint32_t len)
// {
// uint32_t i = 0;
// for (i = 0; i < len; i++) {
// if (i % 16 == 0) {
// printf("\r\n");
// }
// printf("%02x ", data[i]);
// }
// printf("\r\n");
// }
void bflb_reg_dump(uint32_t addr)
{
printf("%08lx[31:0]=%08lx\r\n", addr, *(volatile uint32_t *)(addr));
}
int bflb_data_compare(const uint8_t *expected, uint8_t *input, uint32_t len)
{
int i = 0;
for (i = 0; i < len; i++) {
if (input[i] != expected[i]) {
printf("Compare fail at %d,input %02x, but expect %02x\r\n", i, input[i], expected[i]);
return -1;
}
}
return 0;
}
void bflb_uart_set_console(struct bflb_device_s *dev)
{
console = dev;

View File

@ -54,13 +54,13 @@
#endif
// Support for the decimal notation floating point conversion specifiers (%f, %F)
#ifndef PRINTF_SUPPORT_DECIMAL_SPECIFIERS
#define PRINTF_SUPPORT_DECIMAL_SPECIFIERS 0
#ifndef CONFIG_LIBC_FLOAT
#define CONFIG_LIBC_FLOAT 0
#endif
// Support for the exponential notatin floating point conversion specifiers (%e, %g, %E, %G)
#ifndef PRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS
#define PRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS 0
#ifndef CONFIG_LIBC_FLOAT_EX
#define CONFIG_LIBC_FLOAT_EX 0
#endif
// Default precision for the floating point conversion specifiers (the C standard sets this at 6)
@ -78,11 +78,11 @@
// Support for the long long integral types (with the ll, z and t length modifiers for specifiers
// %d,%i,%o,%x,%X,%u, and with the %p specifier). Note: 'L' (long double) is not supported.
#ifndef PRINTF_SUPPORT_LONG_LONG
#define PRINTF_SUPPORT_LONG_LONG 1
#ifndef CONFIG_LIBC_LONG_LONG
#define CONFIG_LIBC_LONG_LONG 1
#endif
#if PRINTF_SUPPORT_LONG_LONG
#if CONFIG_LIBC_LONG_LONG
typedef unsigned long long printf_unsigned_value_t;
typedef long long printf_signed_value_t;
#else
@ -123,7 +123,7 @@ typedef long printf_signed_value_t;
typedef uint8_t numeric_base_t;
#if (PRINTF_SUPPORT_DECIMAL_SPECIFIERS || PRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS)
#if (CONFIG_LIBC_FLOAT || CONFIG_LIBC_FLOAT_EX)
#include <float.h>
#if FLT_RADIX != 2
#error "Non-binary-radix floating-point types are unsupported."
@ -179,7 +179,7 @@ static inline int get_exp2(double_with_bit_access x)
}
#define PRINTF_ABS(_x) ( (_x) > 0 ? (_x) : -(_x) )
#endif // (PRINTF_SUPPORT_DECIMAL_SPECIFIERS || PRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS)
#endif // (CONFIG_LIBC_FLOAT || CONFIG_LIBC_FLOAT_EX)
// Note in particular the behavior here on LONG_MIN or LLONG_MIN; it is valid
// and well-defined, but if you're not careful you can easily trigger undefined
@ -371,7 +371,7 @@ static size_t print_integer(out_fct_type out, char* buffer, size_t idx, size_t m
return print_integer_finalization(out, buffer, idx, maxlen, buf, len, negative, base, precision, width, flags);
}
#if (PRINTF_SUPPORT_DECIMAL_SPECIFIERS || PRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS)
#if (CONFIG_LIBC_FLOAT || CONFIG_LIBC_FLOAT_EX)
struct double_components {
int_fast64_t integral;
@ -468,7 +468,7 @@ struct scaling_factor update_normalization(struct scaling_factor sf, double extr
return result;
}
#if PRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS
#if CONFIG_LIBC_FLOAT_EX
static struct double_components get_normalized_components(bool negative, unsigned int precision, double non_normalized, struct scaling_factor normalization)
{
struct double_components components;
@ -600,7 +600,7 @@ static size_t print_decimal_number(out_fct_type out, char* buffer, size_t idx, s
return print_broken_up_decimal(value_, out, buffer, idx, maxlen, precision, width, flags, buf, len);
}
#if PRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS
#if CONFIG_LIBC_FLOAT_EX
// internal ftoa variant for exponential floating-point type, contributed by Martijn Jasperse <m.jasperse@gmail.com>
static size_t print_exponential_number(out_fct_type out, char* buffer, size_t idx, size_t maxlen, double number, unsigned int precision, unsigned int width, unsigned int flags, char* buf, size_t len)
{
@ -726,7 +726,7 @@ static size_t print_exponential_number(out_fct_type out, char* buffer, size_t id
}
return idx;
}
#endif // PRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS
#endif // CONFIG_LIBC_FLOAT_EX
static size_t print_floating_point(out_fct_type out, char* buffer, size_t idx, size_t maxlen, double value, unsigned int precision, unsigned int width, unsigned int flags, bool prefer_exponential)
@ -746,7 +746,7 @@ static size_t print_floating_point(out_fct_type out, char* buffer, size_t idx, s
// The required behavior of standard printf is to print _every_ integral-part digit -- which could mean
// printing hundreds of characters, overflowing any fixed internal buffer and necessitating a more complicated
// implementation.
#if PRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS
#if CONFIG_LIBC_FLOAT_EX
return print_exponential_number(out, buffer, idx, maxlen, value, precision, width, flags, buf, len);
#else
return 0U;
@ -765,14 +765,14 @@ static size_t print_floating_point(out_fct_type out, char* buffer, size_t idx, s
}
return
#if PRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS
#if CONFIG_LIBC_FLOAT_EX
prefer_exponential ?
print_exponential_number(out, buffer, idx, maxlen, value, precision, width, flags, buf, len) :
#endif
print_decimal_number(out, buffer, idx, maxlen, value, precision, width, flags, buf, len);
}
#endif // (PRINTF_SUPPORT_DECIMAL_SPECIFIERS || PRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS)
#endif // (CONFIG_LIBC_FLOAT || CONFIG_LIBC_FLOAT_EX)
// internal vsnprintf
static int __vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const char* format, va_list va)
@ -921,7 +921,7 @@ static int __vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, cons
if ((*format == 'i') || (*format == 'd')) {
// signed
if (flags & FLAGS_LONG_LONG) {
#if PRINTF_SUPPORT_LONG_LONG
#if CONFIG_LIBC_LONG_LONG
const long long value = va_arg(va, long long);
idx = print_integer(out, buffer, idx, maxlen, ABS_FOR_PRINTING(value), value < 0, base, precision, width, flags);
#endif
@ -938,7 +938,7 @@ static int __vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, cons
else {
// unsigned
if (flags & FLAGS_LONG_LONG) {
#if PRINTF_SUPPORT_LONG_LONG
#if CONFIG_LIBC_LONG_LONG
idx = print_integer(out, buffer, idx, maxlen, (printf_unsigned_value_t) va_arg(va, unsigned long long), false, base, precision, width, flags);
#endif
}
@ -953,7 +953,7 @@ static int __vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, cons
format++;
break;
}
#if PRINTF_SUPPORT_DECIMAL_SPECIFIERS
#if CONFIG_LIBC_FLOAT
case 'f' :
case 'F' :
if (*format == 'F') flags |= FLAGS_UPPERCASE;
@ -961,7 +961,7 @@ static int __vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, cons
format++;
break;
#endif
#if PRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS
#if CONFIG_LIBC_FLOAT_EX
case 'e':
case 'E':
case 'g':
@ -971,7 +971,7 @@ static int __vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, cons
idx = print_floating_point(out, buffer, idx, maxlen, va_arg(va, double), precision, width, flags, PRINTF_PREFER_EXPONENTIAL);
format++;
break;
#endif // PRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS
#endif // CONFIG_LIBC_FLOAT_EX
case 'c' : {
unsigned int l = 1U;
// pre padding

View File

@ -3,7 +3,7 @@
bflog_t __bflog_recorder;
static uint8_t bflog_pool[1024];
static bflog_direct_stream_t bflog_direct_stream;
bflog_direct_stream_t bflog_direct_stream;
extern uint16_t __console_output(void *ptr, uint16_t size);
@ -16,11 +16,11 @@ void log_init(void)
void *direct = (void *)&bflog_direct_stream;
/*!< create recorder */
bflog_create(record, bflog_pool, 1024, BFLOG_MODE_SYNC);
bflog_create_s(record, bflog_pool, 1024, BFLOG_MODE_SYNC);
/*!< create stream direct */
bflog_direct_create(direct, BFLOG_DIRECT_TYPE_STREAM, BFLOG_DIRECT_COLOR_ENABLE);
bflog_direct_init_stream((void *)direct, __console_output);
bflog_direct_create(direct, BFLOG_DIRECT_TYPE_STREAM, BFLOG_DIRECT_COLOR_ENABLE, NULL, NULL);
bflog_direct_init_stream_s((void *)direct, __console_output);
/*!< connect direct and recorder */
bflog_append_s(record, direct);

192
utils/soft_crc/soft_crc.c Normal file
View File

@ -0,0 +1,192 @@
/**
* @file softcrc.c
* @brief
*
* Copyright (c) 2021 Bouffalolab team
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you 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 "soft_crc.h"
#include "bflb_core.h"
// ---------------- POPULAR POLYNOMIALS ----------------
// CCITT: x^16 + x^12 + x^5 + x^0 (0x1021,init 0x0000)
// CRC-16: x^16 + x^15 + x^2 + x^0 (0x8005,init 0xFFFF)
// we use 0x8005 here and
const uint8_t chCRCHTalbe[] = {
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40
};
const uint8_t chCRCLTalbe[] = {
0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7,
0x05, 0xC5, 0xC4, 0x04, 0xCC, 0x0C, 0x0D, 0xCD, 0x0F, 0xCF, 0xCE, 0x0E,
0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09, 0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9,
0x1B, 0xDB, 0xDA, 0x1A, 0x1E, 0xDE, 0xDF, 0x1F, 0xDD, 0x1D, 0x1C, 0xDC,
0x14, 0xD4, 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3,
0x11, 0xD1, 0xD0, 0x10, 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3, 0xF2, 0x32,
0x36, 0xF6, 0xF7, 0x37, 0xF5, 0x35, 0x34, 0xF4, 0x3C, 0xFC, 0xFD, 0x3D,
0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A, 0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38,
0x28, 0xE8, 0xE9, 0x29, 0xEB, 0x2B, 0x2A, 0xEA, 0xEE, 0x2E, 0x2F, 0xEF,
0x2D, 0xED, 0xEC, 0x2C, 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26,
0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, 0xA0, 0x60, 0x61, 0xA1,
0x63, 0xA3, 0xA2, 0x62, 0x66, 0xA6, 0xA7, 0x67, 0xA5, 0x65, 0x64, 0xA4,
0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F, 0x6E, 0xAE, 0xAA, 0x6A, 0x6B, 0xAB,
0x69, 0xA9, 0xA8, 0x68, 0x78, 0xB8, 0xB9, 0x79, 0xBB, 0x7B, 0x7A, 0xBA,
0xBE, 0x7E, 0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, 0xB4, 0x74, 0x75, 0xB5,
0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71, 0x70, 0xB0,
0x50, 0x90, 0x91, 0x51, 0x93, 0x53, 0x52, 0x92, 0x96, 0x56, 0x57, 0x97,
0x55, 0x95, 0x94, 0x54, 0x9C, 0x5C, 0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E,
0x5A, 0x9A, 0x9B, 0x5B, 0x99, 0x59, 0x58, 0x98, 0x88, 0x48, 0x49, 0x89,
0x4B, 0x8B, 0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C,
0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42, 0x43, 0x83,
0x41, 0x81, 0x80, 0x40
};
uint16_t bflb_soft_crc16(void *in, uint32_t len)
{
uint8_t chCRCHi = 0xFF;
uint8_t chCRCLo = 0xFF;
uint16_t wIndex;
uint8_t *data = (uint8_t *)in;
while (len--) {
wIndex = chCRCLo ^ *data++;
chCRCLo = chCRCHi ^ chCRCHTalbe[wIndex];
chCRCHi = chCRCLTalbe[wIndex];
}
return ((chCRCHi << 8) | chCRCLo);
}
/*
x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1
*/
const uint32_t crc32Tab[256] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
};
uint32_t bflb_soft_crc32_table(void *in, uint32_t len)
{
uint32_t crc = 0;
uint8_t *data = (uint8_t *)in;
crc = crc ^ 0xffffffff;
while (len--) {
crc = crc32Tab[(crc ^ *data++) & 0xFF] ^ (crc >> 8);
}
return crc ^ 0xffffffff;
}
/******************************************************************************
* Name: CRC-32 x32+x26+x23+x22+x16+x12+x11+x10+x8+x7+x5+x4+x2+x+1
* Poly: 0x4C11DB7
* Init: 0xFFFFFFF
* Refin: True
* Refout: True
* Xorout: 0xFFFFFFF
* Alias: CRC_32/ADCCP
* Use: WinRAR,ect.
*****************************************************************************/
uint32_t ATTR_TCM_SECTION bflb_soft_crc32_ex(uint32_t initial, void *in, uint32_t len)
{
uint8_t i;
uint32_t crc = ~initial; // Initial value
uint8_t *data = (uint8_t *)in;
while (len--) {
crc ^= *data++; // crc ^= *data; data++;
for (i = 0; i < 8; ++i) {
if (crc & 1) {
crc = (crc >> 1) ^ 0xEDB88320; // 0xEDB88320= reverse 0x04C11DB7
} else {
crc = (crc >> 1);
}
}
}
return ~crc;
}
uint32_t ATTR_TCM_SECTION bflb_soft_crc32(void *in, uint32_t len)
{
return bflb_soft_crc32_ex(0, in, len);
}

31
utils/soft_crc/soft_crc.h Normal file
View File

@ -0,0 +1,31 @@
/**
* @file softcrc.h
* @brief
*
* Copyright (c) 2021 Bouffalolab team
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you 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 __SOFT_CRC_H__
#define __SOFT_CRC_H__
#include "stdint.h"
uint16_t bflb_soft_crc16(void *in, uint32_t len);
uint32_t bflb_soft_crc32(void *in, uint32_t len);
#endif

View File

@ -22,7 +22,7 @@
#define vlibc_file(_stream) ((vlibc_file_t *)(_stream))
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
int FRESULT_to_errno[20] = {
0,
EIO,
@ -47,7 +47,7 @@ int FRESULT_to_errno[20] = {
};
#endif
#ifdef VLIBC_DEBUG
#ifdef CONFIG_VLIBC_DEBUG
#define CHECK_FILE(_stream, __ret) \
do { \
if ((void *)(_stream) == NULL) { \
@ -84,7 +84,7 @@ void vlibc_clearerr(VLIBC_FILE *stream)
}
else IF_FILE(stream)
{
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
f_error(stream->file) = 0;
#endif
}
@ -109,7 +109,7 @@ int vlibc_feof(VLIBC_FILE *stream)
}
else IF_FILE(stream)
{
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
return f_eof(stream->file);
#else
errno = EIO;
@ -139,7 +139,7 @@ int vlibc_ferror(VLIBC_FILE *stream)
}
else IF_FILE(stream)
{
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
int fresult;
fresult = f_error(stream->file);
@ -162,25 +162,25 @@ static int __get_mode_vlibc_fopen(const char *mode, unsigned char *iomode, unsig
/*!< get file and io open mode */
switch (*mode) {
case 'r':
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
*openmode = FA_READ;
#endif
*iomode = _VLIBC_IO_READ;
break;
case 'w':
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
*openmode = FA_CREATE_ALWAYS | FA_WRITE;
#endif
*iomode = _VLIBC_IO_WRITE;
break;
case 'a':
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
*openmode = FA_OPEN_APPEND | FA_WRITE;
#endif
*iomode = _VLIBC_IO_WRITE;
break;
case 'x':
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
*openmode = FA_CREATE_NEW | FA_WRITE;
#endif
*iomode = _VLIBC_IO_WRITE;
@ -195,7 +195,7 @@ static int __get_mode_vlibc_fopen(const char *mode, unsigned char *iomode, unsig
case '\0':
break;
case '+':
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
*openmode |= (FA_WRITE | FA_READ);
#endif
*iomode |= (_VLIBC_IO_WRITE | _VLIBC_IO_READ);
@ -393,7 +393,7 @@ static VLIBC_FILE *__io_vlibc_open(VLIBC_FILE *fnew, const char *name, unsigned
return fnew;
}
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
static VLIBC_FILE *__file_vlibc_open(VLIBC_FILE *fnew, const char *name, unsigned char openmode)
{
int fresult;
@ -471,7 +471,7 @@ static int __io_vlibc_close(VLIBC_FILE *stream)
return 0;
}
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
static int __file_vlibc_close(VLIBC_FILE *stream)
{
int fresult;
@ -573,7 +573,7 @@ VLIBC_FILE *vlibc_freopen(const char *filename, const char *mode, VLIBC_FILE *st
}
else IF_FILE(stream)
{
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
if (__file_vlibc_close(stream)) {
return NULL;
}
@ -610,7 +610,7 @@ VLIBC_FILE *vlibc_freopen(const char *filename, const char *mode, VLIBC_FILE *st
}
else IF_FILE(stream)
{
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
if (__file_vlibc_close(stream)) {
return NULL;
}
@ -719,7 +719,7 @@ size_t vlibc_fread(void *ptr, size_t size, size_t nmemb, VLIBC_FILE *stream)
}
else IF_FILE(stream)
{
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
int fresult;
size_t bytes;
fresult = f_read(stream->file, ptr, size * nmemb, &bytes);
@ -849,7 +849,7 @@ size_t vlibc_fwrite(const void *ptr, size_t size, size_t nmemb, VLIBC_FILE *stre
}
else IF_FILE(stream)
{
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
int fresult;
size_t bytes;
fresult = f_write(stream->file, ptr, size * nmemb, &bytes);
@ -910,7 +910,7 @@ int vlibc_fflush(VLIBC_FILE *stream)
}
else IF_FILE(stream)
{
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
int fresult;
fresult = f_sync(stream->file);
if (fresult != FR_OK) {
@ -952,7 +952,7 @@ int vlibc_fseek(VLIBC_FILE *stream, long offset, int whence)
}
else IF_FILE(stream)
{
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
int fresult;
long long temp;
@ -1031,7 +1031,7 @@ long vlibc_ftell(VLIBC_FILE *stream)
}
else IF_FILE(stream)
{
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
return (long)f_tell(stream->file);
#else
errno = EIO;
@ -1054,7 +1054,7 @@ int vlibc_remove(const char *filename)
{
CHECK_FILE(filename, EOF);
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
int fresult;
FILINFO finfo;
@ -1091,7 +1091,7 @@ int vlibc_rename(const char *old_filename, const char *new_filename)
{
CHECK_FILE(old_filename, EOF);
CHECK_FILE(new_filename, EOF);
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
int fresult;
fresult = f_rename(old_filename, new_filename);
@ -1125,7 +1125,7 @@ void vlibc_rewind(VLIBC_FILE *stream)
}
else IF_FILE(stream)
{
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
int fresult;
fresult = f_lseek(stream->file, 0);
if (fresult != FR_OK) {
@ -1176,7 +1176,7 @@ void vlibc_setbuf(VLIBC_FILE *stream, char *buffer)
}
else IF_FILE(stream)
{
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
return;
#else
errno = EIO;
@ -1224,7 +1224,7 @@ int vlibc_setvbuf(VLIBC_FILE *stream, char *buffer, int mode, size_t size)
}
else IF_FILE(stream)
{
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
return EOF;
#else
errno = EIO;
@ -1240,7 +1240,7 @@ int vlibc_setvbuf(VLIBC_FILE *stream, char *buffer, int mode, size_t size)
VLIBC_FILE *vlibc_tmpfile(void)
{
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
return NULL;
#else
return NULL;
@ -1249,7 +1249,7 @@ VLIBC_FILE *vlibc_tmpfile(void)
char *vlibc_tmpnam(char *str)
{
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
return NULL;
#else
return NULL;
@ -1260,7 +1260,7 @@ int vlibc_fscanf(VLIBC_FILE *stream, const char *format, ...)
{
CHECK_FILE(stream, EOF);
CHECK_FILE(format, EOF);
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
return EOF;
#else
return EOF;
@ -1270,7 +1270,7 @@ int vlibc_fscanf(VLIBC_FILE *stream, const char *format, ...)
int vlibc_scanf(const char *format, ...)
{
CHECK_FILE(format, EOF);
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
return EOF;
#else
return EOF;
@ -1281,7 +1281,7 @@ int vlibc_sscanf(const char *str, const char *format, ...)
{
CHECK_FILE(str, EOF);
CHECK_FILE(format, EOF);
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
return EOF;
#else
return EOF;
@ -1292,7 +1292,7 @@ int vlibc_vfscanf(VLIBC_FILE *stream, const char *format, va_list arg)
{
CHECK_FILE(stream, EOF);
CHECK_FILE(format, EOF);
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
return EOF;
#else
return EOF;
@ -1302,7 +1302,7 @@ int vlibc_vfscanf(VLIBC_FILE *stream, const char *format, va_list arg)
int vlibc_vscanf(const char *format, va_list arg)
{
CHECK_FILE(format, EOF);
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
return EOF;
#else
return EOF;
@ -1313,7 +1313,7 @@ int vlibc_vsscanf(const char *str, const char *format, va_list arg)
{
CHECK_FILE(str, EOF);
CHECK_FILE(format, EOF);
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
return EOF;
#else
return EOF;
@ -1329,7 +1329,7 @@ int vlibc_fgetc(VLIBC_FILE *stream)
}
else IF_FILE(stream)
{
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
int fresult;
int ch;
size_t bytes;
@ -1361,7 +1361,7 @@ char *vlibc_fgets(char *str, int size, VLIBC_FILE *stream)
{
CHECK_FILE(str, NULL);
CHECK_FILE(stream, NULL);
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
return NULL;
#else
return NULL;
@ -1378,7 +1378,7 @@ int vlibc_fputc(int chr, VLIBC_FILE *stream)
}
else IF_FILE(stream)
{
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
int fresult;
size_t bytes;
fresult = f_write(stream->file, &chr, 1, &bytes);
@ -1419,7 +1419,7 @@ int vlibc_getc(VLIBC_FILE *stream)
}
else IF_FILE(stream)
{
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
int fresult;
int ch;
size_t bytes;
@ -1449,7 +1449,7 @@ int vlibc_getc(VLIBC_FILE *stream)
int vlibc_getchar(void)
{
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
return EOF;
#else
return EOF;
@ -1459,7 +1459,7 @@ int vlibc_getchar(void)
char *vlibc_gets(char *str)
{
CHECK_FILE(str, NULL);
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
return NULL;
#else
return NULL;
@ -1482,7 +1482,7 @@ int vlibc_putc(int chr, VLIBC_FILE *stream)
}
else IF_FILE(stream)
{
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
int fresult;
size_t bytes;
fresult = f_write(stream->file, &chr, 1, &bytes);
@ -1523,7 +1523,7 @@ int vlibc_putchar(int chr)
}
else IF_FILE(vlibc_stdout)
{
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
int fresult;
size_t bytes;
fresult = f_write(vlibc_stdout->file, &chr, 1, &bytes);

View File

@ -6,7 +6,7 @@
#include <stdio.h>
#include <stdint.h>
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
#include "ff.h"
#endif
@ -32,7 +32,7 @@ typedef struct {
union {
struct __vlibc_io *io;
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
FIL *file;
#else
int *file;

View File

@ -54,7 +54,7 @@
#define _VLIBC_TYPEIS_IO ((int)(0x01))
#define _VLIBC_TYPEIS_FILE ((int)(0x02))
#ifdef VLIBC_DEBUG
#ifdef CONFIG_VLIBC_DEBUG
#define CHECK_FILE(_stream, __ret) \
do { \
if ((void *)(_stream) == NULL) { \
@ -76,7 +76,7 @@
#define IF_FILE(_stream) \
if (((vlibc_file(_stream)->magic) & _VLIBC_MAGIC_MASK) == _VLIBC_FILE_MAGIC_CODE)
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
extern int FRESULT_to_errno[20];
#endif
@ -98,18 +98,18 @@ extern int FRESULT_to_errno[20];
#endif
// Support for the decimal notation floating point conversion specifiers (%f, %F)
#ifndef VLIBC_FLOAT
#define VLIBC_FLOAT 0
#ifndef CONFIG_VLIBC_FLOAT
#define CONFIG_VLIBC_FLOAT 0
#endif
// Support for the exponential notation floating point conversion specifiers (%e, %g, %E, %G)
#ifndef VLIBC_FLOAT_EX
#define VLIBC_FLOAT_EX 0
#ifndef CONFIG_VLIBC_FLOAT_EX
#define CONFIG_VLIBC_FLOAT_EX 0
#endif
// Support for the length write-back specifier (%n)
#ifndef VLIBC_WRITEBACK
#define VLIBC_WRITEBACK 0
#ifndef CONFIG_VLIBC_WRITEBACK
#define CONFIG_VLIBC_WRITEBACK 0
#endif
// Default precision for the floating point conversion specifiers (the C standard sets this at 6)
@ -127,8 +127,8 @@ extern int FRESULT_to_errno[20];
// Support for the long long integral types (with the ll, z and t length modifiers for specifiers
// %d,%i,%o,%x,%X,%u, and with the %p specifier). Note: 'L' (long double) is not supported.
#ifndef VLIBC_LONG_LONG
#define VLIBC_LONG_LONG 0
#ifndef CONFIG_VLIBC_LONG_LONG
#define CONFIG_VLIBC_LONG_LONG 0
#endif
// The number of terms in a Taylor series expansion of log_10(x) to
@ -181,7 +181,7 @@ typedef unsigned int printf_flags_t;
typedef uint8_t numeric_base_t;
#if VLIBC_LONG_LONG
#if CONFIG_VLIBC_LONG_LONG
typedef unsigned long long printf_unsigned_value_t;
typedef long long printf_signed_value_t;
#else
@ -194,7 +194,7 @@ typedef long printf_signed_value_t;
// since INT_MAX is the maximum return value, which excludes the
// trailing '\0'.
#if (VLIBC_FLOAT || VLIBC_FLOAT_EX)
#if (CONFIG_VLIBC_FLOAT || CONFIG_VLIBC_FLOAT_EX)
#include <float.h>
#if FLT_RADIX != 2
#error "Non-binary-radix floating-point types are unsupported."
@ -256,7 +256,7 @@ static inline int get_exp2(double_with_bit_access x)
}
#define PRINTF_ABS(_x) ((_x) > 0 ? (_x) : -(_x))
#endif // (VLIBC_FLOAT || VLIBC_FLOAT_EX)
#endif // (CONFIG_VLIBC_FLOAT || CONFIG_VLIBC_FLOAT_EX)
// Note in particular the behavior here on LONG_MIN or LLONG_MIN; it is valid
// and well-defined, but if you're not careful you can easily trigger undefined
@ -300,7 +300,7 @@ static inline void putc_via_file(output_gadget_t *output, char c)
if (write_pos >= VLIBC_FBUFSIZ) {
output->max = 0;
write_pos = 0;
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
FRESULT fresult;
size_t bytes;
fresult = f_write(output->stream->file, output->buffer, VLIBC_FBUFSIZ, &bytes);
@ -527,7 +527,7 @@ static void print_integer(output_gadget_t *output, void (*putc_function)(output_
print_integer_finalization(output, putc_function, buf, len, negative, base, precision, width, flags);
}
#if (VLIBC_FLOAT || VLIBC_FLOAT_EX)
#if (CONFIG_VLIBC_FLOAT || CONFIG_VLIBC_FLOAT_EX)
// Stores a fixed-precision representation of a double relative
// to a fixed precision (which cannot be determined by examining this structure)
@ -585,7 +585,7 @@ static struct double_components get_components(double number, size_t precision)
return number_;
}
#if VLIBC_FLOAT_EX
#if CONFIG_VLIBC_FLOAT_EX
struct scaling_factor {
double raw_factor;
bool multiply; // if true, need to multiply by raw_factor; otherwise need to divide by it
@ -662,7 +662,7 @@ static struct double_components get_normalized_components(bool negative, size_t
}
return components;
}
#endif // VLIBC_FLOAT_EX
#endif // CONFIG_VLIBC_FLOAT_EX
static void print_broken_up_decimal(
struct double_components number_, output_gadget_t *output, void (*putc_function)(output_gadget_t *, char), size_t precision,
@ -749,7 +749,7 @@ static void print_decimal_number(output_gadget_t *output, void (*putc_function)(
print_broken_up_decimal(value_, output, putc_function, precision, width, flags, buf, len);
}
#if VLIBC_FLOAT_EX
#if CONFIG_VLIBC_FLOAT_EX
// A floor function - but one which only works for numbers whose
// floor value is representable by an int.
@ -925,7 +925,7 @@ static void print_exponential_number(output_gadget_t *output, void (*putc_functi
}
}
}
#endif // VLIBC_FLOAT_EX
#endif // CONFIG_VLIBC_FLOAT_EX
static void print_floating_point(output_gadget_t *output, void (*putc_function)(output_gadget_t *, char), double value, size_t precision, size_t width, printf_flags_t flags, bool prefer_exponential)
{
@ -951,7 +951,7 @@ static void print_floating_point(output_gadget_t *output, void (*putc_function)(
// The required behavior of standard printf is to print _every_ integral-part digit -- which could mean
// printing hundreds of characters, overflowing any fixed internal buffer and necessitating a more complicated
// implementation.
#if VLIBC_FLOAT_EX
#if CONFIG_VLIBC_FLOAT_EX
print_exponential_number(output, putc_function, value, precision, width, flags, buf, len);
#endif
return;
@ -968,7 +968,7 @@ static void print_floating_point(output_gadget_t *output, void (*putc_function)(
precision--;
}
#if VLIBC_FLOAT_EX
#if CONFIG_VLIBC_FLOAT_EX
if (prefer_exponential)
print_exponential_number(output, putc_function, value, precision, width, flags, buf, len);
else
@ -976,7 +976,7 @@ static void print_floating_point(output_gadget_t *output, void (*putc_function)(
print_decimal_number(output, putc_function, value, precision, width, flags, buf, len);
}
#endif // (VLIBC_FLOAT || VLIBC_FLOAT_EX)
#endif // (CONFIG_VLIBC_FLOAT || CONFIG_VLIBC_FLOAT_EX)
// Advances the format pointer past the flags, and returns the parsed flags
// due to the characters passed
@ -1133,7 +1133,7 @@ static int _vsnprintf(output_gadget_t *output, void (*putc_function)(output_gadg
// A signed specifier: d, i or possibly I + bit size if enabled
if (flags & FLAGS_LONG_LONG) {
#if VLIBC_LONG_LONG
#if CONFIG_VLIBC_LONG_LONG
const long long value = va_arg(args, long long);
print_integer(output, putc_function, ABS_FOR_PRINTING(value), value < 0, base, precision, width, flags);
#endif
@ -1157,7 +1157,7 @@ static int _vsnprintf(output_gadget_t *output, void (*putc_function)(output_gadg
flags &= ~(FLAGS_PLUS | FLAGS_SPACE);
if (flags & FLAGS_LONG_LONG) {
#if VLIBC_LONG_LONG
#if CONFIG_VLIBC_LONG_LONG
print_integer(output, putc_function, (printf_unsigned_value_t)va_arg(args, unsigned long long), false, base, precision, width, flags);
#endif
} else if (flags & FLAGS_LONG) {
@ -1173,7 +1173,7 @@ static int _vsnprintf(output_gadget_t *output, void (*putc_function)(output_gadg
break;
}
#if VLIBC_FLOAT
#if CONFIG_VLIBC_FLOAT
case 'f':
case 'F':
if (*format == 'F')
@ -1183,7 +1183,7 @@ static int _vsnprintf(output_gadget_t *output, void (*putc_function)(output_gadg
break;
#endif
#if VLIBC_FLOAT_EX
#if CONFIG_VLIBC_FLOAT_EX
case 'e':
case 'E':
case 'g':
@ -1267,7 +1267,7 @@ static int _vsnprintf(output_gadget_t *output, void (*putc_function)(output_gadg
// Many people prefer to disable support for %n, as it lets the caller
// engineer a write to an arbitrary location, of a value the caller
// effectively controls - which could be a security concern in some cases.
#if VLIBC_WRITEBACK
#if CONFIG_VLIBC_WRITEBACK
case 'n': {
if (flags & FLAGS_CHAR)
*(va_arg(args, char *)) = (char)output->pos;
@ -1275,16 +1275,16 @@ static int _vsnprintf(output_gadget_t *output, void (*putc_function)(output_gadg
*(va_arg(args, short *)) = (short)output->pos;
else if (flags & FLAGS_LONG)
*(va_arg(args, long *)) = (long)output->pos;
#if VLIBC_LONG_LONG
#if CONFIG_VLIBC_LONG_LONG
else if (flags & FLAGS_LONG_LONG)
*(va_arg(args, long long *)) = (long long int)output->pos;
#endif // VLIBC_LONG_LONG
#endif // CONFIG_VLIBC_LONG_LONG
else
*(va_arg(args, int *)) = (int)output->pos;
format++;
break;
}
#endif // VLIBC_WRITEBACK
#endif // CONFIG_VLIBC_WRITEBACK
default:
putc_function(output, *format);
@ -1353,7 +1353,7 @@ int vlibc_vfprintf(VLIBC_FILE *stream, const char *format, va_list arg)
}
else IF_FILE(stream)
{
#ifdef VLIBC_PORT_FATFS
#ifdef CONFIG_VLIBC_FATFS
char buffer[VLIBC_FBUFSIZ];
int ret;
FRESULT fresult;