Timer.c Check for prescaler overflow and wrote some documentation with new todo s

interrupts
key 3 years ago
parent ee0f8227b9
commit 5cfbacc060

@ -20,14 +20,15 @@ INTERFACES
- pin - pin
- pin.h Is now only missing interrupt functions - pin.h Is now only missing interrupt functions
- USART - USART
- usart.h Is wirking Great But there are many more functionalities to be added. - usart.h Is working Great But there are many more functionalities to be added.
- usart.h Interrupt and DMA are the next steps - usart.h Interrupt and DMA are the next steps
- deviceSetup - deviceSetup
- deviceSetup.h it's a copy of what ST has made but wit direct register acsess - deviceSetup.h it's a copy of what ST has made but wit direct register acsess
- deviceSetup.h we need to test it with other configurations to see if it works as - deviceSetup.h we need to test it with other configurations to see if it works as
supposed or if the MCU is on it's defaul 8MHz congif. supposed or if the MCU is on it's defaul 8MHz congif.
- setupInit(); funtion is called from bsl/csl/stm32f042/startup/startup_stm32f042x6.s and is called before the main(); - setupInit(); funtion is called from bsl/csl/stm32f042/startup/startup_stm32f042x6.s
and is called before the main();
PROGRAMMING PROGRAMMING

