From 807edfdffc02534ac297fba710257e657c447726 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Sat, 11 Nov 2023 16:02:40 -0500 Subject: [PATCH 001/108] Initial commit --- .clang-format | 202 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..155746eb --- /dev/null +++ b/.clang-format @@ -0,0 +1,202 @@ +# Configuration file for clang-format 17 +--- +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignArrayOfStructures: None +AlignConsecutiveAssignments: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: true +AlignConsecutiveBitFields: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: false +AlignConsecutiveDeclarations: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: false +AlignConsecutiveMacros: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: false +AlignConsecutiveShortCaseStatements: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCaseColons: false +AlignEscapedNewlines: Right +AlignOperands: Align +AlignTrailingComments: + Kind: Never + OverEmptyLines: 0 +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: Empty +AllowShortCaseLabelsOnASingleLine: false +AllowShortEnumsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: Yes +BinPackArguments: false +BinPackParameters: true +BitFieldColonSpacing: Both +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterExternBlock: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakAfterAttributes: Never +BreakAfterJavaFieldAnnotations: false +BreakArrays: true +BreakBeforeBinaryOperators: None +BreakBeforeConceptDeclarations: Always +BreakBeforeBraces: Attach +BreakBeforeInlineASMColon: OnlyMultiline +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +BreakInheritanceList: BeforeColon +BreakStringLiterals: true +ColumnLimit: 100 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +IncludeBlocks: Preserve +IncludeIsMainRegex: '(Test)?$' +IncludeIsMainSourceRegex: '' +IndentAccessModifiers: false +IndentCaseBlocks: false +IndentCaseLabels: true +IndentExternBlock: AfterExternBlock +IndentGotoLabels: true +IndentPPDirectives: None +IndentRequiresClause: true +IndentWidth: 4 +IndentWrappedFunctionNames: false +InsertBraces: true +InsertNewlineAtEOF: false +InsertTrailingCommas: None +IntegerLiteralSeparator: + Binary: 0 + BinaryMinDigits: 0 + Decimal: 0 + DecimalMinDigits: 0 + Hex: 0 + HexMinDigits: 0 +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +KeepEmptyLinesAtEOF: false +LambdaBodyIndentation: Signature +LineEnding: DeriveLF +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: All +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PackConstructorInitializers: BinPack +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyIndentedWhitespace: 0 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Right +PPIndentWidth: -1 +QualifierAlignment: Leave +ReferenceAlignment: Pointer +ReflowComments: true +RemoveBracesLLVM: false +RemoveParentheses: Leave +RemoveSemicolon: false +RequiresClausePosition: OwnLine +RequiresExpressionIndentation: OuterScope +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 1 +SortIncludes: CaseSensitive +SortJavaStaticImport: Before +SortUsingDeclarations: LexicographicNumeric +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceAroundPointerQualifiers: Default +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeJsonColon: false +SpaceBeforeParens: ControlStatements +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: true + AfterOverloadedOperator: false + AfterRequiresInClause: false + AfterRequiresInExpression: false + BeforeNonEmptyParentheses: false +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: Never +SpacesInContainerLiterals: true +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParens: Never +SpacesInParensOptions: + InCStyleCasts: false + InConditionalStatements: false + InEmptyParentheses: false + Other: false +SpacesInSquareBrackets: false +Standard: Latest +TabWidth: 4 +UseTab: Never +VerilogBreakBetweenInstancePorts: true +... From bee751c97672458fa436977d6cea0ef3d71b6853 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Tue, 27 Aug 2024 11:59:33 -0400 Subject: [PATCH 002/108] Update config file for clang-format 19 --- .clang-format | 51 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/.clang-format b/.clang-format index 155746eb..d8c9cf3f 100644 --- a/.clang-format +++ b/.clang-format @@ -1,4 +1,4 @@ -# Configuration file for clang-format 17 +# Waterloo Rocketry Configuration file for clang-format 19 --- AccessModifierOffset: -4 AlignAfterOpenBracket: Align @@ -8,30 +8,56 @@ AlignConsecutiveAssignments: AcrossEmptyLines: false AcrossComments: false AlignCompound: false + AlignFunctionPointers: false PadOperators: true AlignConsecutiveBitFields: Enabled: false AcrossEmptyLines: false AcrossComments: false AlignCompound: false + AlignFunctionPointers: false PadOperators: false AlignConsecutiveDeclarations: Enabled: false AcrossEmptyLines: false AcrossComments: false AlignCompound: false + AlignFunctionPointers: false PadOperators: false AlignConsecutiveMacros: Enabled: false AcrossEmptyLines: false AcrossComments: false AlignCompound: false + AlignFunctionPointers: false PadOperators: false AlignConsecutiveShortCaseStatements: Enabled: false AcrossEmptyLines: false AcrossComments: false + AlignCaseArrows: false AlignCaseColons: false +AlignConsecutiveTableGenBreakingDAGArgColons: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveTableGenCondOperatorColons: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveTableGenDefinitionColons: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false AlignEscapedNewlines: Right AlignOperands: Align AlignTrailingComments: @@ -39,17 +65,18 @@ AlignTrailingComments: OverEmptyLines: 0 AllowAllArgumentsOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: true +AllowBreakBeforeNoexceptSpecifier: Never AllowShortBlocksOnASingleLine: Empty +AllowShortCaseExpressionOnASingleLine: false AllowShortCaseLabelsOnASingleLine: false +AllowShortCompoundRequirementOnASingleLine: false AllowShortEnumsOnASingleLine: false AllowShortFunctionsOnASingleLine: Empty AllowShortIfStatementsOnASingleLine: Never AllowShortLambdasOnASingleLine: All AllowShortLoopsOnASingleLine: false AlwaysBreakAfterDefinitionReturnType: None -AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: false -AlwaysBreakTemplateDeclarations: Yes BinPackArguments: false BinPackParameters: true BitFieldColonSpacing: Both @@ -72,8 +99,10 @@ BraceWrapping: SplitEmptyFunction: true SplitEmptyRecord: true SplitEmptyNamespace: true -BreakAfterAttributes: Never +BreakAdjacentStringLiterals: true +BreakAfterAttributes: Leave BreakAfterJavaFieldAnnotations: false +BreakAfterReturnType: None BreakArrays: true BreakBeforeBinaryOperators: None BreakBeforeConceptDeclarations: Always @@ -81,8 +110,10 @@ BreakBeforeBraces: Attach BreakBeforeInlineASMColon: OnlyMultiline BreakBeforeTernaryOperators: true BreakConstructorInitializers: BeforeColon +BreakFunctionDefinitionParameters: false BreakInheritanceList: BeforeColon BreakStringLiterals: true +BreakTemplateDeclarations: MultiLine ColumnLimit: 100 CommentPragmas: '^ IWYU pragma:' CompactNamespaces: false @@ -119,12 +150,15 @@ IntegerLiteralSeparator: HexMinDigits: 0 JavaScriptQuotes: Leave JavaScriptWrapImports: true -KeepEmptyLinesAtTheStartOfBlocks: true -KeepEmptyLinesAtEOF: false +KeepEmptyLines: + AtEndOfFile: true + AtStartOfBlock: false + AtStartOfFile: true LambdaBodyIndentation: Signature LineEnding: DeriveLF MacroBlockBegin: '' MacroBlockEnd: '' +MainIncludeChar: Quote MaxEmptyLinesToKeep: 1 NamespaceIndentation: All ObjCBinPackProtocolList: Auto @@ -138,6 +172,7 @@ PenaltyBreakBeforeFirstCallParameter: 19 PenaltyBreakComment: 300 PenaltyBreakFirstLessLess: 120 PenaltyBreakOpenParenthesis: 0 +PenaltyBreakScopeResolution: 500 PenaltyBreakString: 1000 PenaltyBreakTemplateDeclaration: 10 PenaltyExcessCharacter: 1000000 @@ -155,6 +190,7 @@ RequiresClausePosition: OwnLine RequiresExpressionIndentation: OuterScope SeparateDefinitionBlocks: Leave ShortNamespaceLines: 1 +SkipMacroDefinitionBody: false SortIncludes: CaseSensitive SortJavaStaticImport: Before SortUsingDeclarations: LexicographicNumeric @@ -176,6 +212,7 @@ SpaceBeforeParensOptions: AfterFunctionDeclarationName: false AfterIfMacros: true AfterOverloadedOperator: false + AfterPlacementOperator: true AfterRequiresInClause: false AfterRequiresInExpression: false BeforeNonEmptyParentheses: false @@ -190,12 +227,14 @@ SpacesInLineCommentPrefix: Maximum: -1 SpacesInParens: Never SpacesInParensOptions: + ExceptDoubleParentheses: false InCStyleCasts: false InConditionalStatements: false InEmptyParentheses: false Other: false SpacesInSquareBrackets: false Standard: Latest +TableGenBreakInsideDAGArg: DontBreak TabWidth: 4 UseTab: Never VerilogBreakBetweenInstancePorts: true From 70d175dc58c9363adeb0e6fd6eb741d84a662f67 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Sun, 15 Sep 2024 16:00:23 -0400 Subject: [PATCH 003/108] Migrate PIC18 timer driver and millis from canlib --- include/timer.h | 16 ++++++++++++ pic18f26k83/timer.c | 62 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 include/timer.h create mode 100644 pic18f26k83/timer.c diff --git a/include/timer.h b/include/timer.h new file mode 100644 index 00000000..4ff34c58 --- /dev/null +++ b/include/timer.h @@ -0,0 +1,16 @@ +#ifndef ROCKETLIB_TIMER_H +#define ROCKETLIB_TIMER_H + +#include + +// utilities for handling the timer used in millis() +void timer0_init(void); + +// should be called from the general ISR to increment the timer +// DOES NOT CLEAR PIR3bits.TMR0IF! This is the responsibility of the top level ISR. +void timer0_handle_interrupt(void); + +// Returns milliseconds since the timer was initialized +uint32_t millis(void); + +#endif /* ROCKETLIB_TIMER_H */ diff --git a/pic18f26k83/timer.c b/pic18f26k83/timer.c new file mode 100644 index 00000000..25a3576f --- /dev/null +++ b/pic18f26k83/timer.c @@ -0,0 +1,62 @@ +#include + +#include "timer.h" + +#ifndef _PIC18F26K83_H_ +#warning "compiling pic18f26k83 hardware specific file on a different microcontroller, WTF?" +#endif + +/* + * Magic numbers: timer is driven on a 500kHz clock and is 8 bits. + * Timer rolls over every 256 counts, or every 512 microseconds. + * MILLIS_INCREMENT = 0, since there are 0 ms added each rollover + * MILLIS_REMAINDER = 512, added each time the timer is triggered + * MILLIS_INCREMENT_CAP = 1000, number of microseconds before we tick over a millisecond + * + * Only the ratio between MILLIS_REMAINDER and MILLIS_INCREMENT_CAP matters, so + * we can optimize things a little bit by dividing both by 8 so that the largest + * value of internal_count can fit within 8 bits. + * + */ +#define MILLIS_INCREMENT 0 +#define MILLIS_REMAINDER 64 +#define MILLIS_INCREMENT_CAP 125 + +volatile static uint32_t millis_counter = 0; + +uint32_t millis(void) { + INTCON0bits.GIE = 0; + uint32_t res = millis_counter; + INTCON0bits.GIE = 1; + return res; +} + +void timer0_init(void) { + PIE3bits.TMR0IE = 1; // enable timer 0 interrupt + + T0CON0bits.EN = 0; // disable timer module + T0CON0bits.MD16 = 0; // set up timer as 8 bits + + T0CON0bits.OUTPS = 0; // set the output prescaler to 1:1 + T0CON1bits.CKPS = 0; // set the prescaler rate to 1:1 + + T0CON1bits.CS = 0x5; // drive timer from 500 kHz + T0CON1bits.ASYNC = 0; // timer zero is synchronized to the system clock + + // enable the module + T0CON0bits.EN = 1; +} + +/* + * Based on Bresenham's algorithm and described here: http://romanblack.com/one_sec.htm + */ +void timer0_handle_interrupt() { + static uint8_t internal_count = 0; + + millis_counter += MILLIS_INCREMENT; + internal_count += MILLIS_REMAINDER; + if (internal_count > MILLIS_INCREMENT_CAP) { + internal_count -= MILLIS_INCREMENT_CAP; + millis_counter++; + } +} From be6f855e6aa9bb707b600281fcfcc3bca49b1baa Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Thu, 3 Oct 2024 09:24:05 -0400 Subject: [PATCH 004/108] Add common return status code enum --- include/common.h | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 include/common.h diff --git a/include/common.h b/include/common.h new file mode 100644 index 00000000..5149983f --- /dev/null +++ b/include/common.h @@ -0,0 +1,9 @@ +#ifndef ROCKETLIB_COMMON_H +#define ROCKETLIB_COMMON_H + +typedef enum { + W_SUCCESS = 0, + W_FAILURE +} status_t; + +#endif From cd11de8128cb76363ce3c54f5357a1a46d7a6587 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Thu, 3 Oct 2024 16:25:24 -0400 Subject: [PATCH 005/108] Setup workflow for unit test --- common/low_pass_filter.c | 5 +++++ include/low_pass_filter.h | 8 ++++++++ 2 files changed, 13 insertions(+) create mode 100644 common/low_pass_filter.c create mode 100644 include/low_pass_filter.h diff --git a/common/low_pass_filter.c b/common/low_pass_filter.c new file mode 100644 index 00000000..b1b8a444 --- /dev/null +++ b/common/low_pass_filter.c @@ -0,0 +1,5 @@ +#include "low_pass_filter.h" + +status_t low_pass_filter_init(void){ + return W_FAILURE; +} diff --git a/include/low_pass_filter.h b/include/low_pass_filter.h new file mode 100644 index 00000000..23d857a3 --- /dev/null +++ b/include/low_pass_filter.h @@ -0,0 +1,8 @@ +#ifndef ROCKETLIB_LOW_PASS_FILTER_H +#define ROCKETLIB_LOW_PASS_FILTER_H + +#include "common.h" + +status_t low_pass_filter_init(void); + +#endif From 470e8287c5196be847e406095c1d79506541e9a5 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Sun, 6 Oct 2024 10:56:43 -0400 Subject: [PATCH 006/108] clang-format low_pass_filter.c --- common/low_pass_filter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/low_pass_filter.c b/common/low_pass_filter.c index b1b8a444..46b29814 100644 --- a/common/low_pass_filter.c +++ b/common/low_pass_filter.c @@ -1,5 +1,5 @@ #include "low_pass_filter.h" -status_t low_pass_filter_init(void){ - return W_FAILURE; +status_t low_pass_filter_init(void) { + return W_FAILURE; } From a4731cad0c2be2c889b82ca6bf3164ab23181f73 Mon Sep 17 00:00:00 2001 From: taisirhassan Date: Wed, 16 Oct 2024 15:42:40 -0400 Subject: [PATCH 007/108] Finished porting over low pass filter logic --- common/low_pass_filter.c | 19 +++++++++++++++++-- include/low_pass_filter.h | 9 +++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/common/low_pass_filter.c b/common/low_pass_filter.c index 46b29814..2ea08d22 100644 --- a/common/low_pass_filter.c +++ b/common/low_pass_filter.c @@ -1,5 +1,20 @@ #include "low_pass_filter.h" -status_t low_pass_filter_init(void) { - return W_FAILURE; +static volatile double alpha_low; + +status_t low_pass_filter_init(double response_time) { + if (response_time <= 0) { + return W_FAILURE; + } + alpha_low = LOW_PASS_ALPHA(response_time); + return W_SUCCESS; +} + +uint16_t update_low_pass(uint16_t new_value, double *low_pass_value) { + if (low_pass_value == NULL) { + return 0; + } + + *low_pass_value = alpha_low * (*low_pass_value) + (1.0 - alpha_low) * new_value; + return (uint16_t)(*low_pass_value); } diff --git a/include/low_pass_filter.h b/include/low_pass_filter.h index 23d857a3..24c3eec2 100644 --- a/include/low_pass_filter.h +++ b/include/low_pass_filter.h @@ -2,7 +2,12 @@ #define ROCKETLIB_LOW_PASS_FILTER_H #include "common.h" +#include -status_t low_pass_filter_init(void); +#define SAMPLE_FREQ(time_diff_ms) (1000.0 / (time_diff_ms)) +#define LOW_PASS_ALPHA(TR) ((SAMPLE_FREQ * TR / 5.0) / (1 + SAMPLE_FREQ * TR / 5.0)) -#endif +status_t low_pass_filter_init(double response_time); +uint16_t update_low_pass(uint16_t new_value, double *low_pass_value); + +#endif /* ROCKETLIB_LOW_PASS_FILTER_H */ From 0a65caa3c953c14566088c26d42e4f460e79d2b9 Mon Sep 17 00:00:00 2001 From: taisirhassan Date: Wed, 16 Oct 2024 20:12:30 -0400 Subject: [PATCH 008/108] Added comments and made alpha_low a pointer in order to allow multiple low pass filters to be initialized --- common/low_pass_filter.c | 27 ++++++++++++++------------- include/low_pass_filter.h | 12 +++++++++--- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/common/low_pass_filter.c b/common/low_pass_filter.c index 2ea08d22..df15ffbc 100644 --- a/common/low_pass_filter.c +++ b/common/low_pass_filter.c @@ -1,20 +1,21 @@ #include "low_pass_filter.h" -static volatile double alpha_low; - -status_t low_pass_filter_init(double response_time) { - if (response_time <= 0) { - return W_FAILURE; +// Initialize the low-pass filter +status_t low_pass_filter_init(double *alpha, double response_time) { + if (alpha == NULL || response_time <= 0) { + return W_FAILURE; // Return failure if the response time is invalid or alpha is NULL } - alpha_low = LOW_PASS_ALPHA(response_time); - return W_SUCCESS; + *alpha = LOW_PASS_ALPHA(response_time); // Calculate and store the alpha value + return W_SUCCESS; // Return success } -uint16_t update_low_pass(uint16_t new_value, double *low_pass_value) { - if (low_pass_value == NULL) { - return 0; +// Update the low-pass filter with a new value +uint16_t update_low_pass(double *alpha, uint16_t new_value, double *low_pass_value) { + if (alpha == NULL || low_pass_value == NULL) { + return 0; // Return 0 if alpha or low_pass_value is NULL } - *low_pass_value = alpha_low * (*low_pass_value) + (1.0 - alpha_low) * new_value; - return (uint16_t)(*low_pass_value); -} + // Update the low-pass filter value + *low_pass_value = *alpha * (*low_pass_value) + (1.0 - *alpha) * new_value; + return (uint16_t)(*low_pass_value); // Return the updated low-pass filter value +} \ No newline at end of file diff --git a/include/low_pass_filter.h b/include/low_pass_filter.h index 24c3eec2..01a4ad2d 100644 --- a/include/low_pass_filter.h +++ b/include/low_pass_filter.h @@ -4,10 +4,16 @@ #include "common.h" #include +// Macro to calculate the sample frequency based on the time difference in milliseconds #define SAMPLE_FREQ(time_diff_ms) (1000.0 / (time_diff_ms)) + +// Macro to calculate the alpha value for the low-pass filter based on the response time #define LOW_PASS_ALPHA(TR) ((SAMPLE_FREQ * TR / 5.0) / (1 + SAMPLE_FREQ * TR / 5.0)) -status_t low_pass_filter_init(double response_time); -uint16_t update_low_pass(uint16_t new_value, double *low_pass_value); +// Initializes the low-pass filter by calculating the alpha value based on the response time +status_t low_pass_filter_init(double *alpha, double response_time); + +// Updates the low-pass filter with a new value and returns the updated filter value +uint16_t update_low_pass(double *alpha, uint16_t new_value, double *low_pass_value); -#endif /* ROCKETLIB_LOW_PASS_FILTER_H */ +#endif /* ROCKETLIB_LOW_PASS_FILTER_H */ \ No newline at end of file From 39975ec8a2daac7c29aabf9000ccf3fc16eadf1c Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Sat, 19 Oct 2024 16:25:31 -0400 Subject: [PATCH 009/108] Rename error code enum to w_status_t --- include/common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/common.h b/include/common.h index 5149983f..ea98a0e4 100644 --- a/include/common.h +++ b/include/common.h @@ -4,6 +4,6 @@ typedef enum { W_SUCCESS = 0, W_FAILURE -} status_t; +} w_status_t; #endif From 65fad361f700709abb8e96a6e50d946bc66393dd Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Mon, 21 Oct 2024 10:51:11 -0400 Subject: [PATCH 010/108] Add rocketlib assert function --- common/low_pass_filter.c | 2 +- include/common.h | 15 +++++++++++++++ include/low_pass_filter.h | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/common/low_pass_filter.c b/common/low_pass_filter.c index 46b29814..5d029194 100644 --- a/common/low_pass_filter.c +++ b/common/low_pass_filter.c @@ -1,5 +1,5 @@ #include "low_pass_filter.h" -status_t low_pass_filter_init(void) { +w_status_t low_pass_filter_init(void) { return W_FAILURE; } diff --git a/include/common.h b/include/common.h index ea98a0e4..24a9266d 100644 --- a/include/common.h +++ b/include/common.h @@ -6,4 +6,19 @@ typedef enum { W_FAILURE } w_status_t; +void w_assert_fail(const char *file, int line, const char *statement); + +#ifdef W_DEBUG + +#define w_assert(statement) \ + if (!(statement)) { \ + w_assert_fail(__FILE__, __LINE__, #statement); \ + } + +#else + +#define w_assert(statement) + +#endif + #endif diff --git a/include/low_pass_filter.h b/include/low_pass_filter.h index 23d857a3..652f6575 100644 --- a/include/low_pass_filter.h +++ b/include/low_pass_filter.h @@ -3,6 +3,6 @@ #include "common.h" -status_t low_pass_filter_init(void); +w_status_t low_pass_filter_init(void); #endif From 3217f7f2bdcd2efd92e06cd7f40a30be01b4414c Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Fri, 25 Oct 2024 14:59:13 -0400 Subject: [PATCH 011/108] Add error code for different error types --- include/common.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/common.h b/include/common.h index 24a9266d..6255d262 100644 --- a/include/common.h +++ b/include/common.h @@ -3,7 +3,12 @@ typedef enum { W_SUCCESS = 0, - W_FAILURE + W_FAILURE, + W_INVALID_PARAM, + W_IO_ERROR, + W_IO_TIMEOUT, + W_MATH_ERROR, + W_OVERFLOW } w_status_t; void w_assert_fail(const char *file, int line, const char *statement); From b9176a7ce098d38bae9badf80dd3eff4aa5b8698 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Thu, 26 Sep 2024 22:15:08 -0400 Subject: [PATCH 012/108] Update clang-format config on 2D array initialize block --- .clang-format | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.clang-format b/.clang-format index d8c9cf3f..aaaaa3d2 100644 --- a/.clang-format +++ b/.clang-format @@ -1,7 +1,7 @@ -# Waterloo Rocketry Configuration file for clang-format 19 +# Waterloo Rocketry Configuration file for clang-format 19 V2 --- AccessModifierOffset: -4 -AlignAfterOpenBracket: Align +AlignAfterOpenBracket: BlockIndent AlignArrayOfStructures: None AlignConsecutiveAssignments: Enabled: false From 2dd3d88b18d95d3779f48e2b4b4799e88f84c43f Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Sat, 19 Oct 2024 16:25:31 -0400 Subject: [PATCH 013/108] Rename error code enum to w_status_t --- include/common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/common.h b/include/common.h index 5149983f..ea98a0e4 100644 --- a/include/common.h +++ b/include/common.h @@ -4,6 +4,6 @@ typedef enum { W_SUCCESS = 0, W_FAILURE -} status_t; +} w_status_t; #endif From 7faa919422ddfaac4c99163a01f57a5b92b436f3 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Mon, 21 Oct 2024 10:51:11 -0400 Subject: [PATCH 014/108] Add rocketlib assert function --- common/low_pass_filter.c | 3 +-- include/common.h | 15 +++++++++++++++ include/low_pass_filter.h | 13 +------------ 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/common/low_pass_filter.c b/common/low_pass_filter.c index df15ffbc..f08ee679 100644 --- a/common/low_pass_filter.c +++ b/common/low_pass_filter.c @@ -1,14 +1,13 @@ #include "low_pass_filter.h" // Initialize the low-pass filter -status_t low_pass_filter_init(double *alpha, double response_time) { +w_status_t low_pass_filter_init(double *alpha, double response_time) { if (alpha == NULL || response_time <= 0) { return W_FAILURE; // Return failure if the response time is invalid or alpha is NULL } *alpha = LOW_PASS_ALPHA(response_time); // Calculate and store the alpha value return W_SUCCESS; // Return success } - // Update the low-pass filter with a new value uint16_t update_low_pass(double *alpha, uint16_t new_value, double *low_pass_value) { if (alpha == NULL || low_pass_value == NULL) { diff --git a/include/common.h b/include/common.h index ea98a0e4..24a9266d 100644 --- a/include/common.h +++ b/include/common.h @@ -6,4 +6,19 @@ typedef enum { W_FAILURE } w_status_t; +void w_assert_fail(const char *file, int line, const char *statement); + +#ifdef W_DEBUG + +#define w_assert(statement) \ + if (!(statement)) { \ + w_assert_fail(__FILE__, __LINE__, #statement); \ + } + +#else + +#define w_assert(statement) + +#endif + #endif diff --git a/include/low_pass_filter.h b/include/low_pass_filter.h index 01a4ad2d..7e4e3aad 100644 --- a/include/low_pass_filter.h +++ b/include/low_pass_filter.h @@ -2,18 +2,7 @@ #define ROCKETLIB_LOW_PASS_FILTER_H #include "common.h" -#include -// Macro to calculate the sample frequency based on the time difference in milliseconds -#define SAMPLE_FREQ(time_diff_ms) (1000.0 / (time_diff_ms)) - -// Macro to calculate the alpha value for the low-pass filter based on the response time -#define LOW_PASS_ALPHA(TR) ((SAMPLE_FREQ * TR / 5.0) / (1 + SAMPLE_FREQ * TR / 5.0)) - -// Initializes the low-pass filter by calculating the alpha value based on the response time -status_t low_pass_filter_init(double *alpha, double response_time); - -// Updates the low-pass filter with a new value and returns the updated filter value -uint16_t update_low_pass(double *alpha, uint16_t new_value, double *low_pass_value); +w_status_t low_pass_filter_init(void); #endif /* ROCKETLIB_LOW_PASS_FILTER_H */ \ No newline at end of file From 115cb728a7bbbdbe81fd0fc16057b8f0d00b81af Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Fri, 25 Oct 2024 14:59:13 -0400 Subject: [PATCH 015/108] Add error code for different error types --- include/common.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/common.h b/include/common.h index 24a9266d..6255d262 100644 --- a/include/common.h +++ b/include/common.h @@ -3,7 +3,12 @@ typedef enum { W_SUCCESS = 0, - W_FAILURE + W_FAILURE, + W_INVALID_PARAM, + W_IO_ERROR, + W_IO_TIMEOUT, + W_MATH_ERROR, + W_OVERFLOW } w_status_t; void w_assert_fail(const char *file, int line, const char *statement); From a31defbff1009a93fdc59d494cf6c3b816a5ec53 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Thu, 26 Sep 2024 22:15:08 -0400 Subject: [PATCH 016/108] Update clang-format config on 2D array initialize block --- .clang-format | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.clang-format b/.clang-format index d8c9cf3f..aaaaa3d2 100644 --- a/.clang-format +++ b/.clang-format @@ -1,7 +1,7 @@ -# Waterloo Rocketry Configuration file for clang-format 19 +# Waterloo Rocketry Configuration file for clang-format 19 V2 --- AccessModifierOffset: -4 -AlignAfterOpenBracket: Align +AlignAfterOpenBracket: BlockIndent AlignArrayOfStructures: None AlignConsecutiveAssignments: Enabled: false From 869f95e49472cb81cab9ed701339c1ddfcddfe1f Mon Sep 17 00:00:00 2001 From: taisirhassan Date: Wed, 16 Oct 2024 15:42:40 -0400 Subject: [PATCH 017/108] Finished porting over low pass filter logic --- include/low_pass_filter.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/include/low_pass_filter.h b/include/low_pass_filter.h index 7e4e3aad..b45e6854 100644 --- a/include/low_pass_filter.h +++ b/include/low_pass_filter.h @@ -2,7 +2,12 @@ #define ROCKETLIB_LOW_PASS_FILTER_H #include "common.h" +#include -w_status_t low_pass_filter_init(void); +#define SAMPLE_FREQ(time_diff_ms) (1000.0 / (time_diff_ms)) +#define LOW_PASS_ALPHA(TR) ((SAMPLE_FREQ * TR / 5.0) / (1 + SAMPLE_FREQ * TR / 5.0)) -#endif /* ROCKETLIB_LOW_PASS_FILTER_H */ \ No newline at end of file +w_status_t low_pass_filter_init(double response_time); +uint16_t update_low_pass(uint16_t new_value, double *low_pass_value); + +#endif /* ROCKETLIB_LOW_PASS_FILTER_H */ From 9b7988282aeb01561e80acb2a92a1bcc6e1364a5 Mon Sep 17 00:00:00 2001 From: taisirhassan Date: Wed, 16 Oct 2024 20:12:30 -0400 Subject: [PATCH 018/108] Added comments and made alpha_low a pointer in order to allow multiple low pass filters to be initialized --- include/low_pass_filter.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/include/low_pass_filter.h b/include/low_pass_filter.h index b45e6854..ad9ba2c4 100644 --- a/include/low_pass_filter.h +++ b/include/low_pass_filter.h @@ -4,10 +4,16 @@ #include "common.h" #include +// Macro to calculate the sample frequency based on the time difference in milliseconds #define SAMPLE_FREQ(time_diff_ms) (1000.0 / (time_diff_ms)) + +// Macro to calculate the alpha value for the low-pass filter based on the response time #define LOW_PASS_ALPHA(TR) ((SAMPLE_FREQ * TR / 5.0) / (1 + SAMPLE_FREQ * TR / 5.0)) -w_status_t low_pass_filter_init(double response_time); -uint16_t update_low_pass(uint16_t new_value, double *low_pass_value); +// Initializes the low-pass filter by calculating the alpha value based on the response time +w_status_t low_pass_filter_init(double *alpha, double response_time); + +// Updates the low-pass filter with a new value and returns the updated filter value +uint16_t update_low_pass(double *alpha, uint16_t new_value, double *low_pass_value); -#endif /* ROCKETLIB_LOW_PASS_FILTER_H */ +#endif /* ROCKETLIB_LOW_PASS_FILTER_H */ \ No newline at end of file From d7ea122d2960682c1a7253cd4edf2b793242dcfa Mon Sep 17 00:00:00 2001 From: taisirhassan Date: Wed, 16 Oct 2024 15:42:40 -0400 Subject: [PATCH 019/108] Finished porting over low pass filter logic --- include/low_pass_filter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/low_pass_filter.h b/include/low_pass_filter.h index ad9ba2c4..64fe78a5 100644 --- a/include/low_pass_filter.h +++ b/include/low_pass_filter.h @@ -16,4 +16,4 @@ w_status_t low_pass_filter_init(double *alpha, double response_time); // Updates the low-pass filter with a new value and returns the updated filter value uint16_t update_low_pass(double *alpha, uint16_t new_value, double *low_pass_value); -#endif /* ROCKETLIB_LOW_PASS_FILTER_H */ \ No newline at end of file +#endif /* ROCKETLIB_LOW_PASS_FILTER_H */ From 0ee279e7f0c6ea19d4e90ee2be24ebe71d1f1724 Mon Sep 17 00:00:00 2001 From: taisirhassan Date: Wed, 16 Oct 2024 20:12:30 -0400 Subject: [PATCH 020/108] Added comments and made alpha_low a pointer in order to allow multiple low pass filters to be initialized --- include/low_pass_filter.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/low_pass_filter.h b/include/low_pass_filter.h index 64fe78a5..b0252c60 100644 --- a/include/low_pass_filter.h +++ b/include/low_pass_filter.h @@ -16,4 +16,7 @@ w_status_t low_pass_filter_init(double *alpha, double response_time); // Updates the low-pass filter with a new value and returns the updated filter value uint16_t update_low_pass(double *alpha, uint16_t new_value, double *low_pass_value); -#endif /* ROCKETLIB_LOW_PASS_FILTER_H */ +// Updates the low-pass filter with a new value and returns the updated filter value +uint16_t update_low_pass(double *alpha, uint16_t new_value, double *low_pass_value); + +#endif /* ROCKETLIB_LOW_PASS_FILTER_H */ \ No newline at end of file From decca85c2b22f554c8261a8d3e42cdcf1c23da7a Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Mon, 21 Oct 2024 10:51:11 -0400 Subject: [PATCH 021/108] Add rocketlib assert function --- include/low_pass_filter.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/low_pass_filter.h b/include/low_pass_filter.h index b0252c60..26524550 100644 --- a/include/low_pass_filter.h +++ b/include/low_pass_filter.h @@ -2,7 +2,6 @@ #define ROCKETLIB_LOW_PASS_FILTER_H #include "common.h" -#include // Macro to calculate the sample frequency based on the time difference in milliseconds #define SAMPLE_FREQ(time_diff_ms) (1000.0 / (time_diff_ms)) From fe9677293a7b1cb40a677eedcbdfd8b2d3071515 Mon Sep 17 00:00:00 2001 From: taisirhassan Date: Tue, 29 Oct 2024 13:22:49 -0400 Subject: [PATCH 022/108] fixed some issues with redefining function twice --- common/low_pass_filter.c | 2 -- include/low_pass_filter.h | 4 +--- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/common/low_pass_filter.c b/common/low_pass_filter.c index 01a33483..f08ee679 100644 --- a/common/low_pass_filter.c +++ b/common/low_pass_filter.c @@ -1,6 +1,5 @@ #include "low_pass_filter.h" - // Initialize the low-pass filter w_status_t low_pass_filter_init(double *alpha, double response_time) { if (alpha == NULL || response_time <= 0) { @@ -8,7 +7,6 @@ w_status_t low_pass_filter_init(double *alpha, double response_time) { } *alpha = LOW_PASS_ALPHA(response_time); // Calculate and store the alpha value return W_SUCCESS; // Return success - } // Update the low-pass filter with a new value uint16_t update_low_pass(double *alpha, uint16_t new_value, double *low_pass_value) { diff --git a/include/low_pass_filter.h b/include/low_pass_filter.h index 26524550..1d471966 100644 --- a/include/low_pass_filter.h +++ b/include/low_pass_filter.h @@ -2,6 +2,7 @@ #define ROCKETLIB_LOW_PASS_FILTER_H #include "common.h" +#include "stdint.h" // Macro to calculate the sample frequency based on the time difference in milliseconds #define SAMPLE_FREQ(time_diff_ms) (1000.0 / (time_diff_ms)) @@ -15,7 +16,4 @@ w_status_t low_pass_filter_init(double *alpha, double response_time); // Updates the low-pass filter with a new value and returns the updated filter value uint16_t update_low_pass(double *alpha, uint16_t new_value, double *low_pass_value); -// Updates the low-pass filter with a new value and returns the updated filter value -uint16_t update_low_pass(double *alpha, uint16_t new_value, double *low_pass_value); - #endif /* ROCKETLIB_LOW_PASS_FILTER_H */ \ No newline at end of file From 355a4737a2f5d8eab10580c9accdf1949ad9671f Mon Sep 17 00:00:00 2001 From: taisirhassan Date: Wed, 30 Oct 2024 00:01:03 -0400 Subject: [PATCH 023/108] added some comments and also fixed some errors with unit tests workflow failing --- common/low_pass_filter.c | 19 +++++++++++++------ include/low_pass_filter.h | 11 +++++++---- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/common/low_pass_filter.c b/common/low_pass_filter.c index f08ee679..192a1841 100644 --- a/common/low_pass_filter.c +++ b/common/low_pass_filter.c @@ -1,20 +1,27 @@ #include "low_pass_filter.h" +#include + +#include // Initialize the low-pass filter w_status_t low_pass_filter_init(double *alpha, double response_time) { + // Check if alpha pointer is NULL or response_time is invalid if (alpha == NULL || response_time <= 0) { - return W_FAILURE; // Return failure if the response time is invalid or alpha is NULL + return W_FAILURE; // Return failure if invalid parameters } - *alpha = LOW_PASS_ALPHA(response_time); // Calculate and store the alpha value - return W_SUCCESS; // Return success + // Calculate and store the alpha value using the LOW_PASS_ALPHA macro + *alpha = LOW_PASS_ALPHA(response_time, response_time); + return W_SUCCESS; // Return success after initialization } + // Update the low-pass filter with a new value uint16_t update_low_pass(double *alpha, uint16_t new_value, double *low_pass_value) { + // Check if alpha or low_pass_value pointers are NULL if (alpha == NULL || low_pass_value == NULL) { - return 0; // Return 0 if alpha or low_pass_value is NULL + return 0; // Return 0 if invalid pointers } - // Update the low-pass filter value - *low_pass_value = *alpha * (*low_pass_value) + (1.0 - *alpha) * new_value; + // Update the low-pass filter value using the alpha parameter + *low_pass_value = (*alpha * (*low_pass_value)) + ((1.0 - *alpha) * new_value); return (uint16_t)(*low_pass_value); // Return the updated low-pass filter value } \ No newline at end of file diff --git a/include/low_pass_filter.h b/include/low_pass_filter.h index 1d471966..c8e2bcb7 100644 --- a/include/low_pass_filter.h +++ b/include/low_pass_filter.h @@ -2,18 +2,21 @@ #define ROCKETLIB_LOW_PASS_FILTER_H #include "common.h" -#include "stdint.h" +#include // Macro to calculate the sample frequency based on the time difference in milliseconds #define SAMPLE_FREQ(time_diff_ms) (1000.0 / (time_diff_ms)) // Macro to calculate the alpha value for the low-pass filter based on the response time -#define LOW_PASS_ALPHA(TR) ((SAMPLE_FREQ * TR / 5.0) / (1 + SAMPLE_FREQ * TR / 5.0)) +#define LOW_PASS_ALPHA(TR, time_diff_ms) \ + ((SAMPLE_FREQ(time_diff_ms) * TR / 5.0) / (1 + SAMPLE_FREQ(time_diff_ms) * TR / 5.0)) -// Initializes the low-pass filter by calculating the alpha value based on the response time +// Function prototype to initialize the low-pass filter +// Calculates and stores the alpha value based on the given response time w_status_t low_pass_filter_init(double *alpha, double response_time); -// Updates the low-pass filter with a new value and returns the updated filter value +// Function prototype to update the low-pass filter with a new value +// Updates the current filtered value and returns the updated filter value uint16_t update_low_pass(double *alpha, uint16_t new_value, double *low_pass_value); #endif /* ROCKETLIB_LOW_PASS_FILTER_H */ \ No newline at end of file From f4054720af98c87b36dc0454f1ef7c25f25e8fef Mon Sep 17 00:00:00 2001 From: taisirhassan Date: Sun, 3 Nov 2024 14:17:49 -0500 Subject: [PATCH 024/108] Refactored low pass filter functions to improve error handling and return types --- common/low_pass_filter.c | 8 ++++---- include/low_pass_filter.h | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/common/low_pass_filter.c b/common/low_pass_filter.c index 192a1841..45491167 100644 --- a/common/low_pass_filter.c +++ b/common/low_pass_filter.c @@ -7,7 +7,7 @@ w_status_t low_pass_filter_init(double *alpha, double response_time) { // Check if alpha pointer is NULL or response_time is invalid if (alpha == NULL || response_time <= 0) { - return W_FAILURE; // Return failure if invalid parameters + return W_INVALID_PARAM; // Return specific error for invalid parameters } // Calculate and store the alpha value using the LOW_PASS_ALPHA macro *alpha = LOW_PASS_ALPHA(response_time, response_time); @@ -15,13 +15,13 @@ w_status_t low_pass_filter_init(double *alpha, double response_time) { } // Update the low-pass filter with a new value -uint16_t update_low_pass(double *alpha, uint16_t new_value, double *low_pass_value) { +bool update_low_pass(double *alpha, uint16_t new_value, double *low_pass_value) { // Check if alpha or low_pass_value pointers are NULL if (alpha == NULL || low_pass_value == NULL) { - return 0; // Return 0 if invalid pointers + return false; // Return false if invalid pointers } // Update the low-pass filter value using the alpha parameter *low_pass_value = (*alpha * (*low_pass_value)) + ((1.0 - *alpha) * new_value); - return (uint16_t)(*low_pass_value); // Return the updated low-pass filter value + return true; // Return true after successful update } \ No newline at end of file diff --git a/include/low_pass_filter.h b/include/low_pass_filter.h index c8e2bcb7..cf060776 100644 --- a/include/low_pass_filter.h +++ b/include/low_pass_filter.h @@ -2,7 +2,7 @@ #define ROCKETLIB_LOW_PASS_FILTER_H #include "common.h" -#include +#include // Macro to calculate the sample frequency based on the time difference in milliseconds #define SAMPLE_FREQ(time_diff_ms) (1000.0 / (time_diff_ms)) @@ -16,7 +16,7 @@ w_status_t low_pass_filter_init(double *alpha, double response_time); // Function prototype to update the low-pass filter with a new value -// Updates the current filtered value and returns the updated filter value -uint16_t update_low_pass(double *alpha, uint16_t new_value, double *low_pass_value); +// Updates the current filtered value and returns success status +bool update_low_pass(double *alpha, uint16_t new_value, double *low_pass_value); #endif /* ROCKETLIB_LOW_PASS_FILTER_H */ \ No newline at end of file From 32b3aebd07ca5b651aaf6f610a7a01101c961658 Mon Sep 17 00:00:00 2001 From: taisirhassan Date: Sun, 3 Nov 2024 14:36:10 -0500 Subject: [PATCH 025/108] Fixed errors with sphinx not compiling properly --- include/low_pass_filter.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/low_pass_filter.h b/include/low_pass_filter.h index cf060776..a8ff4874 100644 --- a/include/low_pass_filter.h +++ b/include/low_pass_filter.h @@ -3,6 +3,7 @@ #include "common.h" #include +#include // Macro to calculate the sample frequency based on the time difference in milliseconds #define SAMPLE_FREQ(time_diff_ms) (1000.0 / (time_diff_ms)) From 2d1793180c913832fee73db8847648551ad1eef3 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Mon, 21 Oct 2024 10:51:11 -0400 Subject: [PATCH 026/108] Add rocketlib assert function --- common/low_pass_filter.c | 2 -- include/low_pass_filter.h | 15 +-------------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/common/low_pass_filter.c b/common/low_pass_filter.c index 45491167..a3b5b3a3 100644 --- a/common/low_pass_filter.c +++ b/common/low_pass_filter.c @@ -5,7 +5,6 @@ // Initialize the low-pass filter w_status_t low_pass_filter_init(double *alpha, double response_time) { - // Check if alpha pointer is NULL or response_time is invalid if (alpha == NULL || response_time <= 0) { return W_INVALID_PARAM; // Return specific error for invalid parameters } @@ -13,7 +12,6 @@ w_status_t low_pass_filter_init(double *alpha, double response_time) { *alpha = LOW_PASS_ALPHA(response_time, response_time); return W_SUCCESS; // Return success after initialization } - // Update the low-pass filter with a new value bool update_low_pass(double *alpha, uint16_t new_value, double *low_pass_value) { // Check if alpha or low_pass_value pointers are NULL diff --git a/include/low_pass_filter.h b/include/low_pass_filter.h index a8ff4874..a7473905 100644 --- a/include/low_pass_filter.h +++ b/include/low_pass_filter.h @@ -5,19 +5,6 @@ #include #include -// Macro to calculate the sample frequency based on the time difference in milliseconds -#define SAMPLE_FREQ(time_diff_ms) (1000.0 / (time_diff_ms)) - -// Macro to calculate the alpha value for the low-pass filter based on the response time -#define LOW_PASS_ALPHA(TR, time_diff_ms) \ - ((SAMPLE_FREQ(time_diff_ms) * TR / 5.0) / (1 + SAMPLE_FREQ(time_diff_ms) * TR / 5.0)) - -// Function prototype to initialize the low-pass filter -// Calculates and stores the alpha value based on the given response time -w_status_t low_pass_filter_init(double *alpha, double response_time); - -// Function prototype to update the low-pass filter with a new value -// Updates the current filtered value and returns success status -bool update_low_pass(double *alpha, uint16_t new_value, double *low_pass_value); +w_status_t low_pass_filter_init(void); #endif /* ROCKETLIB_LOW_PASS_FILTER_H */ \ No newline at end of file From a5c731984b57cca72a11da678d220c5f6d4fd0dc Mon Sep 17 00:00:00 2001 From: taisirhassan Date: Tue, 29 Oct 2024 13:22:49 -0400 Subject: [PATCH 027/108] fixed some issues with redefining function twice --- include/low_pass_filter.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/include/low_pass_filter.h b/include/low_pass_filter.h index a7473905..1d471966 100644 --- a/include/low_pass_filter.h +++ b/include/low_pass_filter.h @@ -2,9 +2,18 @@ #define ROCKETLIB_LOW_PASS_FILTER_H #include "common.h" -#include -#include +#include "stdint.h" -w_status_t low_pass_filter_init(void); +// Macro to calculate the sample frequency based on the time difference in milliseconds +#define SAMPLE_FREQ(time_diff_ms) (1000.0 / (time_diff_ms)) + +// Macro to calculate the alpha value for the low-pass filter based on the response time +#define LOW_PASS_ALPHA(TR) ((SAMPLE_FREQ * TR / 5.0) / (1 + SAMPLE_FREQ * TR / 5.0)) + +// Initializes the low-pass filter by calculating the alpha value based on the response time +w_status_t low_pass_filter_init(double *alpha, double response_time); + +// Updates the low-pass filter with a new value and returns the updated filter value +uint16_t update_low_pass(double *alpha, uint16_t new_value, double *low_pass_value); #endif /* ROCKETLIB_LOW_PASS_FILTER_H */ \ No newline at end of file From 4d508bd3019f04bcd7afdb435dc59bd8f6a12329 Mon Sep 17 00:00:00 2001 From: taisirhassan Date: Sun, 3 Nov 2024 16:14:32 -0500 Subject: [PATCH 028/108] Changed update function to return w_status_t instead of a bool; Updated documentation to reflect this change --- common/low_pass_filter.c | 7 ++++--- include/low_pass_filter.h | 10 ++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/common/low_pass_filter.c b/common/low_pass_filter.c index a3b5b3a3..7b56d806 100644 --- a/common/low_pass_filter.c +++ b/common/low_pass_filter.c @@ -12,14 +12,15 @@ w_status_t low_pass_filter_init(double *alpha, double response_time) { *alpha = LOW_PASS_ALPHA(response_time, response_time); return W_SUCCESS; // Return success after initialization } + // Update the low-pass filter with a new value -bool update_low_pass(double *alpha, uint16_t new_value, double *low_pass_value) { +w_status_t update_low_pass(double *alpha, uint16_t new_value, double *low_pass_value) { // Check if alpha or low_pass_value pointers are NULL if (alpha == NULL || low_pass_value == NULL) { - return false; // Return false if invalid pointers + return W_INVALID_PARAM; // Return specific error for invalid parameters } // Update the low-pass filter value using the alpha parameter *low_pass_value = (*alpha * (*low_pass_value)) + ((1.0 - *alpha) * new_value); - return true; // Return true after successful update + return W_SUCCESS; // Return success after successful update } \ No newline at end of file diff --git a/include/low_pass_filter.h b/include/low_pass_filter.h index 1d471966..360c3823 100644 --- a/include/low_pass_filter.h +++ b/include/low_pass_filter.h @@ -2,18 +2,20 @@ #define ROCKETLIB_LOW_PASS_FILTER_H #include "common.h" -#include "stdint.h" +#include +#include // Macro to calculate the sample frequency based on the time difference in milliseconds #define SAMPLE_FREQ(time_diff_ms) (1000.0 / (time_diff_ms)) // Macro to calculate the alpha value for the low-pass filter based on the response time -#define LOW_PASS_ALPHA(TR) ((SAMPLE_FREQ * TR / 5.0) / (1 + SAMPLE_FREQ * TR / 5.0)) +#define LOW_PASS_ALPHA(TR, time_diff_ms) \ + ((SAMPLE_FREQ(time_diff_ms) * TR / 5.0) / (1 + SAMPLE_FREQ(time_diff_ms) * TR / 5.0)) // Initializes the low-pass filter by calculating the alpha value based on the response time w_status_t low_pass_filter_init(double *alpha, double response_time); -// Updates the low-pass filter with a new value and returns the updated filter value -uint16_t update_low_pass(double *alpha, uint16_t new_value, double *low_pass_value); +// Updates the low-pass filter with a new value and returns the operation status +w_status_t update_low_pass(double *alpha, uint16_t new_value, double *low_pass_value); #endif /* ROCKETLIB_LOW_PASS_FILTER_H */ \ No newline at end of file From 4ab20bcae65f24626749dfb61bfe740991035d75 Mon Sep 17 00:00:00 2001 From: taisirhassan Date: Tue, 5 Nov 2024 20:52:01 -0500 Subject: [PATCH 029/108] Added validation for alpha range and improve test output for a singular input signal to check that the low pass filter is working correctly. Added print statements as well --- common/low_pass_filter.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/common/low_pass_filter.c b/common/low_pass_filter.c index 7b56d806..5fe8f6c1 100644 --- a/common/low_pass_filter.c +++ b/common/low_pass_filter.c @@ -1,7 +1,7 @@ #include "low_pass_filter.h" #include -#include +// #include // Initialize the low-pass filter w_status_t low_pass_filter_init(double *alpha, double response_time) { @@ -20,7 +20,12 @@ w_status_t update_low_pass(double *alpha, uint16_t new_value, double *low_pass_v return W_INVALID_PARAM; // Return specific error for invalid parameters } - // Update the low-pass filter value using the alpha parameter - *low_pass_value = (*alpha * (*low_pass_value)) + ((1.0 - *alpha) * new_value); + // Ensure alpha is within the valid range + if (*alpha <= 0.0 || *alpha >= 1.0) { + return W_INVALID_PARAM; + } + + // Low pass filter formula: y[n] = alpha * x[n] + (1 - alpha) * y[n-1] + *low_pass_value = (*alpha * new_value) + ((1.0 - *alpha) * (*low_pass_value)); return W_SUCCESS; // Return success after successful update } \ No newline at end of file From 0a79f2c5e65736de301a24a96df3a8a7ea172c32 Mon Sep 17 00:00:00 2001 From: taisirhassan Date: Tue, 5 Nov 2024 20:53:51 -0500 Subject: [PATCH 030/108] forgot to uncomment xc.h library --- common/low_pass_filter.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/common/low_pass_filter.c b/common/low_pass_filter.c index 5fe8f6c1..8e15b71c 100644 --- a/common/low_pass_filter.c +++ b/common/low_pass_filter.c @@ -1,7 +1,6 @@ #include "low_pass_filter.h" #include - -// #include +#include // Initialize the low-pass filter w_status_t low_pass_filter_init(double *alpha, double response_time) { From 09d97052c7a95557d9a16cb171d05cf3d796d874 Mon Sep 17 00:00:00 2001 From: taisirhassan Date: Mon, 11 Nov 2024 14:23:15 -0500 Subject: [PATCH 031/108] seriously included a stray comma; also deleted mcu specific library --- common/low_pass_filter.c | 1 - 1 file changed, 1 deletion(-) diff --git a/common/low_pass_filter.c b/common/low_pass_filter.c index 8e15b71c..e351a52e 100644 --- a/common/low_pass_filter.c +++ b/common/low_pass_filter.c @@ -1,6 +1,5 @@ #include "low_pass_filter.h" #include -#include // Initialize the low-pass filter w_status_t low_pass_filter_init(double *alpha, double response_time) { From 9cc97e356595aed329b5b2b96704d3cdce9066c1 Mon Sep 17 00:00:00 2001 From: taisirhassan Date: Wed, 13 Nov 2024 21:55:45 -0500 Subject: [PATCH 032/108] Refactored low-pass filter implementation to replace macros with inline functions for better type safety and readability. Update documentation accordingly. --- common/low_pass_filter.c | 4 ++-- include/low_pass_filter.h | 14 +++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/common/low_pass_filter.c b/common/low_pass_filter.c index e351a52e..b8e7b210 100644 --- a/common/low_pass_filter.c +++ b/common/low_pass_filter.c @@ -6,8 +6,8 @@ w_status_t low_pass_filter_init(double *alpha, double response_time) { if (alpha == NULL || response_time <= 0) { return W_INVALID_PARAM; // Return specific error for invalid parameters } - // Calculate and store the alpha value using the LOW_PASS_ALPHA macro - *alpha = LOW_PASS_ALPHA(response_time, response_time); + // Calculate and store the alpha value using the low_pass_alpha function + *alpha = low_pass_alpha(response_time, response_time); return W_SUCCESS; // Return success after initialization } diff --git a/include/low_pass_filter.h b/include/low_pass_filter.h index 360c3823..a9a2750a 100644 --- a/include/low_pass_filter.h +++ b/include/low_pass_filter.h @@ -5,12 +5,16 @@ #include #include -// Macro to calculate the sample frequency based on the time difference in milliseconds -#define SAMPLE_FREQ(time_diff_ms) (1000.0 / (time_diff_ms)) +// Inline function to calculate the sample frequency based on the time difference in milliseconds +static inline double sample_freq(double time_diff_ms) { + return 1000.0 / time_diff_ms; +} -// Macro to calculate the alpha value for the low-pass filter based on the response time -#define LOW_PASS_ALPHA(TR, time_diff_ms) \ - ((SAMPLE_FREQ(time_diff_ms) * TR / 5.0) / (1 + SAMPLE_FREQ(time_diff_ms) * TR / 5.0)) +// Inline function to calculate the alpha value for the low-pass filter based on the response time +static inline double low_pass_alpha(double TR, double time_diff_ms) { + double freq = sample_freq(time_diff_ms); + return (freq * TR / 5.0) / (1.0 + freq * TR / 5.0); +} // Initializes the low-pass filter by calculating the alpha value based on the response time w_status_t low_pass_filter_init(double *alpha, double response_time); From 0d9ab1802830001dd7802495b461539caaa7c054 Mon Sep 17 00:00:00 2001 From: taisirhassan Date: Wed, 13 Nov 2024 23:54:06 -0500 Subject: [PATCH 033/108] Refactored low-pass filter update function to use direct alpha parameter and improve documentation. Update test cases accordingly. --- common/low_pass_filter.c | 10 +++++----- include/low_pass_filter.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/common/low_pass_filter.c b/common/low_pass_filter.c index b8e7b210..5a522184 100644 --- a/common/low_pass_filter.c +++ b/common/low_pass_filter.c @@ -12,18 +12,18 @@ w_status_t low_pass_filter_init(double *alpha, double response_time) { } // Update the low-pass filter with a new value -w_status_t update_low_pass(double *alpha, uint16_t new_value, double *low_pass_value) { - // Check if alpha or low_pass_value pointers are NULL - if (alpha == NULL || low_pass_value == NULL) { +w_status_t update_low_pass(double alpha, uint16_t new_input_value, double *low_pass_value) { + // Check if low_pass_value pointer is NULL + if (low_pass_value == NULL) { return W_INVALID_PARAM; // Return specific error for invalid parameters } // Ensure alpha is within the valid range - if (*alpha <= 0.0 || *alpha >= 1.0) { + if (alpha <= 0.0 || alpha >= 1.0) { return W_INVALID_PARAM; } // Low pass filter formula: y[n] = alpha * x[n] + (1 - alpha) * y[n-1] - *low_pass_value = (*alpha * new_value) + ((1.0 - *alpha) * (*low_pass_value)); + *low_pass_value = (alpha * new_input_value) + ((1.0 - alpha) * (*low_pass_value)); return W_SUCCESS; // Return success after successful update } \ No newline at end of file diff --git a/include/low_pass_filter.h b/include/low_pass_filter.h index a9a2750a..2f0c9aa8 100644 --- a/include/low_pass_filter.h +++ b/include/low_pass_filter.h @@ -16,10 +16,10 @@ static inline double low_pass_alpha(double TR, double time_diff_ms) { return (freq * TR / 5.0) / (1.0 + freq * TR / 5.0); } -// Initializes the low-pass filter by calculating the alpha value based on the response time +// Initializes the low-pass filter by calculating and storing the alpha value based on the given response time. w_status_t low_pass_filter_init(double *alpha, double response_time); // Updates the low-pass filter with a new value and returns the operation status -w_status_t update_low_pass(double *alpha, uint16_t new_value, double *low_pass_value); +w_status_t update_low_pass(double *alpha, uint16_t new_input_value, double *low_pass_value); #endif /* ROCKETLIB_LOW_PASS_FILTER_H */ \ No newline at end of file From 94cb089241d20b3b31bb3b6738c8f3f18447d4de Mon Sep 17 00:00:00 2001 From: taisirhassan Date: Thu, 14 Nov 2024 00:01:25 -0500 Subject: [PATCH 034/108] Forgot to update update_low_pass function calls to call alpha using pass-by-reference --- include/low_pass_filter.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/low_pass_filter.h b/include/low_pass_filter.h index 2f0c9aa8..0edca690 100644 --- a/include/low_pass_filter.h +++ b/include/low_pass_filter.h @@ -16,10 +16,11 @@ static inline double low_pass_alpha(double TR, double time_diff_ms) { return (freq * TR / 5.0) / (1.0 + freq * TR / 5.0); } -// Initializes the low-pass filter by calculating and storing the alpha value based on the given response time. +// Initializes the low-pass filter by calculating and storing the alpha value based on the given +// response time. w_status_t low_pass_filter_init(double *alpha, double response_time); // Updates the low-pass filter with a new value and returns the operation status -w_status_t update_low_pass(double *alpha, uint16_t new_input_value, double *low_pass_value); +w_status_t update_low_pass(double alpha, uint16_t new_input_value, double *low_pass_value); #endif /* ROCKETLIB_LOW_PASS_FILTER_H */ \ No newline at end of file From a2ed6a6e2a43047cebb4c137bb344185653b4780 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Fri, 25 Oct 2024 17:31:31 -0400 Subject: [PATCH 035/108] Update version number to 2025.1 --- include/common.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/common.h b/include/common.h index 6255d262..bae34572 100644 --- a/include/common.h +++ b/include/common.h @@ -1,6 +1,9 @@ #ifndef ROCKETLIB_COMMON_H #define ROCKETLIB_COMMON_H +#define ROCKETLIB_VERSION_MAJOR 2025 +#define ROCKETLIB_VERSION_MINOR 1 + typedef enum { W_SUCCESS = 0, W_FAILURE, From 8d324a7418537f5d9274c2fb24c076ffe377128b Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Fri, 25 Oct 2024 17:31:47 -0400 Subject: [PATCH 036/108] Remove PIC18F26K83 in PIC18 timer driver file --- pic18f26k83/timer.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pic18f26k83/timer.c b/pic18f26k83/timer.c index 25a3576f..ae575dee 100644 --- a/pic18f26k83/timer.c +++ b/pic18f26k83/timer.c @@ -2,10 +2,6 @@ #include "timer.h" -#ifndef _PIC18F26K83_H_ -#warning "compiling pic18f26k83 hardware specific file on a different microcontroller, WTF?" -#endif - /* * Magic numbers: timer is driven on a 500kHz clock and is 8 bits. * Timer rolls over every 256 counts, or every 512 microseconds. From 8cae1de7e04e64400c8be963df3b975d8d27afff Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Sun, 9 Mar 2025 15:07:34 -0400 Subject: [PATCH 037/108] Initial electrical constant header --- include/electrical.h | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 include/electrical.h diff --git a/include/electrical.h b/include/electrical.h new file mode 100644 index 00000000..25ca35a9 --- /dev/null +++ b/include/electrical.h @@ -0,0 +1,11 @@ +#ifndef ROCKETLIB_ELECTRICAL_H +#define ROCKETLIB_ELECTRICAL_H + +// 12V Rail Powered by 3S LiPo +#define RAIL_12V_MAX_mV 12800 +#define RAIL_12V_MIN_mV 11600 + +// INA180 Current Sense Amplifier +#define INA180A3_GAIN 100 + +#endif From 410480dc1d9a07a9f2ff8a14a5828cb6f4bf5140 Mon Sep 17 00:00:00 2001 From: Joelle Ghobrial <53483634+joelleg123@users.noreply.github.com> Date: Tue, 13 May 2025 19:45:07 -0400 Subject: [PATCH 038/108] Inital push --- common/crc8.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 common/crc8.c diff --git a/common/crc8.c b/common/crc8.c new file mode 100644 index 00000000..65399828 --- /dev/null +++ b/common/crc8.c @@ -0,0 +1,27 @@ +// crc table used for calculation +uint8_t table[256] = { + 0x00, 0x07, 0x0e, 0x09, 0x1c, 0x1b, 0x12, 0x15, 0x38, 0x3f, 0x36, 0x31, 0x24, 0x23, 0x2a, 0x2d, + 0x70, 0x77, 0x7e, 0x79, 0x6c, 0x6b, 0x62, 0x65, 0x48, 0x4f, 0x46, 0x41, 0x54, 0x53, 0x5a, 0x5d, + 0xe0, 0xe7, 0xee, 0xe9, 0xfc, 0xfb, 0xf2, 0xf5, 0xd8, 0xdf, 0xd6, 0xd1, 0xc4, 0xc3, 0xca, 0xcd, + 0x90, 0x97, 0x9e, 0x99, 0x8c, 0x8b, 0x82, 0x85, 0xa8, 0xaf, 0xa6, 0xa1, 0xb4, 0xb3, 0xba, 0xbd, + 0xc7, 0xc0, 0xc9, 0xce, 0xdb, 0xdc, 0xd5, 0xd2, 0xff, 0xf8, 0xf1, 0xf6, 0xe3, 0xe4, 0xed, 0xea, + 0xb7, 0xb0, 0xb9, 0xbe, 0xab, 0xac, 0xa5, 0xa2, 0x8f, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9d, 0x9a, + 0x27, 0x20, 0x29, 0x2e, 0x3b, 0x3c, 0x35, 0x32, 0x1f, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0d, 0x0a, + 0x57, 0x50, 0x59, 0x5e, 0x4b, 0x4c, 0x45, 0x42, 0x6f, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7d, 0x7a, + 0x89, 0x8e, 0x87, 0x80, 0x95, 0x92, 0x9b, 0x9c, 0xb1, 0xb6, 0xbf, 0xb8, 0xad, 0xaa, 0xa3, 0xa4, + 0xf9, 0xfe, 0xf7, 0xf0, 0xe5, 0xe2, 0xeb, 0xec, 0xc1, 0xc6, 0xcf, 0xc8, 0xdd, 0xda, 0xd3, 0xd4, + 0x69, 0x6e, 0x67, 0x60, 0x75, 0x72, 0x7b, 0x7c, 0x51, 0x56, 0x5f, 0x58, 0x4d, 0x4a, 0x43, 0x44, + 0x19, 0x1e, 0x17, 0x10, 0x05, 0x02, 0x0b, 0x0c, 0x21, 0x26, 0x2f, 0x28, 0x3d, 0x3a, 0x33, 0x34, + 0x4e, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5c, 0x5b, 0x76, 0x71, 0x78, 0x7f, 0x6a, 0x6d, 0x64, 0x63, + 0x3e, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2c, 0x2b, 0x06, 0x01, 0x08, 0x0f, 0x1a, 0x1d, 0x14, 0x13, + 0xae, 0xa9, 0xa0, 0xa7, 0xb2, 0xb5, 0xbc, 0xbb, 0x96, 0x91, 0x98, 0x9f, 0x8a, 0x8d, 0x84, 0x83, + 0xde, 0xd9, 0xd0, 0xd7, 0xc2, 0xc5, 0xcc, 0xcb, 0xe6, 0xe1, 0xe8, 0xef, 0xfa, 0xfd, 0xf4, 0xf3 +}; + +uint8_t crc8_checksum(uint8_t *pdata, size_t nbytes, uint8_t crc) { + while (nbytes > 0) { + crc = table[(crc ^ *pdata++) & 0xff]; + --nbytes; + } + return crc; +} From 7c400a91d27d3236f95c2ce6e59603fbf7db5842 Mon Sep 17 00:00:00 2001 From: Joelle Ghobrial <53483634+joelleg123@users.noreply.github.com> Date: Tue, 13 May 2025 20:24:53 -0400 Subject: [PATCH 039/108] Added Relevant Include Statements --- common/crc8.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/common/crc8.c b/common/crc8.c index 65399828..591a9b9d 100644 --- a/common/crc8.c +++ b/common/crc8.c @@ -1,3 +1,6 @@ +#include +#include + // crc table used for calculation uint8_t table[256] = { 0x00, 0x07, 0x0e, 0x09, 0x1c, 0x1b, 0x12, 0x15, 0x38, 0x3f, 0x36, 0x31, 0x24, 0x23, 0x2a, 0x2d, From 81b3ceb5702d7be8d6aae91a9a8c705956eb0654 Mon Sep 17 00:00:00 2001 From: Joelle Ghobrial <53483634+joelleg123@users.noreply.github.com> Date: Tue, 13 May 2025 20:28:33 -0400 Subject: [PATCH 040/108] Alphabetized include statements --- common/crc8.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/crc8.c b/common/crc8.c index 591a9b9d..7eba911c 100644 --- a/common/crc8.c +++ b/common/crc8.c @@ -1,5 +1,5 @@ -#include #include +#include // crc table used for calculation uint8_t table[256] = { From 0a2175af1e16bdcc856a777bb01d05b723efc4ae Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Tue, 17 Jun 2025 19:00:43 -0400 Subject: [PATCH 041/108] Add extern C to common.h and low_pass_filter.h --- include/common.h | 8 ++++++++ include/low_pass_filter.h | 13 +++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/include/common.h b/include/common.h index bae34572..78ab4433 100644 --- a/include/common.h +++ b/include/common.h @@ -14,8 +14,16 @@ typedef enum { W_OVERFLOW } w_status_t; +#ifdef __cplusplus +extern "C" { +#endif + void w_assert_fail(const char *file, int line, const char *statement); +#ifdef __cplusplus +} +#endif + #ifdef W_DEBUG #define w_assert(statement) \ diff --git a/include/low_pass_filter.h b/include/low_pass_filter.h index 0edca690..fd19ec86 100644 --- a/include/low_pass_filter.h +++ b/include/low_pass_filter.h @@ -1,10 +1,15 @@ #ifndef ROCKETLIB_LOW_PASS_FILTER_H #define ROCKETLIB_LOW_PASS_FILTER_H -#include "common.h" #include #include +#include "common.h" + +#ifdef __cplusplus +extern "C" { +#endif + // Inline function to calculate the sample frequency based on the time difference in milliseconds static inline double sample_freq(double time_diff_ms) { return 1000.0 / time_diff_ms; @@ -23,4 +28,8 @@ w_status_t low_pass_filter_init(double *alpha, double response_time); // Updates the low-pass filter with a new value and returns the operation status w_status_t update_low_pass(double alpha, uint16_t new_input_value, double *low_pass_value); -#endif /* ROCKETLIB_LOW_PASS_FILTER_H */ \ No newline at end of file +#ifdef __cplusplus +} +#endif + +#endif /* ROCKETLIB_LOW_PASS_FILTER_H */ From 806c44109881db2ef7abe53bc95a80c035a37652 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Tue, 17 Jun 2025 19:05:02 -0400 Subject: [PATCH 042/108] Add CRC8 header file --- common/crc8.c | 2 +- include/crc8.h | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 include/crc8.h diff --git a/common/crc8.c b/common/crc8.c index 7eba911c..ee5d69b7 100644 --- a/common/crc8.c +++ b/common/crc8.c @@ -2,7 +2,7 @@ #include // crc table used for calculation -uint8_t table[256] = { +static uint8_t table[256] = { 0x00, 0x07, 0x0e, 0x09, 0x1c, 0x1b, 0x12, 0x15, 0x38, 0x3f, 0x36, 0x31, 0x24, 0x23, 0x2a, 0x2d, 0x70, 0x77, 0x7e, 0x79, 0x6c, 0x6b, 0x62, 0x65, 0x48, 0x4f, 0x46, 0x41, 0x54, 0x53, 0x5a, 0x5d, 0xe0, 0xe7, 0xee, 0xe9, 0xfc, 0xfb, 0xf2, 0xf5, 0xd8, 0xdf, 0xd6, 0xd1, 0xc4, 0xc3, 0xca, 0xcd, diff --git a/include/crc8.h b/include/crc8.h new file mode 100644 index 00000000..0af1856c --- /dev/null +++ b/include/crc8.h @@ -0,0 +1,17 @@ +#ifndef ROCKETLIB_CRC8_H +#define ROCKETLIB_CRC8_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +uint8_t crc8_checksum(uint8_t *pdata, size_t nbytes, uint8_t crc); + +#ifdef __cplusplus +} +#endif + +#endif From 38cb1f24d62b59f70da877442c11976b4b040261 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Tue, 17 Jun 2025 19:07:53 -0400 Subject: [PATCH 043/108] Add C++ not supported --- include/timer.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/timer.h b/include/timer.h index 4ff34c58..623cd579 100644 --- a/include/timer.h +++ b/include/timer.h @@ -3,6 +3,10 @@ #include +#ifdef __cplusplus +#error "C++ is not supported" +#endif + // utilities for handling the timer used in millis() void timer0_init(void); From cc7d55b37dddf5a4f8a335440eb7b6c8649c3047 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Tue, 17 Jun 2025 19:10:38 -0400 Subject: [PATCH 044/108] Improve common.h comment --- include/common.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/common.h b/include/common.h index 78ab4433..223fc4f0 100644 --- a/include/common.h +++ b/include/common.h @@ -1,9 +1,11 @@ #ifndef ROCKETLIB_COMMON_H #define ROCKETLIB_COMMON_H +// Rocketlib Version #define ROCKETLIB_VERSION_MAJOR 2025 #define ROCKETLIB_VERSION_MINOR 1 +// Standard Error Code typedef enum { W_SUCCESS = 0, W_FAILURE, @@ -14,6 +16,7 @@ typedef enum { W_OVERFLOW } w_status_t; +// Assertion Macro #ifdef __cplusplus extern "C" { #endif From 747af475f54034ff6c7c06d58aee0a059de9656a Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Tue, 26 Aug 2025 14:35:28 -0400 Subject: [PATCH 045/108] Update clang-format configuration to version 21 --- .clang-format | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/.clang-format b/.clang-format index aaaaa3d2..69b82470 100644 --- a/.clang-format +++ b/.clang-format @@ -1,13 +1,14 @@ -# Waterloo Rocketry Configuration file for clang-format 19 V2 +# Waterloo Rocketry Configuration file for clang-format 21 --- AccessModifierOffset: -4 -AlignAfterOpenBracket: BlockIndent +AlignAfterOpenBracket: Align AlignArrayOfStructures: None AlignConsecutiveAssignments: Enabled: false AcrossEmptyLines: false AcrossComments: false AlignCompound: false + AlignFunctionDeclarations: false AlignFunctionPointers: false PadOperators: true AlignConsecutiveBitFields: @@ -15,6 +16,7 @@ AlignConsecutiveBitFields: AcrossEmptyLines: false AcrossComments: false AlignCompound: false + AlignFunctionDeclarations: false AlignFunctionPointers: false PadOperators: false AlignConsecutiveDeclarations: @@ -22,6 +24,7 @@ AlignConsecutiveDeclarations: AcrossEmptyLines: false AcrossComments: false AlignCompound: false + AlignFunctionDeclarations: true AlignFunctionPointers: false PadOperators: false AlignConsecutiveMacros: @@ -29,6 +32,7 @@ AlignConsecutiveMacros: AcrossEmptyLines: false AcrossComments: false AlignCompound: false + AlignFunctionDeclarations: false AlignFunctionPointers: false PadOperators: false AlignConsecutiveShortCaseStatements: @@ -42,6 +46,7 @@ AlignConsecutiveTableGenBreakingDAGArgColons: AcrossEmptyLines: false AcrossComments: false AlignCompound: false + AlignFunctionDeclarations: false AlignFunctionPointers: false PadOperators: false AlignConsecutiveTableGenCondOperatorColons: @@ -49,6 +54,7 @@ AlignConsecutiveTableGenCondOperatorColons: AcrossEmptyLines: false AcrossComments: false AlignCompound: false + AlignFunctionDeclarations: false AlignFunctionPointers: false PadOperators: false AlignConsecutiveTableGenDefinitionColons: @@ -56,6 +62,7 @@ AlignConsecutiveTableGenDefinitionColons: AcrossEmptyLines: false AcrossComments: false AlignCompound: false + AlignFunctionDeclarations: false AlignFunctionPointers: false PadOperators: false AlignEscapedNewlines: Right @@ -75,11 +82,14 @@ AllowShortFunctionsOnASingleLine: Empty AllowShortIfStatementsOnASingleLine: Never AllowShortLambdasOnASingleLine: All AllowShortLoopsOnASingleLine: false +AllowShortNamespacesOnASingleLine: false AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakBeforeMultilineStrings: false BinPackArguments: false -BinPackParameters: true +BinPackLongBracedList: true +BinPackParameters: BinPack BitFieldColonSpacing: Both +BracedInitializerIndentWidth: -1 BraceWrapping: AfterCaseLabel: false AfterClass: false @@ -108,7 +118,9 @@ BreakBeforeBinaryOperators: None BreakBeforeConceptDeclarations: Always BreakBeforeBraces: Attach BreakBeforeInlineASMColon: OnlyMultiline +BreakBeforeTemplateCloser: true BreakBeforeTernaryOperators: true +BreakBinaryOperations: Never BreakConstructorInitializers: BeforeColon BreakFunctionDefinitionParameters: false BreakInheritanceList: BeforeColon @@ -124,6 +136,7 @@ DerivePointerAlignment: false DisableFormat: false EmptyLineAfterAccessModifier: Never EmptyLineBeforeAccessModifier: LogicalBlock +EnumTrailingComma: Leave ExperimentalAutoDetectBinPacking: false FixNamespaceComments: true IncludeBlocks: Preserve @@ -132,6 +145,7 @@ IncludeIsMainSourceRegex: '' IndentAccessModifiers: false IndentCaseBlocks: false IndentCaseLabels: true +IndentExportBlock: true IndentExternBlock: AfterExternBlock IndentGotoLabels: true IndentPPDirectives: None @@ -154,6 +168,7 @@ KeepEmptyLines: AtEndOfFile: true AtStartOfBlock: false AtStartOfFile: true +KeepFormFeed: false LambdaBodyIndentation: Signature LineEnding: DeriveLF MacroBlockBegin: '' @@ -166,9 +181,11 @@ ObjCBlockIndentWidth: 2 ObjCBreakBeforeNestedBlockParam: true ObjCSpaceAfterProperty: false ObjCSpaceBeforeProtocolList: true +OneLineFormatOffRegex: '' PackConstructorInitializers: BinPack PenaltyBreakAssignment: 2 PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakBeforeMemberAccess: 150 PenaltyBreakComment: 300 PenaltyBreakFirstLessLess: 120 PenaltyBreakOpenParenthesis: 0 @@ -182,8 +199,9 @@ PointerAlignment: Right PPIndentWidth: -1 QualifierAlignment: Leave ReferenceAlignment: Pointer -ReflowComments: true +ReflowComments: Always RemoveBracesLLVM: false +RemoveEmptyLinesInUnwrappedLines: true RemoveParentheses: Leave RemoveSemicolon: false RequiresClausePosition: OwnLine @@ -191,11 +209,14 @@ RequiresExpressionIndentation: OuterScope SeparateDefinitionBlocks: Leave ShortNamespaceLines: 1 SkipMacroDefinitionBody: false -SortIncludes: CaseSensitive +SortIncludes: + Enabled: true + IgnoreCase: false SortJavaStaticImport: Before SortUsingDeclarations: LexicographicNumeric SpaceAfterCStyleCast: false SpaceAfterLogicalNot: false +SpaceAfterOperatorKeyword: false SpaceAfterTemplateKeyword: true SpaceAroundPointerQualifiers: Default SpaceBeforeAssignmentOperators: true @@ -211,6 +232,7 @@ SpaceBeforeParensOptions: AfterFunctionDefinitionName: false AfterFunctionDeclarationName: false AfterIfMacros: true + AfterNot: false AfterOverloadedOperator: false AfterPlacementOperator: true AfterRequiresInClause: false @@ -238,4 +260,5 @@ TableGenBreakInsideDAGArg: DontBreak TabWidth: 4 UseTab: Never VerilogBreakBetweenInstancePorts: true +WrapNamespaceBodyWithEmptyLines: Always ... From bbb07ab1a42108e74c13b7c7a6495f9f551b3b8d Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Wed, 27 Aug 2025 08:51:16 -0400 Subject: [PATCH 046/108] Update clang-format 21 options --- .clang-format | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.clang-format b/.clang-format index 69b82470..ece428e7 100644 --- a/.clang-format +++ b/.clang-format @@ -110,7 +110,7 @@ BraceWrapping: SplitEmptyRecord: true SplitEmptyNamespace: true BreakAdjacentStringLiterals: true -BreakAfterAttributes: Leave +BreakAfterAttributes: Never BreakAfterJavaFieldAnnotations: false BreakAfterReturnType: None BreakArrays: true @@ -136,7 +136,7 @@ DerivePointerAlignment: false DisableFormat: false EmptyLineAfterAccessModifier: Never EmptyLineBeforeAccessModifier: LogicalBlock -EnumTrailingComma: Leave +EnumTrailingComma: Remove ExperimentalAutoDetectBinPacking: false FixNamespaceComments: true IncludeBlocks: Preserve @@ -206,7 +206,7 @@ RemoveParentheses: Leave RemoveSemicolon: false RequiresClausePosition: OwnLine RequiresExpressionIndentation: OuterScope -SeparateDefinitionBlocks: Leave +SeparateDefinitionBlocks: Always ShortNamespaceLines: 1 SkipMacroDefinitionBody: false SortIncludes: From 19696877eede4d6a6865e4a7bd9ca507efcbe027 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Wed, 27 Aug 2025 13:54:56 -0400 Subject: [PATCH 047/108] Switch to use tabs --- .clang-format | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.clang-format b/.clang-format index ece428e7..5f4c94ce 100644 --- a/.clang-format +++ b/.clang-format @@ -1,4 +1,4 @@ -# Waterloo Rocketry Configuration file for clang-format 21 +# Configuration file for clang-format 21 --- AccessModifierOffset: -4 AlignAfterOpenBracket: Align @@ -258,7 +258,7 @@ SpacesInSquareBrackets: false Standard: Latest TableGenBreakInsideDAGArg: DontBreak TabWidth: 4 -UseTab: Never +UseTab: Always VerilogBreakBetweenInstancePorts: true WrapNamespaceBodyWithEmptyLines: Always ... From e3c33aea78a72f4bd91623de4ef497340f5e625b Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Wed, 27 Aug 2025 14:00:58 -0400 Subject: [PATCH 048/108] Clang-format all code --- common/crc8.c | 43 +++++++++++++++++++-------------------- common/low_pass_filter.c | 34 +++++++++++++++---------------- include/common.h | 20 +++++++++--------- include/low_pass_filter.h | 6 +++--- pic18f26k83/timer.c | 42 +++++++++++++++++++------------------- 5 files changed, 72 insertions(+), 73 deletions(-) diff --git a/common/crc8.c b/common/crc8.c index ee5d69b7..41131419 100644 --- a/common/crc8.c +++ b/common/crc8.c @@ -3,28 +3,27 @@ // crc table used for calculation static uint8_t table[256] = { - 0x00, 0x07, 0x0e, 0x09, 0x1c, 0x1b, 0x12, 0x15, 0x38, 0x3f, 0x36, 0x31, 0x24, 0x23, 0x2a, 0x2d, - 0x70, 0x77, 0x7e, 0x79, 0x6c, 0x6b, 0x62, 0x65, 0x48, 0x4f, 0x46, 0x41, 0x54, 0x53, 0x5a, 0x5d, - 0xe0, 0xe7, 0xee, 0xe9, 0xfc, 0xfb, 0xf2, 0xf5, 0xd8, 0xdf, 0xd6, 0xd1, 0xc4, 0xc3, 0xca, 0xcd, - 0x90, 0x97, 0x9e, 0x99, 0x8c, 0x8b, 0x82, 0x85, 0xa8, 0xaf, 0xa6, 0xa1, 0xb4, 0xb3, 0xba, 0xbd, - 0xc7, 0xc0, 0xc9, 0xce, 0xdb, 0xdc, 0xd5, 0xd2, 0xff, 0xf8, 0xf1, 0xf6, 0xe3, 0xe4, 0xed, 0xea, - 0xb7, 0xb0, 0xb9, 0xbe, 0xab, 0xac, 0xa5, 0xa2, 0x8f, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9d, 0x9a, - 0x27, 0x20, 0x29, 0x2e, 0x3b, 0x3c, 0x35, 0x32, 0x1f, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0d, 0x0a, - 0x57, 0x50, 0x59, 0x5e, 0x4b, 0x4c, 0x45, 0x42, 0x6f, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7d, 0x7a, - 0x89, 0x8e, 0x87, 0x80, 0x95, 0x92, 0x9b, 0x9c, 0xb1, 0xb6, 0xbf, 0xb8, 0xad, 0xaa, 0xa3, 0xa4, - 0xf9, 0xfe, 0xf7, 0xf0, 0xe5, 0xe2, 0xeb, 0xec, 0xc1, 0xc6, 0xcf, 0xc8, 0xdd, 0xda, 0xd3, 0xd4, - 0x69, 0x6e, 0x67, 0x60, 0x75, 0x72, 0x7b, 0x7c, 0x51, 0x56, 0x5f, 0x58, 0x4d, 0x4a, 0x43, 0x44, - 0x19, 0x1e, 0x17, 0x10, 0x05, 0x02, 0x0b, 0x0c, 0x21, 0x26, 0x2f, 0x28, 0x3d, 0x3a, 0x33, 0x34, - 0x4e, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5c, 0x5b, 0x76, 0x71, 0x78, 0x7f, 0x6a, 0x6d, 0x64, 0x63, - 0x3e, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2c, 0x2b, 0x06, 0x01, 0x08, 0x0f, 0x1a, 0x1d, 0x14, 0x13, - 0xae, 0xa9, 0xa0, 0xa7, 0xb2, 0xb5, 0xbc, 0xbb, 0x96, 0x91, 0x98, 0x9f, 0x8a, 0x8d, 0x84, 0x83, - 0xde, 0xd9, 0xd0, 0xd7, 0xc2, 0xc5, 0xcc, 0xcb, 0xe6, 0xe1, 0xe8, 0xef, 0xfa, 0xfd, 0xf4, 0xf3 -}; + 0x00, 0x07, 0x0e, 0x09, 0x1c, 0x1b, 0x12, 0x15, 0x38, 0x3f, 0x36, 0x31, 0x24, 0x23, 0x2a, 0x2d, + 0x70, 0x77, 0x7e, 0x79, 0x6c, 0x6b, 0x62, 0x65, 0x48, 0x4f, 0x46, 0x41, 0x54, 0x53, 0x5a, 0x5d, + 0xe0, 0xe7, 0xee, 0xe9, 0xfc, 0xfb, 0xf2, 0xf5, 0xd8, 0xdf, 0xd6, 0xd1, 0xc4, 0xc3, 0xca, 0xcd, + 0x90, 0x97, 0x9e, 0x99, 0x8c, 0x8b, 0x82, 0x85, 0xa8, 0xaf, 0xa6, 0xa1, 0xb4, 0xb3, 0xba, 0xbd, + 0xc7, 0xc0, 0xc9, 0xce, 0xdb, 0xdc, 0xd5, 0xd2, 0xff, 0xf8, 0xf1, 0xf6, 0xe3, 0xe4, 0xed, 0xea, + 0xb7, 0xb0, 0xb9, 0xbe, 0xab, 0xac, 0xa5, 0xa2, 0x8f, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9d, 0x9a, + 0x27, 0x20, 0x29, 0x2e, 0x3b, 0x3c, 0x35, 0x32, 0x1f, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0d, 0x0a, + 0x57, 0x50, 0x59, 0x5e, 0x4b, 0x4c, 0x45, 0x42, 0x6f, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7d, 0x7a, + 0x89, 0x8e, 0x87, 0x80, 0x95, 0x92, 0x9b, 0x9c, 0xb1, 0xb6, 0xbf, 0xb8, 0xad, 0xaa, 0xa3, 0xa4, + 0xf9, 0xfe, 0xf7, 0xf0, 0xe5, 0xe2, 0xeb, 0xec, 0xc1, 0xc6, 0xcf, 0xc8, 0xdd, 0xda, 0xd3, 0xd4, + 0x69, 0x6e, 0x67, 0x60, 0x75, 0x72, 0x7b, 0x7c, 0x51, 0x56, 0x5f, 0x58, 0x4d, 0x4a, 0x43, 0x44, + 0x19, 0x1e, 0x17, 0x10, 0x05, 0x02, 0x0b, 0x0c, 0x21, 0x26, 0x2f, 0x28, 0x3d, 0x3a, 0x33, 0x34, + 0x4e, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5c, 0x5b, 0x76, 0x71, 0x78, 0x7f, 0x6a, 0x6d, 0x64, 0x63, + 0x3e, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2c, 0x2b, 0x06, 0x01, 0x08, 0x0f, 0x1a, 0x1d, 0x14, 0x13, + 0xae, 0xa9, 0xa0, 0xa7, 0xb2, 0xb5, 0xbc, 0xbb, 0x96, 0x91, 0x98, 0x9f, 0x8a, 0x8d, 0x84, 0x83, + 0xde, 0xd9, 0xd0, 0xd7, 0xc2, 0xc5, 0xcc, 0xcb, 0xe6, 0xe1, 0xe8, 0xef, 0xfa, 0xfd, 0xf4, 0xf3}; uint8_t crc8_checksum(uint8_t *pdata, size_t nbytes, uint8_t crc) { - while (nbytes > 0) { - crc = table[(crc ^ *pdata++) & 0xff]; - --nbytes; - } - return crc; + while (nbytes > 0) { + crc = table[(crc ^ *pdata++) & 0xff]; + --nbytes; + } + return crc; } diff --git a/common/low_pass_filter.c b/common/low_pass_filter.c index 5a522184..b26cbbe0 100644 --- a/common/low_pass_filter.c +++ b/common/low_pass_filter.c @@ -3,27 +3,27 @@ // Initialize the low-pass filter w_status_t low_pass_filter_init(double *alpha, double response_time) { - if (alpha == NULL || response_time <= 0) { - return W_INVALID_PARAM; // Return specific error for invalid parameters - } - // Calculate and store the alpha value using the low_pass_alpha function - *alpha = low_pass_alpha(response_time, response_time); - return W_SUCCESS; // Return success after initialization + if (alpha == NULL || response_time <= 0) { + return W_INVALID_PARAM; // Return specific error for invalid parameters + } + // Calculate and store the alpha value using the low_pass_alpha function + *alpha = low_pass_alpha(response_time, response_time); + return W_SUCCESS; // Return success after initialization } // Update the low-pass filter with a new value w_status_t update_low_pass(double alpha, uint16_t new_input_value, double *low_pass_value) { - // Check if low_pass_value pointer is NULL - if (low_pass_value == NULL) { - return W_INVALID_PARAM; // Return specific error for invalid parameters - } + // Check if low_pass_value pointer is NULL + if (low_pass_value == NULL) { + return W_INVALID_PARAM; // Return specific error for invalid parameters + } - // Ensure alpha is within the valid range - if (alpha <= 0.0 || alpha >= 1.0) { - return W_INVALID_PARAM; - } + // Ensure alpha is within the valid range + if (alpha <= 0.0 || alpha >= 1.0) { + return W_INVALID_PARAM; + } - // Low pass filter formula: y[n] = alpha * x[n] + (1 - alpha) * y[n-1] - *low_pass_value = (alpha * new_input_value) + ((1.0 - alpha) * (*low_pass_value)); - return W_SUCCESS; // Return success after successful update + // Low pass filter formula: y[n] = alpha * x[n] + (1 - alpha) * y[n-1] + *low_pass_value = (alpha * new_input_value) + ((1.0 - alpha) * (*low_pass_value)); + return W_SUCCESS; // Return success after successful update } \ No newline at end of file diff --git a/include/common.h b/include/common.h index 223fc4f0..f8555929 100644 --- a/include/common.h +++ b/include/common.h @@ -7,13 +7,13 @@ // Standard Error Code typedef enum { - W_SUCCESS = 0, - W_FAILURE, - W_INVALID_PARAM, - W_IO_ERROR, - W_IO_TIMEOUT, - W_MATH_ERROR, - W_OVERFLOW + W_SUCCESS = 0, + W_FAILURE, + W_INVALID_PARAM, + W_IO_ERROR, + W_IO_TIMEOUT, + W_MATH_ERROR, + W_OVERFLOW } w_status_t; // Assertion Macro @@ -30,9 +30,9 @@ void w_assert_fail(const char *file, int line, const char *statement); #ifdef W_DEBUG #define w_assert(statement) \ - if (!(statement)) { \ - w_assert_fail(__FILE__, __LINE__, #statement); \ - } + if (!(statement)) { \ + w_assert_fail(__FILE__, __LINE__, #statement); \ + } #else diff --git a/include/low_pass_filter.h b/include/low_pass_filter.h index fd19ec86..380f2ed9 100644 --- a/include/low_pass_filter.h +++ b/include/low_pass_filter.h @@ -12,13 +12,13 @@ extern "C" { // Inline function to calculate the sample frequency based on the time difference in milliseconds static inline double sample_freq(double time_diff_ms) { - return 1000.0 / time_diff_ms; + return 1000.0 / time_diff_ms; } // Inline function to calculate the alpha value for the low-pass filter based on the response time static inline double low_pass_alpha(double TR, double time_diff_ms) { - double freq = sample_freq(time_diff_ms); - return (freq * TR / 5.0) / (1.0 + freq * TR / 5.0); + double freq = sample_freq(time_diff_ms); + return (freq * TR / 5.0) / (1.0 + freq * TR / 5.0); } // Initializes the low-pass filter by calculating and storing the alpha value based on the given diff --git a/pic18f26k83/timer.c b/pic18f26k83/timer.c index ae575dee..9aaa42a8 100644 --- a/pic18f26k83/timer.c +++ b/pic18f26k83/timer.c @@ -21,38 +21,38 @@ volatile static uint32_t millis_counter = 0; uint32_t millis(void) { - INTCON0bits.GIE = 0; - uint32_t res = millis_counter; - INTCON0bits.GIE = 1; - return res; + INTCON0bits.GIE = 0; + uint32_t res = millis_counter; + INTCON0bits.GIE = 1; + return res; } void timer0_init(void) { - PIE3bits.TMR0IE = 1; // enable timer 0 interrupt + PIE3bits.TMR0IE = 1; // enable timer 0 interrupt - T0CON0bits.EN = 0; // disable timer module - T0CON0bits.MD16 = 0; // set up timer as 8 bits + T0CON0bits.EN = 0; // disable timer module + T0CON0bits.MD16 = 0; // set up timer as 8 bits - T0CON0bits.OUTPS = 0; // set the output prescaler to 1:1 - T0CON1bits.CKPS = 0; // set the prescaler rate to 1:1 + T0CON0bits.OUTPS = 0; // set the output prescaler to 1:1 + T0CON1bits.CKPS = 0; // set the prescaler rate to 1:1 - T0CON1bits.CS = 0x5; // drive timer from 500 kHz - T0CON1bits.ASYNC = 0; // timer zero is synchronized to the system clock + T0CON1bits.CS = 0x5; // drive timer from 500 kHz + T0CON1bits.ASYNC = 0; // timer zero is synchronized to the system clock - // enable the module - T0CON0bits.EN = 1; + // enable the module + T0CON0bits.EN = 1; } /* * Based on Bresenham's algorithm and described here: http://romanblack.com/one_sec.htm */ void timer0_handle_interrupt() { - static uint8_t internal_count = 0; - - millis_counter += MILLIS_INCREMENT; - internal_count += MILLIS_REMAINDER; - if (internal_count > MILLIS_INCREMENT_CAP) { - internal_count -= MILLIS_INCREMENT_CAP; - millis_counter++; - } + static uint8_t internal_count = 0; + + millis_counter += MILLIS_INCREMENT; + internal_count += MILLIS_REMAINDER; + if (internal_count > MILLIS_INCREMENT_CAP) { + internal_count -= MILLIS_INCREMENT_CAP; + millis_counter++; + } } From 48479c9b9b8e8c5714035bd28a626ae1b874b802 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Sat, 4 Oct 2025 10:48:09 -0400 Subject: [PATCH 049/108] Migrate pic18 timer doc to doxygen --- include/timer.h | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/include/timer.h b/include/timer.h index 623cd579..c252ef8a 100644 --- a/include/timer.h +++ b/include/timer.h @@ -1,3 +1,11 @@ +/** + * @file + * @brief PIC18 Timer driver provides millis function + * + * This module provides basic timer functionalities, such as initializing Timer0, handling + * interrupts, and tracking milliseconds since the timer was started. + */ + #ifndef ROCKETLIB_TIMER_H #define ROCKETLIB_TIMER_H @@ -7,14 +15,34 @@ #error "C++ is not supported" #endif -// utilities for handling the timer used in millis() +/** + * @brief Initializes Timer0 for time tracking. This function must be called before using any other + * timer-related functionality. + * + * - Enables Timer0 interrupt. + * - Sets the timer to 8-bit mode. + * - Driven by a 500 kHz clock. + * - Ensures the timer is synchronized to the system clock. + */ void timer0_init(void); -// should be called from the general ISR to increment the timer -// DOES NOT CLEAR PIR3bits.TMR0IF! This is the responsibility of the top level ISR. +/** + * @brief Function should be called from main ISR when Timer0 interrupt is triggered + * + * This function should be called from the main Interrupt Service Routine (ISR) whenever the Timer0 + * interrupt is triggered. It updates the internal time counter. + * + * @warning This function does **not** clear the interrupt flag (`PIR3bits.TMR0IF`), This is the + * responsibility of the top level ISR. + */ void timer0_handle_interrupt(void); -// Returns milliseconds since the timer was initialized +/** + * @brief Returns the number of milliseconds since `timer0_init()` was called + * + * Returns the number of milliseconds since `timer0_init()` was called. This is a safe function that + * disables interrupts momentarily to return a consistent value. + */ uint32_t millis(void); #endif /* ROCKETLIB_TIMER_H */ From d8613325dea8480aeb871d948deb92e8dcc8697d Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Sat, 4 Oct 2025 10:57:34 -0400 Subject: [PATCH 050/108] Add CRC8 function documentation --- common/crc8.c | 2 +- include/crc8.h | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/common/crc8.c b/common/crc8.c index 41131419..35d79d43 100644 --- a/common/crc8.c +++ b/common/crc8.c @@ -20,7 +20,7 @@ static uint8_t table[256] = { 0xae, 0xa9, 0xa0, 0xa7, 0xb2, 0xb5, 0xbc, 0xbb, 0x96, 0x91, 0x98, 0x9f, 0x8a, 0x8d, 0x84, 0x83, 0xde, 0xd9, 0xd0, 0xd7, 0xc2, 0xc5, 0xcc, 0xcb, 0xe6, 0xe1, 0xe8, 0xef, 0xfa, 0xfd, 0xf4, 0xf3}; -uint8_t crc8_checksum(uint8_t *pdata, size_t nbytes, uint8_t crc) { +uint8_t crc8_checksum(const uint8_t *pdata, size_t nbytes, uint8_t crc) { while (nbytes > 0) { crc = table[(crc ^ *pdata++) & 0xff]; --nbytes; diff --git a/include/crc8.h b/include/crc8.h index 0af1856c..4f0244d0 100644 --- a/include/crc8.h +++ b/include/crc8.h @@ -8,7 +8,17 @@ extern "C" { #endif -uint8_t crc8_checksum(uint8_t *pdata, size_t nbytes, uint8_t crc); +/** + * @brief Compute CRC8 + * + * Computes the CRC8 checksum of input data + * + * @param pdata Input data buffer + * @param nbytes Buffer size in bytes + * @param crc CRC8 checksum of previous CRC8 calculation if calculating checksum on multiple discontinuous buffers, otherwise 0 + * @return Computed CRC8 checksum + */ +uint8_t crc8_checksum(const uint8_t *pdata, size_t nbytes, uint8_t crc); #ifdef __cplusplus } From 0440aee3717c8b6c3922d542efc5fd60ec6e4bbf Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Sat, 4 Oct 2025 11:10:22 -0400 Subject: [PATCH 051/108] Document standard error code --- include/common.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/include/common.h b/include/common.h index f8555929..f77a4356 100644 --- a/include/common.h +++ b/include/common.h @@ -1,18 +1,27 @@ #ifndef ROCKETLIB_COMMON_H #define ROCKETLIB_COMMON_H -// Rocketlib Version -#define ROCKETLIB_VERSION_MAJOR 2025 +/// @brief Rocketlib major release number, shall be design cycle year +#define ROCKETLIB_VERSION_MAJOR 2026 + +/// @brief Rocketlib minor release number, shall be the Nth release of the design cycle #define ROCKETLIB_VERSION_MINOR 1 -// Standard Error Code +/// @brief Standard error code typedef enum { + /// @brief Success W_SUCCESS = 0, + /// @brief Failure, if not one of the more specific case below W_FAILURE, + /// @brief Illegal function call arguments/parameters W_INVALID_PARAM, + /// @brief IO error, for example no SD card was plugged in W_IO_ERROR, + /// @brief IO timeout, for example SD car takes too long to respond W_IO_TIMEOUT, + /// @brief Math error, for example divide by zero W_MATH_ERROR, + /// @brief Buffer overflow, for example trying to write to a full FIFO W_OVERFLOW } w_status_t; From c573e24111881b2d82c21c02e7f9204b2be4989c Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Sat, 4 Oct 2025 11:21:08 -0400 Subject: [PATCH 052/108] Document assertion --- include/common.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/common.h b/include/common.h index f77a4356..65ef5364 100644 --- a/include/common.h +++ b/include/common.h @@ -30,6 +30,15 @@ typedef enum { extern "C" { #endif +/** + * @brief Assertion fail handler + * + * Assertion fail handler, shall be implemented in the firmware, only used if `W_DEBUG` is defined + * + * @param file Path to C source file contains assertion failure + * @param line C source line number of assertion failure + * @param statement Statement caused assertion failure + */ void w_assert_fail(const char *file, int line, const char *statement); #ifdef __cplusplus @@ -45,6 +54,12 @@ void w_assert_fail(const char *file, int line, const char *statement); #else +/** + * @brief Assertion + * + * Works just like standard C assertion, except use can define custom assertion failure handler(see + * `w_assert_fail`), only active when `W_DEBUG` is defined + */ #define w_assert(statement) #endif From 90c38269befc993eb367283bdaf337933a98665e Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Sat, 4 Oct 2025 11:26:03 -0400 Subject: [PATCH 053/108] Format all code --- include/crc8.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/crc8.h b/include/crc8.h index 4f0244d0..03c02523 100644 --- a/include/crc8.h +++ b/include/crc8.h @@ -15,7 +15,8 @@ extern "C" { * * @param pdata Input data buffer * @param nbytes Buffer size in bytes - * @param crc CRC8 checksum of previous CRC8 calculation if calculating checksum on multiple discontinuous buffers, otherwise 0 + * @param crc CRC8 checksum of previous CRC8 calculation if calculating checksum on multiple + * discontinuous buffers, otherwise 0 * @return Computed CRC8 checksum */ uint8_t crc8_checksum(const uint8_t *pdata, size_t nbytes, uint8_t crc); From c20842349c3138d27b9ef2a8fcdcea24a99df2b6 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Sat, 4 Oct 2025 16:57:39 -0400 Subject: [PATCH 054/108] Fix typo --- include/common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/common.h b/include/common.h index 65ef5364..6c5056dd 100644 --- a/include/common.h +++ b/include/common.h @@ -17,7 +17,7 @@ typedef enum { W_INVALID_PARAM, /// @brief IO error, for example no SD card was plugged in W_IO_ERROR, - /// @brief IO timeout, for example SD car takes too long to respond + /// @brief IO timeout, for example SD card takes too long to respond W_IO_TIMEOUT, /// @brief Math error, for example divide by zero W_MATH_ERROR, From db3a2dd07af5a06867b9b2130b2385dbd5189101 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Sun, 12 Oct 2025 01:53:00 -0400 Subject: [PATCH 055/108] Fix low pass filter lint errors --- common/low_pass_filter.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/common/low_pass_filter.c b/common/low_pass_filter.c index b26cbbe0..56b14d20 100644 --- a/common/low_pass_filter.c +++ b/common/low_pass_filter.c @@ -1,5 +1,8 @@ -#include "low_pass_filter.h" #include +#include + +#include "common.h" +#include "low_pass_filter.h" // Initialize the low-pass filter w_status_t low_pass_filter_init(double *alpha, double response_time) { @@ -26,4 +29,4 @@ w_status_t update_low_pass(double alpha, uint16_t new_input_value, double *low_p // Low pass filter formula: y[n] = alpha * x[n] + (1 - alpha) * y[n-1] *low_pass_value = (alpha * new_input_value) + ((1.0 - alpha) * (*low_pass_value)); return W_SUCCESS; // Return success after successful update -} \ No newline at end of file +} From e1dbcc90f3f5f55adc39372db9a182f5cbed0e45 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Sun, 12 Oct 2025 10:11:22 -0400 Subject: [PATCH 056/108] Update unit test to use rockettest framework --- tests/Makefile | 67 +++++++++++++++++++++++++ tests/rockettest.cpp | 78 ++++++++++++++++++++++++++++ tests/rockettest.hpp | 39 ++++++++++++++ tests/test_low_pass_filter.cpp | 92 ++++++++++++++++++++++++++++++++++ 4 files changed, 276 insertions(+) create mode 100644 tests/Makefile create mode 100644 tests/rockettest.cpp create mode 100644 tests/rockettest.hpp create mode 100644 tests/test_low_pass_filter.cpp diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 00000000..8e87d966 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,67 @@ +ROCKETLIB_PATH := .. + +CFLAGS := \ + -std=c99 \ + -Wall \ + -Wextra \ + -pedantic \ + -MMD \ + -O2 \ + -I$(ROCKETLIB_PATH)/include + +ifeq ($(COVERAGE), 1) + +CFLAGS += \ + -fprofile-arcs \ + -ftest-coverage + +LDFLAGS += -Wl,-lgcov + +endif + +CXXFLAGS := \ + -std=c++23 \ + -Wall \ + -Wextra \ + -pedantic \ + -MMD \ + -O2 \ + -I$(ROCKETLIB_PATH)/include + +ROCKETLIB_SRCS := \ + $(ROCKETLIB_PATH)/common/crc8.c \ + $(ROCKETLIB_PATH)/common/low_pass_filter.c + +TEST_SRCS := \ + rockettest.cpp \ + test_low_pass_filter.cpp + +ROCKETLIB_OBJS = $(ROCKETLIB_SRCS:.c=.o) +ROCKETLIB_DEPS = $(ROCKETLIB_SRCS:.c=.d) + +TEST_OBJS = $(TEST_SRCS:.cpp=.o) +TEST_DEPS = $(TEST_SRCS:.cpp=.d) + +unit_test: $(ROCKETLIB_OBJS) $(TEST_OBJS) + $(CXX) $^ $(LDFLAGS) -o $@ + +.PHONY: run_test +run_test: unit_test + ./unit_test + +ifeq ($(COVERAGE), 1) + +coverage.info: run_test + lcov --capture --branch-coverage --directory ../common --output-file $@ + +html: coverage.info + genhtml $^ --branch-coverage --output-directory $@ + +endif + +-include $(ROCKETLIB_DEPS) +-include $(TEST_DEPS) + +.PHONY: clean +clean: + rm -rf $(ROCKETLIB_OBJS) $(ROCKETLIB_DEPS) $(TEST_OBJS) $(TEST_DEPS) *.o ../common/*.gcda ../common/*.gcno unit_test coverage.info html diff --git a/tests/rockettest.cpp b/tests/rockettest.cpp new file mode 100644 index 00000000..873cb07e --- /dev/null +++ b/tests/rockettest.cpp @@ -0,0 +1,78 @@ +#include +#include +#include +#include +#include + +#include "rockettest.hpp" + +int main(int argc, char *argv[]) { + int seed = std::time({}); + + int opt; + while ((opt = getopt(argc, argv, "s:")) != -1) { + switch (opt) { + case 's': + seed = atoi(optarg); + break; + + default: + std::cout << "Usage: unit_test [-s random_seed] [test_names..]" << std::endl; + std::cout << "If random_seed is not provided then current time is used as seed" + << std::endl; + std::cout << "If test_names are not provided then all tests will run" << std::endl; + return EXIT_FAILURE; + } + } + + std::cout << "Random seed " << seed << std::endl; + std::srand(seed); + + bool all_passed = true; + + if (optind < argc) { + // Run selected tests + for (; optind < argc; optind++) { + if (rockettest_test::tests.contains(argv[optind])) { + if (!(*rockettest_test::tests[argv[optind]])()) { + all_passed = false; + } + } else { + all_passed = false; + std::cout << CONSOLE_COLOUR_RED << "NOT FOUND " << CONSOLE_COLOUR_RESET + << argv[optind] << std::endl; + } + } + + } else { + // Run all test + for (auto &rt : rockettest_test::tests) { + if (!(*rt.second)()) { + all_passed = false; + } + } + } + + if (all_passed) { + return EXIT_SUCCESS; + } + + return EXIT_FAILURE; +} + +std::map rockettest_test::tests; + +rockettest_test::rockettest_test(const char *test_name) : name(test_name) { + tests[test_name] = this; +} + +bool rockettest_test::operator()() { + std::cout << "Running " << name << std::endl; + bool test_result = run_test(); + if (test_result == true) { + std::cout << CONSOLE_COLOUR_GREEN << "PASSED " << CONSOLE_COLOUR_RESET << name << std::endl; + } else { + std::cout << CONSOLE_COLOUR_RED << "FAILED " << CONSOLE_COLOUR_RESET << name << std::endl; + } + return test_result; +} diff --git a/tests/rockettest.hpp b/tests/rockettest.hpp new file mode 100644 index 00000000..4ead6dbe --- /dev/null +++ b/tests/rockettest.hpp @@ -0,0 +1,39 @@ +#ifndef ROCKETTEST_H +#define ROCKETTEST_H + +#include +#include +#include +#include +#include + +#define CONSOLE_COLOUR_RESET "\033[0m" +#define CONSOLE_COLOUR_RED "\033[1;31m" +#define CONSOLE_COLOUR_GREEN "\033[1;32m" + +#define rockettest_assert(statement) \ + if (!(statement)) { \ + std::cout << "Assertion failed " << __FILE__ << ':' << __LINE__ << ' ' << #statement \ + << std::endl; \ + test_passed = false; \ + } + +template T rockettest_rand() { + return static_cast(std::rand() & mask); +} + +class rockettest_test { + const char *name; + +public: + static std::map tests; + + rockettest_test() = delete; + rockettest_test(const char *test_name); + + virtual bool run_test() = 0; + + bool operator()(); +}; + +#endif diff --git a/tests/test_low_pass_filter.cpp b/tests/test_low_pass_filter.cpp new file mode 100644 index 00000000..1894807a --- /dev/null +++ b/tests/test_low_pass_filter.cpp @@ -0,0 +1,92 @@ +#include +#include +#include +#include +#include + +#include "common.h" +#include "low_pass_filter.h" + +#include "rockettest.hpp" + +#define EPSILON 0.0001 + +class low_pass_filter_init_test : rockettest_test { +public: + low_pass_filter_init_test() : rockettest_test("low_pass_filter_init_test") {} + + bool run_test() override { + bool test_passed = true; + + double alpha; + // Test with valid input + rockettest_assert(low_pass_filter_init(&alpha, 1.0) == W_SUCCESS); + // Test with invalid input (NULL pointer) + rockettest_assert(low_pass_filter_init(NULL, 1.0) == W_INVALID_PARAM); + // Test with invalid input (negative response time) + rockettest_assert(low_pass_filter_init(&alpha, -1.0) == W_INVALID_PARAM); + // Test with invalid input (zero response time) + rockettest_assert(low_pass_filter_init(&alpha, 0.0) == W_INVALID_PARAM); + + return test_passed; + } +}; + +low_pass_filter_init_test low_pass_filter_init_test_inst; + +class low_pass_filter_update_test : rockettest_test { +public: + low_pass_filter_update_test() : rockettest_test("low_pass_filter_update_test") {} + + bool run_test() override { + bool test_passed = true; + + double alpha = 0.1; // Smoothing factor (0 < alpha < 1) + double low_pass_value = 0.0; // Initial low-pass filtered value + uint16_t new_input_value = 100; // Fixed input value to test behavior + int iterations = 50; // Number of times to apply the filter + w_status_t result; + + printf("Testing Low-Pass Filter with Fixed Input\n"); + printf("-----------------------------------------\n"); + printf("Alpha (smoothing factor): %.2f\n", alpha); + printf("Input Value: %u\n\n", new_input_value); + + for (int i = 1; i <= iterations; ++i) { + // Store the previous low_pass_value before updating + double previous_low_pass = low_pass_value; + // Calculate the expected value based on the low-pass filter formula + double expected = (alpha * new_input_value) + ((1.0 - alpha) * previous_low_pass); + // Update the low-pass filter with the fixed input value + result = update_low_pass(alpha, new_input_value, &low_pass_value); + rockettest_assert(result == W_SUCCESS); + // Print the current iteration and values + printf("Iteration %2d: Low-Pass Value = %.4f | Expected ~ %.4f\n", + i, + low_pass_value, + expected); + // Verify the correctness of the low-pass update + rockettest_assert(fabs(low_pass_value - expected) < EPSILON); + } + + printf("\nAll iterations completed successfully.\n\n"); + + // Test with alpha out of range + result = update_low_pass(-0.1, new_input_value, &low_pass_value); + rockettest_assert(result == W_INVALID_PARAM); + printf("Invalid alpha (negative) test passed.\n"); + + result = update_low_pass(1.1, new_input_value, &low_pass_value); + rockettest_assert(result == W_INVALID_PARAM); + printf("Invalid alpha (greater than 1) test passed.\n"); + + // Test with NULL low_pass_value + result = update_low_pass(alpha, new_input_value, NULL); + rockettest_assert(result == W_INVALID_PARAM); + printf("Null low_pass_value test passed.\n"); + + return test_passed; + } +}; + +low_pass_filter_update_test low_pass_filter_update_test_inst; From cea0490394e1622abeb5ccad3645307bc0e9281c Mon Sep 17 00:00:00 2001 From: Taisir Hassan Date: Wed, 5 Nov 2025 01:46:25 -0500 Subject: [PATCH 057/108] Document low_pass_filter.h with doxygen docstring Closes #55 --- include/low_pass_filter.h | 55 +++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/include/low_pass_filter.h b/include/low_pass_filter.h index 380f2ed9..d81e9143 100644 --- a/include/low_pass_filter.h +++ b/include/low_pass_filter.h @@ -1,3 +1,12 @@ +/** + * @file + * @brief Low-pass filter implementation + * + * This module provides a low-pass filter implementation for smoothing sensor readings + * and reducing noise in analog signals. The filter uses an exponential moving average + * algorithm with configurable response time. + */ + #ifndef ROCKETLIB_LOW_PASS_FILTER_H #define ROCKETLIB_LOW_PASS_FILTER_H @@ -10,22 +19,58 @@ extern "C" { #endif -// Inline function to calculate the sample frequency based on the time difference in milliseconds +/** + * @brief Calculate the sample frequency based on the time difference in milliseconds + * + * @param time_diff_ms Time difference between samples in milliseconds + * @return double Sample frequency in Hz + */ static inline double sample_freq(double time_diff_ms) { return 1000.0 / time_diff_ms; } -// Inline function to calculate the alpha value for the low-pass filter based on the response time +/** + * @brief Calculate the alpha value for the low-pass filter based on the response time + * + * The alpha value determines the filter's responsiveness. A higher alpha value results + * in faster response but less filtering, while a lower alpha value provides more filtering + * but slower response. + * + * @param TR Response time constant in milliseconds + * @param time_diff_ms Time difference between samples in milliseconds + * @return double Alpha value (0.0 to 1.0) for the low-pass filter + */ static inline double low_pass_alpha(double TR, double time_diff_ms) { double freq = sample_freq(time_diff_ms); return (freq * TR / 5.0) / (1.0 + freq * TR / 5.0); } -// Initializes the low-pass filter by calculating and storing the alpha value based on the given -// response time. +/** + * @brief Initializes the low-pass filter by calculating and storing the alpha value + * + * This function calculates the alpha value based on the given response time and stores + * it in the provided pointer. The alpha value is used in subsequent filter updates. + * + * @param alpha Pointer to store the calculated alpha value + * @param response_time Response time constant in milliseconds (must be > 0) + * @return w_status_t Returns W_SUCCESS on success, W_INVALID_PARAM if alpha is NULL or + * response_time is invalid + */ w_status_t low_pass_filter_init(double *alpha, double response_time); -// Updates the low-pass filter with a new value and returns the operation status +/** + * @brief Updates the low-pass filter with a new value and returns the operation status + * + * This function applies the low-pass filter algorithm to the new input value using the + * provided alpha value. The filtered result is stored in low_pass_value and updated + * in-place for the next iteration. + * + * @param alpha Alpha value (0.0 to 1.0) for the low-pass filter + * @param new_input_value New input value to filter + * @param low_pass_value Pointer to the current filtered value (updated in-place) + * @return w_status_t Returns W_SUCCESS on success, W_INVALID_PARAM if low_pass_value is + * NULL or alpha is out of valid range (0.0 to 1.0) + */ w_status_t update_low_pass(double alpha, uint16_t new_input_value, double *low_pass_value); #ifdef __cplusplus From 700c7f9324593acf977ab5e822afb7bf95eca77e Mon Sep 17 00:00:00 2001 From: Taisir Hassan Date: Wed, 5 Nov 2025 02:37:38 -0500 Subject: [PATCH 058/108] Add doxygen documentation for low_pass_filter.c functions --- common/low_pass_filter.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/common/low_pass_filter.c b/common/low_pass_filter.c index 56b14d20..925981c7 100644 --- a/common/low_pass_filter.c +++ b/common/low_pass_filter.c @@ -4,7 +4,17 @@ #include "common.h" #include "low_pass_filter.h" -// Initialize the low-pass filter +/** + * @brief Initializes the low-pass filter by calculating and storing the alpha value + * + * This function calculates the alpha value based on the given response time and stores + * it in the provided pointer. The alpha value is used in subsequent filter updates. + * + * @param alpha Pointer to store the calculated alpha value + * @param response_time Response time constant in milliseconds (must be > 0) + * @return w_status_t Returns W_SUCCESS on success, W_INVALID_PARAM if alpha is NULL or + * response_time is invalid + */ w_status_t low_pass_filter_init(double *alpha, double response_time) { if (alpha == NULL || response_time <= 0) { return W_INVALID_PARAM; // Return specific error for invalid parameters @@ -14,7 +24,19 @@ w_status_t low_pass_filter_init(double *alpha, double response_time) { return W_SUCCESS; // Return success after initialization } -// Update the low-pass filter with a new value +/** + * @brief Updates the low-pass filter with a new value and returns the operation status + * + * This function applies the low-pass filter algorithm to the new input value using the + * provided alpha value. The filtered result is stored in low_pass_value and updated + * in-place for the next iteration. + * + * @param alpha Alpha value (0.0 to 1.0) for the low-pass filter + * @param new_input_value New input value to filter + * @param low_pass_value Pointer to the current filtered value (updated in-place) + * @return w_status_t Returns W_SUCCESS on success, W_INVALID_PARAM if low_pass_value is + * NULL or alpha is out of valid range (0.0 to 1.0) + */ w_status_t update_low_pass(double alpha, uint16_t new_input_value, double *low_pass_value) { // Check if low_pass_value pointer is NULL if (low_pass_value == NULL) { From e10464574a22a097d2ee19a59c0097a6c59cbe5d Mon Sep 17 00:00:00 2001 From: Xukun Li Date: Sun, 9 Nov 2025 19:36:17 -0500 Subject: [PATCH 059/108] add mbr parser function --- common/mbr.c | 31 ++++++++++++++++++++++++++++++ include/mbr.h | 18 +++++++++++++++++ tests/Makefile | 6 ++++-- tests/test_mbr.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 common/mbr.c create mode 100644 include/mbr.h create mode 100644 tests/test_mbr.cpp diff --git a/common/mbr.c b/common/mbr.c new file mode 100644 index 00000000..76b97774 --- /dev/null +++ b/common/mbr.c @@ -0,0 +1,31 @@ +#include + +#define MBR_PT_OFFSET 0x1BE +#define MBR_PT_SIZE 16 +#define MBR_TYPE_OFF 4 +#define MBR_LBA_OFF 8 + +w_status_t mbr_parse(uint8_t *first_sector, uint8_t partition_type, uint32_t *sector_lba) { + if (!first_sector || !sector_lba) { + return W_INVALID_PARAM; + } + + // Set sector_lba to 0 as default + *sector_lba = 0; + + // First partition entry starts at 0x01BE in the first sector + uint8_t *entry = first_sector + MBR_PT_OFFSET; + + // Each partition entry has a size of 16 bytes + for (int i = 0; i < 4; i++, entry += MBR_PT_SIZE) { + // Partition type locates at 0x04 in each partition + uint8_t type = entry[MBR_TYPE_OFF]; + if (type == partition_type) { + *sector_lba = (uint32_t)entry[MBR_LBA_OFF] | ((uint32_t)entry[MBR_LBA_OFF + 1] << 8) | + ((uint32_t)entry[MBR_LBA_OFF + 2] << 16) | + ((uint32_t)entry[MBR_LBA_OFF + 3] << 24); + return W_SUCCESS; + } + } + return W_FAILURE; +} diff --git a/include/mbr.h b/include/mbr.h new file mode 100644 index 00000000..70cd21a9 --- /dev/null +++ b/include/mbr.h @@ -0,0 +1,18 @@ +#include +#include + +#include "common.h" + +/** + * @brief To find the starting sector of a given type of partition + * + * This function finds the lba for the partition that matches the partition type + * provided in the first sector. Put lba as 0 if the corresponding partition + * cannot be found. + * + * @param first_sector 512 byte buffer contains content of first sector + * @param partition_type The partition type trying to find + * @param sector_lba Pointer to the start offset of the sector + * @return w_status_t Returns W_SUCCESS on success, W_FAILURE if partition cannot be found + */ +w_status_t mbr_parse(uint8_t *first_sector, uint8_t partition_type, uint32_t *sector_lba); diff --git a/tests/Makefile b/tests/Makefile index 8e87d966..8dcfa03e 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -30,11 +30,13 @@ CXXFLAGS := \ ROCKETLIB_SRCS := \ $(ROCKETLIB_PATH)/common/crc8.c \ - $(ROCKETLIB_PATH)/common/low_pass_filter.c + $(ROCKETLIB_PATH)/common/low_pass_filter.c \ + $(ROCKETLIB_PATH)/common/mbr.c TEST_SRCS := \ rockettest.cpp \ - test_low_pass_filter.cpp + test_low_pass_filter.cpp \ + test_mbr.cpp ROCKETLIB_OBJS = $(ROCKETLIB_SRCS:.c=.o) ROCKETLIB_DEPS = $(ROCKETLIB_SRCS:.c=.d) diff --git a/tests/test_mbr.cpp b/tests/test_mbr.cpp new file mode 100644 index 00000000..1b4db6ef --- /dev/null +++ b/tests/test_mbr.cpp @@ -0,0 +1,48 @@ +#include +#include +#include +#include +#include + +#include "common.h" +#include "mbr.h" + +#include "rockettest.hpp" + +class mbr_test : rockettest_test { +public: + mbr_test() : rockettest_test("mbr_test") {} + + bool run_test() override { + bool test_passed = true; + + // Example partition type + uint8_t partition_type = 0x07; + + // Declare sector lba + uint32_t sector_lba; + + // Example first sector + uint8_t first_sector[512] = {0}; + uint8_t *entry = first_sector + 0x1BE; + + entry[0] = 0x80; // boot flag + entry[4] = partition_type; // partition type + // Imaginary LBA: 0x001100000 + entry[8] = 0x00; // LBA low byte (LBA is little-endian) + entry[9] = 0x00; + entry[10] = 0x11; + entry[11] = 0x00; // LBA high byte + + // Test with valid input + rockettest_assert(mbr_parse(first_sector, partition_type, §or_lba) == W_SUCCESS); + // Test with invalid input (NULL first sector) + rockettest_assert(mbr_parse(nullptr, partition_type, §or_lba) == W_INVALID_PARAM); + // Test with invalid input (NULL LBA) + rockettest_assert(mbr_parse(first_sector, partition_type, nullptr) == W_INVALID_PARAM); + // Test with a partition type that cannot be found + rockettest_assert(mbr_parse(first_sector, 0x00, §or_lba) == W_FAILURE); + + return test_passed; + } +}; From acf5eb76f3c0e5399213904a466108a3fca7c404 Mon Sep 17 00:00:00 2001 From: Xukun Li Date: Sun, 9 Nov 2025 19:42:12 -0500 Subject: [PATCH 060/108] header file includes --- common/mbr.c | 3 ++- tests/test_mbr.cpp | 6 ------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/common/mbr.c b/common/mbr.c index 76b97774..e3baacf9 100644 --- a/common/mbr.c +++ b/common/mbr.c @@ -1,4 +1,5 @@ -#include +#include "mbr.h" +#include "common.h" #define MBR_PT_OFFSET 0x1BE #define MBR_PT_SIZE 16 diff --git a/tests/test_mbr.cpp b/tests/test_mbr.cpp index 1b4db6ef..4f863c69 100644 --- a/tests/test_mbr.cpp +++ b/tests/test_mbr.cpp @@ -1,9 +1,3 @@ -#include -#include -#include -#include -#include - #include "common.h" #include "mbr.h" From d5a3266dec607e84885b0bb6cb21ae212bae53d2 Mon Sep 17 00:00:00 2001 From: Xukun Li Date: Sun, 9 Nov 2025 20:38:24 -0500 Subject: [PATCH 061/108] adjust header files inclusions --- common/mbr.c | 4 +++- tests/test_mbr.cpp | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/common/mbr.c b/common/mbr.c index e3baacf9..9e24656c 100644 --- a/common/mbr.c +++ b/common/mbr.c @@ -1,5 +1,7 @@ -#include "mbr.h" +#include + #include "common.h" +#include "mbr.h" #define MBR_PT_OFFSET 0x1BE #define MBR_PT_SIZE 16 diff --git a/tests/test_mbr.cpp b/tests/test_mbr.cpp index 4f863c69..3e10e2c2 100644 --- a/tests/test_mbr.cpp +++ b/tests/test_mbr.cpp @@ -1,3 +1,5 @@ +#include + #include "common.h" #include "mbr.h" From f4f2fdade18ec8bcaa47b4bfea6026fe42e52ea4 Mon Sep 17 00:00:00 2001 From: Xukun Li Date: Fri, 21 Nov 2025 19:48:00 -0500 Subject: [PATCH 062/108] Add boot signature check --- common/mbr.c | 8 ++++++++ tests/test_mbr.cpp | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/common/mbr.c b/common/mbr.c index 9e24656c..17b50727 100644 --- a/common/mbr.c +++ b/common/mbr.c @@ -3,6 +3,7 @@ #include "common.h" #include "mbr.h" +#define BOOT_SIGNATURE_OFFSET 0x1FE #define MBR_PT_OFFSET 0x1BE #define MBR_PT_SIZE 16 #define MBR_TYPE_OFF 4 @@ -13,6 +14,13 @@ w_status_t mbr_parse(uint8_t *first_sector, uint8_t partition_type, uint32_t *se return W_INVALID_PARAM; } + // Boot signature starts at 0x01FE in the first sector + uint8_t *boot_signature = first_sector + BOOT_SIGNATURE_OFFSET; + // Boot signature check + if (boot_signature[0] != 0x55 || boot_signature[1] != 0xAA) { + return W_FAILURE; + } + // Set sector_lba to 0 as default *sector_lba = 0; diff --git a/tests/test_mbr.cpp b/tests/test_mbr.cpp index 3e10e2c2..931c8654 100644 --- a/tests/test_mbr.cpp +++ b/tests/test_mbr.cpp @@ -30,6 +30,13 @@ class mbr_test : rockettest_test { entry[10] = 0x11; entry[11] = 0x00; // LBA high byte + // Test with invalid boot signature + rockettest_assert(mbr_parse(first_sector, partition_type, §or_lba) == W_FAILURE); + + uint8_t *boot_signature = first_sector + 0x1FE; + boot_signature[0] = 0x55; + boot_signature[1] = 0xAA; + // Test with valid input rockettest_assert(mbr_parse(first_sector, partition_type, §or_lba) == W_SUCCESS); // Test with invalid input (NULL first sector) From 456e0ce83e561e0f4eb5dfbaea68620be80de96b Mon Sep 17 00:00:00 2001 From: Xukun Li Date: Fri, 21 Nov 2025 20:06:46 -0500 Subject: [PATCH 063/108] MBR header file update --- include/mbr.h | 13 +++++++++++++ tests/test_mbr.cpp | 4 +++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/mbr.h b/include/mbr.h index 70cd21a9..505d411c 100644 --- a/include/mbr.h +++ b/include/mbr.h @@ -1,8 +1,15 @@ +#ifndef ROCKETLIB_MBR_H +#define ROCKETLIB_MBR_H + #include #include #include "common.h" +#ifdef __cplusplus +extern "C" { +#endif + /** * @brief To find the starting sector of a given type of partition * @@ -16,3 +23,9 @@ * @return w_status_t Returns W_SUCCESS on success, W_FAILURE if partition cannot be found */ w_status_t mbr_parse(uint8_t *first_sector, uint8_t partition_type, uint32_t *sector_lba); + +#ifdef __cplusplus +} +#endif + +#endif /* ROCKETLIB_MBR_H */ diff --git a/tests/test_mbr.cpp b/tests/test_mbr.cpp index 931c8654..a268d0f7 100644 --- a/tests/test_mbr.cpp +++ b/tests/test_mbr.cpp @@ -44,8 +44,10 @@ class mbr_test : rockettest_test { // Test with invalid input (NULL LBA) rockettest_assert(mbr_parse(first_sector, partition_type, nullptr) == W_INVALID_PARAM); // Test with a partition type that cannot be found - rockettest_assert(mbr_parse(first_sector, 0x00, §or_lba) == W_FAILURE); + rockettest_assert(mbr_parse(first_sector, 0x06, §or_lba) == W_FAILURE); return test_passed; } }; + +mbr_test mbr_test_inst; \ No newline at end of file From 528313c137da9b6fd2ddee427d7aef7a951b316a Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Thu, 19 Feb 2026 08:59:19 -0500 Subject: [PATCH 064/108] Update rockettest to support testing assertion triggering --- tests/Makefile | 45 ++++++++++++++++++++++++---------- tests/rockettest.cpp | 23 +++++++++++++++++ tests/rockettest.hpp | 18 +++++++++++--- tests/test_low_pass_filter.cpp | 18 +++++++------- tests/test_mbr.cpp | 16 +++++++----- 5 files changed, 89 insertions(+), 31 deletions(-) diff --git a/tests/Makefile b/tests/Makefile index 8dcfa03e..b9733041 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -6,7 +6,14 @@ CFLAGS := \ -Wextra \ -pedantic \ -MMD \ - -O2 \ + -I$(ROCKETLIB_PATH)/include + +CXXFLAGS := \ + -std=c++20 \ + -Wall \ + -Wextra \ + -pedantic \ + -MMD \ -I$(ROCKETLIB_PATH)/include ifeq ($(COVERAGE), 1) @@ -15,18 +22,27 @@ CFLAGS += \ -fprofile-arcs \ -ftest-coverage +CXXFLAGS += \ + -fprofile-arcs \ + -ftest-coverage + LDFLAGS += -Wl,-lgcov endif -CXXFLAGS := \ - -std=c++23 \ - -Wall \ - -Wextra \ - -pedantic \ - -MMD \ - -O2 \ - -I$(ROCKETLIB_PATH)/include +ifeq ($(DEBUG), 1) + +CFLAGS += -Og -g + +CXXFLAGS += -Og -g + +else + +CFLAGS += -O2 + +CXXFLAGS += -O2 + +endif ROCKETLIB_SRCS := \ $(ROCKETLIB_PATH)/common/crc8.c \ @@ -54,10 +70,13 @@ run_test: unit_test ifeq ($(COVERAGE), 1) coverage.info: run_test - lcov --capture --branch-coverage --directory ../common --output-file $@ + lcov --capture --branch-coverage --no-external --directory ../common --directory . -o $@ + +coverage-filtered.info: coverage.info + lcov --remove $^ "*/tests/*" -o $@ --branch-coverage -html: coverage.info - genhtml $^ --branch-coverage --output-directory $@ +html: coverage-filtered.info + genhtml $^ --flat --branch-coverage --output-directory $@ endif @@ -66,4 +85,4 @@ endif .PHONY: clean clean: - rm -rf $(ROCKETLIB_OBJS) $(ROCKETLIB_DEPS) $(TEST_OBJS) $(TEST_DEPS) *.o ../common/*.gcda ../common/*.gcno unit_test coverage.info html + rm -rf $(ROCKETLIB_OBJS) $(ROCKETLIB_DEPS) $(TEST_OBJS) $(TEST_DEPS) *.o ../common/*.gcda ../common/*.gcno *.gcda *.gcno unit_test *.info html diff --git a/tests/rockettest.cpp b/tests/rockettest.cpp index 873cb07e..d8f0808f 100644 --- a/tests/rockettest.cpp +++ b/tests/rockettest.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -76,3 +77,25 @@ bool rockettest_test::operator()() { } return test_result; } + +static std::jmp_buf assert_test_env; + +void rocketlib_assert_pass_cpp(const char *file, int line, const char *statement) {} + +void rocketlib_assert_fail_cpp(const char *file, int line, const char *statement) { + std::longjmp(assert_test_env, 1); +} + +extern "C" void rocketlib_assert_pass_c(const char *file, int line, const char *statement) {} + +extern "C" void rocketlib_assert_fail_c(const char *file, int line, const char *statement) { + std::longjmp(assert_test_env, 1); +} + +bool rockettest_check_assert_sjlj(std::function funccall) { + if (setjmp(assert_test_env) == 0) { + funccall(); + return false; + } + return true; +} diff --git a/tests/rockettest.hpp b/tests/rockettest.hpp index 4ead6dbe..d9801c39 100644 --- a/tests/rockettest.hpp +++ b/tests/rockettest.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -11,13 +12,22 @@ #define CONSOLE_COLOUR_RED "\033[1;31m" #define CONSOLE_COLOUR_GREEN "\033[1;32m" -#define rockettest_assert(statement) \ - if (!(statement)) { \ - std::cout << "Assertion failed " << __FILE__ << ':' << __LINE__ << ' ' << #statement \ +#define rockettest_check_expr_true(expr) \ + if (!(expr)) { \ + std::cout << CONSOLE_COLOUR_RED << "E: " << CONSOLE_COLOUR_RESET \ + << "Expression should be true " << __FILE__ << ':' << __LINE__ << ' ' << #expr \ << std::endl; \ test_passed = false; \ } +#define rockettest_check_assert_triggered(funccall) \ + if (!rockettest_check_assert_sjlj((funccall))) { \ + std::cout << CONSOLE_COLOUR_RED << "E: " << CONSOLE_COLOUR_RESET \ + << "Rocketlib w_assert did not trigger on " << __FILE__ << ':' << __LINE__ \ + << ' ' << #funccall << std::endl; \ + test_passed = false; \ + } + template T rockettest_rand() { return static_cast(std::rand() & mask); } @@ -36,4 +46,6 @@ class rockettest_test { bool operator()(); }; +bool rockettest_check_assert_sjlj(std::function funccall); + #endif diff --git a/tests/test_low_pass_filter.cpp b/tests/test_low_pass_filter.cpp index 1894807a..edfa6305 100644 --- a/tests/test_low_pass_filter.cpp +++ b/tests/test_low_pass_filter.cpp @@ -20,13 +20,13 @@ class low_pass_filter_init_test : rockettest_test { double alpha; // Test with valid input - rockettest_assert(low_pass_filter_init(&alpha, 1.0) == W_SUCCESS); + rockettest_check_expr_true(low_pass_filter_init(&alpha, 1.0) == W_SUCCESS); // Test with invalid input (NULL pointer) - rockettest_assert(low_pass_filter_init(NULL, 1.0) == W_INVALID_PARAM); + rockettest_check_expr_true(low_pass_filter_init(NULL, 1.0) == W_INVALID_PARAM); // Test with invalid input (negative response time) - rockettest_assert(low_pass_filter_init(&alpha, -1.0) == W_INVALID_PARAM); + rockettest_check_expr_true(low_pass_filter_init(&alpha, -1.0) == W_INVALID_PARAM); // Test with invalid input (zero response time) - rockettest_assert(low_pass_filter_init(&alpha, 0.0) == W_INVALID_PARAM); + rockettest_check_expr_true(low_pass_filter_init(&alpha, 0.0) == W_INVALID_PARAM); return test_passed; } @@ -59,30 +59,30 @@ class low_pass_filter_update_test : rockettest_test { double expected = (alpha * new_input_value) + ((1.0 - alpha) * previous_low_pass); // Update the low-pass filter with the fixed input value result = update_low_pass(alpha, new_input_value, &low_pass_value); - rockettest_assert(result == W_SUCCESS); + rockettest_check_expr_true(result == W_SUCCESS); // Print the current iteration and values printf("Iteration %2d: Low-Pass Value = %.4f | Expected ~ %.4f\n", i, low_pass_value, expected); // Verify the correctness of the low-pass update - rockettest_assert(fabs(low_pass_value - expected) < EPSILON); + rockettest_check_expr_true(fabs(low_pass_value - expected) < EPSILON); } printf("\nAll iterations completed successfully.\n\n"); // Test with alpha out of range result = update_low_pass(-0.1, new_input_value, &low_pass_value); - rockettest_assert(result == W_INVALID_PARAM); + rockettest_check_expr_true(result == W_INVALID_PARAM); printf("Invalid alpha (negative) test passed.\n"); result = update_low_pass(1.1, new_input_value, &low_pass_value); - rockettest_assert(result == W_INVALID_PARAM); + rockettest_check_expr_true(result == W_INVALID_PARAM); printf("Invalid alpha (greater than 1) test passed.\n"); // Test with NULL low_pass_value result = update_low_pass(alpha, new_input_value, NULL); - rockettest_assert(result == W_INVALID_PARAM); + rockettest_check_expr_true(result == W_INVALID_PARAM); printf("Null low_pass_value test passed.\n"); return test_passed; diff --git a/tests/test_mbr.cpp b/tests/test_mbr.cpp index a268d0f7..7eb0a6d7 100644 --- a/tests/test_mbr.cpp +++ b/tests/test_mbr.cpp @@ -31,23 +31,27 @@ class mbr_test : rockettest_test { entry[11] = 0x00; // LBA high byte // Test with invalid boot signature - rockettest_assert(mbr_parse(first_sector, partition_type, §or_lba) == W_FAILURE); + rockettest_check_expr_true(mbr_parse(first_sector, partition_type, §or_lba) == + W_FAILURE); uint8_t *boot_signature = first_sector + 0x1FE; boot_signature[0] = 0x55; boot_signature[1] = 0xAA; // Test with valid input - rockettest_assert(mbr_parse(first_sector, partition_type, §or_lba) == W_SUCCESS); + rockettest_check_expr_true(mbr_parse(first_sector, partition_type, §or_lba) == + W_SUCCESS); // Test with invalid input (NULL first sector) - rockettest_assert(mbr_parse(nullptr, partition_type, §or_lba) == W_INVALID_PARAM); + rockettest_check_expr_true(mbr_parse(nullptr, partition_type, §or_lba) == + W_INVALID_PARAM); // Test with invalid input (NULL LBA) - rockettest_assert(mbr_parse(first_sector, partition_type, nullptr) == W_INVALID_PARAM); + rockettest_check_expr_true(mbr_parse(first_sector, partition_type, nullptr) == + W_INVALID_PARAM); // Test with a partition type that cannot be found - rockettest_assert(mbr_parse(first_sector, 0x06, §or_lba) == W_FAILURE); + rockettest_check_expr_true(mbr_parse(first_sector, 0x06, §or_lba) == W_FAILURE); return test_passed; } }; -mbr_test mbr_test_inst; \ No newline at end of file +mbr_test mbr_test_inst; From e7f23f4c5e29c4d4243f2f648d9d5c31777e7cd6 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Fri, 20 Feb 2026 06:27:33 -0500 Subject: [PATCH 065/108] Add support for assert testing --- common/crc8.c | 3 +++ include/common.h | 32 ++++++++++++++++++++++++++++++++ tests/Makefile | 3 +++ tests/test_crc8.cpp | 25 +++++++++++++++++++++++++ 4 files changed, 63 insertions(+) create mode 100644 tests/test_crc8.cpp diff --git a/common/crc8.c b/common/crc8.c index 35d79d43..40d08c20 100644 --- a/common/crc8.c +++ b/common/crc8.c @@ -1,6 +1,8 @@ #include #include +#include "common.h" + // crc table used for calculation static uint8_t table[256] = { 0x00, 0x07, 0x0e, 0x09, 0x1c, 0x1b, 0x12, 0x15, 0x38, 0x3f, 0x36, 0x31, 0x24, 0x23, 0x2a, 0x2d, @@ -21,6 +23,7 @@ static uint8_t table[256] = { 0xde, 0xd9, 0xd0, 0xd7, 0xc2, 0xc5, 0xcc, 0xcb, 0xe6, 0xe1, 0xe8, 0xef, 0xfa, 0xfd, 0xf4, 0xf3}; uint8_t crc8_checksum(const uint8_t *pdata, size_t nbytes, uint8_t crc) { + w_assert(pdata); while (nbytes > 0) { crc = table[(crc ^ *pdata++) & 0xff]; --nbytes; diff --git a/include/common.h b/include/common.h index 6c5056dd..64deb5f7 100644 --- a/include/common.h +++ b/include/common.h @@ -25,6 +25,8 @@ typedef enum { W_OVERFLOW } w_status_t; +#ifndef UNIT_TEST + // Assertion Macro #ifdef __cplusplus extern "C" { @@ -64,4 +66,34 @@ void w_assert_fail(const char *file, int line, const char *statement); #endif +#else + +#ifdef __cplusplus + +extern void rocketlib_assert_pass_cpp(const char *file, int line, const char *statement); +extern void rocketlib_assert_fail_cpp(const char *file, int line, const char *statement); + +#define w_assert(statement) \ + if (statement) { \ + rocketlib_assert_pass_cpp(__FILE__, __LINE__, #statement); \ + } else { \ + rocketlib_assert_fail_cpp(__FILE__, __LINE__, #statement); \ + } + +#else + +extern void rocketlib_assert_pass_c(const char *file, int line, const char *statement); +extern void rocketlib_assert_fail_c(const char *file, int line, const char *statement); + +#define w_assert(statement) \ + if (statement) { \ + rocketlib_assert_pass_c(__FILE__, __LINE__, #statement); \ + } else { \ + rocketlib_assert_fail_c(__FILE__, __LINE__, #statement); \ + } + +#endif + +#endif + #endif diff --git a/tests/Makefile b/tests/Makefile index b9733041..9a137c4c 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -6,6 +6,7 @@ CFLAGS := \ -Wextra \ -pedantic \ -MMD \ + -DUNIT_TEST \ -I$(ROCKETLIB_PATH)/include CXXFLAGS := \ @@ -14,6 +15,7 @@ CXXFLAGS := \ -Wextra \ -pedantic \ -MMD \ + -DUNIT_TEST \ -I$(ROCKETLIB_PATH)/include ifeq ($(COVERAGE), 1) @@ -51,6 +53,7 @@ ROCKETLIB_SRCS := \ TEST_SRCS := \ rockettest.cpp \ + test_crc8.cpp \ test_low_pass_filter.cpp \ test_mbr.cpp diff --git a/tests/test_crc8.cpp b/tests/test_crc8.cpp new file mode 100644 index 00000000..5558afe5 --- /dev/null +++ b/tests/test_crc8.cpp @@ -0,0 +1,25 @@ +#include + +#include "common.h" +#include "crc8.h" + +#include "rockettest.hpp" + +class crc8_test : rockettest_test { +public: + crc8_test() : rockettest_test("crc8_test") {} + + bool run_test() override { + bool test_passed = true; + + rockettest_check_assert_triggered( + [] { crc8_checksum(nullptr, 0, 0); }); // nullptr reject with zero input size + + rockettest_check_assert_triggered( + [] { crc8_checksum(nullptr, 5, 0); }); // nullptr reject with not-zero input size + + return test_passed; + } +}; + +crc8_test crc8_test_inst; From 087bb7b84229bf390a432e07456ecc13021df978 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Fri, 20 Feb 2026 06:36:30 -0500 Subject: [PATCH 066/108] Add a CRC8 calculation test --- tests/test_crc8.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_crc8.cpp b/tests/test_crc8.cpp index 5558afe5..4b6c14ee 100644 --- a/tests/test_crc8.cpp +++ b/tests/test_crc8.cpp @@ -16,7 +16,10 @@ class crc8_test : rockettest_test { [] { crc8_checksum(nullptr, 0, 0); }); // nullptr reject with zero input size rockettest_check_assert_triggered( - [] { crc8_checksum(nullptr, 5, 0); }); // nullptr reject with not-zero input size + [] { crc8_checksum(nullptr, 5, 0); }); // nullptr reject with non-zero input size + + const uint8_t input[5] = {'A', 'B', 'C', 'D', 'E'}; + rockettest_check_expr_true(crc8_checksum(input, sizeof(input), 0) == 0xf5); return test_passed; } From 116ec82a3cb43ad4671d0d705c58f0ac8eeb6e9c Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Fri, 6 Mar 2026 18:59:30 -0500 Subject: [PATCH 067/108] Move makefile to root directory --- {tests => rockettest}/rockettest.cpp | 0 {tests => rockettest}/rockettest.hpp | 0 tests/Makefile | 91 ---------------------------- 3 files changed, 91 deletions(-) rename {tests => rockettest}/rockettest.cpp (100%) rename {tests => rockettest}/rockettest.hpp (100%) delete mode 100644 tests/Makefile diff --git a/tests/rockettest.cpp b/rockettest/rockettest.cpp similarity index 100% rename from tests/rockettest.cpp rename to rockettest/rockettest.cpp diff --git a/tests/rockettest.hpp b/rockettest/rockettest.hpp similarity index 100% rename from tests/rockettest.hpp rename to rockettest/rockettest.hpp diff --git a/tests/Makefile b/tests/Makefile deleted file mode 100644 index 9a137c4c..00000000 --- a/tests/Makefile +++ /dev/null @@ -1,91 +0,0 @@ -ROCKETLIB_PATH := .. - -CFLAGS := \ - -std=c99 \ - -Wall \ - -Wextra \ - -pedantic \ - -MMD \ - -DUNIT_TEST \ - -I$(ROCKETLIB_PATH)/include - -CXXFLAGS := \ - -std=c++20 \ - -Wall \ - -Wextra \ - -pedantic \ - -MMD \ - -DUNIT_TEST \ - -I$(ROCKETLIB_PATH)/include - -ifeq ($(COVERAGE), 1) - -CFLAGS += \ - -fprofile-arcs \ - -ftest-coverage - -CXXFLAGS += \ - -fprofile-arcs \ - -ftest-coverage - -LDFLAGS += -Wl,-lgcov - -endif - -ifeq ($(DEBUG), 1) - -CFLAGS += -Og -g - -CXXFLAGS += -Og -g - -else - -CFLAGS += -O2 - -CXXFLAGS += -O2 - -endif - -ROCKETLIB_SRCS := \ - $(ROCKETLIB_PATH)/common/crc8.c \ - $(ROCKETLIB_PATH)/common/low_pass_filter.c \ - $(ROCKETLIB_PATH)/common/mbr.c - -TEST_SRCS := \ - rockettest.cpp \ - test_crc8.cpp \ - test_low_pass_filter.cpp \ - test_mbr.cpp - -ROCKETLIB_OBJS = $(ROCKETLIB_SRCS:.c=.o) -ROCKETLIB_DEPS = $(ROCKETLIB_SRCS:.c=.d) - -TEST_OBJS = $(TEST_SRCS:.cpp=.o) -TEST_DEPS = $(TEST_SRCS:.cpp=.d) - -unit_test: $(ROCKETLIB_OBJS) $(TEST_OBJS) - $(CXX) $^ $(LDFLAGS) -o $@ - -.PHONY: run_test -run_test: unit_test - ./unit_test - -ifeq ($(COVERAGE), 1) - -coverage.info: run_test - lcov --capture --branch-coverage --no-external --directory ../common --directory . -o $@ - -coverage-filtered.info: coverage.info - lcov --remove $^ "*/tests/*" -o $@ --branch-coverage - -html: coverage-filtered.info - genhtml $^ --flat --branch-coverage --output-directory $@ - -endif - --include $(ROCKETLIB_DEPS) --include $(TEST_DEPS) - -.PHONY: clean -clean: - rm -rf $(ROCKETLIB_OBJS) $(ROCKETLIB_DEPS) $(TEST_OBJS) $(TEST_DEPS) *.o ../common/*.gcda ../common/*.gcno *.gcda *.gcno unit_test *.info html From b3ec387740705b4a9508b3d3614f1f9c8591bc95 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Fri, 6 Mar 2026 19:05:22 -0500 Subject: [PATCH 068/108] enable InsertNewlineAtEOF clang-format option --- .clang-format | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.clang-format b/.clang-format index 5f4c94ce..5d422766 100644 --- a/.clang-format +++ b/.clang-format @@ -153,7 +153,7 @@ IndentRequiresClause: true IndentWidth: 4 IndentWrappedFunctionNames: false InsertBraces: true -InsertNewlineAtEOF: false +InsertNewlineAtEOF: true InsertTrailingCommas: None IntegerLiteralSeparator: Binary: 0 From 2dfd0526fb304f68a954e3e61484baad9a91e4c1 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Sat, 7 Mar 2026 15:13:09 -0500 Subject: [PATCH 069/108] Create a separate build directory --- flows/firmware-library.mk | 116 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 flows/firmware-library.mk diff --git a/flows/firmware-library.mk b/flows/firmware-library.mk new file mode 100644 index 00000000..2a17373e --- /dev/null +++ b/flows/firmware-library.mk @@ -0,0 +1,116 @@ +CLANG_FORMAT := clang-format +CLANG_TIDY := clang-tidy + +INCLUDE_PATH_FLAGS := $(foreach inc, $(INCLUDE_PATH), $(addprefix -I, $(inc))) + +C_CXX_FLAGS := \ + $(INCLUDE_PATH_FLAGS) \ + -Wall \ + -Wextra \ + -pedantic \ + -MMD \ + -DUNIT_TEST + +CFLAGS := \ + $(C_CXX_FLAGS) \ + -std=c99 + +CXXFLAGS := \ + $(C_CXX_FLAGS) \ + -std=c++20 \ + -Irockettest + +CLANG_TIDY_FLAGS := \ + --warnings-as-errors="*" \ + --checks="clang-*,misc-*" \ + --extra-arg-before="-std=c99" \ + --extra-arg-before="-pedantic" \ + --extra-arg-before="-Iinclude" + +ifeq ($(COVERAGE), 1) + +CFLAGS += \ + -fprofile-arcs \ + -ftest-coverage + +CXXFLAGS += \ + -fprofile-arcs \ + -ftest-coverage + +LDFLAGS += -Wl,-lgcov + +endif + +ifeq ($(DEBUG), 1) + +CFLAGS += -Og -g + +CXXFLAGS += -Og -g + +else + +CFLAGS += -O2 + +CXXFLAGS += -O2 + +endif + +CPP_SRCS := \ + rockettest/rockettest.cpp \ + $(TEST_SRCS) + +ifeq ($(COVERAGE), 1) +TEST_BUILD_DIR := build/test-cov +else +TEST_BUILD_DIR := build/test +endif + +COMMON_C_OBJS = $(patsubst %.c,$(TEST_BUILD_DIR)/%.o,$(COMMON_C_SRCS)) +COMMON_C_DEPS = $(COMMON_C_SRCS:.c=.d) + +CPP_OBJS = $(patsubst %.cpp,$(TEST_BUILD_DIR)/%.o,$(CPP_SRCS)) +CPP_DEPS = $(CPP_SRCS:.cpp=.d) + +$(TEST_BUILD_DIR)/%.o: %.c + @mkdir -p $(dir $@) + $(CC) $(CFLAGS) -c $< -o $@ + +$(TEST_BUILD_DIR)/%.o: %.cpp + @mkdir -p $(dir $@) + $(CXX) $(CXXFLAGS) -c $< -o $@ + +$(TEST_BUILD_DIR)/unit_test: $(COMMON_C_OBJS) $(CPP_OBJS) + @mkdir -p $(dir $@) + $(CXX) $^ $(LDFLAGS) -o $@ + +.PHONY: run_test +run_test: $(TEST_BUILD_DIR)/unit_test + ./$(TEST_BUILD_DIR)/unit_test + +ifeq ($(COVERAGE), 1) + +$(TEST_BUILD_DIR)/coverage.info: run_test + lcov --capture --branch-coverage --mcdc-coverage --no-external --directory . -o $@ + +$(TEST_BUILD_DIR)/coverage-filtered.info: $(TEST_BUILD_DIR)/coverage.info + lcov --remove $^ "*/tests/*" "*/rockettest/*" -o $@ --branch-coverage --mcdc-coverage + +$(TEST_BUILD_DIR)/html: $(TEST_BUILD_DIR)/coverage-filtered.info + genhtml $^ --flat --branch-coverage --mcdc-coverage --output-directory $@ + +endif + +.PHONY: lint +lint: + $(CLANG_TIDY) $(CLANG_TIDY_FLAGS) $(COMMON_C_SRCS) $(COMMON_C_HEADERS) + +.PHONY: format +format: + $(CLANG_FORMAT) -i $(COMMON_C_SRCS) $(COMMON_C_HEADERS) $(PIC18_C_SRCS) $(PIC18_C_HEADERS) $(STM32H7_C_SRCS) $(STM32H7_C_HEADERS) $(TEST_SRCS) + +-include $(COMMON_C_DEPS) +-include $(CPP_DEPS) + +.PHONY: clean +clean: + rm -rf build From e23b162ae3160c2825c2bdd6ffa268fdcdf83c8d Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Sat, 7 Mar 2026 15:35:55 -0500 Subject: [PATCH 070/108] Enable MC/DC code coverage --- flows/firmware-library.mk | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/flows/firmware-library.mk b/flows/firmware-library.mk index 2a17373e..e6b758cf 100644 --- a/flows/firmware-library.mk +++ b/flows/firmware-library.mk @@ -31,7 +31,9 @@ ifeq ($(COVERAGE), 1) CFLAGS += \ -fprofile-arcs \ - -ftest-coverage + -ftest-coverage \ + -fcondition-coverage \ + -fpath-coverage CXXFLAGS += \ -fprofile-arcs \ From a6f70af3f4ecbe0e0febaf3a6fd43920397f1354 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Sat, 7 Mar 2026 16:06:13 -0500 Subject: [PATCH 071/108] refactor rockettest path handling --- flows/firmware-library.mk | 57 +++++++++++++++------------------------ 1 file changed, 22 insertions(+), 35 deletions(-) diff --git a/flows/firmware-library.mk b/flows/firmware-library.mk index e6b758cf..9f24ddc5 100644 --- a/flows/firmware-library.mk +++ b/flows/firmware-library.mk @@ -1,16 +1,33 @@ CLANG_FORMAT := clang-format CLANG_TIDY := clang-tidy -INCLUDE_PATH_FLAGS := $(foreach inc, $(INCLUDE_PATH), $(addprefix -I, $(inc))) +INCLUDE_PATH_C_CXX_FLAGS := $(foreach inc, $(INCLUDE_PATH), $(addprefix -I, $(inc))) +INCLUDE_PATH_CLANG_TIDY_FLAGS := $(foreach inc, $(INCLUDE_PATH), $(addprefix --extra-arg-before="-I, $(addsuffix ", $(inc)))) C_CXX_FLAGS := \ - $(INCLUDE_PATH_FLAGS) \ + $(INCLUDE_PATH_C_CXX_FLAGS) \ -Wall \ -Wextra \ -pedantic \ -MMD \ -DUNIT_TEST +ifeq ($(DEBUG), 1) +C_CXX_FLAGS += -Og -g +else +C_CXX_FLAGS += -O2 +endif + +ifeq ($(COVERAGE), 1) +C_CXX_FLAGS += \ + -fprofile-arcs \ + -ftest-coverage \ + -fcondition-coverage \ + -fpath-coverage + +LDFLAGS += -Wl,-lgcov +endif + CFLAGS := \ $(C_CXX_FLAGS) \ -std=c99 @@ -18,47 +35,17 @@ CFLAGS := \ CXXFLAGS := \ $(C_CXX_FLAGS) \ -std=c++20 \ - -Irockettest + -I$(ROCKETTEST_PATH) CLANG_TIDY_FLAGS := \ --warnings-as-errors="*" \ --checks="clang-*,misc-*" \ --extra-arg-before="-std=c99" \ --extra-arg-before="-pedantic" \ - --extra-arg-before="-Iinclude" - -ifeq ($(COVERAGE), 1) - -CFLAGS += \ - -fprofile-arcs \ - -ftest-coverage \ - -fcondition-coverage \ - -fpath-coverage - -CXXFLAGS += \ - -fprofile-arcs \ - -ftest-coverage - -LDFLAGS += -Wl,-lgcov - -endif - -ifeq ($(DEBUG), 1) - -CFLAGS += -Og -g - -CXXFLAGS += -Og -g - -else - -CFLAGS += -O2 - -CXXFLAGS += -O2 - -endif + $(INCLUDE_PATH_CLANG_TIDY_FLAGS) CPP_SRCS := \ - rockettest/rockettest.cpp \ + $(ROCKETTEST_PATH)/rockettest.cpp \ $(TEST_SRCS) ifeq ($(COVERAGE), 1) From 72c3277448e9ef4a014c7f38feceacc9d78fdafb Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Sat, 7 Mar 2026 16:27:56 -0500 Subject: [PATCH 072/108] Update rockettest related makefile variable --- flows/firmware-library.mk | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/flows/firmware-library.mk b/flows/firmware-library.mk index 9f24ddc5..4cccc4bd 100644 --- a/flows/firmware-library.mk +++ b/flows/firmware-library.mk @@ -1,11 +1,11 @@ CLANG_FORMAT := clang-format CLANG_TIDY := clang-tidy -INCLUDE_PATH_C_CXX_FLAGS := $(foreach inc, $(INCLUDE_PATH), $(addprefix -I, $(inc))) -INCLUDE_PATH_CLANG_TIDY_FLAGS := $(foreach inc, $(INCLUDE_PATH), $(addprefix --extra-arg-before="-I, $(addsuffix ", $(inc)))) +INCLUDE_PATHS_C_CXX_FLAGS := $(foreach inc, $(INCLUDE_PATHS), $(addprefix -I, $(inc))) +INCLUDE_PATHS_CLANG_TIDY_FLAGS := $(foreach inc, $(INCLUDE_PATHS), $(addprefix --extra-arg-before="-I, $(addsuffix ", $(inc)))) C_CXX_FLAGS := \ - $(INCLUDE_PATH_C_CXX_FLAGS) \ + $(INCLUDE_PATHS_C_CXX_FLAGS) \ -Wall \ -Wextra \ -pedantic \ @@ -35,17 +35,17 @@ CFLAGS := \ CXXFLAGS := \ $(C_CXX_FLAGS) \ -std=c++20 \ - -I$(ROCKETTEST_PATH) + -I$(ROCKETTEST_INCLUDE_PATH) CLANG_TIDY_FLAGS := \ --warnings-as-errors="*" \ --checks="clang-*,misc-*" \ --extra-arg-before="-std=c99" \ --extra-arg-before="-pedantic" \ - $(INCLUDE_PATH_CLANG_TIDY_FLAGS) + $(INCLUDE_PATHS_CLANG_TIDY_FLAGS) CPP_SRCS := \ - $(ROCKETTEST_PATH)/rockettest.cpp \ + $(ROCKETTEST_SRCS) \ $(TEST_SRCS) ifeq ($(COVERAGE), 1) @@ -95,7 +95,7 @@ lint: .PHONY: format format: - $(CLANG_FORMAT) -i $(COMMON_C_SRCS) $(COMMON_C_HEADERS) $(PIC18_C_SRCS) $(PIC18_C_HEADERS) $(STM32H7_C_SRCS) $(STM32H7_C_HEADERS) $(TEST_SRCS) + $(CLANG_FORMAT) -i $(COMMON_C_SRCS) $(COMMON_C_HEADERS) $(PIC18_C_SRCS) $(PIC18_C_HEADERS) $(STM32H7_C_SRCS) $(STM32H7_C_HEADERS) $(TEST_SRCS) $(ROCKETTEST_SRCS) $(ROCKETTEST_HEADERS) -include $(COMMON_C_DEPS) -include $(CPP_DEPS) From c03f86e6448ea5d92fac5e84d45c639cec36f2f8 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Sun, 8 Mar 2026 12:15:19 -0400 Subject: [PATCH 073/108] Add a function in rockettest to generate random integers in range --- rockettest/rockettest.hpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/rockettest/rockettest.hpp b/rockettest/rockettest.hpp index d9801c39..28cfb444 100644 --- a/rockettest/rockettest.hpp +++ b/rockettest/rockettest.hpp @@ -28,10 +28,16 @@ test_passed = false; \ } -template T rockettest_rand() { +template T rockettest_rand_field() { return static_cast(std::rand() & mask); } +// Generate a random number in [min,max) +template T rockettest_rand_range(T min, T max) { + return static_cast((std::rand() % (static_cast(max) - static_cast(min))) + + static_cast(min)); +} + class rockettest_test { const char *name; From c815f4a93639981811273d6615146a6d267c57b4 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Tue, 10 Mar 2026 21:20:23 -0400 Subject: [PATCH 074/108] Add a clang-format check makefile target --- flows/firmware-library.mk | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/flows/firmware-library.mk b/flows/firmware-library.mk index 4cccc4bd..e1f00b1a 100644 --- a/flows/firmware-library.mk +++ b/flows/firmware-library.mk @@ -89,14 +89,26 @@ $(TEST_BUILD_DIR)/html: $(TEST_BUILD_DIR)/coverage-filtered.info endif +#################### +# Linting +#################### + .PHONY: lint lint: $(CLANG_TIDY) $(CLANG_TIDY_FLAGS) $(COMMON_C_SRCS) $(COMMON_C_HEADERS) +#################### +# Formatting +#################### + .PHONY: format format: $(CLANG_FORMAT) -i $(COMMON_C_SRCS) $(COMMON_C_HEADERS) $(PIC18_C_SRCS) $(PIC18_C_HEADERS) $(STM32H7_C_SRCS) $(STM32H7_C_HEADERS) $(TEST_SRCS) $(ROCKETTEST_SRCS) $(ROCKETTEST_HEADERS) +.PHONY: format-check +format-check: + $(CLANG_FORMAT) --dry-run -Werror $(COMMON_C_SRCS) $(COMMON_C_HEADERS) $(PIC18_C_SRCS) $(PIC18_C_HEADERS) $(STM32H7_C_SRCS) $(STM32H7_C_HEADERS) $(TEST_SRCS) $(ROCKETTEST_SRCS) $(ROCKETTEST_HEADERS) + -include $(COMMON_C_DEPS) -include $(CPP_DEPS) From 6bf0ae80fd757917abd48610af7875aa404ad5ac Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Tue, 10 Mar 2026 21:44:51 -0400 Subject: [PATCH 075/108] Add xc8 and xc16 compile makefile target --- flows/firmware-library.mk | 81 +++++++++++++++++++++++++++++++++------ 1 file changed, 69 insertions(+), 12 deletions(-) diff --git a/flows/firmware-library.mk b/flows/firmware-library.mk index e1f00b1a..8d6b501b 100644 --- a/flows/firmware-library.mk +++ b/flows/firmware-library.mk @@ -37,6 +37,15 @@ CXXFLAGS := \ -std=c++20 \ -I$(ROCKETTEST_INCLUDE_PATH) +XC8_C_FLAGS := \ + -mcpu=18F26K83 \ + -mdfp=xc8 \ + -Iinclude \ + -c \ + -mwarn=-9 \ + -std=c99 \ + -Wpedantic + CLANG_TIDY_FLAGS := \ --warnings-as-errors="*" \ --checks="clang-*,misc-*" \ @@ -49,46 +58,90 @@ CPP_SRCS := \ $(TEST_SRCS) ifeq ($(COVERAGE), 1) -TEST_BUILD_DIR := build/test-cov +BUILD_DIR := build/test-cov else -TEST_BUILD_DIR := build/test +BUILD_DIR := build/test endif -COMMON_C_OBJS = $(patsubst %.c,$(TEST_BUILD_DIR)/%.o,$(COMMON_C_SRCS)) +COMMON_C_OBJS = $(patsubst %.c,$(BUILD_DIR)/%.o,$(COMMON_C_SRCS)) COMMON_C_DEPS = $(COMMON_C_SRCS:.c=.d) -CPP_OBJS = $(patsubst %.cpp,$(TEST_BUILD_DIR)/%.o,$(CPP_SRCS)) +CPP_OBJS = $(patsubst %.cpp,$(BUILD_DIR)/%.o,$(CPP_SRCS)) CPP_DEPS = $(CPP_SRCS:.cpp=.d) -$(TEST_BUILD_DIR)/%.o: %.c +####################### +# XC8 Compile Variables +####################### + +XC8 := /opt/microchip/xc8/v3.10/bin/xc8-cc +xc8-build: CC := $(XC8) +xc8-build: CFLAGS := -mcpu=18F26K83 -mdfp=xc8 -Iinclude -mwarn=-9 -std=c99 -Wpedantic +xc8-build: BUILD_DIR := build/xc8 + +######################## +# XC16 Compile Variables +######################## + +XC16 := /opt/microchip/xc16/v2.10/bin/xc16-gcc +xc16-build: CC := $(XC16) +xc16-build: CFLAGS := -mcpu=33EP256GP502 -Iinclude -std=c99 -Wall +xc16-build: BUILD_DIR := build/xc16 + +###################### +# Object files compile +###################### +$(BUILD_DIR)/%.o: %.c @mkdir -p $(dir $@) $(CC) $(CFLAGS) -c $< -o $@ -$(TEST_BUILD_DIR)/%.o: %.cpp +$(BUILD_DIR)/%.o: %.cpp @mkdir -p $(dir $@) $(CXX) $(CXXFLAGS) -c $< -o $@ -$(TEST_BUILD_DIR)/unit_test: $(COMMON_C_OBJS) $(CPP_OBJS) +#################### +# Unit Test Build +#################### +$(BUILD_DIR)/unit_test: $(COMMON_C_OBJS) $(CPP_OBJS) @mkdir -p $(dir $@) $(CXX) $^ $(LDFLAGS) -o $@ .PHONY: run_test -run_test: $(TEST_BUILD_DIR)/unit_test - ./$(TEST_BUILD_DIR)/unit_test +run_test: $(BUILD_DIR)/unit_test + ./$(BUILD_DIR)/unit_test + +############################### +# Unit Test with Coverage Build +############################### ifeq ($(COVERAGE), 1) -$(TEST_BUILD_DIR)/coverage.info: run_test +$(BUILD_DIR)/coverage.info: run_test lcov --capture --branch-coverage --mcdc-coverage --no-external --directory . -o $@ -$(TEST_BUILD_DIR)/coverage-filtered.info: $(TEST_BUILD_DIR)/coverage.info +$(BUILD_DIR)/coverage-filtered.info: $(BUILD_DIR)/coverage.info lcov --remove $^ "*/tests/*" "*/rockettest/*" -o $@ --branch-coverage --mcdc-coverage -$(TEST_BUILD_DIR)/html: $(TEST_BUILD_DIR)/coverage-filtered.info +$(BUILD_DIR)/html: $(BUILD_DIR)/coverage-filtered.info genhtml $^ --flat --branch-coverage --mcdc-coverage --output-directory $@ endif +#################### +# XC8 Build +#################### + +.PHONY: xc8-build +xc8-build: $(COMMON_C_OBJS) + echo "$(CC) $(COMMON_C_OBJS)" + +#################### +# XC16 Build +#################### + +.PHONY: xc6-build +xc16-build: $(COMMON_C_OBJS) + echo "$(CC) $(COMMON_C_OBJS)" + #################### # Linting #################### @@ -112,6 +165,10 @@ format-check: -include $(COMMON_C_DEPS) -include $(CPP_DEPS) +#################### +# Clean +#################### + .PHONY: clean clean: rm -rf build From 4e155153f9a034f37ea055fbca1d5971c4788657 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Tue, 10 Mar 2026 21:50:37 -0400 Subject: [PATCH 076/108] Generalize XC8 compiler DFP path --- flows/firmware-library.mk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flows/firmware-library.mk b/flows/firmware-library.mk index 8d6b501b..bf591d1f 100644 --- a/flows/firmware-library.mk +++ b/flows/firmware-library.mk @@ -75,7 +75,7 @@ CPP_DEPS = $(CPP_SRCS:.cpp=.d) XC8 := /opt/microchip/xc8/v3.10/bin/xc8-cc xc8-build: CC := $(XC8) -xc8-build: CFLAGS := -mcpu=18F26K83 -mdfp=xc8 -Iinclude -mwarn=-9 -std=c99 -Wpedantic +xc8-build: CFLAGS := -mcpu=18F26K83 -mdfp=$(XC8_DFP_PATH) -Iinclude -mwarn=-9 -std=c99 -Wpedantic xc8-build: BUILD_DIR := build/xc8 ######################## @@ -132,7 +132,7 @@ endif .PHONY: xc8-build xc8-build: $(COMMON_C_OBJS) - echo "$(CC) $(COMMON_C_OBJS)" + true #################### # XC16 Build @@ -140,7 +140,7 @@ xc8-build: $(COMMON_C_OBJS) .PHONY: xc6-build xc16-build: $(COMMON_C_OBJS) - echo "$(CC) $(COMMON_C_OBJS)" + true #################### # Linting From 3ad561389ab2505981663cd5ded393700aedcfba Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Wed, 11 Mar 2026 08:08:42 -0400 Subject: [PATCH 077/108] refactor unit test section of makefile --- flows/firmware-library.mk | 108 ++++++++++++++++++++++++-------------- 1 file changed, 69 insertions(+), 39 deletions(-) diff --git a/flows/firmware-library.mk b/flows/firmware-library.mk index bf591d1f..89cff3c4 100644 --- a/flows/firmware-library.mk +++ b/flows/firmware-library.mk @@ -1,8 +1,8 @@ -CLANG_FORMAT := clang-format -CLANG_TIDY := clang-tidy +########################### +# Common Build Variables +########################### INCLUDE_PATHS_C_CXX_FLAGS := $(foreach inc, $(INCLUDE_PATHS), $(addprefix -I, $(inc))) -INCLUDE_PATHS_CLANG_TIDY_FLAGS := $(foreach inc, $(INCLUDE_PATHS), $(addprefix --extra-arg-before="-I, $(addsuffix ", $(inc)))) C_CXX_FLAGS := \ $(INCLUDE_PATHS_C_CXX_FLAGS) \ @@ -37,59 +37,84 @@ CXXFLAGS := \ -std=c++20 \ -I$(ROCKETTEST_INCLUDE_PATH) -XC8_C_FLAGS := \ - -mcpu=18F26K83 \ - -mdfp=xc8 \ - -Iinclude \ - -c \ - -mwarn=-9 \ - -std=c99 \ - -Wpedantic - -CLANG_TIDY_FLAGS := \ - --warnings-as-errors="*" \ - --checks="clang-*,misc-*" \ - --extra-arg-before="-std=c99" \ - --extra-arg-before="-pedantic" \ - $(INCLUDE_PATHS_CLANG_TIDY_FLAGS) CPP_SRCS := \ $(ROCKETTEST_SRCS) \ $(TEST_SRCS) -ifeq ($(COVERAGE), 1) -BUILD_DIR := build/test-cov -else -BUILD_DIR := build/test +ifeq ($(filter run-test,$(MAKECMDGOALS)),run-test) + BUILD_DIR := build/test-cov endif -COMMON_C_OBJS = $(patsubst %.c,$(BUILD_DIR)/%.o,$(COMMON_C_SRCS)) -COMMON_C_DEPS = $(COMMON_C_SRCS:.c=.d) +ifeq ($(filter run-test-cov,$(MAKECMDGOALS)),run-test-cov) + BUILD_DIR := build/test-cov +endif -CPP_OBJS = $(patsubst %.cpp,$(BUILD_DIR)/%.o,$(CPP_SRCS)) -CPP_DEPS = $(CPP_SRCS:.cpp=.d) +ifeq ($(filter gen-cov-html,$(MAKECMDGOALS)),gen-cov-html) + BUILD_DIR := build/test-cov +endif ####################### # XC8 Compile Variables ####################### XC8 := /opt/microchip/xc8/v3.10/bin/xc8-cc -xc8-build: CC := $(XC8) -xc8-build: CFLAGS := -mcpu=18F26K83 -mdfp=$(XC8_DFP_PATH) -Iinclude -mwarn=-9 -std=c99 -Wpedantic -xc8-build: BUILD_DIR := build/xc8 + +ifeq ($(filter xc8-build,$(MAKECMDGOALS)),xc8-build) + CC := $(XC8) + CFLAGS := -mcpu=18F26K83 -mdfp=$(XC8_DFP_PATH) -mwarn=-9 -std=c99 -Wpedantic $(INCLUDE_PATHS_C_CXX_FLAGS) + BUILD_DIR := build/xc8 +endif ######################## # XC16 Compile Variables ######################## XC16 := /opt/microchip/xc16/v2.10/bin/xc16-gcc -xc16-build: CC := $(XC16) -xc16-build: CFLAGS := -mcpu=33EP256GP502 -Iinclude -std=c99 -Wall -xc16-build: BUILD_DIR := build/xc16 + +ifeq ($(filter xc16-build,$(MAKECMDGOALS)),xc16-build) + CC := $(XC16) + CFLAGS := -mcpu=33EP256GP502 -std=c99 -Wall $(INCLUDE_PATHS_C_CXX_FLAGS) + BUILD_DIR := build/xc16 +endif + +#################### +# Linting Variables +#################### + +CLANG_TIDY := clang-tidy +INCLUDE_PATHS_CLANG_TIDY_FLAGS := $(foreach inc, $(INCLUDE_PATHS), $(addprefix --extra-arg-before="-I, $(addsuffix ", $(inc)))) + +CLANG_TIDY_FLAGS := \ + --warnings-as-errors="*" \ + --checks="clang-*,misc-*" \ + --extra-arg-before="-std=c99" \ + --extra-arg-before="-pedantic" \ + $(INCLUDE_PATHS_CLANG_TIDY_FLAGS) + +###################### +# Formatting Variables +###################### + +CLANG_FORMAT := clang-format + +########################################### +# Object File and Dependency File Variables +########################################### + +COMMON_C_OBJS = $(patsubst %.c,$(BUILD_DIR)/%.o,$(COMMON_C_SRCS)) +COMMON_C_DEPS = $(COMMON_C_SRCS:.c=.d) + +PIC18_C_OBJS = $(patsubst %.c,$(BUILD_DIR)/%.o,$(PIC18_C_SRCS)) +PIC18_C_DEPS = $(PIC18_C_SRCS:.c=.d) + +CPP_OBJS = $(patsubst %.cpp,$(BUILD_DIR)/%.o,$(CPP_SRCS)) +CPP_DEPS = $(CPP_SRCS:.cpp=.d) ###################### # Object files compile ###################### + $(BUILD_DIR)/%.o: %.c @mkdir -p $(dir $@) $(CC) $(CFLAGS) -c $< -o $@ @@ -101,21 +126,24 @@ $(BUILD_DIR)/%.o: %.cpp #################### # Unit Test Build #################### + $(BUILD_DIR)/unit_test: $(COMMON_C_OBJS) $(CPP_OBJS) @mkdir -p $(dir $@) $(CXX) $^ $(LDFLAGS) -o $@ -.PHONY: run_test -run_test: $(BUILD_DIR)/unit_test +.PHONY: run-test +run-test: $(BUILD_DIR)/unit_test ./$(BUILD_DIR)/unit_test ############################### # Unit Test with Coverage Build ############################### -ifeq ($(COVERAGE), 1) +.PHONY: run-test-cov +run-test-cov: $(BUILD_DIR)/unit_test + ./$(BUILD_DIR)/unit_test -$(BUILD_DIR)/coverage.info: run_test +$(BUILD_DIR)/coverage.info: run-test lcov --capture --branch-coverage --mcdc-coverage --no-external --directory . -o $@ $(BUILD_DIR)/coverage-filtered.info: $(BUILD_DIR)/coverage.info @@ -124,21 +152,23 @@ $(BUILD_DIR)/coverage-filtered.info: $(BUILD_DIR)/coverage.info $(BUILD_DIR)/html: $(BUILD_DIR)/coverage-filtered.info genhtml $^ --flat --branch-coverage --mcdc-coverage --output-directory $@ -endif +.PHONY: gen-cov-html +gen-cov-html: $(BUILD_DIR)/html + true #################### # XC8 Build #################### .PHONY: xc8-build -xc8-build: $(COMMON_C_OBJS) +xc8-build: $(COMMON_C_OBJS) $(PIC18_C_OBJS) true #################### # XC16 Build #################### -.PHONY: xc6-build +.PHONY: xc16-build xc16-build: $(COMMON_C_OBJS) true From ddf98bf016acc372f14a9c71c24a4e644cd2baab Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Wed, 11 Mar 2026 08:21:59 -0400 Subject: [PATCH 078/108] Fully refactor unit test makefile --- flows/firmware-library.mk | 45 ++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/flows/firmware-library.mk b/flows/firmware-library.mk index 89cff3c4..590d92d4 100644 --- a/flows/firmware-library.mk +++ b/flows/firmware-library.mk @@ -1,3 +1,11 @@ +########################### +# Source FIle Path Variables +########################### + +CPP_SRCS := \ + $(ROCKETTEST_SRCS) \ + $(TEST_SRCS) + ########################### # Common Build Variables ########################### @@ -18,14 +26,20 @@ else C_CXX_FLAGS += -O2 endif -ifeq ($(COVERAGE), 1) -C_CXX_FLAGS += \ - -fprofile-arcs \ - -ftest-coverage \ - -fcondition-coverage \ - -fpath-coverage +ifeq ($(filter run-test,$(MAKECMDGOALS)),run-test) + BUILD_DIR := build/test +endif + +ifneq ($(filter run-test-cov gen-cov-html,$(MAKECMDGOALS)),) + BUILD_DIR := build/test-cov -LDFLAGS += -Wl,-lgcov + C_CXX_FLAGS += \ + -fprofile-arcs \ + -ftest-coverage \ + -fcondition-coverage \ + -fpath-coverage + + LDFLAGS += -Wl,-lgcov endif CFLAGS := \ @@ -37,23 +51,6 @@ CXXFLAGS := \ -std=c++20 \ -I$(ROCKETTEST_INCLUDE_PATH) - -CPP_SRCS := \ - $(ROCKETTEST_SRCS) \ - $(TEST_SRCS) - -ifeq ($(filter run-test,$(MAKECMDGOALS)),run-test) - BUILD_DIR := build/test-cov -endif - -ifeq ($(filter run-test-cov,$(MAKECMDGOALS)),run-test-cov) - BUILD_DIR := build/test-cov -endif - -ifeq ($(filter gen-cov-html,$(MAKECMDGOALS)),gen-cov-html) - BUILD_DIR := build/test-cov -endif - ####################### # XC8 Compile Variables ####################### From 57ae9e237f3d4f9e4b09c130c6e2224d369987d5 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Wed, 11 Mar 2026 09:05:14 -0400 Subject: [PATCH 079/108] add a rockettest submodule path make variable --- flows/firmware-library.mk | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/flows/firmware-library.mk b/flows/firmware-library.mk index 590d92d4..d2cf6caa 100644 --- a/flows/firmware-library.mk +++ b/flows/firmware-library.mk @@ -1,7 +1,11 @@ ########################### -# Source FIle Path Variables +# Source File Path Variables ########################### +ROCKETTEST_SRCS := $(ROCKETLIB_SUBMODULE_PATH)/rockettest/rockettest.cpp +ROCKETTEST_HEADERS := $(ROCKETLIB_SUBMODULE_PATH)/rockettest/rockettest.hpp +ROCKETTEST_INCLUDE_PATH := $(ROCKETLIB_SUBMODULE_PATH)/rockettest + CPP_SRCS := \ $(ROCKETTEST_SRCS) \ $(TEST_SRCS) From 92af5a5823debf7f1b8a2b2ff4b3e01df2936a85 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Wed, 11 Mar 2026 19:19:32 -0400 Subject: [PATCH 080/108] specify clang-format config file path --- flows/firmware-library.mk | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/flows/firmware-library.mk b/flows/firmware-library.mk index d2cf6caa..bdb0d2d7 100644 --- a/flows/firmware-library.mk +++ b/flows/firmware-library.mk @@ -16,8 +16,9 @@ CPP_SRCS := \ INCLUDE_PATHS_C_CXX_FLAGS := $(foreach inc, $(INCLUDE_PATHS), $(addprefix -I, $(inc))) -C_CXX_FLAGS := \ +C_CXX_FLAGS += \ $(INCLUDE_PATHS_C_CXX_FLAGS) \ + $(EXTRA_C_CXX_FLAGS) \ -Wall \ -Wextra \ -pedantic \ @@ -191,7 +192,7 @@ format: .PHONY: format-check format-check: - $(CLANG_FORMAT) --dry-run -Werror $(COMMON_C_SRCS) $(COMMON_C_HEADERS) $(PIC18_C_SRCS) $(PIC18_C_HEADERS) $(STM32H7_C_SRCS) $(STM32H7_C_HEADERS) $(TEST_SRCS) $(ROCKETTEST_SRCS) $(ROCKETTEST_HEADERS) + $(CLANG_FORMAT) --dry-run -Werror --style=file:$(ROCKETLIB_SUBMODULE_PATH)/.clang-format $(COMMON_C_SRCS) $(COMMON_C_HEADERS) $(PIC18_C_SRCS) $(PIC18_C_HEADERS) $(STM32H7_C_SRCS) $(STM32H7_C_HEADERS) $(TEST_SRCS) $(ROCKETTEST_SRCS) $(ROCKETTEST_HEADERS) -include $(COMMON_C_DEPS) -include $(CPP_DEPS) From fa03510ff6fe982a8ab4b4e173436dea491b1f5e Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Wed, 11 Mar 2026 19:23:07 -0400 Subject: [PATCH 081/108] Apply user specified C/C++ flags be applied to linting --- flows/firmware-library.mk | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/flows/firmware-library.mk b/flows/firmware-library.mk index bdb0d2d7..f33a5d12 100644 --- a/flows/firmware-library.mk +++ b/flows/firmware-library.mk @@ -86,13 +86,15 @@ endif CLANG_TIDY := clang-tidy INCLUDE_PATHS_CLANG_TIDY_FLAGS := $(foreach inc, $(INCLUDE_PATHS), $(addprefix --extra-arg-before="-I, $(addsuffix ", $(inc)))) +EXTRA_C_CXX_CLANG_TIDY_FLAGS := $(foreach flag, $(EXTRA_C_CXX_FLAGS), $(addprefix --extra-arg-before=", $(addsuffix ", $(flag)))) CLANG_TIDY_FLAGS := \ --warnings-as-errors="*" \ --checks="clang-*,misc-*" \ --extra-arg-before="-std=c99" \ --extra-arg-before="-pedantic" \ - $(INCLUDE_PATHS_CLANG_TIDY_FLAGS) + $(INCLUDE_PATHS_CLANG_TIDY_FLAGS) \ + $(EXTRA_C_CXX_CLANG_TIDY_FLAGS) ###################### # Formatting Variables From e90644bec9160e2436ddcdf428020809fb8c14db Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Wed, 11 Mar 2026 19:26:16 -0400 Subject: [PATCH 082/108] Use user specified C/C++ flags on Microchip xc8 and xc16 compile --- flows/firmware-library.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flows/firmware-library.mk b/flows/firmware-library.mk index f33a5d12..3ecbfc68 100644 --- a/flows/firmware-library.mk +++ b/flows/firmware-library.mk @@ -64,7 +64,7 @@ XC8 := /opt/microchip/xc8/v3.10/bin/xc8-cc ifeq ($(filter xc8-build,$(MAKECMDGOALS)),xc8-build) CC := $(XC8) - CFLAGS := -mcpu=18F26K83 -mdfp=$(XC8_DFP_PATH) -mwarn=-9 -std=c99 -Wpedantic $(INCLUDE_PATHS_C_CXX_FLAGS) + CFLAGS := -mcpu=18F26K83 -mdfp=$(XC8_DFP_PATH) -mwarn=-9 -std=c99 -Wpedantic $(INCLUDE_PATHS_C_CXX_FLAGS) $(EXTRA_C_CXX_FLAGS) BUILD_DIR := build/xc8 endif @@ -76,7 +76,7 @@ XC16 := /opt/microchip/xc16/v2.10/bin/xc16-gcc ifeq ($(filter xc16-build,$(MAKECMDGOALS)),xc16-build) CC := $(XC16) - CFLAGS := -mcpu=33EP256GP502 -std=c99 -Wall $(INCLUDE_PATHS_C_CXX_FLAGS) + CFLAGS := -mcpu=33EP256GP502 -std=c99 -Wall $(INCLUDE_PATHS_C_CXX_FLAGS) $(EXTRA_C_CXX_FLAGS) BUILD_DIR := build/xc16 endif From 74e7a6c099dd3a3fc5210ed606600f15b546c900 Mon Sep 17 00:00:00 2001 From: lukeqin-s <181533015+lukeqin-s@users.noreply.github.com> Date: Mon, 30 Mar 2026 18:31:52 -0400 Subject: [PATCH 083/108] Add CLAMP macro Added a macro to clamp a value within specified bounds. --- include/common.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/common.h b/include/common.h index 64deb5f7..89a85cda 100644 --- a/include/common.h +++ b/include/common.h @@ -96,4 +96,16 @@ extern void rocketlib_assert_fail_c(const char *file, int line, const char *stat #endif +/** + * @brief Clamp a value between a lower and upper bound + * + * @param x The value to clamp + * @param lo The lower bound, inclusive + * @param hi The upper bound, inclusive + * + * Note: This macro evaluates its arguments multiple times, so do NOT do clamp(x++, 0, 255) + * to avoid incrementing x multiple times. + */ +#define CLAMP(x, lo, hi) (((x) < (lo)) ? (lo) : (((x) > (hi)) ? (hi) : (x))) + #endif From 79a1da56c9e9bced18ea84ad52c379ed6c9b0b32 Mon Sep 17 00:00:00 2001 From: lukeqin-s <181533015+lukeqin-s@users.noreply.github.com> Date: Mon, 30 Mar 2026 19:59:57 -0400 Subject: [PATCH 084/108] Changed clamping functions for uint32, int32, and float - Changed to static inline functions - Added #include --- include/common.h | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/include/common.h b/include/common.h index 89a85cda..bd7e1692 100644 --- a/include/common.h +++ b/include/common.h @@ -1,3 +1,5 @@ +#include + #ifndef ROCKETLIB_COMMON_H #define ROCKETLIB_COMMON_H @@ -97,15 +99,39 @@ extern void rocketlib_assert_fail_c(const char *file, int line, const char *stat #endif /** - * @brief Clamp a value between a lower and upper bound + * @brief Clamps a 32 bit unsigned integer between a lower and upper bound. * * @param x The value to clamp * @param lo The lower bound, inclusive * @param hi The upper bound, inclusive + * @return The clamped value + */ +static inline uint32_t clamp_uint32(uint32_t x, uint32_t lo, uint32_t hi) { + return (x < lo) ? lo : ((x > hi) ? hi : x); +} + +/** + * @brief Clamps a 32 bit signed integer between a lower and upper bound. * - * Note: This macro evaluates its arguments multiple times, so do NOT do clamp(x++, 0, 255) - * to avoid incrementing x multiple times. + * @param x The value to clamp + * @param lo The lower bound, inclusive + * @param hi The upper bound, inclusive + * @return The clamped value */ -#define CLAMP(x, lo, hi) (((x) < (lo)) ? (lo) : (((x) > (hi)) ? (hi) : (x))) +static inline int32_t clamp_int32(int32_t x, int32_t lo, int32_t hi) { + return (x < lo) ? lo : ((x > hi) ? hi : x); +} + +/** + * @brief Clamps a 32 bit float between a lower and upper bound. + * + * @param x The value to clamp + * @param lo The lower bound, inclusive + * @param hi The upper bound, inclusive + * @return The clamped value + */ +static inline float clamp_float(float x, float lo, float hi) { + return (x < lo) ? lo : ((x > hi) ? hi : x); +} #endif From f25387d4a3e988a9fb2ac2f01ef53cc880107cff Mon Sep 17 00:00:00 2001 From: unknown <181533015+lukeqin-s@users.noreply.github.com> Date: Mon, 30 Mar 2026 23:17:33 -0400 Subject: [PATCH 085/108] - Added test_map.cpp to test the math functions in common.h. - Changed clamp function if statements to be expanded and more readable. --- include/common.h | 47 ++++++++++----- tests/test_math.cpp | 137 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 170 insertions(+), 14 deletions(-) create mode 100644 tests/test_math.cpp diff --git a/include/common.h b/include/common.h index bd7e1692..eaba5f55 100644 --- a/include/common.h +++ b/include/common.h @@ -1,8 +1,9 @@ -#include - #ifndef ROCKETLIB_COMMON_H #define ROCKETLIB_COMMON_H +#include +#include "math.h" + /// @brief Rocketlib major release number, shall be design cycle year #define ROCKETLIB_VERSION_MAJOR 2026 @@ -102,36 +103,54 @@ extern void rocketlib_assert_fail_c(const char *file, int line, const char *stat * @brief Clamps a 32 bit unsigned integer between a lower and upper bound. * * @param x The value to clamp - * @param lo The lower bound, inclusive - * @param hi The upper bound, inclusive + * @param low The lower bound, inclusive + * @param high The upper bound, inclusive * @return The clamped value */ -static inline uint32_t clamp_uint32(uint32_t x, uint32_t lo, uint32_t hi) { - return (x < lo) ? lo : ((x > hi) ? hi : x); +static inline uint32_t value_clamp_uint32(uint32_t x, uint32_t low, uint32_t high) { + if (x < low) { + return low; + } else if (x > high) { + return high; + } else { + return x; + } } /** * @brief Clamps a 32 bit signed integer between a lower and upper bound. * * @param x The value to clamp - * @param lo The lower bound, inclusive - * @param hi The upper bound, inclusive + * @param low The lower bound, inclusive + * @param high The upper bound, inclusive * @return The clamped value */ -static inline int32_t clamp_int32(int32_t x, int32_t lo, int32_t hi) { - return (x < lo) ? lo : ((x > hi) ? hi : x); +static inline int32_t value_clamp_int32(int32_t x, int32_t low, int32_t high) { + if (x < low) { + return low; + } else if (x > high) { + return high; + } else { + return x; + } } /** * @brief Clamps a 32 bit float between a lower and upper bound. * * @param x The value to clamp - * @param lo The lower bound, inclusive - * @param hi The upper bound, inclusive + * @param low The lower bound, inclusive + * @param high The upper bound, inclusive * @return The clamped value */ -static inline float clamp_float(float x, float lo, float hi) { - return (x < lo) ? lo : ((x > hi) ? hi : x); +static inline float value_clamp_float(float x, float low, float high) { + if (x < low) { + return low; + } else if (x > high) { + return high; + } else { + return x; + } } #endif diff --git a/tests/test_math.cpp b/tests/test_math.cpp new file mode 100644 index 00000000..a0661c1a --- /dev/null +++ b/tests/test_math.cpp @@ -0,0 +1,137 @@ +#include +#include +#include +#include + +#include "common.h" + +#include "rockettest.hpp" + +#include "common/math/math.h" + +class value_clamp_uint32_test : rockettest_test { +public: + value_clamp_uint32_test() : rockettest_test("value_clamp_uint32_test") {} + + bool run_test() override { + bool test_passed = true; + + printf("value_clamp_uint32: in-range and boundary behavior\n"); + rockettest_check_expr_true(value_clamp_uint32(50u, 10u, 100u) == 50u); + rockettest_check_expr_true(value_clamp_uint32(10u, 10u, 100u) == 10u); + rockettest_check_expr_true(value_clamp_uint32(100u, 10u, 100u) == 100u); + + printf("value_clamp_uint32: out-of-range behavior\n"); + rockettest_check_expr_true(value_clamp_uint32(9u, 10u, 100u) == 10u); + rockettest_check_expr_true(value_clamp_uint32(101u, 10u, 100u) == 100u); + + printf("value_clamp_uint32: extreme values\n"); + rockettest_check_expr_true(value_clamp_uint32(0u, 1u, 2u) == 1u); + rockettest_check_expr_true( + value_clamp_uint32(std::numeric_limits::max(), 1u, 2u) == 2u); + rockettest_check_expr_true(value_clamp_uint32(0u, + 0u, + std::numeric_limits::max()) == 0u); + rockettest_check_expr_true(value_clamp_uint32(std::numeric_limits::max(), + 0u, + std::numeric_limits::max()) == + std::numeric_limits::max()); + + printf("value_clamp_uint32: degenerate range\n"); + rockettest_check_expr_true(value_clamp_uint32(0u, 42u, 42u) == 42u); + rockettest_check_expr_true(value_clamp_uint32(42u, 42u, 42u) == 42u); + rockettest_check_expr_true(value_clamp_uint32(100u, 42u, 42u) == 42u); + + return test_passed; + } +}; + +value_clamp_uint32_test value_clamp_uint32_test_inst; + +class value_clamp_int32_test : rockettest_test { +public: + value_clamp_int32_test() : rockettest_test("value_clamp_int32_test") {} + + bool run_test() override { + bool test_passed = true; + + printf("value_clamp_int32: in-range and boundary behavior\n"); + rockettest_check_expr_true(value_clamp_int32(0, -10, 10) == 0); + rockettest_check_expr_true(value_clamp_int32(-10, -10, 10) == -10); + rockettest_check_expr_true(value_clamp_int32(10, -10, 10) == 10); + + printf("value_clamp_int32: out-of-range behavior\n"); + rockettest_check_expr_true(value_clamp_int32(-11, -10, 10) == -10); + rockettest_check_expr_true(value_clamp_int32(11, -10, 10) == 10); + + printf("value_clamp_int32: extreme values\n"); + rockettest_check_expr_true( + value_clamp_int32(std::numeric_limits::min(), -5, 5) == -5); + rockettest_check_expr_true( + value_clamp_int32(std::numeric_limits::max(), -5, 5) == 5); + rockettest_check_expr_true(value_clamp_int32(std::numeric_limits::min(), + std::numeric_limits::min(), + std::numeric_limits::max()) == + std::numeric_limits::min()); + rockettest_check_expr_true(value_clamp_int32(std::numeric_limits::max(), + std::numeric_limits::min(), + std::numeric_limits::max()) == + std::numeric_limits::max()); + + printf("value_clamp_int32: degenerate range\n"); + rockettest_check_expr_true(value_clamp_int32(-100, 7, 7) == 7); + rockettest_check_expr_true(value_clamp_int32(7, 7, 7) == 7); + rockettest_check_expr_true(value_clamp_int32(100, 7, 7) == 7); + + return test_passed; + } +}; + +value_clamp_int32_test value_clamp_int32_test_inst; + +class value_clamp_float_test : rockettest_test { +public: + value_clamp_float_test() : rockettest_test("value_clamp_float_test") {} + + bool run_test() override { + bool test_passed = true; + + printf("value_clamp_float: in-range and boundary behavior\n"); + rockettest_check_expr_true(value_clamp_float(0.5f, -1.0f, 1.0f) == 0.5f); + rockettest_check_expr_true(value_clamp_float(-1.0f, -1.0f, 1.0f) == -1.0f); + rockettest_check_expr_true(value_clamp_float(1.0f, -1.0f, 1.0f) == 1.0f); + + printf("value_clamp_float: out-of-range behavior\n"); + rockettest_check_expr_true(value_clamp_float(-2.0f, -1.0f, 1.0f) == -1.0f); + rockettest_check_expr_true(value_clamp_float(2.0f, -1.0f, 1.0f) == 1.0f); + + printf("value_clamp_float: finite extreme values\n"); + rockettest_check_expr_true(value_clamp_float(std::numeric_limits::lowest(), + -1.0f, + 1.0f) == -1.0f); + rockettest_check_expr_true(value_clamp_float(std::numeric_limits::max(), + -1.0f, + 1.0f) == 1.0f); + + printf("value_clamp_float: infinity behavior\n"); + rockettest_check_expr_true(value_clamp_float(-std::numeric_limits::infinity(), + -10.0f, + 10.0f) == -10.0f); + rockettest_check_expr_true(value_clamp_float(std::numeric_limits::infinity(), + -10.0f, + 10.0f) == 10.0f); + + printf("value_clamp_float: NaN behavior\n"); + const float nan_value = std::numeric_limits::quiet_NaN(); + rockettest_check_expr_true(std::isnan(value_clamp_float(nan_value, -1.0f, 1.0f))); + + printf("value_clamp_float: degenerate range\n"); + rockettest_check_expr_true(value_clamp_float(-5.0f, 3.5f, 3.5f) == 3.5f); + rockettest_check_expr_true(value_clamp_float(3.5f, 3.5f, 3.5f) == 3.5f); + rockettest_check_expr_true(value_clamp_float(9.0f, 3.5f, 3.5f) == 3.5f); + + return test_passed; + } +}; + +value_clamp_float_test value_clamp_float_test_inst; From 382ca3a0972d6e3b8e119cd3225d7d852bcbeed4 Mon Sep 17 00:00:00 2001 From: unknown <181533015+lukeqin-s@users.noreply.github.com> Date: Mon, 30 Mar 2026 23:30:11 -0400 Subject: [PATCH 086/108] - Removed unused include in test_math.cpp and common.h - Added test_math.cpp to Makefile --- include/common.h | 1 - tests/test_math.cpp | 2 -- 2 files changed, 3 deletions(-) diff --git a/include/common.h b/include/common.h index eaba5f55..e55a56c5 100644 --- a/include/common.h +++ b/include/common.h @@ -2,7 +2,6 @@ #define ROCKETLIB_COMMON_H #include -#include "math.h" /// @brief Rocketlib major release number, shall be design cycle year #define ROCKETLIB_VERSION_MAJOR 2026 diff --git a/tests/test_math.cpp b/tests/test_math.cpp index a0661c1a..d51afbf6 100644 --- a/tests/test_math.cpp +++ b/tests/test_math.cpp @@ -7,8 +7,6 @@ #include "rockettest.hpp" -#include "common/math/math.h" - class value_clamp_uint32_test : rockettest_test { public: value_clamp_uint32_test() : rockettest_test("value_clamp_uint32_test") {} From 076ba4edbf8de55f02d328c0298f915703191141 Mon Sep 17 00:00:00 2001 From: unknown <181533015+lukeqin-s@users.noreply.github.com> Date: Mon, 30 Mar 2026 23:40:50 -0400 Subject: [PATCH 087/108] - Followed clang-format for test_math.cpp - Sorted TEST_SRCS by alphabetical order in Makefile --- tests/test_math.cpp | 57 +++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/tests/test_math.cpp b/tests/test_math.cpp index d51afbf6..cee58b43 100644 --- a/tests/test_math.cpp +++ b/tests/test_math.cpp @@ -27,15 +27,14 @@ class value_clamp_uint32_test : rockettest_test { rockettest_check_expr_true(value_clamp_uint32(0u, 1u, 2u) == 1u); rockettest_check_expr_true( value_clamp_uint32(std::numeric_limits::max(), 1u, 2u) == 2u); - rockettest_check_expr_true(value_clamp_uint32(0u, - 0u, - std::numeric_limits::max()) == 0u); + rockettest_check_expr_true( + value_clamp_uint32(0u, 0u, std::numeric_limits::max()) == 0u); rockettest_check_expr_true(value_clamp_uint32(std::numeric_limits::max(), - 0u, - std::numeric_limits::max()) == - std::numeric_limits::max()); + 0u, + std::numeric_limits::max()) == + std::numeric_limits::max()); - printf("value_clamp_uint32: degenerate range\n"); + printf("value_clamp_uint32: interval with zero width\n"); rockettest_check_expr_true(value_clamp_uint32(0u, 42u, 42u) == 42u); rockettest_check_expr_true(value_clamp_uint32(42u, 42u, 42u) == 42u); rockettest_check_expr_true(value_clamp_uint32(100u, 42u, 42u) == 42u); @@ -63,20 +62,20 @@ class value_clamp_int32_test : rockettest_test { rockettest_check_expr_true(value_clamp_int32(11, -10, 10) == 10); printf("value_clamp_int32: extreme values\n"); - rockettest_check_expr_true( - value_clamp_int32(std::numeric_limits::min(), -5, 5) == -5); - rockettest_check_expr_true( - value_clamp_int32(std::numeric_limits::max(), -5, 5) == 5); + rockettest_check_expr_true(value_clamp_int32(std::numeric_limits::min(), -5, 5) == + -5); + rockettest_check_expr_true(value_clamp_int32(std::numeric_limits::max(), -5, 5) == + 5); rockettest_check_expr_true(value_clamp_int32(std::numeric_limits::min(), - std::numeric_limits::min(), - std::numeric_limits::max()) == - std::numeric_limits::min()); + std::numeric_limits::min(), + std::numeric_limits::max()) == + std::numeric_limits::min()); rockettest_check_expr_true(value_clamp_int32(std::numeric_limits::max(), - std::numeric_limits::min(), - std::numeric_limits::max()) == - std::numeric_limits::max()); + std::numeric_limits::min(), + std::numeric_limits::max()) == + std::numeric_limits::max()); - printf("value_clamp_int32: degenerate range\n"); + printf("value_clamp_int32: interval with zero width\n"); rockettest_check_expr_true(value_clamp_int32(-100, 7, 7) == 7); rockettest_check_expr_true(value_clamp_int32(7, 7, 7) == 7); rockettest_check_expr_true(value_clamp_int32(100, 7, 7) == 7); @@ -104,26 +103,22 @@ class value_clamp_float_test : rockettest_test { rockettest_check_expr_true(value_clamp_float(2.0f, -1.0f, 1.0f) == 1.0f); printf("value_clamp_float: finite extreme values\n"); - rockettest_check_expr_true(value_clamp_float(std::numeric_limits::lowest(), - -1.0f, - 1.0f) == -1.0f); - rockettest_check_expr_true(value_clamp_float(std::numeric_limits::max(), - -1.0f, - 1.0f) == 1.0f); + rockettest_check_expr_true( + value_clamp_float(std::numeric_limits::lowest(), -1.0f, 1.0f) == -1.0f); + rockettest_check_expr_true( + value_clamp_float(std::numeric_limits::max(), -1.0f, 1.0f) == 1.0f); printf("value_clamp_float: infinity behavior\n"); - rockettest_check_expr_true(value_clamp_float(-std::numeric_limits::infinity(), - -10.0f, - 10.0f) == -10.0f); - rockettest_check_expr_true(value_clamp_float(std::numeric_limits::infinity(), - -10.0f, - 10.0f) == 10.0f); + rockettest_check_expr_true( + value_clamp_float(-std::numeric_limits::infinity(), -10.0f, 10.0f) == -10.0f); + rockettest_check_expr_true( + value_clamp_float(std::numeric_limits::infinity(), -10.0f, 10.0f) == 10.0f); printf("value_clamp_float: NaN behavior\n"); const float nan_value = std::numeric_limits::quiet_NaN(); rockettest_check_expr_true(std::isnan(value_clamp_float(nan_value, -1.0f, 1.0f))); - printf("value_clamp_float: degenerate range\n"); + printf("value_clamp_float: interval with zero width\n"); rockettest_check_expr_true(value_clamp_float(-5.0f, 3.5f, 3.5f) == 3.5f); rockettest_check_expr_true(value_clamp_float(3.5f, 3.5f, 3.5f) == 3.5f); rockettest_check_expr_true(value_clamp_float(9.0f, 3.5f, 3.5f) == 3.5f); From e7486bbb821464759f62b3b94796590c8c8bcae1 Mon Sep 17 00:00:00 2001 From: unknown <181533015+lukeqin-s@users.noreply.github.com> Date: Thu, 2 Apr 2026 22:44:18 -0400 Subject: [PATCH 088/108] Added typedefs for float32_t and float64_t common.h with static assert width checks. Moved clamp functions to mathops.h. Added mathops.h to Makefile. Changed test_math.cpp to use float32_t. --- include/common.h | 70 +++++++++------------------------------------ include/mathops.h | 62 +++++++++++++++++++++++++++++++++++++++ tests/test_math.cpp | 53 ++++++++++++++++++---------------- 3 files changed, 104 insertions(+), 81 deletions(-) create mode 100644 include/mathops.h diff --git a/include/common.h b/include/common.h index e55a56c5..3b05a622 100644 --- a/include/common.h +++ b/include/common.h @@ -1,14 +1,26 @@ #ifndef ROCKETLIB_COMMON_H #define ROCKETLIB_COMMON_H -#include - /// @brief Rocketlib major release number, shall be design cycle year #define ROCKETLIB_VERSION_MAJOR 2026 /// @brief Rocketlib minor release number, shall be the Nth release of the design cycle #define ROCKETLIB_VERSION_MINOR 1 +typedef float float32_t; +typedef double float64_t; + +#ifdef __cplusplus +#define STATIC_ASSERT(expr, msg) static_assert((expr), msg); +#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) +#define STATIC_ASSERT(expr, msg) _Static_assert((expr), msg); +#else +#define STATIC_ASSERT(expr, msg) +#endif + +STATIC_ASSERT(sizeof(float32_t) == 4, "float32_t must be 32 bits") +STATIC_ASSERT(sizeof(float64_t) == 8, "float64_t must be 64 bits") + /// @brief Standard error code typedef enum { /// @brief Success @@ -98,58 +110,4 @@ extern void rocketlib_assert_fail_c(const char *file, int line, const char *stat #endif -/** - * @brief Clamps a 32 bit unsigned integer between a lower and upper bound. - * - * @param x The value to clamp - * @param low The lower bound, inclusive - * @param high The upper bound, inclusive - * @return The clamped value - */ -static inline uint32_t value_clamp_uint32(uint32_t x, uint32_t low, uint32_t high) { - if (x < low) { - return low; - } else if (x > high) { - return high; - } else { - return x; - } -} - -/** - * @brief Clamps a 32 bit signed integer between a lower and upper bound. - * - * @param x The value to clamp - * @param low The lower bound, inclusive - * @param high The upper bound, inclusive - * @return The clamped value - */ -static inline int32_t value_clamp_int32(int32_t x, int32_t low, int32_t high) { - if (x < low) { - return low; - } else if (x > high) { - return high; - } else { - return x; - } -} - -/** - * @brief Clamps a 32 bit float between a lower and upper bound. - * - * @param x The value to clamp - * @param low The lower bound, inclusive - * @param high The upper bound, inclusive - * @return The clamped value - */ -static inline float value_clamp_float(float x, float low, float high) { - if (x < low) { - return low; - } else if (x > high) { - return high; - } else { - return x; - } -} - #endif diff --git a/include/mathops.h b/include/mathops.h new file mode 100644 index 00000000..f7f4578f --- /dev/null +++ b/include/mathops.h @@ -0,0 +1,62 @@ +#ifndef MATHOPS_H +#define MATHOPS_H + +#include + +#include "common.h" + +/** + * @brief Clamps a 32 bit unsigned integer between a lower and upper bound. + * + * @param x The value to clamp + * @param low The lower bound, inclusive + * @param high The upper bound, inclusive + * @return The clamped value + */ +static inline uint32_t value_clamp_uint32(uint32_t x, uint32_t low, uint32_t high) { + if (x < low) { + return low; + } else if (x > high) { + return high; + } else { + return x; + } +} + +/** + * @brief Clamps a 32 bit signed integer between a lower and upper bound. + * + * @param x The value to clamp + * @param low The lower bound, inclusive + * @param high The upper bound, inclusive + * @return The clamped value + */ +static inline int32_t value_clamp_int32(int32_t x, int32_t low, int32_t high) { + if (x < low) { + return low; + } else if (x > high) { + return high; + } else { + return x; + } +} + +/** + * @brief Clamps a 32 bit float between a lower and upper bound. + * + * @param x The value to clamp + * @param low The lower bound, inclusive + * @param high The upper bound, inclusive + * @return The clamped value + */ +static inline float32_t value_clamp_float32(float32_t x, float32_t low, float32_t high) { + if (x < low) { + return low; + } else if (x > high) { + return high; + } else { + return x; + } +} + +#endif diff --git a/tests/test_math.cpp b/tests/test_math.cpp index cee58b43..fb557dc2 100644 --- a/tests/test_math.cpp +++ b/tests/test_math.cpp @@ -4,6 +4,7 @@ #include #include "common.h" +#include "mathops.h" #include "rockettest.hpp" @@ -93,35 +94,37 @@ class value_clamp_float_test : rockettest_test { bool run_test() override { bool test_passed = true; - printf("value_clamp_float: in-range and boundary behavior\n"); - rockettest_check_expr_true(value_clamp_float(0.5f, -1.0f, 1.0f) == 0.5f); - rockettest_check_expr_true(value_clamp_float(-1.0f, -1.0f, 1.0f) == -1.0f); - rockettest_check_expr_true(value_clamp_float(1.0f, -1.0f, 1.0f) == 1.0f); + printf("value_clamp_float32: in-range and boundary behavior\n"); + rockettest_check_expr_true(value_clamp_float32(0.5f, -1.0f, 1.0f) == 0.5f); + rockettest_check_expr_true(value_clamp_float32(-1.0f, -1.0f, 1.0f) == -1.0f); + rockettest_check_expr_true(value_clamp_float32(1.0f, -1.0f, 1.0f) == 1.0f); - printf("value_clamp_float: out-of-range behavior\n"); - rockettest_check_expr_true(value_clamp_float(-2.0f, -1.0f, 1.0f) == -1.0f); - rockettest_check_expr_true(value_clamp_float(2.0f, -1.0f, 1.0f) == 1.0f); + printf("value_clamp_float32: out-of-range behavior\n"); + rockettest_check_expr_true(value_clamp_float32(-2.0f, -1.0f, 1.0f) == -1.0f); + rockettest_check_expr_true(value_clamp_float32(2.0f, -1.0f, 1.0f) == 1.0f); - printf("value_clamp_float: finite extreme values\n"); + printf("value_clamp_float32: finite extreme values\n"); rockettest_check_expr_true( - value_clamp_float(std::numeric_limits::lowest(), -1.0f, 1.0f) == -1.0f); + value_clamp_float32(std::numeric_limits::lowest(), -1.0f, 1.0f) == -1.0f); rockettest_check_expr_true( - value_clamp_float(std::numeric_limits::max(), -1.0f, 1.0f) == 1.0f); - - printf("value_clamp_float: infinity behavior\n"); - rockettest_check_expr_true( - value_clamp_float(-std::numeric_limits::infinity(), -10.0f, 10.0f) == -10.0f); - rockettest_check_expr_true( - value_clamp_float(std::numeric_limits::infinity(), -10.0f, 10.0f) == 10.0f); - - printf("value_clamp_float: NaN behavior\n"); - const float nan_value = std::numeric_limits::quiet_NaN(); - rockettest_check_expr_true(std::isnan(value_clamp_float(nan_value, -1.0f, 1.0f))); - - printf("value_clamp_float: interval with zero width\n"); - rockettest_check_expr_true(value_clamp_float(-5.0f, 3.5f, 3.5f) == 3.5f); - rockettest_check_expr_true(value_clamp_float(3.5f, 3.5f, 3.5f) == 3.5f); - rockettest_check_expr_true(value_clamp_float(9.0f, 3.5f, 3.5f) == 3.5f); + value_clamp_float32(std::numeric_limits::max(), -1.0f, 1.0f) == 1.0f); + + printf("value_clamp_float32: infinity behavior\n"); + rockettest_check_expr_true(value_clamp_float32(-std::numeric_limits::infinity(), + -10.0f, + 10.0f) == -10.0f); + rockettest_check_expr_true(value_clamp_float32(std::numeric_limits::infinity(), + -10.0f, + 10.0f) == 10.0f); + + printf("value_clamp_float32: NaN behavior\n"); + const float32_t nan_value = std::numeric_limits::quiet_NaN(); + rockettest_check_expr_true(std::isnan(value_clamp_float32(nan_value, -1.0f, 1.0f))); + + printf("value_clamp_float32: interval with zero width\n"); + rockettest_check_expr_true(value_clamp_float32(-5.0f, 3.5f, 3.5f) == 3.5f); + rockettest_check_expr_true(value_clamp_float32(3.5f, 3.5f, 3.5f) == 3.5f); + rockettest_check_expr_true(value_clamp_float32(9.0f, 3.5f, 3.5f) == 3.5f); return test_passed; } From 3896900dfa30dd80d2b99097c2a9bf6fb7cfe382 Mon Sep 17 00:00:00 2001 From: unknown <181533015+lukeqin-s@users.noreply.github.com> Date: Sun, 5 Apr 2026 12:18:34 -0400 Subject: [PATCH 089/108] Renamed test_math.cpp to test_mathops.cpp and changed Makefile accordingly. Refractored test_mathops.cpp to consistantly use float32 naming. Switched order of includes in mathops.h. --- include/mathops.h | 4 ++-- tests/{test_math.cpp => test_mathops.cpp} | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) rename tests/{test_math.cpp => test_mathops.cpp} (96%) diff --git a/include/mathops.h b/include/mathops.h index f7f4578f..31e748da 100644 --- a/include/mathops.h +++ b/include/mathops.h @@ -1,5 +1,5 @@ -#ifndef MATHOPS_H -#define MATHOPS_H +#ifndef ROCKETLIB_MATHOPS_H +#define ROCKETLIB_MATHOPS_H #include diff --git a/tests/test_math.cpp b/tests/test_mathops.cpp similarity index 96% rename from tests/test_math.cpp rename to tests/test_mathops.cpp index fb557dc2..2d6bc702 100644 --- a/tests/test_math.cpp +++ b/tests/test_mathops.cpp @@ -87,9 +87,9 @@ class value_clamp_int32_test : rockettest_test { value_clamp_int32_test value_clamp_int32_test_inst; -class value_clamp_float_test : rockettest_test { +class value_clamp_float32_test : rockettest_test { public: - value_clamp_float_test() : rockettest_test("value_clamp_float_test") {} + value_clamp_float32_test() : rockettest_test("value_clamp_float32_test") {} bool run_test() override { bool test_passed = true; @@ -130,4 +130,4 @@ class value_clamp_float_test : rockettest_test { } }; -value_clamp_float_test value_clamp_float_test_inst; +value_clamp_float32_test value_clamp_float32_test_inst; From 689c96483182ba98779f12423188635b1a4fee62 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Sun, 12 Apr 2026 18:41:49 -0400 Subject: [PATCH 090/108] Use no optimization for unit test run to ensure correct coverage --- flows/firmware-library.mk | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/flows/firmware-library.mk b/flows/firmware-library.mk index 3ecbfc68..7b1e62a7 100644 --- a/flows/firmware-library.mk +++ b/flows/firmware-library.mk @@ -23,13 +23,9 @@ C_CXX_FLAGS += \ -Wextra \ -pedantic \ -MMD \ - -DUNIT_TEST - -ifeq ($(DEBUG), 1) -C_CXX_FLAGS += -Og -g -else -C_CXX_FLAGS += -O2 -endif + -DUNIT_TEST \ + -O0 \ + -g ifeq ($(filter run-test,$(MAKECMDGOALS)),run-test) BUILD_DIR := build/test From 491a6a1e866fa8ad23f95fbc9bba25b43c83b592 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Sun, 12 Apr 2026 18:55:06 -0400 Subject: [PATCH 091/108] Add an option to enable gcc analyzer --- flows/firmware-library.mk | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/flows/firmware-library.mk b/flows/firmware-library.mk index 7b1e62a7..aca1810c 100644 --- a/flows/firmware-library.mk +++ b/flows/firmware-library.mk @@ -1,3 +1,9 @@ +########################### +# User Configure Variable +########################### + +ENABLE_GCC_ANALYZER := 0 + ########################### # Source File Path Variables ########################### @@ -52,6 +58,10 @@ CXXFLAGS := \ -std=c++20 \ -I$(ROCKETTEST_INCLUDE_PATH) +ifeq ($(ENABLE_GCC_ANALYZER), 1) + CFLAGS += -fanalyzer +endif + ####################### # XC8 Compile Variables ####################### From 4d01d0f81c30dc1f69964cce3c45be132b5d9145 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Sun, 12 Apr 2026 19:21:22 -0400 Subject: [PATCH 092/108] Add option to enable sanatizers --- flows/firmware-library.mk | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/flows/firmware-library.mk b/flows/firmware-library.mk index aca1810c..f977b028 100644 --- a/flows/firmware-library.mk +++ b/flows/firmware-library.mk @@ -3,6 +3,7 @@ ########################### ENABLE_GCC_ANALYZER := 0 +ENABLE_SANITIZER := 0 ########################### # Source File Path Variables @@ -33,6 +34,11 @@ C_CXX_FLAGS += \ -O0 \ -g +ifeq ($(ENABLE_SANITIZER), 1) + C_CXX_FLAGS += -fsanitize=undefined + LDFLAGS += -fsanitize=address,undefined +endif + ifeq ($(filter run-test,$(MAKECMDGOALS)),run-test) BUILD_DIR := build/test endif From 458684f5aa232de834456dc09eeeeb0d711cc2ad Mon Sep 17 00:00:00 2001 From: Skyler Ma Date: Wed, 15 Apr 2026 20:02:47 -0400 Subject: [PATCH 093/108] Add MBR parse test coverage for invalid boot signature --- tests/test_mbr.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/test_mbr.cpp b/tests/test_mbr.cpp index 7eb0a6d7..f5a72c8b 100644 --- a/tests/test_mbr.cpp +++ b/tests/test_mbr.cpp @@ -21,6 +21,7 @@ class mbr_test : rockettest_test { // Example first sector uint8_t first_sector[512] = {0}; uint8_t *entry = first_sector + 0x1BE; + uint8_t *boot_signature = first_sector + 0x1FE; entry[0] = 0x80; // boot flag entry[4] = partition_type; // partition type @@ -30,11 +31,21 @@ class mbr_test : rockettest_test { entry[10] = 0x11; entry[11] = 0x00; // LBA high byte - // Test with invalid boot signature + // Test with invalid both bytes of boot signature + rockettest_check_expr_true(mbr_parse(first_sector, partition_type, §or_lba) == + W_FAILURE); + + boot_signature[1] = 0xAA; + // Test with invalid first byte of boot signature + rockettest_check_expr_true(mbr_parse(first_sector, partition_type, §or_lba) == + W_FAILURE); + + boot_signature[0] = 0x55; + boot_signature[1] = 0x00; + // Test with invalid second byte of boot signature rockettest_check_expr_true(mbr_parse(first_sector, partition_type, §or_lba) == W_FAILURE); - uint8_t *boot_signature = first_sector + 0x1FE; boot_signature[0] = 0x55; boot_signature[1] = 0xAA; From ebf586556b1804797d81761bd078d59ce91c83d7 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Wed, 15 Apr 2026 19:41:56 -0400 Subject: [PATCH 094/108] Add a data format error common error code --- include/common.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/common.h b/include/common.h index 3b05a622..5e3045d4 100644 --- a/include/common.h +++ b/include/common.h @@ -36,7 +36,9 @@ typedef enum { /// @brief Math error, for example divide by zero W_MATH_ERROR, /// @brief Buffer overflow, for example trying to write to a full FIFO - W_OVERFLOW + W_OVERFLOW, + /// @brief Data format error, for example input is a malformed CAN packet + W_DATA_FORMAT_ERROR } w_status_t; #ifndef UNIT_TEST From 72d2c6b46875ee56d886d1bce1b730b4c1f0b9b5 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Sun, 19 Apr 2026 22:41:36 -0400 Subject: [PATCH 095/108] Add rockettest self test --- rockettest/rockettest.hpp | 40 +++++++++++++++----- tests/test_rockettest.cpp | 78 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+), 10 deletions(-) create mode 100644 tests/test_rockettest.cpp diff --git a/rockettest/rockettest.hpp b/rockettest/rockettest.hpp index 28cfb444..72690eef 100644 --- a/rockettest/rockettest.hpp +++ b/rockettest/rockettest.hpp @@ -8,6 +8,10 @@ #include #include +/** + * Base functionality + */ + #define CONSOLE_COLOUR_RESET "\033[0m" #define CONSOLE_COLOUR_RED "\033[1;31m" #define CONSOLE_COLOUR_GREEN "\033[1;32m" @@ -28,16 +32,6 @@ test_passed = false; \ } -template T rockettest_rand_field() { - return static_cast(std::rand() & mask); -} - -// Generate a random number in [min,max) -template T rockettest_rand_range(T min, T max) { - return static_cast((std::rand() % (static_cast(max) - static_cast(min))) + - static_cast(min)); -} - class rockettest_test { const char *name; @@ -54,4 +48,30 @@ class rockettest_test { bool rockettest_check_assert_sjlj(std::function funccall); +/** + * Random Number Generation + */ + +template T rockettest_rand_field() { + return static_cast(std::rand() & mask); +} + +template +T rockettest_rand_field_with_exclude(T exclude) { + T rn = static_cast(std::rand() & mask); + return rn; +} + +// Generate a random number in [min,max) +template T rockettest_rand_range(T min, T max) { + return static_cast((std::rand() % (static_cast(max) - static_cast(min))) + + static_cast(min)); +} + +template T rockettest_rand_range_with_exclude(T min, T max, T exclude) { + T rn = static_cast((std::rand() % (static_cast(max) - static_cast(min))) + + static_cast(min)); + return rn; +} + #endif diff --git a/tests/test_rockettest.cpp b/tests/test_rockettest.cpp new file mode 100644 index 00000000..89195069 --- /dev/null +++ b/tests/test_rockettest.cpp @@ -0,0 +1,78 @@ +#include +#include + +#include "rockettest.hpp" + +class test_rand_field : rockettest_test { +public: + test_rand_field() : rockettest_test("test_rand_field") {} + + bool run_test() override { + bool test_passed = true; + + int dist[256]{}; + + for (int i = 0; i < 10000; i++) { + uint8_t randval = rockettest_rand_field(); + dist[randval]++; + } + + int min_occurrence = 10000; + int max_occurrence = 0; + + for (int k : dist) { + rockettest_check_expr_true(k >= 1); + if (k > max_occurrence) { + max_occurrence = k; + } + if (k < min_occurrence) { + min_occurrence = k; + } + } + + std::cout << "Max Occurrence = " << max_occurrence << std::endl; + std::cout << "Min Occurrence = " << min_occurrence << std::endl; + + return test_passed; + } +}; + +test_rand_field test_rand_field_inst; + +class test_rand_range : rockettest_test { +public: + test_rand_range() : rockettest_test("test_rand_range") {} + + bool run_test() override { + bool test_passed = true; + + int dist[100]{}; + + for (int i = 0; i < 10000; i++) { + uint8_t randval = rockettest_rand_range(100, 200); + rockettest_check_expr_true(randval >= 100); + rockettest_check_expr_true(randval < 200); + dist[randval - 100]++; + } + + int min_occurrence = 10000; + int max_occurrence = 0; + + for (int k : dist) { + rockettest_check_expr_true(k >= 1); + if (k > max_occurrence) { + max_occurrence = k; + } + if (k < min_occurrence) { + min_occurrence = k; + } + } + + std::cout << "Max Occurrence = " << max_occurrence << std::endl; + std::cout << "Min Occurrence = " << min_occurrence << std::endl; + + return test_passed; + } +}; + +test_rand_range test_rand_range_inst; From 9238c06d31c9e24902465006bb894bd0f027f27a Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Sun, 19 Apr 2026 23:25:40 -0400 Subject: [PATCH 096/108] Implement random with exclude function --- rockettest/rockettest.hpp | 9 +++++ tests/test_rockettest.cpp | 74 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) diff --git a/rockettest/rockettest.hpp b/rockettest/rockettest.hpp index 72690eef..6b541abb 100644 --- a/rockettest/rockettest.hpp +++ b/rockettest/rockettest.hpp @@ -59,6 +59,9 @@ template T rockettest_rand_field() template T rockettest_rand_field_with_exclude(T exclude) { T rn = static_cast(std::rand() & mask); + if (rn == exclude) { + rn = (rn + 1) & mask; + } return rn; } @@ -71,6 +74,12 @@ template T rockettest_rand_range(T min, T max) { template T rockettest_rand_range_with_exclude(T min, T max, T exclude) { T rn = static_cast((std::rand() % (static_cast(max) - static_cast(min))) + static_cast(min)); + if (rn == exclude) { + rn += 1; + if (rn == max) { + rn = min; + } + } return rn; } diff --git a/tests/test_rockettest.cpp b/tests/test_rockettest.cpp index 89195069..e79c1fd4 100644 --- a/tests/test_rockettest.cpp +++ b/tests/test_rockettest.cpp @@ -76,3 +76,77 @@ class test_rand_range : rockettest_test { }; test_rand_range test_rand_range_inst; + +class test_rand_field_with_exclude : rockettest_test { +public: + test_rand_field_with_exclude() : rockettest_test("test_rand_field_with_exclude") {} + + bool run_test() override { + bool test_passed = true; + + int dist[256]{}; + + for (int i = 0; i < 10000; i++) { + uint8_t randval = rockettest_rand_field_with_exclude(120); + rockettest_check_expr_true(randval != 120); + dist[randval]++; + } + + int min_occurrence = 10000; + int max_occurrence = 0; + + for (int k : dist) { + if (k > max_occurrence) { + max_occurrence = k; + } + if ((k < min_occurrence) && (k > 0)) { + min_occurrence = k; + } + } + + std::cout << "Max Occurrence = " << max_occurrence << std::endl; + std::cout << "Min Non-Zero Occurrence = " << min_occurrence << std::endl; + + return test_passed; + } +}; + +test_rand_field_with_exclude test_rand_field_with_exclude_inst; + +class test_rand_range_with_exclude : rockettest_test { +public: + test_rand_range_with_exclude() : rockettest_test("test_rand_range_with_exclude") {} + + bool run_test() override { + bool test_passed = true; + + int dist[100]{}; + + for (int i = 0; i < 10000; i++) { + uint8_t randval = rockettest_rand_range_with_exclude(100, 200, 150); + rockettest_check_expr_true(randval >= 100); + rockettest_check_expr_true(randval < 200); + rockettest_check_expr_true(randval != 150); + dist[randval - 100]++; + } + + int min_occurrence = 10000; + int max_occurrence = 0; + + for (int k : dist) { + if (k > max_occurrence) { + max_occurrence = k; + } + if ((k < min_occurrence) && (k > 0)) { + min_occurrence = k; + } + } + + std::cout << "Max Occurrence = " << max_occurrence << std::endl; + std::cout << "Min Non-Zero Occurrence = " << min_occurrence << std::endl; + + return test_passed; + } +}; + +test_rand_range_with_exclude test_rand_range_with_exclude_inst; From 085a6ddf98b4f2d0caeed380c9d470d0d836b8c8 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Wed, 22 Apr 2026 08:09:13 -0400 Subject: [PATCH 097/108] Add a buffer underflow error code --- include/common.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/common.h b/include/common.h index 5e3045d4..2427c203 100644 --- a/include/common.h +++ b/include/common.h @@ -35,8 +35,10 @@ typedef enum { W_IO_TIMEOUT, /// @brief Math error, for example divide by zero W_MATH_ERROR, - /// @brief Buffer overflow, for example trying to write to a full FIFO + /// @brief Buffer overflow, for example trying to write/push to a full FIFO buffer W_OVERFLOW, + /// @brief Buffer underflow, for example trying to read/pop from an empty FIFO buffer + W_UNDERFLOW, /// @brief Data format error, for example input is a malformed CAN packet W_DATA_FORMAT_ERROR } w_status_t; From 9f39aef548657e3ecb0bfaf3afb60e3a8befda24 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Sat, 4 Jul 2026 12:31:07 -0400 Subject: [PATCH 098/108] Add W_NO_DATA --- include/common.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/common.h b/include/common.h index 2427c203..4ab502c9 100644 --- a/include/common.h +++ b/include/common.h @@ -40,7 +40,9 @@ typedef enum { /// @brief Buffer underflow, for example trying to read/pop from an empty FIFO buffer W_UNDERFLOW, /// @brief Data format error, for example input is a malformed CAN packet - W_DATA_FORMAT_ERROR + W_DATA_FORMAT_ERROR, + /// @brief Succeed, but no data available + W_NO_DATA } w_status_t; #ifndef UNIT_TEST From 512c13d6040d61e4b873224de7c2e8bbe83e5460 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Sat, 29 Aug 2026 23:42:27 -0400 Subject: [PATCH 099/108] Update clang-format configuration file to version 23 --- .clang-format | 68 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 12 deletions(-) diff --git a/.clang-format b/.clang-format index 5d422766..e4ce2ac0 100644 --- a/.clang-format +++ b/.clang-format @@ -1,4 +1,4 @@ -# Configuration file for clang-format 21 +# Configuration file for clang-format 23 --- AccessModifierOffset: -4 AlignAfterOpenBracket: Align @@ -10,6 +10,7 @@ AlignConsecutiveAssignments: AlignCompound: false AlignFunctionDeclarations: false AlignFunctionPointers: false + EnumAssignments: false PadOperators: true AlignConsecutiveBitFields: Enabled: false @@ -18,6 +19,7 @@ AlignConsecutiveBitFields: AlignCompound: false AlignFunctionDeclarations: false AlignFunctionPointers: false + EnumAssignments: false PadOperators: false AlignConsecutiveDeclarations: Enabled: false @@ -26,6 +28,7 @@ AlignConsecutiveDeclarations: AlignCompound: false AlignFunctionDeclarations: true AlignFunctionPointers: false + EnumAssignments: false PadOperators: false AlignConsecutiveMacros: Enabled: false @@ -34,6 +37,7 @@ AlignConsecutiveMacros: AlignCompound: false AlignFunctionDeclarations: false AlignFunctionPointers: false + EnumAssignments: false PadOperators: false AlignConsecutiveShortCaseStatements: Enabled: false @@ -48,6 +52,7 @@ AlignConsecutiveTableGenBreakingDAGArgColons: AlignCompound: false AlignFunctionDeclarations: false AlignFunctionPointers: false + EnumAssignments: false PadOperators: false AlignConsecutiveTableGenCondOperatorColons: Enabled: false @@ -56,6 +61,7 @@ AlignConsecutiveTableGenCondOperatorColons: AlignCompound: false AlignFunctionDeclarations: false AlignFunctionPointers: false + EnumAssignments: false PadOperators: false AlignConsecutiveTableGenDefinitionColons: Enabled: false @@ -64,30 +70,35 @@ AlignConsecutiveTableGenDefinitionColons: AlignCompound: false AlignFunctionDeclarations: false AlignFunctionPointers: false + EnumAssignments: false PadOperators: false AlignEscapedNewlines: Right AlignOperands: Align AlignTrailingComments: + AlignPPAndNotPP: false Kind: Never OverEmptyLines: 0 AllowAllArgumentsOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: true AllowBreakBeforeNoexceptSpecifier: Never +AllowBreakBeforeQtProperty: false AllowShortBlocksOnASingleLine: Empty AllowShortCaseExpressionOnASingleLine: false AllowShortCaseLabelsOnASingleLine: false AllowShortCompoundRequirementOnASingleLine: false AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: Empty +AllowShortFunctionsOnASingleLine: + Empty: true + Inline: false + Other: false AllowShortIfStatementsOnASingleLine: Never AllowShortLambdasOnASingleLine: All AllowShortLoopsOnASingleLine: false AllowShortNamespacesOnASingleLine: false +AllowShortRecordOnASingleLine: EmptyAndAttached AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakBeforeMultilineStrings: false -BinPackArguments: false BinPackLongBracedList: true -BinPackParameters: BinPack BitFieldColonSpacing: Both BracedInitializerIndentWidth: -1 BraceWrapping: @@ -112,16 +123,29 @@ BraceWrapping: BreakAdjacentStringLiterals: true BreakAfterAttributes: Never BreakAfterJavaFieldAnnotations: false +BreakAfterOpenBracketBracedList: true +BreakAfterOpenBracketFunction: false +BreakAfterOpenBracketIf: false +BreakAfterOpenBracketLoop: false +BreakAfterOpenBracketSwitch: false BreakAfterReturnType: None BreakArrays: true BreakBeforeBinaryOperators: None +BreakBeforeCloseBracketBracedList: true +BreakBeforeCloseBracketFunction: false +BreakBeforeCloseBracketIf: false +BreakBeforeCloseBracketLoop: false +BreakBeforeCloseBracketSwitch: false BreakBeforeConceptDeclarations: Always BreakBeforeBraces: Attach BreakBeforeInlineASMColon: OnlyMultiline -BreakBeforeTemplateCloser: true +BreakBeforeReturnType: None +BreakBeforeTemplateCloser: false BreakBeforeTernaryOperators: true -BreakBinaryOperations: Never +BreakBinaryOperations: + Default: Never BreakConstructorInitializers: BeforeColon +BreakFunctionDeclarationParameters: false BreakFunctionDefinitionParameters: false BreakInheritanceList: BeforeColon BreakStringLiterals: true @@ -131,7 +155,7 @@ CommentPragmas: '^ IWYU pragma:' CompactNamespaces: false ConstructorInitializerIndentWidth: 4 ContinuationIndentWidth: 4 -Cpp11BracedListStyle: true +Cpp11BracedListStyle: AlignFirstComment DerivePointerAlignment: false DisableFormat: false EmptyLineAfterAccessModifier: Never @@ -147,7 +171,7 @@ IndentCaseBlocks: false IndentCaseLabels: true IndentExportBlock: true IndentExternBlock: AfterExternBlock -IndentGotoLabels: true +IndentGotoLabels: OuterIndent IndentPPDirectives: None IndentRequiresClause: true IndentWidth: 4 @@ -157,10 +181,16 @@ InsertNewlineAtEOF: true InsertTrailingCommas: None IntegerLiteralSeparator: Binary: 0 - BinaryMinDigits: 0 + BinaryMinDigitsInsert: 0 + BinaryMaxDigitsRemove: 0 Decimal: 0 - DecimalMinDigits: 0 + DecimalMinDigitsInsert: 0 + DecimalMaxDigitsRemove: 0 Hex: 0 + HexMinDigitsInsert: 0 + HexMaxDigitsRemove: 0 + BinaryMinDigits: 0 + DecimalMinDigits: 0 HexMinDigits: 0 JavaScriptQuotes: Leave JavaScriptWrapImports: true @@ -176,13 +206,25 @@ MacroBlockEnd: '' MainIncludeChar: Quote MaxEmptyLinesToKeep: 1 NamespaceIndentation: All +NumericLiteralCase: + ExponentLetter: Lower + HexDigit: Lower + Prefix: Lower + Suffix: Upper ObjCBinPackProtocolList: Auto ObjCBlockIndentWidth: 2 ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterMethodDeclarationPrefix: true ObjCSpaceAfterProperty: false ObjCSpaceBeforeProtocolList: true OneLineFormatOffRegex: '' +PackArguments: + BinPack: BinPack + BreakAfter: 0 PackConstructorInitializers: BinPack +PackParameters: + BinPack: BinPack + BreakAfter: 0 PenaltyBreakAssignment: 2 PenaltyBreakBeforeFirstCallParameter: 19 PenaltyBreakBeforeMemberAccess: 150 @@ -212,6 +254,7 @@ SkipMacroDefinitionBody: false SortIncludes: Enabled: true IgnoreCase: false + IgnoreExtension: false SortJavaStaticImport: Before SortUsingDeclarations: LexicographicNumeric SpaceAfterCStyleCast: false @@ -223,6 +266,7 @@ SpaceBeforeAssignmentOperators: true SpaceBeforeCaseColon: false SpaceBeforeCpp11BracedList: false SpaceBeforeCtorInitializerColon: true +SpaceBeforeEnumUnderlyingTypeColon: true SpaceBeforeInheritanceColon: true SpaceBeforeJsonColon: false SpaceBeforeParens: ControlStatements @@ -240,7 +284,7 @@ SpaceBeforeParensOptions: BeforeNonEmptyParentheses: false SpaceBeforeRangeBasedForLoopColon: true SpaceBeforeSquareBrackets: false -SpaceInEmptyBlock: false +SpaceInEmptyBraces: Never SpacesBeforeTrailingComments: 1 SpacesInAngles: Never SpacesInContainerLiterals: true @@ -258,7 +302,7 @@ SpacesInSquareBrackets: false Standard: Latest TableGenBreakInsideDAGArg: DontBreak TabWidth: 4 -UseTab: Always +UseTab: AlignWithSpaces VerilogBreakBetweenInstancePorts: true WrapNamespaceBodyWithEmptyLines: Always ... From 29d620aad06f51f1d4f3f2399ed610254de227ec Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Sat, 29 Aug 2026 23:44:11 -0400 Subject: [PATCH 100/108] Format all code --- common/crc8.c | 3 +- common/mbr.c | 10 ++--- rockettest/rockettest.cpp | 4 +- rockettest/rockettest.hpp | 12 +++--- tests/test_low_pass_filter.cpp | 6 +-- tests/test_mathops.cpp | 73 ++++++++++++++++------------------ tests/test_mbr.cpp | 20 +++++----- 7 files changed, 62 insertions(+), 66 deletions(-) diff --git a/common/crc8.c b/common/crc8.c index 40d08c20..c479f552 100644 --- a/common/crc8.c +++ b/common/crc8.c @@ -20,7 +20,8 @@ static uint8_t table[256] = { 0x4e, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5c, 0x5b, 0x76, 0x71, 0x78, 0x7f, 0x6a, 0x6d, 0x64, 0x63, 0x3e, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2c, 0x2b, 0x06, 0x01, 0x08, 0x0f, 0x1a, 0x1d, 0x14, 0x13, 0xae, 0xa9, 0xa0, 0xa7, 0xb2, 0xb5, 0xbc, 0xbb, 0x96, 0x91, 0x98, 0x9f, 0x8a, 0x8d, 0x84, 0x83, - 0xde, 0xd9, 0xd0, 0xd7, 0xc2, 0xc5, 0xcc, 0xcb, 0xe6, 0xe1, 0xe8, 0xef, 0xfa, 0xfd, 0xf4, 0xf3}; + 0xde, 0xd9, 0xd0, 0xd7, 0xc2, 0xc5, 0xcc, 0xcb, 0xe6, 0xe1, 0xe8, 0xef, 0xfa, 0xfd, 0xf4, 0xf3 +}; uint8_t crc8_checksum(const uint8_t *pdata, size_t nbytes, uint8_t crc) { w_assert(pdata); diff --git a/common/mbr.c b/common/mbr.c index 17b50727..795c2d4d 100644 --- a/common/mbr.c +++ b/common/mbr.c @@ -3,8 +3,8 @@ #include "common.h" #include "mbr.h" -#define BOOT_SIGNATURE_OFFSET 0x1FE -#define MBR_PT_OFFSET 0x1BE +#define BOOT_SIGNATURE_OFFSET 0x1fe +#define MBR_PT_OFFSET 0x1be #define MBR_PT_SIZE 16 #define MBR_TYPE_OFF 4 #define MBR_LBA_OFF 8 @@ -17,7 +17,7 @@ w_status_t mbr_parse(uint8_t *first_sector, uint8_t partition_type, uint32_t *se // Boot signature starts at 0x01FE in the first sector uint8_t *boot_signature = first_sector + BOOT_SIGNATURE_OFFSET; // Boot signature check - if (boot_signature[0] != 0x55 || boot_signature[1] != 0xAA) { + if (boot_signature[0] != 0x55 || boot_signature[1] != 0xaa) { return W_FAILURE; } @@ -33,8 +33,8 @@ w_status_t mbr_parse(uint8_t *first_sector, uint8_t partition_type, uint32_t *se uint8_t type = entry[MBR_TYPE_OFF]; if (type == partition_type) { *sector_lba = (uint32_t)entry[MBR_LBA_OFF] | ((uint32_t)entry[MBR_LBA_OFF + 1] << 8) | - ((uint32_t)entry[MBR_LBA_OFF + 2] << 16) | - ((uint32_t)entry[MBR_LBA_OFF + 3] << 24); + ((uint32_t)entry[MBR_LBA_OFF + 2] << 16) | + ((uint32_t)entry[MBR_LBA_OFF + 3] << 24); return W_SUCCESS; } } diff --git a/rockettest/rockettest.cpp b/rockettest/rockettest.cpp index d8f0808f..d1c751ae 100644 --- a/rockettest/rockettest.cpp +++ b/rockettest/rockettest.cpp @@ -20,7 +20,7 @@ int main(int argc, char *argv[]) { default: std::cout << "Usage: unit_test [-s random_seed] [test_names..]" << std::endl; std::cout << "If random_seed is not provided then current time is used as seed" - << std::endl; + << std::endl; std::cout << "If test_names are not provided then all tests will run" << std::endl; return EXIT_FAILURE; } @@ -41,7 +41,7 @@ int main(int argc, char *argv[]) { } else { all_passed = false; std::cout << CONSOLE_COLOUR_RED << "NOT FOUND " << CONSOLE_COLOUR_RESET - << argv[optind] << std::endl; + << argv[optind] << std::endl; } } diff --git a/rockettest/rockettest.hpp b/rockettest/rockettest.hpp index 6b541abb..34315f7a 100644 --- a/rockettest/rockettest.hpp +++ b/rockettest/rockettest.hpp @@ -19,16 +19,16 @@ #define rockettest_check_expr_true(expr) \ if (!(expr)) { \ std::cout << CONSOLE_COLOUR_RED << "E: " << CONSOLE_COLOUR_RESET \ - << "Expression should be true " << __FILE__ << ':' << __LINE__ << ' ' << #expr \ - << std::endl; \ + << "Expression should be true " << __FILE__ << ':' << __LINE__ << ' ' << #expr \ + << std::endl; \ test_passed = false; \ } #define rockettest_check_assert_triggered(funccall) \ if (!rockettest_check_assert_sjlj((funccall))) { \ std::cout << CONSOLE_COLOUR_RED << "E: " << CONSOLE_COLOUR_RESET \ - << "Rocketlib w_assert did not trigger on " << __FILE__ << ':' << __LINE__ \ - << ' ' << #funccall << std::endl; \ + << "Rocketlib w_assert did not trigger on " << __FILE__ << ':' << __LINE__ \ + << ' ' << #funccall << std::endl; \ test_passed = false; \ } @@ -68,12 +68,12 @@ T rockettest_rand_field_with_exclude(T exclude) { // Generate a random number in [min,max) template T rockettest_rand_range(T min, T max) { return static_cast((std::rand() % (static_cast(max) - static_cast(min))) + - static_cast(min)); + static_cast(min)); } template T rockettest_rand_range_with_exclude(T min, T max, T exclude) { T rn = static_cast((std::rand() % (static_cast(max) - static_cast(min))) + - static_cast(min)); + static_cast(min)); if (rn == exclude) { rn += 1; if (rn == max) { diff --git a/tests/test_low_pass_filter.cpp b/tests/test_low_pass_filter.cpp index edfa6305..cf6c5af9 100644 --- a/tests/test_low_pass_filter.cpp +++ b/tests/test_low_pass_filter.cpp @@ -61,10 +61,8 @@ class low_pass_filter_update_test : rockettest_test { result = update_low_pass(alpha, new_input_value, &low_pass_value); rockettest_check_expr_true(result == W_SUCCESS); // Print the current iteration and values - printf("Iteration %2d: Low-Pass Value = %.4f | Expected ~ %.4f\n", - i, - low_pass_value, - expected); + printf("Iteration %2d: Low-Pass Value = %.4f | Expected ~ %.4f\n", i, low_pass_value, + expected); // Verify the correctness of the low-pass update rockettest_check_expr_true(fabs(low_pass_value - expected) < EPSILON); } diff --git a/tests/test_mathops.cpp b/tests/test_mathops.cpp index 2d6bc702..37ef5b22 100644 --- a/tests/test_mathops.cpp +++ b/tests/test_mathops.cpp @@ -16,29 +16,28 @@ class value_clamp_uint32_test : rockettest_test { bool test_passed = true; printf("value_clamp_uint32: in-range and boundary behavior\n"); - rockettest_check_expr_true(value_clamp_uint32(50u, 10u, 100u) == 50u); - rockettest_check_expr_true(value_clamp_uint32(10u, 10u, 100u) == 10u); - rockettest_check_expr_true(value_clamp_uint32(100u, 10u, 100u) == 100u); + rockettest_check_expr_true(value_clamp_uint32(50U, 10U, 100U) == 50U); + rockettest_check_expr_true(value_clamp_uint32(10U, 10U, 100U) == 10U); + rockettest_check_expr_true(value_clamp_uint32(100U, 10U, 100U) == 100U); printf("value_clamp_uint32: out-of-range behavior\n"); - rockettest_check_expr_true(value_clamp_uint32(9u, 10u, 100u) == 10u); - rockettest_check_expr_true(value_clamp_uint32(101u, 10u, 100u) == 100u); + rockettest_check_expr_true(value_clamp_uint32(9U, 10U, 100U) == 10U); + rockettest_check_expr_true(value_clamp_uint32(101U, 10U, 100U) == 100U); printf("value_clamp_uint32: extreme values\n"); - rockettest_check_expr_true(value_clamp_uint32(0u, 1u, 2u) == 1u); + rockettest_check_expr_true(value_clamp_uint32(0U, 1U, 2U) == 1U); rockettest_check_expr_true( - value_clamp_uint32(std::numeric_limits::max(), 1u, 2u) == 2u); + value_clamp_uint32(std::numeric_limits::max(), 1U, 2U) == 2U); rockettest_check_expr_true( - value_clamp_uint32(0u, 0u, std::numeric_limits::max()) == 0u); - rockettest_check_expr_true(value_clamp_uint32(std::numeric_limits::max(), - 0u, - std::numeric_limits::max()) == - std::numeric_limits::max()); + value_clamp_uint32(0U, 0U, std::numeric_limits::max()) == 0U); + rockettest_check_expr_true(value_clamp_uint32(std::numeric_limits::max(), 0U, + std::numeric_limits::max()) == + std::numeric_limits::max()); printf("value_clamp_uint32: interval with zero width\n"); - rockettest_check_expr_true(value_clamp_uint32(0u, 42u, 42u) == 42u); - rockettest_check_expr_true(value_clamp_uint32(42u, 42u, 42u) == 42u); - rockettest_check_expr_true(value_clamp_uint32(100u, 42u, 42u) == 42u); + rockettest_check_expr_true(value_clamp_uint32(0U, 42U, 42U) == 42U); + rockettest_check_expr_true(value_clamp_uint32(42U, 42U, 42U) == 42U); + rockettest_check_expr_true(value_clamp_uint32(100U, 42U, 42U) == 42U); return test_passed; } @@ -64,17 +63,17 @@ class value_clamp_int32_test : rockettest_test { printf("value_clamp_int32: extreme values\n"); rockettest_check_expr_true(value_clamp_int32(std::numeric_limits::min(), -5, 5) == - -5); + -5); rockettest_check_expr_true(value_clamp_int32(std::numeric_limits::max(), -5, 5) == - 5); + 5); rockettest_check_expr_true(value_clamp_int32(std::numeric_limits::min(), - std::numeric_limits::min(), - std::numeric_limits::max()) == - std::numeric_limits::min()); + std::numeric_limits::min(), + std::numeric_limits::max()) == + std::numeric_limits::min()); rockettest_check_expr_true(value_clamp_int32(std::numeric_limits::max(), - std::numeric_limits::min(), - std::numeric_limits::max()) == - std::numeric_limits::max()); + std::numeric_limits::min(), + std::numeric_limits::max()) == + std::numeric_limits::max()); printf("value_clamp_int32: interval with zero width\n"); rockettest_check_expr_true(value_clamp_int32(-100, 7, 7) == 7); @@ -95,36 +94,34 @@ class value_clamp_float32_test : rockettest_test { bool test_passed = true; printf("value_clamp_float32: in-range and boundary behavior\n"); - rockettest_check_expr_true(value_clamp_float32(0.5f, -1.0f, 1.0f) == 0.5f); - rockettest_check_expr_true(value_clamp_float32(-1.0f, -1.0f, 1.0f) == -1.0f); - rockettest_check_expr_true(value_clamp_float32(1.0f, -1.0f, 1.0f) == 1.0f); + rockettest_check_expr_true(value_clamp_float32(0.5F, -1.0F, 1.0F) == 0.5F); + rockettest_check_expr_true(value_clamp_float32(-1.0F, -1.0F, 1.0F) == -1.0F); + rockettest_check_expr_true(value_clamp_float32(1.0F, -1.0F, 1.0F) == 1.0F); printf("value_clamp_float32: out-of-range behavior\n"); - rockettest_check_expr_true(value_clamp_float32(-2.0f, -1.0f, 1.0f) == -1.0f); - rockettest_check_expr_true(value_clamp_float32(2.0f, -1.0f, 1.0f) == 1.0f); + rockettest_check_expr_true(value_clamp_float32(-2.0F, -1.0F, 1.0F) == -1.0F); + rockettest_check_expr_true(value_clamp_float32(2.0F, -1.0F, 1.0F) == 1.0F); printf("value_clamp_float32: finite extreme values\n"); rockettest_check_expr_true( - value_clamp_float32(std::numeric_limits::lowest(), -1.0f, 1.0f) == -1.0f); + value_clamp_float32(std::numeric_limits::lowest(), -1.0F, 1.0F) == -1.0F); rockettest_check_expr_true( - value_clamp_float32(std::numeric_limits::max(), -1.0f, 1.0f) == 1.0f); + value_clamp_float32(std::numeric_limits::max(), -1.0F, 1.0F) == 1.0F); printf("value_clamp_float32: infinity behavior\n"); rockettest_check_expr_true(value_clamp_float32(-std::numeric_limits::infinity(), - -10.0f, - 10.0f) == -10.0f); + -10.0F, 10.0F) == -10.0F); rockettest_check_expr_true(value_clamp_float32(std::numeric_limits::infinity(), - -10.0f, - 10.0f) == 10.0f); + -10.0F, 10.0F) == 10.0F); printf("value_clamp_float32: NaN behavior\n"); const float32_t nan_value = std::numeric_limits::quiet_NaN(); - rockettest_check_expr_true(std::isnan(value_clamp_float32(nan_value, -1.0f, 1.0f))); + rockettest_check_expr_true(std::isnan(value_clamp_float32(nan_value, -1.0F, 1.0F))); printf("value_clamp_float32: interval with zero width\n"); - rockettest_check_expr_true(value_clamp_float32(-5.0f, 3.5f, 3.5f) == 3.5f); - rockettest_check_expr_true(value_clamp_float32(3.5f, 3.5f, 3.5f) == 3.5f); - rockettest_check_expr_true(value_clamp_float32(9.0f, 3.5f, 3.5f) == 3.5f); + rockettest_check_expr_true(value_clamp_float32(-5.0F, 3.5F, 3.5F) == 3.5F); + rockettest_check_expr_true(value_clamp_float32(3.5F, 3.5F, 3.5F) == 3.5F); + rockettest_check_expr_true(value_clamp_float32(9.0F, 3.5F, 3.5F) == 3.5F); return test_passed; } diff --git a/tests/test_mbr.cpp b/tests/test_mbr.cpp index f5a72c8b..ed8c4d52 100644 --- a/tests/test_mbr.cpp +++ b/tests/test_mbr.cpp @@ -20,8 +20,8 @@ class mbr_test : rockettest_test { // Example first sector uint8_t first_sector[512] = {0}; - uint8_t *entry = first_sector + 0x1BE; - uint8_t *boot_signature = first_sector + 0x1FE; + uint8_t *entry = first_sector + 0x1be; + uint8_t *boot_signature = first_sector + 0x1fe; entry[0] = 0x80; // boot flag entry[4] = partition_type; // partition type @@ -33,31 +33,31 @@ class mbr_test : rockettest_test { // Test with invalid both bytes of boot signature rockettest_check_expr_true(mbr_parse(first_sector, partition_type, §or_lba) == - W_FAILURE); + W_FAILURE); - boot_signature[1] = 0xAA; + boot_signature[1] = 0xaa; // Test with invalid first byte of boot signature rockettest_check_expr_true(mbr_parse(first_sector, partition_type, §or_lba) == - W_FAILURE); + W_FAILURE); boot_signature[0] = 0x55; boot_signature[1] = 0x00; // Test with invalid second byte of boot signature rockettest_check_expr_true(mbr_parse(first_sector, partition_type, §or_lba) == - W_FAILURE); + W_FAILURE); boot_signature[0] = 0x55; - boot_signature[1] = 0xAA; + boot_signature[1] = 0xaa; // Test with valid input rockettest_check_expr_true(mbr_parse(first_sector, partition_type, §or_lba) == - W_SUCCESS); + W_SUCCESS); // Test with invalid input (NULL first sector) rockettest_check_expr_true(mbr_parse(nullptr, partition_type, §or_lba) == - W_INVALID_PARAM); + W_INVALID_PARAM); // Test with invalid input (NULL LBA) rockettest_check_expr_true(mbr_parse(first_sector, partition_type, nullptr) == - W_INVALID_PARAM); + W_INVALID_PARAM); // Test with a partition type that cannot be found rockettest_check_expr_true(mbr_parse(first_sector, 0x06, §or_lba) == W_FAILURE); From 5e8404fc2f5649029af3148357fe5ffb33c4df1e Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Sat, 29 Aug 2026 23:49:11 -0400 Subject: [PATCH 101/108] Fix lint error --- common/crc8.c | 1 + 1 file changed, 1 insertion(+) diff --git a/common/crc8.c b/common/crc8.c index c479f552..5bed51ed 100644 --- a/common/crc8.c +++ b/common/crc8.c @@ -23,6 +23,7 @@ static uint8_t table[256] = { 0xde, 0xd9, 0xd0, 0xd7, 0xc2, 0xc5, 0xcc, 0xcb, 0xe6, 0xe1, 0xe8, 0xef, 0xfa, 0xfd, 0xf4, 0xf3 }; +// NOLINTNEXTLINE(misc-use-internal-linkage) uint8_t crc8_checksum(const uint8_t *pdata, size_t nbytes, uint8_t crc) { w_assert(pdata); while (nbytes > 0) { From 1539642200ece72218c5d0ab7129b84f6a58fb8e Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Wed, 30 Sep 2026 09:07:08 -0400 Subject: [PATCH 102/108] Remove rocketlib submodule --- .gitmodules | 3 --- rocketlib | 1 - 2 files changed, 4 deletions(-) delete mode 100644 .gitmodules delete mode 160000 rocketlib diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 49e1a81c..00000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "rocketlib"] - path = rocketlib - url = https://github.com/waterloo-rocketry/rocketlib.git diff --git a/rocketlib b/rocketlib deleted file mode 160000 index 21a7cb53..00000000 --- a/rocketlib +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 21a7cb53cd32961cf31a4ee1fcc118ded65d46bd From 301654c82a1c4283b6a2ca18bc3c974b52b19d08 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Sat, 3 Oct 2026 17:46:09 -0400 Subject: [PATCH 103/108] canlib file reorganization, remove dspic33e can driver --- Makefile | 54 ++--- {util => can_buffer}/can_rcv_buffer.c | 2 +- {util => can_buffer}/can_rcv_buffer.h | 2 +- {util => can_buffer}/can_tx_buffer.c | 2 +- {util => can_buffer}/can_tx_buffer.h | 2 +- {util => can_buffer}/safe_ring_buffer.c | 2 +- {util => can_buffer}/safe_ring_buffer.h | 2 +- {util => can_buffer}/timing_util.c | 2 +- {util => can_buffer}/timing_util.h | 2 +- {message => can_message}/msg_actuator.c | 2 +- {message => can_message}/msg_actuator.h | 2 +- {message => can_message}/msg_canards.c | 2 +- {message => can_message}/msg_canards.h | 2 +- {message => can_message}/msg_common.h | 2 +- {message => can_message}/msg_general.c | 2 +- {message => can_message}/msg_general.h | 2 +- {message => can_message}/msg_gps.c | 2 +- {message => can_message}/msg_gps.h | 2 +- {message => can_message}/msg_recovery.c | 2 +- {message => can_message}/msg_recovery.h | 2 +- {message => can_message}/msg_sensor.c | 2 +- {message => can_message}/msg_sensor.h | 2 +- {message => can_message}/msg_stream.c | 2 +- {message => can_message}/msg_stream.h | 2 +- {message => can_message}/msg_telemetry.c | 2 +- {message => can_message}/msg_telemetry.h | 2 +- canlib.h | 47 ---- {include => common}/common.h | 0 dspic33e/dspic33e_can.c | 271 ----------------------- dspic33e/dspic33e_can.h | 41 ---- tests/test_crc8.cpp | 2 +- tests/test_low_pass_filter.cpp | 2 +- tests/test_mathops.cpp | 2 +- tests/test_mbr.cpp | 2 +- tests/test_msg_actuator.cpp | 6 +- tests/test_msg_canards.cpp | 4 +- tests/test_msg_common.cpp | 2 +- tests/test_msg_general.cpp | 6 +- tests/test_msg_gps.cpp | 4 +- tests/test_msg_recovery.cpp | 4 +- tests/test_msg_sensor.cpp | 4 +- tests/test_msg_stream.cpp | 6 +- tests/test_msg_telemetry.cpp | 4 +- tests/test_nullptr_reject.cpp | 26 +-- tests/test_timing_util.cpp | 4 +- tests/test_tx_rcv_buffer.cpp | 6 +- 46 files changed, 94 insertions(+), 453 deletions(-) rename {util => can_buffer}/can_rcv_buffer.c (97%) rename {util => can_buffer}/can_rcv_buffer.h (99%) rename {util => can_buffer}/can_tx_buffer.c (97%) rename {util => can_buffer}/can_tx_buffer.h (97%) rename {util => can_buffer}/safe_ring_buffer.c (98%) rename {util => can_buffer}/safe_ring_buffer.h (98%) rename {util => can_buffer}/timing_util.c (97%) rename {util => can_buffer}/timing_util.h (95%) rename {message => can_message}/msg_actuator.c (98%) rename {message => can_message}/msg_actuator.h (97%) rename {message => can_message}/msg_canards.c (98%) rename {message => can_message}/msg_canards.h (98%) rename {message => can_message}/msg_common.h (99%) rename {message => can_message}/msg_general.c (99%) rename {message => can_message}/msg_general.h (98%) rename {message => can_message}/msg_gps.c (99%) rename {message => can_message}/msg_gps.h (99%) rename {message => can_message}/msg_recovery.c (98%) rename {message => can_message}/msg_recovery.h (97%) rename {message => can_message}/msg_sensor.c (99%) rename {message => can_message}/msg_sensor.h (99%) rename {message => can_message}/msg_stream.c (99%) rename {message => can_message}/msg_stream.h (97%) rename {message => can_message}/msg_telemetry.c (98%) rename {message => can_message}/msg_telemetry.h (98%) delete mode 100644 canlib.h rename {include => common}/common.h (100%) delete mode 100644 dspic33e/dspic33e_can.c delete mode 100644 dspic33e/dspic33e_can.h diff --git a/Makefile b/Makefile index 75f40d4d..66a59009 100644 --- a/Makefile +++ b/Makefile @@ -1,31 +1,31 @@ COMMON_C_SRCS := \ - message/msg_actuator.c \ - message/msg_canards.c \ - message/msg_general.c \ - message/msg_gps.c \ - message/msg_recovery.c \ - message/msg_sensor.c \ - message/msg_stream.c \ - message/msg_telemetry.c \ - util/can_rcv_buffer.c \ - util/can_tx_buffer.c \ - util/safe_ring_buffer.c \ - util/timing_util.c + can_message/msg_actuator.c \ + can_message/msg_canards.c \ + can_message/msg_general.c \ + can_message/msg_gps.c \ + can_message/msg_recovery.c \ + can_message/msg_sensor.c \ + can_message/msg_stream.c \ + can_message/msg_telemetry.c \ + can_buffer/can_rcv_buffer.c \ + can_buffer/can_tx_buffer.c \ + can_buffer/safe_ring_buffer.c \ + can_buffer/timing_util.c COMMON_C_HEADERS := \ - message/msg_actuator.h \ - message/msg_canards.h \ - message/msg_common.h \ - message/msg_general.h \ - message/msg_gps.h \ - message/msg_recovery.h \ - message/msg_sensor.h \ - message/msg_stream.h \ - message/msg_telemetry.h \ - util/can_rcv_buffer.h \ - util/can_tx_buffer.h \ - util/safe_ring_buffer.h \ - util/timing_util.h + can_message/msg_actuator.h \ + can_message/msg_canards.h \ + can_message/msg_common.h \ + can_message/msg_general.h \ + can_message/msg_gps.h \ + can_message/msg_recovery.h \ + can_message/msg_sensor.h \ + can_message/msg_stream.h \ + can_message/msg_telemetry.h \ + can_buffer/can_rcv_buffer.h \ + can_buffer/can_tx_buffer.h \ + can_buffer/safe_ring_buffer.h \ + can_buffer/timing_util.h PIC18_C_SRCS := pic18f26k83/pic18f26k83_can.c @@ -51,8 +51,8 @@ TEST_SRCS := \ tests/test_timing_util.cpp \ tests/test_tx_rcv_buffer.cpp -ROCKETLIB_SUBMODULE_PATH := rocketlib +ROCKETLIB_SUBMODULE_PATH := . EXTRA_C_CXX_FLAGS := -DBOARD_TYPE_UNIQUE_ID=BOARD_TYPE_ID_ARMING -DBOARD_INST_UNIQUE_ID=BOARD_INST_ID_ROCKET -include rocketlib/flows/firmware-library.mk +include flows/firmware-library.mk diff --git a/util/can_rcv_buffer.c b/can_buffer/can_rcv_buffer.c similarity index 97% rename from util/can_rcv_buffer.c rename to can_buffer/can_rcv_buffer.c index 2125f70c..3f82b44e 100644 --- a/util/can_rcv_buffer.c +++ b/can_buffer/can_rcv_buffer.c @@ -1,6 +1,6 @@ #include -#include "common.h" +#include "common/common.h" #include "can.h" #include "can_rcv_buffer.h" diff --git a/util/can_rcv_buffer.h b/can_buffer/can_rcv_buffer.h similarity index 99% rename from util/can_rcv_buffer.h rename to can_buffer/can_rcv_buffer.h index f1f831b8..37feb70b 100644 --- a/util/can_rcv_buffer.h +++ b/can_buffer/can_rcv_buffer.h @@ -24,7 +24,7 @@ #include #include -#include "common.h" +#include "common/common.h" #include "can.h" diff --git a/util/can_tx_buffer.c b/can_buffer/can_tx_buffer.c similarity index 97% rename from util/can_tx_buffer.c rename to can_buffer/can_tx_buffer.c index 2e6ec58e..9c90f7ae 100644 --- a/util/can_tx_buffer.c +++ b/can_buffer/can_tx_buffer.c @@ -1,6 +1,6 @@ #include -#include "common.h" +#include "common/common.h" #include "can.h" #include "can_tx_buffer.h" diff --git a/util/can_tx_buffer.h b/can_buffer/can_tx_buffer.h similarity index 97% rename from util/can_tx_buffer.h rename to can_buffer/can_tx_buffer.h index df64ffe0..5bf98495 100644 --- a/util/can_tx_buffer.h +++ b/can_buffer/can_tx_buffer.h @@ -4,7 +4,7 @@ #include #include -#include "common.h" +#include "common/common.h" #include "can.h" diff --git a/util/safe_ring_buffer.c b/can_buffer/safe_ring_buffer.c similarity index 98% rename from util/safe_ring_buffer.c rename to can_buffer/safe_ring_buffer.c index 7efab72b..b26c7106 100644 --- a/util/safe_ring_buffer.c +++ b/can_buffer/safe_ring_buffer.c @@ -1,7 +1,7 @@ #include #include -#include "common.h" +#include "common/common.h" #include "safe_ring_buffer.h" diff --git a/util/safe_ring_buffer.h b/can_buffer/safe_ring_buffer.h similarity index 98% rename from util/safe_ring_buffer.h rename to can_buffer/safe_ring_buffer.h index fa328c7d..ccee52cc 100644 --- a/util/safe_ring_buffer.h +++ b/can_buffer/safe_ring_buffer.h @@ -4,7 +4,7 @@ #include #include -#include "common.h" +#include "common/common.h" /* * Context variable for the module. This allows you to initialize multiple diff --git a/util/timing_util.c b/can_buffer/timing_util.c similarity index 97% rename from util/timing_util.c rename to can_buffer/timing_util.c index 9ae97a2d..4e579d08 100644 --- a/util/timing_util.c +++ b/can_buffer/timing_util.c @@ -1,6 +1,6 @@ #include -#include "common.h" +#include "common/common.h" #include "can.h" #include "timing_util.h" diff --git a/util/timing_util.h b/can_buffer/timing_util.h similarity index 95% rename from util/timing_util.h rename to can_buffer/timing_util.h index a3aa86db..bd94346e 100644 --- a/util/timing_util.h +++ b/can_buffer/timing_util.h @@ -4,7 +4,7 @@ #include #include -#include "common.h" +#include "common/common.h" #include "can.h" diff --git a/message/msg_actuator.c b/can_message/msg_actuator.c similarity index 98% rename from message/msg_actuator.c rename to can_message/msg_actuator.c index 9af719ff..ad005158 100644 --- a/message/msg_actuator.c +++ b/can_message/msg_actuator.c @@ -1,7 +1,7 @@ #include #include -#include "common.h" +#include "common/common.h" #include "can.h" #include "message_types.h" diff --git a/message/msg_actuator.h b/can_message/msg_actuator.h similarity index 97% rename from message/msg_actuator.h rename to can_message/msg_actuator.h index 075dc854..743665cb 100644 --- a/message/msg_actuator.h +++ b/can_message/msg_actuator.h @@ -4,7 +4,7 @@ #include #include -#include "common.h" +#include "common/common.h" #include "can.h" #include "message_types.h" diff --git a/message/msg_canards.c b/can_message/msg_canards.c similarity index 98% rename from message/msg_canards.c rename to can_message/msg_canards.c index b0ba6630..a3933afa 100644 --- a/message/msg_canards.c +++ b/can_message/msg_canards.c @@ -1,7 +1,7 @@ #include #include -#include "common.h" +#include "common/common.h" #include "can.h" #include "message_types.h" diff --git a/message/msg_canards.h b/can_message/msg_canards.h similarity index 98% rename from message/msg_canards.h rename to can_message/msg_canards.h index 3b1a457d..e9928f47 100644 --- a/message/msg_canards.h +++ b/can_message/msg_canards.h @@ -4,7 +4,7 @@ #include #include -#include "common.h" +#include "common/common.h" #include "can.h" #include "message_types.h" diff --git a/message/msg_common.h b/can_message/msg_common.h similarity index 99% rename from message/msg_common.h rename to can_message/msg_common.h index 4c115735..58850c76 100644 --- a/message/msg_common.h +++ b/can_message/msg_common.h @@ -7,7 +7,7 @@ #include "can.h" #include "message_types.h" -#include "common.h" +#include "common/common.h" #ifndef CANLIB_DYNAMIC_BOARD_ID diff --git a/message/msg_general.c b/can_message/msg_general.c similarity index 99% rename from message/msg_general.c rename to can_message/msg_general.c index 486d34cd..603c2d1e 100644 --- a/message/msg_general.c +++ b/can_message/msg_general.c @@ -2,7 +2,7 @@ #include #include -#include "common.h" +#include "common/common.h" #include "can.h" #include "message_types.h" diff --git a/message/msg_general.h b/can_message/msg_general.h similarity index 98% rename from message/msg_general.h rename to can_message/msg_general.h index 6c6c2bfd..9fbcea0b 100644 --- a/message/msg_general.h +++ b/can_message/msg_general.h @@ -4,7 +4,7 @@ #include #include -#include "common.h" +#include "common/common.h" #include "can.h" #include "message_types.h" diff --git a/message/msg_gps.c b/can_message/msg_gps.c similarity index 99% rename from message/msg_gps.c rename to can_message/msg_gps.c index 1fd69f70..90ca5924 100644 --- a/message/msg_gps.c +++ b/can_message/msg_gps.c @@ -1,7 +1,7 @@ #include #include -#include "common.h" +#include "common/common.h" #include "can.h" #include "message_types.h" diff --git a/message/msg_gps.h b/can_message/msg_gps.h similarity index 99% rename from message/msg_gps.h rename to can_message/msg_gps.h index ff269511..015e7f2a 100644 --- a/message/msg_gps.h +++ b/can_message/msg_gps.h @@ -4,7 +4,7 @@ #include #include -#include "common.h" +#include "common/common.h" #include "can.h" #include "message_types.h" diff --git a/message/msg_recovery.c b/can_message/msg_recovery.c similarity index 98% rename from message/msg_recovery.c rename to can_message/msg_recovery.c index c68ff039..ed37298f 100644 --- a/message/msg_recovery.c +++ b/can_message/msg_recovery.c @@ -1,6 +1,6 @@ #include -#include "common.h" +#include "common/common.h" #include "can.h" #include "message_types.h" diff --git a/message/msg_recovery.h b/can_message/msg_recovery.h similarity index 97% rename from message/msg_recovery.h rename to can_message/msg_recovery.h index 46182ba5..fd05925e 100644 --- a/message/msg_recovery.h +++ b/can_message/msg_recovery.h @@ -4,7 +4,7 @@ #include #include -#include "common.h" +#include "common/common.h" #include "can.h" #include "message_types.h" diff --git a/message/msg_sensor.c b/can_message/msg_sensor.c similarity index 99% rename from message/msg_sensor.c rename to can_message/msg_sensor.c index 94a68f2d..165c4a41 100644 --- a/message/msg_sensor.c +++ b/can_message/msg_sensor.c @@ -1,7 +1,7 @@ #include #include -#include "common.h" +#include "common/common.h" #include "can.h" #include "message_types.h" diff --git a/message/msg_sensor.h b/can_message/msg_sensor.h similarity index 99% rename from message/msg_sensor.h rename to can_message/msg_sensor.h index b5700595..86d7c1c9 100644 --- a/message/msg_sensor.h +++ b/can_message/msg_sensor.h @@ -4,7 +4,7 @@ #include #include -#include "common.h" +#include "common/common.h" #include "can.h" #include "message_types.h" diff --git a/message/msg_stream.c b/can_message/msg_stream.c similarity index 99% rename from message/msg_stream.c rename to can_message/msg_stream.c index 02c9f9c4..8a0ac036 100644 --- a/message/msg_stream.c +++ b/can_message/msg_stream.c @@ -1,7 +1,7 @@ #include #include -#include "common.h" +#include "common/common.h" #include "can.h" #include "message_types.h" diff --git a/message/msg_stream.h b/can_message/msg_stream.h similarity index 97% rename from message/msg_stream.h rename to can_message/msg_stream.h index 5f74464e..d53ad79e 100644 --- a/message/msg_stream.h +++ b/can_message/msg_stream.h @@ -4,7 +4,7 @@ #include #include -#include "common.h" +#include "common/common.h" #include "can.h" #include "message_types.h" diff --git a/message/msg_telemetry.c b/can_message/msg_telemetry.c similarity index 98% rename from message/msg_telemetry.c rename to can_message/msg_telemetry.c index 136e4b39..4f6764a3 100644 --- a/message/msg_telemetry.c +++ b/can_message/msg_telemetry.c @@ -1,7 +1,7 @@ #include #include -#include "common.h" +#include "common/common.h" #include "can.h" #include "message_types.h" diff --git a/message/msg_telemetry.h b/can_message/msg_telemetry.h similarity index 98% rename from message/msg_telemetry.h rename to can_message/msg_telemetry.h index f710396b..4ce3e04a 100644 --- a/message/msg_telemetry.h +++ b/can_message/msg_telemetry.h @@ -4,7 +4,7 @@ #include #include -#include "common.h" +#include "common/common.h" #include "can.h" #include "message_types.h" diff --git a/canlib.h b/canlib.h deleted file mode 100644 index 20eff29b..00000000 --- a/canlib.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef CANLIB_CANLIB_H -#define CANLIB_CANLIB_H - -// NOLINTBEGIN - -#include "can.h" -#include "message_types.h" - -#include "message/msg_actuator.h" -#include "message/msg_canards.h" -#include "message/msg_common.h" -#include "message/msg_general.h" -#include "message/msg_gps.h" -#include "message/msg_recovery.h" -#include "message/msg_sensor.h" -#include "message/msg_stream.h" -#include "message/msg_telemetry.h" - -#include "util/can_rcv_buffer.h" -#include "util/can_tx_buffer.h" -#include "util/timing_util.h" - -#if (defined(STM32H723xx) || defined(STM32H733xx) || defined(STM32H750xx) || defined(STM32H753xx)) - -#include "stm32h7/stm32h7_can.h" - -#elif ConfName == PIC18F26K83 - -#include "pic18f26k83/pic18f26k83_can.h" - -#elif ConfName == MCP2515 - -#include "mcp2515/mcp_2515.h" - -#elif ConfName == DSPIC33EPXXXGP50X - -#include "dspic33epxxxgp50x/dspic33epxxxgp50x_can.h" - -#else - -#error "canlib project configuration not set." - -#endif - -// NOLINTEND - -#endif diff --git a/include/common.h b/common/common.h similarity index 100% rename from include/common.h rename to common/common.h diff --git a/dspic33e/dspic33e_can.c b/dspic33e/dspic33e_can.c deleted file mode 100644 index 802e6fe9..00000000 --- a/dspic33e/dspic33e_can.c +++ /dev/null @@ -1,271 +0,0 @@ -#include - -#include "dspic33e_can.h" - -static void (*can_rcv_cb)(const can_msg_t *message); - -// make a RAM buffer big enough to hold 32 CAN message -#define CAN_BUF_NUM 32 -static unsigned int can_msg_buf[CAN_BUF_NUM][8] __attribute__((aligned(CAN_BUF_NUM * 16))); - -// private functions -static void init_filters_and_masks(); -static void init_dma_channels(); -static void init_can_interrupts(); -static void buffer_to_msg(const unsigned int *buffer, can_msg_t *received); - -// Initialization function for CAN. The driver currently only runs in -// callback mode, and that callback will be triggered in an interrupt -// context. Please make the callback as short (in time) as possible. -void dspic33e_can_init(const can_timing_t *timing, - void (*receive_callback)(const can_msg_t *message), bool run_in_loopback) { - // store pointer to the receive callback - can_rcv_cb = receive_callback; - - // set can module to config mode - C1CTRL1bits.REQOP = 0x4; - // wait until that mode takes effect - while (C1CTRL1bits.OPMODE != 0x4) {} - - // allow writing of control bits - C1CTRL1bits.WIN = 1; - - // set baud rate and other timing details - C1CFG1bits.SJW = timing->sjw; - C1CFG1bits.BRP = timing->brp; - C1CFG2bits.SEG2PHTS = timing->btlmode; - C1CFG2bits.SAM = timing->sam; - C1CFG2bits.SEG1PH = timing->seg1ph; - C1CFG2bits.PRSEG = timing->prseg; - C1CFG2bits.SEG2PH = timing->seg2ph; - - // set up DMA and FIFO: don't use the FIFO, use 32 buffers for DMA - C1FCTRLbits.DMABS = 0b110; - C1FCTRLbits.FSA = 0b11111; - - // set up filters and masks - init_filters_and_masks(); - - // disable writes to C1CTRL - C1CTRL1bits.WIN = 0; - - // set the first transmit buffer as transmit, all others as - // receive buffers (we don't need plural transmits (I think)) - C1TR01CONbits.TXEN0 = 0x1; - C1TR01CONbits.TXEN1 = 0x0; - C1TR23CONbits.TXEN2 = 0x0; - C1TR23CONbits.TXEN3 = 0x0; - C1TR45CONbits.TXEN4 = 0x0; - C1TR45CONbits.TXEN5 = 0x0; - C1TR67CONbits.TXEN6 = 0x0; - C1TR67CONbits.TXEN7 = 0x0; - - // initialize the DMA module: This driver requires DMA0 and DMA1, - // so don't use those elsewhere - init_dma_channels(); - - // if you wanna run this driver in loopback mode, we can - // accomodate that - if (run_in_loopback) { - // set loopback mode - C1CTRL1bits.REQOP = 2; - // wait until change is applied - while (C1CTRL1bits.OPMODE != 0x2) {} - } else { - C1CTRL1bits.REQOP = 0; - while (C1CTRL1bits.OPMODE != 0) {} - } - - // initialize the interrupts - init_can_interrupts(); -} - -// Priority must be a 2 bit number defining how high the priority of -// this message is vs the other ones queued to be sent. 0 is lowest -// priority, 3 is highest -void dspic33e_can_send(const can_msg_t *message) { - // put the SID in buffer 0 of the DMA buffers - can_msg_buf[0][0] = ((message->sid >> 18) << 2) | 0x3; - can_msg_buf[0][1] = (message->sid >> 6) & 0xfff; - // set the length and rest of EID - can_msg_buf[0][2] = ((message->sid & 0x3f) << 10) | message->data_len; - - // copy data over. Note that this is a 16 bit part, so we - // interlace the bytes of data. To see the structure that the CAN - // module wants a CAN message to be in, look at datasheet section - // 21.5 - can_msg_buf[0][3] = ((message->data[1] << 8) | message->data[0]); - can_msg_buf[0][4] = ((message->data[3] << 8) | message->data[2]); - can_msg_buf[0][5] = ((message->data[5] << 8) | message->data[4]); - can_msg_buf[0][6] = ((message->data[7] << 8) | message->data[6]); - - // the message priority is always 3 (the highest) - C1TR01CONbits.TX0PRI = 3; - - C1TR01CONbits.TXREQ0 = 1; -} - -// Returns true if a message is ready to be sent -bool dspic33e_can_send_rdy(void) { - return C1TR01CONbits.TXREQ0 == 0; -} - -// Interrupt that runs whenever IFS2::C1IF is set -void __attribute__((__interrupt__, no_auto_psv)) _C1Interrupt(void) { - // a transmit successfully finished, we abort the message so it - // isn't set repeatedly - if (C1INTFbits.TBIF) { - C1INTFbits.TBIF = 0; - C1TR01CONbits.TXABT0 = 1; - return; - } - if (C1INTFbits.RBIF) { - // check all receive buffers, trigger the callback with every - // filled buffer - can_msg_t cb_message; - if (C1RXFUL1bits.RXFUL1) { - buffer_to_msg(can_msg_buf[1], &cb_message); - C1RXFUL1bits.RXFUL1 = 0; - can_rcv_cb(&cb_message); - } - if (C1RXFUL1bits.RXFUL2) { - buffer_to_msg(can_msg_buf[2], &cb_message); - C1RXFUL1bits.RXFUL2 = 0; - can_rcv_cb(&cb_message); - } - if (C1RXFUL1bits.RXFUL3) { - buffer_to_msg(can_msg_buf[3], &cb_message); - C1RXFUL1bits.RXFUL3 = 0; - can_rcv_cb(&cb_message); - } - if (C1RXFUL1bits.RXFUL4) { - buffer_to_msg(can_msg_buf[4], &cb_message); - C1RXFUL1bits.RXFUL4 = 0; - can_rcv_cb(&cb_message); - } - C1INTFbits.RBIF = 0; - return; - } - if (C1INTFbits.RBOVIF) { - // we weren't fast enough to catch all the messages - // in the future, raise a warning now - C1INTFbits.RBOVIF = 0; - return; - } - if (C1INTFbits.ERRIF) { - C1INTFbits.ERRIF = 0; - } - - // there are no other CAN interrupts that we want to deal - // with, so lower the main interrupt flag - IFS2bits.C1IF = 0; - return; -} - -// Converts the DsPIC's internal CAN message buffer format into our -// message struct format -static void buffer_to_msg(const unsigned int *buffer, can_msg_t *received) { - received->sid = ((buffer[0] >> 2) & 0x7ff) << 18; - received->sid |= (buffer[1] & 0xfff) << 6; - received->sid |= (buffer[2] >> 10) & 0x3f; - received->data_len = (buffer[2] & 0x0f); - // fallthroughs are intentional - switch (received->data_len) { - case 8: - received->data[7] = ((buffer[6] >> 8) & 0xff); - case 7: - received->data[6] = (buffer[6] & 0xff); - case 6: - received->data[5] = ((buffer[5] >> 8) & 0xff); - case 5: - received->data[4] = (buffer[5] & 0xff); - case 4: - received->data[3] = ((buffer[4] >> 8) & 0xff); - case 3: - received->data[2] = (buffer[4] & 0xff); - case 2: - received->data[1] = ((buffer[3] >> 8) & 0xff); - case 1: - received->data[0] = (buffer[3] & 0xff); - case 0: - default: - return; - } -} - -static void init_dma_channels() { - // use DMA channel 0 as the CAN Tx channel - DMA0CONbits.CHEN = 0; // disable for setup - DMA0CONbits.SIZE = 0; // set to word size, not byte size - DMA0CONbits.DIR = 1; // read from RAM, write to CAN - DMA0CONbits.AMODE = 0b10; // peripheral indirect addressing mode - DMA0CONbits.MODE = 0; // continuous mode, disable ping-pong mode - DMA0REQbits.IRQSEL = 0b01000110; // ECAN1-TX Data request - DMA0CNT = 7; // 8 words in a CAN message - DMA0PAD = (volatile uint16_t)&C1TXD; - DMA0STAL = (uint16_t)&can_msg_buf; - DMA0STAH = (uint16_t)&can_msg_buf; - DMA0CONbits.CHEN = 1; // we are go for DMA - - // enable DMA channel 1 as the CAN Rx channel - DMA1CONbits.CHEN = 0; - DMA1CONbits.SIZE = 0x0; - DMA1CONbits.DIR = 0x0; - DMA1CONbits.AMODE = 0x2; - DMA1CONbits.MODE = 0x0; - DMA1REQ = 34; - DMA1CNT = 7; - DMA1PAD = (volatile unsigned int)&C1RXD; - DMA1STAL = (unsigned int)&can_msg_buf; - DMA1STAH = (unsigned int)&can_msg_buf; - DMA1CONbits.CHEN = 0x1; -} - -static void init_can_interrupts() { - __builtin_enable_interrupts(); - - // put down a bunch of flags - C1RXFUL1 = 0; - C1RXFUL2 = 0; - C1RXOVF1 = 0; - C1RXOVF2 = 0; - C1INTFbits.RBIF = 0; - C1INTFbits.ERRIF = 0; - C1INTFbits.TBIF = 0; - - // enable interrupts on transmit and receive. Disable error interrupts - C1INTEbits.TBIE = 1; - C1INTEbits.RBIE = 1; - C1INTEbits.ERRIE = 0; - - // enable CAN1 interrupts - IEC2bits.C1IE = 1; -} - -// macro for the reduction of typing, only used in -// init_filters_and_masks. Sets filter n to point at mask 0, with -// filter SID 0, and cause the CAN buffer pointer for that filter to -// be n+1 -#define INIT_FILTER(n) \ - do { \ - /*point all filters at mask 0*/ \ - C1FMSKSEL1bits.F##n##MSK = 0; \ - /*set the filter SID to 0*/ \ - C1RXF##n##SID = 0; \ - /*point filter number at buffer (number+1)*/ \ - C1BUFPNT1bits.F##n##BP = ((n) + 1); \ - } while (0) - -// This driver does not currently support hardware filtering of -// incoming messages. All messages will be received, all will be -// handled the same through the callback. -static void init_filters_and_masks(void) { - // set mask 0 to accept all messages - C1RXM0SID = 0; - - // use 4 receive buffers in order to try to prevent overflows - INIT_FILTER(0); - INIT_FILTER(1); - INIT_FILTER(2); - INIT_FILTER(3); -} diff --git a/dspic33e/dspic33e_can.h b/dspic33e/dspic33e_can.h deleted file mode 100644 index 66982ada..00000000 --- a/dspic33e/dspic33e_can.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef CANLIB_DSPIC33E_CAN_H -#define CANLIB_DSPIC33E_CAN_H - -#include "can.h" - -#ifdef __cplusplus -#error "C++ is not supported" -#endif - -/** - * @brief Initialize DSPIC33E CAN Controller - * - * @param timing Timing parameters generated by `can_generate_timing_params` function - * @param receive_callback CAN message receive handler, the function would be called when a CAN - * message is received - * @param run_in_loopback Run CAN Controller in loopback mode when `true` - * - * @warning Note that this function DOES NOT setup the inputs and outputs from the CAN module to the - * output pins, application code must do that. In order to do that, CANRXPPS must be set to the - * proper pin value for the CANRX pin, and ___PPS must be set to 0x33 to mark it as outputting from - * the CAN module. In addition, TRIS and ANSEL registers for whatever pin is being used must be set - * to the right values. - */ -void dspic33e_can_init(const can_timing_t *timing, - void (*receive_callback)(const can_msg_t *message), bool run_in_loopback); - -/** - * @brief Send a CAN message - * - * @param message CAN message to be sent - */ -void dspic33e_can_send(const can_msg_t *message); - -/** - * @brief Check if CAN controller is ready to send a message - * - * @return return `true` if ready to send a message - */ -bool dspic33e_can_send_rdy(void); - -#endif diff --git a/tests/test_crc8.cpp b/tests/test_crc8.cpp index 4b6c14ee..484df0bd 100644 --- a/tests/test_crc8.cpp +++ b/tests/test_crc8.cpp @@ -1,6 +1,6 @@ #include -#include "common.h" +#include "common/common.h" #include "crc8.h" #include "rockettest.hpp" diff --git a/tests/test_low_pass_filter.cpp b/tests/test_low_pass_filter.cpp index cf6c5af9..16c158f8 100644 --- a/tests/test_low_pass_filter.cpp +++ b/tests/test_low_pass_filter.cpp @@ -4,7 +4,7 @@ #include #include -#include "common.h" +#include "common/common.h" #include "low_pass_filter.h" #include "rockettest.hpp" diff --git a/tests/test_mathops.cpp b/tests/test_mathops.cpp index 37ef5b22..9a0397ea 100644 --- a/tests/test_mathops.cpp +++ b/tests/test_mathops.cpp @@ -3,7 +3,7 @@ #include #include -#include "common.h" +#include "common/common.h" #include "mathops.h" #include "rockettest.hpp" diff --git a/tests/test_mbr.cpp b/tests/test_mbr.cpp index ed8c4d52..6b1ac869 100644 --- a/tests/test_mbr.cpp +++ b/tests/test_mbr.cpp @@ -1,6 +1,6 @@ #include -#include "common.h" +#include "common/common.h" #include "mbr.h" #include "rockettest.hpp" diff --git a/tests/test_msg_actuator.cpp b/tests/test_msg_actuator.cpp index 268668e3..41d427bb 100644 --- a/tests/test_msg_actuator.cpp +++ b/tests/test_msg_actuator.cpp @@ -1,12 +1,12 @@ #include #include -#include "common.h" +#include "common/common.h" #include "rockettest.hpp" #include "can.h" -#include "message/msg_actuator.h" -#include "message/msg_common.h" +#include "can_message/msg_actuator.h" +#include "can_message/msg_common.h" #include "message_types.h" class actuator_cmd_message_test : rockettest_test { diff --git a/tests/test_msg_canards.cpp b/tests/test_msg_canards.cpp index e3850578..0eeb3050 100644 --- a/tests/test_msg_canards.cpp +++ b/tests/test_msg_canards.cpp @@ -3,8 +3,8 @@ #include "rockettest.hpp" #include "can.h" -#include "message/msg_canards.h" -#include "message/msg_common.h" +#include "can_message/msg_canards.h" +#include "can_message/msg_common.h" #include "message_types.h" class canard_firmware_error_message_test : rockettest_test { diff --git a/tests/test_msg_common.cpp b/tests/test_msg_common.cpp index 1bca4204..b99c21f8 100644 --- a/tests/test_msg_common.cpp +++ b/tests/test_msg_common.cpp @@ -4,7 +4,7 @@ #include "rockettest.hpp" #include "can.h" -#include "message/msg_common.h" +#include "can_message/msg_common.h" class timestamp_test : rockettest_test { public: diff --git a/tests/test_msg_general.cpp b/tests/test_msg_general.cpp index 723b34b1..832a83f9 100644 --- a/tests/test_msg_general.cpp +++ b/tests/test_msg_general.cpp @@ -1,11 +1,11 @@ #include -#include "common.h" +#include "common/common.h" #include "rockettest.hpp" #include "can.h" -#include "message/msg_common.h" -#include "message/msg_general.h" +#include "can_message/msg_common.h" +#include "can_message/msg_general.h" #include "message_types.h" class general_status_message_test : rockettest_test { diff --git a/tests/test_msg_gps.cpp b/tests/test_msg_gps.cpp index 389231df..590fbabd 100644 --- a/tests/test_msg_gps.cpp +++ b/tests/test_msg_gps.cpp @@ -3,8 +3,8 @@ #include "rockettest.hpp" #include "can.h" -#include "message/msg_common.h" -#include "message/msg_gps.h" +#include "can_message/msg_common.h" +#include "can_message/msg_gps.h" #include "message_types.h" class gps_timestamp_message_test : rockettest_test { diff --git a/tests/test_msg_recovery.cpp b/tests/test_msg_recovery.cpp index 40865e76..d049bdbf 100644 --- a/tests/test_msg_recovery.cpp +++ b/tests/test_msg_recovery.cpp @@ -3,8 +3,8 @@ #include "rockettest.hpp" #include "can.h" -#include "message/msg_common.h" -#include "message/msg_recovery.h" +#include "can_message/msg_common.h" +#include "can_message/msg_recovery.h" #include "message_types.h" class recovery_cmd_message_test : rockettest_test { diff --git a/tests/test_msg_sensor.cpp b/tests/test_msg_sensor.cpp index a97f301e..244defe0 100644 --- a/tests/test_msg_sensor.cpp +++ b/tests/test_msg_sensor.cpp @@ -3,8 +3,8 @@ #include "rockettest.hpp" #include "can.h" -#include "message/msg_common.h" -#include "message/msg_sensor.h" +#include "can_message/msg_common.h" +#include "can_message/msg_sensor.h" #include "message_types.h" namespace { diff --git a/tests/test_msg_stream.cpp b/tests/test_msg_stream.cpp index 99d0228e..e33e1c87 100644 --- a/tests/test_msg_stream.cpp +++ b/tests/test_msg_stream.cpp @@ -1,12 +1,12 @@ #include #include -#include "common.h" +#include "common/common.h" #include "rockettest.hpp" #include "can.h" -#include "message/msg_common.h" -#include "message/msg_stream.h" +#include "can_message/msg_common.h" +#include "can_message/msg_stream.h" #include "message_types.h" namespace { diff --git a/tests/test_msg_telemetry.cpp b/tests/test_msg_telemetry.cpp index 1844ee53..522fabcd 100644 --- a/tests/test_msg_telemetry.cpp +++ b/tests/test_msg_telemetry.cpp @@ -3,8 +3,8 @@ #include "rockettest.hpp" #include "can.h" -#include "message/msg_common.h" -#include "message/msg_telemetry.h" +#include "can_message/msg_common.h" +#include "can_message/msg_telemetry.h" #include "message_types.h" class telemetry_info_message_test : rockettest_test { diff --git a/tests/test_nullptr_reject.cpp b/tests/test_nullptr_reject.cpp index 9965f690..4ea23bc4 100644 --- a/tests/test_nullptr_reject.cpp +++ b/tests/test_nullptr_reject.cpp @@ -4,19 +4,19 @@ #include "message_types.h" #include "rockettest.hpp" -#include "message/msg_actuator.h" -#include "message/msg_canards.h" -#include "message/msg_common.h" -#include "message/msg_general.h" -#include "message/msg_gps.h" -#include "message/msg_recovery.h" -#include "message/msg_sensor.h" -#include "message/msg_stream.h" -#include "message/msg_telemetry.h" -#include "util/can_rcv_buffer.h" -#include "util/can_tx_buffer.h" -#include "util/safe_ring_buffer.h" -#include "util/timing_util.h" +#include "can_buffer/can_rcv_buffer.h" +#include "can_buffer/can_tx_buffer.h" +#include "can_buffer/safe_ring_buffer.h" +#include "can_buffer/timing_util.h" +#include "can_message/msg_actuator.h" +#include "can_message/msg_canards.h" +#include "can_message/msg_common.h" +#include "can_message/msg_general.h" +#include "can_message/msg_gps.h" +#include "can_message/msg_recovery.h" +#include "can_message/msg_sensor.h" +#include "can_message/msg_stream.h" +#include "can_message/msg_telemetry.h" namespace { diff --git a/tests/test_timing_util.cpp b/tests/test_timing_util.cpp index 63e1efd9..efbb0563 100644 --- a/tests/test_timing_util.cpp +++ b/tests/test_timing_util.cpp @@ -1,8 +1,8 @@ -#include "common.h" +#include "common/common.h" #include "rockettest.hpp" #include "can.h" -#include "util/timing_util.h" +#include "can_buffer/timing_util.h" class timing_util_test : public rockettest_test { public: diff --git a/tests/test_tx_rcv_buffer.cpp b/tests/test_tx_rcv_buffer.cpp index 0ea87cc2..a57e48b8 100644 --- a/tests/test_tx_rcv_buffer.cpp +++ b/tests/test_tx_rcv_buffer.cpp @@ -4,11 +4,11 @@ #include #include "can.h" -#include "common.h" +#include "common/common.h" #include "rockettest.hpp" -#include "util/can_rcv_buffer.h" -#include "util/can_tx_buffer.h" +#include "can_buffer/can_rcv_buffer.h" +#include "can_buffer/can_tx_buffer.h" // Tx Buffer Test From 69103eefcce65ba120777632b0f165210a03fc57 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Sat, 3 Oct 2026 19:18:47 -0400 Subject: [PATCH 104/108] Sort all files into folders --- Makefile | 33 +++++++++---- can.h | 47 ------------------- can_buffer/can_rcv_buffer.c | 2 +- can_buffer/can_rcv_buffer.h | 2 +- can_buffer/can_tx_buffer.c | 2 +- can_buffer/can_tx_buffer.h | 2 +- can_message/can.h | 18 +++++++ can_message/msg_actuator.c | 4 +- can_message/msg_actuator.h | 4 +- can_message/msg_canards.c | 4 +- can_message/msg_canards.h | 4 +- can_message/msg_common.h | 4 +- can_message/msg_general.c | 4 +- can_message/msg_general.h | 4 +- can_message/msg_gps.c | 4 +- can_message/msg_gps.h | 4 +- can_message/msg_recovery.c | 4 +- can_message/msg_recovery.h | 4 +- can_message/msg_sensor.c | 4 +- can_message/msg_sensor.h | 4 +- can_message/msg_stream.c | 4 +- can_message/msg_stream.h | 4 +- can_message/msg_telemetry.c | 4 +- can_message/msg_telemetry.h | 4 +- .../packet_format.h | 4 +- {include => common}/crc8.h | 0 {include => common}/electrical.h | 0 {include => common}/low_pass_filter.h | 0 {include => common}/mathops.h | 0 {common => logging}/mbr.c | 2 +- {include => logging}/mbr.h | 2 +- mcp2515/mcp2515.c | 2 +- mcp2515/mcp2515.h | 2 +- pic18f26k83/pic18f26k83_can.c | 1 + pic18f26k83/pic18f26k83_can.h | 4 +- {include => pic18f26k83}/timer.h | 0 {can_buffer => pic18f26k83}/timing_util.c | 1 - {can_buffer => pic18f26k83}/timing_util.h | 25 +++++++++- stm32h7/stm32h7_can.h | 2 +- tests/test_msg_actuator.cpp | 4 +- tests/test_msg_canards.cpp | 4 +- tests/test_msg_common.cpp | 4 +- tests/test_msg_general.cpp | 4 +- tests/test_msg_gps.cpp | 4 +- tests/test_msg_recovery.cpp | 4 +- tests/test_msg_sensor.cpp | 4 +- tests/test_msg_stream.cpp | 4 +- tests/test_msg_telemetry.cpp | 4 +- tests/test_nullptr_reject.cpp | 6 +-- tests/test_timing_util.cpp | 4 +- tests/test_tx_rcv_buffer.cpp | 2 +- 51 files changed, 137 insertions(+), 130 deletions(-) delete mode 100644 can.h create mode 100644 can_message/can.h rename message_types.h => can_message/packet_format.h (99%) rename {include => common}/crc8.h (100%) rename {include => common}/electrical.h (100%) rename {include => common}/low_pass_filter.h (100%) rename {include => common}/mathops.h (100%) rename {common => logging}/mbr.c (97%) rename {include => logging}/mbr.h (96%) rename {include => pic18f26k83}/timer.h (100%) rename {can_buffer => pic18f26k83}/timing_util.c (98%) rename {can_buffer => pic18f26k83}/timing_util.h (54%) diff --git a/Makefile b/Makefile index 66a59009..6e171bee 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,7 @@ COMMON_C_SRCS := \ + can_buffer/can_rcv_buffer.c \ + can_buffer/can_tx_buffer.c \ + can_buffer/safe_ring_buffer.c \ can_message/msg_actuator.c \ can_message/msg_canards.c \ can_message/msg_general.c \ @@ -7,12 +10,15 @@ COMMON_C_SRCS := \ can_message/msg_sensor.c \ can_message/msg_stream.c \ can_message/msg_telemetry.c \ - can_buffer/can_rcv_buffer.c \ - can_buffer/can_tx_buffer.c \ - can_buffer/safe_ring_buffer.c \ - can_buffer/timing_util.c + common/crc8.c \ + common/low_pass_filter.c \ + logging/mbr.c \ + pic18f26k83/timing_util.c COMMON_C_HEADERS := \ + can_buffer/can_rcv_buffer.h \ + can_buffer/can_tx_buffer.h \ + can_buffer/safe_ring_buffer.h \ can_message/msg_actuator.h \ can_message/msg_canards.h \ can_message/msg_common.h \ @@ -22,14 +28,21 @@ COMMON_C_HEADERS := \ can_message/msg_sensor.h \ can_message/msg_stream.h \ can_message/msg_telemetry.h \ - can_buffer/can_rcv_buffer.h \ - can_buffer/can_tx_buffer.h \ - can_buffer/safe_ring_buffer.h \ - can_buffer/timing_util.h + common/common.h \ + common/crc8.h \ + common/electrical.h \ + common/low_pass_filter.h \ + common/mathops.h \ + logging/mbr.h \ + pic18f26k83/timing_util.h -PIC18_C_SRCS := pic18f26k83/pic18f26k83_can.c +PIC18_C_SRCS := \ + pic18f26k83/pic18f26k83_can.c \ + pic18f26k83/timer.c -PIC18_C_HEADERS := pic18f26k83/pic18f26k83_can.h +PIC18_C_HEADERS := \ + pic18f26k83/pic18f26k83_can.h \ + pic18f26k83/timer.h STM32H7_C_SRCS := stm32h7/stm32h7_can.c diff --git a/can.h b/can.h deleted file mode 100644 index d680c7e3..00000000 --- a/can.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * file that defines structures that are common across all 3 of - * Waterloo Rocketry's CAN implementations - */ - -#ifndef CANLIB_CAN_H -#define CANLIB_CAN_H - -#include -#include - -#define CANLIB_BIT_TIME_US 4 - -typedef uint32_t can_sid_t; - -// Timing parameters -typedef struct { - // BaudRate Prescaler - uint8_t brp; - // Synchronization Jump Width - uint8_t sjw; - - // sample once or three times - uint8_t sam; - // phase segment 1 bits - uint8_t seg1ph; - // phase segment 2 bits - uint8_t seg2ph; - // propagation time segment bits - uint8_t prseg; - - // Phase segment 2 time select bit. If true, then use seg2ph, - // otherwise take minimum viable phase length - bool btlmode; -} can_timing_t; - -// Things that are in a CAN message -typedef struct { - // Standard Identifier - 29 bits long - can_sid_t sid; - // How many bytes are used in data - uint8_t data_len; - // the data you want to transmit - uint8_t data[8]; -} can_msg_t; - -#endif // CAN_H_ diff --git a/can_buffer/can_rcv_buffer.c b/can_buffer/can_rcv_buffer.c index 3f82b44e..7ab5e00f 100644 --- a/can_buffer/can_rcv_buffer.c +++ b/can_buffer/can_rcv_buffer.c @@ -2,7 +2,7 @@ #include "common/common.h" -#include "can.h" +#include "can_message/can.h" #include "can_rcv_buffer.h" #include "safe_ring_buffer.h" diff --git a/can_buffer/can_rcv_buffer.h b/can_buffer/can_rcv_buffer.h index 37feb70b..1eaa02e2 100644 --- a/can_buffer/can_rcv_buffer.h +++ b/can_buffer/can_rcv_buffer.h @@ -26,7 +26,7 @@ #include "common/common.h" -#include "can.h" +#include "can_message/can.h" #ifdef __cplusplus extern "C" { diff --git a/can_buffer/can_tx_buffer.c b/can_buffer/can_tx_buffer.c index 9c90f7ae..518716c9 100644 --- a/can_buffer/can_tx_buffer.c +++ b/can_buffer/can_tx_buffer.c @@ -2,7 +2,7 @@ #include "common/common.h" -#include "can.h" +#include "can_message/can.h" #include "can_tx_buffer.h" #include "safe_ring_buffer.h" diff --git a/can_buffer/can_tx_buffer.h b/can_buffer/can_tx_buffer.h index 5bf98495..573013ed 100644 --- a/can_buffer/can_tx_buffer.h +++ b/can_buffer/can_tx_buffer.h @@ -6,7 +6,7 @@ #include "common/common.h" -#include "can.h" +#include "can_message/can.h" #ifdef __cplusplus extern "C" { diff --git a/can_message/can.h b/can_message/can.h new file mode 100644 index 00000000..68930a4d --- /dev/null +++ b/can_message/can.h @@ -0,0 +1,18 @@ +#ifndef ROCKETLIB_CAN_H +#define ROCKETLIB_CAN_H + +#include +#include + +typedef uint32_t can_sid_t; + +typedef struct { + // Standard Identifier - 29 bits long + can_sid_t sid; + // How many bytes are used in data + uint8_t data_len; + // the data you want to transmit + uint8_t data[8]; +} can_msg_t; + +#endif diff --git a/can_message/msg_actuator.c b/can_message/msg_actuator.c index ad005158..a5c370fb 100644 --- a/can_message/msg_actuator.c +++ b/can_message/msg_actuator.c @@ -3,8 +3,8 @@ #include "common/common.h" -#include "can.h" -#include "message_types.h" +#include "can_message/can.h" +#include "can_message/packet_format.h" #include "msg_actuator.h" #include "msg_common.h" diff --git a/can_message/msg_actuator.h b/can_message/msg_actuator.h index 743665cb..d5e6748d 100644 --- a/can_message/msg_actuator.h +++ b/can_message/msg_actuator.h @@ -6,8 +6,8 @@ #include "common/common.h" -#include "can.h" -#include "message_types.h" +#include "can_message/can.h" +#include "can_message/packet_format.h" #ifdef __cplusplus extern "C" { diff --git a/can_message/msg_canards.c b/can_message/msg_canards.c index a3933afa..c81ce1a5 100644 --- a/can_message/msg_canards.c +++ b/can_message/msg_canards.c @@ -3,8 +3,8 @@ #include "common/common.h" -#include "can.h" -#include "message_types.h" +#include "can_message/can.h" +#include "can_message/packet_format.h" #include "msg_canards.h" #include "msg_common.h" diff --git a/can_message/msg_canards.h b/can_message/msg_canards.h index e9928f47..ddcaaf89 100644 --- a/can_message/msg_canards.h +++ b/can_message/msg_canards.h @@ -6,8 +6,8 @@ #include "common/common.h" -#include "can.h" -#include "message_types.h" +#include "can_message/can.h" +#include "can_message/packet_format.h" #ifdef __cplusplus extern "C" { diff --git a/can_message/msg_common.h b/can_message/msg_common.h index 58850c76..c3f39b00 100644 --- a/can_message/msg_common.h +++ b/can_message/msg_common.h @@ -4,8 +4,8 @@ #include #include -#include "can.h" -#include "message_types.h" +#include "can_message/can.h" +#include "can_message/packet_format.h" #include "common/common.h" diff --git a/can_message/msg_general.c b/can_message/msg_general.c index 603c2d1e..2c2e07c5 100644 --- a/can_message/msg_general.c +++ b/can_message/msg_general.c @@ -4,8 +4,8 @@ #include "common/common.h" -#include "can.h" -#include "message_types.h" +#include "can_message/can.h" +#include "can_message/packet_format.h" #include "msg_common.h" #include "msg_general.h" diff --git a/can_message/msg_general.h b/can_message/msg_general.h index 9fbcea0b..b3182cde 100644 --- a/can_message/msg_general.h +++ b/can_message/msg_general.h @@ -6,8 +6,8 @@ #include "common/common.h" -#include "can.h" -#include "message_types.h" +#include "can_message/can.h" +#include "can_message/packet_format.h" #ifdef __cplusplus extern "C" { diff --git a/can_message/msg_gps.c b/can_message/msg_gps.c index 90ca5924..6bc56025 100644 --- a/can_message/msg_gps.c +++ b/can_message/msg_gps.c @@ -3,8 +3,8 @@ #include "common/common.h" -#include "can.h" -#include "message_types.h" +#include "can_message/can.h" +#include "can_message/packet_format.h" #include "msg_common.h" #include "msg_gps.h" diff --git a/can_message/msg_gps.h b/can_message/msg_gps.h index 015e7f2a..08a66cc0 100644 --- a/can_message/msg_gps.h +++ b/can_message/msg_gps.h @@ -6,8 +6,8 @@ #include "common/common.h" -#include "can.h" -#include "message_types.h" +#include "can_message/can.h" +#include "can_message/packet_format.h" #ifdef __cplusplus extern "C" { diff --git a/can_message/msg_recovery.c b/can_message/msg_recovery.c index ed37298f..8dc02a48 100644 --- a/can_message/msg_recovery.c +++ b/can_message/msg_recovery.c @@ -2,8 +2,8 @@ #include "common/common.h" -#include "can.h" -#include "message_types.h" +#include "can_message/can.h" +#include "can_message/packet_format.h" #include "msg_common.h" #include "msg_recovery.h" diff --git a/can_message/msg_recovery.h b/can_message/msg_recovery.h index fd05925e..a057798d 100644 --- a/can_message/msg_recovery.h +++ b/can_message/msg_recovery.h @@ -6,8 +6,8 @@ #include "common/common.h" -#include "can.h" -#include "message_types.h" +#include "can_message/can.h" +#include "can_message/packet_format.h" #ifdef __cplusplus extern "C" { diff --git a/can_message/msg_sensor.c b/can_message/msg_sensor.c index 165c4a41..9162ba13 100644 --- a/can_message/msg_sensor.c +++ b/can_message/msg_sensor.c @@ -3,8 +3,8 @@ #include "common/common.h" -#include "can.h" -#include "message_types.h" +#include "can_message/can.h" +#include "can_message/packet_format.h" #include "msg_common.h" #include "msg_sensor.h" diff --git a/can_message/msg_sensor.h b/can_message/msg_sensor.h index 86d7c1c9..ccead023 100644 --- a/can_message/msg_sensor.h +++ b/can_message/msg_sensor.h @@ -6,8 +6,8 @@ #include "common/common.h" -#include "can.h" -#include "message_types.h" +#include "can_message/can.h" +#include "can_message/packet_format.h" #ifdef __cplusplus extern "C" { diff --git a/can_message/msg_stream.c b/can_message/msg_stream.c index 8a0ac036..508e13c7 100644 --- a/can_message/msg_stream.c +++ b/can_message/msg_stream.c @@ -3,8 +3,8 @@ #include "common/common.h" -#include "can.h" -#include "message_types.h" +#include "can_message/can.h" +#include "can_message/packet_format.h" #include "msg_common.h" #include "msg_stream.h" diff --git a/can_message/msg_stream.h b/can_message/msg_stream.h index d53ad79e..3e753c9c 100644 --- a/can_message/msg_stream.h +++ b/can_message/msg_stream.h @@ -6,8 +6,8 @@ #include "common/common.h" -#include "can.h" -#include "message_types.h" +#include "can_message/can.h" +#include "can_message/packet_format.h" #ifdef __cplusplus extern "C" { diff --git a/can_message/msg_telemetry.c b/can_message/msg_telemetry.c index 4f6764a3..3cffe517 100644 --- a/can_message/msg_telemetry.c +++ b/can_message/msg_telemetry.c @@ -3,8 +3,8 @@ #include "common/common.h" -#include "can.h" -#include "message_types.h" +#include "can_message/can.h" +#include "can_message/packet_format.h" #include "msg_common.h" #include "msg_telemetry.h" diff --git a/can_message/msg_telemetry.h b/can_message/msg_telemetry.h index 4ce3e04a..28609731 100644 --- a/can_message/msg_telemetry.h +++ b/can_message/msg_telemetry.h @@ -6,8 +6,8 @@ #include "common/common.h" -#include "can.h" -#include "message_types.h" +#include "can_message/can.h" +#include "can_message/packet_format.h" #ifdef __cplusplus extern "C" { diff --git a/message_types.h b/can_message/packet_format.h similarity index 99% rename from message_types.h rename to can_message/packet_format.h index 519cbba1..b877714c 100644 --- a/message_types.h +++ b/can_message/packet_format.h @@ -1,7 +1,7 @@ // Auto generated file, do not edit directly -#ifndef CANLIB_MESSAGE_TYPES_H -#define CANLIB_MESSAGE_TYPES_H +#ifndef CANLIB_PACKET_FORAMT_H +#define CANLIB_PACKET_FORAMT_H // Message Priority typedef enum { diff --git a/include/crc8.h b/common/crc8.h similarity index 100% rename from include/crc8.h rename to common/crc8.h diff --git a/include/electrical.h b/common/electrical.h similarity index 100% rename from include/electrical.h rename to common/electrical.h diff --git a/include/low_pass_filter.h b/common/low_pass_filter.h similarity index 100% rename from include/low_pass_filter.h rename to common/low_pass_filter.h diff --git a/include/mathops.h b/common/mathops.h similarity index 100% rename from include/mathops.h rename to common/mathops.h diff --git a/common/mbr.c b/logging/mbr.c similarity index 97% rename from common/mbr.c rename to logging/mbr.c index 795c2d4d..3f08eefb 100644 --- a/common/mbr.c +++ b/logging/mbr.c @@ -1,6 +1,6 @@ #include -#include "common.h" +#include "common/common.h" #include "mbr.h" #define BOOT_SIGNATURE_OFFSET 0x1fe diff --git a/include/mbr.h b/logging/mbr.h similarity index 96% rename from include/mbr.h rename to logging/mbr.h index 505d411c..9cca1047 100644 --- a/include/mbr.h +++ b/logging/mbr.h @@ -4,7 +4,7 @@ #include #include -#include "common.h" +#include "common/common.h" #ifdef __cplusplus extern "C" { diff --git a/mcp2515/mcp2515.c b/mcp2515/mcp2515.c index 47b31602..6bb9ca67 100644 --- a/mcp2515/mcp2515.c +++ b/mcp2515/mcp2515.c @@ -1,6 +1,6 @@ #include -#include "can.h" +#include "can_message/can.h" #include "mcp2515.h" #include "mcp2515_regs.h" diff --git a/mcp2515/mcp2515.h b/mcp2515/mcp2515.h index 2d8730a3..20dabd4a 100644 --- a/mcp2515/mcp2515.h +++ b/mcp2515/mcp2515.h @@ -4,7 +4,7 @@ #include #include -#include "can.h" +#include "can_message/can.h" #ifdef __cplusplus #error "C++ is not supported" diff --git a/pic18f26k83/pic18f26k83_can.c b/pic18f26k83/pic18f26k83_can.c index 0d1f3aca..bc33661e 100644 --- a/pic18f26k83/pic18f26k83_can.c +++ b/pic18f26k83/pic18f26k83_can.c @@ -2,6 +2,7 @@ #include #include "pic18f26k83_can.h" +#include "timing_util.h" static void (*can_rcv_cb)(const can_msg_t *message); diff --git a/pic18f26k83/pic18f26k83_can.h b/pic18f26k83/pic18f26k83_can.h index 69bfbc79..7663fb74 100644 --- a/pic18f26k83/pic18f26k83_can.h +++ b/pic18f26k83/pic18f26k83_can.h @@ -3,7 +3,9 @@ #include -#include "can.h" +#include "can_message/can.h" + +#include "timing_util.h" #ifdef __cplusplus #error "C++ is not supported" diff --git a/include/timer.h b/pic18f26k83/timer.h similarity index 100% rename from include/timer.h rename to pic18f26k83/timer.h diff --git a/can_buffer/timing_util.c b/pic18f26k83/timing_util.c similarity index 98% rename from can_buffer/timing_util.c rename to pic18f26k83/timing_util.c index 4e579d08..f8222cbb 100644 --- a/can_buffer/timing_util.c +++ b/pic18f26k83/timing_util.c @@ -2,7 +2,6 @@ #include "common/common.h" -#include "can.h" #include "timing_util.h" #if (CANLIB_BIT_TIME_US != 4) diff --git a/can_buffer/timing_util.h b/pic18f26k83/timing_util.h similarity index 54% rename from can_buffer/timing_util.h rename to pic18f26k83/timing_util.h index bd94346e..7abbaefb 100644 --- a/can_buffer/timing_util.h +++ b/pic18f26k83/timing_util.h @@ -6,12 +6,33 @@ #include "common/common.h" -#include "can.h" - #ifdef __cplusplus extern "C" { #endif +#define CANLIB_BIT_TIME_US 4 + +// Timing parameters +typedef struct { + // BaudRate Prescaler + uint8_t brp; + // Synchronization Jump Width + uint8_t sjw; + + // sample once or three times + uint8_t sam; + // phase segment 1 bits + uint8_t seg1ph; + // phase segment 2 bits + uint8_t seg2ph; + // propagation time segment bits + uint8_t prseg; + + // Phase segment 2 time select bit. If true, then use seg2ph, + // otherwise take minimum viable phase length + bool btlmode; +} can_timing_t; + /** * @brief Generate CAN bus timing setting for PIC microcontrollers * @param system_freq PIC Fosc frequency in Hz diff --git a/stm32h7/stm32h7_can.h b/stm32h7/stm32h7_can.h index 7219e6dd..dce1f1c9 100644 --- a/stm32h7/stm32h7_can.h +++ b/stm32h7/stm32h7_can.h @@ -5,7 +5,7 @@ #include "stm32h7xx_hal.h" -#include "can.h" +#include "can_message/can.h" #ifdef __cplusplus extern "C" { diff --git a/tests/test_msg_actuator.cpp b/tests/test_msg_actuator.cpp index 41d427bb..6cc79157 100644 --- a/tests/test_msg_actuator.cpp +++ b/tests/test_msg_actuator.cpp @@ -4,10 +4,10 @@ #include "common/common.h" #include "rockettest.hpp" -#include "can.h" +#include "can_message/can.h" #include "can_message/msg_actuator.h" #include "can_message/msg_common.h" -#include "message_types.h" +#include "can_message/packet_format.h" class actuator_cmd_message_test : rockettest_test { public: diff --git a/tests/test_msg_canards.cpp b/tests/test_msg_canards.cpp index 0eeb3050..acb24013 100644 --- a/tests/test_msg_canards.cpp +++ b/tests/test_msg_canards.cpp @@ -2,10 +2,10 @@ #include "rockettest.hpp" -#include "can.h" +#include "can_message/can.h" #include "can_message/msg_canards.h" #include "can_message/msg_common.h" -#include "message_types.h" +#include "can_message/packet_format.h" class canard_firmware_error_message_test : rockettest_test { public: diff --git a/tests/test_msg_common.cpp b/tests/test_msg_common.cpp index b99c21f8..12c1dafb 100644 --- a/tests/test_msg_common.cpp +++ b/tests/test_msg_common.cpp @@ -1,9 +1,9 @@ #include -#include "message_types.h" +#include "can_message/packet_format.h" #include "rockettest.hpp" -#include "can.h" +#include "can_message/can.h" #include "can_message/msg_common.h" class timestamp_test : rockettest_test { diff --git a/tests/test_msg_general.cpp b/tests/test_msg_general.cpp index 832a83f9..b20873e3 100644 --- a/tests/test_msg_general.cpp +++ b/tests/test_msg_general.cpp @@ -3,10 +3,10 @@ #include "common/common.h" #include "rockettest.hpp" -#include "can.h" +#include "can_message/can.h" #include "can_message/msg_common.h" #include "can_message/msg_general.h" -#include "message_types.h" +#include "can_message/packet_format.h" class general_status_message_test : rockettest_test { public: diff --git a/tests/test_msg_gps.cpp b/tests/test_msg_gps.cpp index 590fbabd..79ce782e 100644 --- a/tests/test_msg_gps.cpp +++ b/tests/test_msg_gps.cpp @@ -2,10 +2,10 @@ #include "rockettest.hpp" -#include "can.h" +#include "can_message/can.h" #include "can_message/msg_common.h" #include "can_message/msg_gps.h" -#include "message_types.h" +#include "can_message/packet_format.h" class gps_timestamp_message_test : rockettest_test { public: diff --git a/tests/test_msg_recovery.cpp b/tests/test_msg_recovery.cpp index d049bdbf..ed58d0e9 100644 --- a/tests/test_msg_recovery.cpp +++ b/tests/test_msg_recovery.cpp @@ -2,10 +2,10 @@ #include "rockettest.hpp" -#include "can.h" +#include "can_message/can.h" #include "can_message/msg_common.h" #include "can_message/msg_recovery.h" -#include "message_types.h" +#include "can_message/packet_format.h" class recovery_cmd_message_test : rockettest_test { public: diff --git a/tests/test_msg_sensor.cpp b/tests/test_msg_sensor.cpp index 244defe0..754d523b 100644 --- a/tests/test_msg_sensor.cpp +++ b/tests/test_msg_sensor.cpp @@ -2,10 +2,10 @@ #include "rockettest.hpp" -#include "can.h" +#include "can_message/can.h" #include "can_message/msg_common.h" #include "can_message/msg_sensor.h" -#include "message_types.h" +#include "can_message/packet_format.h" namespace { diff --git a/tests/test_msg_stream.cpp b/tests/test_msg_stream.cpp index e33e1c87..a61e0f92 100644 --- a/tests/test_msg_stream.cpp +++ b/tests/test_msg_stream.cpp @@ -4,10 +4,10 @@ #include "common/common.h" #include "rockettest.hpp" -#include "can.h" +#include "can_message/can.h" #include "can_message/msg_common.h" #include "can_message/msg_stream.h" -#include "message_types.h" +#include "can_message/packet_format.h" namespace { diff --git a/tests/test_msg_telemetry.cpp b/tests/test_msg_telemetry.cpp index 522fabcd..33a2cf91 100644 --- a/tests/test_msg_telemetry.cpp +++ b/tests/test_msg_telemetry.cpp @@ -2,10 +2,10 @@ #include "rockettest.hpp" -#include "can.h" +#include "can_message/can.h" #include "can_message/msg_common.h" #include "can_message/msg_telemetry.h" -#include "message_types.h" +#include "can_message/packet_format.h" class telemetry_info_message_test : rockettest_test { public: diff --git a/tests/test_nullptr_reject.cpp b/tests/test_nullptr_reject.cpp index 4ea23bc4..2d9ebaeb 100644 --- a/tests/test_nullptr_reject.cpp +++ b/tests/test_nullptr_reject.cpp @@ -1,13 +1,12 @@ #include -#include "can.h" -#include "message_types.h" +#include "can_message/can.h" +#include "can_message/packet_format.h" #include "rockettest.hpp" #include "can_buffer/can_rcv_buffer.h" #include "can_buffer/can_tx_buffer.h" #include "can_buffer/safe_ring_buffer.h" -#include "can_buffer/timing_util.h" #include "can_message/msg_actuator.h" #include "can_message/msg_canards.h" #include "can_message/msg_common.h" @@ -17,6 +16,7 @@ #include "can_message/msg_sensor.h" #include "can_message/msg_stream.h" #include "can_message/msg_telemetry.h" +#include "pic18f26k83/timing_util.h" namespace { diff --git a/tests/test_timing_util.cpp b/tests/test_timing_util.cpp index efbb0563..1f30b589 100644 --- a/tests/test_timing_util.cpp +++ b/tests/test_timing_util.cpp @@ -1,8 +1,8 @@ #include "common/common.h" #include "rockettest.hpp" -#include "can.h" -#include "can_buffer/timing_util.h" +#include "can_message/can.h" +#include "pic18f26k83/timing_util.h" class timing_util_test : public rockettest_test { public: diff --git a/tests/test_tx_rcv_buffer.cpp b/tests/test_tx_rcv_buffer.cpp index a57e48b8..d8c7fd9e 100644 --- a/tests/test_tx_rcv_buffer.cpp +++ b/tests/test_tx_rcv_buffer.cpp @@ -3,7 +3,7 @@ #include #include -#include "can.h" +#include "can_message/can.h" #include "common/common.h" #include "rockettest.hpp" From fee9beb7959c26d56d7763a50249b827a67c3c06 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Sat, 3 Oct 2026 20:14:00 -0400 Subject: [PATCH 105/108] Update include guard format --- Makefile | 15 ++++++++++----- can_buffer/can_rcv_buffer.h | 4 ++-- can_buffer/can_tx_buffer.h | 4 ++-- can_buffer/safe_ring_buffer.h | 4 ++-- can_message/msg_actuator.h | 4 ++-- can_message/msg_canards.h | 4 ++-- can_message/msg_common.h | 8 ++++---- can_message/msg_general.c | 2 +- can_message/msg_general.h | 4 ++-- can_message/msg_gps.h | 4 ++-- can_message/msg_recovery.h | 4 ++-- can_message/msg_sensor.h | 4 ++-- can_message/msg_stream.h | 4 ++-- can_message/msg_telemetry.h | 4 ++-- can_message/packet_format.h | 4 ++-- flows/firmware-library.mk | 6 +++--- mcp2515/mcp2515.h | 4 ++-- mcp2515/mcp2515_regs.h | 4 ++-- pic18f26k83/pic18f26k83_can.c | 2 +- pic18f26k83/pic18f26k83_can.h | 6 +++--- ...iming_util.c => pic18f26k83_can_timing_util.c} | 6 +++--- ...iming_util.h => pic18f26k83_can_timing_util.h} | 8 ++++---- pic18f26k83/{timer.c => pic18f26k83_timer.c} | 2 +- pic18f26k83/{timer.h => pic18f26k83_timer.h} | 0 stm32h7/stm32h7_can.h | 4 ++-- tests/test_crc8.cpp | 2 +- tests/test_low_pass_filter.cpp | 2 +- tests/test_mathops.cpp | 2 +- tests/test_mbr.cpp | 2 +- tests/test_nullptr_reject.cpp | 5 +++-- tests/test_timing_util.cpp | 14 +++++++++----- 31 files changed, 76 insertions(+), 66 deletions(-) rename pic18f26k83/{timing_util.c => pic18f26k83_can_timing_util.c} (84%) rename pic18f26k83/{timing_util.h => pic18f26k83_can_timing_util.h} (82%) rename pic18f26k83/{timer.c => pic18f26k83_timer.c} (98%) rename pic18f26k83/{timer.h => pic18f26k83_timer.h} (100%) diff --git a/Makefile b/Makefile index 6e171bee..954774cd 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ COMMON_C_SRCS := \ common/crc8.c \ common/low_pass_filter.c \ logging/mbr.c \ - pic18f26k83/timing_util.c + pic18f26k83/pic18f26k83_can_timing_util.c COMMON_C_HEADERS := \ can_buffer/can_rcv_buffer.h \ @@ -34,23 +34,27 @@ COMMON_C_HEADERS := \ common/low_pass_filter.h \ common/mathops.h \ logging/mbr.h \ - pic18f26k83/timing_util.h + pic18f26k83/pic18f26k83_can_timing_util.h PIC18_C_SRCS := \ pic18f26k83/pic18f26k83_can.c \ - pic18f26k83/timer.c + pic18f26k83/pic18f26k83_timer.c PIC18_C_HEADERS := \ pic18f26k83/pic18f26k83_can.h \ - pic18f26k83/timer.h + pic18f26k83/pic18f26k83_timer.h STM32H7_C_SRCS := stm32h7/stm32h7_can.c STM32H7_C_HEADERS := stm32h7/stm32h7_can.h -INCLUDE_PATHS := . rocketlib/include +INCLUDE_PATHS := . TEST_SRCS := \ + tests/test_crc8.cpp \ + tests/test_low_pass_filter.cpp \ + tests/test_mathops.cpp \ + tests/test_mbr.cpp \ tests/test_msg_actuator.cpp \ tests/test_msg_canards.cpp \ tests/test_msg_common.cpp \ @@ -61,6 +65,7 @@ TEST_SRCS := \ tests/test_msg_stream.cpp \ tests/test_msg_telemetry.cpp \ tests/test_nullptr_reject.cpp \ + tests/test_rockettest.cpp \ tests/test_timing_util.cpp \ tests/test_tx_rcv_buffer.cpp diff --git a/can_buffer/can_rcv_buffer.h b/can_buffer/can_rcv_buffer.h index 1eaa02e2..59036bf8 100644 --- a/can_buffer/can_rcv_buffer.h +++ b/can_buffer/can_rcv_buffer.h @@ -1,5 +1,5 @@ -#ifndef CANLIB_CAN_RCV_BUFFER_H -#define CANLIB_CAN_RCV_BUFFER_H +#ifndef ROCKETLIB_CAN_RCV_BUFFER_H +#define ROCKETLIB_CAN_RCV_BUFFER_H /** * @file can_rcv_buffer.h diff --git a/can_buffer/can_tx_buffer.h b/can_buffer/can_tx_buffer.h index 573013ed..b67dbee3 100644 --- a/can_buffer/can_tx_buffer.h +++ b/can_buffer/can_tx_buffer.h @@ -1,5 +1,5 @@ -#ifndef CANLIB_CAN_TX_BUFFER_H -#define CANLIB_CAN_TX_BUFFER_H +#ifndef ROCKETLIB_CAN_TX_BUFFER_H +#define ROCKETLIB_CAN_TX_BUFFER_H #include #include diff --git a/can_buffer/safe_ring_buffer.h b/can_buffer/safe_ring_buffer.h index ccee52cc..1d966f66 100644 --- a/can_buffer/safe_ring_buffer.h +++ b/can_buffer/safe_ring_buffer.h @@ -1,5 +1,5 @@ -#ifndef CANLIB_SAFE_RING_BUFFER_H -#define CANLIB_SAFE_RING_BUFFER_H +#ifndef ROCKETLIB_SAFE_RING_BUFFER_H +#define ROCKETLIB_SAFE_RING_BUFFER_H #include #include diff --git a/can_message/msg_actuator.h b/can_message/msg_actuator.h index d5e6748d..3ec5ec8a 100644 --- a/can_message/msg_actuator.h +++ b/can_message/msg_actuator.h @@ -1,5 +1,5 @@ -#ifndef CANLIB_ACTUATOR_H -#define CANLIB_ACTUATOR_H +#ifndef ROCKETLIB_ACTUATOR_H +#define ROCKETLIB_ACTUATOR_H #include #include diff --git a/can_message/msg_canards.h b/can_message/msg_canards.h index ddcaaf89..2f9e156b 100644 --- a/can_message/msg_canards.h +++ b/can_message/msg_canards.h @@ -1,5 +1,5 @@ -#ifndef CANLIB_CANARDS_H -#define CANLIB_CANARDS_H +#ifndef ROCKETLIB_CANARDS_H +#define ROCKETLIB_CANARDS_H #include #include diff --git a/can_message/msg_common.h b/can_message/msg_common.h index c3f39b00..3c148afc 100644 --- a/can_message/msg_common.h +++ b/can_message/msg_common.h @@ -1,5 +1,5 @@ -#ifndef CANLIB_COMMON_H -#define CANLIB_COMMON_H +#ifndef ROCKETLIB_MSG_COMMON_H +#define ROCKETLIB_MSG_COMMON_H #include #include @@ -9,7 +9,7 @@ #include "common/common.h" -#ifndef CANLIB_DYNAMIC_BOARD_ID +#ifndef CAN_DYNAMIC_BOARD_ID #ifndef BOARD_TYPE_UNIQUE_ID #warning BOARD_TYPE_UNIQUE_ID not defined, please set that up in project @@ -91,7 +91,7 @@ static inline uint16_t get_timestamp(const can_msg_t *msg) { } // Dynamic board ID specific function -#ifdef CANLIB_DYNAMIC_BOARD_ID +#ifdef CAN_DYNAMIC_BOARD_ID static inline void set_board_id(uint8_t board_type_id, uint8_t board_inst_id) { w_assert(((uint32_t)board_type_id & 0xc0) == 0); diff --git a/can_message/msg_general.c b/can_message/msg_general.c index 2c2e07c5..e0f10fc7 100644 --- a/can_message/msg_general.c +++ b/can_message/msg_general.c @@ -128,7 +128,7 @@ w_status_t check_board_need_reset(const can_msg_t *msg, bool *board_need_reset) return status; } -#ifndef CANLIB_DYNAMIC_BOARD_ID +#ifndef CAN_DYNAMIC_BOARD_ID const uint8_t board_type_unique_id = BOARD_TYPE_UNIQUE_ID; const uint8_t board_inst_unique_id = BOARD_INST_UNIQUE_ID; #endif diff --git a/can_message/msg_general.h b/can_message/msg_general.h index b3182cde..213405cb 100644 --- a/can_message/msg_general.h +++ b/can_message/msg_general.h @@ -1,5 +1,5 @@ -#ifndef CANLIB_GENERAL_H -#define CANLIB_GENERAL_H +#ifndef ROCKETLIB_GENERAL_H +#define ROCKETLIB_GENERAL_H #include #include diff --git a/can_message/msg_gps.h b/can_message/msg_gps.h index 08a66cc0..8e70fca2 100644 --- a/can_message/msg_gps.h +++ b/can_message/msg_gps.h @@ -1,5 +1,5 @@ -#ifndef CANLIB_GPS_H -#define CANLIB_GPS_H +#ifndef ROCKETLIB_GPS_H +#define ROCKETLIB_GPS_H #include #include diff --git a/can_message/msg_recovery.h b/can_message/msg_recovery.h index a057798d..2fcf2309 100644 --- a/can_message/msg_recovery.h +++ b/can_message/msg_recovery.h @@ -1,5 +1,5 @@ -#ifndef CANLIB_RECOVERY_H -#define CANLIB_RECOVERY_H +#ifndef ROCKETLIB_RECOVERY_H +#define ROCKETLIB_RECOVERY_H #include #include diff --git a/can_message/msg_sensor.h b/can_message/msg_sensor.h index ccead023..58131552 100644 --- a/can_message/msg_sensor.h +++ b/can_message/msg_sensor.h @@ -1,5 +1,5 @@ -#ifndef CANLIB_SENSOR_H -#define CANLIB_SENSOR_H +#ifndef ROCKETLIB_SENSOR_H +#define ROCKETLIB_SENSOR_H #include #include diff --git a/can_message/msg_stream.h b/can_message/msg_stream.h index 3e753c9c..911d70bd 100644 --- a/can_message/msg_stream.h +++ b/can_message/msg_stream.h @@ -1,5 +1,5 @@ -#ifndef CANLIB_STREAM_H -#define CANLIB_STREAM_H +#ifndef ROCKETLIB_STREAM_H +#define ROCKETLIB_STREAM_H #include #include diff --git a/can_message/msg_telemetry.h b/can_message/msg_telemetry.h index 28609731..c9ba0030 100644 --- a/can_message/msg_telemetry.h +++ b/can_message/msg_telemetry.h @@ -1,5 +1,5 @@ -#ifndef CANLIB_TELEMETRY_H -#define CANLIB_TELEMETRY_H +#ifndef ROCKETLIB_TELEMETRY_H +#define ROCKETLIB_TELEMETRY_H #include #include diff --git a/can_message/packet_format.h b/can_message/packet_format.h index b877714c..e7aa658f 100644 --- a/can_message/packet_format.h +++ b/can_message/packet_format.h @@ -1,7 +1,7 @@ // Auto generated file, do not edit directly -#ifndef CANLIB_PACKET_FORAMT_H -#define CANLIB_PACKET_FORAMT_H +#ifndef ROCKETLIB_PACKET_FORAMT_H +#define ROCKETLIB_PACKET_FORAMT_H // Message Priority typedef enum { diff --git a/flows/firmware-library.mk b/flows/firmware-library.mk index f977b028..52afcbe3 100644 --- a/flows/firmware-library.mk +++ b/flows/firmware-library.mk @@ -119,13 +119,13 @@ CLANG_FORMAT := clang-format ########################################### COMMON_C_OBJS = $(patsubst %.c,$(BUILD_DIR)/%.o,$(COMMON_C_SRCS)) -COMMON_C_DEPS = $(COMMON_C_SRCS:.c=.d) +COMMON_C_DEPS = $(patsubst %.c,$(BUILD_DIR)/%.d,$(COMMON_C_SRCS)) PIC18_C_OBJS = $(patsubst %.c,$(BUILD_DIR)/%.o,$(PIC18_C_SRCS)) -PIC18_C_DEPS = $(PIC18_C_SRCS:.c=.d) +PIC18_C_DEPS = $(patsubst %.c,$(BUILD_DIR)/%.d,$(PIC18_C_SRCS)) CPP_OBJS = $(patsubst %.cpp,$(BUILD_DIR)/%.o,$(CPP_SRCS)) -CPP_DEPS = $(CPP_SRCS:.cpp=.d) +CPP_DEPS = $(patsubst %.cpp,$(BUILD_DIR)/%.d,$(CPP_SRCS)) ###################### # Object files compile diff --git a/mcp2515/mcp2515.h b/mcp2515/mcp2515.h index 20dabd4a..f933903d 100644 --- a/mcp2515/mcp2515.h +++ b/mcp2515/mcp2515.h @@ -1,5 +1,5 @@ -#ifndef CANLIB_MCP2515_H -#define CANLIB_MCP2515_H +#ifndef ROCKETLIB_MCP2515_H +#define ROCKETLIB_MCP2515_H #include #include diff --git a/mcp2515/mcp2515_regs.h b/mcp2515/mcp2515_regs.h index c3faa196..924c8f92 100644 --- a/mcp2515/mcp2515_regs.h +++ b/mcp2515/mcp2515_regs.h @@ -1,5 +1,5 @@ -#ifndef CANLIB_MCP2515_REGS_H -#define CANLIB_MCP2515_REGS_H +#ifndef ROCKETLIB_MCP2515_REGS_H +#define ROCKETLIB_MCP2515_REGS_H // MCP2515 register addresses #define RXF0SIDH 0x00 diff --git a/pic18f26k83/pic18f26k83_can.c b/pic18f26k83/pic18f26k83_can.c index bc33661e..c0e96e25 100644 --- a/pic18f26k83/pic18f26k83_can.c +++ b/pic18f26k83/pic18f26k83_can.c @@ -2,7 +2,7 @@ #include #include "pic18f26k83_can.h" -#include "timing_util.h" +#include "pic18f26k83_can_timing_util.h" static void (*can_rcv_cb)(const can_msg_t *message); diff --git a/pic18f26k83/pic18f26k83_can.h b/pic18f26k83/pic18f26k83_can.h index 7663fb74..a6b089c6 100644 --- a/pic18f26k83/pic18f26k83_can.h +++ b/pic18f26k83/pic18f26k83_can.h @@ -1,11 +1,11 @@ -#ifndef CANLIB_PIC18F26K83_CAN_H -#define CANLIB_PIC18F26K83_CAN_H +#ifndef ROCKETLIB_PIC18F26K83_CAN_H +#define ROCKETLIB_PIC18F26K83_CAN_H #include #include "can_message/can.h" -#include "timing_util.h" +#include "pic18f26k83_can_timing_util.h" #ifdef __cplusplus #error "C++ is not supported" diff --git a/pic18f26k83/timing_util.c b/pic18f26k83/pic18f26k83_can_timing_util.c similarity index 84% rename from pic18f26k83/timing_util.c rename to pic18f26k83/pic18f26k83_can_timing_util.c index f8222cbb..4c5f2022 100644 --- a/pic18f26k83/timing_util.c +++ b/pic18f26k83/pic18f26k83_can_timing_util.c @@ -2,13 +2,13 @@ #include "common/common.h" -#include "timing_util.h" +#include "pic18f26k83_can_timing_util.h" -#if (CANLIB_BIT_TIME_US != 4) +#if (CAN_BIT_TIME_US != 4) #warning "the bit time that can.h is expecting is not what timing_util is expecting" #endif -w_status_t can_generate_timing_params(uint32_t system_freq, can_timing_t *timing) { +w_status_t pic18f26k83_can_generate_timing_params(uint32_t system_freq, can_timing_t *timing) { w_assert(timing); // this function is designed to create a bit time of 4 microseconds diff --git a/pic18f26k83/timing_util.h b/pic18f26k83/pic18f26k83_can_timing_util.h similarity index 82% rename from pic18f26k83/timing_util.h rename to pic18f26k83/pic18f26k83_can_timing_util.h index 7abbaefb..e1475fdf 100644 --- a/pic18f26k83/timing_util.h +++ b/pic18f26k83/pic18f26k83_can_timing_util.h @@ -1,5 +1,5 @@ -#ifndef CANLIB_TIMING_UTIL_H -#define CANLIB_TIMING_UTIL_H +#ifndef ROCKETLIB_TIMING_UTIL_H +#define ROCKETLIB_TIMING_UTIL_H #include #include @@ -10,7 +10,7 @@ extern "C" { #endif -#define CANLIB_BIT_TIME_US 4 +#define CAN_BIT_TIME_US 4 // Timing parameters typedef struct { @@ -39,7 +39,7 @@ typedef struct { * @param timing buffer to write timing parameters to * @return `W_SUCCESS` if system_freq is valid and parameters have been written to `timing` */ -w_status_t can_generate_timing_params(uint32_t system_freq, can_timing_t *timing); +w_status_t pic18f26k83_can_generate_timing_params(uint32_t system_freq, can_timing_t *timing); #ifdef __cplusplus } diff --git a/pic18f26k83/timer.c b/pic18f26k83/pic18f26k83_timer.c similarity index 98% rename from pic18f26k83/timer.c rename to pic18f26k83/pic18f26k83_timer.c index 9aaa42a8..e233bc8c 100644 --- a/pic18f26k83/timer.c +++ b/pic18f26k83/pic18f26k83_timer.c @@ -1,6 +1,6 @@ #include -#include "timer.h" +#include "pic18f26k83_timer.h" /* * Magic numbers: timer is driven on a 500kHz clock and is 8 bits. diff --git a/pic18f26k83/timer.h b/pic18f26k83/pic18f26k83_timer.h similarity index 100% rename from pic18f26k83/timer.h rename to pic18f26k83/pic18f26k83_timer.h diff --git a/stm32h7/stm32h7_can.h b/stm32h7/stm32h7_can.h index dce1f1c9..2ccc6638 100644 --- a/stm32h7/stm32h7_can.h +++ b/stm32h7/stm32h7_can.h @@ -1,5 +1,5 @@ -#ifndef CANLIB_STM32H7_CAN_H -#define CANLIB_STM32H7_CAN_H +#ifndef ROCKETLIB_STM32H7_CAN_H +#define ROCKETLIB_STM32H7_CAN_H #include diff --git a/tests/test_crc8.cpp b/tests/test_crc8.cpp index 484df0bd..f1bf268f 100644 --- a/tests/test_crc8.cpp +++ b/tests/test_crc8.cpp @@ -1,7 +1,7 @@ #include #include "common/common.h" -#include "crc8.h" +#include "common/crc8.h" #include "rockettest.hpp" diff --git a/tests/test_low_pass_filter.cpp b/tests/test_low_pass_filter.cpp index 16c158f8..cd598bfe 100644 --- a/tests/test_low_pass_filter.cpp +++ b/tests/test_low_pass_filter.cpp @@ -5,7 +5,7 @@ #include #include "common/common.h" -#include "low_pass_filter.h" +#include "common/low_pass_filter.h" #include "rockettest.hpp" diff --git a/tests/test_mathops.cpp b/tests/test_mathops.cpp index 9a0397ea..c16bb1e8 100644 --- a/tests/test_mathops.cpp +++ b/tests/test_mathops.cpp @@ -4,7 +4,7 @@ #include #include "common/common.h" -#include "mathops.h" +#include "common/mathops.h" #include "rockettest.hpp" diff --git a/tests/test_mbr.cpp b/tests/test_mbr.cpp index 6b1ac869..5548d999 100644 --- a/tests/test_mbr.cpp +++ b/tests/test_mbr.cpp @@ -1,7 +1,7 @@ #include #include "common/common.h" -#include "mbr.h" +#include "logging/mbr.h" #include "rockettest.hpp" diff --git a/tests/test_nullptr_reject.cpp b/tests/test_nullptr_reject.cpp index 2d9ebaeb..96b99247 100644 --- a/tests/test_nullptr_reject.cpp +++ b/tests/test_nullptr_reject.cpp @@ -16,7 +16,7 @@ #include "can_message/msg_sensor.h" #include "can_message/msg_stream.h" #include "can_message/msg_telemetry.h" -#include "pic18f26k83/timing_util.h" +#include "pic18f26k83/pic18f26k83_can_timing_util.h" namespace { @@ -580,7 +580,8 @@ class msg_ptr_nullptr_reject_test : rockettest_test { // ----------------------- // timing_util tests // ----------------------- - rockettest_check_assert_triggered([] { can_generate_timing_params(48000000, nullptr); }); + rockettest_check_assert_triggered( + [] { pic18f26k83_can_generate_timing_params(48000000, nullptr); }); return test_passed; } }; diff --git a/tests/test_timing_util.cpp b/tests/test_timing_util.cpp index 1f30b589..f29db475 100644 --- a/tests/test_timing_util.cpp +++ b/tests/test_timing_util.cpp @@ -2,7 +2,7 @@ #include "rockettest.hpp" #include "can_message/can.h" -#include "pic18f26k83/timing_util.h" +#include "pic18f26k83/pic18f26k83_can_timing_util.h" class timing_util_test : public rockettest_test { public: @@ -14,7 +14,8 @@ class timing_util_test : public rockettest_test { can_timing_t timing; // 48 MHz, for example PIC18 with 12 MHz crystal and 4xPLL enabled - rockettest_check_expr_true(can_generate_timing_params(48000000, &timing) == W_SUCCESS); + rockettest_check_expr_true(pic18f26k83_can_generate_timing_params(48000000, &timing) == + W_SUCCESS); rockettest_check_expr_true(timing.brp == 7); rockettest_check_expr_true(timing.sjw == 3); rockettest_check_expr_true(timing.btlmode == 1); @@ -24,7 +25,8 @@ class timing_util_test : public rockettest_test { rockettest_check_expr_true(timing.seg2ph == 4); // 12 MHz, for example PIC18 with 12 MHz crystal and 4xPLL disabled - rockettest_check_expr_true(can_generate_timing_params(12000000, &timing) == W_SUCCESS); + rockettest_check_expr_true(pic18f26k83_can_generate_timing_params(12000000, &timing) == + W_SUCCESS); rockettest_check_expr_true(timing.brp == 1); rockettest_check_expr_true(timing.sjw == 3); rockettest_check_expr_true(timing.btlmode == 1); @@ -34,7 +36,8 @@ class timing_util_test : public rockettest_test { rockettest_check_expr_true(timing.seg2ph == 4); // 6 MHz, currently not used on physical hardware - rockettest_check_expr_true(can_generate_timing_params(6000000, &timing) == W_SUCCESS); + rockettest_check_expr_true(pic18f26k83_can_generate_timing_params(6000000, &timing) == + W_SUCCESS); rockettest_check_expr_true(timing.brp == 0); rockettest_check_expr_true(timing.sjw == 3); rockettest_check_expr_true(timing.btlmode == 1); @@ -44,7 +47,8 @@ class timing_util_test : public rockettest_test { rockettest_check_expr_true(timing.seg2ph == 4); // Invalid system frequency - rockettest_check_expr_true(can_generate_timing_params(0, &timing) == W_INVALID_PARAM); + rockettest_check_expr_true(pic18f26k83_can_generate_timing_params(0, &timing) == + W_INVALID_PARAM); return test_passed; } From 0e39e37901cf68e856c8c37761609ebbe00be949 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Tue, 6 Oct 2026 20:18:53 -0400 Subject: [PATCH 106/108] Make all header include use absolute path --- can_buffer/can_rcv_buffer.c | 4 ++-- can_buffer/can_tx_buffer.c | 4 ++-- can_buffer/safe_ring_buffer.c | 2 +- can_message/msg_actuator.c | 4 ++-- can_message/msg_canards.c | 4 ++-- can_message/msg_general.c | 4 ++-- can_message/msg_gps.c | 4 ++-- can_message/msg_recovery.c | 4 ++-- can_message/msg_sensor.c | 4 ++-- can_message/msg_stream.c | 4 ++-- can_message/msg_telemetry.c | 4 ++-- can_message/packet_format.h | 4 ++-- common/crc8.c | 2 +- common/low_pass_filter.c | 4 ++-- common/low_pass_filter.h | 2 +- common/mathops.h | 2 +- logging/mbr.c | 2 +- pic18f26k83/pic18f26k83_can.c | 4 ++-- pic18f26k83/pic18f26k83_can.h | 2 +- pic18f26k83/pic18f26k83_can_timing_util.c | 2 +- pic18f26k83/pic18f26k83_timer.c | 2 +- 21 files changed, 34 insertions(+), 34 deletions(-) diff --git a/can_buffer/can_rcv_buffer.c b/can_buffer/can_rcv_buffer.c index 7ab5e00f..b9d9e65f 100644 --- a/can_buffer/can_rcv_buffer.c +++ b/can_buffer/can_rcv_buffer.c @@ -2,9 +2,9 @@ #include "common/common.h" +#include "can_buffer/can_rcv_buffer.h" +#include "can_buffer/safe_ring_buffer.h" #include "can_message/can.h" -#include "can_rcv_buffer.h" -#include "safe_ring_buffer.h" static srb_ctx_t buf; static bool overflow_flag; diff --git a/can_buffer/can_tx_buffer.c b/can_buffer/can_tx_buffer.c index 518716c9..9a30c61e 100644 --- a/can_buffer/can_tx_buffer.c +++ b/can_buffer/can_tx_buffer.c @@ -2,9 +2,9 @@ #include "common/common.h" +#include "can_buffer/can_tx_buffer.h" +#include "can_buffer/safe_ring_buffer.h" #include "can_message/can.h" -#include "can_tx_buffer.h" -#include "safe_ring_buffer.h" typedef struct { void (*can_send_fp)(const can_msg_t *); diff --git a/can_buffer/safe_ring_buffer.c b/can_buffer/safe_ring_buffer.c index b26c7106..367515c9 100644 --- a/can_buffer/safe_ring_buffer.c +++ b/can_buffer/safe_ring_buffer.c @@ -3,7 +3,7 @@ #include "common/common.h" -#include "safe_ring_buffer.h" +#include "can_buffer/safe_ring_buffer.h" static size_t get_offset_bytes(const srb_ctx_t *ctx, size_t index) { w_assert(ctx); diff --git a/can_message/msg_actuator.c b/can_message/msg_actuator.c index a5c370fb..54b45fd0 100644 --- a/can_message/msg_actuator.c +++ b/can_message/msg_actuator.c @@ -4,9 +4,9 @@ #include "common/common.h" #include "can_message/can.h" +#include "can_message/msg_actuator.h" +#include "can_message/msg_common.h" #include "can_message/packet_format.h" -#include "msg_actuator.h" -#include "msg_common.h" void build_actuator_cmd_msg(can_msg_prio_t prio, uint16_t timestamp, can_actuator_id_t actuator_id, can_actuator_state_t actuator_cmd, can_msg_t *output) { diff --git a/can_message/msg_canards.c b/can_message/msg_canards.c index c81ce1a5..a92252d6 100644 --- a/can_message/msg_canards.c +++ b/can_message/msg_canards.c @@ -4,9 +4,9 @@ #include "common/common.h" #include "can_message/can.h" +#include "can_message/msg_canards.h" +#include "can_message/msg_common.h" #include "can_message/packet_format.h" -#include "msg_canards.h" -#include "msg_common.h" void build_canard_firmware_error_msg(can_msg_prio_t prio, uint16_t timestamp, can_canards_module_id_t module_id, uint32_t error_bitfield, diff --git a/can_message/msg_general.c b/can_message/msg_general.c index e0f10fc7..8bf24e70 100644 --- a/can_message/msg_general.c +++ b/can_message/msg_general.c @@ -5,9 +5,9 @@ #include "common/common.h" #include "can_message/can.h" +#include "can_message/msg_common.h" +#include "can_message/msg_general.h" #include "can_message/packet_format.h" -#include "msg_common.h" -#include "msg_general.h" void build_general_board_status_msg(can_msg_prio_t prio, uint16_t timestamp, uint32_t board_error_bitfield, can_msg_t *output) { diff --git a/can_message/msg_gps.c b/can_message/msg_gps.c index 6bc56025..c7844ad0 100644 --- a/can_message/msg_gps.c +++ b/can_message/msg_gps.c @@ -4,9 +4,9 @@ #include "common/common.h" #include "can_message/can.h" +#include "can_message/msg_common.h" +#include "can_message/msg_gps.h" #include "can_message/packet_format.h" -#include "msg_common.h" -#include "msg_gps.h" void build_gps_time_msg(can_msg_prio_t prio, uint16_t timestamp, uint8_t utc_hours, uint8_t utc_mins, uint8_t utc_secs, uint8_t utc_dsecs, can_msg_t *output) { diff --git a/can_message/msg_recovery.c b/can_message/msg_recovery.c index 8dc02a48..9322f8e7 100644 --- a/can_message/msg_recovery.c +++ b/can_message/msg_recovery.c @@ -3,9 +3,9 @@ #include "common/common.h" #include "can_message/can.h" +#include "can_message/msg_common.h" +#include "can_message/msg_recovery.h" #include "can_message/packet_format.h" -#include "msg_common.h" -#include "msg_recovery.h" void build_alt_arm_cmd_msg(can_msg_prio_t prio, uint16_t timestamp, can_altimeter_id_t alt_id, can_alt_arm_state_t arm_cmd, can_msg_t *output) { diff --git a/can_message/msg_sensor.c b/can_message/msg_sensor.c index 9162ba13..cb23d60c 100644 --- a/can_message/msg_sensor.c +++ b/can_message/msg_sensor.c @@ -4,9 +4,9 @@ #include "common/common.h" #include "can_message/can.h" +#include "can_message/msg_common.h" +#include "can_message/msg_sensor.h" #include "can_message/packet_format.h" -#include "msg_common.h" -#include "msg_sensor.h" void build_analog_sensor_16bit_msg(can_msg_prio_t prio, uint16_t timestamp, can_analog_sensor_id_t sensor_id, uint16_t sensor_data, diff --git a/can_message/msg_stream.c b/can_message/msg_stream.c index 508e13c7..cc45e82a 100644 --- a/can_message/msg_stream.c +++ b/can_message/msg_stream.c @@ -4,9 +4,9 @@ #include "common/common.h" #include "can_message/can.h" +#include "can_message/msg_common.h" +#include "can_message/msg_stream.h" #include "can_message/packet_format.h" -#include "msg_common.h" -#include "msg_stream.h" // Fields are 24-bit big-endian. #define STREAM_SIZE_MAX 0xffffffU diff --git a/can_message/msg_telemetry.c b/can_message/msg_telemetry.c index 3cffe517..d9a27f57 100644 --- a/can_message/msg_telemetry.c +++ b/can_message/msg_telemetry.c @@ -4,9 +4,9 @@ #include "common/common.h" #include "can_message/can.h" +#include "can_message/msg_common.h" +#include "can_message/msg_telemetry.h" #include "can_message/packet_format.h" -#include "msg_common.h" -#include "msg_telemetry.h" void build_telemetry_info_msg(can_msg_prio_t prio, uint16_t timestamp, uint8_t channel_id, uint8_t lqi, int8_t rssi, can_msg_t *output) { diff --git a/can_message/packet_format.h b/can_message/packet_format.h index e7aa658f..10c1a310 100644 --- a/can_message/packet_format.h +++ b/can_message/packet_format.h @@ -1,7 +1,7 @@ // Auto generated file, do not edit directly -#ifndef ROCKETLIB_PACKET_FORAMT_H -#define ROCKETLIB_PACKET_FORAMT_H +#ifndef ROCKETLIB_PACKET_FORMAT_H +#define ROCKETLIB_PACKET_FORMAT_H // Message Priority typedef enum { diff --git a/common/crc8.c b/common/crc8.c index 5bed51ed..e6ca2ec9 100644 --- a/common/crc8.c +++ b/common/crc8.c @@ -1,7 +1,7 @@ #include #include -#include "common.h" +#include "common/common.h" // crc table used for calculation static uint8_t table[256] = { diff --git a/common/low_pass_filter.c b/common/low_pass_filter.c index 925981c7..a41ec9b6 100644 --- a/common/low_pass_filter.c +++ b/common/low_pass_filter.c @@ -1,8 +1,8 @@ #include #include -#include "common.h" -#include "low_pass_filter.h" +#include "common/common.h" +#include "common/low_pass_filter.h" /** * @brief Initializes the low-pass filter by calculating and storing the alpha value diff --git a/common/low_pass_filter.h b/common/low_pass_filter.h index d81e9143..d0cadcfc 100644 --- a/common/low_pass_filter.h +++ b/common/low_pass_filter.h @@ -13,7 +13,7 @@ #include #include -#include "common.h" +#include "common/common.h" #ifdef __cplusplus extern "C" { diff --git a/common/mathops.h b/common/mathops.h index 31e748da..b629cbc3 100644 --- a/common/mathops.h +++ b/common/mathops.h @@ -3,7 +3,7 @@ #include -#include "common.h" +#include "common/common.h" /** * @brief Clamps a 32 bit unsigned integer between a lower and upper bound. diff --git a/logging/mbr.c b/logging/mbr.c index 3f08eefb..d570bf9d 100644 --- a/logging/mbr.c +++ b/logging/mbr.c @@ -1,7 +1,7 @@ #include #include "common/common.h" -#include "mbr.h" +#include "logging/mbr.h" #define BOOT_SIGNATURE_OFFSET 0x1fe #define MBR_PT_OFFSET 0x1be diff --git a/pic18f26k83/pic18f26k83_can.c b/pic18f26k83/pic18f26k83_can.c index c0e96e25..50b86c11 100644 --- a/pic18f26k83/pic18f26k83_can.c +++ b/pic18f26k83/pic18f26k83_can.c @@ -1,8 +1,8 @@ #include #include -#include "pic18f26k83_can.h" -#include "pic18f26k83_can_timing_util.h" +#include "pic18f26k83/pic18f26k83_can.h" +#include "pic18f26k83/pic18f26k83_can_timing_util.h" static void (*can_rcv_cb)(const can_msg_t *message); diff --git a/pic18f26k83/pic18f26k83_can.h b/pic18f26k83/pic18f26k83_can.h index a6b089c6..ed6f9e74 100644 --- a/pic18f26k83/pic18f26k83_can.h +++ b/pic18f26k83/pic18f26k83_can.h @@ -5,7 +5,7 @@ #include "can_message/can.h" -#include "pic18f26k83_can_timing_util.h" +#include "pic18f26k83/pic18f26k83_can_timing_util.h" #ifdef __cplusplus #error "C++ is not supported" diff --git a/pic18f26k83/pic18f26k83_can_timing_util.c b/pic18f26k83/pic18f26k83_can_timing_util.c index 4c5f2022..f7ebf183 100644 --- a/pic18f26k83/pic18f26k83_can_timing_util.c +++ b/pic18f26k83/pic18f26k83_can_timing_util.c @@ -2,7 +2,7 @@ #include "common/common.h" -#include "pic18f26k83_can_timing_util.h" +#include "pic18f26k83/pic18f26k83_can_timing_util.h" #if (CAN_BIT_TIME_US != 4) #warning "the bit time that can.h is expecting is not what timing_util is expecting" diff --git a/pic18f26k83/pic18f26k83_timer.c b/pic18f26k83/pic18f26k83_timer.c index e233bc8c..257271bc 100644 --- a/pic18f26k83/pic18f26k83_timer.c +++ b/pic18f26k83/pic18f26k83_timer.c @@ -1,6 +1,6 @@ #include -#include "pic18f26k83_timer.h" +#include "pic18f26k83/pic18f26k83_timer.h" /* * Magic numbers: timer is driven on a 500kHz clock and is 8 bits. From 0073c94bfc02e116f0635978c0bc66793a9c84d4 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Tue, 6 Oct 2026 20:44:14 -0400 Subject: [PATCH 107/108] Update library versioning in common.h --- common/common.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/common/common.h b/common/common.h index 4ab502c9..7ce0eee4 100644 --- a/common/common.h +++ b/common/common.h @@ -1,12 +1,16 @@ #ifndef ROCKETLIB_COMMON_H #define ROCKETLIB_COMMON_H -/// @brief Rocketlib major release number, shall be design cycle year -#define ROCKETLIB_VERSION_MAJOR 2026 +/// @brief Rocketlib major release number, shall be the design cycle year +#define ROCKETLIB_VERSION_MAJOR 2027 -/// @brief Rocketlib minor release number, shall be the Nth release of the design cycle +/// @brief Rocketlib minor release number, shall be the RocketCAN protocol version #define ROCKETLIB_VERSION_MINOR 1 +/// @brief Rocketlib patch release number, shall be the n-th revision of this library that does not +/// involve RocketCAN protocol change +#define ROCKETLIB_VERSION_PATCH 0 + typedef float float32_t; typedef double float64_t; From d198a1f4ecb990f07c3d60c2c0cd7d93eb7a0ad0 Mon Sep 17 00:00:00 2001 From: Jason Xu <40355221+JasonBrave@users.noreply.github.com> Date: Wed, 7 Oct 2026 08:54:05 -0400 Subject: [PATCH 108/108] Add rocketlib.h which includes all device independent headers --- Makefile | 1 + rocketlib.h | 31 +++++++++++++++++++++++++++++++ tests/test_crc8.cpp | 3 +-- tests/test_low_pass_filter.cpp | 3 +-- tests/test_mathops.cpp | 3 +-- tests/test_mbr.cpp | 3 +-- tests/test_nullptr_reject.cpp | 15 +-------------- tests/test_tx_rcv_buffer.cpp | 5 +---- 8 files changed, 38 insertions(+), 26 deletions(-) create mode 100644 rocketlib.h diff --git a/Makefile b/Makefile index 954774cd..3eb63585 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ COMMON_C_SRCS := \ logging/mbr.c \ pic18f26k83/pic18f26k83_can_timing_util.c +# rocketlib.h is intentional not included to avoid clang-tidy misc-include-cleaner error COMMON_C_HEADERS := \ can_buffer/can_rcv_buffer.h \ can_buffer/can_tx_buffer.h \ diff --git a/rocketlib.h b/rocketlib.h new file mode 100644 index 00000000..eb04cc45 --- /dev/null +++ b/rocketlib.h @@ -0,0 +1,31 @@ +#ifndef ROCKETLIB_ROCKETLIB_H +#define ROCKETLIB_ROCKETLIB_H + +// Common headers +#include "common/common.h" +#include "common/crc8.h" +#include "common/electrical.h" +#include "common/low_pass_filter.h" +#include "common/mathops.h" + +// CAN message headers +#include "can_message/can.h" +#include "can_message/msg_actuator.h" +#include "can_message/msg_canards.h" +#include "can_message/msg_common.h" +#include "can_message/msg_general.h" +#include "can_message/msg_gps.h" +#include "can_message/msg_recovery.h" +#include "can_message/msg_sensor.h" +#include "can_message/msg_stream.h" +#include "can_message/msg_telemetry.h" + +// CAN buffer headers +#include "can_buffer/can_rcv_buffer.h" +#include "can_buffer/can_tx_buffer.h" +#include "can_buffer/safe_ring_buffer.h" + +// Logging headers +#include "logging/mbr.h" + +#endif diff --git a/tests/test_crc8.cpp b/tests/test_crc8.cpp index f1bf268f..c174adc8 100644 --- a/tests/test_crc8.cpp +++ b/tests/test_crc8.cpp @@ -1,7 +1,6 @@ #include -#include "common/common.h" -#include "common/crc8.h" +#include "rocketlib.h" #include "rockettest.hpp" diff --git a/tests/test_low_pass_filter.cpp b/tests/test_low_pass_filter.cpp index cd598bfe..7689ad70 100644 --- a/tests/test_low_pass_filter.cpp +++ b/tests/test_low_pass_filter.cpp @@ -4,8 +4,7 @@ #include #include -#include "common/common.h" -#include "common/low_pass_filter.h" +#include "rocketlib.h" #include "rockettest.hpp" diff --git a/tests/test_mathops.cpp b/tests/test_mathops.cpp index c16bb1e8..4382c4b5 100644 --- a/tests/test_mathops.cpp +++ b/tests/test_mathops.cpp @@ -3,8 +3,7 @@ #include #include -#include "common/common.h" -#include "common/mathops.h" +#include "rocketlib.h" #include "rockettest.hpp" diff --git a/tests/test_mbr.cpp b/tests/test_mbr.cpp index 5548d999..53ff2cdd 100644 --- a/tests/test_mbr.cpp +++ b/tests/test_mbr.cpp @@ -1,7 +1,6 @@ #include -#include "common/common.h" -#include "logging/mbr.h" +#include "rocketlib.h" #include "rockettest.hpp" diff --git a/tests/test_nullptr_reject.cpp b/tests/test_nullptr_reject.cpp index 96b99247..eb23c5b5 100644 --- a/tests/test_nullptr_reject.cpp +++ b/tests/test_nullptr_reject.cpp @@ -1,22 +1,9 @@ #include -#include "can_message/can.h" -#include "can_message/packet_format.h" #include "rockettest.hpp" -#include "can_buffer/can_rcv_buffer.h" -#include "can_buffer/can_tx_buffer.h" -#include "can_buffer/safe_ring_buffer.h" -#include "can_message/msg_actuator.h" -#include "can_message/msg_canards.h" -#include "can_message/msg_common.h" -#include "can_message/msg_general.h" -#include "can_message/msg_gps.h" -#include "can_message/msg_recovery.h" -#include "can_message/msg_sensor.h" -#include "can_message/msg_stream.h" -#include "can_message/msg_telemetry.h" #include "pic18f26k83/pic18f26k83_can_timing_util.h" +#include "rocketlib.h" namespace { diff --git a/tests/test_tx_rcv_buffer.cpp b/tests/test_tx_rcv_buffer.cpp index d8c7fd9e..4c95a37b 100644 --- a/tests/test_tx_rcv_buffer.cpp +++ b/tests/test_tx_rcv_buffer.cpp @@ -3,12 +3,9 @@ #include #include -#include "can_message/can.h" -#include "common/common.h" #include "rockettest.hpp" -#include "can_buffer/can_rcv_buffer.h" -#include "can_buffer/can_tx_buffer.h" +#include "rocketlib.h" // Tx Buffer Test