Skip to content

Commit 44c4470

Browse files
committed
fw/drivers/dma: add dma driver for sf32lb
Signed-off-by: Qingsong Gou <gouqs@hotmail.com>
1 parent 00bdcb2 commit 44c4470

9 files changed

Lines changed: 179 additions & 0 deletions

File tree

boards/obelix_dvt/defconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ CONFIG_RNG_SF32LB=y
8080
CONFIG_CPUMODE=y
8181
CONFIG_CPUMODE_SF32LB=y
8282

83+
CONFIG_DMA=y
84+
CONFIG_DMA_SF32LB=y
85+
8386
CONFIG_DYNAMIC_BACKLIGHT=y
8487
CONFIG_ACCEL_SENSITIVITY=y
8588
CONFIG_APP_SCALING=y

boards/obelix_pvt/defconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ CONFIG_RNG_SF32LB=y
8080
CONFIG_CPUMODE=y
8181
CONFIG_CPUMODE_SF32LB=y
8282

83+
CONFIG_DMA=y
84+
CONFIG_DMA_SF32LB=y
85+
8386
CONFIG_DYNAMIC_BACKLIGHT=y
8487
CONFIG_ACCEL_SENSITIVITY=y
8588
CONFIG_APP_SCALING=y

src/fw/drivers/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ rsource "ambient/Kconfig"
77
rsource "backlight/Kconfig"
88
rsource "battery/Kconfig"
99
rsource "cpumode/Kconfig"
10+
rsource "dma/Kconfig"
1011
rsource "display/Kconfig"
1112
rsource "exti/Kconfig"
1213
rsource "flash/Kconfig"

src/fw/drivers/dma/Kconfig

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# SPDX-FileCopyrightText: 2026 Core Devices LLC
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
menuconfig DMA
5+
bool "DMA"
6+
help
7+
DMA Drivers
8+
9+
if DMA
10+
11+
config DMA_NRF5
12+
bool "Nordic nRF5 DMA Controller"
13+
help
14+
Support for the Nordic nRF5 DMA controller.
15+
16+
config DMA_SF32LB
17+
bool "SiFli SF32LB DMA Controller"
18+
help
19+
Support for the SiFli SF32LB DMA controller.
20+
21+
endif # DMA

src/fw/drivers/dma/sf32lb.c

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

src/fw/drivers/dma/sf32lb.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
#include "bf0_hal_dma.h"
3+
4+
struct DMARequest {
5+
DMA_HandleTypeDef *handle;
6+
};

src/fw/drivers/dma/wscript_build

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# SPDX-FileCopyrightText: 2026 Core Devices LLC
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
use = ['freertos', 'fw_includes']
5+
6+
if bld.env.CONFIG_DMA_NRF5:
7+
use.append('hal_nordic')
8+
sources.append('nrf5.c')
9+
elif bld.env.CONFIG_DMA_SF32LB:
10+
use.append('hal_sifli')
11+
sources.append('sf32lb.c')
12+
13+
bld.objects(
14+
name='driver_dma',
15+
source=sources,
16+
use=use,
17+
)
18+
19+
bld.env.DRIVERS.append('driver_dma')

src/fw/drivers/stubs/dma.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include "drivers/dma.h"
2+
3+
4+
#include <stdint.h>
5+
#include <stdbool.h>
6+
7+
8+
T_STATIC DMADirectRequestHandler handlers[DMA_CHANNEL_NUM];
9+
10+
static void dma_cplt_callback(DMA_HandleTypeDef *hdma)
11+
{
12+
13+
}
14+
15+
void dma_request_init(DMARequest *this)
16+
{
17+
18+
}
19+
20+
void dma_request_start_direct(DMARequest *this, void *dst, const void *src, uint32_t length,
21+
DMADirectRequestHandler handler, void *context)
22+
{
23+
24+
}
25+
26+
void dma_request_start_circular(DMARequest *this, void *dst, const void *src, uint32_t length,
27+
DMACircularRequestHandler handler, void *context)
28+
{
29+
30+
}
31+
32+
void dma_request_stop(DMARequest *this)
33+
{
34+
35+
}
36+
37+
bool dma_request_in_progress(DMARequest *this)
38+
{
39+
return true;
40+
}
41+
42+
uint32_t dma_request_get_current_data_counter(DMARequest *this)
43+
{
44+
return 0;
45+
}
46+
47+
bool dma_request_get_and_clear_transfer_error(DMARequest *this);
48+
{
49+
return true;
50+
}
51+
52+
void dma_request_set_memory_increment_disabled(DMARequest *this, bool disabled)
53+
{
54+
55+
}

src/fw/drivers/wscript_build

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,4 +381,7 @@ bld(
381381
use=bld.env.DRIVERS,
382382
)
383383

384+
if bld.env.CONFIG_DMA:
385+
bld.recurse('dma')
386+
384387
# vim:filetype=python

0 commit comments

Comments
 (0)