diff --git a/bsl/csl/interfaces/pin.h b/bsl/csl/interfaces/pin.h index 3c538ad..f2b83d5 100644 --- a/bsl/csl/interfaces/pin.h +++ b/bsl/csl/interfaces/pin.h @@ -92,6 +92,9 @@ typedef struct typedef enum { notValidMode, + UnvalidAlternate, + OutOfRangeAlternate, + NotValidSpeed, notValidOut, OutOfRange, NotDeclared, @@ -99,7 +102,6 @@ typedef enum NoPullUpDown, NotAnalog, NotDigital, - TooFast, Bocked, AlreadyUsed, NotGpio @@ -178,7 +180,7 @@ void pinHardwareInfo(pinNo_t pinNo); * @brief Handles the given error and stops all further execution. * Dependeing on the platfonr an the form of information printing. */ -void pinThrowError(); +void pinThrowError(pinErrors_t error); #ifdef __cplusplus } diff --git a/bsl/csl/interfaces/timer.h b/bsl/csl/interfaces/timer.h index 362e021..fb49498 100644 --- a/bsl/csl/interfaces/timer.h +++ b/bsl/csl/interfaces/timer.h @@ -1,4 +1,22 @@ +#include "hardwareDescription.h" +typedef enum { + functionNotSupported, + prescalerOutOfRange +} timerError_t; + +typedef enum { + upCounting, + downCounting, + centerAligned +} timerCountDirection_t; + +typedef enum { + inputCapture, + outputCompare, + pwm, + onePulse +} timerMode_t; void timerActivateBus(timerNo_t timer); void timerEnableTimer(timerNo_t timer); @@ -12,7 +30,16 @@ void timerClearCounter(timerNo_t timer); /* Second stage configuration */ -void setTimerHz(timerNo_t timer, uint16_t hz); -void setTimerMs(timerNo_t timer, uint16_t ms); -void setTimerNs(timerNo_t timer, uint16_t ns); -void setTimerPs(timerNo_t timer, uint16_t ps); +void timerSetHz(timerNo_t timer, uint16_t hz); +void timerSetMs(timerNo_t timer, uint16_t ms); +void timerSetNs(timerNo_t timer, uint16_t ns); +void timerSetPs(timerNo_t timer, uint16_t ps); + +void timerSart(timerNo_t timer); +void timerStop(timerNo_t timer); +uint32_t timerGetCount(timerNo_t timer); + +void timerThrowError(timerError_t error); + + + diff --git a/bsl/csl/stm32f042/Device/hardwareDescription.h b/bsl/csl/stm32f042/Device/hardwareDescription.h index d12a011..949d110 100644 --- a/bsl/csl/stm32f042/Device/hardwareDescription.h +++ b/bsl/csl/stm32f042/Device/hardwareDescription.h @@ -11,7 +11,7 @@ #define MAX_SPI_CHANNEL_COUNT 2 #define MAX_I2S_CHANNEL_COUNT 2 #define MAX_CAN_CHANNEL_COUNT 1 - +#define MAX_TIMER_CHANNEL_COUNT 6 #define MAX_N_PORTS_COUNT 3 #define MAX_PORT_PINS_COUNT 16 @@ -21,6 +21,10 @@ #define MAX_PORT_B_PIN_NO 15 #define MAX_PORT_F_PIN_NO 1 + + + + typedef enum { // NAME = BASE ADDR | PORT | PIN NO @@ -54,7 +58,10 @@ typedef enum pinF1 = 0x20 | 1 /*!< Port: F Pin: 1 -> Port F Mask | Pin Mask */ }pinNo_t; -static const uint32_t portBase_Addr_List[3] = {GPIOA_BASE, GPIOB_BASE, GPIOF_BASE}; +static const uint32_t portBase_Addr_List[MAX_N_PORTS_COUNT] = { + GPIOA_BASE, + GPIOB_BASE, + GPIOF_BASE}; static const uint8_t altFunc_List[MAX_N_PORTS_COUNT][MAX_PORT_PINS_COUNT] = { { // PORT A @@ -112,3 +119,28 @@ static const uint8_t altFunc_List[MAX_N_PORTS_COUNT][MAX_PORT_PINS_COUNT] = { 0b00000000 //N.A } }; + +// Timers + +typedef enum { + timer_1, + timer_2, + timer_3, + timer_14, + timer_16, + timer_17 +} timerNo_t; + +typedef enum { + hb, + hsi +}clkSources_t; + +static const uint32_t timerBase_Addr_List[MAX_TIMER_CHANNEL_COUNT] = { + TIM1_BASE, + TIM2_BASE, + TIM3_BASE, + TIM14_BASE, + TIM16_BASE, + TIM17_BASE +}; diff --git a/bsl/csl/stm32f042/Src/CMakeLists.txt b/bsl/csl/stm32f042/Src/CMakeLists.txt index e325d80..b8d9059 100644 --- a/bsl/csl/stm32f042/Src/CMakeLists.txt +++ b/bsl/csl/stm32f042/Src/CMakeLists.txt @@ -23,3 +23,9 @@ target_compile_definitions(stmInit PRIVATE ${C_DEFS}) target_include_directories(stmInit PUBLIC ${INTERFACES_DIR} ${CSL_INCLUDES}) add_library(sub::init ALIAS stmInit) +add_library(stmTimer timer.c) +target_compile_options(stmTimer PRIVATE ${C_FLAGS}) +target_compile_definitions(stmTimer PRIVATE ${C_DEFS}) +target_include_directories(stmTimer PUBLIC ${INTERFACES_DIR} ${CSL_INCLUDES}) +add_library(sub::timer ALIAS stmTimer) + diff --git a/bsl/csl/stm32f042/Src/pin.c b/bsl/csl/stm32f042/Src/pin.c index 96ea668..35b29a3 100644 --- a/bsl/csl/stm32f042/Src/pin.c +++ b/bsl/csl/stm32f042/Src/pin.c @@ -21,8 +21,6 @@ */ #include "pin.h" -#include "utils_assert.h" - #define MODER_IN 0x0UL #define MODER_OUT 0x1UL @@ -123,9 +121,15 @@ void pinSetSpeed(pinNo_t pinNo, pinSpeed_t speed) void pinSetAlternate(pinNo_t pinNo, uint16_t alternate) { - assert(altFunc_List[PIN_PORT][PIN_NO] & (1<<(7-alternate))); - assert(alternate < 16); - + if(!(altFunc_List[PIN_PORT][PIN_NO] & (1<<(7-alternate)))) + { + pinThrowError(UnvalidAlternate); + } + if(alternate > 15) + { + pinThrowError(OutOfRangeAlternate); + } + if(PIN_NO < 8) { PIN_BASE->AFR[0] &= ~(0x0F << (PIN_NO * 4)); PIN_BASE->AFR[0] |= ((alternate & 0x0F) << (PIN_NO * 4)); @@ -197,9 +201,9 @@ void pinHardwareInfo(pinNo_t pinNo) //TODO : define where to print anh woh to print } -void pinThrowError() +void pinThrowError(pinErrors_t error) { - //TODO : Define what for an error di we whant to implement + while(1); } diff --git a/bsl/csl/stm32f042/Src/timer.c b/bsl/csl/stm32f042/Src/timer.c new file mode 100644 index 0000000..34308e9 --- /dev/null +++ b/bsl/csl/stm32f042/Src/timer.c @@ -0,0 +1,93 @@ +#include "timer.h" + +static const uint32_ + +void timerActivateBus(timerNo_t timer) +{ + +} + +void timerEnableTimer(timerNo_t timer) +{ + +} + +void timerSetClkSource(timerNo_t timer, clkSources_t clk) +{ + +} + +void timerSetMode(timerNo_t timer, timerMode_t mode) +{ + +} + +void timerSetCountDirection(timerNo_t timer, timerCountDirection_t direction) +{ + +} + +void timerSetPrescaler(timerNo_t timer, uint32_t prescaler) +{ + +} + +void timerSetPostscaler(timerNo_t timer, uint32_t postscaler) +{ + +} + +void timerSetAutoReload(timerNo_t timer, uint32_t reload) +{ + +} + +void timerClearCounter(timerNo_t timer) +{ + +} + + +/* Second stage configuration */ +void timerSetHz(timerNo_t timer, uint16_t hz) +{ + +} + +void timerSetMs(timerNo_t timer, uint16_t ms) +{ + +} + +void timerSetNs(timerNo_t timer, uint16_t ns) +{ + +} + +void timerSetPs(timerNo_t timer, uint16_t ps) +{ + +} + + +void timerSart(timerNo_t timer) +{ + +} + +void timerStop(timerNo_t timer) +{ + +} + +uint32_t timerGetCount(timerNo_t timer) +{ + +} + + +void timerThrowError(timerError_t error) +{ + +} + diff --git a/bsl/nucleo_f042k6/bslConfig.cmake b/bsl/nucleo_f042k6/bslConfig.cmake index f6f2c60..0c7695e 100644 --- a/bsl/nucleo_f042k6/bslConfig.cmake +++ b/bsl/nucleo_f042k6/bslConfig.cmake @@ -77,4 +77,4 @@ list(APPEND EXTRA_LIBS sub::delay) list(APPEND EXTRA_LIBS sub::pin) list(APPEND EXTRA_LIBS sub::usart) list(APPEND EXTRA_LIBS sub::init) -list(APPEND EXTRA_LIBS sub::assert) +list(APPEND EXTRA_LIBS sub::timer) diff --git a/main.cpp b/main.cpp index 4c4622d..dcd74ba 100644 --- a/main.cpp +++ b/main.cpp @@ -1,3 +1,6 @@ +#warning "Generated from: " __FILE__ + + #include "main.hpp" #include "delay.h" #include "deviceSetup.h" @@ -8,11 +11,8 @@ int main(int argc, char *argv[]) { uint8_t i = 0; uint8_t a = '0'; - delayInitMs(8000000, 1000); -// FreeRTOS_Delay dly; -// dly.wait(); pinConfig(pinB3, output, pushPull, def_res, def_speed); pinConfig(pinA0, input, def_stage, pullDown, def_speed); @@ -52,30 +52,7 @@ int main(int argc, char *argv[]) } else if(a == '0'){ pinWrite(pinB3,0); } -/* - if(a == '1' && latch != latch_old) - { - pinToggle(pinB3); - //pinWrite(pinB3,1); - } - else - { - pinWrite(pinB3,0); - } - */ - - - //test if the gpio port works as an input -/* - if(pinRead(pinA0) && !latch_old) - { - pinWrite(pinB3,1); - } - else - { - pinWrite(pinB3,0); - } - */ + delayMs(100); } return 1;