1// This is a hacky workaround for the fact that the HiFive1 FTDI chip 2// doesn't do hardware flow control and the UART0 interrupt handler 3// takes an eternity to complete since it does CoAP message handling. 4package main 5 6import ( 7 "io" 8 "time" 9)1011const (12 pause = 1 * time.Second13 fifoDepth = 814)1516type SlowWriter struct {17 w io.Writer18}1920func NewSlowWriter(w io.Writer) SlowWriter {21 return SlowWriter{w: w}22}2324func (w SlowWriter) Write(p []byte) (int, error) {25 var n int26 for i, c := range p {27 if i != 0 && i%fifoDepth == 0 {28 time.Sleep(pause)29 }3031 written, err := w.w.Write([]byte{c})32 if err != nil {33 return n, err34 }3536 n += written37 }3839 return n, nil40}