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
extSetChannelModeI behaviour
Moderators: RoccoMarco, lbednarz, tfAteba
- Giovanni
- Site Admin
- Posts: 14891
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: extSetChannelModeI behaviour
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
EXT_CH_MODE_AUTOSTART is only used from ext_lld_start() and has no more effect after starting the driver.
Giovanni
Re: extSetChannelModeI behaviour
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:
but not
2) extSetChannelMode() should only be called on a disabled channel
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
- Giovanni
- Site Admin
- Posts: 14891
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: extSetChannelModeI behaviour
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
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
Re: extSetChannelModeI behaviour
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.
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.
Re: extSetChannelModeI behaviour
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.
- Giovanni
- Site Admin
- Posts: 14891
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: extSetChannelModeI behaviour
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
OK, documentation is never enough.
Note that EXT is going to disappear in HAL 6.0 (2018), PAL will also handle external interrupts.
Giovanni