Skip to content

Commit

Permalink
Memory alignment issue (#54)
Browse files Browse the repository at this point in the history
Co-authored-by: Benjamin <>
  • Loading branch information
bezineb5 authored Jun 3, 2024
1 parent f673315 commit a7af541
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bcm283x/timer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package bcm283x

import (
"sync/atomic"
"time"

"periph.io/x/host/v3/cpu"
Expand All @@ -17,7 +18,10 @@ func ReadTime() time.Duration {
if drvDMA.timerMemory == nil {
return 0
}
return (time.Duration(drvDMA.timerMemory.high)<<32 | time.Duration(drvDMA.timerMemory.low)) * time.Microsecond
// Use atomic package to safely access memory
high := atomic.LoadUint32(&drvDMA.timerMemory.high)
low := atomic.LoadUint32(&drvDMA.timerMemory.low)
return (time.Duration(high)<<32 | time.Duration(low)) * time.Microsecond
}

// Nanospin spins the CPU without calling into the kernel code if possible.
Expand Down

0 comments on commit a7af541

Please sign in to comment.