fix: error handling, timeouts
This commit is contained in:
@ -9,8 +9,10 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
adressWriteTimeout = 140 * time.Nanosecond
|
||||
dataStrobeTimeout = 250 * time.Nanosecond // (Data transfer)
|
||||
adressWriteTimeout = 40 * time.Nanosecond
|
||||
dataStrobeTimeout = 160 * time.Nanosecond // (Data transfer)
|
||||
dataReadTimeout = 300 * time.Nanosecond
|
||||
gapTimeout = 2000 * time.Nanosecond
|
||||
maxWaitCycles = 100
|
||||
)
|
||||
|
||||
@ -68,7 +70,20 @@ func (d *device) Reset() {
|
||||
d.PinE.Output()
|
||||
d.PinRES.Output()
|
||||
d.busOutput()
|
||||
d.PinA0.Low()
|
||||
d.PinRW.Low()
|
||||
d.PinE.Low()
|
||||
d.PinDB0.Low()
|
||||
d.PinDB1.Low()
|
||||
d.PinDB2.Low()
|
||||
d.PinDB3.Low()
|
||||
d.PinDB4.Low()
|
||||
d.PinDB5.Low()
|
||||
d.PinDB6.Low()
|
||||
d.PinDB7.Low()
|
||||
d.PinE1.Low()
|
||||
d.PinE2.Low()
|
||||
d.PinRES.High()
|
||||
}
|
||||
|
||||
func (d *device) WriteByte(b byte, cd rpio.State) {
|
||||
@ -78,6 +93,7 @@ func (d *device) WriteByte(b byte, cd rpio.State) {
|
||||
d.PinA0.Write(cd)
|
||||
|
||||
// Write bus
|
||||
d.logger.Printf("Write byte %x\n", b)
|
||||
d.PinDB0.Write(rpio.State((b >> 0) & 1))
|
||||
d.PinDB1.Write(rpio.State((b >> 1) & 1))
|
||||
d.PinDB2.Write(rpio.State((b >> 2) & 1))
|
||||
@ -99,8 +115,8 @@ func (d *device) WriteByte(b byte, cd rpio.State) {
|
||||
func (d *device) WriteBytes(b []byte, cd rpio.State) {
|
||||
// d.logger.Println("Write byte", b, cd, l, r)
|
||||
d.busOutput()
|
||||
d.PinRW.Low() // We write
|
||||
d.PinA0.Write(cd)
|
||||
d.PinRW.Low() // We write
|
||||
|
||||
// Write bus
|
||||
d.PinDB0.Write(rpio.State(b[0]))
|
||||
@ -113,24 +129,26 @@ func (d *device) WriteBytes(b []byte, cd rpio.State) {
|
||||
d.PinDB7.Write(rpio.State(b[7]))
|
||||
|
||||
// Strobe start
|
||||
time.Sleep(adressWriteTimeout)
|
||||
d.PinE.High()
|
||||
time.Sleep(dataStrobeTimeout)
|
||||
|
||||
// Strobe end
|
||||
d.PinE.Low()
|
||||
time.Sleep(time.Millisecond - dataStrobeTimeout - adressWriteTimeout)
|
||||
time.Sleep(gapTimeout - dataStrobeTimeout - adressWriteTimeout)
|
||||
}
|
||||
|
||||
func (d *device) ReadByte(cd rpio.State) byte {
|
||||
// Setup
|
||||
var b byte
|
||||
d.busOutput()
|
||||
d.PinRW.High() // We write
|
||||
d.busInput()
|
||||
d.PinA0.Write(cd)
|
||||
d.PinRW.High() // We read
|
||||
|
||||
// Strobe start
|
||||
time.Sleep(adressWriteTimeout)
|
||||
d.PinE.High()
|
||||
time.Sleep(dataStrobeTimeout)
|
||||
time.Sleep(dataReadTimeout)
|
||||
|
||||
// Read
|
||||
b = uint8(d.PinDB0.Read()) |
|
||||
@ -144,26 +162,26 @@ func (d *device) ReadByte(cd rpio.State) byte {
|
||||
|
||||
// Strobe end
|
||||
d.PinE.Low()
|
||||
time.Sleep(time.Millisecond - dataStrobeTimeout - adressWriteTimeout)
|
||||
time.Sleep(gapTimeout - dataReadTimeout - adressWriteTimeout)
|
||||
return b
|
||||
}
|
||||
|
||||
func (d *device) WaitReady() error {
|
||||
d.busInput() // Set bus to input
|
||||
d.PinRW.High() // We read
|
||||
d.PinA0.Low() // Status
|
||||
d.PinRW.High() // We read
|
||||
time.Sleep(adressWriteTimeout)
|
||||
|
||||
// Strobe start
|
||||
d.PinE.High()
|
||||
time.Sleep(dataStrobeTimeout)
|
||||
time.Sleep(dataReadTimeout)
|
||||
|
||||
// Wait status flag drop
|
||||
ok := false
|
||||
d.busInput() // Set bus to input
|
||||
for counter := 0; counter < maxWaitCycles; counter++ {
|
||||
if d.PinDB7.Read() != rpio.High {
|
||||
//d.logger.Printf("BUS:%d%d%d%d%d%d%d%d\n", d.pinDB0.Read(), d.pinDB1.Read(), d.pinDB2.Read(), d.pinDB3.Read(), d.pinDB4.Read(), d.pinDB5.Read(), d.pinDB6.Read(), d.pinDB7.Read())
|
||||
//d.logger.Printf("BUS:%d%d%d%d%d%d%d%d\n", d.PinDB0.Read(), d.PinDB1.Read(), d.PinDB2.Read(), d.PinDB3.Read(), d.PinDB4.Read(), d.PinDB5.Read(), d.PinDB6.Read(), d.PinDB7.Read())
|
||||
ok = true
|
||||
break
|
||||
}
|
||||
@ -174,12 +192,12 @@ func (d *device) WaitReady() error {
|
||||
|
||||
// Strobe end
|
||||
d.PinE.Low()
|
||||
time.Sleep(time.Millisecond - dataStrobeTimeout - adressWriteTimeout)
|
||||
time.Sleep(gapTimeout - dataReadTimeout - adressWriteTimeout)
|
||||
// d.logger.Println("Ready")
|
||||
return nil
|
||||
}
|
||||
|
||||
// Set bus pins to output
|
||||
// Set bus Pins to output
|
||||
func (d *device) busOutput() {
|
||||
// if d.isBusOutput {
|
||||
// return
|
||||
|
Reference in New Issue
Block a user