ICU and timer channel?

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

User avatar
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?

Post 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
utzig
Posts: 359
Joined: Sat Jan 07, 2012 6:22 pm
Has thanked: 1 time
Been thanked: 20 times

Re: ICU and timer channel?

Post 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
User avatar
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?

Post 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
mobyfab
Posts: 484
Joined: Sat Nov 19, 2011 6:47 pm
Has thanked: 21 times
Been thanked: 31 times

Re: ICU and timer channel?

Post by mobyfab »

Does the modification work for channel 3 and 4 as well?

Thanks.
User avatar
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?

Post by Giovanni »

No, just 1 and 2, supporting also 3 and 4 would probably be far more complex.

Giovanni
mobyfab
Posts: 484
Joined: Sat Nov 19, 2011 6:47 pm
Has thanked: 21 times
Been thanked: 31 times

Re: ICU and timer channel?

Post by mobyfab »

What needs to be done?
User avatar
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?

Post by Giovanni »

It was discussed before in this same thread:

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

Giovanni
User avatar
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?

Post 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
mobyfab
Posts: 484
Joined: Sat Nov 19, 2011 6:47 pm
Has thanked: 21 times
Been thanked: 31 times

Re: ICU and timer channel?

Post by mobyfab »

This is why I was asking, since you made some changes :)
utzig
Posts: 359
Joined: Sat Jan 07, 2012 6:22 pm
Has thanked: 1 time
Been thanked: 20 times

Re: ICU and timer channel?

Post 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.
Post Reply