extSetChannelModeI behaviour

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

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
dflogeras
Posts: 232
Joined: Tue Sep 03, 2013 8:16 pm
Has thanked: 8 times
Been thanked: 22 times

extSetChannelModeI behaviour

Post by dflogeras »

Hi

Chibi_3.0.2, armv6m

At some point in a program I wish to change one of my EXT configs from RISING to FALLING edge. For that I am using the extSetChannelModeI() function.

I did notice however, that within the extSetChannelModeI() implementation, the last thing it does is calls ext_lld_channel_enable(). Is this intended, since there are already functions to Start/Stop channels? Also it makes the AUTOSTART option do nothing. I guess it also would assume that the channel is in the stopped condition, but doesn't seem to check for that or mention in the docs. Am I missing something?

D
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: extSetChannelModeI behaviour

Post by Giovanni »

ext_lld_channel_enable() is the function that reprograms the channel, what is the problem exactly?

EXT_CH_MODE_AUTOSTART is only used from ext_lld_start() and has no more effect after starting the driver.

Giovanni
dflogeras
Posts: 232
Joined: Tue Sep 03, 2013 8:16 pm
Has thanked: 8 times
Been thanked: 22 times

Re: extSetChannelModeI behaviour

Post by dflogeras »

I guess I have always seen extChannelEnable/Disable() as a complementary pair, which may be my misunderstanding. To clarify, are the following points correct:

1) extSetChannelMode() would replace the Enable() call. For instance if I wished to switch from rising edge to falling edge, I would do:

Code: Select all

extChannelDisable( .. );
extSetChannelMode( .. );

but not

Code: Select all

extChannelDisable( .. );
extSetChannelMode( .. );
extChannelEnable( .. );


2) extSetChannelMode() should only be called on a disabled channel
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: extSetChannelModeI behaviour

Post by Giovanni »

Yes.

I know it is a bit confusing, it is one of those drivers requiring one more pass. Even because that overriding the "const" declaration in extSetChannelModeI() is something don't like.

Giovanni
dflogeras
Posts: 232
Joined: Tue Sep 03, 2013 8:16 pm
Has thanked: 8 times
Been thanked: 22 times

Re: extSetChannelModeI behaviour

Post by dflogeras »

Thanks for clarifying.

All software has imperfections, but you warn us clearly about the const problem. That being said, it is up to the user to read and comprehend the issue, and also to follow your warning. In my opinion, a more explicit approach could be:
- Make a #define in halconf.h (something like EXT_USE_DYNAMIC_CONFIGURATION)
- Only expose the non-const API (setChannelMode/I() ) if that option is ticked
- Let the compiler enforce the const rule, since by enabling it you are explicitly agreeing that your data structure must be in ram
- If you do not enable it, the Start/Stop functions may remain const and work happily on RAM/ROM data structures.
hyOzd
Posts: 20
Joined: Tue Jul 21, 2015 12:17 pm
Has thanked: 1 time
Been thanked: 2 times

Re: extSetChannelModeI behaviour

Post by hyOzd »

Hi Giovanni, from documentation it is not apparent that `extSetChannelMode` also enables the channel. That caused frustrating moments for me : ) until I read the source code. It would be nice if you could add this as a note.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: extSetChannelModeI behaviour

Post by Giovanni »

Hi,

OK, documentation is never enough.

Note that EXT is going to disappear in HAL 6.0 (2018), PAL will also handle external interrupts.

Giovanni
Post Reply