Hi,

I'm using STM32F4 + libopencm3. I have noticed that some of the library
functions are declared to have a pointer to registers as a parameter:

For example, in rcc.h:
void rcc_peripheral_enable_clock(volatile uint32_t *reg, uint32_t en);

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?

A fix to this problem is to wrap the valid register values in an enum and
use the enum as the function parameter. The new declaration of this
function will be:

void rcc_peripheral_enable_clock(clock_enable_reg_t clock_enable_reg,
uint32_t en);

Was this option considered?

Thanks so much!
Linge
------------------------------------------------------------------------------
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
libopencm3-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libopencm3-devel

Reply via email to