diff --git a/.clangd b/.clangd deleted file mode 100644 index a1c8ac4d..00000000 --- a/.clangd +++ /dev/null @@ -1,5 +0,0 @@ -Diagnostics: - Suppress: - - redefinition_different_typedef # hopefully this won't be needed once FreeRTOS has been updated - - main # _startup calls main after libc has been initialized. This is industry standard - - language-extension-token # for asm calls in .c files \ No newline at end of file diff --git a/.gitignore b/.gitignore index 918ccf9d..7f8e97a3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,18 +1,8 @@ +# IDEs .vscode/ .idea/ -bin/ -.*.sw* -template/ -version -cquery_log.txt -compile_commands.json -.ccls-cache/ -.ccls -temp.log -temp.errors -.d/ -.clangd/ -.cache/ +# OS .DS_Store -*.zip -firmware/libv5rt \ No newline at end of file +# Meson +/.clangd +subprojects/*/ \ No newline at end of file diff --git a/Makefile b/Makefile deleted file mode 100644 index a7b17f97..00000000 --- a/Makefile +++ /dev/null @@ -1,110 +0,0 @@ -################################################################################ -######################### User configurable parameters ######################### -# VEX SDK version -SDK_VERSION:=V5_20240802_15_00_00 - -# filename extensions -CEXTS:=c -ASMEXTS:=s S -CXXEXTS:=cpp c++ cc - -# probably shouldn't modify these, but you may need them below -ROOT=. -FWDIR:=$(ROOT)/firmware -BINDIR=$(ROOT)/bin -SRCDIR=$(ROOT)/src -INCDIR=$(ROOT)/include -EXTRA_INCDIR=$(FWDIR)/libv5rt/sdk/vexv5/patched_include - -# Directories to be excluded from all builds -EXCLUDE_SRCDIRS+=$(SRCDIR)/tests - -C_STANDARD=gnu2x -CXX_STANDARD=gnu++23 - -WARNFLAGS+=-Wall -Wpedantic -EXTRA_CFLAGS= -EXTRA_CXXFLAGS= - -.DEFAULT_GOAL=quick -USE_PACKAGE:=0 - -# object files to keep in libv5rt.a -RETAIN_OBJECTS:= v5_fstubs.c.obj v5_util.c.obj v5_apijump.c.obj v5_apiuser.c.obj v5_apigraphics.c.obj v5_apiversions.c.obj - -# Set this to 1 to add additional rules to compile your project as a PROS library template -IS_LIBRARY:=1 -LIBNAME:=libpros -VERSION=$(shell cat $(ROOT)/version) -# EXCLUDE_SRC_FROM_LIB= $(SRCDIR)/unpublishedfile.c -EXCLUDE_SRC_FROM_LIB+=$(EXCLUDE_SRCDIRS) -# this line excludes opcontrol.c and similar files -EXCLUDE_SRC_FROM_LIB+=$(foreach file, $(SRCDIR)/main,$(foreach cext,$(CEXTS),$(file).$(cext)) $(foreach cxxext,$(CXXEXTS),$(file).$(cxxext))) - -# files that get distributed to every user (beyond your source archive) - add -# whatever files you want here. This line is configured to add all header files -# that are in the the include directory get exported -TEMPLATE_FILES=$(ROOT)/common.mk $(FWDIR)/v5.ld $(FWDIR)/v5-common.ld $(FWDIR)/v5-hot.ld -TEMPLATE_FILES+=$(FWDIR)/libc.a $(FWDIR)/libm.a -TEMPLATE_FILES+= $(INCDIR)/api.h $(INCDIR)/main.h $(INCDIR)/pros/*.* -TEMPLATE_FILES+= $(SRCDIR)/main.cpp -TEMPLATE_FILES+= $(ROOT)/template-gitignore - -PATCHED_SDK=$(FWDIR)/libv5rt/sdk/vexv5/libv5rt.patched.a - -EXTRA_LIB_DEPS=$(INCDIR)/api.h $(PATCHED_SDK) - -################################################################################ -################################################################################ -########## Nothing below this line should be edited by typical users ########### --include ./common.mk - -.PHONY: download_sdk patch_sdk_headers clean - -download_sdk: scripts/get_libv5rt.py - @echo "Downloading SDK" - $(VV)python3 scripts/get_libv5rt.py $(SDK_VERSION) - -patch_sdk_headers: download_sdk scripts/patch_headers.py - @echo "Patching SDK headers" - $(VV)python3 scripts/patch_headers.py - -# Override clean, necessary to remove patched sdk on clean -clean:: - @echo "Cleaning SDK" - @rm -rf $(EXTRA_INCDIR) - @rm -rf $(FWDIR)/libv5rt - -$(PATCHED_SDK): $(FWDIR)/libv5rt/sdk/vexv5/libv5rt.a - $(call test_output_2,Stripping unwanted symbols from libv5rt.a ,$(STRIP) $^ @scripts/libv5rt-strip-options.txt -o $@, $(DONE_STRING)) - -CREATE_TEMPLATE_ARGS=--system "./**/*" -CREATE_TEMPLATE_ARGS+=--user "src/main.{cpp,c,cc}" --user "include/main.{hpp,h,hh}" --user "Makefile" --user ".gitignore" -CREATE_TEMPLATE_ARGS+=--target v5 -CREATE_TEMPLATE_ARGS+=--output bin/monolith.bin --cold_output bin/cold.package.bin --hot_output bin/hot.package.bin --cold_addr 58720256 --hot_addr 125829120 - -template:: patch_sdk_headers clean-template library - $(VV)mkdir -p $(TEMPLATE_DIR) - @echo "Moving template files to $(TEMPLATE_DIR)" - $Dif [ $(shell uname -s) == "Darwin" ]; then \ - rsync -R $(TEMPLATE_FILES) $(TEMPLATE_DIR); \ - else \ - cp --parents -r $(TEMPLATE_FILES) $(TEMPLATE_DIR); \ - fi - $(VV)mkdir -p $(TEMPLATE_DIR)/firmware - $Dcp $(LIBAR) $(TEMPLATE_DIR)/firmware - $Dcp $(ROOT)/template-Makefile $(TEMPLATE_DIR)/Makefile - $Dmv $(TEMPLATE_DIR)/template-gitignore $(TEMPLATE_DIR)/.gitignore - @echo "Creating template" - $Dpros c create-template $(TEMPLATE_DIR) kernel $(shell cat $(ROOT)/version) $(CREATE_TEMPLATE_ARGS) - -libv5rt_EXTRACTION_DIR=$(BINDIR)/libv5rt -$(LIBAR): patch_sdk_headers $(call GETALLOBJ,$(EXCLUDE_SRC_FROM_LIB)) $(EXTRA_LIB_DEPS) - $(VV)mkdir -p $(libv5rt_EXTRACTION_DIR) - $(call test_output_2,Extracting libv5rt, cd $(libv5rt_EXTRACTION_DIR) && $(AR) x ../../$(PATCHED_SDK), $(DONE_STRING)) - - $(eval libv5rt_OBJECTS := $(shell $(AR) t $(PATCHED_SDK))) - $(eval libv5rt_OBJECTS := $(filter $(RETAIN_OBJECTS),$(libv5rt_OBJECTS))) - - -$Drm -f $@ - $(call test_output_2,Creating $@, $(AR) rcs $@ $(addprefix $(libv5rt_EXTRACTION_DIR)/, $(libv5rt_OBJECTS)) $(call GETALLOBJ,$(EXCLUDE_SRC_FROM_LIB)), $(DONE_STRING)) \ No newline at end of file diff --git a/common.mk b/common.mk deleted file mode 100644 index ef55b2f9..00000000 --- a/common.mk +++ /dev/null @@ -1,265 +0,0 @@ -ARCHTUPLE=arm-none-eabi- -DEVICE=VEX EDR V5 - -MFLAGS=-mcpu=cortex-a9 -mfpu=neon-fp16 -mfloat-abi=hard -Os -g -CPPFLAGS=-D_POSIX_THREADS -D_UNIX98_THREAD_MUTEX_ATTRIBUTES -D_POSIX_TIMERS -D_POSIX_MONOTONIC_CLOCK -GCCFLAGS=-ffunction-sections -fdata-sections -fdiagnostics-color -funwind-tables - -WARNFLAGS+=-Wno-psabi - -SPACE := $() $() -COMMA := , - -C_STANDARD?=gnu2x -CXX_STANDARD?=gnu++23 - -DEPDIR := .d -$(shell mkdir -p $(DEPDIR)) -DEPFLAGS = -MT $$@ -MMD -MP -MF $(DEPDIR)/$$*.Td -MAKEDEPFOLDER = -$(VV)mkdir -p $(DEPDIR)/$$(dir $$(patsubst $(BINDIR)/%, %, $(ROOT)/$$@)) -RENAMEDEPENDENCYFILE = -$(VV)mv -f $(DEPDIR)/$$*.Td $$(patsubst $(SRCDIR)/%, $(DEPDIR)/%.d, $(ROOT)/$$<) && touch $$@ - -LIBRARIES+=$(wildcard $(FWDIR)/*.a) -# Cannot include newlib and libc because not all of the req'd stubs are implemented -EXCLUDE_COLD_LIBRARIES+=$(FWDIR)/libc.a $(FWDIR)/libm.a -COLD_LIBRARIES=$(filter-out $(EXCLUDE_COLD_LIBRARIES), $(LIBRARIES)) -wlprefix=-Wl,$(subst $(SPACE),$(COMMA),$1) -LNK_FLAGS=--gc-sections --start-group $(strip $(LIBRARIES)) -lgcc -lstdc++ --end-group -T$(FWDIR)/v5-common.ld --no-warn-rwx-segments - -ASMFLAGS=$(MFLAGS) $(WARNFLAGS) -CFLAGS=$(MFLAGS) $(CPPFLAGS) $(WARNFLAGS) $(GCCFLAGS) --std=$(C_STANDARD) -CXXFLAGS=$(MFLAGS) $(CPPFLAGS) $(WARNFLAGS) $(GCCFLAGS) --std=$(CXX_STANDARD) -LDFLAGS=$(MFLAGS) $(WARNFLAGS) -nostdlib $(GCCFLAGS) -SIZEFLAGS=-d --common -NUMFMTFLAGS=--to=iec --format %.2f --suffix=B - -AR:=$(ARCHTUPLE)ar -# using arm-none-eabi-as generates a listing by default. This produces a super verbose output. -# Using gcc accomplishes the same thing without the extra output -AS:=$(ARCHTUPLE)gcc -CC:=$(ARCHTUPLE)gcc -CXX:=$(ARCHTUPLE)g++ -LD:=$(ARCHTUPLE)g++ -OBJCOPY:=$(ARCHTUPLE)objcopy -SIZETOOL:=$(ARCHTUPLE)size -READELF:=$(ARCHTUPLE)readelf -STRIP:=$(ARCHTUPLE)strip - -ifneq (, $(shell command -v gnumfmt 2> /dev/null)) - SIZES_NUMFMT:=| gnumfmt --field=-4 --header $(NUMFMTFLAGS) -else -ifneq (, $(shell command -v numfmt 2> /dev/null)) - SIZES_NUMFMT:=| numfmt --field=-4 --header $(NUMFMTFLAGS) -else - SIZES_NUMFMT:= -endif -endif - -ifneq (, $(shell command -v sed 2> /dev/null)) -SIZES_SED:=| sed -e 's/ dec/total/' -else -SIZES_SED:= -endif - -rwildcard=$(foreach d,$(filter-out $3,$(wildcard $1*)),$(call rwildcard,$d/,$2,$3)$(filter $(subst *,%,$2),$d)) - -# Colors -NO_COLOR=$(shell printf "%b" "\033[0m") -OK_COLOR=$(shell printf "%b" "\033[32;01m") -ERROR_COLOR=$(shell printf "%b" "\033[31;01m") -WARN_COLOR=$(shell printf "%b" "\033[33;01m") -STEP_COLOR=$(shell printf "%b" "\033[37;01m") -OK_STRING=$(OK_COLOR)[OK]$(NO_COLOR) -DONE_STRING=$(OK_COLOR)[DONE]$(NO_COLOR) -ERROR_STRING=$(ERROR_COLOR)[ERRORS]$(NO_COLOR) -WARN_STRING=$(WARN_COLOR)[WARNINGS]$(NO_COLOR) -ECHO=/bin/printf "%s\n" -echo=@$(ECHO) "$2$1$(NO_COLOR)" -echon=@/bin/printf "%s" "$2$1$(NO_COLOR)" - -define test_output_2 -@if test $(BUILD_VERBOSE) -eq $(or $4,1); then printf "%s\n" "$2"; fi; -@output="$$($2 2>&1)"; exit=$$?; \ -if test 0 -ne $$exit; then \ - printf "%s%s\n" "$1" "$(ERROR_STRING)"; \ - printf "%s\n" "$$output"; \ - exit $$exit; \ -elif test -n "$$output"; then \ - printf "%s%s\n" "$1" "$(WARN_STRING)"; \ - printf "%s\n" "$$output"; \ -else \ - printf "%s%s\n" "$1" "$3"; \ -fi; -endef - -define test_output -@output=$$($1 2>&1); exit=$$?; \ -if test 0 -ne $$exit; then \ - printf "%s\n" "$(ERROR_STRING)" $$?; \ - printf "%s\n" $$output; \ - exit $$exit; \ -elif test -n "$$output"; then \ - printf "%s\n" "$(WARN_STRING)"; \ - printf "%s" $$output; \ -else \ - printf "%s\n" "$2"; \ -fi; -endef - -# Makefile Verbosity -ifeq ("$(origin VERBOSE)", "command line") -BUILD_VERBOSE = $(VERBOSE) -endif -ifeq ("$(origin V)", "command line") -BUILD_VERBOSE = $(V) -endif - -ifndef BUILD_VERBOSE -BUILD_VERBOSE = 0 -endif - -# R is reduced (default messages) - build verbose = 0 -# V is verbose messages - verbosity = 1 -# VV is super verbose - verbosity = 2 -ifeq ($(BUILD_VERBOSE), 0) -R = @echo -D = @ -VV = @ -endif -ifeq ($(BUILD_VERBOSE), 1) -R = @echo -D = -VV = @ -endif -ifeq ($(BUILD_VERBOSE), 2) -R = -D = -VV = -endif - -INCLUDE=$(foreach dir,$(INCDIR) $(EXTRA_INCDIR),-iquote"$(dir)") - -ASMSRC=$(foreach asmext,$(ASMEXTS),$(call rwildcard, $(SRCDIR),*.$(asmext), $1)) -ASMOBJ=$(addprefix $(BINDIR)/,$(patsubst $(SRCDIR)/%,%.o,$(call ASMSRC,$1))) -CSRC=$(foreach cext,$(CEXTS),$(call rwildcard, $(SRCDIR),*.$(cext), $1)) -COBJ=$(addprefix $(BINDIR)/,$(patsubst $(SRCDIR)/%,%.o,$(call CSRC, $1))) -CXXSRC=$(foreach cxxext,$(CXXEXTS),$(call rwildcard, $(SRCDIR),*.$(cxxext), $1)) -CXXOBJ=$(addprefix $(BINDIR)/,$(patsubst $(SRCDIR)/%,%.o,$(call CXXSRC,$1))) - -GETALLOBJ=$(sort $(call ASMOBJ,$1) $(call COBJ,$1) $(call CXXOBJ,$1)) - -ARCHIVE_TEXT_LIST=$(subst $(SPACE),$(COMMA),$(notdir $(basename $(LIBRARIES)))) - -LDTIMEOBJ:=$(BINDIR)/_pros_ld_timestamp.o - -BIN:=$(BINDIR)/monolith.bin -ELF:=$(basename $(BIN)).elf - --include $(wildcard $(FWDIR)/*.mk) - -.PHONY: all clean quick - -quick: $(BIN) - -all: clean $(BIN) - -clean:: - @echo Cleaning project - -$Drm -rf $(BINDIR) - -$Drm -rf $(DEPDIR) - -ifeq ($(IS_LIBRARY),1) -ifeq ($(LIBNAME),libbest) -$(error "You should rename your library! libbest is the default library name and should be changed") -endif - -LIBAR=$(BINDIR)/$(LIBNAME).a -TEMPLATE_DIR=$(ROOT)/template - -clean-template: - @echo Cleaning $(TEMPLATE_DIR) - -$Drm -rf $(TEMPLATE_DIR) - -$(LIBAR): $(call GETALLOBJ,$(EXCLUDE_SRC_FROM_LIB)) $(EXTRA_LIB_DEPS) - -$Dmkdir $(BINDIR) - -$Drm -f $@ - $(call test_output_2,Creating $@ ,$(AR) rcs $@ $^, $(DONE_STRING)) - -.PHONY: library -library: $(LIBAR) - -.PHONY: template -template:: clean-template $(LIBAR) - $Dpros c create-template . $(LIBNAME) $(VERSION) $(foreach file,$(TEMPLATE_FILES) $(LIBAR),--system "$(file)") --target v5 $(CREATE_TEMPLATE_FLAGS) -endif - -# if project is a library source, compile the archive and link output.elf against the archive rather than source objects -ifeq ($(IS_LIBRARY),1) -ELF_DEPS+=$(filter-out $(call GETALLOBJ,$(EXCLUDE_SRC_FROM_LIB)), $(call GETALLOBJ,$(EXCLUDE_SRCDIRS))) -LIBRARIES+=$(LIBAR) -else -ELF_DEPS+=$(call GETALLOBJ,$(EXCLUDE_SRCDIRS)) -endif - -$(BIN): $(ELF) $(BINDIR) - $(call test_output_2,Creating $@ for $(DEVICE) ,$(OBJCOPY) $< -O binary $@,$(DONE_STRING)) - -$(ELF): $(ELF_DEPS) $(LIBRARIES) - $(call _pros_ld_timestamp) - $(call test_output_2,Linking project with $(ARCHIVE_TEXT_LIST) ,$(LD) $(LDFLAGS) $(ELF_DEPS) $(LDTIMEOBJ) $(call wlprefix,-T$(FWDIR)/v5.ld $(LNK_FLAGS)) -o $@,$(OK_STRING)) - @echo Section sizes: - -$(VV)$(SIZETOOL) $(SIZEFLAGS) $@ $(SIZES_SED) $(SIZES_NUMFMT) - -define asm_rule -$(BINDIR)/%.$1.o: $(SRCDIR)/%.$1 - $(VV)mkdir -p $$(dir $$@) - $$(call test_output_2,Compiled $$< ,$(AS) -c $(ASMFLAGS) -o $$@ $$<,$(OK_STRING)) -endef -$(foreach asmext,$(ASMEXTS),$(eval $(call asm_rule,$(asmext)))) - -define c_rule -$(BINDIR)/%.$1.o: $(SRCDIR)/%.$1 -$(BINDIR)/%.$1.o: $(SRCDIR)/%.$1 $(DEPDIR)/$(basename %).d - $(VV)mkdir -p $$(dir $$@) - $(MAKEDEPFOLDER) - $$(call test_output_2,Compiled $$< ,$(CC) -c $(INCLUDE) -iquote"$(INCDIR)/$$(dir $$*)" $(CFLAGS) $(EXTRA_CFLAGS) $(DEPFLAGS) -o $$@ $$<,$(OK_STRING)) - $(RENAMEDEPENDENCYFILE) -endef -$(foreach cext,$(CEXTS),$(eval $(call c_rule,$(cext)))) - -define cxx_rule -$(BINDIR)/%.$1.o: $(SRCDIR)/%.$1 -$(BINDIR)/%.$1.o: $(SRCDIR)/%.$1 $(DEPDIR)/$(basename %).d - $(VV)mkdir -p $$(dir $$@) - $(MAKEDEPFOLDER) - $$(call test_output_2,Compiled $$< ,$(CXX) -c $(INCLUDE) -iquote"$(INCDIR)/$$(dir $$*)" $(CXXFLAGS) $(EXTRA_CXXFLAGS) $(DEPFLAGS) -o $$@ $$<,$(OK_STRING)) - $(RENAMEDEPENDENCYFILE) -endef -$(foreach cxxext,$(CXXEXTS),$(eval $(call cxx_rule,$(cxxext)))) - -define _pros_ld_timestamp -$(VV)mkdir -p $(dir $(LDTIMEOBJ)) -@# Pipe a line of code defining _PROS_COMPILE_TOOLSTAMP and _PROS_COMPILE_DIRECTORY into GCC, -@# which allows compilation from stdin. We define _PROS_COMPILE_DIRECTORY using a command line-defined macro -@# which is the pwd | tail bit, which will truncate the path to the last 23 characters -@# -@# const int _PROS_COMPILE_TIMESTAMP_INT = $(( $(date +%s) - $(date +%z) * 3600 )) -@# char const * const _PROS_COMPILE_TIEMSTAMP = __DATE__ " " __TIME__ -@# char const * const _PROS_COMPILE_DIRECTORY = "$(shell pwd | tail -c 23)"; -@# -@# The shell command $$(($$(date +%s)+($$(date +%-z)/100*3600))) fetches the current -@# unix timestamp, and then adds the UTC timezone offset to account for time zones. - -$(call test_output_2,Adding timestamp ,echo 'const int _PROS_COMPILE_TIMESTAMP_INT = $(shell echo $$(($$(date +%s)+($$(date +%-z)/100*3600)))); char const * const _PROS_COMPILE_TIMESTAMP = __DATE__ " " __TIME__; char const * const _PROS_COMPILE_DIRECTORY = "$(wildcard $(shell pwd | tail -c 23))";' | $(CC) -c -x c $(CFLAGS) $(EXTRA_CFLAGS) -o $(LDTIMEOBJ) -,$(OK_STRING)) -endef - -# these rules are for build-compile-commands, which just print out sysroot information -cc-sysroot: - @echo | $(CC) -c -x c $(CFLAGS) $(EXTRA_CFLAGS) --verbose -o /dev/null - -cxx-sysroot: - @echo | $(CXX) -c -x c++ $(CXXFLAGS) $(EXTRA_CXXFLAGS) --verbose -o /dev/null - - -$(DEPDIR)/%.d: ; -.PRECIOUS: $(DEPDIR)/%.d - -include $(wildcard $(patsubst $(SRCDIR)/%,$(DEPDIR)/%.d,$(CSRC) $(CXXSRC))) \ No newline at end of file diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 3acc3e77..a8613040 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -58,19 +58,29 @@ In Visual Studio Code, open the command palette with (`ctrl+shift+p` or `command ### Step 3: Compile > [!IMPORTANT] -> You'll need the [clangd](https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd) and [PROS](https://marketplace.visualstudio.com/items?itemName=sigbots.pros) VSCode extensions for this step +> You'll need [Meson](https://mesonbuild.com/Getting-meson.html), and [arm-none-eabi-gcc](https://learn.arm.com/install-guides/gcc/arm-gnu/) for this step. -Once you have your ZestCode fork open in VSCode, you'll need to compile it so clangd (your linting tool) works properly. Open the PROS Integrated Terminal, and it should already be busy compiling. If not, run the following command: +In your project, open your terminal to set up and configure meson with this command: ``` -make clean; pros build-compile-commands +meson setup --wipe --cross-file scripts/v5.ini build ``` -It might take a while for the first build, but subsequent builds will be many times faster. After the build is done, open the command palette and run `clangd: Restart language server`. The linter should now be working properly. +Then, you can compile the project with this command: -### Step 4: Making your changes +``` +meson compile -C build +``` + +> [!TIP] +> You might have to restart your editor before Clangd starts working properly + +### Step 4: Make your changes + +> [!IMPORTANT] +> If you add any new source files, you will need to add them to [meson.build](../meson.build) -The project file structure is explained in [STRUCTURE.md](./STRUCTURE.md). Read through it so you know where you should make your changes. +The project file structure is explained in [STRUCTURE.md](../STRUCTURE.md). Read through it so you know where you should make your changes. Details on the code style can be found in [STYLEGUIDE.md](./STYLEGUIDE.md). You should commit changes regularly. This isn't a requirement, but it will make your life easier, especially for more complex PRs. diff --git a/docs/STRUCTURE.md b/docs/STRUCTURE.md index 0897a948..48b2f919 100644 --- a/docs/STRUCTURE.md +++ b/docs/STRUCTURE.md @@ -7,8 +7,6 @@ Looking at the file structure of a project like this can feel intimidating. This - `docs` contains documentation and documentation generation config files -- `firmware` contains static libraries that are used to compile ZestCode - - `include` contains the header files - `include/common` headers used in various parts of the project - `include/pros` headers that are distributed to user projects @@ -26,4 +24,8 @@ Looking at the file structure of a project like this can feel intimidating. This - `src/rtos` sources, build scripts, and misc files of FreeRTOS - `src/system` sources for low-level system functionality - `src/system/dev` sources for serial I/O and file management - - `src/tests` contain tests to ensure certain features work \ No newline at end of file + +- `subprojects` contains wrap files for dependencies + +- `tests` contains unit tests + - `tests/examples` contains example code \ No newline at end of file diff --git a/firmware/libc.a b/firmware/libc.a deleted file mode 100644 index a2e1cdb7..00000000 Binary files a/firmware/libc.a and /dev/null differ diff --git a/firmware/libm.a b/firmware/libm.a deleted file mode 100644 index 63c9951f..00000000 Binary files a/firmware/libm.a and /dev/null differ diff --git a/firmware/v5.ld b/firmware/v5.ld deleted file mode 100644 index f3a2788b..00000000 --- a/firmware/v5.ld +++ /dev/null @@ -1,37 +0,0 @@ -/* This stack is used during initialization, but FreeRTOS tasks have their own - stack allocated in BSS or Heap (kernel tasks in FreeRTOS .bss heap; user tasks - in standard heap) */ -_STACK_SIZE = DEFINED(_STACK_SIZE) ? _STACK_SIZE : 0x2000; - -_ABORT_STACK_SIZE = DEFINED(_ABORT_STACK_SIZE) ? _ABORT_STACK_SIZE : 1024; -_SUPERVISOR_STACK_SIZE = DEFINED(_SUPERVISOR_STACK_SIZE) ? _SUPERVISOR_STACK_SIZE : 2048; -_IRQ_STACK_SIZE = DEFINED(_IRQ_STACK_SIZE) ? _IRQ_STACK_SIZE : 1024; -_FIQ_STACK_SIZE = DEFINED(_FIQ_STACK_SIZE) ? _FIQ_STACK_SIZE : 1024; -_UNDEF_STACK_SIZE = DEFINED(_UNDEF_STACK_SIZE) ? _UNDEF_STACK_SIZE : 1024; - -_HEAP_SIZE = DEFINED(_HEAP_SIZE) ? _HEAP_SIZE : 0x02E00000; /* ~48 MB */ - -/* Define Memories in the system */ -start_of_cold_mem = 0x03800000; -_COLD_MEM_SIZE = 0x04800000; -end_of_cold_mem = start_of_cold_mem + _COLD_MEM_SIZE; - -start_of_hot_mem = 0x07800000; -_HOT_MEM_SIZE = 0x00800000; -end_of_hot_mem = start_of_hot_mem + _HOT_MEM_SIZE; - -MEMORY -{ - /* user code 72M */ - COLD_MEMORY : ORIGIN = start_of_cold_mem, LENGTH = _COLD_MEM_SIZE /* Just under 19 MB */ - HEAP : ORIGIN = 0x04A00000, LENGTH = _HEAP_SIZE - HOT_MEMORY : ORIGIN = start_of_hot_mem, LENGTH = _HOT_MEM_SIZE /* Just over 8 MB */ -} - -/* used in _sbrk implementation */ -_HEAP_START = ORIGIN(HEAP); -_HEAP_END = ORIGIN(HEAP) + LENGTH(HEAP); - -REGION_ALIAS("RAM", COLD_MEMORY); - -ENTRY(_start) diff --git a/include/common/string.h b/include/common/string2.h similarity index 97% rename from include/common/string.h rename to include/common/string2.h index 0aec5d9a..59c542ae 100644 --- a/include/common/string.h +++ b/include/common/string2.h @@ -23,6 +23,7 @@ * * \return The duplicate string */ +#include char* kstrdup(const char* s); /** diff --git a/include/pros/version.h b/include/pros/version.h deleted file mode 100644 index 829f63a4..00000000 --- a/include/pros/version.h +++ /dev/null @@ -1,23 +0,0 @@ -/** - * \file version.h - * - * PROS Version Information - * - * Contains PROS kernel version information - * - * - * \copyright Copyright (c) 2017-2024, Purdue University ACM SIGBots. - * All rights reserved. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -#pragma once - -#define PROS_VERSION_MAJOR 4 -#define PROS_VERSION_MINOR 1 - -#define PROS_VERSION_PATCH 0 -#define PROS_VERSION_STRING "4.1.0" diff --git a/include/rtos/message_buffer.h b/include/rtos/message_buffer.h index 268ab901..5dc71be0 100644 --- a/include/rtos/message_buffer.h +++ b/include/rtos/message_buffer.h @@ -63,7 +63,7 @@ #define FREERTOS_MESSAGE_BUFFER_H /* Message buffers are built onto of stream buffers. */ -#include "stream_buffer.h" +#include "rtos/stream_buffer.h" #if defined( __cplusplus ) extern "C" { diff --git a/include/rtos/semphr.h b/include/rtos/semphr.h index ec9cd7e7..80f69a6a 100644 --- a/include/rtos/semphr.h +++ b/include/rtos/semphr.h @@ -32,8 +32,8 @@ #error "include FreeRTOS.h" must appear in source files before "include semphr.h" #endif -#include "queue.h" -#include "task.h" +#include "rtos/queue.h" +#include "rtos/task.h" typedef queue_t sem_t; typedef queue_t mutex_t; diff --git a/include/rtos/task.h b/include/rtos/task.h index 1069e506..8004d1b1 100644 --- a/include/rtos/task.h +++ b/include/rtos/task.h @@ -25,7 +25,7 @@ * 1 tab == 4 spaces! */ -#include "FreeRTOS.h" +#include "rtos/FreeRTOS.h" #ifndef INC_TASK_H #define INC_TASK_H @@ -34,7 +34,7 @@ #error "include FreeRTOS.h must appear in source files before include task.h" #endif -#include "list.h" +#include "rtos/list.h" #ifdef __cplusplus extern "C" { diff --git a/include/rtos/timers.h b/include/rtos/timers.h index 9a680d5c..f2e96485 100644 --- a/include/rtos/timers.h +++ b/include/rtos/timers.h @@ -35,7 +35,7 @@ /*lint -save -e537 This headers are only multiply included if the application code happens to also be including task.h. */ -#include "task.h" +#include "rtos/task.h" /*lint -restore */ #ifdef __cplusplus diff --git a/include/vdml/registry.h b/include/vdml/registry.h index 2f8b64a1..9856fa7f 100644 --- a/include/vdml/registry.h +++ b/include/vdml/registry.h @@ -14,7 +14,7 @@ #pragma once #include "pros/apix.h" -#include "v5_api.h" +#include "v5_api_patched.h" #include "vdml/vdml.h" #ifdef __cplusplus diff --git a/meson.build b/meson.build new file mode 100644 index 00000000..9c88e6c2 --- /dev/null +++ b/meson.build @@ -0,0 +1,116 @@ +# This is the main build script. +# This is where we configure how ZestCode is built. +# It's used in combination with scripts/v5.ini, which tells Meson (the build system) +# what tools to use and what platform the program is built for. + +# project configuration +project( + 'zestcode', # project name (zestcode) + ['c', 'cpp'], # written in both C and C++ (for now) + version : '0.0.0', + meson_version: '>= 1.2.0', # we use splitlines which was introduced in meson v1.2.0 + default_options: [ + 'c_std=gnu2x', # latest c standard supported in gcc v13 + 'cpp_std=gnu++23', # latest c++ standard supported in gcc v13 + 'warning_level=3', # 0, 1, 2, 3, or everything. Higher means more warnings + 'optimization=s', # minimize binary size to minimize upload times. We have a ton of performance overhead + 'debug=true', # debug symbols are not included in the final .bin file, so they don't increase upload time at all + 'force_fallback_for=v5, v5_header' + ], +) + +# patches the .clangd file so the system includes work. +# runs whenever meson is configured +python = find_program('python3') +patch_clangd = files('scripts' / 'patch_clangd.py') +run_command(python, patch_clangd, meson.get_compiler('c'), check: true) + +# possible source file extensions +file_exts = [ + '*.s', # assembly + '*.S', # assembly + '*.c', # C + '*.h', # C + '*.cpp', # C++ + '*.hpp' # C++ +] +get_files = files('scripts' / 'get_files.py') +# get all source files +get_files_result = run_command(python, get_files, 'src', file_exts, check: true) +source = get_files_result.stdout().strip().splitlines() + +# optimization flags passed to the compiler +optimization_flags = [ + '-ffunction-sections', # used in combination with --gc-sections to reduce binary size + '-fdata-sections', # used in combination with --gc-sections to reduce binary size + '-fno-strict-aliasing', # needed due to bad coding practices in the FreeRTOS source +] + +# formatting flags passed to the compiler and linker +formatting_flags = [ + '-fdiagnostics-color', # makes the compiler output easier to read, by using colors! +] +add_global_arguments(formatting_flags, language: 'c') +add_global_arguments(formatting_flags, language: 'cpp') +add_global_link_arguments(formatting_flags, language: 'c') +add_global_link_arguments(formatting_flags, language: 'cpp') + +# miscellaneous flags passed to the linker +linker_flags = [ + '-Wl,--gc-sections', # used in combination with -ffunction-sections and -fdata-sections to reduce binary size + '-Wl,--no-warn-rwx-segments' # silences a warning that does not make a difference for our use case +] + +# system libraries we depend on +system_deps = [ + '-nostdlib', # we still need to implement some newlib stubs + '-lc', # libc + '-lm', # libm + '-lgcc', #libgcc + '-lstdc++', # libstdc++ +] +add_global_link_arguments( system_deps, language: 'c') +add_global_link_arguments(system_deps, language: 'cpp') + +# configuration of the standard library +stdlib_conf = [ + '-D_POSIX_MONOTONIC_CLOCK', # enable the POSIX monotonic clock +] + +# apply all these flags and configs +add_global_arguments(optimization_flags, formatting_flags, stdlib_conf, language: 'c') +add_global_arguments(optimization_flags, formatting_flags, stdlib_conf, language: 'cpp') +add_global_link_arguments(optimization_flags, linker_flags, formatting_flags, system_deps, language: 'c') +add_global_link_arguments(optimization_flags, linker_flags, formatting_flags, system_deps, language: 'cpp') + +# include directories. +# we only specify the top level in order to enforce paths in include directives. +include = include_directories('./include') + +# this is what user projects will link against, so we use declare_dependency instead of static_library +zestcode_dep = declare_dependency( + sources: source, + include_directories: include, + dependencies: dependency('v5_header'), +) + +# TODO: figure out a better way to do this in a future Tests PR +elf = executable( + 'program.elf', + sources: './tests/examples/basic.cpp', + include_directories: include, + dependencies: [ + dependency('v5'), + zestcode_dep.as_link_whole() # link whole so libc symbols are overridden + ] +) + +# meson won't create the binary file for uploading, so we have to do it ourselves +objcopy = find_program('arm-none-eabi-objcopy') +custom_target( + 'program.bin', + output: 'program.bin', + input: elf, + build_by_default: true, # otherwise it won't be built + command: [objcopy, ['-O', 'binary', '-S', '@INPUT@', '@OUTPUT@']], +) diff --git a/project.pros b/project.pros deleted file mode 100644 index aa82057d..00000000 --- a/project.pros +++ /dev/null @@ -1,30 +0,0 @@ -{ - "py/object": "pros.conductor.project.Project", - "py/state": { - "project_name": "kernel-dev", - "target": "v5", - "templates": { - "kernel": { - "py/object": "pros.conductor.templates.local_template.LocalTemplate", - "location": "./template", - "metadata": { - "origin": "local", - "output": "bin/monolith.bin", - "hot_output": "bin/hot.package.bin", - "cold_output": "bin/cold.package.bin", - "cold_addr": 58720256, - "hot_addr": 125829120 - }, - "name": "kernel", - "supported_kernels": null, - "system_files": [], - "target": "v5", - "user_files": [], - "version": "3.0.0-beta1" - } - }, - "upload_options": { - "slot": 1 - } - } -} \ No newline at end of file diff --git a/scripts/.clangd b/scripts/.clangd new file mode 100644 index 00000000..18fcf80b --- /dev/null +++ b/scripts/.clangd @@ -0,0 +1,11 @@ +CompileFlags: + CompilationDatabase: build # this is where meson generates compile_commands.json + Add: [ + # system include paths will be inserted, making them the first 6 elements of the array + ] +Index: + StandardLibrary: No # we use headers from arm-none-eabi. We can turn this off with no downside. +Diagnostics: + Suppress: + - redefinition_different_typedef # TODO: remove if possible once FreeRTOS has been updated + - language-extension-token # for asm calls in .c files \ No newline at end of file diff --git a/scripts/get_files.py b/scripts/get_files.py new file mode 100644 index 00000000..33003b67 --- /dev/null +++ b/scripts/get_files.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 + +""" +Meson Build Source File Collector + +This script recursively searches a directory for source files matching specified extensions +and outputs their absolute paths. Intended for integration with Meson build system, so +you don't have to list every single one of your source files. +""" + +import sys +from pathlib import Path + +def main(): + """ + Main function handling command-line arguments and file discovery. + + Process flow: + 1. Validate command-line arguments + 2. Resolve source directory path + 3. Recursively search for files matching patterns + 4. Deduplicate and sort results + 5. Output absolute file paths + """ + if len(sys.argv) < 3: + print(f"Usage: {sys.argv[0]} ...", file=sys.stderr) + sys.exit(1) + + # Resolve source directory to absolute path + source_dir = Path(sys.argv[1]).resolve() + + # Extract file extension patterns from arguments (supports glob patterns like *.c) + patterns = sys.argv[2:] + + # Verify source directory exists + if not source_dir.is_dir(): + print(f"Error: Source directory '{source_dir}' does not exist.", file=sys.stderr) + sys.exit(1) + + # Use set to avoid duplicate entries from overlapping patterns + files = set() + + # Process each file pattern + for pattern in patterns: + # Recursive glob search (rglob) through directory tree + for path in source_dir.rglob(pattern): + # Skip directories that might match pattern (e.g., 'some.dir' matching *.h) + if path.is_file(): + # Add resolved absolute path to ensure consistency + files.add(path.resolve()) + + # Sort files for deterministic output order + sorted_files = sorted(files) + + # Print results in format Meson can consume (one absolute path per line) + for file_path in sorted_files: + print(file_path) + +if __name__ == '__main__': + # Entry point when executed directly + main() \ No newline at end of file diff --git a/scripts/get_libv5rt.py b/scripts/get_libv5rt.py deleted file mode 100644 index 061401d1..00000000 --- a/scripts/get_libv5rt.py +++ /dev/null @@ -1,163 +0,0 @@ -import urllib.request -import urllib.error -import json -import sys -import os -import zipfile -import shutil - -MANIFEST_URL = "https://content.vexrobotics.com/vexos/public/V5/vscode/sdk/cpp/manifest.json" - -def fetch_manifest(manifest_url): - headers = { - "User-Agent": ("Mozilla/5.0 (Windows NT 10.0; Win64; x64) " - "AppleWebKit/537.36 (KHTML, like Gecko) " - "Chrome/114.0.0.0 Safari/537.36") - } - req = urllib.request.Request(manifest_url, headers=headers) - try: - with urllib.request.urlopen(req) as response: - data = response.read().decode('utf-8') - manifest = json.loads(data) - return manifest - except urllib.error.URLError: - print("No internet connection detected. Proceeding without online version check.") - return None - except Exception as e: - print(f"Error fetching manifest: {e}") - sys.exit(1) - -def download_zip(file_name): - # Construct the URL using the version passed (in its original format). - url = f"https://content.vexrobotics.com/vexos/public/V5/vscode/sdk/cpp/{file_name}.zip" - print(f"Downloading from: {url}") - - headers = { - "User-Agent": ("Mozilla/5.0 (Windows NT 10.0; Win64; x64) " - "AppleWebKit/537.36 (KHTML, like Gecko) " - "Chrome/114.0.0.0 Safari/537.36") - } - req = urllib.request.Request(url, headers=headers) - - zip_filename = f"{file_name}.zip" - try: - with urllib.request.urlopen(req) as response: - with open(zip_filename, "wb") as out_file: - while True: - chunk = response.read(8192) - if not chunk: - break - out_file.write(chunk) - except urllib.error.URLError as e: - raise e - - print(f"Downloaded file saved as: {zip_filename}") - return zip_filename - -def extract_zip(zip_filename): - # Set extraction path to firmware/libv5rt/sdk relative to the script's location. - script_dir = os.path.dirname(os.path.abspath(__file__)) - extract_path = os.path.join(script_dir, "..", "firmware", "libv5rt", "sdk") - os.makedirs(extract_path, exist_ok=True) - - try: - with zipfile.ZipFile(zip_filename, 'r') as zip_ref: - members = zip_ref.namelist() - # Determine common prefix among all members. - common_prefix = os.path.commonprefix(members) - if common_prefix and not common_prefix.endswith('/'): - common_prefix = common_prefix.rsplit('/', 1)[0] + '/' - print(f"Common prefix: '{common_prefix}'") - - for member in members: - # Remove the common prefix if it exists. - member_new = member[len(common_prefix):] if common_prefix and member.startswith(common_prefix) else member - if not member_new: - continue - target_path = os.path.join(extract_path, member_new) - if member.endswith('/'): - os.makedirs(target_path, exist_ok=True) - else: - os.makedirs(os.path.dirname(target_path), exist_ok=True) - with zip_ref.open(member) as source, open(target_path, "wb") as target: - shutil.copyfileobj(source, target) - print(f"Extracted file contents to: {extract_path}") - except zipfile.BadZipFile as e: - print(f"Error extracting ZIP file: {e}") - sys.exit(1) - -def version_tuple(version_str): - """Converts a version string like '20240802.15.00.00' to a tuple of integers.""" - try: - return tuple(map(int, version_str.split('.'))) - except Exception: - return () - -def main(): - # Expect a version argument passed on the command line. - if len(sys.argv) < 2: - print("Usage: script.py ") - sys.exit(1) - - # The version should be in the format "V5_20240802_15_00_00" - passed_version = sys.argv[1] - # Normalize the version (remove "V5_" and convert underscores to dots) - normalized_passed = passed_version.replace("V5_", "").replace("_", ".") - print(f"Using version: {passed_version} (normalized: {normalized_passed})") - - # Attempt to fetch the online manifest to check for a later version. - manifest = fetch_manifest(MANIFEST_URL) - if manifest and "latest" in manifest: - online_version_raw = manifest["latest"] - normalized_online = online_version_raw.replace("V5_", "").replace("_", ".") - # Compare version tuples - if version_tuple(normalized_online) > version_tuple(normalized_passed): - print(f"WARNING: A later SDK version is available online: {online_version_raw} " - f"(normalized: {normalized_online}) compared to the specified version {passed_version}.") - - # Determine the SDK installation directory. - script_dir = os.path.dirname(os.path.abspath(__file__)) - sdk_dir = os.path.join(script_dir, "..", "firmware", "libv5rt", "sdk") - - # If the SDK directory exists, check its version. - if os.path.exists(sdk_dir): - local_manifest_path = os.path.join(sdk_dir, "manifest.json") - if os.path.exists(local_manifest_path): - try: - with open(local_manifest_path, "r") as f: - local_manifest = json.load(f) - local_version = local_manifest.get("version", "") - if local_version == normalized_passed: - print("SDK is already at the specified version. No update is necessary.") - sys.exit(0) - else: - print(f"Local SDK version ({local_version}) differs from specified version. Deleting old installation...") - shutil.rmtree(sdk_dir) - except Exception as e: - print(f"Error reading local manifest: {e}. Removing SDK directory.") - shutil.rmtree(sdk_dir) - else: - print("SDK directory exists but manifest.json not found. Removing directory.") - shutil.rmtree(sdk_dir) - - # Attempt to download the SDK zip using the passed version. - try: - zip_file = download_zip(passed_version) - except urllib.error.URLError as e: - if os.path.exists(sdk_dir): - print("No internet available. Using the existing SDK as the latest version.") - sys.exit(0) - else: - print("No internet available and no local SDK is installed. Cannot proceed.") - sys.exit(1) - - extract_zip(zip_file) - - try: - os.remove(zip_file) - print(f"Deleted zip file: {zip_file}") - except Exception as e: - print(f"Error deleting zip file: {e}") - -if __name__ == "__main__": - main() diff --git a/scripts/libv5rt-strip-options.txt b/scripts/libv5rt-strip-options.txt deleted file mode 100644 index 03a9613d..00000000 --- a/scripts/libv5rt-strip-options.txt +++ /dev/null @@ -1,8 +0,0 @@ --N open --N _fstat --N fcntl --N lseek --N read --N write --N isatty --R .ARM.attributes diff --git a/scripts/patch_clangd.py b/scripts/patch_clangd.py new file mode 100644 index 00000000..91a9cd0f --- /dev/null +++ b/scripts/patch_clangd.py @@ -0,0 +1,125 @@ +#!/usr/bin/env python3 + +# Generates a .clangd file from the template .clangd found in the scripts folder, and places it in the project root. +# Necessary to automatically determine and tell clangd where to find system includes. + +import sys +import os +import subprocess +import re +import shutil + +def main(): + if len(sys.argv) != 2: + print(f"Usage: python3 {sys.argv[0]} ") + sys.exit(1) + + gcc_executable = sys.argv[1] + + # Obtain sysroot by calling `arm-none-eabi-gcc --print-sysroot` + try: + output = subprocess.check_output([gcc_executable, "--print-sysroot"], universal_newlines=True) + sysroot = output.strip() + except Exception as e: + print(f"Error: Unable to run '{gcc_executable} --print-sysroot': {e}") + sys.exit(1) + + # The base directory is the parent of the sysroot. + base_dir = os.path.dirname(sysroot) + + # Automatically detect the gcc version folder inside lib/gcc/arm-none-eabi. + gcc_dir = os.path.join(base_dir, "lib", "gcc", "arm-none-eabi") + if not os.path.isdir(gcc_dir): + print(f"Error: {gcc_dir} is not a valid directory") + sys.exit(1) + + # List all subdirectories in gcc_dir. + subdirs = [d for d in os.listdir(gcc_dir) if os.path.isdir(os.path.join(gcc_dir, d))] + if not subdirs: + print(f"Error: No directories found in {gcc_dir}") + sys.exit(1) + + # Choose the directory with the highest semantic version. + try: + gcc_version = max(subdirs, key=lambda v: tuple(map(int, v.split(".")))) + except Exception as e: + print(f"Error: Could not determine highest semantic version in {gcc_dir}: {e}") + sys.exit(1) + + # Construct the six include strings. + outputs = [ + f"-isystem{base_dir}/lib/gcc/arm-none-eabi/{gcc_version}/../../../../arm-none-eabi/include/c++/{gcc_version}", + f"-isystem{base_dir}/lib/gcc/arm-none-eabi/{gcc_version}/../../../../arm-none-eabi/include/c++/{gcc_version}/arm-none-eabi/thumb/v7-a+simd/hard", + f"-isystem{base_dir}/lib/gcc/arm-none-eabi/{gcc_version}/../../../../arm-none-eabi/include/c++/{gcc_version}/backward", + f"-isystem{base_dir}/lib/gcc/arm-none-eabi/{gcc_version}/include", + f"-isystem{base_dir}/lib/gcc/arm-none-eabi/{gcc_version}/include-fixed", + f"-isystem{base_dir}/lib/gcc/arm-none-eabi/{gcc_version}/../../../../arm-none-eabi/include" + ] + # Normalize paths to use forward slashes. + outputs = [s.replace(os.sep, '/') for s in outputs] + + # Determine the script's directory and its parent. + script_dir = os.path.dirname(os.path.abspath(__file__)) + parent_dir = os.path.dirname(script_dir) + + # Source .clangd file in the same directory as the script. + source_clangd_path = os.path.join(script_dir, ".clangd") + if not os.path.isfile(source_clangd_path): + print(f"Error: {source_clangd_path} does not exist.") + sys.exit(1) + + # Destination .clangd file in the parent directory. + dest_clangd_path = os.path.join(parent_dir, ".clangd") + try: + shutil.copy2(source_clangd_path, dest_clangd_path) + print(f"Copied {source_clangd_path} to {dest_clangd_path}") + except Exception as e: + print(f"Error copying .clangd: {e}") + sys.exit(1) + + # Read the content of the copied .clangd file. + with open(dest_clangd_path, 'r') as f: + content = f.read() + + # Locate the "Add" section using regex. + # This pattern captures the block starting with "Add:" and an opening bracket, + # then captures its contents until the closing bracket. + pattern = r"(Add:\s*\[\s*\n)(.*?)(\n\s*\])" + match = re.search(pattern, content, flags=re.DOTALL) + if not match: + print("Error: Failed to find the 'Add' section in the .clangd file.") + sys.exit(1) + + prefix = match.group(1) # e.g., "Add: [\n" with indentation + block_content = match.group(2) + suffix = match.group(3) # e.g., "\n ]" (closing bracket with indentation) + + # Split the block into lines. + lines = block_content.splitlines() + + # Determine the indentation from the first non-empty line, or default to 4 spaces. + indent = " " + for line in lines: + stripped = line.lstrip() + if stripped: + indent = line[:len(line)-len(stripped)] + break + + # Build new lines for the computed strings. + new_inserts = [f'{indent}"{item}",' for item in outputs] + + # Insert the new lines at the beginning of the existing block. + new_block_lines = new_inserts + lines + new_block = prefix + "\n".join(new_block_lines) + suffix + + # Replace the original Add block with the new block. + new_content = "# If you want to edit this file, edit scripts/.clangd and reconfigure meson\n" + content[:match.start()] + new_block + content[match.end():] + + # Write the updated content back to the destination .clangd file. + with open(dest_clangd_path, 'w') as f: + f.write(new_content) + + print(f"Successfully updated {dest_clangd_path}.") + +if __name__ == "__main__": + main() diff --git a/scripts/patch_headers.py b/scripts/patch_headers.py deleted file mode 100644 index 9dec6f4e..00000000 --- a/scripts/patch_headers.py +++ /dev/null @@ -1,93 +0,0 @@ -''' -Adds __attribute__((pcs("aapcs")) to all sdk function declarations to allow properly linking -with the sdk (which uses the soft float abi) when building pros with the hard float abi -''' - -from os import listdir, makedirs -from os.path import isfile, join, exists, dirname, realpath - -def print_and_exit(message): - print(message) - print("Failed to patch libv5rt") - exit(1) - -# get the current directory -try: - current_dir = dirname(realpath(__file__)) -except: - print_and_exit("Could not get working directory!") -# set the include path and the include path of the patched SDK -include_path = current_dir + "/../firmware/libv5rt/sdk/vexv5/include/" -patched_include_path = current_dir + "/../firmware/libv5rt/sdk/vexv5/patched_include/" -# create the include path if it does not exist already -if exists(patched_include_path): - print("libv5rt already patched") - exit(0) -else: - try: - makedirs(patched_include_path) - except: - print_and_exit("Could not create directory for patched libv5rt") - -# get a list of files in the include path -try: - all_files = listdir(include_path) -except: - print_and_exit("Error getting directories and files in include path") -files = [] -for f in all_files: - if isfile(join(include_path, f)) and str(f).endswith(".h"): - files.append(f) - -# patch headers -for file_name in files: - header_file = "" - output = "" - skip_next_line = False - try: - with open(join(include_path, file_name), "r") as file: - header_file = file.read() - except: - print_and_exit("Failed to open file in v5rts") - for line in header_file.splitlines(): - if skip_next_line: - # This line is a macro continuation - if not line.endswith(("\\")): - # macro continuation ends here - skip_next_line = False - continue - if line.strip().startswith(("/", "*")): - # it's a comment - output += f"{line}\n" - continue - if line.strip().startswith(("#")): - # it's a preprocessor directive - output += f"{line}\n" - if line.endswith(("\\")): - skip_next_line = True - continue - if line.strip().startswith(("}", "{", "extern")): - # it's an extern c block or struct definition - output += f"{line}\n" - continue - if line.strip().startswith(("typedef", "struct", "enum")): - # it's a struct/enum definition or typedef - output += f"{line}\n" - continue - if not line or line.isspace(): - # it's blank - output += f"{line}\n" - continue - if ");" not in line: - # just in case something that isn't a function slips past the previous checks - # ");" should only occur in a function definition - output += f"{line}\n" - continue - output += f"__attribute__((pcs(\"aapcs\"))) {line}\n" - try: - with open(join(patched_include_path, file_name), "w") as file: - file.write(output) - except: - print_and_exit("Failed to write patched file") - -print("libv5rt patched successfully") \ No newline at end of file diff --git a/scripts/public_symbols.txt b/scripts/public_symbols.txt deleted file mode 100644 index 7b5bffb7..00000000 --- a/scripts/public_symbols.txt +++ /dev/null @@ -1,39 +0,0 @@ -millis -task_create -task_delete -task_delay -task_delay_until -task_get_priority -task_set_priority -task_get_state -task_suspend -task_resume -task_get_count -task_get_name -task_get_by_name -task_notify -task_notify_ext -task_notify_take -task_notify_clear -mutex_create -mutex_take -mutex_give -sem_create -sem_wait -sem_post -task_abort_delay -sem_binary_create -mutex_recursive_create -mutex_recursive_take -mutex_recursive_give -mutex_get_owner -sem_get_count -queue_create -queue_prepend -queue_append -queue_peek -queue_recv -queue_get_waiting -queue_get_available -queue_delete -queue_reset diff --git a/scripts/v5.ini b/scripts/v5.ini new file mode 100644 index 00000000..253a0d60 --- /dev/null +++ b/scripts/v5.ini @@ -0,0 +1,35 @@ +# Cross-compile configuration for the VEX V5. +# Essentially, it tells meson what tools to use and what flags +# to use so it can compile code that can run on the V5 + +# compiler flags +[constants] +arch_flags = ['-mcpu=cortex-a9', '-mfpu=neon-fp16', '-mfloat-abi=hard'] # the fastest arch flags possible for the A9 in the v5 +linkerscript = ['-T../scripts/v5.ld'] + +# build options +[built-in options] +default_library = 'static' # the v5 does not support shared objects +prefer_static = 'true' +c_args = arch_flags +cpp_args = arch_flags +c_link_args = arch_flags + linkerscript +cpp_link_args = arch_flags + linkerscript + +# what executables to use to compile ZestCode +[binaries] +c = 'arm-none-eabi-gcc' +cpp = 'arm-none-eabi-g++' +ar = 'arm-none-eabi-ar' +objcopy = 'arm-none-eabi-objcopy' +objdump = 'arm-none-eabi-objdump' +strip = 'arm-none-eabi-strip' +size = 'arm-none-eabi-size' + +# specs of the v5 brain +[host_machine] +system = 'none' +kernel = 'none' +cpu_family = 'arm' +cpu = 'cortex-a9' +endian = 'little' \ No newline at end of file diff --git a/firmware/v5-common.ld b/scripts/v5.ld similarity index 73% rename from firmware/v5-common.ld rename to scripts/v5.ld index da7e9cf4..4ae99025 100644 --- a/firmware/v5-common.ld +++ b/scripts/v5.ld @@ -1,3 +1,46 @@ +/* Linkerscript for the VEX V5. + * This script tells the compiler how to structure the program binary, + * and where it should be stored in RAM. + */ + +/* This stack is used during initialization, but FreeRTOS tasks have their own + stack allocated in BSS or Heap (kernel tasks in FreeRTOS .bss heap; user tasks + in standard heap) */ +_STACK_SIZE = DEFINED(_STACK_SIZE) ? _STACK_SIZE : 0x2000; + +_ABORT_STACK_SIZE = DEFINED(_ABORT_STACK_SIZE) ? _ABORT_STACK_SIZE : 1024; +_SUPERVISOR_STACK_SIZE = DEFINED(_SUPERVISOR_STACK_SIZE) ? _SUPERVISOR_STACK_SIZE : 2048; +_IRQ_STACK_SIZE = DEFINED(_IRQ_STACK_SIZE) ? _IRQ_STACK_SIZE : 1024; +_FIQ_STACK_SIZE = DEFINED(_FIQ_STACK_SIZE) ? _FIQ_STACK_SIZE : 1024; +_UNDEF_STACK_SIZE = DEFINED(_UNDEF_STACK_SIZE) ? _UNDEF_STACK_SIZE : 1024; + +_HEAP_SIZE = DEFINED(_HEAP_SIZE) ? _HEAP_SIZE : 0x02E00000; /* ~48 MB */ + +/* Define Memories in the system */ +start_of_cold_mem = 0x03800000; +_COLD_MEM_SIZE = 0x04800000; +end_of_cold_mem = start_of_cold_mem + _COLD_MEM_SIZE; + +start_of_hot_mem = 0x07800000; +_HOT_MEM_SIZE = 0x00800000; +end_of_hot_mem = start_of_hot_mem + _HOT_MEM_SIZE; + +MEMORY +{ + /* user code 72M */ + COLD_MEMORY : ORIGIN = start_of_cold_mem, LENGTH = _COLD_MEM_SIZE /* Just under 19 MB */ + HEAP : ORIGIN = 0x04A00000, LENGTH = _HEAP_SIZE + HOT_MEMORY : ORIGIN = start_of_hot_mem, LENGTH = _HOT_MEM_SIZE /* Just over 8 MB */ +} + +/* used in _sbrk implementation */ +_HEAP_START = ORIGIN(HEAP); +_HEAP_END = ORIGIN(HEAP) + LENGTH(HEAP); + +REGION_ALIAS("RAM", COLD_MEMORY); + +ENTRY(_start) + /* Define the sections, and where they are mapped in memory */ SECTIONS { diff --git a/scripts/verify-symbols.sh b/scripts/verify-symbols.sh deleted file mode 100644 index f830be79..00000000 --- a/scripts/verify-symbols.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -# when running this script, there should be nothing red or dark blue on the right panel (what's the in header files) with the following exceptions - -# the pros::c::* functions. They're #ifdef __cplusplus'd out into a namespace. The C linkages demonstrate that it's fine -# Default arguments exist in the constructor in the header file, but not in the implementation - -shopt -s globstar -# Convenience script to manually verify that all functions in the public headers exist in the source directory -vimdiff <(ctags --sort=yes --c-kinds=f --extra=-f+q --fields=S -f - src/**/* | awk '{if(index($0, "signature:")) print $1, substr($0, index($0, "signature:"))}' | sort ) <(ctags --sort=yes --c-kinds=p --extra=-f+q --fields=S -f - include/pros/**/* | awk '{if(index($0, "signature:")) print $1, substr($0, index($0, "signature:"))}' | sort) diff --git a/src/common/cobs.c b/src/common/cobs.c index 809b4c9f..d3c0893d 100644 --- a/src/common/cobs.c +++ b/src/common/cobs.c @@ -16,7 +16,7 @@ #include -#include "cobs.h" +#include "common/cobs.h" size_t cobs_encode_measure(const uint8_t* restrict src, const size_t src_len, const uint32_t prefix) { size_t read_idx = 0; diff --git a/src/common/string.c b/src/common/string2.c similarity index 100% rename from src/common/string.c rename to src/common/string2.c diff --git a/src/devices/battery.c b/src/devices/battery.c index e718ce5e..7fc29fba 100644 --- a/src/devices/battery.c +++ b/src/devices/battery.c @@ -11,7 +11,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "v5_api.h" +#include "v5_api_patched.h" #include "vdml/vdml.h" int32_t battery_get_voltage(void) { diff --git a/src/devices/competition.cpp b/src/devices/competition.cpp index 08e65be3..5e1f7dc6 100644 --- a/src/devices/competition.cpp +++ b/src/devices/competition.cpp @@ -12,7 +12,7 @@ */ #include "pros/misc.h" -#include "v5_api.h" +#include "v5_api_patched.h" // TODO: remove this C API extern "C" { diff --git a/src/devices/registry.c b/src/devices/registry.c index 8dff0557..69b0c29a 100644 --- a/src/devices/registry.c +++ b/src/devices/registry.c @@ -17,7 +17,7 @@ #include "kapi.h" #include "pros/apix.h" #include "pros/misc.h" -#include "v5_api.h" +#include "v5_api_patched.h" #include "vdml/vdml.h" #include diff --git a/src/devices/screen.c b/src/devices/screen.c index 40ef6833..7311076c 100644 --- a/src/devices/screen.c +++ b/src/devices/screen.c @@ -16,7 +16,7 @@ #include "common/linkedlist.h" #include "kapi.h" -#include "v5_api.h" // vexDisplay* +#include "v5_api_patched.h" // vexDisplay* #include #include diff --git a/src/devices/vdml_usd.c b/src/devices/vdml_usd.c index cf971bd2..65c1cc33 100644 --- a/src/devices/vdml_usd.c +++ b/src/devices/vdml_usd.c @@ -12,7 +12,7 @@ */ #include "pros/error.h" -#include "v5_api.h" +#include "v5_api_patched.h" #include #include diff --git a/src/rtos/heap_4.c b/src/rtos/heap_4.c index 2ac367fc..729048e1 100644 --- a/src/rtos/heap_4.c +++ b/src/rtos/heap_4.c @@ -35,8 +35,8 @@ */ #include -#include "FreeRTOS.h" -#include "task.h" +#include "rtos/FreeRTOS.h" +#include "rtos/task.h" #if( configSUPPORT_DYNAMIC_ALLOCATION == 0 ) #error This file must not be used if configSUPPORT_DYNAMIC_ALLOCATION is 0 diff --git a/src/rtos/list.c b/src/rtos/list.c index 9e1bae85..e690fde1 100644 --- a/src/rtos/list.c +++ b/src/rtos/list.c @@ -27,8 +27,8 @@ #include -#include "FreeRTOS.h" -#include "list.h" +#include "rtos/FreeRTOS.h" +#include "rtos/list.h" /*----------------------------------------------------------- * PUBLIC LIST API documented in list.h diff --git a/src/rtos/port.c b/src/rtos/port.c index c51e07d0..baa30bc3 100644 --- a/src/rtos/port.c +++ b/src/rtos/port.c @@ -29,8 +29,8 @@ #include /* Scheduler includes. */ -#include "FreeRTOS.h" -#include "task.h" +#include "rtos/FreeRTOS.h" +#include "rtos/task.h" #ifndef configINTERRUPT_CONTROLLER_BASE_ADDRESS #error configINTERRUPT_CONTROLLER_BASE_ADDRESS must be defined. See http://www.freertos.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html diff --git a/src/rtos/queue.c b/src/rtos/queue.c index 41646b20..80411b0a 100644 --- a/src/rtos/queue.c +++ b/src/rtos/queue.c @@ -28,9 +28,9 @@ #include #include -#include "FreeRTOS.h" -#include "task.h" -#include "queue.h" +#include "rtos/FreeRTOS.h" +#include "rtos/task.h" +#include "rtos/queue.h" /* Constants used with the cRxLock and cTxLock structure members. */ diff --git a/src/rtos/refactor.sh b/src/rtos/refactor.sh deleted file mode 100644 index 1246b12e..00000000 --- a/src/rtos/refactor.sh +++ /dev/null @@ -1,3 +0,0 @@ -# Change the current order of the awk print is to convert FreeRTOS style to PROS -# style. Change from `$1, $2` to `$2, $1` to go the other way. -cat src/rtos/refactor.tsv | dos2unix | awk '/^\s*$/ {next;} {if(NR>1) { printf "s/\\\\<%s\\\\>/%s/g\n", $1, $2 } }' | xargs -I '{}' zsh -c 'echo "{}"; sed -i "{}" **/*.(h|c|md|s|S|cpp|c++|cc)' diff --git a/src/rtos/refactor.tsv b/src/rtos/refactor.tsv deleted file mode 100644 index b59c3158..00000000 --- a/src/rtos/refactor.tsv +++ /dev/null @@ -1,101 +0,0 @@ -Original Refactored -TaskHandle_t task_t -TaskFunction_t task_fn_t -eTaskState task_state_e_t -eRunning E_TASK_STATE_RUNNING -eReady E_TASK_STATE_READY -eBlocked E_TASK_STATE_BLOCKED -eSuspended E_TASK_STATE_SUSPENDED -eDeleted E_TASK_STATE_DELETED -eInvalid E_TASK_STATE_INVALID -eNotifyAction notify_action_e_t -eNoAction E_NOTIFY_ACTION_NONE -eSetBits E_NOTIFY_ACTION_BITS -eIncrement E_NOTIFY_ACTION_INCR -eSetValueWithOverwrite E_NOTIFY_ACTION_OWRITE -eSetValueWithoutOverwrite E_NOTIFY_ACTION_NO_OWRITE -QueueHandle_t queue_t -SemaphoreHandle_t sem_t -MutexHandle_t mutex_t -StackType_t task_stack_t -StaticTask_t static_task_s_t -BaseType_t int32_t -UBaseType_t uint32_t -TickType_t uint32_t -ListItem_t list_item_t -StaticSemaphore_t static_sem_s_t -StaticQueue_t static_queue_s_t -StreamBufferHandle_t stream_buf_t -StaticStreamBuffer_t static_stream_buf_s_t -MessageBufferHandle_t msg_buf_t -StaticMessageBuffer_t static_msg_buf_s_t - - - -xTaskCreate task_create -xTaskCreateStatic task_create_static -vTaskDelete task_delete -vTaskDelay task_delay -vTaskDelayUntil task_delay_until -uxTaskPriorityGet task_get_priority -vTaskPrioritySet task_set_priority -eTaskGetState task_get_state -vTaskSuspend task_suspend -vTaskResume task_resume -xTaskAbortDelay task_abort_delay -vTaskStartScheduler rtos_sched_start -vTaskEndScheduler rtos_sched_stop -vTaskSuspendAll rtos_suspend_all -xTaskResumeAll rtos_resume_all -xTaskGetTickCount millis -uxTaskGetNumberOfTasks task_get_count -pcTaskGetName task_get_name -xTaskGetHandle task_get_by_name -xTaskGenericNotify task_notify_ext -ulTaskNotifyTake task_notify_take -xTaskNotifyWait task_notify_wait -xTaskNotifyStateClear task_notify_clear -xTaskGetCurrentTaskHandle task_get_current -xQueueCreate queue_create -xQueueSendToFront queue_prepend -xQueueSendToBack queue_append -xQueueOverwrite queue_overwrite -xQueuePeek queue_peek -xQueueReceive queue_recv -uxQueueMessagesWaiting queue_get_waiting -uxQueueSpacesAvailable queue_get_available -vQueueDelete queue_delete -xSemaphoreCreateBinary sem_binary_create -xSemaphoreTake sem_wait -xSemaphoreTakeRecursive mutex_recursive_take -xSemaphoreGive sem_post -xSemaphoreGiveRecursive mutex_recursive_give -xSemaphoreCreateMutex mutex_create -xSemaphoreCreateRecursiveMutex mutex_recursive_create -xSemaphoreCreateCounting sem_create -vSemaphoreDelete sem_delete -xSemaphoreGetMutexHolder mutex_get_owner -uxSemaphoreGetCount sem_get_count -pvPortMalloc kmalloc -vPortFree kfree -xSemaphoreCreateMutexStatic mutex_create_static -xSemaphoreCreateCountingStatic sem_create_static -xQueueCreateStatic queue_create_static -xStreamBufferCreateStatic stream_buf_create_static -xStreamBufferCreate stream_buf_create -xStreamBufferSend stream_buf_send -xStreamBufferReceive stream_buf_recv -xStreamBufferDelete stream_buf_delete -xStreamBufferBytesAvailable stream_buf_get_used -xStreamBufferSpacesAvailable stream_buf_get_unused -xStreamBufferSetTriggerLevel stream_buf_set_trigger -xStreamBufferReset stream_buf_reset -xStreamBufferIsEmpty stream_buf_is_empty -xStreamBufferIsFull stream_buf_is_full -xMessageBufferSend msg_buf_send -xMessageBufferReceive msg_buf_recv -xMessageBufferDelete msg_buf_delete -xMessageBufferSpacesAvailable msg_buf_get_unused -xMessageBufferReset msg_buf_reset -xMessageBufferIsEmpty msg_buf_is_empty -xMessageBufferIsFull msg_buf_is_full diff --git a/src/rtos/semphr.c b/src/rtos/semphr.c index bee1cc5b..fdd4f8f8 100644 --- a/src/rtos/semphr.c +++ b/src/rtos/semphr.c @@ -1,5 +1,5 @@ -#include "FreeRTOS.h" -#include "semphr.h" +#include "rtos/FreeRTOS.h" +#include "rtos/semphr.h" /** * semphr. h diff --git a/src/rtos/stream_buffer.c b/src/rtos/stream_buffer.c index 504f1ac8..47abc2f7 100644 --- a/src/rtos/stream_buffer.c +++ b/src/rtos/stream_buffer.c @@ -35,9 +35,9 @@ task.h is included from an application file. */ #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE /* FreeRTOS includes. */ -#include "FreeRTOS.h" -#include "task.h" -#include "stream_buffer.h" +#include "rtos/FreeRTOS.h" +#include "rtos/task.h" +#include "rtos/stream_buffer.h" #if( configUSE_TASK_NOTIFICATIONS != 1 ) #error configUSE_TASK_NOTIFICATIONS must be set to 1 to build stream_buffer.c diff --git a/src/rtos/tasks.c b/src/rtos/tasks.c index a413af49..806760f8 100644 --- a/src/rtos/tasks.c +++ b/src/rtos/tasks.c @@ -29,7 +29,7 @@ #include #include -#include "v5_api.h" +#include "v5_api_patched.h" /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining all the API functions to use the MPU wrappers. That should only be done when @@ -37,10 +37,10 @@ task.h is included from an application file. */ #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE /* FreeRTOS includes. */ -#include "FreeRTOS.h" -#include "task.h" -#include "timers.h" -#include "stack_macros.h" +#include "rtos/FreeRTOS.h" +#include "rtos/task.h" +#include "rtos/timers.h" +#include "rtos/stack_macros.h" /* Lint e961 and e750 are suppressed as a MISRA exception justified because the MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined for the @@ -263,7 +263,7 @@ to its original value when it is released. */ #define taskEVENT_LIST_ITEM_VALUE_IN_USE 0x80000000UL #endif -#include "tcb.h" +#include "rtos/tcb.h" /*lint -save -e956 A manual analysis and inspection has been used to determine which static variables must be declared volatile. */ @@ -4749,6 +4749,13 @@ uint32_t uxReturn; #if( configUSE_TASK_NOTIFICATIONS == 1 ) + void task_notify_when_deleting( + task_t target_task, + task_t task_to_notify, + uint32_t value, + notify_action_e_t notify_action + ); + void task_join(task_t task) { if(!task) return; TaskStatus_t xTaskDetails; diff --git a/src/rtos/timers.c b/src/rtos/timers.c index 039c8a94..f0089b3c 100644 --- a/src/rtos/timers.c +++ b/src/rtos/timers.c @@ -33,10 +33,10 @@ all the API functions to use the MPU wrappers. That should only be done when task.h is included from an application file. */ #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE -#include "FreeRTOS.h" -#include "task.h" -#include "queue.h" -#include "timers.h" +#include "rtos/FreeRTOS.h" +#include "rtos/task.h" +#include "rtos/queue.h" +#include "rtos/timers.h" #if ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 0 ) #error configUSE_TIMERS must be set to 1 to make the xTimerPendFunctionCall() function available. diff --git a/src/system/cpp_support.cpp b/src/system/cpp_support.cpp index 9e5a8b42..76c0eb7a 100644 --- a/src/system/cpp_support.cpp +++ b/src/system/cpp_support.cpp @@ -12,7 +12,7 @@ */ #include "rtos/task.h" -#include "v5_api.h" +#include "v5_api_patched.h" #include #include diff --git a/src/system/dev/ser_daemon.c b/src/system/dev/ser_daemon.c index dbd2f034..2fb86ec7 100644 --- a/src/system/dev/ser_daemon.c +++ b/src/system/dev/ser_daemon.c @@ -16,9 +16,8 @@ */ #include "kapi.h" -#include "pros/version.h" #include "system/dev/banners.h" -#include "v5_api.h" +#include "v5_api_patched.h" #define MAX_COMMAND_LENGTH 32 @@ -40,7 +39,7 @@ void print_small_banner(void) { char const* const directory = _PROS_COMPILE_DIRECTORY; iprintf( short_banner, - PROS_VERSION_STRING, + "0.0.0", // PROS_VERSION_STRING, uptime / 1000, // clangd is lying to you uptime % 1000, // clangd is lying to you timestamp, @@ -59,7 +58,7 @@ void print_large_banner(void) { char const* const directory = _PROS_COMPILE_DIRECTORY; iprintf( large_banner, - PROS_VERSION_STRING, + "0.0.0", // PROS_VERSION_STRING, version[3], version[2], version[1], diff --git a/src/system/dev/ser_driver.c b/src/system/dev/ser_driver.c index 5d7675aa..eac72ce2 100644 --- a/src/system/dev/ser_driver.c +++ b/src/system/dev/ser_driver.c @@ -19,7 +19,7 @@ #include "kapi.h" #include "system/dev/ser.h" #include "system/dev/vfs.h" -#include "v5_api.h" +#include "v5_api_patched.h" #include diff --git a/src/system/dev/usd_driver.c b/src/system/dev/usd_driver.c index 63b5a3d1..db71291a 100644 --- a/src/system/dev/usd_driver.c +++ b/src/system/dev/usd_driver.c @@ -15,7 +15,7 @@ #include "kapi.h" // IWYU pragma: keep #include "system/dev/usd.h" #include "system/dev/vfs.h" -#include "v5_api.h" +#include "v5_api_patched.h" #include #include diff --git a/src/system/dev/vfs.c b/src/system/dev/vfs.c index 4e38ab15..c8b02f1e 100644 --- a/src/system/dev/vfs.c +++ b/src/system/dev/vfs.c @@ -109,8 +109,8 @@ int _open(const char* file, int flags, int mode) { return ser_open_r(r, file + strlen("/ser"), flags, mode); } else if (strstr(file, "/usd") == file) { return usd_open_r(r, file + strlen("/usd"), flags, mode); - } else if (strstr(file, "/dev") == file) { - return dev_open_r(r, file + strlen("/dev"), flags, mode); + //} else if (strstr(file, "/dev") == file) { + // return dev_open_r(r, file + strlen("/dev"), flags, mode); } else { return usd_open_r(r, file, flags, mode); } diff --git a/src/system/rtos_hooks.c b/src/system/rtos_hooks.c index fa0c9876..526f2230 100644 --- a/src/system/rtos_hooks.c +++ b/src/system/rtos_hooks.c @@ -16,7 +16,7 @@ #include "rtos/FreeRTOS.h" #include "rtos/semphr.h" #include "rtos/task.h" -#include "v5_api.h" +#include "v5_api_patched.h" void vexTasksRun(); diff --git a/src/system/startup.cpp b/src/system/startup.cpp index cc087725..1ea4979d 100644 --- a/src/system/startup.cpp +++ b/src/system/startup.cpp @@ -13,7 +13,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "v5_api.h" +#include "v5_api_patched.h" #include #include @@ -97,6 +97,10 @@ void _start() { // This is the industry standard #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpedantic" +#pragma GCC diagnostic ignored "-Wunknown-pragmas" +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wmain" main(); +#pragma clang diagnostic pop #pragma GCC diagnostic pop } diff --git a/src/system/stubs.cpp b/src/system/stubs.cpp index 7dee04d0..f464c258 100644 --- a/src/system/stubs.cpp +++ b/src/system/stubs.cpp @@ -18,7 +18,7 @@ #include "pros/misc.h" #include "rtos/task.h" -#include "v5_api.h" +#include "v5_api_patched.h" #include #include diff --git a/src/system/unwind.c b/src/system/unwind.c index 177c7e64..b4817a23 100644 --- a/src/system/unwind.c +++ b/src/system/unwind.c @@ -16,7 +16,7 @@ #include "rtos/task.h" #include "rtos/tcb.h" #include "unwind-arm-common.h" -#include "v5_api.h" +#include "v5_api_patched.h" #include #include diff --git a/subprojects/v5.wrap b/subprojects/v5.wrap new file mode 100644 index 00000000..6f951c4a --- /dev/null +++ b/subprojects/v5.wrap @@ -0,0 +1,8 @@ +[wrap-git] +url = https://github.com/ZestCommunity/libv5rt-meson.git +revision = v1.2 +depth = 1 + +[provide] +v5 = v5_lib_dep +v5_header = v5_header_dep \ No newline at end of file diff --git a/template-Makefile b/template-Makefile deleted file mode 100644 index ece80655..00000000 --- a/template-Makefile +++ /dev/null @@ -1,47 +0,0 @@ -################################################################################ -######################### User configurable parameters ######################### -# filename extensions -CEXTS:=c -ASMEXTS:=s S -CXXEXTS:=cpp c++ cc - -# probably shouldn't modify these, but you may need them below -ROOT=. -FWDIR:=$(ROOT)/firmware -BINDIR=$(ROOT)/bin -SRCDIR=$(ROOT)/src -INCDIR=$(ROOT)/include - -WARNFLAGS+= -EXTRA_CFLAGS= -EXTRA_CXXFLAGS= - -# Set to 1 to enable hot/cold linking -USE_PACKAGE:=1 - -# Add libraries you do not wish to include in the cold image here -# EXCLUDE_COLD_LIBRARIES:= $(FWDIR)/your_library.a -EXCLUDE_COLD_LIBRARIES:= - -# Set this to 1 to add additional rules to compile your project as a PROS library template -IS_LIBRARY:=0 -# TODO: CHANGE THIS! -# Be sure that your header files are in the include directory inside of a folder with the -# same name as what you set LIBNAME to below. -LIBNAME:=libbest -VERSION:=1.0.0 -# EXCLUDE_SRC_FROM_LIB= $(SRCDIR)/unpublishedfile.c -# this line excludes opcontrol.c and similar files -EXCLUDE_SRC_FROM_LIB+=$(foreach file, $(SRCDIR)/main,$(foreach cext,$(CEXTS),$(file).$(cext)) $(foreach cxxext,$(CXXEXTS),$(file).$(cxxext))) - -# files that get distributed to every user (beyond your source archive) - add -# whatever files you want here. This line is configured to add all header files -# that are in the directory include/LIBNAME -TEMPLATE_FILES=$(INCDIR)/$(LIBNAME)/*.h $(INCDIR)/$(LIBNAME)/*.hpp - -.DEFAULT_GOAL=quick - -################################################################################ -################################################################################ -########## Nothing below this line should be edited by typical users ########### --include ./common.mk diff --git a/template-gitignore b/template-gitignore deleted file mode 100644 index e303e2c0..00000000 --- a/template-gitignore +++ /dev/null @@ -1,17 +0,0 @@ -# Compiled Object files -*.o -*.obj - -# Executables -*.bin -*.elf - -# PROS -bin/ -.vscode/ -.cache/ -compile_commands.json -temp.log -temp.errors -*.ini -.d/ \ No newline at end of file diff --git a/src/tests/errno_reentrancy.c b/tests/errno_reentrancy.c similarity index 95% rename from src/tests/errno_reentrancy.c rename to tests/errno_reentrancy.c index e10eee8b..400cc4a2 100644 --- a/src/tests/errno_reentrancy.c +++ b/tests/errno_reentrancy.c @@ -1,6 +1,6 @@ #include #include "api.h" -#include "v5_api.h" +#include "v5_api_patched.h" void task_a_fn(void* ign) { vexDisplayString(2, "Errno from A is: %d\n", errno); diff --git a/src/main.cpp b/tests/examples/basic.cpp similarity index 100% rename from src/main.cpp rename to tests/examples/basic.cpp diff --git a/src/tests/exceptions.cpp b/tests/exceptions.cpp similarity index 92% rename from src/tests/exceptions.cpp rename to tests/exceptions.cpp index 06a283a5..2c8c31fa 100644 --- a/src/tests/exceptions.cpp +++ b/tests/exceptions.cpp @@ -1,7 +1,7 @@ #include #include -#include "v5_api.h" +#include "v5_api_patched.h" #include "rtos/FreeRTOS.h" #include "rtos/task.h" diff --git a/src/tests/mutexes.c b/tests/mutexes.c similarity index 100% rename from src/tests/mutexes.c rename to tests/mutexes.c diff --git a/src/tests/rtos_function_linking.c b/tests/rtos_function_linking.c similarity index 100% rename from src/tests/rtos_function_linking.c rename to tests/rtos_function_linking.c diff --git a/src/tests/segfault.cpp b/tests/segfault.cpp similarity index 100% rename from src/tests/segfault.cpp rename to tests/segfault.cpp diff --git a/src/tests/static_tast_states.c b/tests/static_tast_states.c similarity index 100% rename from src/tests/static_tast_states.c rename to tests/static_tast_states.c diff --git a/src/tests/task_notify_when_deleting.c b/tests/task_notify_when_deleting.c similarity index 100% rename from src/tests/task_notify_when_deleting.c rename to tests/task_notify_when_deleting.c diff --git a/src/tests/unwind.cpp b/tests/unwind.cpp similarity index 100% rename from src/tests/unwind.cpp rename to tests/unwind.cpp