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
+2 -2
View File
@@ -140,7 +140,7 @@ func (i2c I2C) Configure(config I2CConfig) {
// SCL Frequency = CPU Clock Frequency / (16 + (2 * TWBR))
// NOTE: TWBR should be 10 or higher for master mode.
// It is 72 for a 16mhz board with 100kHz TWI
avr.TWBR.Set(uint8(((CPU_FREQUENCY / config.Frequency) - 16) / 2))
avr.TWBR.Set(uint8(((CPUFrequency() / config.Frequency) - 16) / 2))
// Enable twi module.
avr.TWCR.Set(avr.TWCR_TWEN)
@@ -235,7 +235,7 @@ func (uart UART) Configure(config UARTConfig) {
// Set baud rate based on prescale formula from
// https://www.microchip.com/webdoc/AVRLibcReferenceManual/FAQ_1faq_wrong_baud_rate.html
// ((F_CPU + UART_BAUD_RATE * 8L) / (UART_BAUD_RATE * 16L) - 1)
ps := ((CPU_FREQUENCY+config.BaudRate*8)/(config.BaudRate*16) - 1)
ps := ((CPUFrequency()+config.BaudRate*8)/(config.BaudRate*16) - 1)
avr.UBRR0H.Set(uint8(ps >> 8))
avr.UBRR0L.Set(uint8(ps & 0xff))