Documentation
¶
Overview ¶
Package uart provides access to the registers of UART peripheral. It also provides the driver that implements io.ReadWriter interface.
Index ¶
- type Baudrate
- type Config
- type Driver
- func (d *Driver) Disable()
- func (d *Driver) DisableRx() (rxbuf []byte)
- func (d *Driver) Enable()
- func (d *Driver) EnableRx(rxbuf []byte)
- func (d *Driver) IRQ() rtos.IRQ
- func (d *Driver) ISR()
- func (d *Driver) Len() int
- func (d *Driver) Periph() *Periph
- func (d *Driver) Read(p []byte) (n int, err error)
- func (d *Driver) ReadByte() (b byte, err error)
- func (d *Driver) SetBaudrate(br Baudrate)
- func (d *Driver) SetConfig(cfg Config)
- func (d *Driver) SetReadTimeout(timeout time.Duration)
- func (d *Driver) SetWriteTimeout(timeout time.Duration)
- func (d *Driver) UsePin(pin gpio.Pin, s Signal)
- func (d *Driver) Write(p []byte) (int, error)
- func (d *Driver) WriteByte(b byte) (err error)
- func (d *Driver) WriteString(s string) (n int, err error)
- type DriverError
- type ErrorBits
- type Event
- type Periph
- func (p *Periph) ClearERRORSRC(e ErrorBits)
- func (p *Periph) Event(e Event) *te.Event
- func (p *Periph) LoadBAUDRATE() Baudrate
- func (p *Periph) LoadCONFIG() Config
- func (p *Periph) LoadENABLE() bool
- func (p *Periph) LoadERRORSRC() ErrorBits
- func (p *Periph) LoadPSEL(s Signal) (psel gpio.PSEL, en bool)
- func (p *Periph) LoadRXD() byte
- func (p *Periph) LoadSHORTS() Shorts
- func (p *Periph) StoreBAUDRATE(br Baudrate)
- func (p *Periph) StoreCONFIG(cfg Config)
- func (p *Periph) StoreENABLE(en bool)
- func (p *Periph) StorePSEL(s Signal, psel gpio.PSEL, en bool)
- func (p *Periph) StoreSHORTS(s Shorts)
- func (p *Periph) StoreTXD(b byte)
- func (p *Periph) Task(t Task) *te.Task
- type Shorts
- type Signal
- type Task
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Baudrate ¶
type Baudrate uint32
const ( Baud1200 Baudrate = 0x0004F000 // Actual rate: 1205 baud. Baud2400 Baudrate = 0x0009D000 // Actual rate: 2396 baud. Baud4800 Baudrate = 0x0013B000 // Actual rate: 4808 baud. Baud9600 Baudrate = 0x00275000 // Actual rate: 9598 baud. Baud14400 Baudrate = 0x003B0000 // Actual rate: 14414 baud. Baud19200 Baudrate = 0x004EA000 // Actual rate: 19208 baud. Baud28800 Baudrate = 0x0075F000 // Actual rate: 28829 baud. Baud31250 Baudrate = 0x00800000 Baud38400 Baudrate = 0x009D5000 // Actual rate: 38462 baud. Baud56000 Baudrate = 0x00E50000 // Actual rate: 55944 baud. Baud57600 Baudrate = 0x00EBF000 // Actual rate: 57762 baud. Baud76800 Baudrate = 0x013A9000 // Actual rate: 76923 baud. Baud115200 Baudrate = 0x01D7E000 // Actual rate: 115942 baud. Baud230400 Baudrate = 0x03AFB000 // Actual rate: 231884 baud. Baud250000 Baudrate = 0x04000000 Baud460800 Baudrate = 0x075F7000 // Actual rate: 470588 baud. Baud921600 Baudrate = 0x0EBED000 // Actual rate: 941176 baud. Baud1M Baudrate = 0x10000000 )
type Driver ¶
type Driver struct {
// contains filtered or unexported fields
}
Driver is an interrupt based driver for UART peripheral. It is optimized for error free links (it is fast and efficient but has some limitations when it comes to reporting Rx errors).
Reading from UART you may encounter errors detected by the hardware (there is no hardware error detection on writing). This driver treats all Rx hardware errors as asynchronous events but at least the ErrOverrun is in fact synchronous. So the Rx errors other than ErrTimeout are simply imformative about the connection quallity or the reading performance. You cannot determine which data has been affected (use other techniques to ensure data integrity.
Set the read timeout to ensure wake-up in case of missing data. The hardware may not detect some Rx errors or the error can be signaled before you try to read affected data because of the hardware and software buffering. This means that the reader can not rely on waking up in case of Rx error. Consider also that the remote party can reset unexpectedly and depending on the protocol used it can be quiet waiting for data request or initialization sequence.
The write operation can block only if the hardware flow control is enabled. In this case you can use write timeout to detect problems with the remote party or RTS/CTS signaling.
The driver supports one reading goroutine and one writing goroutine that both can work concurrently with the driver.
func (*Driver) DisableRx ¶
DisableRx disables the UART receiver. The receive buffer is returned and no longer referenced by driver. You can use the STOPRX and STARTRX tasks directly if you want to temporary disable the receiver leaving the driver intact.
func (*Driver) EnableRx ¶
EnableRx enables the UART receiver. If rxbuf is not nil the Driver uses the provided slice to buffer received data. Othewrise it allocates a small buffer itself. At least 2-byte buffer is required, which is effectively one byte buffer because the other byte always remains unused for efficient checking of an empty state. You cannot rely on 6-byte hardware buffer as extension of the software buffer because for the performance reasons the ISR will not return until it has read all bytes from hardware. If the software buffer is full the ISR simply drops read bytes until there is no more data to read. EnableRx panics if the receiving is already enabled or rxbuf is too short.
func (*Driver) IRQ ¶ added in v0.1.2
IRQ returns the interrupt assigned to UART peripheral used by driver.
func (*Driver) ISR ¶
func (d *Driver) ISR()
ISR handles UART interrupts. It supports the reading thread to run in parallel on another CPU.
func (*Driver) Read ¶
Read reads up to len(p) bytes into p. It returns number of bytes read and an error if detected. Read blocks only if the internal buffer is empty (d.Len() > 0 ensure non-blocking read).
func (*Driver) ReadByte ¶
ReadByte reads one byte and returns error if detected. ReadByte blocks only if the internal buffer is empty (d.Len() > 0 ensure non-blocking read).
func (*Driver) SetBaudrate ¶ added in v0.1.2
SetBaudrate sets Tx and Rx baudrate.
func (*Driver) SetConfig ¶ added in v0.1.2
SetConfig allows to configure UART peripheral to use hardware flow controll, add and check parity bit, and use two stop bits instead default one.
func (*Driver) SetReadTimeout ¶ added in v0.1.2
SetReadTimeout sets the read timeout used by Read* functions.
func (*Driver) SetWriteTimeout ¶ added in v0.1.2
SetWriteTimeout sets the write timeout used by Write* functions.
func (*Driver) Write ¶
Write sends bytes from p to the remote party. It return the number of bytes sent and error if detected. It does not provide any guarantee that the bytes sent were received by the remote party.
type DriverError ¶
type DriverError uint8
const ( // ErrBufOverflow is returned if one or more received bytes has been dropped // because of the lack of free space in the driver's receive buffer. ErrBufOverflow DriverError = iota + 1 // ErrTimeout is returned if timeout occured. It means that the read/write // operation has been interrupted. In case of write you can not determine // the exact number of bytes sent to the remote party. ErrTimeout )
type ErrorBits ¶ added in v0.1.2
type ErrorBits uint8
ErrorBits is a bitfield that lists detected errors.
type Periph ¶
func (*Periph) ClearERRORSRC ¶
ClearERRORSRC clears specfied error flags.
func (*Periph) LoadBAUDRATE ¶
LoadBAUDRATE returns configured baudrate.
func (*Periph) LoadCONFIG ¶ added in v0.1.2
LoadCONFIG returns configuration. nRF52.
func (*Periph) LoadENABLE ¶
LoadENABLE reports whether the UART peripheral is enabled.
func (*Periph) LoadERRORSRC ¶
LoadERRORSRC returns error flags.
func (*Periph) LoadSHORTS ¶
func (*Periph) StoreBAUDRATE ¶
StoreBAUDRATE stores baudrate.
func (*Periph) StoreCONFIG ¶ added in v0.1.2
StoreCONFIG stores baudrate. nRF52.
func (*Periph) StoreENABLE ¶
StoreENABLE enables or disables UART peripheral.