implementing timer. basic outline of the timer implemented. implemnted HW descriptions

interrupts
key 4 years ago
parent 32acece232
commit e633e46c8d

@ -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
}

@ -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);

@ -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
};

@ -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)

@ -21,8 +21,6 @@
*/
#include "pin.h"
#include "utils_assert.h"
#define MODER_IN 0x0UL
#define MODER_OUT 0x1UL
@ -123,8 +121,14 @@ 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));
@ -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);
}

@ -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)
{
}

@ -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)

@ -1,3 +1,6 @@
#warning "Generated from: " __FILE__
#include "main.hpp"
#include "delay.h"
#include "deviceSetup.h"
@ -9,10 +12,7 @@ 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;

Loading…
Cancel
Save