diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 574c3458..def0ec10 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,6 +9,6 @@ repos: files: ^src/ exclude: 'lib/' - id: cppcheck - args: [--force] + args: [--force,--check-level=exhaustive] files: ^src/ exclude: 'lib/' diff --git a/bin/firmware.bin b/bin/firmware.bin index 4907a1a4..4229f121 100644 Binary files a/bin/firmware.bin and b/bin/firmware.bin differ diff --git a/bin/firmware32.bin b/bin/firmware32.bin index 66d71e58..479d69a2 100644 Binary files a/bin/firmware32.bin and b/bin/firmware32.bin differ diff --git a/bin/firmware32c3.bin b/bin/firmware32c3.bin index da349a5a..9ef7bae3 100644 Binary files a/bin/firmware32c3.bin and b/bin/firmware32c3.bin differ diff --git a/bin/firmware32lite.bin b/bin/firmware32lite.bin index 6f3b7807..101e888b 100644 Binary files a/bin/firmware32lite.bin and b/bin/firmware32lite.bin differ diff --git a/bin/firmware32s2.bin b/bin/firmware32s2.bin index e9d0a2f2..0df88760 100644 Binary files a/bin/firmware32s2.bin and b/bin/firmware32s2.bin differ diff --git a/bin/firmware32s3.bin b/bin/firmware32s3.bin index 340cbd55..e14a1629 100644 Binary files a/bin/firmware32s3.bin and b/bin/firmware32s3.bin differ diff --git a/html/app.js.gz b/html/app.js.gz index a926615a..e9b11054 100644 Binary files a/html/app.js.gz and b/html/app.js.gz differ diff --git a/lib/gcov/gcov_gcc.c b/lib/gcov/gcov_gcc.c deleted file mode 100644 index a9077388..00000000 --- a/lib/gcov/gcov_gcc.c +++ /dev/null @@ -1,344 +0,0 @@ -/**********************************************************************/ -/** @addtogroup embedded_gcov - * @{ - * @file - * @version $Id: $ - * - * @author 2021-08-31 kjpeters Working and cleaned up version. - * - * @note Based on GCOV-related code of the Linux kernel, - * as described online by Thanassis Tsiodras (April 2016) - * https://www.thanassis.space/coverage.html - * and by Alexander Tarasikov - * http://allsoftwaresucks.blogspot.com/2015/05/gcov-is-amazing-yet-undocumented.html - * with additional investigation, updating, cleanup, and portability - * by Ken Peters. - * - * @brief Private source file for embedded gcov. - * - **********************************************************************/ -/* - * This code provides functions to handle gcc's profiling data format - * introduced with gcc 4.7. - * - * This file is based heavily on gcc_3_4.c file. - * - * For a better understanding, refer to gcc source: - * gcc/gcov-io.h - * libgcc/libgcov.c - * - * Uses gcc-internal data definitions. - */ - -#include "gcov_gcc.h" - -#ifdef GCOV_OPT_RESET_WATCHDOG -/* In an embedded system, you might want to reset any watchdog timer below, */ -/* depending on your timeout versus gcov tree size */ -/* If so, include any needed header files. */ -#include "all.h" -#include "defs.h" -#endif // GCOV_OPT_RESET_WATCHDOG - - -/** - * struct gcov_ctr_info - information about counters for a single function - * @num: number of counter values for this type - * @values: array of counter values for this type - * - * This data is generated by gcc during compilation and doesn't change - * at run-time with the exception of the values array. - */ -/* Compare to libgcc/libgcov.h */ -struct gcov_ctr_info { - gcov_unsigned_t num; - gcov_type *values; -}; - -/** - * struct gcov_fn_info - profiling meta data per function - * @key: comdat key - * @ident: unique ident of function - * @lineno_checksum: function lineo_checksum - * @cfg_checksum: function cfg checksum - * @ctrs: instrumented counters - * - * This data is generated by gcc during compilation and doesn't change - * at run-time. - * - * Information about a single function. This uses the trailing array - * idiom. The number of counters is determined from the merge pointer - * array in gcov_info. The key is used to detect which of a set of - * comdat functions was selected -- it points to the gcov_info object - * of the object file containing the selected comdat function. - */ -/* Compare to libgcc/libgcov.h */ -struct gcov_fn_info { - const struct gcov_info *key; - gcov_unsigned_t ident; - gcov_unsigned_t lineno_checksum; - gcov_unsigned_t cfg_checksum; - struct gcov_ctr_info ctrs[1]; -}; - -/* Type of function used to merge counters. */ -/* Compare to libgcc/libgcov.h */ -typedef void (*gcov_merge_fn) (gcov_type *, gcov_unsigned_t); - -/** - * struct gcov_info - profiling data per object file - * @version: gcov version magic indicating the gcc version used for compilation - * @next: list head for a singly-linked list - * @stamp: uniquifying time stamp - * @filename: name of the associated gcov data file - * @merge: merge functions (null for unused counter type) - * @n_functions: number of instrumented functions - * @functions: pointer to pointers to function information - * - * This data is generated by gcc during compilation and doesn't change - * at run-time with the exception of the next pointer. - */ -/* Compare to libgcc/libgcov.h */ -struct gcov_info { - gcov_unsigned_t version; - struct gcov_info *next; - gcov_unsigned_t stamp; - const char *filename; - gcov_merge_fn merge[GCOV_COUNTERS]; - unsigned n_functions; - struct gcov_fn_info **functions; -}; - -/** - * gcov_info_filename - return info filename - * @info: profiling data set - * - * Need this to access opaque gcov_info to get filename in public code. - */ -const char *gcov_info_filename(struct gcov_info *info) -{ - return info->filename; -} - -/* See gcc/gcov-io.h for description of number formats */ - -/** - * store_gcov_unsigned - store 32 bit number in gcov format to buffer - * @buffer: target buffer or NULL - * @off: offset into the buffer - * @v: value to be stored - * - * Number format defined by gcc: numbers are recorded in the 32 bit - * unsigned binary form of the endianness of the machine generating the - * file. Returns the number of bytes stored. If @buffer is %NULL, doesn't - * store anything. - */ -/* Slightly like gcc/gcov-io.c function gcov_write_unsigned() (1-word item) */ -/* Need buffer to be 32-bit-aligned for type-safe internal usage */ -static size_t store_gcov_unsigned(gcov_unsigned_t *buffer, size_t off, gcov_unsigned_t v) -{ - gcov_unsigned_t *data; - - if (buffer) { - data = buffer + off; - *data = v; - } - - /* return count of buffer data type units */ - return sizeof(*data)/sizeof(*buffer); -} - -/** - * store_gcov_tag_length - 32 bit tag and 32 bit length in gcov format to buffer - * @buffer: target buffer or NULL - * @off: offset into the buffer - * @tag: tag value to be stored - * @length: length value to be stored - * - * Number format defined by gcc: numbers are recorded in the 32 bit - * unsigned binary form of the endianness of the machine generating the - * file. 64 bit numbers are stored as two 32 bit numbers, the low part - * first. Returns the number of bytes stored. If @buffer is %NULL, doesn't store - * anything. - */ -/* Slightly like gcc/gcov-io.c function gcov_write_tag_length() (1-word tag and 1-word length) */ -/* or gcov_write_tag() (1-word tag and implied 1-word "length = 0") */ -/* Need buffer to be 32-bit-aligned for type-safe internal usage */ -static size_t store_gcov_tag_length(gcov_unsigned_t *buffer, size_t off, gcov_unsigned_t tag, gcov_unsigned_t length) -{ - gcov_unsigned_t *data; - - if (buffer) { - data = buffer + off; - - data[0] = tag; - data[1] = length; - } - - /* return count of buffer data type units */ - return sizeof(*data)/sizeof(*buffer) * 2; -} - -/** - * store_gcov_counter - store 64 bit number in gcov format to buffer - * @buffer: target buffer or NULL - * @off: offset into the buffer - * @v: value to be stored - * - * Number format defined by gcc: numbers are recorded in the 32 bit - * unsigned binary form of the endianness of the machine generating the - * file. 64 bit numbers are stored as two 32 bit numbers, the low part - * first. Returns the number of bytes stored. If @buffer is %NULL, doesn't store - * anything. - */ -/* Slightly like gcc/gcov-io.c function gcov_write_counter() (2-word item) */ -/* Need buffer to be 32-bit-aligned for type-safe internal usage */ -static size_t store_gcov_counter(gcov_unsigned_t *buffer, size_t off, gcov_type v) -{ - gcov_unsigned_t *data; - - if (buffer) { - data = buffer + off; - - data[0] = (v & 0xffffffffUL); - data[1] = (v >> 32); - } - - /* return count of buffer data type units */ - return sizeof(*data)/sizeof(*buffer) * 2; -} - -/** - * gcov_convert_to_gcda - convert profiling data set to gcda file format - * @buffer: the buffer to store file data or %NULL if no data should be stored - * @info: profiling data set to be converted - * - * Returns the number of bytes that were/would have been stored into the buffer. - */ -/* Our own creation, but compare to libgcc/libgcov-driver.c function write_one_data() */ -/* Need buffer to be 32-bit-aligned for type-safe internal usage */ -size_t gcov_convert_to_gcda(gcov_unsigned_t *buffer, struct gcov_info *gi_ptr) -{ - const struct gcov_fn_info *fi_ptr; - const struct gcov_ctr_info *ci_ptr; - unsigned int fi_idx; - unsigned int ct_idx; - unsigned int cv_idx; - size_t pos = 0; /* offset in buffer, in buffer data type units */ - - /* File header. */ - pos += store_gcov_tag_length(buffer, pos, GCOV_DATA_MAGIC, gi_ptr->version); - pos += store_gcov_unsigned(buffer, pos, gi_ptr->stamp); - - /* Write execution counts for each function. */ - for (fi_idx = 0; fi_idx < gi_ptr->n_functions; fi_idx++) { - fi_ptr = gi_ptr->functions[fi_idx]; - -#ifdef GCOV_OPT_RESET_WATCHDOG - /* In an embedded system, you might want to reset any watchdog timer here, */ - /* depending on your timeout versus gcov tree size */ - SP_WDG = WATCHDOG_RESET; -#endif // GCOV_OPT_RESET_WATCHDOG - - /* Function record. */ - pos += store_gcov_tag_length(buffer, pos, GCOV_TAG_FUNCTION, GCOV_TAG_FUNCTION_LENGTH); - - pos += store_gcov_unsigned(buffer, pos, fi_ptr->ident); - pos += store_gcov_unsigned(buffer, pos, fi_ptr->lineno_checksum); - pos += store_gcov_unsigned(buffer, pos, fi_ptr->cfg_checksum); - - ci_ptr = fi_ptr->ctrs; - - for (ct_idx = 0; ct_idx < GCOV_COUNTERS; ct_idx++) { - if (!gi_ptr->merge[ct_idx]) { - /* Unused counter */ - continue; - } - - /* Counter record. */ - pos += store_gcov_tag_length(buffer, pos, - GCOV_TAG_FOR_COUNTER(ct_idx), - GCOV_TAG_COUNTER_LENGTH(ci_ptr->num)); - - for (cv_idx = 0; cv_idx < ci_ptr->num; cv_idx++) { - pos += store_gcov_counter(buffer, pos, - ci_ptr->values[cv_idx]); - } - ci_ptr++; - } - } - - /* return count of bytes (convert from count of buffer data type units) */ - return pos * sizeof(*buffer); -} - -/** - * gcov_clear_counters - set profiling counters to zero - * @info: profiling data set to be cleared - * - */ -/* Our own creation, but compare to libgcc/libgcov-driver.c function write_one_data() */ -void gcov_clear_counters(struct gcov_info *gi_ptr) -{ - const struct gcov_fn_info *fi_ptr; - const struct gcov_ctr_info *ci_ptr; - unsigned int fi_idx; - unsigned int ct_idx; - unsigned int cv_idx; - - /* Clear execution counts for each function. */ - for (fi_idx = 0; fi_idx < gi_ptr->n_functions; fi_idx++) { - fi_ptr = gi_ptr->functions[fi_idx]; - - ci_ptr = fi_ptr->ctrs; - - for (ct_idx = 0; ct_idx < GCOV_COUNTERS; ct_idx++) { - if (!gi_ptr->merge[ct_idx]) { - /* Unused counter */ - continue; - } - - /* Counter record. */ - for (cv_idx = 0; cv_idx < ci_ptr->num; cv_idx++) { - ci_ptr->values[cv_idx] = 0; - } - ci_ptr++; - } - } - - return; -} - -/** @} - */ -/* - * embedded-gcov gcov_gcc.c gcov internals interface code - * - * Copyright (c) 2021 California Institute of Technology (“Caltech”). - * U.S. Government sponsorship acknowledged. - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of Caltech nor its operating division, the Jet Propulsion Laboratory, - * nor the names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ diff --git a/lib/gcov/gcov_gcc.h b/lib/gcov/gcov_gcc.h deleted file mode 100644 index 4c464a03..00000000 --- a/lib/gcov/gcov_gcc.h +++ /dev/null @@ -1,136 +0,0 @@ -/**********************************************************************/ -/** @addtogroup embedded_gcov - * @{ - * @file - * @version $Id: $ - * - * @author 2021-08-31 kjpeters Working and cleaned up version. - * @author 2022-01-07 kjpeters Adjust gcc releases for GCOV_COUNTERS. - * - * @note Based on GCOV-related code of the Linux kernel, - * as described online by Thanassis Tsiodras (April 2016) - * https://www.thanassis.space/coverage.html - * and by Alexander Tarasikov - * http://allsoftwaresucks.blogspot.com/2015/05/gcov-is-amazing-yet-undocumented.html - * with additional investigation, updating, cleanup, and portability - * by Ken Peters. - * - * @brief Private header file for embedded gcov. - * - **********************************************************************/ -/* - * This code is based on the GCOV-related code of the Linux kernel (kept under - * "kernel/gcov"). It basically uses the convert_to_gcda function to generate - * the .gcda files information upon application completion, and dump it on the - * host filesystem via GDB scripting. - * - * Original Linux banner follows below - but note that the Linux guys have - * nothing to do with these modifications, so blame me (and contact me) - * if something goes wrong. - * - * Thanassis Tsiodras - * Real-time Embedded Software Engineer - * System, Software and Technology Department - * European Space Agency - * - * e-mail: ttsiodras@gmail.com / Thanassis.Tsiodras@esa.int (work) - * - */ - - -/* - * Profiling infrastructure declarations. - * - * This file is based on gcc-internal definitions. Data structures are - * defined to be compatible with gcc counterparts. For a better - * understanding, refer to gcc source: gcc/gcov-io.h. - * - * Copyright IBM Corp. 2009 - * Author(s): Peter Oberparleiter - * - * Uses gcc-internal data definitions. - */ - -#ifndef GCOV_GCC_H -#define GCOV_GCC_H GCOV_GCC_H - -#include // for size_t - -#include "gcov_public.h" - -/* Compare to gcc/gcov-counter.def and gcc/gcov-io.h */ -/* GCC has changed this back and forth over time, do not know exact GCC versions */ -/* This has been used with GCC 7.5.0 and GCC 11.1.0 */ -#if (__GNUC__ >= 10) -#define GCOV_COUNTERS 8 -#elif (__GNUC__ >= 5) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9) -#define GCOV_COUNTERS 9 -#else -#define GCOV_COUNTERS 8 -#endif - -/* Compare to gcc/gcov-io.h */ - -/* - * Profiling data types used for gcc 3.4 and above - these are defined by - * gcc and need to be kept as close to the original definition as possible to - * remain compatible. - * Compare to gcc/gcov-io.h - * (gcc 11.1.0 (but not 11.2.0) multiplied counter length by 2*4, - * but we do not need to duplicate that glitch(?)) - */ -#define GCOV_DATA_MAGIC ((gcov_unsigned_t) 0x67636461) -#define GCOV_TAG_FUNCTION ((gcov_unsigned_t) 0x01000000) -#define GCOV_TAG_FUNCTION_LENGTH (3) -#define GCOV_TAG_COUNTER_BASE ((gcov_unsigned_t) 0x01a10000) -#define GCOV_TAG_COUNTER_LENGTH(NUM) ((NUM) * 2) -#define GCOV_TAG_FOR_COUNTER(count) (GCOV_TAG_COUNTER_BASE + ((gcov_unsigned_t) (count) << 17)) - -/* Interface to access gcov_info data */ -/* Our own creation */ -const char *gcov_info_filename(struct gcov_info *info); - -/* Convert internal gcov data tree into .gcds output format */ -/* Our own creation (though based on gcc internals, see source code) */ -/* Need buffer to be 32-bit-aligned for type-safe internal usage */ -size_t gcov_convert_to_gcda(gcov_unsigned_t *buffer, struct gcov_info *info); - -/* Convert internal gcov data tree into .gcds output format */ -/* Our own creation (though based on gcc internals, see source code) */ -void gcov_clear_counters(struct gcov_info *gi_ptr); - -#endif /* GCOV_GCC_H */ - -/** @} - */ -/* - * embedded-gcov gcov_gcc.h gcov internals interface code - * - * Copyright (c) 2021 California Institute of Technology (“Caltech”). - * U.S. Government sponsorship acknowledged. - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of Caltech nor its operating division, the Jet Propulsion Laboratory, - * nor the names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ diff --git a/lib/gcov/gcov_printf.c b/lib/gcov/gcov_printf.c deleted file mode 100644 index 99da3075..00000000 --- a/lib/gcov/gcov_printf.c +++ /dev/null @@ -1,296 +0,0 @@ -/**********************************************************************/ -/** @addtogroup gcov - * @{ - * @file - * @version $Id: gcov_printf.c 302 2015-09-14 23:41:57Z scclancy $ - * @author 2008-10-30 cyamamot - * @author 2021-08-24 kjpeters - * @author 2022-01-03 kjpeters Adjust character output for portability. - * - * Provide small imitation printf function. - * This is only needed if you want serial port outputs and - * do not have already-existing functions to do the printing. - * If you select this, then you need to provide a function - * write_bytes() that does the actual serial output in your system. - * - * @brief Formatted printing utility functions - **********************************************************************/ - -#include "gcov_public.h" - -#ifdef GCOV_OPT_PROVIDE_PRINTF_IMITATION - -#include - -/* Include any files you need to get your write_bytes() function */ -/* that does the actual serial output in your system. */ -/* - * INT32 - * write_bytes(INT32 fd, - * CHAR_T const *buf, - * UINT32 nbyte); - * where - * @param [in] fd (which serial port) - * @param [in,out] *buf (bytes to send out) - * @param [in] nbyte (number of bytes to send) - * - * @return -1 if error, otherwise returns byte count written to UART - */ -#include -#include -//#define write_bytes(fd, buf, n) putchar((int)(*(buf))) -extern void write_bytes(int fd, char* buf, int n); - -/*********************************************************************** - * The following functions support gcov_printf and are not meant to be - * called otherwise. - **********************************************************************/ -static void gcov_uli2a(unsigned long int num, unsigned int base, int uc,char * bf); -static void gcov_uli2a(unsigned long int num, unsigned int base, int uc,char * bf) -{ - int n=0; - unsigned int d=1; - while (num/d >= base) - d*=base; - while (d!=0) { - int dgt = num / d; - num%=d; - d/=base; - if (n || dgt>0|| d==0) { - *bf++ = dgt+(dgt<10 ? '0' : (uc ? 'A' : 'a')-10); - ++n; - } - } - *bf=0; -} - -static void gcov_li2a (long num, char * bf); -static void gcov_li2a (long num, char * bf) -{ - if (num<0) { - num=-num; - *bf++ = '-'; - } - gcov_uli2a(num,10,0,bf); -} - -static void gcov_ui2a(unsigned int num, unsigned int base, int uc,char * bf); -static void gcov_ui2a(unsigned int num, unsigned int base, int uc,char * bf) -{ - int n=0; - unsigned int d=1; - while (num/d >= base) - d*=base; - while (d!=0) { - int dgt = num / d; - num%= d; - d/=base; - if (n || dgt>0 || d==0) { - *bf++ = dgt+(dgt<10 ? '0' : (uc ? 'A' : 'a')-10); - ++n; - } - } - *bf=0; -} - -static void gcov_i2a (int num, char * bf); -static void gcov_i2a (int num, char * bf) -{ - if (num<0) { - num=-num; - *bf++ = '-'; - } - gcov_ui2a(num,10,0,bf); -} - -static int gcov_a2d(char ch); -static int gcov_a2d(char ch) -{ - if (ch>='0' && ch<='9') - return ch-'0'; - else if (ch>='a' && ch<='f') - return ch-'a'+10; - else if (ch>='A' && ch<='F') - return ch-'A'+10; - else return -1; -} - -static char gcov_a2i(char ch, const char* src,int base,int* nump,int *numc); -static char gcov_a2i(char ch, const char* src,int base,int* nump,int *numc) -{ - const char* p= src; - int n=0; - int num=0; - int digit; - while ((digit=gcov_a2d(ch))>=0) { - if (digit>base) break; - num=num*base+digit; - ch=*p++; - n++; - } - *nump=num; - *numc=n; - return ch; -} - -static void gcov_putchw(int n, char z, char* bf); -static void gcov_putchw(int n, char z, char* bf) -{ - char fc=z? '0' : ' '; - char ch; - char* p=bf; - while (*p++ && n > 0) - n--; - while (n-- > 0) - write_bytes(1,&fc,1); - while ((ch= *bf++)) - write_bytes(1,&ch,1); -} - - - -/**********************************************************************/ -/** @brief - * - * @author 2008-10-30 cyamamot - * @author 2021-08-24 kjpeters - * @author 2022-01-03 kjpeters Adjust character output for portability. - * - * @param [in] *fmt - * @param [in] va - * - * @note This is a supporting function for \ref gcov_printf gcov_printf - * and is not meant to be called otherwise. - **********************************************************************/ -static void gcov_format(const char *fmt, va_list va); -static void gcov_format(const char *fmt, va_list va) -{ - // 10/3/2017 m. chase - Added abort flag to remove the need of goto - - char bf[12]; - char ch; - char c2; - char abort_flg = 0; // make nonzero to abort - - while ((ch=*(fmt++)) && (!abort_flg)) { - if (ch!='%') - write_bytes(1,&ch,1); - else { - char lz=0; - char lng=0; - int w=0; - int n=0; - ch=*(fmt++); - if (ch=='0') { - ch=*(fmt++); - lz=1; - } - if (ch>='0' && ch<='9') { - ch=gcov_a2i(ch,fmt,10,&w,&n); - fmt+=n; - } - if (ch=='l') { - ch=*(fmt++); - lng=1; - } - if(ch==0) { - abort_flg = 1; - } - else { - switch (ch) { - case 'u' : { - if (lng) - gcov_uli2a(va_arg(va, unsigned long int),10,0,bf); - else - gcov_ui2a(va_arg(va, unsigned int),10,0,bf); - gcov_putchw(w,lz,bf); - break; - } - case 'd' : { - if (lng) - gcov_li2a(va_arg(va, unsigned long int),bf); - else - gcov_i2a(va_arg(va, int),bf); - gcov_putchw(w,lz,bf); - break; - } - case 'x': case 'X' : - if (lng) - gcov_uli2a(va_arg(va, unsigned long int),16,(ch=='X'),bf); - else - gcov_ui2a(va_arg(va, unsigned int),16,(ch=='X'),bf); - gcov_putchw(w,lz,bf); - break; - case 'c' : - c2 = (char)(va_arg(va, int)); - write_bytes(1,&c2,1); - break; - case 's' : - gcov_putchw(w,0,va_arg(va, char*)); - break; - case '%' : - write_bytes(1,&ch,1); - default: - break; - } - } - } - } -} - - - -/**********************************************************************/ -/** @brief Simplistic printf() function, floating point not supported - * - * @author 2008-10-30 cyamamot - * @author 2021-08-24 kjpeters - * - * @param [in] *fmt - * @param [in] ... variable length argument list - * - **********************************************************************/ -void gcov_printf(const char *fmt, ...) -{ - va_list va; - va_start(va,fmt); - gcov_format(fmt,va); - va_end(va); -} - -#endif // GCOV_OPT_PROVIDE_PRINTF_IMITATION - - -/** @} - */ -/* - * embedded-gcov gcov_printf.c gcov small printf imitation if needed - * - * Copyright (c) 2021 California Institute of Technology (“Caltech”). - * U.S. Government sponsorship acknowledged. - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of Caltech nor its operating division, the Jet Propulsion Laboratory, - * nor the names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ diff --git a/lib/gcov/gcov_public.c b/lib/gcov/gcov_public.c deleted file mode 100644 index eded9a36..00000000 --- a/lib/gcov/gcov_public.c +++ /dev/null @@ -1,494 +0,0 @@ -/**********************************************************************/ -/** @addtogroup embedded_gcov - * @{ - * @file - * @version $Id: $ - * - * @author 2021-08-31 kjpeters Working and cleaned up version. - * @author 2021-09-20 kjpeters Use preprocessor macros to hide printf. - * @author 2022-01-03 kjpeters Add file output. - * @author 2022-07-31 kjpeters Add reinit of static variables. - * - * @note Based on GCOV-related code of the Linux kernel, - * as described online by Thanassis Tsiodras (April 2016) - * https://www.thanassis.space/coverage.html - * and by Alexander Tarasikov - * http://allsoftwaresucks.blogspot.com/2015/05/gcov-is-amazing-yet-undocumented.html - * with additional investigation, updating, cleanup, and portability - * by Ken Peters. - * - * @brief Public source file for embedded gcov. - * - **********************************************************************/ -/* - * This code is based on the GCOV-related code of the Linux kernel (kept under - * "kernel/gcov"). It basically uses the convert_to_gcda function to generate - * the .gcda files information upon application completion, and dump it on the - * host filesystem via GDB scripting. - * - * Original Linux banner follows below - but note that the Linux guys have - * nothing to do with these modifications, so blame me (and contact me) - * if something goes wrong. - * - * Thanassis Tsiodras - * Real-time Embedded Software Engineer - * System, Software and Technology Department - * European Space Agency - * - * e-mail: ttsiodras@gmail.com / Thanassis.Tsiodras@esa.int (work) - * - */ - - -/* - * This code maintains a list of active profiling data structures. - * - * Copyright IBM Corp. 2009 - * Author(s): Peter Oberparleiter - * - * Uses gcc-internal data definitions. - * Based on the gcov-kernel patch by: - * Hubertus Franke - * Nigel Hinds - * Rajan Ravindran - * Peter Oberparleiter - * Paul Larson - */ - -#include "gcov_gcc.h" - -typedef unsigned int u32; -#define UINT32 unsigned int - -#if defined(GCOV_OPT_USE_MALLOC) || defined(GCOV_OPT_USE_STDLIB) -#include -#endif - -#if defined(GCOV_OPT_PRINT_STATUS) || defined(GCOV_OPT_OUTPUT_SERIAL_HEXDUMP) -/* Include any header files needed for serial port I/O */ -/* Not always stdio.h for highly embedded systems */ -#include -//#include "all.h" -#endif - -#ifdef GCOV_OPT_OUTPUT_BINARY_MEMORY -/* You need to set the output buffer pointer to your memory block */ -/* Size used will depend on size and complexity of source code - * that you have compiled for coverage. */ -static unsigned char *gcov_output_buffer = (unsigned char *)(0x42000000); -static gcov_unsigned_t gcov_output_index; -#endif // GCOV_OPT_OUTPUT_BINARY_MEMORY - -typedef struct tagGcovInfo { - struct gcov_info *info; - struct tagGcovInfo *next; -} GcovInfo; -static GcovInfo *gcov_headGcov = NULL; - -#ifndef GCOV_OPT_USE_MALLOC -/* Declare space. Need one entry per file compiled for coverage. */ -static GcovInfo gcov_GcovInfo[100]; -static gcov_unsigned_t gcov_GcovIndex = 0; - -/* Declare space. Needs to be enough for the largest single file coverage data. */ -/* Size used will depend on size and complexity of source code - * that you have compiled for coverage. */ -/* Need buffer to be 32-bit-aligned for type-safe internal usage */ -gcov_unsigned_t gcov_buf[8192]; -#endif // not GCOV_OPT_USE_MALLOC - -/* ----------------------------------------------------------- */ -/* - * __gcov_init is called by gcc-generated constructor code for each - * object file compiled with -fprofile-arcs. - * - * Depending on how your embedded system starts up, - * you may need to enable (in gcov_public.h) and call - * the helper function __gcov_call_constructors below - * from close to the beginning of your code. - */ - -void __gcov_init(struct gcov_info *info) -{ - GcovInfo *newHead = NULL; - -#ifdef GCOV_OPT_PRINT_STATUS - GCOV_PRINT_STR("__gcov_init called for "); - GCOV_PRINT_STR(gcov_info_filename(info)); - GCOV_PRINT_STR("\n"); -#ifdef GCOV_OPT_USE_STDLIB - fflush(stdout); -#endif // GCOV_OPT_USE_STDLIB -#endif // GCOV_OPT_PRINT_STATUS - -#ifdef GCOV_OPT_USE_MALLOC - newHead = malloc(sizeof(GcovInfo)); -#else - if (gcov_GcovIndex >= sizeof(gcov_GcovInfo)/sizeof(gcov_GcovInfo[0])) { - newHead = NULL; - } else { - newHead = gcov_GcovInfo + gcov_GcovIndex; - } -#endif // GCOV_OPT_USE_MALLOC else - - if (!newHead) { -#ifdef GCOV_OPT_PRINT_STATUS - GCOV_PRINT_STR("Out of memory!"); GCOV_PRINT_STR("\n"); -#endif // GCOV_OPT_PRINT_STATUS -#ifdef GCOV_OPT_USE_STDLIB - exit(1); -#else - return; -#endif // GCOV_OPT_USE_STDLIB - } - - newHead->info = info; - newHead->next = gcov_headGcov; - gcov_headGcov = newHead; - -#ifndef GCOV_OPT_USE_MALLOC - gcov_GcovIndex++; -#endif // not GCOV_OPT_USE_MALLOC -} - - -/* ----------------------------------------------------------- */ -#ifdef GCOV_OPT_PROVIDE_CALL_CONSTRUCTORS -/* - * Your code may need to call this function to execute the - * contructors that call __gcov_init (even in plain C). - * Might be needed if you are not running a standard - * C program startup (such as in boot code). - * - * If used, you need to provide a linker file that creates a constructor section, - * and defines symbols __ctor_list at the start and __ctor_end at the end. - * gcov_public.h has external declarations for those symbols. - * - * An example linker file segment: - -.ctors : { - __ctor_list = . ; - *(SORT(.ctors.*)) - *(.ctors) - __ctor_end = . ; - . = ALIGN(16); -} > ram - - * - */ - -void __gcov_call_constructors(void) { - void **ctor; - - /* Reinitialize static variables. - * In case of unusual situations, where your code re-executes - * this function without your code actually restarting, - * so that static variables would otherwise - * be left as is, not reinitialized. - * - * This does not clear line counters that might also - * remain in such a situation, call __gcov_clear() if - * you need to clear the counters. - * - * If not actually restarting, and if using malloc, - * and if you do not call __gcov_exit between calls - * to this function to free the memory, - * you will have memory leaks. - */ - gcov_headGcov = NULL; -#ifndef GCOV_OPT_USE_MALLOC - gcov_GcovIndex = 0; -#endif - - ctor = &__ctor_list; - while (ctor != &__ctor_end) { - void (*func)(void); - - func = (void ( *)(void))(*(UINT32 *)ctor); - - func(); - ctor++; - } -} -#endif // GCOV_OPT_PROVIDE_CALL_CONSTRUCTORS - - -/* ----------------------------------------------------------- */ -/* - * __gcov_exit needs to be called in your code at the point - * where you want to generate coverage data for extraction. - */ -void __gcov_exit(void) -{ - GcovInfo *listptr = gcov_headGcov; - -#if defined(GCOV_OPT_OUTPUT_BINARY_FILE) || defined(GCOV_OPT_OUTPUT_BINARY_MEMORY) - char const *p; -#endif - -#ifdef GCOV_OPT_OUTPUT_BINARY_FILE - unsigned char bf; - GCOV_FILE_TYPE file; -#endif // GCOV_OPT_OUTPUT_BINARY_FILE - -#ifdef GCOV_OPT_OUTPUT_BINARY_MEMORY - gcov_output_index = 0; -#endif // GCOV_OPT_OUTPUT_BINARY_MEMORY - -#ifdef GCOV_OPT_PRINT_STATUS - GCOV_PRINT_STR("gcov_exit"); GCOV_PRINT_STR("\n"); -#endif // GCOV_OPT_PRINT_STATUS - -#ifdef GCOV_OPT_OUTPUT_BINARY_FILE - file = GCOV_OPEN_FILE(GCOV_OUTPUT_BINARY_FILENAME); - if (GCOV_OPEN_ERROR(file)) { -#ifdef GCOV_OPT_PRINT_STATUS - GCOV_PRINT_STR("Unable to open gcov output file!"); GCOV_PRINT_STR("\n"); -#endif // GCOV_OPT_PRINT_STATUS -#ifdef GCOV_OPT_USE_STDLIB - exit(1); -#else - return; -#endif // GCOV_OPT_USE_STDLIB - } -#endif // GCOV_OPT_OUTPUT_BINARY_FILE - - while (listptr) { - gcov_unsigned_t *buffer = NULL; // Need buffer to be 32-bit-aligned for type-safe internal usage - u32 bytesNeeded; - - /* Do pretend conversion to see how many bytes are needed */ - bytesNeeded = gcov_convert_to_gcda(NULL, listptr->info); - -#ifdef GCOV_OPT_USE_MALLOC - buffer = malloc(bytesNeeded); -#else - if (bytesNeeded > sizeof(gcov_buf)/sizeof(char)) { - buffer = (gcov_unsigned_t *)NULL; - } else { - buffer = gcov_buf; - } -#endif // GCOV_OPT_USE_MALLOC else - - if (!buffer) { -#ifdef GCOV_OPT_PRINT_STATUS - GCOV_PRINT_STR("Out of memory!"); GCOV_PRINT_STR("\n"); -#endif // GCOV_OPT_PRINT_STATUS -#ifdef GCOV_OPT_USE_STDLIB - exit(1); -#else - return; -#endif // GCOV_OPT_USE_STDLIB - } - - /* Do the real conversion into buffer */ - gcov_convert_to_gcda(buffer, listptr->info); - -#if defined(GCOV_OPT_PRINT_STATUS) || defined(GCOV_OPT_OUTPUT_SERIAL_HEXDUMP) - GCOV_PRINT_STR("Emitting "); - GCOV_PRINT_NUM(bytesNeeded); - GCOV_PRINT_STR(" bytes for "); - GCOV_PRINT_STR(gcov_info_filename(listptr->info)); - GCOV_PRINT_STR("\n"); -#endif - -#ifdef GCOV_OPT_OUTPUT_BINARY_FILE - /* write the filename */ - p = gcov_info_filename(listptr->info); - while (p && (*p)) { - bf = (*p++); - (void)GCOV_WRITE_BYTE(file, bf); - } - /* add trailing null char */ - bf = '\0'; - (void)GCOV_WRITE_BYTE(file, bf); - - /* write the data byte count */ - /* we don't know endianness, so use division for consistent MSB first */ - bf = (unsigned char)(bytesNeeded / 16777216); - (void)GCOV_WRITE_BYTE(file, bf); - bf = (unsigned char)(bytesNeeded / 65536); - (void)GCOV_WRITE_BYTE(file, bf); - bf = (unsigned char)(bytesNeeded / 255); - (void)GCOV_WRITE_BYTE(file, bf); - bf = (unsigned char)(bytesNeeded); - (void)GCOV_WRITE_BYTE(file, bf); - - /* write the data */ - for (u32 i=0; iinfo); - while (p && (*p)) { - gcov_output_buffer[gcov_output_index++] = (*p++); - } - /* add trailing null char */ - gcov_output_buffer[gcov_output_index++] = '\0'; - - /* store the data byte count */ - /* we don't know endianness, so use division for consistent MSB first */ - gcov_output_buffer[gcov_output_index++] = (unsigned char)(bytesNeeded / 16777216); - gcov_output_buffer[gcov_output_index++] = (unsigned char)(bytesNeeded / 65536); - gcov_output_buffer[gcov_output_index++] = (unsigned char)(bytesNeeded / 255); - gcov_output_buffer[gcov_output_index++] = (unsigned char)(bytesNeeded); - - /* copy the data */ - for (u32 i=0; iinfo)); - GCOV_PRINT_STR("\n"); -#endif // GCOV_OPT_OUTPUT_SERIAL_HEXDUMP - -/* Other output methods might be imagined, - * if you have flash that can be written directly, - * or the luxury of a filesystem, etc. - */ - -#ifdef GCOV_OPT_USE_MALLOC - free(buffer); -#endif // GCOV_OPT_USE_MALLOC - - listptr = listptr->next; - } /* end while listptr */ - - /* Add end marker to output */ -#ifdef GCOV_OPT_OUTPUT_BINARY_FILE - bf = 'G'; - (void)GCOV_WRITE_BYTE(file, bf); - bf = 'c'; - (void)GCOV_WRITE_BYTE(file, bf); - bf = 'o'; - (void)GCOV_WRITE_BYTE(file, bf); - bf = 'v'; - (void)GCOV_WRITE_BYTE(file, bf); - bf = ' '; - (void)GCOV_WRITE_BYTE(file, bf); - bf = 'E'; - (void)GCOV_WRITE_BYTE(file, bf); - bf = 'n'; - (void)GCOV_WRITE_BYTE(file, bf); - bf = 'd'; - (void)GCOV_WRITE_BYTE(file, bf); - bf = '\0'; - (void)GCOV_WRITE_BYTE(file, bf); - - GCOV_CLOSE_FILE(file); -#endif // GCOV_OPT_OUTPUT_BINARY_FILE - -#ifdef GCOV_OPT_OUTPUT_BINARY_MEMORY - gcov_output_buffer[gcov_output_index++] = 'G'; - gcov_output_buffer[gcov_output_index++] = 'c'; - gcov_output_buffer[gcov_output_index++] = 'o'; - gcov_output_buffer[gcov_output_index++] = 'v'; - gcov_output_buffer[gcov_output_index++] = ' '; - gcov_output_buffer[gcov_output_index++] = 'E'; - gcov_output_buffer[gcov_output_index++] = 'n'; - gcov_output_buffer[gcov_output_index++] = 'd'; - gcov_output_buffer[gcov_output_index++] = '\0'; -#endif // GCOV_OPT_OUTPUT_BINARY_MEMORY - -#if defined(GCOV_OPT_PRINT_STATUS) || defined(GCOV_OPT_OUTPUT_SERIAL_HEXDUMP) - GCOV_PRINT_STR("Gcov End"); - GCOV_PRINT_STR("\n"); -#endif -} - -/* ----------------------------------------------------------- */ -#ifdef GCOV_OPT_PROVIDE_CLEAR_COUNTERS -/* - * __gcov_clear is optional to call if you want to clear the counters, - * such as after program startup (if you don't want to count the startup) - * or between test runs. - * The counters are automatically zero at startup. - */ -void __gcov_clear(void) -{ - GcovInfo *listptr = gcov_headGcov; - -#ifdef GCOV_OPT_PRINT_STATUS - GCOV_PRINT_STR("gcov_clear"); GCOV_PRINT_STR("\n"); -#endif // GCOV_OPT_PRINT_STATUS - - while (listptr) { - - gcov_clear_counters(listptr->info); - - listptr = listptr->next; - } -} -#endif // GCOV_OPT_PROVIDE_CLEAR_COUNTERS - -/* ----------------------------------------------------------- */ -/* - * This function should never be called. Merging is not supported. - * Just providing for the interface, and to warn if someone - * (including gcc internals) tries to use it. - */ -void __gcov_merge_add(gcov_type *counters, gcov_unsigned_t n_counters) -{ - (void)counters; // ignore unused param - (void)n_counters; // ignore unused param - -#ifdef GCOV_OPT_PRINT_STATUS - GCOV_PRINT_STR("__gcov_merge_add isn't called, right? Right? RIGHT?"); -#endif // GCOV_OPT_PRINT_STATUS - -#ifdef GCOV_OPT_USE_STDLIB - fflush(stdout); - exit(1); -#else - return; -#endif // GCOV_OPT_USE_STDLIB -} - -/** @} - */ -/* - * embedded-gcov gcov_public.c gcov application interface code - * - * Copyright (c) 2021 California Institute of Technology (“Caltech”). - * U.S. Government sponsorship acknowledged. - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of Caltech nor its operating division, the Jet Propulsion Laboratory, - * nor the names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ diff --git a/lib/gcov/gcov_public.h b/lib/gcov/gcov_public.h deleted file mode 100644 index 776fd01a..00000000 --- a/lib/gcov/gcov_public.h +++ /dev/null @@ -1,269 +0,0 @@ -/**********************************************************************/ -/** @addtogroup embedded_gcov - * @{ - * @file - * @version $Id: $ - * - * @author 2021-08-31 kjpeters Working and cleaned up version. - * @author 2021-09-20 kjpeters Provide optional printf imitation. - * @author 2022-01-03 kjpeters Add file output. - * - * @note Based on GCOV-related code of the Linux kernel, - * as described online by Thanassis Tsiodras (April 2016) - * https://www.thanassis.space/coverage.html - * and by Alexander Tarasikov - * http://allsoftwaresucks.blogspot.com/2015/05/gcov-is-amazing-yet-undocumented.html - * with additional investigation, updating, cleanup, and portability - * by Ken Peters. - * - * @brief Public header file for embedded gcov. - * - **********************************************************************/ -#ifndef __GCOV_PUBLIC_H__ -#define __GCOV_PUBLIC_H__ - -/* User-selectable compile-time options for the embedded gcov */ -/* Not all have been fully tested */ - -/* select internal customizations ------------------------------------ */ -/* needed to adapt to your system */ - -/* Allow functions to use malloc to get data buffers. - * Not all embedded systems allow that, but instead - * must declare all data in advance. - * If not allowing malloc, might require your custom code - * in gcov_public.c to set buffer sizes. - */ -#define GCOV_OPT_USE_MALLOC - -/* Allow functions to use othe stdlib functions. - * Not all embedded systems allow that, but instead - * haave their own functions or imitations. - * If not allowing stdlib, might require your custom code - * in gcov_public.c to call appropriate functions. - */ -#define GCOV_OPT_USE_STDLIB - -/* Allow functions to print status and error messages. - * Not all embedded systems support that. - * If not enabled, you might want custom code in gcov_public.c - * to indicate some other way. - * If defined, you must also provide defs below - * for GCOV_PRINT_STR and GCOV_PRINT_NUM. - */ -#define GCOV_OPT_PRINT_STATUS - -/* Reset watchdog timeout during gcov tree scanning. - * Might be needed if you enable serial output on a slow port, - * or if you have a very short watchdog timeout. - * Requires your custom code in gcov_gcc.c - */ -//#define GCOV_OPT_RESET_WATCHDOG - -/* Provide function to call constructor list (even in plain C) - * (to call the gcc-generated code that calls __gcov_init). - * Might be needed if you are not running a standard - * C program startup that already does this (such as in boot code). - * If defined, requires your custom linker file code as described below. - */ -#define GCOV_OPT_PROVIDE_CALL_CONSTRUCTORS - -#ifdef GCOV_OPT_PROVIDE_CALL_CONSTRUCTORS -/* start and end of constructor section defined in link file */ -/* you have to provide appropriate linker file code to define these, - * if your compiler/runtime environment does not automatically. - * An example linker file segment: - -.ctors : { - __ctor_list = . ; - *(SORT(.ctors.*)) - *(.ctors) - __ctor_end = . ; - . = ALIGN(16); -} > ram - - */ -extern void *__ctor_list; -extern void *__ctor_end; -#endif // GCOV_OPT_PROVIDE_CALL_CONSTRUCTORS - -/* Provide function to clear the counter data. - * This is only needed if you want to be able to clear - * the counter data after startup (the counters start up at zero). - * Might be needed if you want to avoid counting your FSW startup, - * or if you want to clear the counters between tests. - * You might NOT want this if you are extremely memory constrained - * (such as in PROM) and do not need this function to take up some bytes. - */ -#define GCOV_OPT_PROVIDE_CLEAR_COUNTERS - -/* Provide small imitation printf function. - * This is only needed if you want serial port outputs and - * do not have already-existing functions to do the printing. - * If you select this, then you need to provide a function - * write_bytes() that does the actual serial output in your system. - * See gcov_printf.c - */ -#define GCOV_OPT_PROVIDE_PRINTF_IMITATION - -/* select data output method(s) ------------------------------------ */ - -/* Other output methods might be imagined, - * if you have flash that can be written directly, etc. - * Can be nice to write the concatenated results - * to one file instead of a bunch of separate .gcda files. - */ -/* Output gcda data as binary format in file. - * Might require your custom code in gcov_public.c - * if your file headers and functions are non-standard. - * Can be combined with other GCOV_OPT_OUTPUT_* options. - */ -//#define GCOV_OPT_OUTPUT_BINARY_FILE - -/* Modify this output filename if desired */ -/* Not used if you do not define GCOV_OPT_OUTPUT_BINARY_FILE */ -#define GCOV_OUTPUT_BINARY_FILENAME "gcov_output.bin" - -/* Modify file headers, data type and functions, if needed */ -/* Not used if you do not define GCOV_OPT_OUTPUT_BINARY_FILE */ -#ifdef GCOV_OPT_OUTPUT_BINARY_FILE -#if 1 -#include -#include -#include -#include - -typedef int GCOV_FILE_TYPE; -#define GCOV_OPEN_FILE(filename) open((filename), (O_CREAT|O_WRONLY), (S_IRWXU|S_IRWXG|S_IRWXO)) -#define GCOV_OPEN_ERROR(fileref) ((fileref) < 0) -#define GCOV_CLOSE_FILE(fileref) close((fileref)) -#define GCOV_WRITE_BYTE(fileref, char_var) write((fileref), &(char_var), (1)) -#else -#include - -typedef FILE * GCOV_FILE_TYPE; -#define GCOV_OPEN_FILE(filename) fopen((filename), ("wb")) -#define GCOV_OPEN_ERROR(fileref) ((fileref) == NULL) -#define GCOV_CLOSE_FILE(fileref) fclose((fileref)) -#define GCOV_WRITE_BYTE(fileref, char_var) fprintf((fileref), "%c", (char_var)) -#endif -#endif // GCOV_OPT_OUTPUT_BINARY_FILE - -/* Output gcda data as binary format in memory block. - * Requires your custom code in gcov_public.c - * to set the starting address of the block. - * Can be combined with other GCOV_OPT_OUTPUT_* options. - */ -//#define GCOV_OPT_OUTPUT_BINARY_MEMORY - -/* Output gcda data as hexdump format ASCII on serial port. - * Might require your custom code in gcov_public.c - * if your serial headers and functions are not stdio.h, - * puts, and printf. - * If defined, you must also provide defs below - * for GCOV_PRINT_STR and GCOV_PRINT_NUM. - * Can be combined with other GCOV_OPT_OUTPUT_* options. - */ -#define GCOV_OPT_OUTPUT_SERIAL_HEXDUMP - -/* Function to print a string without newline. - * Not used if you don't define either GCOV_OPT_PRINT_STATUS - * or GCOV_OPT_OUTPUT_SERIAL_HEXDUMP. - * If you do, you need to set this as appropriate for your system. - * You might need to add header files to gcc_public.c - */ -//#define GCOV_PRINT_STR(str) fputs((str), stdout) -//#define GCOV_PRINT_STR(str) printf("%s", str) -#define GCOV_PRINT_STR(str) gcov_printf("%s", str) -//#define GCOV_PRINT_STR(str) puts((str)) - -/* Function to print a number without newline. - * Not used if you don't define either GCOV_OPT_PRINT_STATUS - * or GCOV_OPT_OUTPUT_SERIAL_HEXDUMP. - * If you do, you need to set this as appropriate for your system. - * You might need to add header files to gcc_public.c - */ -//#define GCOV_PRINT_NUM(num) printf("%d", (num)) -#define GCOV_PRINT_NUM(num) gcov_printf("%d", (num)) -//#define GCOV_PRINT_NUM(num) print_num((num)) - -/* Function to print hexdump address. - * Not used if you don't define GCOV_OPT_OUTPUT_SERIAL_HEXDUMP. - * If you do, you need to set this as appropriate for your system. - * You might need to add header files to gcc_public.c - */ -//#define GCOV_PRINT_HEXDUMP_ADDR(num) printf("%08x: ", (num)) -#define GCOV_PRINT_HEXDUMP_ADDR(num) gcov_printf("%08x: ", (num)) - -/* Function to print hexdump data value. - * Not used if you don't define GCOV_OPT_OUTPUT_SERIAL_HEXDUMP. - * If you do, you need to set this as appropriate for your system. - * You might need to add header files to gcc_public.c - */ -//#define GCOV_PRINT_HEXDUMP_DATA(num) printf("%02x ", (num)) -#define GCOV_PRINT_HEXDUMP_DATA(num) gcov_printf("%02x ", (num)) - -/* End of user settings ---------------------------------- */ - -/* Opaque gcov_info. The gcov structures can change as for example in gcc 4.7 so - * we cannot use full definition here and they need to be placed in gcc specific - * implementation of gcov. This also means no direct access to the members in - * generic code and usage of the interface below.*/ -struct gcov_info; - -/* Compare to gcc/gcov-io.h */ -typedef unsigned gcov_unsigned_t; -typedef long long gcov_type; - -/* Compare to libgcc/libgcov.h */ -void __gcov_init(struct gcov_info *info); -void __gcov_exit(void); -void __gcov_merge_add(gcov_type *counters, gcov_unsigned_t n_counters); - -/* Our own creations */ -#ifdef GCOV_OPT_PROVIDE_CLEAR_COUNTERS -void __gcov_clear(void); -#endif -#ifdef GCOV_OPT_PROVIDE_CALL_CONSTRUCTORS -void __gcov_call_constructors(void); -#endif - -#ifdef GCOV_OPT_PROVIDE_PRINTF_IMITATION -void gcov_printf(const char *fmt, ...); -#endif - -#endif // __GCOV_PUBLIC_H__ - -/** @} - */ -/* - * embedded-gcov gcov_public.h gcov application interface code - * - * Copyright (c) 2021 California Institute of Technology (“Caltech”). - * U.S. Government sponsorship acknowledged. - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of Caltech nor its operating division, the Jet Propulsion Laboratory, - * nor the names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ diff --git a/platformio.ini b/platformio.ini index 6a1f1492..da569824 100644 --- a/platformio.ini +++ b/platformio.ini @@ -148,33 +148,6 @@ board_build.partitions = part32.csv board_build.filesystem = littlefs board_build.embed_txtfiles = ${common_env_data.html_files} -; [env:gravity32c3v1-release] -; framework = arduino -; platform = ${common_env_data.platform32} -; upload_speed = ${common_env_data.upload_speed} -; monitor_speed = ${common_env_data.monitor_speed} -; extra_scripts = ${common_env_data.extra_scripts} -; build_unflags = -; ${common_env_data.build_unflags} -; build_flags = -; -Wl,-Map,output.map -; ${common_env_data.build_flags} -; -D LOG_LEVEL=4 -; -D CORE_DEBUG_LEVEL=2 -; -D ESP32C3 -; -D ARDUINO_ESP32C3_DEV -; -D ESP32C3_REV1 -; #-D USE_SERIAL_PINS # Use the TX/RX pins for the serial port -; lib_deps = -; ${common_env_data.lib_deps} -; ${common_env_data.lib_deps32} -; lib_ignore = -; board = lolin_c3_mini -; build_type = release -; board_build.partitions = part32.csv -; board_build.filesystem = littlefs -; board_build.embed_txtfiles = ${common_env_data.html_files} - [env:gravity32s2-release] framework = arduino platform = ${common_env_data.platform32} @@ -257,45 +230,3 @@ build_type = release board_build.partitions = part32.csv board_build.filesystem = littlefs board_build.embed_txtfiles = ${common_env_data.html_files} - -[env:cov-esp32] -framework = arduino -platform = ${common_env_data.platform32} -upload_speed = ${common_env_data.upload_speed} -monitor_speed = ${common_env_data.monitor_speed} -extra_scripts = - ${common_env_data.extra_scripts} - #script/merge_firmware.py - pre:script/gcov_filter.py -build_unflags = - ${common_env_data.build_unflags} -build_flags = - -Wl,-Map,output.map - ${common_env_data.build_flags} - -D ACTIVATE_GCOV - -D ESP32S2 - -D ARDUINO_ESP32S2_DEV - #-D ESP32C3 - #-D ARDUINO_ESP32C3_DEV - #-D USER_SSID=\""\"" - #-D USER_SSID_PWD=\""\"" - -D LOG_LEVEL=4 - -D CORE_DEBUG_LEVEL=2 - #-D USE_SERIAL_PINS # Use the TX/RX pins for the serial port - -D ARDUINO_USB_CDC_ON_BOOT=1 -lib_deps = - ${common_env_data.lib_deps} - #${common_env_data.lib_deps32} -lib_ignore = -board = lolin_s2_mini -build_type = debug -board_build.partitions = part32.csv -board_build.filesystem = littlefs -board_build.embed_txtfiles = ${common_env_data.html_files} -#board_build.flash_mode = dio -custom_gcov_files = disable -#custom_gcov_files = webserver.cpp gyro.cpp main.cpp -#custom_gcov_files = webserver.cpp -#custom_gcov_files = main.cpp -#custom_gcov_files = wifi.cpp - diff --git a/src/ble.cpp b/src/ble.cpp index e3b9216a..2d721be1 100644 --- a/src/ble.cpp +++ b/src/ble.cpp @@ -35,24 +35,6 @@ SOFTWARE. // Tilt data format is described here. Only SG and Temp is transmitted over BLE. // https://kvurd.com/blog/tilt-hydrometer-ibeacon-data-format/ -class CharacteristicCallbacks : public NimBLECharacteristicCallbacks { - private: - volatile bool _isRead = false; - - public: - void clearReadFlag() { _isRead = false; } - bool isRead() { return _isRead; } - - void onRead(NimBLECharacteristic* pCharacteristic) { -#if LOG_LEVEL == 6 - Log.verbose(F("BLE : Remote reading data" CR)); -#endif - _isRead = true; - } -}; - -static CharacteristicCallbacks myCharCallbacks; - void BleSender::init() { if (_initFlag) return; @@ -218,39 +200,6 @@ void BleSender::sendCustomBeaconData(float battery, float tempC, float gravity, _advertising->stop(); } -void BleSender::sendGravitymonData(String payload) { - Log.info(F("BLE : Updating data for gravitymon data transmission" CR)); - - _advertising->stop(); - - if (!_server) { - Log.info( - F("BLE : Creating BLE server for gravitymon data transmission" CR)); - - _server = BLEDevice::createServer(); - _service = _server->createService(BLEUUID("180a")); - _characteristic = _service->createCharacteristic( - BLEUUID("2ac4"), NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::BROADCAST); - _characteristic->setCallbacks(&myCharCallbacks); - _service->start(); - _advertising->addServiceUUID(BLEUUID("180a")); - _advertising->setName("gravitymon"); - _advertising->setScanResponse(false); - _advertising->setMinPreferred(0x06); - _advertising->setMaxPreferred(0x12); - } - - myCharCallbacks.clearReadFlag(); - - if (payload.length() > 510) { - writeErrorLog("BLE : Payload is to long for sending over BLE"); - payload = "{\"error\":\"payload to long\"}"; - } - - _characteristic->setValue(payload); - _advertising->start(); -} - void BleSender::dumpPayload(const char* p, int len) { for (int i = 0; i < len; i++) { EspSerial.printf("%X%X ", (*(p + i) & 0xf0) >> 4, (*(p + i) & 0x0f)); @@ -258,6 +207,4 @@ void BleSender::dumpPayload(const char* p, int len) { EspSerial.println(); } -bool BleSender::isGravitymonDataSent() { return myCharCallbacks.isRead(); } - #endif // ENABLE_BLE diff --git a/src/ble.hpp b/src/ble.hpp index a49eb41d..c09ff048 100644 --- a/src/ble.hpp +++ b/src/ble.hpp @@ -53,10 +53,6 @@ class BleSender { void sendEddystone(float battery, float tempC, float gravity, float angle); void sendCustomBeaconData(float battery, float tempC, float gravity, float angle); - - // Use GATT - void sendGravitymonData(String payload); - bool isGravitymonDataSent(); }; #endif // ENABLE_BLE diff --git a/src/config.hpp b/src/config.hpp index 6bd22c3d..d2252ae7 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -32,7 +32,6 @@ enum BleFormat { BLE_DISABLED = 0, BLE_TILT = 1, BLE_TILT_PRO = 2, - BLE_GRAVITYMON_SERVICE = 3, BLE_GRAVITYMON_EDDYSTONE = 4, BLE_GRAVITYMON_IBEACON = 5 }; diff --git a/src/main.cpp b/src/main.cpp index 36c885e7..3dc95418 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -42,12 +42,6 @@ SOFTWARE. #include #include -#if defined(ACTIVATE_GCOV) -extern "C" { -#include -} -#endif - const char* CFG_APPNAME = "gravitymon"; const char* CFG_FILENAME = "/gravitymon2.json"; const char* CFG_AP_SSID = "GravityMon"; @@ -75,7 +69,7 @@ BleSender myBleSender; #ifdef DEACTIVATE_SLEEPMODE const int interval = 1000; // ms, time to wait between changes to output #else -int interval = 200; // ms, time to wait between changes to output +int interval = 200; // ms, time to wait between changes to output #endif bool sleepModeAlwaysSkip = false; // Flag set in web interface to override normal behaviour @@ -155,8 +149,11 @@ void setup() { // Do this setup for all modes exect wifi setup switch (runMode) { case RunMode::wifiSetupMode: +#if !defined(ESP32C3) + // We cant use LED on ESP32C3 since that pin is connected to GYRO ledOn(LedColor::RED); // Red or fast flashing to indicate connection // error +#endif myWifi.startAP(); break; @@ -210,7 +207,10 @@ void setup() { case RunMode::configurationMode: if (myWifi.isConnected()) { Log.notice(F("Main: Activating web server." CR)); +#if !defined(ESP32C3) + // We cant use LED on ESP32C3 since that pin is connected to GYRO ledOn(LedColor::BLUE); // Blue or slow flashing to indicate config mode +#endif PERF_BEGIN("main-wifi-ota"); if (myOta.checkFirmwareVersion()) myOta.updateFirmware(); PERF_END("main-wifi-ota"); @@ -220,16 +220,22 @@ void setup() { mySerialWebSocket.begin(myWebServer.getWebServer(), &Serial); mySerial.begin(&mySerialWebSocket); } else { +#if !defined(ESP32C3) + // We cant use LED on ESP32C3 since that pin is connected to GYRO ledOn(LedColor::RED); // Red or fast flashing to indicate connection - // error +#endif + // error } interval = 1000; // Change interval from 200ms to 1s break; default: +#if !defined(ESP32C3) + // We cant use LED on ESP32C3 since that pin is connected to GYRO ledOn( LedColor::GREEN); // Green or fast flashing to indicate gravity mode +#endif break; } @@ -314,16 +320,6 @@ bool loopReadGravity() { myBleSender.sendEddystone(myBatteryVoltage.getVoltage(), tempC, gravitySG, angle); } break; - case BleFormat::BLE_GRAVITYMON_SERVICE: { - TemplatingEngine engine; - GravmonPush push(&myConfig); - push.setupTemplateEngine(engine, angle, gravitySG, corrGravitySG, - tempC, (millis() - runtimeMillis) / 1000, - myBatteryVoltage.getVoltage()); - String tpl = push.getTemplate(GravmonPush::TEMPLATE_BLE); - String payload = engine.create(tpl.c_str()); - myBleSender.sendGravitymonData(payload); - } break; } } #endif // ESP32 && !ESP32S2 @@ -356,22 +352,6 @@ bool loopReadGravity() { (millis() - runtimeMillis) / 1000); } } - -#if defined(ESP32) && !defined(ESP32S2) - if (myConfig.getBleFormat() == BleFormat::BLE_GRAVITYMON_SERVICE) { - Log.notice(F("Main: Waiting for ble service to be read." CR)); - int i = 0; - while (!myBleSender.isGravitymonDataSent() && i < 10) { - delay(500); - EspSerial.print("."); - i++; - } - EspSerial.print(CR); - if (myBleSender.isGravitymonDataSent()) - Log.notice(F("Main: Ble service was read by client." CR)); - } -#endif // ESP32 && !ESP32S2 - PERF_END("loop-push"); // Send stats to influx after each push run. diff --git a/src/webserver.cpp b/src/webserver.cpp index dcbb0fee..b8af4f2f 100644 --- a/src/webserver.cpp +++ b/src/webserver.cpp @@ -37,12 +37,6 @@ SOFTWARE. #include #include -#if defined(ACTIVATE_GCOV) -extern "C" { -#include -} -#endif - #if !defined(ESP8266) #include #include diff --git a/test/tests.cpp b/test/tests.cpp index f517271d..aedbefa4 100644 --- a/test/tests.cpp +++ b/test/tests.cpp @@ -24,11 +24,6 @@ SOFTWARE. #include #include #include -#if defined( ACTIVATE_GCOV ) -extern "C" { -#include -} -#endif #include using aunit::Printer; diff --git a/test/tests_x.cpp b/test/tests_x.cpp index a557b9bd..ea7dabf5 100644 --- a/test/tests_x.cpp +++ b/test/tests_x.cpp @@ -25,18 +25,9 @@ SOFTWARE. #include #include -#if defined( ACTIVATE_GCOV ) -extern "C" { -#include -} -#endif - // This should be the last test and its used to dump the gcov data to serial. Uncomment __gcov_exit() to dump coverage data. test(test_exit) { -#if defined( ACTIVATE_GCOV ) - __gcov_exit(); -#endif } // EOF