kendryte / kendryte-standalone-sdk

Standalone SDK for kendryte K210
https://kendryte.com
Apache License 2.0
440 stars 161 forks source link

Feature: Synchronization between cached and non-cached memory #129

Open nsch0e opened 3 years ago

nsch0e commented 3 years ago

Missing feature

Function to synchronize between cached and non-cached memory so they contain the same content.

Justification

For example dma seems to work only on non-cached memory so all cached memory arguments get copied to extra allocated non-cached memory: https://github.com/kendryte/kendryte-standalone-sdk/blob/06a2ea71f250e91d66fa156ff82ae1f5b9fc6e56/lib/drivers/dmac.c#L373 this is non-performant and dangerous because of the amount of mallocs used.

Workarounds (kind of)

you can use a normal variable as non-cached by subtracting the offset between cache and non-cached memory like this:

uint8_t arrCached[1024];
uint8_t *arr = arrCached - 0x40000000;

but there is no guarantee at any point that arrCached and arr show the same results although they point to mirrored memory.

Would using the mb() (memory barrier) macro be enough? https://github.com/kendryte/kendryte-standalone-sdk/blob/06a2ea71f250e91d66fa156ff82ae1f5b9fc6e56/lib/bsp/include/atomic.h#L36

Kind regards!