uart

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 21, 2025 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FE uint32 = 0x01 << 0 //+ Framing error.
	PE uint32 = 0x01 << 1 //+ Parity error.
	BE uint32 = 0x01 << 2 //+ Break error.
	OE uint32 = 0x01 << 3 //+ Overrun error.
)

RSR bits

View Source
const (
	TXIFLSEL = 0x07 << 0 //+ Transmit interrupt FIFO level select.
	RXIFLSEL = 0x07 << 3 //+ Receive interrupt FIFO level select
)

IFLS bits

View Source
const (
	TXIFLSELn = 0
	RXIFLSELn = 3
)

IFLS bit offsets

View Source
const (
	Break      = Config(BRK)       // send break
	ParityEven = Config(PEN | EPS) // even parity
	ParityOdd  = Config(PEN)       // odd parity
	Stop2b     = Config(STP2)      // two stop bits instead of one

	WordLen = Config(3 << WLENn) // Data word length:
	Word5b  = Config(0 << WLENn) // - 5 bit
	Word6b  = Config(1 << WLENn) // - 6 bit
	Word7b  = Config(2 << WLENn) // - 7 bit
	Word8b  = Config(3 << WLENn) // - 8 bit
)
View Source
const WLENn = 5

LCR_H bit ofsets

Variables

View Source
var ErrTimeout = errors.New("uart: timeout")

Functions

This section is empty.

Types

type CR

type CR uint32
const (
	UARTEN CR = 0x01 << 0  //+ UART enable.
	SIREN  CR = 0x01 << 1  //+ SIR enable.
	SIRLP  CR = 0x01 << 2  //+ SIR low-power IrDA mode.
	LBE    CR = 0x01 << 7  //+ Loopback enable.
	TXE    CR = 0x01 << 8  //+ Transmit enable.
	RXE    CR = 0x01 << 9  //+ Receive enable.
	DTRn   CR = 0x01 << 10 //+ Data transmit ready.
	RTSn   CR = 0x01 << 11 //+ Request to send.
	OUT1   CR = 0x01 << 12 //+ Complement of the UART Out1 modem status output.
	OUT2   CR = 0x01 << 13 //+ Complement of the UART Out2 modem status output
	RTSEN  CR = 0x01 << 14 //+ RTS hardware flow control enable.
	CTSEN  CR = 0x01 << 15 //+ CTS hardware flow control enable.
)

CR bits

type Config

type Config uint32

type DMACR

type DMACR uint32
const (
	RXDMAE   DMACR = 0x01 << 0 //+ Receive DMA enable.
	TXDMAE   DMACR = 0x01 << 1 //+ Transmit DMA enable.
	DMAONERR DMACR = 0x01 << 2 //+ DMA on error.
)

DMACR bits

type Driver

type Driver struct {
	// contains filtered or unexported fields
}

Driver provides a driver for the UART peripheral.

The driver Rx and Tx parts are independent in means that they can be used conncurently by two goroutines. However, a given transmission direction can only be used by one goroutine at the same time.

func NewDriver

func NewDriver(p *Periph) *Driver

NewDriver returns a new driver for p.

func (*Driver) Baudrate

func (d *Driver) Baudrate() int

func (*Driver) Config

func (d *Driver) Config() Config

func (*Driver) Disable

func (d *Driver) Disable()

func (*Driver) DisableRx

func (d *Driver) DisableRx()

func (*Driver) DisableTx

func (d *Driver) DisableTx()

DisableTx waits for the end of transfer (see WaitTxDone) and disables the Tx part of the UART.

func (*Driver) Enable

func (d *Driver) Enable()

func (*Driver) EnableRx

func (d *Driver) EnableRx()

func (*Driver) EnableTx

func (d *Driver) EnableTx()

EnableTx enables the Tx part of the UART.

func (*Driver) ISR

func (d *Driver) ISR()

ISR is the interrupt handler that handles the data transfers scheduled by the read and write methods.

func (*Driver) Periph

func (d *Driver) Periph() *Periph

Periph returns the underlying UART peripheral.

func (*Driver) Read

func (d *Driver) Read(s []byte) (n int, err error)

func (*Driver) ReadByte

func (d *Driver) ReadByte() (b byte, err error)

func (*Driver) SetBaudrate

func (d *Driver) SetBaudrate(baudrate int) (actual int)

SetBaudrate sets the UART baudrate.

func (*Driver) SetConfig

func (d *Driver) SetConfig(cfg Config)

SetConfig sets the URAT configuration.

func (*Driver) SetReadTimeout

func (d *Driver) SetReadTimeout(timeout time.Duration)

SetReadTimeout sets the read timeout used by Read* functions.

func (*Driver) SetWriteTimeout

func (d *Driver) SetWriteTimeout(timeout time.Duration)

SetWriteTimeout sets the write timeout used by Write* functions.

func (*Driver) Setup

func (d *Driver) Setup(cfg Config, baudrate int) (actualBaud int)

Setup resets the underlying UART peripheral and configures it according to the driver needs. Next it calls the SetConfig and SetBaudrate methods with the provided arguments. You still need to call EnableTx/EnabeRx.

