On 10/11/2013 11:50 PM, Karl P wrote:
>> >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;
> To my (simple) mind, it's the advantage for someone coming new to some
> application code and seeing "rcc_peripheral_enable_clock" and thinking, "Ok,
> this turns on a clock" and then briefly looking at some (not pretty) #defines
> and going, "right, USB, I'll just assume those other bits are right, because
> this code is working, now I know what this line of code does"
I agree with you. And this opens possibility to something better:
Maybe rcc_peripheral_enable_clock function could check incoming
parameters and verify they are correct. This could be done only if DEBUG
is defined, so there is no extra overhead. In case of error, function
could call some user overridable function that allows user to print
error on console, or what ever he/she wishes to do with it.
I think part of the problem is also documentation. There are some
functions that are hard to use because documentation and source code
both fail to tell what parameter value should be. Take for example
STM32F1xx->USART->usart_set_stopbits. Document says:
"USART Set Stop Bit(s).
The stop bits are specified as 0.5, 1, 1.5 or 2.
Parameters
[in] usart unsigned 32 bit. USART block register address base
usart_reg_base
[in] stopbits unsigned 32 bit. Stop bits usart_cr2_stopbits.
"
Function is:
"
107 void usart_set_stopbits(uint32_t usart, uint32_t stopbits)
108 {
109 uint32_t reg32;
110
111 reg32 = USART_CR2(usart);
112 reg32 = (reg32 & ~USART_CR2_STOPBITS_MASK) | stopbits;
113 USART_CR2(usart) = reg32;
114 }
"
So there is no way of knowing what should be inside stopbits variable.
------------------------------------------------------------------------------
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