From ac48839b70d7fadd1ebcc4d578b935d3d8f7b12f Mon Sep 17 00:00:00 2001 From: polymurph Date: Fri, 12 Nov 2021 09:35:26 +0100 Subject: [PATCH] added assert from standart libs -> creates a lot of overhead. we must create our own lightweight assert --- bsl/csl/stm32f042/Src/pin.c | 22 ++++++++++++---------- utils/assert.c | 8 ++++++++ utils/assert.h | 4 ++++ 3 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 utils/assert.c create mode 100644 utils/assert.h diff --git a/bsl/csl/stm32f042/Src/pin.c b/bsl/csl/stm32f042/Src/pin.c index 48987ea..037858e 100644 --- a/bsl/csl/stm32f042/Src/pin.c +++ b/bsl/csl/stm32f042/Src/pin.c @@ -22,6 +22,8 @@ #include "pin.h" +#include + #define MODER_IN 0x0UL #define MODER_OUT 0x1UL #define MODER_ALTERNATE 0x2UL @@ -121,17 +123,17 @@ void pinSetSpeed(pinNo_t pinNo, pinSpeed_t speed) void pinSetAlternate(pinNo_t pinNo, uint16_t alternate) { - if(altFunc_List[PIN_PORT][PIN_NO] & (1<<(7-alternate))) //chekc if alternate function is awailble - { - if(PIN_NO < 8) - { - PIN_BASE->AFR[0] &= ~(0x0F << (PIN_NO * 4)); - PIN_BASE->AFR[0] |= ((alternate & 0x0F) << (PIN_NO * 4)); - return; - } - PIN_BASE->AFR[1] &= ~(0x0F << ((PIN_NO-8) * 4)); - PIN_BASE->AFR[1] |= ((alternate & 0x0F) << ((PIN_NO-8) * 4)); + assert(altFunc_List[PIN_PORT][PIN_NO] & (1<<(7-alternate))); + assert(alternate < 16); + + if(PIN_NO < 8) { + PIN_BASE->AFR[0] &= ~(0x0F << (PIN_NO * 4)); + PIN_BASE->AFR[0] |= ((alternate & 0x0F) << (PIN_NO * 4)); + return; } + + PIN_BASE->AFR[1] &= ~(0x0F << ((PIN_NO-8) * 4)); + PIN_BASE->AFR[1] |= ((alternate & 0x0F) << ((PIN_NO-8) * 4)); } void pinConfig(pinNo_t pinNo, pinMode_t mode, pinStage_t stage, pinPullUpDown_t resistance, pinSpeed_t speed) diff --git a/utils/assert.c b/utils/assert.c new file mode 100644 index 0000000..51bb067 --- /dev/null +++ b/utils/assert.c @@ -0,0 +1,8 @@ +#include "assert.h" + +void assert(int check) +{ + while(!check) { + // dead loop here + }; +} diff --git a/utils/assert.h b/utils/assert.h new file mode 100644 index 0000000..1211176 --- /dev/null +++ b/utils/assert.h @@ -0,0 +1,4 @@ + + + +void assert(int check);