@ -10,8 +10,11 @@
* **Detailed Description :** * **Detailed Description :**
* This the timer interface and belongs to the interface layer * This the timer interface and belongs to the interface layer
* *
* @todo * @todo Following functions are to be implmented :
* - 19.12.2021 : Should we check for a 32 to 16 bit overflow situation. * timerSetHz
* timerSetMs
* timerSetNs
* timerSetPs
************************************************************************************************** **************************************************************************************************
*/ */
@ -24,9 +27,11 @@ extern "C" {
#include "hardwareDescription.h" #include "hardwareDescription.h"
/*! Emun of possible Timer Errors */
typedef enum { typedef enum {
functionNotSupported, functionNotSupported, /*!< This Funtion is not awailable on this **HARDWARE** */
prescalerOutOfRange prescalerOutOfRange /*!< Set prescaler value exeeds the Register's **HARDWARE** size */
} timerError_t; } timerError_t;
typedef enum { typedef enum {
@ -41,12 +46,21 @@ typedef enum {
onePulse onePulse
} timerMode_t; } timerMode_t;
/*!
* Reset the timer to its default state.
*/
void timerReset(timerNo_t timer); void timerReset(timerNo_t timer);
void timerActivateBus(timerNo_t timer); void timerActivateBus(timerNo_t timer);
void timerEnable(timerNo_t timer); void timerEnable(timerNo_t timer);
void timerDisable(timerNo_t timer); void timerDisable(timerNo_t timer);
void timerSetMode(timerNo_t timer, timerMode_t mode); void timerSetMode(timerNo_t timer, timerMode_t mode);
void timerSetCountDirection(timerNo_t timer, timerCountDirection_t direction); void timerSetCountDirection(timerNo_t timer, timerCountDirection_t direction);
/*!
* Sets the given timer's prescaler value.
* This fucntion will also check if the entered prascaler value exeeds the register size.
* If violated the prescalerOutOfRange Error will be generated.
*/
void timerSetPrescaler(timerNo_t timer, uint32_t prescaler); void timerSetPrescaler(timerNo_t timer, uint32_t prescaler);
void timerSetPostscaler(timerNo_t timer, uint32_t postscaler); void timerSetPostscaler(timerNo_t timer, uint32_t postscaler);
void timerSetAutoReload(timerNo_t timer, uint32_t reload); void timerSetAutoReload(timerNo_t timer, uint32_t reload);
@ -56,6 +70,7 @@ void timerClearCounter(timerNo_t timer);
/* Second stage configuration */ /* Second stage configuration */
void timerInit(timerNo_t timer, uint32_t prescaler, uint32_t period, timerCountDirection_t direction, timerMode_t mode); void timerInit(timerNo_t timer, uint32_t prescaler, uint32_t period, timerCountDirection_t direction, timerMode_t mode);
void timerSetHz(timerNo_t timer, uint16_t hz); void timerSetHz(timerNo_t timer, uint16_t hz);
void timerSetMs(timerNo_t timer, uint16_t ms); void timerSetMs(timerNo_t timer, uint16_t ms);
void timerSetNs(timerNo_t timer, uint16_t ns); void timerSetNs(timerNo_t timer, uint16_t ns);

@ -194,6 +194,9 @@ static const uint8_t timerBus_En_bitPos[MAX_TIMER_CHANNEL_COUNT] = {
RCC_APB2ENR_TIM17EN_Pos RCC_APB2ENR_TIM17EN_Pos
}; };
/*!
* RCC timer Reset Bit Position list
* */
static const uint8_t timerBus_Rst_bitPos[MAX_TIMER_CHANNEL_COUNT] = { static const uint8_t timerBus_Rst_bitPos[MAX_TIMER_CHANNEL_COUNT] = {
RCC_APB2RSTR_TIM1RST_Pos, RCC_APB2RSTR_TIM1RST_Pos,
RCC_APB1RSTR_TIM2RST_Pos, RCC_APB1RSTR_TIM2RST_Pos,
@ -203,13 +206,28 @@ static const uint8_t timerBus_Rst_bitPos[MAX_TIMER_CHANNEL_COUNT] = {
RCC_APB2RSTR_TIM17RST_Pos RCC_APB2RSTR_TIM17RST_Pos
}; };
/*!
* RCC Bus number index list connected to the timer
* */
static const uint8_t timerBus_No[MAX_TIMER_CHANNEL_COUNT] = { static const uint8_t timerBus_No[MAX_TIMER_CHANNEL_COUNT] = {
2, 2, /*!< timer 1 is connected to bus 2 */
1, 1, /*!< timer 2 is connected to bus 1 */
1, 1, /*!< timer 3 is connected to bus 1 */
1, 1, /*!< timer 14 is connected to bus 1 */
2, 2, /*!< timer 16 is connected to bus 2 */
2 2 /*!< timer 17 is connected to bus 2 */
};
/*!
* Timer Prescaler resolution list TO BE DELETED IF NOT NEEDED
* */
static const uint32_t timerRes_Prescaler[MAX_TIMER_CHANNEL_COUNT] = {
0xFFFF, /*!< Timer 1 Prescaler Max Value */
0xFFFF, /*!< Timer 2 Prescaler Max Value */
0xFFFF, /*!< Timer 3 Prescaler Max Value */
0xFFFF, /*!< Timer 14 Prescaler Max Value */
0xFFFF, /*!< Timer 16 Prescaler Max Value */
0xFFFF, /*!< Timer 17 Prescaler Max Value */
}; };
#ifdef __cplusplus #ifdef __cplusplus

@ -54,12 +54,17 @@ void timerSetCountDirection(timerNo_t timer, timerCountDirection_t direction)
void timerSetPrescaler(timerNo_t timer, uint32_t prescaler) void timerSetPrescaler(timerNo_t timer, uint32_t prescaler)
{ {
BASE->PSC = prescaler; if(prescaler > timerRes_Prescaler[timer])
{
timerThrowError(prescalerOutOfRange);
return; // To prevent writing wrong value in to the Register
}
BASE->PSC = prescaler;
} }
void timerSetPostscaler(timerNo_t timer, uint32_t postscaler) void timerSetPostscaler(timerNo_t timer, uint32_t postscaler)
{ {
timerThrowError(functionNotSupported);
} }
void timerSetAutoReload(timerNo_t timer, uint32_t reload) void timerSetAutoReload(timerNo_t timer, uint32_t reload)
@ -138,7 +143,6 @@ void timerSetPs(timerNo_t timer, uint16_t ps)
} }
void timerSart(timerNo_t timer) void timerSart(timerNo_t timer)
{ {
timerEnable(timer); timerEnable(timer);
@ -163,6 +167,6 @@ uint32_t timerGetCount(timerNo_t timer)
void timerThrowError(timerError_t error) void timerThrowError(timerError_t error)
{ {
while(1);
} }

@ -1,6 +1,3 @@
#warning "Generated from: " __FILE__
#include "main.hpp" #include "main.hpp"
#include "delay.h" #include "delay.h"
#include "deviceSetup.h" #include "deviceSetup.h"
@ -11,14 +8,11 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
uint8_t i = 0; uint8_t i = 0;
uint8_t a = '0';
delayInitMs(8000000, 1000);
//timerSetHz(timer_2,3); delayInitMs(8000000, 1000); // Clock Freq and Divider for ARM library
timerInit(timer_2, 7999, 999, downCounting, counter); timerInit(timer_1, 7999, 999, downCounting, counter);
timerSart(timer_2); timerSart(timer_1);
pinConfig(pinB3, output, pushPull, def_res, def_speed); pinConfig(pinB3, output, pushPull, def_res, def_speed);
pinConfig(pinA0, input, def_stage, pullDown, def_speed); pinConfig(pinA0, input, def_stage, pullDown, def_speed);
@ -33,7 +27,7 @@ int main(int argc, char *argv[])
noFlowControl); noFlowControl);
//clears screen and send the wellcome messgae //clears screen and send the wellcome messgae
// print_Usart(usart2, ASCII_clear); print_Usart(usart2, ASCII_clear);
print_Usart(usart2, const_cast<char *>("Wellcome to our KED project\n\r")); print_Usart(usart2, const_cast<char *>("Wellcome to our KED project\n\r"));
@ -54,22 +48,6 @@ int main(int argc, char *argv[])
pinToggle(pinB3); pinToggle(pinB3);
} }
/*
while(1)
{
//USART will rteturn what wou type and trun led on if you press "1"
a = usartGetChar(usart2);
usartSendChar(usart2, a);
if(a == '1') {
pinWrite(pinB3,1);
} else if(a == '0'){
pinWrite(pinB3,0);
delayMs(100);
}
*/
return 1; return 1;
} }

Loading…
Cancel
Save