func (*Driver) UsePin

func (d *Driver) UsePin(pin iomux.Pin, sig Signal) bool

UsePin is a helper function that can be used to configure IO pins as required by the UART peripheral. Only certain pins can be used (see datasheet). UsePin returns true on succes or false if it isn't possible to use a pin as a sig. See also Periph.Pins.

func (*Driver) WaitTxDone

func (d *Driver) WaitTxDone()

WaitTxDone waits until the last byte (including all the stop bits) from the last write operation has been sent. Be aware that your program may not be fast enough to perform a time critital action after this function returns. Use it only to avoid distrubing your own UART transmision by the following actions in program order. For example, disabling the RS485 output driver just after returning from WaitTxDone may be done too late because of the other gorutines or interrupt handlers so the slave device may start sending a response on the bus that is still connected to your RS485 driver (use PIO or a hardware solution instaed).

func (*Driver) Write

func (d *Driver) Write(s []byte) (n int, err error)

func (*Driver) WriteByte

func (d *Driver) WriteByte(b byte) error

func (*Driver) WriteString

func (d *Driver) WriteString(s string) (n int, err error)

type Error

type Error struct {
	// contains filtered or unexported fields
}

func (*Error) Error

func (e *Error) Error() string

func (*Error) Status

func (e *Error) Status() uint32

Status return the error flags as in the RSR register (see FE, PE, BE, OE).

type FR

type FR uint32
const (
	CTSn FR = 0x01 << 0 //+ Clear to send.
	DSRn FR = 0x01 << 1 //+ Data set ready.
	DCDn FR = 0x01 << 2 //+ Data carrier detect.
	BUSY FR = 0x01 << 3 //+ UART busy.
	RXFE FR = 0x01 << 4 //+ Receive FIFO empty.
	TXFF FR = 0x01 << 5 //+ Transmit FIFO full.
	RXFF FR = 0x01 << 6 //+ Receive FIFO full.
	TXFE FR = 0x01 << 7 //+ Transmit FIFO empty.
	RI   FR = 0x01 << 8 //+ Ring indicator.
)

FR bits

type INT

type INT uint32
const (
	RIMI  INT = 0x01 << 0  //+ nUARTRI modem interrupt.
	CTSMI INT = 0x01 << 1  //+ nUARTCTS modem interrupt.
	DCDMI INT = 0x01 << 2  //+ nUARTDCD modem interrupt.
	DSRMI INT = 0x01 << 3  //+ nUARTDSR modem interrupt.
	RXI   INT = 0x01 << 4  //+ Receive interrupt.
	TXI   INT = 0x01 << 5  //+ Transmit interrupt.
	RTI   INT = 0x01 << 6  //+ Receive timeout interrupt.
	FEI   INT = 0x01 << 7  //+ Framing error interrupt.
	PEI   INT = 0x01 << 8  //+ Parity error interrupt.
	BEI   INT = 0x01 << 9  //+ Break error interrupt.
	OEI   INT = 0x01 << 10 //+ Overrun error interrupt.
)

type LCR_H

type LCR_H uint32
const (
	BRK  LCR_H = 0x01 << 0 //+ Send break.
	PEN  LCR_H = 0x01 << 1 //+ Parity enable.
	EPS  LCR_H = 0x01 << 2 //+ Even parity select.
	STP2 LCR_H = 0x01 << 3 //+ Two stop bits select.
	FEN  LCR_H = 0x01 << 4 //+ Enable FIFOs.
	WLEN LCR_H = 0x03 << 5 //+ Word length.
	SPS  LCR_H = 0x01 << 7 //+ Stick parity select.
)

LCR_H bits

type Periph

type Periph struct {
	DR  mmio.U32
	RSR mmio.U32

	FR mmio.R32[FR]

	ILPR  mmio.U32
	IBRD  mmio.U32
	FBRD  mmio.U32
	LCR_H mmio.R32[LCR_H]
	CR    mmio.R32[CR]
	IFLS  mmio.U32
	IMSC  mmio.R32[INT]
	RIS   mmio.R32[INT]
	MIS   mmio.R32[INT]
	ICR   mmio.R32[INT]
	DMACR mmio.R32[DMACR]

	PERIPHID0 mmio.U32
	PERIPHID1 mmio.U32
	PERIPHID2 mmio.U32
	PERIPHID3 mmio.U32
	PCELLID0  mmio.U32
	PCELLID1  mmio.U32
	PCELLID2  mmio.U32
	PCELLID3  mmio.U32
	// contains filtered or unexported fields
}

func UART

func UART(n int) *Periph

UART returns the UART peripheral.

func (*Periph) Pins

func (p *Periph) Pins(sig Signal) []iomux.Pin

Pins returns the IO pins that can be used for the singal sig.

func (*Periph) SetReset

func (p *Periph) SetReset(assert bool)

SetReset allows to assert/deassert the reset signal to the UART peripheral.

type Signal

type Signal int8
const (
	TXD Signal = iota
	RXD
	CTS
	RTS
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL