Page 3 of 6

Re: ICU and timer channel?

Posted: Sat Feb 18, 2012 5:52 pm
by Giovanni
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

Re: ICU and timer channel?

Posted: Wed Feb 22, 2012 9:40 pm
by utzig
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

Re: ICU and timer channel?

Posted: Wed Feb 22, 2012 9:49 pm
by Giovanni
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

Re: ICU and timer channel?

Posted: Mon Mar 12, 2012 7:14 pm
by mobyfab
Does the modification work for channel 3 and 4 as well?

Thanks.

Re: ICU and timer channel?

Posted: Mon Mar 12, 2012 7:15 pm
by Giovanni
No, just 1 and 2, supporting also 3 and 4 would probably be far more complex.

Giovanni

Re: ICU and timer channel?

Posted: Tue Mar 13, 2012 2:26 pm
by mobyfab
What needs to be done?

Re: ICU and timer channel?

Posted: Tue Mar 13, 2012 2:34 pm
by Giovanni
It was discussed before in this same thread:

viewtopic.php?f=2&t=247#p2120

Giovanni

Re: ICU and timer channel?

Posted: Tue Mar 13, 2012 3:15 pm
by Giovanni
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

Re: ICU and timer channel?

Posted: Tue Mar 13, 2012 3:54 pm
by mobyfab
This is why I was asking, since you made some changes :)

Re: ICU and timer channel?

Posted: Thu Mar 15, 2012 3:17 pm
by utzig
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.