-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathall_generate.go
More file actions
99 lines (86 loc) · 2.26 KB
/
all_generate.go
File metadata and controls
99 lines (86 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package piolib
import (
"errors"
"math"
"runtime"
"time"
"unsafe"
pio "github.com/tinygo-org/pio/rp2-pio"
)
const timeoutRetries = math.MaxUint16 * 8
var (
errTimeout = errors.New("piolib:timeout")
errContentionTimeout = errors.New("piolib:contention timeout")
errBusy = errors.New("piolib:busy")
errDMAUnavail = errors.New("piolib:DMA channel unavailable")
)
//go:generate pioasm -o go parallel8.pio parallel8_pio.go
//go:generate pioasm -o go pulsar.pio pulsar_pio.go
//go:generate pioasm -o go spi.pio spi_pio.go
//go:generate pioasm -o go ws2812b.pio ws2812b_pio.go
//go:generate pioasm -o go i2s.pio i2s_pio.go
//go:generate pioasm -o go spi3w.pio spi3w_pio.go
//go:generate pioasm -o go ws2812bfourpixels.pio ws2812bfourpixels_pio.go
func gosched() {
runtime.Gosched()
}
type deadline struct {
t time.Time
}
func (dl deadline) expired() bool {
if dl.t.IsZero() {
return false
}
return time.Since(dl.t) > 0
}
type deadliner struct {
// timeout is a bitshift value for the timeout.
timeout uint8
}
func (ch deadliner) newDeadline() deadline {
var t time.Time
if ch.timeout != 0 {
calc := time.Duration(1 << ch.timeout)
t = time.Now().Add(calc)
}
return deadline{t: t}
}
func (ch *deadliner) setTimeout(timeout time.Duration) {
if timeout <= 0 {
ch.timeout = 0
return // No timeout.
}
for i := uint8(0); i < 64; i++ {
calc := time.Duration(1 << i)
if calc > timeout {
ch.timeout = i
return
}
}
}
// helperPushUntilStall pushes buf data elements into TxReg through DMA if enabled or via [pio.StateMachine.TxPut] if dma disabled.
// It blocks until TxStall flag is set in state machine FDEBUG register. TxStall flag cleared immediately on this function call.
func helperPushUntilStall[T uint8 | uint16 | uint32](sm pio.StateMachine, dma dmaChannel, buf []T) (err error) {
sm.ClearTxStalled()
if dma.helperIsEnabled() {
dreq := dmaPIO_TxDREQ(sm)
err = dmaPush(dma, (*T)(unsafe.Pointer(sm.TxReg())), buf, dreq)
} else {
i := 0
for i < len(buf) {
if sm.IsTxFIFOFull() {
gosched()
continue
}
sm.TxPut(uint32(buf[i]))
i++
}
}
if err != nil {
return err
}
for !sm.HasTxStalled() {
gosched() // Block until empty.
}
return nil
}