machine: rename CPU_FREQUENCY -> CPUFrequency()

These all-caps constants aren't in the Go style, so rename it to
CPUFrequency (which is more aligned with Go style). Additionally, make
it a function so that it is possible to add support for changing the
frequency in the future.

Tested by running `make smoketest`. None of the outputs did change.
This commit is contained in:
Ayke van Laethem
2019-12-16 19:59:30 +01:00
committed by Ron Evans
parent 2778377ac9
commit 768c652468
13 changed files with 41 additions and 21 deletions
+6 -4
View File
@@ -10,7 +10,9 @@ import (
"errors"
)
const CPU_FREQUENCY = 72000000
func CPUFrequency() uint32 {
return 72000000
}
const (
PinInput PinMode = 0 // Input mode
@@ -163,10 +165,10 @@ func (uart UART) SetBaudRate(br uint32) {
var divider uint32
if uart.Bus == stm32.USART1 {
// first divide by PCLK2 prescaler (div 1) and then desired baudrate
divider = CPU_FREQUENCY / br
divider = CPUFrequency() / br
} else {
// first divide by PCLK1 prescaler (div 2) and then desired baudrate
divider = CPU_FREQUENCY / 2 / br
divider = CPUFrequency() / 2 / br
}
uart.Bus.BRR.Set(divider)
}
@@ -360,7 +362,7 @@ func (i2c I2C) Configure(config I2CConfig) {
i2c.Bus.CR1.ClearBits(stm32.I2C_CR1_PE)
// pclk1 clock speed is main frequency divided by PCLK1 prescaler (div 2)
pclk1 := uint32(CPU_FREQUENCY / 2)
pclk1 := CPUFrequency() / 2
// set freqency range to PCLK1 clock speed in MHz
// aka setting the value 36 means to use 36 MHz clock