dma

package
v0.13.3 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2025 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Overview

Package dma provides uniform interface to the DMA controllers.

Index

Constants

View Source
const CacheMaint = cacheMaint

A CacheMaint indicates whether DMA requires cache maintenance.

View Source
const MemAlign = cacheLineSize

An MemAlign is the prefered memory alignment for DMA operations. It's always power of 2 and defined in such a way that a fully MemAlign aligned (top and bottom) memory region corresponds to the complete data cache lines.

Variables

This section is empty.

Functions

func AlignOffsets added in v0.13.3

func AlignOffsets(ptr unsafe.Pointer, size uintptr) (start, end uintptr)

AlignOffsets calculatest the start and end offsets to the MemAlign aligned portion of the memory described by ptr and size.

func MakeSlice added in v0.13.3

func MakeSlice[T any](len, cap int) (slice []T)

MakeSlice works like make([]T, len, cap) but guarantees that the returned slice has the prefered DMA alignment (see MemAlign).

func New added in v0.13.3

func New[T any]() (ptr *T)

New works like new(T) but guarantees that the allocated variable has the prefered DMA alignment (see MemAlign).

Types

type Channel

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

func (Channel) Clear

func (c Channel) Clear(ev Event, err Error)

Clear clears specified flags.

func (Channel) Disable

func (c Channel) Disable()

Disable disables channel.

func (Channel) DisableIRQ

func (c Channel) DisableIRQ(ev Event, err Error)

DisableIRQ disables IRQs generation by ev, err.

func (Channel) Enable

func (c Channel) Enable()

Enable enables the channel c. All events and errors should be cleared before call this method.

func (Channel) EnableIRQ

func (c Channel) EnableIRQ(ev Event, err Error)

EnableIRQ enables generation of IRQs by ev, err. Documentation does not mention it, but IRQ can be not generated if an event was asserted before enable IRQ for it. So always enable IRQs before channel. Typically, the correct sequence is as follows:

c.Clear(EvAll, ErrAll)
c.EnableIRQ(ev, err)
c.Enable()

func (Channel) Enabled

func (c Channel) Enabled() bool

Returns true if channel is enabled.

func (Channel) IRQEnabled

func (c Channel) IRQEnabled() (Event, Error)

IRQEnabled returns events that are enabled to generate interrupt requests.

func (Channel) Len

func (c Channel) Len() int

Len returns current number of words to transfer.

func (Channel) Prio

func (c Channel) Prio() Prio

func (Channel) SetAddrM

func (c Channel) SetAddrM(a unsafe.Pointer)

SetAddrM sets memory address.

func (Channel) SetAddrP

func (c Channel) SetAddrP(a unsafe.Pointer)

SetAddrP sets peripheral address (or memory source address in case of MTM).

func (Channel) SetLen

func (c Channel) SetLen(n int)

SetLen sets number of words to transfer (n <= 65535).

func (Channel) SetPrio

func (c Channel) SetPrio(prio Prio)

func (Channel) SetWordSize

func (c Channel) SetWordSize(p, m uintptr)

SetWordSize sets the word size (in bytes) for peripheral and memory side of transfer.

func (Channel) Setup

func (c Channel) Setup(m Mode)

Setup configures the DMA channel channel.

func (Channel) Status

func (c Channel) Status() (Event, Error)

Status returns current event and error flags.

func (Channel) WordSize

func (c Channel) WordSize() (p, m uintptr)

WordSize returns the current word size (in bytes) for peripheral and memory side of transfer.

type Controller

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

func DMA

func DMA(n int) *Controller

DMA returns n-th DMA controller. The first controller number is 1.

func (*Controller) Channel

func (d *Controller) Channel(sn, rn int) Channel

Channel returns the value that represents the sn stream (F1/Lx DMA channel) together with the connected to it cn request channel (ignored for F1/Lx). Channels with the same sn points to the same DMA stream so they can't be used at the same time.

func (*Controller) DisableClock

func (d *Controller) DisableClock()

DisableClock disables clock to the DMA controller.

func (*Controller) EnableClock

func (d *Controller) EnableClock(lp bool)

EnableClock enables clock to the DMA controller. The lp parameter determines whether the clock remains on in the low power (sleep) mode.

func (*Controller) Reset

func (d *Controller) Reset()

Reset resets the DMA controller.

type Error

type Error uint8
const (
	ErrTransfer   Error = trerr // Transfer Error.
	ErrDirectMode Error = dmerr // Direct Mode Error.
	ErrFIFO       Error = fferr // FIFO Error.

	ErrAll = ErrTransfer | ErrDirectMode | ErrFIFO
)

func (Error) Error

func (err Error) Error() string

type Event

type Event uint8
const (
	Complete     Event = trce // Transfer Complete Event.
	HalfComplete Event = htce // Half Transfer Complete Event.

	EvAll = Complete | HalfComplete
)

type Mode

type Mode uint32
const (
	PTM Mode = 0   // Read from peripheral, write to memory.
	MTP Mode = mtp // Read from memory, write to peripheral.
	MTM Mode = mtm // Read from memory (AddrP), write to memory.

	Circ Mode = circ // Enable circular mode.
	IncP Mode = incP // Peripheral increment mode.
	IncM Mode = incM // Memory increment mode.
	PFC  Mode = pfc  // Peripheral flow controller.

	FT1 Mode = ft1 // FIFO mode, threshold 1/4.
	FT2 Mode = ft2 // FIFO mode, threshold 2/4.
	FT3 Mode = ft3 // FIFO mode, threshold 3/4.
	FT4 Mode = ft4 // FIFO mode, threshold 4/4.

	TrBuf Mode = trbuf // Bufferable transfers. H7 only, for UART/USART/LPUART.

	PB4  Mode = pb4  // Peripheral burst transfer, 4 beats.
	PB8  Mode = pb8  // Peripheral burst transfer, 8 beats.
	PB16 Mode = pb16 // Peripheral burst transfer, 16 beats.
	MB4  Mode = mb4  // Memory burst transfer, 4 beats.
	MB8  Mode = mb4  // Memory burst transfer, 4 beats.
	MB16 Mode = mb4  // Memory burst transfer, 4 beats.
)

type Prio

type Prio uint8

Prio describes DMA stream priority level.

const (
	Low      Prio = 0     // Low priority.
	Medium   Prio = prioM // Medium priority.
	High     Prio = prioH // High priority.
	VeryHigh Prio = prioV // Very high priority.
)

Jump to

Keyboard shortcuts

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