2019-10-24 19:06:19 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2019 Song Qiang <songqiang1304521@gmail.com>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2020-01-27 10:52:56 +01:00
|
|
|
#ifndef DMA_STM32_H_
|
|
|
|
#define DMA_STM32_H_
|
|
|
|
|
2020-08-28 15:04:00 +02:00
|
|
|
#include <soc.h>
|
2020-11-20 18:33:07 +01:00
|
|
|
#include <stm32_ll_dma.h>
|
2020-08-28 15:04:00 +02:00
|
|
|
#include <drivers/dma.h>
|
|
|
|
#include <drivers/clock_control/stm32_clock_control.h>
|
|
|
|
|
2020-01-27 10:52:56 +01:00
|
|
|
/* Maximum data sent in single transfer (Bytes) */
|
|
|
|
#define DMA_STM32_MAX_DATA_ITEMS 0xffff
|
|
|
|
|
|
|
|
struct dma_stm32_stream {
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t direction;
|
2020-04-23 11:38:06 +02:00
|
|
|
#ifdef CONFIG_DMAMUX_STM32
|
|
|
|
int mux_channel; /* stores the dmamux channel */
|
|
|
|
#endif /* CONFIG_DMAMUX_STM32 */
|
2020-01-27 10:52:56 +01:00
|
|
|
bool source_periph;
|
2020-12-18 10:49:23 +01:00
|
|
|
bool hal_override;
|
2020-08-23 09:13:21 +02:00
|
|
|
volatile bool busy;
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t src_size;
|
|
|
|
uint32_t dst_size;
|
2020-07-29 09:02:03 +02:00
|
|
|
void *user_data; /* holds the client data */
|
2020-07-29 08:55:43 +02:00
|
|
|
dma_callback_t dma_callback;
|
2020-01-27 10:52:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct dma_stm32_data {
|
2021-08-04 16:58:04 +02:00
|
|
|
struct dma_context dma_ctx;
|
2020-01-27 10:52:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct dma_stm32_config {
|
|
|
|
struct stm32_pclken pclken;
|
2020-04-30 20:33:38 +02:00
|
|
|
void (*config_irq)(const struct device *dev);
|
2020-01-27 10:52:56 +01:00
|
|
|
bool support_m2m;
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t base;
|
2020-08-21 23:50:00 +02:00
|
|
|
uint32_t max_streams;
|
2020-10-15 08:50:23 +02:00
|
|
|
#ifdef CONFIG_DMAMUX_STM32
|
|
|
|
uint8_t offset; /* position in the list of dmamux channel list */
|
|
|
|
#endif
|
2020-08-21 23:50:00 +02:00
|
|
|
struct dma_stm32_stream *streams;
|
2020-01-27 10:52:56 +01:00
|
|
|
};
|
2019-10-24 19:06:19 +08:00
|
|
|
|
2020-08-22 14:28:52 +02:00
|
|
|
uint32_t dma_stm32_id_to_stream(uint32_t id);
|
2021-03-30 18:22:30 +03:00
|
|
|
#if !defined(CONFIG_DMAMUX_STM32)
|
2020-08-22 14:28:52 +02:00
|
|
|
uint32_t dma_stm32_slot_to_channel(uint32_t id);
|
|
|
|
#endif
|
|
|
|
|
2020-08-28 15:04:00 +02:00
|
|
|
typedef void (*dma_stm32_clear_flag_func)(DMA_TypeDef *DMAx);
|
|
|
|
typedef uint32_t (*dma_stm32_check_flag_func)(DMA_TypeDef *DMAx);
|
|
|
|
|
|
|
|
bool dma_stm32_is_tc_active(DMA_TypeDef *DMAx, uint32_t id);
|
|
|
|
void dma_stm32_clear_tc(DMA_TypeDef *DMAx, uint32_t id);
|
|
|
|
bool dma_stm32_is_ht_active(DMA_TypeDef *DMAx, uint32_t id);
|
|
|
|
void dma_stm32_clear_ht(DMA_TypeDef *DMAx, uint32_t id);
|
|
|
|
bool dma_stm32_is_te_active(DMA_TypeDef *DMAx, uint32_t id);
|
|
|
|
void dma_stm32_clear_te(DMA_TypeDef *DMAx, uint32_t id);
|
|
|
|
|
|
|
|
#ifdef CONFIG_DMA_STM32_V1
|
|
|
|
bool dma_stm32_is_dme_active(DMA_TypeDef *DMAx, uint32_t id);
|
|
|
|
void dma_stm32_clear_dme(DMA_TypeDef *DMAx, uint32_t id);
|
|
|
|
bool dma_stm32_is_fe_active(DMA_TypeDef *DMAx, uint32_t id);
|
|
|
|
void dma_stm32_clear_fe(DMA_TypeDef *DMAx, uint32_t id);
|
|
|
|
#endif
|
|
|
|
|
2020-03-11 09:45:08 +01:00
|
|
|
#ifdef CONFIG_DMA_STM32_V2
|
2020-08-28 15:04:00 +02:00
|
|
|
bool dma_stm32_is_gi_active(DMA_TypeDef *DMAx, uint32_t id);
|
|
|
|
void dma_stm32_clear_gi(DMA_TypeDef *DMAx, uint32_t id);
|
2020-03-11 09:45:08 +01:00
|
|
|
#endif
|
2019-10-24 19:06:19 +08:00
|
|
|
|
2020-08-21 23:50:00 +02:00
|
|
|
bool stm32_dma_is_irq_active(DMA_TypeDef *dma, uint32_t id);
|
2021-02-03 16:57:10 +01:00
|
|
|
bool stm32_dma_is_ht_irq_active(DMA_TypeDef *dma, uint32_t id);
|
|
|
|
bool stm32_dma_is_tc_irq_active(DMA_TypeDef *dma, uint32_t id);
|
2020-08-21 23:50:00 +02:00
|
|
|
|
2020-05-27 11:26:57 -05:00
|
|
|
void stm32_dma_dump_stream_irq(DMA_TypeDef *dma, uint32_t id);
|
|
|
|
void stm32_dma_clear_stream_irq(DMA_TypeDef *dma, uint32_t id);
|
|
|
|
bool stm32_dma_is_irq_happened(DMA_TypeDef *dma, uint32_t id);
|
|
|
|
bool stm32_dma_is_unexpected_irq_happened(DMA_TypeDef *dma, uint32_t id);
|
|
|
|
void stm32_dma_enable_stream(DMA_TypeDef *dma, uint32_t id);
|
|
|
|
int stm32_dma_disable_stream(DMA_TypeDef *dma, uint32_t id);
|
2021-03-30 18:22:30 +03:00
|
|
|
|
|
|
|
#if !defined(CONFIG_DMAMUX_STM32)
|
|
|
|
void stm32_dma_config_channel_function(DMA_TypeDef *dma, uint32_t id,
|
|
|
|
uint32_t slot);
|
|
|
|
#endif
|
2020-03-11 09:45:08 +01:00
|
|
|
|
2019-10-24 19:06:19 +08:00
|
|
|
#ifdef CONFIG_DMA_STM32_V1
|
2020-05-27 11:26:57 -05:00
|
|
|
void stm32_dma_disable_fifo_irq(DMA_TypeDef *dma, uint32_t id);
|
2019-10-24 19:06:19 +08:00
|
|
|
bool stm32_dma_check_fifo_mburst(LL_DMA_InitTypeDef *DMAx);
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t stm32_dma_get_fifo_threshold(uint16_t fifo_mode_control);
|
|
|
|
uint32_t stm32_dma_get_mburst(struct dma_config *config, bool source_periph);
|
|
|
|
uint32_t stm32_dma_get_pburst(struct dma_config *config, bool source_periph);
|
2019-10-24 19:06:19 +08:00
|
|
|
#endif
|
2020-01-27 10:52:56 +01:00
|
|
|
|
2020-04-23 11:38:06 +02:00
|
|
|
#ifdef CONFIG_DMAMUX_STM32
|
|
|
|
/* dma_stm32_ api functions are exported to the dmamux_stm32 */
|
2020-08-23 09:20:17 +02:00
|
|
|
#define DMA_STM32_EXPORT_API
|
2020-04-30 20:33:38 +02:00
|
|
|
int dma_stm32_configure(const struct device *dev, uint32_t id,
|
2020-08-23 09:20:17 +02:00
|
|
|
struct dma_config *config);
|
2020-04-30 20:33:38 +02:00
|
|
|
int dma_stm32_reload(const struct device *dev, uint32_t id,
|
2020-08-23 09:20:17 +02:00
|
|
|
uint32_t src, uint32_t dst, size_t size);
|
2020-04-30 20:33:38 +02:00
|
|
|
int dma_stm32_start(const struct device *dev, uint32_t id);
|
|
|
|
int dma_stm32_stop(const struct device *dev, uint32_t id);
|
2020-12-16 16:44:53 +02:00
|
|
|
int dma_stm32_get_status(const struct device *dev, uint32_t id,
|
|
|
|
struct dma_status *stat);
|
2020-08-23 09:20:17 +02:00
|
|
|
#else
|
|
|
|
#define DMA_STM32_EXPORT_API static
|
2020-04-23 11:38:06 +02:00
|
|
|
#endif /* CONFIG_DMAMUX_STM32 */
|
|
|
|
|
2020-01-27 10:52:56 +01:00
|
|
|
#endif /* DMA_STM32_H_*/
|