EICU. Timer widht (16-32 bits) now stored in driver field and detected durign startup

This commit is contained in:
barthess 2015-03-05 15:59:32 +03:00
parent e75668f53b
commit ae1ce0ea2b
2 changed files with 26 additions and 6 deletions

View File

@ -149,7 +149,7 @@ static eicuresult_t get_time_both(EICUDriver *eicup,
unsigned subtraction math.*/ unsigned subtraction math.*/
/* 16-bit timer */ /* 16-bit timer */
if (0xFFFF == eicup->tim->ARR) { if (EICU_WIDTH_16 == eicup->width) {
uint16_t cmp = compare; uint16_t cmp = compare;
uint16_t la = chp->last_active; uint16_t la = chp->last_active;
uint16_t li = chp->last_idle; uint16_t li = chp->last_idle;
@ -159,7 +159,7 @@ static eicuresult_t get_time_both(EICUDriver *eicup,
ret.period = p; ret.period = p;
} }
/* 32-bit timer */ /* 32-bit timer */
else if (0xFFFFFFFF == eicup->tim->ARR) { else if (EICU_WIDTH_32 == eicup->width) {
ret.width = chp->last_idle - chp->last_active; ret.width = chp->last_idle - chp->last_active;
ret.period = compare - chp->last_active; ret.period = compare - chp->last_active;
return ret; return ret;
@ -193,14 +193,14 @@ static eicucnt_t get_time_width(EICUDriver *eicup,
unsigned subtraction math.*/ unsigned subtraction math.*/
/* 16-bit timer */ /* 16-bit timer */
if (0xFFFF == eicup->tim->ARR) { if (EICU_WIDTH_16 == eicup->width) {
uint16_t cmp = compare; uint16_t cmp = compare;
uint16_t la = chp->last_active; uint16_t la = chp->last_active;
uint16_t ret = cmp - la; uint16_t ret = cmp - la;
return ret; return ret;
} }
/* 32-bit timer */ /* 32-bit timer */
else if (0xFFFFFFFF == eicup->tim->ARR) { else if (EICU_WIDTH_32 == eicup->width) {
return compare - chp->last_active; return compare - chp->last_active;
} }
/* error trap */ /* error trap */
@ -231,14 +231,14 @@ static eicucnt_t get_time_period(EICUDriver *eicup,
unsigned subtraction math.*/ unsigned subtraction math.*/
/* 16-bit timer */ /* 16-bit timer */
if (0xFFFF == eicup->tim->ARR) { if (EICU_WIDTH_16 == eicup->width) {
uint16_t cmp = compare; uint16_t cmp = compare;
uint16_t li = chp->last_idle; uint16_t li = chp->last_idle;
uint16_t ret = cmp - li; uint16_t ret = cmp - li;
return ret; return ret;
} }
/* 32-bit timer */ /* 32-bit timer */
else if (0xFFFFFFFF == eicup->tim->ARR) { else if (EICU_WIDTH_32 == eicup->width) {
return compare - chp->last_idle; return compare - chp->last_idle;
} }
/* error trap */ /* error trap */
@ -807,6 +807,14 @@ void eicu_lld_start(EICUDriver *eicup) {
eicup->tim->PSC = (uint16_t)psc; eicup->tim->PSC = (uint16_t)psc;
eicup->tim->ARR = (eicucnt_t)-1; eicup->tim->ARR = (eicucnt_t)-1;
/* Detect width.*/
if (0xFFFFFFFF == eicup->tim->ARR)
eicup->width = EICU_WIDTH_32;
else if (0xFFFF == eicup->tim->ARR)
eicup->width = EICU_WIDTH_16;
else
osalSysHalt("Unsupported width");
/* Reset registers */ /* Reset registers */
eicup->tim->SMCR = 0; eicup->tim->SMCR = 0;
eicup->tim->CCMR1 = 0; eicup->tim->CCMR1 = 0;

View File

@ -281,6 +281,14 @@ typedef enum {
EICU_INPUT_BOTH EICU_INPUT_BOTH
} eicucapturemode_t; } eicucapturemode_t;
/**
* @brief Timer registers width in bits.
*/
typedef enum {
EICU_WIDTH_16,
EICU_WIDTH_32
} eicutimerwidth_t;
/** /**
* @brief EICU frequency type. * @brief EICU frequency type.
*/ */
@ -390,6 +398,10 @@ struct EICUDriver {
* @brief Timer base clock. * @brief Timer base clock.
*/ */
uint32_t clock; uint32_t clock;
/**
* @brief Timer registers width in bits.
*/
eicutimerwidth_t width;
/** /**
* @brief Pointer to configuration for the driver. * @brief Pointer to configuration for the driver.
*/ */