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:
parent
e0b3cba571
commit
669104d841
14
cpu/sam0_common/periph/Kconfig.spi
Normal file
14
cpu/sam0_common/periph/Kconfig.spi
Normal 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.
|
@ -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);
|
||||
|
1
cpu/samd21/periph/Kconfig.spi
Normal file
1
cpu/samd21/periph/Kconfig.spi
Normal file
@ -0,0 +1 @@
|
||||
source "$(RIOTCPU)/sam0_common/periph/Kconfig.spi"
|
1
cpu/samd5x/periph/Kconfig.spi
Normal file
1
cpu/samd5x/periph/Kconfig.spi
Normal file
@ -0,0 +1 @@
|
||||
source "$(RIOTCPU)/sam0_common/periph/Kconfig.spi"
|
1
cpu/saml1x/periph/Kconfig.spi
Normal file
1
cpu/saml1x/periph/Kconfig.spi
Normal file
@ -0,0 +1 @@
|
||||
source "$(RIOTCPU)/sam0_common/periph/Kconfig.spi"
|
1
cpu/saml21/periph/Kconfig.spi
Normal file
1
cpu/saml21/periph/Kconfig.spi
Normal file
@ -0,0 +1 @@
|
||||
source "$(RIOTCPU)/sam0_common/periph/Kconfig.spi"
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user