diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a2a972..43462e8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,8 +11,10 @@ option(COMPILE_TESTS "Compile the tests" OFF) add_library(libblisp_obj OBJECT lib/blisp.c + lib/blisp_easy.c + lib/blisp_util.c lib/chip/blisp_chip_bl60x.c - lib/chip/blisp_chip_bl70x.c lib/blisp_easy.c) + lib/chip/blisp_chip_bl70x.c) target_include_directories(libblisp_obj PRIVATE ${CMAKE_SOURCE_DIR}/include/) diff --git a/include/blisp_util.h b/include/blisp_util.h index f1f4d8f..1f00480 100644 --- a/include/blisp_util.h +++ b/include/blisp_util.h @@ -2,35 +2,18 @@ #ifndef _BLISP_UTIL_H #define _BLISP_UTIL_H -#include -#include +#include #ifdef WIN32 -#include +# include #else -#include +# include #endif -static void blisp_dlog(const char* format, ...) -{ - fflush(stdout); - va_list args; - va_start(args, format); - vfprintf(stderr, format, args); - va_end(args); - fputc('\n', stderr); -} +void blisp_dlog(const char* format, ...); +void sleep_ms(int milliseconds); -static void sleep_ms(int milliseconds) { -#ifdef WIN32 - Sleep(milliseconds); -#else - struct timespec ts; - ts.tv_sec = milliseconds / 1000; - ts.tv_nsec = (milliseconds % 1000) * 1000000; - nanosleep(&ts, NULL); -#endif -} +uint32_t crc32_calculate(const void *data, size_t data_len); /** * * Generated on Mon Jan 9 19:56:36 2023 @@ -80,19 +63,4 @@ static const uint32_t crc_table[256] = { 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d }; -static uint32_t crc32_calculate(const void *data, size_t data_len) -{ - uint32_t crc = 0xffffffff; - const unsigned char *d = (const unsigned char *)data; - unsigned int tbl_idx; - - while (data_len--) { - tbl_idx = (crc ^ *d) & 0xff; - crc = (crc_table[tbl_idx] ^ (crc >> 8)) & 0xffffffff; - d++; - } - return (crc & 0xffffffff) ^ 0xffffffff; -} - - -#endif \ No newline at end of file +#endif diff --git a/lib/blisp_util.c b/lib/blisp_util.c new file mode 100644 index 0000000..27bca4f --- /dev/null +++ b/lib/blisp_util.c @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: MIT +#include +#include +#include + +#ifdef WIN32 +# include +#else +# include +#endif + +#include "blisp_util.h" + +void blisp_dlog(const char* format, ...) +{ + fflush(stdout); + va_list args; + va_start(args, format); + vfprintf(stderr, format, args); + va_end(args); + fputc('\n', stderr); +} + + +void sleep_ms(int milliseconds) { +#ifdef WIN32 + Sleep(milliseconds); +#else + struct timespec ts; + ts.tv_sec = milliseconds / 1000; + ts.tv_nsec = (milliseconds % 1000) * 1000000; + nanosleep(&ts, NULL); +#endif +} + +uint32_t crc32_calculate(const void *data, size_t data_len) +{ + uint32_t crc = 0xffffffff; + const unsigned char *d = (const unsigned char *)data; + unsigned int tbl_idx; + + while (data_len--) { + tbl_idx = (crc ^ *d) & 0xff; + crc = (crc_table[tbl_idx] ^ (crc >> 8)) & 0xffffffff; + d++; + } + return (crc & 0xffffffff) ^ 0xffffffff; +}