Hardware description

The hardware description is a file containing all addresses and parameters of the hardware. It is used to configure the Dma and all GPIO devices.

Variables

Variables

constexpr uint32_t DEFAULT_DATA_SIZE = 8

The DEFAULT_DATA_SIZE constant represents the size of each data transfer (per valid clock cycle) in bytes.

The ADC uses 64 bit data transfers by default (meaning 8 byte).

constexpr uint32_t DMA_START_ADDRESS = 0x20000000

The DMA_START_ADDRESS constant represents the start address of the DMA buffer.

The DMA buffer is reserved in the physical memory. This constant represents the start address of the DMA buffer. It must match the start address in the device tree.

constexpr uint32_t DEFAULT_PACKAGE_SIZE = 0x400000

The DEFAULT_PACKAGE_SIZE constant represents the the amount of transfers before each DMA interrupt.

The hardware packs together transfers into packages. This constant represents the amount of transfers per package. Calculating DEFAULT_DATA_SIZE * DEFAULT_PACKAGE_SIZE gives the number of bytes per package (see DEFAULT_PACKAGE_SIZE_BYTES). It must match the package size set in the hardware design.

constexpr uint32_t DEFAULT_PACKAGE_SIZE_BYTES = DEFAULT_DATA_SIZE * DEFAULT_PACKAGE_SIZE

The DEFAULT_PACKAGE_SIZE_BYTES constant represents the the amount of bytes before each DMA interrupt.

The hardware packs together transfers into packages. This constant represents the amount of bytes per package. Calculating DEFAULT_DATA_SIZE * DEFAULT_PACKAGE_SIZE gives the number of bytes per package.

constexpr uint8_t DMA_COUNT = 2

The DMA_COUNT constant represents the amount of ADC channels.

The used ADC has two DMA channels.

constexpr uint32_t DMA_RESERVED_SPACE = 0x10000000

The DMA_RESERVED_SPACE constant represents the total reserved space for DMA buffers.

The DMA buffers are reserved in the physical memory. This constant represents the total reserved space. It must match the reserved space in the device tree.

constexpr uint32_t DMA_DESCRIPTOR_BASE = 0x80000000

The DMA_DESCRIPTOR_BASE constant represents the physical location of the DMA descriptor memory.

The DMA descriptor memory is reserved in the physical memory. Block RAM is used in hardware.

constexpr uint32_t DMA_DESCRIPTOR_SIZE = 0x40u

The DMA_DESCRIPTOR_SIZE constant represents the size of a DMA descriptor.

This is given by documentation of the DMA.

constexpr uint32_t DMA_DESCRIPTOR_PER_DMA = (DMA_RESERVED_SPACE / DMA_COUNT) / (DEFAULT_PACKAGE_SIZE * DEFAULT_DATA_SIZE)

The DMA_DESCRIPTOR_PER_DMA constant represents the amount of DMA descriptors per DMA device.

The formula calculates the optimal amount of DMA descriptors per DMA device so that the whole reserved memory is used.

constexpr std::array<DMA_DEVICE, DMA_COUNT> DMAS = {{{0x80400000, 0, "/dev/udmabuf0", "/dev/uio0"}, {0x80410000, DMA_DESCRIPTOR_SIZE * DMA_DESCRIPTOR_PER_DMA, "/dev/udmabuf1", "/dev/uio1"}}}

The DMAS constant represents the DMA devices used for the ADC.

The first DMA device is used for ADC channel 0, the second DMA device is used for ADC channel 1.

constexpr uint32_t GPIO_ENABLED = 0x81200000

The GPIO_ENABLED constant represents the address fro the register controlling the enabled state of the ADC channels.

There are 2 ADC channels. The lowest 2 bit represent the ADC channels.

Example: 0b0000000000000001 enables ADC channel 0

constexpr uint32_t GPIO_MEASUREMENT_INTERRUPT = 0x81210000

The GPIO_MEASUREMENT_INTERRUPT constant represents the address for the registers controlling the measurement interrupt.

This GPIO uses two registers. The first is an input register, the second is an output register.

The first register is used to read the status of the measurement.

  • bit [0..1]: stopped status of ADC channel 0 and 1

  • bit [2..3]: DMA interrupt status of ADC channel 0 and 1

The second register is used to disable further interrupts.

  • bit [0..1]: disable interrupt for ADC channel 0 and 1 (0 = no further interrupts, 1 = interrupts work)

constexpr uint32_t GPIO_MEASUREMENT_TIME = 0x81220000

The GPIO_MEASUREMENT_TIME constant represents the address for the register controlling the measurement time.

This GPIO uses one register. The register is used to set the measurement time.

The measurement time is given in ms.

constexpr uint32_t GPIO_TRIGGER_VALUE = 0x81240000

The GPIO_TRIGGER_VALUE constant represents the address for the register controlling the trigger value.

This GPIO uses one register. The register is used to set the trigger value.

The trigger value is given in a value corresponding to the ADC value.

constexpr uint32_t GPIO_LONG_GATE = 0x81230000

The GPIO_LONG_GATE constant represents the address for the register controlling the long gate.

This GPIO uses one register. The register is used to set the long gate.

The long gate sets the number of samples to be measured once a trigger occurs.

constexpr uint32_t GPIO_PRE_GATE = 0x81250000

The GPIO_PRE_GATE constant represents the address for the register controlling the pre gate.

This GPIO uses one register. The register is used to set the pre gate.

The pre gate sets the number of samples to be measured to be be output before the trigger occurred.

struct DMA_DEVICE
#include <hwdevice.h>

The DMA_DEVICE struct represents a DMA device.

This struct is used to configure the DMA devices used for the ADC.

Public Members

uint32_t mRegister

The register address of the DMA device.

uint32_t mDescriptorOffset

The offset of the DMA descriptor memory.

const char *mDmaDevice

The device name of the DMA device.

const char *mUioDevice

The device name of the UIO device.