>>>>> "Linge" == Linge Dai <[email protected]> writes:
Linge> Hi, I'm using STM32F4 + libopencm3. I have noticed that some of
Linge> the library functions are declared to have a pointer to registers
Linge> as a parameter:
Linge> For example, in rcc.h: void rcc_peripheral_enable_clock(volatile
Linge> uint32_t *reg, uint32_t en);
Linge> which allows modifying any arbitrary register. The programmers
Linge> need to explicitly enforce restrictions on what to pass to the
Linge> function. Is the API meant to be designed this way?
Linge> A fix to this problem is to wrap the valid register values in an
Linge> enum and use the enum as the function parameter. The new
Linge> declaration of this function will be:
Linge> void rcc_peripheral_enable_clock(clock_enable_reg_t
Linge> clock_enable_reg, uint32_t en);
I think that function is overcomplicated and as you point out dangerous.
What is the advantage of e.g. writing
rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_USBEN);
against directly writing
RCC_APB1ENR |= RCC_APB1ENR_USBEN;
Bye
--
Uwe Bonnes [email protected]
Institut fuer Kernphysik Schlossgartenstrasse 9 64289 Darmstadt
--------- Tel. 06151 162516 -------- Fax. 06151 164321 ----------
------------------------------------------------------------------------------
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