|
| 1 | +/* SPDX-FileCopyrightText: 2026 Core Devices LLC */ |
| 2 | +/* SPDX-License-Identifier: Apache-2.0 */ |
| 3 | + |
| 4 | +#include <stdint.h> |
| 5 | +#include <stdbool.h> |
| 6 | + |
| 7 | +#include "drivers/dma.h" |
| 8 | + |
| 9 | + |
| 10 | +#include "sf32lb.h" |
| 11 | + |
| 12 | +#define DMA_CHANNEL_NUM 8U |
| 13 | + |
| 14 | +static DMADirectRequestHandler handlers[DMA_CHANNEL_NUM]; |
| 15 | +static DMACircularRequestHandler circular_handlers[DMA_CHANNEL_NUM]; |
| 16 | + |
| 17 | +static void dma_cplt_callback(DMA_HandleTypeDef *hdma) |
| 18 | +{ |
| 19 | + DMARequest *this = (DMARequest *)hdma->Parent; //container_of? |
| 20 | + |
| 21 | + if (handlers[hdma->ChannelIndex] != NULL) |
| 22 | + handlers[hdma->ChannelIndex](this, NULL); |
| 23 | +} |
| 24 | + |
| 25 | +void dma_request_init(DMARequest *this) |
| 26 | +{ |
| 27 | + HAL_DMA_Init(this->handle); |
| 28 | +} |
| 29 | + |
| 30 | +void dma_request_start_direct(DMARequest *this, void *dst, const void *src, uint32_t length, |
| 31 | + DMADirectRequestHandler handler, void *context) |
| 32 | +{ |
| 33 | + HAL_DMA_RegisterCallback(this->handle, HAL_DMA_XFER_CPLT_CB_ID, dma_cplt_callback); |
| 34 | + handlers[this->handle->ChannelIndex] = handler; |
| 35 | + HAL_DMA_Start_IT(this->handle, (uint32_t)src, (uint32_t)dst, length); |
| 36 | +} |
| 37 | + |
| 38 | +void dma_request_start_circular(DMARequest *this, void *dst, const void *src, uint32_t length, |
| 39 | + DMACircularRequestHandler handler, void *context) |
| 40 | +{ |
| 41 | + HAL_DMA_RegisterCallback(this->handle, HAL_DMA_XFER_CPLT_CB_ID, dma_cplt_callback); |
| 42 | + circular_handlers[this->handle->ChannelIndex] = handler; |
| 43 | + HAL_DMA_Start_IT(this->handle, (uint32_t)src, (uint32_t)dst, length); |
| 44 | +} |
| 45 | + |
| 46 | +void dma_request_stop(DMARequest *this) |
| 47 | +{ |
| 48 | + HAL_DMA_Abort(this->handle); |
| 49 | +} |
| 50 | + |
| 51 | +bool dma_request_in_progress(DMARequest *this) |
| 52 | +{ |
| 53 | + return (HAL_DMA_GetState(this->handle) == HAL_DMA_STATE_BUSY); |
| 54 | +} |
| 55 | + |
| 56 | +uint32_t dma_request_get_current_data_counter(DMARequest *this) |
| 57 | +{ |
| 58 | + return 0; |
| 59 | +// return HAL_DMA_GetCurrentDataCounter(this->handle); |
| 60 | +} |
| 61 | + |
| 62 | +bool dma_request_get_and_clear_transfer_error(DMARequest *this) |
| 63 | +{ |
| 64 | + return false; |
| 65 | +} |
| 66 | + |
| 67 | +void dma_request_set_memory_increment_disabled(DMARequest *this, bool disabled) |
| 68 | +{ |
| 69 | + |
| 70 | +} |
0 commit comments