machine/samd21: correct calculation for runtime ticks() function so that go routine scheduling can function as expected as described in issue #149
Signed-off-by: Ron Evans <ron@hybridgroup.com>
Этот коммит содержится в:
родитель
acaf096586
коммит
7f027ddd33
1 изменённых файлов: 4 добавлений и 8 удалений
|
@ -205,11 +205,7 @@ func initRTC() {
|
||||||
|
|
||||||
// set Mode0 to 32-bit counter (mode 0) with prescaler 1 and GCLK2 is 32KHz/1
|
// set Mode0 to 32-bit counter (mode 0) with prescaler 1 and GCLK2 is 32KHz/1
|
||||||
sam.RTC_MODE0.CTRL = sam.RegValue16((sam.RTC_MODE0_CTRL_MODE_COUNT32 << sam.RTC_MODE0_CTRL_MODE_Pos) |
|
sam.RTC_MODE0.CTRL = sam.RegValue16((sam.RTC_MODE0_CTRL_MODE_COUNT32 << sam.RTC_MODE0_CTRL_MODE_Pos) |
|
||||||
(sam.RTC_MODE0_CTRL_PRESCALER_DIV1 << sam.RTC_MODE0_CTRL_PRESCALER_Pos) |
|
(sam.RTC_MODE0_CTRL_PRESCALER_DIV1 << sam.RTC_MODE0_CTRL_PRESCALER_Pos))
|
||||||
sam.RTC_MODE0_CTRL_MATCHCLR)
|
|
||||||
waitForSync()
|
|
||||||
|
|
||||||
sam.RTC_MODE0.COMP0 = 0xffffffff
|
|
||||||
waitForSync()
|
waitForSync()
|
||||||
|
|
||||||
// re-enable RTC
|
// re-enable RTC
|
||||||
|
@ -256,7 +252,7 @@ func ticks() timeUnit {
|
||||||
sam.RTC_MODE0.READREQ = sam.RTC_MODE0_READREQ_RREQ
|
sam.RTC_MODE0.READREQ = sam.RTC_MODE0_READREQ_RREQ
|
||||||
waitForSync()
|
waitForSync()
|
||||||
|
|
||||||
rtcCounter := uint64(sam.RTC_MODE0.COUNT) * 30 // each counter tick == 30.5us
|
rtcCounter := (uint64(sam.RTC_MODE0.COUNT) * 305) / 10 // each counter tick == 30.5us
|
||||||
offset := (rtcCounter - timerLastCounter) // change since last measurement
|
offset := (rtcCounter - timerLastCounter) // change since last measurement
|
||||||
timerLastCounter = rtcCounter
|
timerLastCounter = rtcCounter
|
||||||
timestamp += timeUnit(offset) // TODO: not precise
|
timestamp += timeUnit(offset) // TODO: not precise
|
||||||
|
@ -277,7 +273,7 @@ func timerSleep(ticks uint32) {
|
||||||
|
|
||||||
// set compare value
|
// set compare value
|
||||||
cnt := sam.RTC_MODE0.COUNT
|
cnt := sam.RTC_MODE0.COUNT
|
||||||
sam.RTC_MODE0.COMP0 = sam.RegValue(uint32(cnt) + (ticks / 30)) // each counter tick == 30.5us
|
sam.RTC_MODE0.COMP0 = sam.RegValue(uint32(cnt) + (ticks * 10 / 305)) // each counter tick == 30.5us
|
||||||
waitForSync()
|
waitForSync()
|
||||||
|
|
||||||
// enable IRQ for CMP0 compare
|
// enable IRQ for CMP0 compare
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче