teensy40: fix PIT clock, which actually uses 24 MHz OSC

see: https://forum.pjrc.com/threads/63979-What-peripherals-are-affected-by-the-undocumented-24-MHz-OSC-circuit-on-Teensy-4-0
Этот коммит содержится в:
ardnew 2020-10-22 20:58:42 -05:00 коммит произвёл Ron Evans
родитель f93b28057a
коммит 0d9c46b59e
2 изменённых файлов: 8 добавлений и 9 удалений

Просмотреть файл

@ -9,7 +9,7 @@ import (
// Core, bus, and peripheral clock frequencies (Hz)
const (
CORE_FREQ = 600000000 // 600 MHz
OSC_FREQ = 100000 // 100 kHz (see note below)
SYSTICK_FREQ = 100000 // 100 kHz (see note below)
_ // -----------
AHB_FREQ = 600000000 // 600 MHz
CAN_FREQ = 40000000 // 40 MHz
@ -65,7 +65,7 @@ var (
}
)
// Note about OSC_FREQ from Teensyduino (cores/teensy4/startup.c):
// Note about SYSTICK_FREQ from Teensyduino (cores/teensy4/startup.c):
//
// | ARM SysTick is used for most Ardiuno timing functions, delay(), millis(),
// | micros(). SysTick can run from either the ARM core clock, or from an

Просмотреть файл

@ -11,15 +11,14 @@ import (
type timeUnit int64
const (
SYST_FREQ = OSC_FREQ // HW divides 24 MHz XTALOSC down to 100 kHz
lastCycle = SYST_FREQ/1000 - 1
microsPerCycle = 1000000 / SYST_FREQ
const ( // HW divides 24 MHz XTALOSC down to 100 kHz
lastCycle = SYSTICK_FREQ/1000 - 1
microsPerCycle = 1000000 / SYSTICK_FREQ
)
const (
PIT_FREQ = OSC_FREQ // HW divides 24 MHz XTALOSC down to 100 kHz
pitMicrosPerCycle = 1000000 / PIT_FREQ
PIT_FREQ = PERCLK_FREQ
pitCyclesPerMicro = PIT_FREQ / 1000000
pitSleepTimer = 0 // x4 32-bit PIT timers [0..3]
)
@ -88,7 +87,7 @@ func sleepTicks(duration timeUnit) {
curr := ticks()
last := curr + duration
for curr < last {
cycles := timeUnit((last - curr) * pitMicrosPerCycle)
cycles := timeUnit((last - curr) / pitCyclesPerMicro)
if cycles > 0xFFFFFFFF {
cycles = 0xFFFFFFFF
}