Hi,
I merged the patch and made some more changes. Please verify everything is OK when you have a chance. Note that the fields in the configuration structure have been reordered. I made anther change in order to make icuGetWidth() and icuGetPeriod() work regardless the selected input.
I hope I didn't introduce errors.
Giovanni
ICU and timer channel?
Moderators: RoccoMarco, lbednarz, tfAteba
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: ICU and timer channel?
Hi Giovanni,
It is working for me right now with the changes but I'm quite sure there's a problem there.
The trick you did using wccrp, pccrp is really cool. And I think that it enables the removal of channel testing in icu_lld_serve_interrupt and icu_lld_enable because it already swaps the CCRs so there would be no need to do it in these functions.
I'm not entirely sure of this yet because I always use both period and width callbacks so it doesn't make any difference. I'll try to give it a run using only width and only period by Friday.
Is it a guideline putting new fields in a struct always at the end?
Att,
Fabio Utzig
It is working for me right now with the changes but I'm quite sure there's a problem there.
The trick you did using wccrp, pccrp is really cool. And I think that it enables the removal of channel testing in icu_lld_serve_interrupt and icu_lld_enable because it already swaps the CCRs so there would be no need to do it in these functions.
I'm not entirely sure of this yet because I always use both period and width callbacks so it doesn't make any difference. I'll try to give it a run using only width and only period by Friday.
Is it a guideline putting new fields in a struct always at the end?
Att,
Fabio Utzig
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: ICU and timer channel?
Any further improvement is welcome of course.
About fields, by putting them at the end you keep backward compatibility, shorter initializers fill the remaining fields to zero. But the reason because I moved "channel" to the end is not just that, it is an STM32-specific implementation field to it must stay below the "/* End of the mandatory fields.*/" line, fields above that line are part of the "standard" driver.
Giovanni
About fields, by putting them at the end you keep backward compatibility, shorter initializers fill the remaining fields to zero. But the reason because I moved "channel" to the end is not just that, it is an STM32-specific implementation field to it must stay below the "/* End of the mandatory fields.*/" line, fields above that line are part of the "standard" driver.
Giovanni
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: ICU and timer channel?
No, just 1 and 2, supporting also 3 and 4 would probably be far more complex.
Giovanni
Giovanni
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: ICU and timer channel?
After reviewing the code, thanks to recent changes supporting channels 3 and 4 should not be particularly difficult because access to CCR registers has already been abstracted.
It is mainly matter or extending the current code and testing.
Giovanni
It is mainly matter or extending the current code and testing.
Giovanni
Re: ICU and timer channel?
Giovanni,
I just reviewed the whole ICU driver with an oscilloscope and everything is right, working with CH1 and CH2 in both LOW and HIGH active modes. So what I suggested before of maybe having to remove the tests for channel in icu_lld_enable and icu_lld_serve_interrupt was wrong.
Still I don't like this tests! They just make the code more "duplicated" (for the lack of a better expression). What I would suggest would be something very similar to what you did with wccrp and pccrp. Add two new fields to the Driver structure to hold the masks for TIM_SR_CCx and TIM_CR_CCx for both channels, initialized on the same place as wccrp/pccrp. This way the both functions cited before would get cleaner. I will do this next and see how it looks.
Also regarding channels 3 and 4 the reference manual at section 15.3.6 states this: "The PWM input mode can be used only with the TIMx_CH1/TIMx_CH2 signals due to the fact that only TI1FP1 and TI2FP2 are connected to the slave mode controller."
So, I guess it's not possible to use these channels 3 and 4. At least the way everything is done today.
I just reviewed the whole ICU driver with an oscilloscope and everything is right, working with CH1 and CH2 in both LOW and HIGH active modes. So what I suggested before of maybe having to remove the tests for channel in icu_lld_enable and icu_lld_serve_interrupt was wrong.
Still I don't like this tests! They just make the code more "duplicated" (for the lack of a better expression). What I would suggest would be something very similar to what you did with wccrp and pccrp. Add two new fields to the Driver structure to hold the masks for TIM_SR_CCx and TIM_CR_CCx for both channels, initialized on the same place as wccrp/pccrp. This way the both functions cited before would get cleaner. I will do this next and see how it looks.
Also regarding channels 3 and 4 the reference manual at section 15.3.6 states this: "The PWM input mode can be used only with the TIMx_CH1/TIMx_CH2 signals due to the fact that only TI1FP1 and TI2FP2 are connected to the slave mode controller."
So, I guess it's not possible to use these channels 3 and 4. At least the way everything is done today.