Acia Tx return nothing when there is no new data

This commit is contained in:
Ariejan de Vroom 2014-08-21 10:02:04 +02:00
parent f934c5cdf6
commit 3747d8ce41
2 changed files with 20 additions and 4 deletions

View File

@ -95,10 +95,14 @@ func (a *Acia6551) statusRegister() byte {
// Implements io.Reader, for external programs to read TX'ed data from
// the serial output.
func (a *Acia6551) Read(p []byte) (n int, err error) {
a.txEmpty = true
copy(p, []byte{a.tx})
// TODO: Handle txInterrupt
return 1, nil
if a.txEmpty {
return 0, nil
} else {
a.txEmpty = true
copy(p, []byte{a.tx})
// TODO: Handle txInterrupt
return 1, nil
}
}
// Implements io.Writer, for external programs to write to the

View File

@ -36,6 +36,18 @@ func TestAciaReset(t *testing.T) {
assert.Equal(t, 0, a.controlData)
}
func TestAciaReaderWithTxEmpty(t *testing.T) {
a := AciaSubject()
// Nothing to read
assert.True(t, a.txEmpty)
value := make([]byte, 1)
bytesRead, _ := a.Read(value)
assert.Equal(t, 0, bytesRead)
}
func TestAciaWriteByteAndReader(t *testing.T) {
a := AciaSubject()