Skip to content

Extend snrt_dma_memset #200

@colluca

Description

@colluca

The snrt_memset function in alloc.h:

// TODO colluca: optimize by using DMA
inline void *snrt_memset(void *ptr, int value, size_t num) {
for (uint32_t i = 0; i < num; ++i)
*((uint8_t *)ptr + i) = (unsigned char)value;
return ptr;
}

And the snrt_dma_memset function in dma.h are to some extent redundant:

/**
* @brief Fast memset function performed by DMA.
* @param ptr Pointer to the start of the region.
* @param value Value to set.
* @param len Number of bytes, must be a multiple of the DMA bus width.
*/
inline void snrt_dma_memset(void *ptr, uint8_t value, uint32_t len) {
// set first 64bytes to value
// memset(ptr, value, 64);
uint8_t *p = ptr;
uint32_t nbytes = 64;
while (nbytes--) {
*p++ = value;
}
// DMA copy the the rest
snrt_dma_txid_t memset_txid =
snrt_dma_start_2d(ptr, ptr, 64, 64, 0, len / 64);
snrt_dma_wait_all();
}

Merge them and also handle specific case of a memset to zero by taking advantage of the cluster's zero memory. See the following as an example:

snrt_dma_start_1d((void*)(tls_ptr + i * tls_offset),
(void*)(snrt_zero_memory_ptr()), size);

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions