From 1a0e7b8d6af31f4b0ff5d6f9174e0824e0801cd0 Mon Sep 17 00:00:00 2001 From: dzid26 Date: Wed, 17 Jul 2024 18:46:54 +0100 Subject: [PATCH] Added suport for C23 --- src/Makefile | 2 +- src/ebike_app.c | 2 +- src/ebike_app.h | 3 +-- src/main.h | 4 ++++ tests/load_c_code.py | 6 +++--- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Makefile b/src/Makefile index 8f72acd6..ae1dccb2 100644 --- a/src/Makefile +++ b/src/Makefile @@ -67,7 +67,7 @@ RELS = $(addprefix $(ODIR)/,$(notdir $(EXTRASRCS:.c=.rel))) RELS_DEBUG = $(addprefix $(ODIR_DEBUG)/,$(notdir $(EXTRASRCS:.c=.rel))) override INCLUDES += -I$(IDIR) -I. -override CFLAGS += -m$(PLATFORM) -D$(DEVICE) -Ddouble=float --std-c99 --nolospre --opt-code-speed --peep-asm --peep-file peep.txt +override CFLAGS += -m$(PLATFORM) -D$(DEVICE) -Ddouble=float --std-c23 --nolospre --opt-code-speed --peep-asm --peep-file peep.txt override DEBUG_FLAGS += --out-fmt-elf --debug -D TIME_DEBUG LIBS = diff --git a/src/ebike_app.c b/src/ebike_app.c index 5eebf76c..8e2bc880 100644 --- a/src/ebike_app.c +++ b/src/ebike_app.c @@ -159,7 +159,7 @@ static uint32_t ui32_odometer_compensation_mm = ZERO_ODOMETER_COMPENSATION; static uint8_t ui8_adc_throttle_assist = 0; volatile uint8_t ui8_throttle_adc_in = 0; static uint8_t ui8_throttle_mode_array[2] = {THROTTLE_MODE,STREET_MODE_THROTTLE_MODE}; -volatile bool pedals_torque_loaded = false; +volatile uint8_t pedals_torque_loaded = 0U; // cruise control static uint8_t ui8_cruise_threshold_speed_x10_array[2] = {CRUISE_OFFROAD_THRESHOLD_SPEED_X10,CRUISE_STREET_THRESHOLD_SPEED_X10}; diff --git a/src/ebike_app.h b/src/ebike_app.h index 1080e26e..5ad83f1a 100644 --- a/src/ebike_app.h +++ b/src/ebike_app.h @@ -10,7 +10,6 @@ #define EBIKE_APP_H_ #include -#include // startup boost mode #define CADENCE 0 @@ -22,7 +21,7 @@ extern volatile uint8_t ui8_system_state; // pedals are loaded -extern volatile bool pedals_torque_loaded; +extern volatile uint8_t pedals_torque_loaded; //throttle is enabled and applied extern volatile uint8_t ui8_throttle_adc_in; diff --git a/src/main.h b/src/main.h index 46868fea..dddbbd72 100644 --- a/src/main.h +++ b/src/main.h @@ -500,4 +500,8 @@ HALL_COUNTER_OFFSET_UP: 29 -> 44 #define AVAIABLE_FOR_FUTURE_USE 0 // EEPROM + + +static_assert(MOTOR_TYPE == 0 || MOTOR_TYPE == 1); + #endif // _MAIN_H_ diff --git a/tests/load_c_code.py b/tests/load_c_code.py index 34e986d1..67e6763d 100644 --- a/tests/load_c_code.py +++ b/tests/load_c_code.py @@ -25,7 +25,7 @@ #define __asm__(x) #define __trap """ -compiler_args = ["-std=c99", "-Wall", "-Wextra"] +compiler_args = ["-std=c23", "-Wall", "-Wextra"] linker_args = [] custom_parser = '' # actually don't use sdcpp as the cdef stdint definitions should match x86 platform @@ -117,7 +117,7 @@ def visit_Typedef(self, n, *args): def generate_cdef(module_name, src_file): # exceptions needed on some platforms (mingw) skip_extensions = ["__attribute__(x)=", "__extension__=", "__MINGW_EXTENSION="] - skip_std_includes = ["_INC_STDIO", "_INC_STDDEF", "__STDDEF_H__", "_MATH_H_", "_INC_CORECRT",] + skip_std_includes = ["_INC_STDIO", "_INC_STDDEF", "__STDDEF_H__", "_MATH_H_", "_INC_CORECRT", "static_assert(x)="] undef_macros = [] std_include = [] if shutil.which(custom_parser): @@ -126,7 +126,7 @@ def generate_cdef(module_name, src_file): else: print("Parsing with 'cpp'") cpp_path = 'cpp' - cpp_args = ["-xc"] + cpp_args = ["-xc", "-std=c2x"] idirs = [r'-I' + d for d in include_dirs + std_include] ddefs = [r'-D' + d for d in define_macros + skip_std_includes + skip_extensions]