IMplmentation of timer ouput compare modules not yet compiled!

interrupts
key 3 years ago
parent 1ca19f313c
commit d733f2c856

@ -23,12 +23,13 @@ extern "C" {
#endif
#include "hardwareDescription.h"
#include "pin.h"
/*! Emun of possible Timer Errors */
typedef enum {
functionNotSupported, /*!< This Funtion is not awailable on this **HARDWARE** */
prescalerOutOfRange /*!< Set prescaler value exeeds the Register's **HARDWARE** size */
prescalerOutOfRange, /*!< Set prescaler value exeeds the Register's **HARDWARE** size */
ccChannelNoOutOfRange /*!< The Selecter internal Capture/Compare timer cahnnel is not given by the **HARDWARE** size */
} timerError_t;
/*! Enum of possible counting modes */
@ -57,7 +58,7 @@ typedef enum {
inactive_force_low, /*!< Pin if forced **low** */
pwm_normal, /*!< Standart PWM mode */
pwm_inverted /*!< Inverted PWM mode */
};
} timerOutputCompareMode_t ;
/*!
* @brief Reset the timer to its default state
@ -131,14 +132,36 @@ void timerClearCounter(timerNo_t timer);
void timerInitCounter( timerNo_t timer,
uint32_t prescaler,
uint32_t period,
uint32_t autoReload,
timerCountDirection_t direction);
/*!
* This funtion is not implemented yet. Will be used to implment pwm functionality of the timer.
*/
void timerInitPwm( timerNo_t timer,
uint32_t prescaler,
uint32_t period,
timerCountDirection_t direction);
/*!
* @brief Sets the Timer to the desired compare mode The function timerInitCounter(); Should be
* called before to init the Timer.
* Calling this function will stop the timer and clear the counter.
*
* @param timer The desired timer number
* @param mode The desired output compare mode
* @param timerIoChannel The internal Timer Capture compare channel to be used.
* @param pinNo The desired Pin Number to be used as outpujt
* @param alternate The Alternate funtion No for the given Pin
* @param polarity Sets the <F2> the given Pin
*/
void timerInitOutputCompare( timerNo_t timer,
timerOutputCompareMode_t mode,
uint8_t timerIoChannel,
pinNo_t pinNo,
uint16_t alternate,
uint8_t polarity);
/*!
* @brief Set the outoreload value of the timer
*
@ -157,9 +180,24 @@ void timerSetMs(timerNo_t timer, uint16_t ms);
void timerSetNs(timerNo_t timer, uint16_t ns);
void timerSetPs(timerNo_t timer, uint16_t ps);
/*!
* @brief Enables the timer
* @param timer The desired timer number
*/
void timerSart(timerNo_t timer);
/*!
* @brief Disables the timer
* @param timer The desired timer number
*/
void timerHalt(timerNo_t timer);
/*!
* @brief Halts the timer and then clears the counter.
* @param timer The desired timer number
*/
void timerStop(timerNo_t timer);
uint32_t timerGetCount(timerNo_t timer);
void timerThrowError(timerError_t error);

@ -37,7 +37,7 @@ void timerDisable(timerNo_t timer)
void timerSetMode(timerNo_t timer, timerMode_t mode)
{
//Implement
// Propably not needed
}
void timerSetCountDirection(timerNo_t timer, timerCountDirection_t direction)
@ -88,21 +88,67 @@ void timerClearUpdateInterrupt(timerNo_t timer)
BASE->SR &= ~1;
}
/* Second stage configuration */
void timerInitCounter ( timerNo_t timer,
uint32_t prescaler,
uint32_t period,
uint32_t autoReload,
timerCountDirection_t direction)
{
timerActivateBus(timer);
timerReset(timer);
timerSetMode(timer, counter);
timerSetCountDirection(timer,direction);
timerSetPrescaler(timer, prescaler);
timerSetAutoReload(timer, period);
timerSetAutoReload(timer, autoReload);
}
void timerConfigOutputCompare( timerNo_t timer,
timerOutputCompareMode_t mode,
uint8_t timerIoChannel,
pinNo_t pinNo,
uint16_t alternate,
uint8_t polarity)
{
timerStop(timer);
pinSetAlternate(pinNo,alternate);
switch(timerIoChannel)
{
case 1:
BASE->CCMR1 &= ~TIM_CCMR1_OC1M;
BASE->CCMR1 |= mode << TIM_CCMR1_OC1M_Pos;
BASE->CCER |= TIM_CCER_CC1E;
BASE->CCER |= (1&&polarity) << TIM_CCER_CC1P_Pos;
BASE->CCER &= ~TIM_CCER_CC1NP;
break;
case 2:
BASE->CCMR1 &= ~TIM_CCMR1_OC2M;
BASE->CCMR1 |= mode << TIM_CCMR1_OC2M_Pos;
BASE->CCER |= TIM_CCER_CC2E;
BASE->CCER |= (1&&polarity) << TIM_CCER_CC2P_Pos;
BASE->CCER &= ~TIM_CCER_CC2NP;
break;
case 3:
BASE->CCMR2 &= ~TIM_CCMR2_OC3M;
BASE->CCMR2 |= mode << TIM_CCMR2_OC3M_Pos;
BASE->CCER |= TIM_CCER_CC3E;
BASE->CCER |= (1&&polarity) << TIM_CCER_CC3P_Pos;
BASE->CCER &= ~TIM_CCER_CC3NP;
break;
case 4:
BASE->CCMR2 &= ~TIM_CCMR2_OC4M;
BASE->CCMR2 |= mode << TIM_CCMR2_OC4M_Pos;
BASE->CCER |= TIM_CCER_CC4E;
BASE->CCER |= (1&&polarity) << TIM_CCER_CC4P_Pos;
BASE->CCER &= ~TIM_CCER_CC4NP;
break;
default:
timerThrowError(ccChannelNoOutOfRange);
break;
};
}
/* Bus Clock
* ------------------------------ = Duty (Hz)
* (Prescaler-1) * (Period-1)
@ -159,6 +205,7 @@ void timerStop(timerNo_t timer)
timerClearCounter(timer);
}
uint32_t timerGetCount(timerNo_t timer)
{
return BASE->CNT;
@ -169,4 +216,4 @@ void timerThrowError(timerError_t error)
{
while(1);
}

Loading…
Cancel
Save