machine/hifive1: add GPIO Get() implementation and update other implementation to match latest SVD wrappers
Signed-off-by: Ron Evans <ron@hybridgroup.com>
Этот коммит содержится в:
родитель
92e07ec8af
коммит
2168b1b516
3 изменённых файлов: 38 добавлений и 8 удалений
|
@ -2,6 +2,29 @@
|
||||||
|
|
||||||
package machine
|
package machine
|
||||||
|
|
||||||
|
const (
|
||||||
|
D0 = P16
|
||||||
|
D1 = P17
|
||||||
|
D2 = P18
|
||||||
|
D3 = P19 // Green LED/PWM
|
||||||
|
D4 = P20 // PWM
|
||||||
|
D5 = P21 // Blue LED/PWM
|
||||||
|
D6 = P22 // Red LED/PWM
|
||||||
|
D7 = P16
|
||||||
|
D8 = NoPin // PWM?
|
||||||
|
D9 = P01
|
||||||
|
D10 = P02
|
||||||
|
D11 = P03
|
||||||
|
D12 = P04
|
||||||
|
D13 = P05
|
||||||
|
D14 = NoPin // not connected
|
||||||
|
D15 = P09 // does not seem to work?
|
||||||
|
D16 = P10 // PWM
|
||||||
|
D17 = P11 // PWM
|
||||||
|
D18 = P12 // SDA/PWM
|
||||||
|
D19 = P13 // SDL/PWM
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
LED = LED1
|
LED = LED1
|
||||||
LED1 = LED_RED
|
LED1 = LED_RED
|
||||||
|
|
|
@ -30,6 +30,13 @@ func (p Pin) Set(high bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get returns the current value of a GPIO pin.
|
||||||
|
func (p Pin) Get() bool {
|
||||||
|
val := sifive.GPIO0.VALUE.Get() & (1 << uint8(p))
|
||||||
|
println(sifive.GPIO0.VALUE.Get())
|
||||||
|
return (val > 0)
|
||||||
|
}
|
||||||
|
|
||||||
type UART struct {
|
type UART struct {
|
||||||
Bus *sifive.UART_Type
|
Bus *sifive.UART_Type
|
||||||
Buffer *RingBuffer
|
Buffer *RingBuffer
|
||||||
|
|
|
@ -47,17 +47,17 @@ func init() {
|
||||||
|
|
||||||
func pric_init() {
|
func pric_init() {
|
||||||
// Make sure the HFROSC is on
|
// Make sure the HFROSC is on
|
||||||
sifive.PRIC.HFROSCCFG.SetBits(sifive.PRIC_HFROSCCFG_ENABLE)
|
sifive.PRCI.HFROSCCFG.SetBits(sifive.PRCI_HFROSCCFG_ENABLE)
|
||||||
|
|
||||||
// Run off 16 MHz Crystal for accuracy.
|
// Run off 16 MHz Crystal for accuracy.
|
||||||
sifive.PRIC.PLLCFG.SetBits(sifive.PRIC_PLLCFG_REFSEL | sifive.PRIC_PLLCFG_BYPASS)
|
sifive.PRCI.PLLCFG.SetBits(sifive.PRCI_PLLCFG_REFSEL | sifive.PRCI_PLLCFG_BYPASS)
|
||||||
sifive.PRIC.PLLCFG.SetBits(sifive.PRIC_PLLCFG_SEL)
|
sifive.PRCI.PLLCFG.SetBits(sifive.PRCI_PLLCFG_SEL)
|
||||||
|
|
||||||
// Turn off HFROSC to save power
|
// Turn off HFROSC to save power
|
||||||
sifive.PRIC.HFROSCCFG.ClearBits(sifive.PRIC_HFROSCCFG_ENABLE)
|
sifive.PRCI.HFROSCCFG.ClearBits(sifive.PRCI_HFROSCCFG_ENABLE)
|
||||||
|
|
||||||
// Enable the RTC.
|
// Enable the RTC.
|
||||||
sifive.RTC.CONFIG.Set(sifive.RTC_CONFIG_ENALWAYS)
|
sifive.RTC.RTCCFG.Set(sifive.RTC_RTCCFG_ENALWAYS)
|
||||||
}
|
}
|
||||||
|
|
||||||
func preinit() {
|
func preinit() {
|
||||||
|
@ -85,10 +85,10 @@ func putchar(c byte) {
|
||||||
func ticks() timeUnit {
|
func ticks() timeUnit {
|
||||||
// Combining the low bits and the high bits yields a time span of over 270
|
// Combining the low bits and the high bits yields a time span of over 270
|
||||||
// years without counter rollover.
|
// years without counter rollover.
|
||||||
highBits := sifive.RTC.HI.Get()
|
highBits := sifive.RTC.RTCHI.Get()
|
||||||
for {
|
for {
|
||||||
lowBits := sifive.RTC.LO.Get()
|
lowBits := sifive.RTC.RTCLO.Get()
|
||||||
newHighBits := sifive.RTC.HI.Get()
|
newHighBits := sifive.RTC.RTCHI.Get()
|
||||||
if newHighBits == highBits {
|
if newHighBits == highBits {
|
||||||
// High bits stayed the same.
|
// High bits stayed the same.
|
||||||
return timeUnit(lowBits) | (timeUnit(highBits) << 32)
|
return timeUnit(lowBits) | (timeUnit(highBits) << 32)
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче