-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathsf32lb.c
More file actions
75 lines (57 loc) · 1.94 KB
/
sf32lb.c
File metadata and controls
75 lines (57 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* SPDX-FileCopyrightText: 2026 Core Devices LLC */
/* SPDX-License-Identifier: Apache-2.0 */
#include <stdint.h>
#include <stdbool.h>
#include "board/board.h"
#include <bf0_hal.h>
#include "sf32lb.h"
#define DMA_CHANNEL_NUM 8U
struct DMARequest {
DMA_HandleTypeDef *handle;
};
static DMADirectRequestHandler handlers[DMA_CHANNEL_NUM];
static DMACircularRequestHandler circular_handlers[DMA_CHANNEL_NUM];
static void dma_cplt_callback(DMA_HandleTypeDef *hdma)
{
DMARequest *this = (DMARequest *)hdma->Parent; //container_of?
if (handlers[hdma->ChannelIndex] != NULL)
handlers[hdma->ChannelIndex](this, NULL);
}
void dma_request_init(DMARequest *this)
{
HAL_DMA_Init(this->handle);
}
void dma_request_start_direct(DMARequest *this, void *dst, const void *src, uint32_t length,
DMADirectRequestHandler handler, void *context)
{
HAL_DMA_RegisterCallback(this->handle, HAL_DMA_XFER_CPLT_CB_ID, dma_cplt_callback);
handlers[this->handle->ChannelIndex] = handler;
HAL_DMA_Start_IT(this->handle, (uint32_t)src, (uint32_t)dst, length);
}
void dma_request_start_circular(DMARequest *this, void *dst, const void *src, uint32_t length,
DMACircularRequestHandler handler, void *context)
{
HAL_DMA_RegisterCallback(this->handle, HAL_DMA_XFER_CPLT_CB_ID, dma_cplt_callback);
circular_handlers[this->handle->ChannelIndex] = handler;
HAL_DMA_Start_IT(this->handle, (uint32_t)src, (uint32_t)dst, length);
}
void dma_request_stop(DMARequest *this)
{
HAL_DMA_Abort(this->handle);
}
bool dma_request_in_progress(DMARequest *this)
{
return (HAL_DMA_GetState(this->handle) == HAL_DMA_STATE_BUSY);
}
uint32_t dma_request_get_current_data_counter(DMARequest *this)
{
return 0;
// return HAL_DMA_GetCurrentDataCounter(this->handle);
}
bool dma_request_get_and_clear_transfer_error(DMARequest *this)
{
return false;
}
void dma_request_set_memory_increment_disabled(DMARequest *this, bool disabled)
{
}