CMSIS bug for Timer capture functions

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CMSIS bug for Timer capture functions

374 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tjoAG on Fri Nov 23 00:22:00 MST 2012
Hi all

There must be something wrong with the Timer capture function in the CMSIS for the LPC17xx!!

See this function:

<code>
/*********************************************************************//**
* @brief Get Capture Interrupt Status
* @param[in]TIMx Timer selection, should be:
*- LPC_TIM0: TIMER0 peripheral
*- LPC_TIM1: TIMER1 peripheral
*- LPC_TIM2: TIMER2 peripheral
*- LPC_TIM3: TIMER3 peripheral
* @param[in]IntFlag: interrupt type, should be:
* - TIM_MR0_INT: Interrupt for Match channel 0
* - TIM_MR1_INT: Interrupt for Match channel 1
* - TIM_MR2_INT: Interrupt for Match channel 2
* - TIM_MR3_INT: Interrupt for Match channel 3
* - TIM_CR0_INT: Interrupt for Capture channel 0
* - TIM_CR1_INT: Interrupt for Capture channel 1
* @return FlagStatus
* - SET : interrupt
* - RESET : no interrupt
**********************************************************************/
FlagStatus TIM_GetIntCaptureStatus(LPC_TIM_TypeDef *TIMx, TIM_INT_TYPE IntFlag)
{
uint8_t temp;
temp = (TIMx->IR) & (1<<(4+IntFlag));
if(temp)
return SET;
return RESET;
}
</code>

The defines for the function
<code>
/***********************************************************************
* Timer device enumeration
**********************************************************************/
/** @brief interrupt type */
typedef enum
{
TIM_MR0_INT =0, /*!< interrupt for Match channel 0*/
TIM_MR1_INT =1, /*!< interrupt for Match channel 1*/
TIM_MR2_INT =2, /*!< interrupt for Match channel 2*/
TIM_MR3_INT =3, /*!< interrupt for Match channel 3*/
TIM_CR0_INT =4, /*!< interrupt for Capture channel 0*/
TIM_CR1_INT =5, /*!< interrupt for Capture channel 1*/
}TIM_INT_TYPE;
</code>

So getting the capture status for the TIM_CR0_INT would resolve in masking the IR register with:

0x100 (1 << (4 + 4))

Should have been 0x10 (bit 4)!!!

Thomas
Labels (1)
0 Kudos
1 Reply

357 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TKoe on Fri Nov 23 01:23:14 MST 2012
Hi!

Yep, looks like the "4+" part is wrong here.
The function TIM_GetIntStatus can be used instead though, because that does pretty much the same.

Maybe at one point the capture part was supposed to be an extra typedef where TIM_CR0_INT = 0 and TIM_CR1_INT = 1...


Regards!
0 Kudos