first implementation of timer but the test in main doesn't work debbug needed

interrupts
key 4 years ago
parent 3063fdde11
commit 4082a6ad83

@ -1,3 +1,20 @@
/**
**************************************************************************************************
* @file timer.h
* @author Kerem Yollu & Edwin Koch
* @date 19.12.2021
* @version 1.0
**************************************************************************************************
* @brief This is the genral interface for timers.
*
* **Detailed Description :**
* This the timer interface and belongs to the interface layer
*
* @todo
* - 19.12.2021 : Should we check for a 32 to 16 bit overflow situation.
**************************************************************************************************
*/
#include "hardwareDescription.h"
typedef enum {
@ -41,5 +58,3 @@ uint32_t timerGetCount(timerNo_t timer);
void timerThrowError(timerError_t error);

@ -1,8 +1,22 @@
/*! Enum of the awailable pins for this package */
#include "stm32f042x6.h"
/**
**************************************************************************************************
* @file hardwareDescription.h
* @author Kerem Yollu & Edwin Koch
* @date 19.12.2021
* @version 1.0
**************************************************************************************************
* @brief This file contains all hardware specific definitions for STM32F042K6
*
* **Detailed Description :**
* This Header file contains all the registers and their bit manipulation options.
* All the extra Tables created here are to somplifly the main codes readability
*
* @todo
* - 19.12.2021 : implement until it runs :)
**************************************************************************************************
*/
// this file contains all the specific hardware definitions for the given chip stm32f042x6.
// Its used for the interfaces for the CSL.
#include "stm32f042x6.h"
#define PACKAGE_LQFP32 1
@ -120,20 +134,23 @@ static const uint8_t altFunc_List[MAX_N_PORTS_COUNT][MAX_PORT_PINS_COUNT] = {
}
};
// Timers
/*! Enum for awailable timer DS Page: 12 (block diagaram) The order of the enums is very important and should not be changed as it is used ofr table indexing */
typedef enum {
timer_1,
timer_2,
timer_3,
timer_14,
timer_16,
timer_17
timer_1, /*!< Advanced control 16-bit timer with PWM capability RM Page: 320 */
timer_2, /*!< General purpose 32-bit timer RM Page: 393 */
timer_3, /*!< General purpose 16-bit timer RM Page: 393 */
timer_14, /*!< General purpose 16-bit timer RM Page: 459 */
timer_16, /*!< General purpose 16-bit timer RM Page: 480 */
timer_17 /*!< General purpose 16-bit timer RM Page: 480 */
} timerNo_t;
typedef enum {
hb,
hsi
/*! Enum for awailable clok sources RM Page: 95 */
typedef enum {
HSI, /*!< High speed internal */
HSE, /*!< High speed external */
LSI, /*!< Low speed internal */
LSE /*!< Low speed External */
}clkSources_t;
static const uint32_t timerBase_Addr_List[MAX_TIMER_CHANNEL_COUNT] = {
@ -144,3 +161,21 @@ static const uint32_t timerBase_Addr_List[MAX_TIMER_CHANNEL_COUNT] = {
TIM16_BASE,
TIM17_BASE
};
static const uint8_t timerBus_En_bitPos[MAX_TIMER_CHANNEL_COUNT] = {
RCC_APB2ENR_TIM1EN_Pos,
RCC_APB1ENR_TIM2EN_Pos,
RCC_APB1ENR_TIM3EN_Pos,
RCC_APB1ENR_TIM14EN_Pos,
RCC_APB2ENR_TIM16EN_Pos,
RCC_APB2ENR_TIM17EN_Pos
};
static const uint8_t timerBus_No[MAX_TIMER_CHANNEL_COUNT] = {
2,
1,
1,
1,
2,
2
};

@ -1,15 +1,22 @@
#include "timer.h"
static const uint32_
#define BASE ((TIM_TypeDef *)timerBase_Addr_List[timer])
void timerActivateBus(timerNo_t timer)
{
if(timerBus_No[timer]==1)
{
RCC->APB1ENR |= (1<<timerBus_En_bitPos[timer]);
return;
}
RCC->APB2ENR |= (1<<timerBus_En_bitPos[timer]);
}
void timerEnableTimer(timerNo_t timer)
{
BASE->CR1 &= ~0x01; //all the timers have the same CEN bit in CR1 register pos 0
}
void timerSetClkSource(timerNo_t timer, clkSources_t clk)
@ -29,7 +36,7 @@ void timerSetCountDirection(timerNo_t timer, timerCountDirection_t direction)
void timerSetPrescaler(timerNo_t timer, uint32_t prescaler)
{
BASE->PSC = prescaler;
}
void timerSetPostscaler(timerNo_t timer, uint32_t postscaler)
@ -39,12 +46,13 @@ void timerSetPostscaler(timerNo_t timer, uint32_t postscaler)
void timerSetAutoReload(timerNo_t timer, uint32_t reload)
{
BASE->ARR = reload;
}
void timerClearCounter(timerNo_t timer)
{
BASE->CNT = 0;
}

@ -867,7 +867,8 @@ WARN_LOGFILE =
INPUT = @CMAKE_CURRENT_SOURCE_DIR@/ \
@CMAKE_CURRENT_SOURCE_DIR@/bsl/csl/interfaces/ \
@CMAKE_CURRENT_SOURCE_DIR@/bsl/csl/stm32f042/Drivers/CMSIS/Device/ST/STM32F0xx/Include/ \
@CMAKE_CURRENT_SOURCE_DIR@/bsl/csl/stm32f042/Src/
@CMAKE_CURRENT_SOURCE_DIR@/bsl/csl/stm32f042/Src/ \
@CMAKE_CURRENT_SOURCE_DIR@/bsl/csl/stm32f042/Device/
# This tag can be used to specify the character encoding of the source files

@ -3,6 +3,7 @@
#include "deviceSetup.h"
#include "usart.h"
#include "ascii.h"
#include "timer.h"
int main(int argc, char *argv[])
{
@ -11,6 +12,12 @@ int main(int argc, char *argv[])
delayInitMs(8000000, 1000);
timerActivateBus(timer_2);
timerSetPrescaler(timer_2,159999);
timerSetAutoReload(timer_2,999999);
timerClearCounter(timer_2);
timerEnableTimer(timer_2);
pinConfig(pinB3, output, pushPull, def_res, def_speed);
pinConfig(pinA0, input, def_stage, pullDown, def_speed);
@ -39,6 +46,10 @@ int main(int argc, char *argv[])
while(1)
{
while(!(TIM2->SR & 1));
TIM2->SR &=~ 1;
pinToggle(pinB3);
/*
//USART will rteturn what wou type and trun led on if you press "1"
a = usartGetChar(usart2);
usartSendChar(usart2, a);
@ -61,6 +72,7 @@ int main(int argc, char *argv[])
pinWrite(pinB3,0);
}
delayMs(10);
*/
}
return 1;
}

Loading…
Cancel
Save