Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(D1): add builders for DMAC descriptors (#284)
Currently, the DMAC descriptor configuration fields are bit-packed every time a descriptor is constructed. However, the drivers which use DMA always construct descriptors with the same configuration bitfields -- only the addresses and lengths change. We can make this more efficient by constructing the config field once and copying it into each new descriptor. This branch replaces the existing `DescriptorConfig` struct with a `DescriptorBuilder`, which is basically the same thing except it actually constructs the bitfields as single `u32`s, which can then just be copied into a final `Descriptor` for each DMA op. I used `mycelium-bitfield` to do this --- mostly for fun, but it's maybe a bit more readable than the previous code? I dunno. Using the builder, we are able to pack all the configuration fields that don't change a single time. Both of the DMA operations currently run by our SPI and UART drivers always use the same destination addresses, so we're also able to only pack that a single time. Now, only the length and source address have to be re-packed for each new DMA transfer that's started by these drivers. The builder also allows us to avoid some unrepresentable or inconsistent states. We now have builder methods that take source and destination slices and registers, and automatically set the `AddressMode` to `Linear` when the source/dest is a slice, or to `Io` when it's a register. When a slice operand is used, we're also able to set the byte counter to the length of the slice (or the minimum of two slice lengths, when both operands are slices), and set the DRQ type to `Dram` for that operand. Furthermore, I've added additional validation when constructing descriptors.
- Loading branch information