1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

cpu/sam0_common: SPI: don't perform DMA transfer for small buffers

Setting up a DMA transfer can take longer than sending out a buffer
byte by byte if the buffer is small.

DMA only shows advantages for large buffers, using it for every transfer
will cause a net slowdown.

Since we did not come up with a good way to determine the treshold based
on the SPI frequency, just use a fixed buffer for now so that DMA can be
used without slowing things down overall.
This commit is contained in:
Benjamin Valentin 2021-10-01 12:41:03 +02:00
parent e0b3cba571
commit 669104d841
7 changed files with 30 additions and 1 deletions

View File

@ -0,0 +1,14 @@
# Copyright (c) 2020 HAW Hamburg
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
config SPI_DMA_THRESHOLD_BYTES
int "SPI DMA threshold (bytes)"
depends on MODULE_PERIPH_DMA
depends on MODULE_PERIPH_SPI
default 16
help
Threshold in bytes under which no SPI DMA transfer will be performed.
Polling will be used instead.

View File

@ -36,6 +36,14 @@
#define ENABLE_DEBUG 0
#include "debug.h"
/**
* @brief Threshold under which polling transfers are used instead of DMA
* TODO: determine at run-time based on SPI clock
*/
#ifndef CONFIG_SPI_DMA_THRESHOLD_BYTES
#define CONFIG_SPI_DMA_THRESHOLD_BYTES 16
#endif
/**
* @brief Array holding one pre-initialized mutex for each SPI device
*/
@ -508,7 +516,7 @@ void spi_transfer_bytes(spi_t bus, spi_cs_t cs, bool cont,
gpio_clear((gpio_t)cs);
}
if (_use_dma(bus)) {
if (_use_dma(bus) && len > CONFIG_SPI_DMA_THRESHOLD_BYTES) {
#ifdef MODULE_PERIPH_DMA
/* The DMA promises not to modify the const out data */
_dma_transfer(bus, out, in, len);

View File

@ -0,0 +1 @@
source "$(RIOTCPU)/sam0_common/periph/Kconfig.spi"

View File

@ -0,0 +1 @@
source "$(RIOTCPU)/sam0_common/periph/Kconfig.spi"

View File

@ -0,0 +1 @@
source "$(RIOTCPU)/sam0_common/periph/Kconfig.spi"

View File

@ -0,0 +1 @@
source "$(RIOTCPU)/sam0_common/periph/Kconfig.spi"

View File

@ -41,4 +41,7 @@ config MODULE_PERIPH_INIT_SPI_GPIO_MODE
default y if MODULE_PERIPH_INIT
depends on MODULE_PERIPH_SPI_GPIO_MODE
# Include CPU specific configurations
osource "$(RIOTCPU)/$(CPU)/periph/Kconfig.spi"
endif # MODULE_PERIPH_SPI