Skip to content

Commit 2168b1b

Browse files
deadprogramaykevl
authored andcommitted
machine/hifive1: add GPIO Get() implementation and update other implementation to match latest SVD wrappers
Signed-off-by: Ron Evans <[email protected]>
1 parent 92e07ec commit 2168b1b

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

src/machine/board_hifive1b.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,29 @@
22

33
package machine
44

5+
const (
6+
D0 = P16
7+
D1 = P17
8+
D2 = P18
9+
D3 = P19 // Green LED/PWM
10+
D4 = P20 // PWM
11+
D5 = P21 // Blue LED/PWM
12+
D6 = P22 // Red LED/PWM
13+
D7 = P16
14+
D8 = NoPin // PWM?
15+
D9 = P01
16+
D10 = P02
17+
D11 = P03
18+
D12 = P04
19+
D13 = P05
20+
D14 = NoPin // not connected
21+
D15 = P09 // does not seem to work?
22+
D16 = P10 // PWM
23+
D17 = P11 // PWM
24+
D18 = P12 // SDA/PWM
25+
D19 = P13 // SDL/PWM
26+
)
27+
528
const (
629
LED = LED1
730
LED1 = LED_RED

src/machine/machine_fe310.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ func (p Pin) Set(high bool) {
3030
}
3131
}
3232

33+
// Get returns the current value of a GPIO pin.
34+
func (p Pin) Get() bool {
35+
val := sifive.GPIO0.VALUE.Get() & (1 << uint8(p))
36+
println(sifive.GPIO0.VALUE.Get())
37+
return (val > 0)
38+
}
39+
3340
type UART struct {
3441
Bus *sifive.UART_Type
3542
Buffer *RingBuffer

src/runtime/runtime_fe310.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ func init() {
4747

4848
func pric_init() {
4949
// Make sure the HFROSC is on
50-
sifive.PRIC.HFROSCCFG.SetBits(sifive.PRIC_HFROSCCFG_ENABLE)
50+
sifive.PRCI.HFROSCCFG.SetBits(sifive.PRCI_HFROSCCFG_ENABLE)
5151

5252
// Run off 16 MHz Crystal for accuracy.
53-
sifive.PRIC.PLLCFG.SetBits(sifive.PRIC_PLLCFG_REFSEL | sifive.PRIC_PLLCFG_BYPASS)
54-
sifive.PRIC.PLLCFG.SetBits(sifive.PRIC_PLLCFG_SEL)
53+
sifive.PRCI.PLLCFG.SetBits(sifive.PRCI_PLLCFG_REFSEL | sifive.PRCI_PLLCFG_BYPASS)
54+
sifive.PRCI.PLLCFG.SetBits(sifive.PRCI_PLLCFG_SEL)
5555

5656
// Turn off HFROSC to save power
57-
sifive.PRIC.HFROSCCFG.ClearBits(sifive.PRIC_HFROSCCFG_ENABLE)
57+
sifive.PRCI.HFROSCCFG.ClearBits(sifive.PRCI_HFROSCCFG_ENABLE)
5858

5959
// Enable the RTC.
60-
sifive.RTC.CONFIG.Set(sifive.RTC_CONFIG_ENALWAYS)
60+
sifive.RTC.RTCCFG.Set(sifive.RTC_RTCCFG_ENALWAYS)
6161
}
6262

6363
func preinit() {
@@ -85,10 +85,10 @@ func putchar(c byte) {
8585
func ticks() timeUnit {
8686
// Combining the low bits and the high bits yields a time span of over 270
8787
// years without counter rollover.
88-
highBits := sifive.RTC.HI.Get()
88+
highBits := sifive.RTC.RTCHI.Get()
8989
for {
90-
lowBits := sifive.RTC.LO.Get()
91-
newHighBits := sifive.RTC.HI.Get()
90+
lowBits := sifive.RTC.RTCLO.Get()
91+
newHighBits := sifive.RTC.RTCHI.Get()
9292
if newHighBits == highBits {
9393
// High bits stayed the same.
9494
return timeUnit(lowBits) | (timeUnit(highBits) << 32)

0 commit comments

Comments
 (0)