On Wed, Oct 9, 2013 at 10:06 AM, Linge Dai <[email protected]> wrote:
> which allows modifying any arbitrary register. The programmers need to
> explicitly enforce restrictions on what to pass to the function. Is the API
> meant to be designed this way?
>
I don't know, I didn't design it, but I approve of the API as designed.
One of the challenges of writing embedded code is that you need to be
cognizant of careful programming vs performance cost. It is true you could
wrap the function, or the parameter to the function, and there is a library
that does exactly that, its is the ST Micro Standard Peripheral library.
Many people, myself included, find it unusable. Not just for the
wrapping/unwrapping, gratuitous structuring stuff, but it is solving
problems that do not exist.
So lets look at this function call again, rcc_peripheral_enable_clock. Its
true you could pass it any register, hell you could cast and arbitrary 32
bit hex constant to a pointer and just pass it right in there! But unless
you actually pass it the register that is involved in enabling the
peripheral clock, it won't do what you expect, and your code won't run.
Even the simplest basic function test will fail because the peripheral your
code is using won't actually have its clock enabled.
So in this case no wrapping, checking, or other syntactic helper is
particularly necessary as the act of trying out the resulting program will
immediately call out the problem, albeit at a later stage, but this is no
different than if you had called with an otherwise valid RCC clock enable
but for the wrong peripheral. By weighing the utility of the extra
complexity (technical debt) against the effectiveness in preventing the
erroneous outcome, I don't think adding extra check code would be a useful
addition.
Just my opinion of course,
--Chuck
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60134071&iu=/4140/ostg.clktrk
_______________________________________________
libopencm3-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libopencm3-devel