Skip to content

Commit 3baad47

Browse files
authored
Merge pull request #4682 from greedyhao/ab32
[bluetrum] add fmrx support
2 parents a896d97 + 8da49ff commit 3baad47

File tree

9 files changed

+134
-52
lines changed

9 files changed

+134
-52
lines changed

bsp/bluetrum/ab32vg1-ab-prougen/.config

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ CONFIG_RT_USING_DEVICE_OPS=y
7474
CONFIG_RT_USING_CONSOLE=y
7575
CONFIG_RT_CONSOLEBUF_SIZE=128
7676
CONFIG_RT_CONSOLE_DEVICE_NAME="uart0"
77-
CONFIG_RT_VER_NUM=0x40003
77+
CONFIG_RT_VER_NUM=0x40004
7878
# CONFIG_RT_USING_CPU_FFS is not set
7979
# CONFIG_ARCH_CPU_STACK_GROWS_UPWARD is not set
8080

@@ -160,6 +160,7 @@ CONFIG_RT_USING_PIN=y
160160
CONFIG_RT_USING_LIBC=y
161161
# CONFIG_RT_USING_PTHREADS is not set
162162
# CONFIG_RT_USING_MODULE is not set
163+
CONFIG_RT_LIBC_FIXED_TIMEZONE=8
163164

164165
#
165166
# Network
@@ -197,6 +198,11 @@ CONFIG_RT_USING_LIBC=y
197198
# CONFIG_RT_USING_ULOG is not set
198199
# CONFIG_RT_USING_UTEST is not set
199200

201+
#
202+
# RT-Thread Utestcases
203+
#
204+
# CONFIG_RT_USING_UTESTCASES is not set
205+
200206
#
201207
# RT-Thread online packages
202208
#
@@ -309,9 +315,11 @@ CONFIG_RT_USING_LIBC=y
309315
# CONFIG_PKG_USING_STEMWIN is not set
310316
# CONFIG_PKG_USING_WAVPLAYER is not set
311317
# CONFIG_PKG_USING_TJPGD is not set
318+
# CONFIG_PKG_USING_PDFGEN is not set
312319
# CONFIG_PKG_USING_HELIX is not set
313320
# CONFIG_PKG_USING_AZUREGUIX is not set
314321
# CONFIG_PKG_USING_TOUCHGFX2RTT is not set
322+
# CONFIG_PKG_USING_NUEMWIN is not set
315323

316324
#
317325
# tools packages
@@ -349,6 +357,10 @@ CONFIG_RT_USING_LIBC=y
349357
# CONFIG_PKG_USING_ANV_TESTSUIT is not set
350358
# CONFIG_PKG_USING_ANV_BENCH is not set
351359
# CONFIG_PKG_USING_DEVMEM is not set
360+
# CONFIG_PKG_USING_REGEX is not set
361+
# CONFIG_PKG_USING_MEM_SANDBOX is not set
362+
# CONFIG_PKG_USING_SOLAR_TERMS is not set
363+
# CONFIG_PKG_USING_GAN_ZHI is not set
352364

353365
#
354366
# system packages
@@ -396,6 +408,7 @@ CONFIG_RT_USING_LIBC=y
396408
# CONFIG_PKG_USING_QFPLIB_M3 is not set
397409
# CONFIG_PKG_USING_LPM is not set
398410
# CONFIG_PKG_USING_TLSF is not set
411+
# CONFIG_PKG_USING_EVENT_RECORDER is not set
399412

400413
#
401414
# peripheral libraries and drivers
@@ -463,6 +476,7 @@ CONFIG_RT_USING_LIBC=y
463476
# CONFIG_PKG_USING_LIBNFC is not set
464477
# CONFIG_PKG_USING_MFOC is not set
465478
# CONFIG_PKG_USING_TMC51XX is not set
479+
# CONFIG_PKG_USING_TCA9534 is not set
466480

467481
#
468482
# AI packages
@@ -490,6 +504,7 @@ CONFIG_RT_USING_LIBC=y
490504
# CONFIG_PKG_USING_FLEXIBLE_BUTTON is not set
491505
# CONFIG_PKG_USING_CANFESTIVAL is not set
492506
# CONFIG_PKG_USING_ZLIB is not set
507+
# CONFIG_PKG_USING_MINIZIP is not set
493508
# CONFIG_PKG_USING_DSTR is not set
494509
# CONFIG_PKG_USING_TINYFRAME is not set
495510
# CONFIG_PKG_USING_KENDRYTE_DEMO is not set

bsp/bluetrum/ab32vg1-ab-prougen/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ ab32vg1-prougen 是 中科蓝讯(Bluetrum) 推出的一款基于 RISC-V 内核
4848
| FLASH | 即将支持 | 对接 FAL |
4949
| TIMER | 支持 | |
5050
| PWM | 支持 | LPWM 的 G1 G2 G3 之间是互斥的,只能三选一 |
51-
| FM receive | 即将支持 | |
51+
| FM receive | 支持 | |
5252
| USB Device | 暂不支持 | |
5353
| USB Host | 暂不支持 | |
5454

bsp/bluetrum/ab32vg1-ab-prougen/board/board.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ void rt_soft_isr(int vector, void *param);
1919
void cpu_irq_comm(void);
2020
void set_cpu_irq_comm(void (*irq_hook)(void));
2121
void load_cache();
22+
void os_cache_init(void);
2223
void sys_error_hook(uint8_t err_no);
2324

24-
typedef void (*os_cache_setfunc_func)(void *load_cache_func, void *io_read);
2525
typedef void (*spiflash_init_func)(uint8_t sf_read, uint8_t dummy);
2626

27-
#define os_cache_setfunc ((os_cache_setfunc_func) 0x84024)
28-
2927
static struct rt_mutex mutex_spiflash = {0};
28+
static struct rt_mutex mutex_cache = {0};
3029
extern volatile rt_uint8_t rt_interrupt_nest;
3130
extern uint32_t __heap_start, __heap_end;
3231

@@ -148,8 +147,9 @@ void rt_hw_us_delay(rt_uint32_t us)
148147
RT_SECTION(".irq.cache")
149148
void cache_init(void)
150149
{
151-
os_cache_setfunc(load_cache, NULL);
150+
os_cache_init();
152151
rt_mutex_init(&mutex_spiflash, "flash_mutex", RT_IPC_FLAG_FIFO);
152+
rt_mutex_init(&mutex_cache, "cache_mutex", RT_IPC_FLAG_FIFO);
153153
}
154154

155155
RT_SECTION(".irq.cache")
@@ -170,6 +170,24 @@ void os_spiflash_unlock(void)
170170
}
171171
}
172172

173+
RT_SECTION(".irq.cache")
174+
void os_cache_lock(void)
175+
{
176+
// if (rt_thread_self()->stat == RT_THREAD_RUNNING) {
177+
if ((rt_thread_self() != RT_NULL) && (rt_interrupt_nest == 0)) {
178+
rt_mutex_take(&mutex_cache, RT_WAITING_FOREVER);
179+
}
180+
}
181+
182+
RT_SECTION(".irq.cache")
183+
void os_cache_unlock(void)
184+
{
185+
// if (rt_thread_self()->stat == RT_THREAD_RUNNING) {
186+
if ((rt_thread_self() != RT_NULL) && (rt_interrupt_nest == 0)) {
187+
rt_mutex_release(&mutex_cache);
188+
}
189+
}
190+
173191
RT_SECTION(".irq.err.str")
174192
static const char stack_info[] = "thread sp=0x%x name=%s";
175193

bsp/bluetrum/ab32vg1-ab-prougen/board/ports/audio/drv_sound.c

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,21 @@
1313
#define DBG_LVL DBG_INFO
1414
#include <rtdbg.h>
1515

16-
#define SAI_AUDIO_FREQUENCY_44K ((uint32_t)44100u)
1716
#define SAI_AUDIO_FREQUENCY_48K ((uint32_t)48000u)
17+
#define SAI_AUDIO_FREQUENCY_44K ((uint32_t)44100u)
18+
#define SAI_AUDIO_FREQUENCY_38K ((uint32_t)38000u)
1819
#define TX_FIFO_SIZE (1024)
1920

2021
struct sound_device
2122
{
2223
struct rt_audio_device audio;
2324
struct rt_audio_configure replay_config;
2425
rt_sem_t semaphore;
25-
rt_thread_t thread;
26+
rt_thread_t thread;
2627
rt_uint8_t *tx_fifo;
2728
rt_uint8_t *rx_fifo;
2829
rt_uint8_t volume;
30+
rt_uint8_t dma_to_aubuf;
2931
};
3032

3133
static struct sound_device snd_dev = {0};
@@ -120,16 +122,15 @@ void audio_sem_pend(void)
120122

121123
void saia_frequency_set(uint32_t frequency)
122124
{
125+
DACDIGCON0 &= ~(0xf << 2);
123126
if (frequency == SAI_AUDIO_FREQUENCY_48K) {
124-
DACDIGCON0 |= BIT(1);
125-
DACDIGCON0 &= ~(0xf << 2);
126-
DACDIGCON0 |= BIT(6);
127+
DACDIGCON0 |= (0 << 2);
127128
} else if (frequency == SAI_AUDIO_FREQUENCY_44K) {
128-
DACDIGCON0 &= ~BIT(1);
129-
DACDIGCON0 &= ~(0xf << 2);
130-
DACDIGCON0 |= BIT(1);
131-
DACDIGCON0 |= BIT(6);
129+
DACDIGCON0 |= (1 << 2);
130+
} else if (frequency == SAI_AUDIO_FREQUENCY_38K) {
131+
DACDIGCON0 |= (2 << 2);
132132
}
133+
DACDIGCON0 |= BIT(6);
133134
}
134135

135136
void saia_channels_set(uint8_t channels)
@@ -271,6 +272,10 @@ static rt_err_t sound_configure(struct rt_audio_device *audio, struct rt_audio_c
271272
break;
272273
}
273274

275+
case AUDIO_MIXER_EXTEND:
276+
snd_dev->dma_to_aubuf = caps->udata.value;
277+
break;
278+
274279
default:
275280
result = -RT_ERROR;
276281
break;
@@ -349,6 +354,7 @@ static rt_err_t sound_init(struct rt_audio_device *audio)
349354
/* set default params */
350355
saia_frequency_set(snd_dev->replay_config.samplerate);
351356
saia_channels_set(snd_dev->replay_config.channels);
357+
saia_volume_set(snd_dev->volume);
352358

353359
return RT_EOK;
354360
}
@@ -368,9 +374,7 @@ static rt_err_t sound_start(struct rt_audio_device *audio, int stream)
368374
AUBUFSIZE |= (TX_FIFO_SIZE / 8) << 16;
369375
AUBUFSTARTADDR = DMA_ADR(snd_dev->rx_fifo);
370376

371-
DACDIGCON0 = BIT(0) | BIT(10); // (0x01<<2)
372-
DACVOLCON = 0x7fff; // -60DB
373-
DACVOLCON |= BIT(20);
377+
DACDIGCON0 |= BIT(0) | BIT(10); // (0x01<<2)
374378

375379
AUBUFCON |= BIT(1);
376380
}
@@ -380,13 +384,11 @@ static rt_err_t sound_start(struct rt_audio_device *audio, int stream)
380384

381385
static rt_err_t sound_stop(struct rt_audio_device *audio, int stream)
382386
{
383-
struct sound_device *snd_dev = RT_NULL;
384-
385387
RT_ASSERT(audio != RT_NULL);
386-
snd_dev = (struct sound_device *)audio->parent.user_data;
387388

388389
if (stream == AUDIO_STREAM_REPLAY)
389390
{
391+
DACDIGCON0 = 0;
390392
AUBUFCON &= ~BIT(4);
391393
LOG_D("close sound device");
392394
}
@@ -463,7 +465,7 @@ static void audio_thread_entry(void *parameter)
463465
{
464466
while (1)
465467
{
466-
if (snd_dev.audio.replay->activated == RT_TRUE) {
468+
if ((snd_dev.dma_to_aubuf == RT_FALSE) && (snd_dev.audio.replay->activated == RT_TRUE)) {
467469
rt_audio_tx_complete(&snd_dev.audio);
468470
} else {
469471
rt_thread_mdelay(50);
@@ -506,7 +508,7 @@ static int rt_hw_sound_init(void)
506508
RT_NULL,
507509
1024,
508510
20, // must equal or lower than tshell priority
509-
5
511+
1
510512
);
511513

512514
if (snd_dev.thread != RT_NULL)
@@ -516,7 +518,7 @@ static int rt_hw_sound_init(void)
516518

517519
/* init default configuration */
518520
{
519-
snd_dev.replay_config.samplerate = 48000;
521+
snd_dev.replay_config.samplerate = SAI_AUDIO_FREQUENCY_48K;
520522
snd_dev.replay_config.channels = 2;
521523
snd_dev.replay_config.samplebits = 16;
522524
snd_dev.volume = 55;

bsp/bluetrum/ab32vg1-ab-prougen/link.lds

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ SECTIONS
4343
. = ALIGN(4);
4444
PROVIDE(__ctors_start__ = .);
4545
KEEP (*(SORT(.init_array.*)))
46-
KEEP (*(.init_array))
46+
KEEP (*(.init_array*))
4747
PROVIDE(__ctors_end__ = .);
4848

4949
. = ALIGN(4);
@@ -73,21 +73,17 @@ SECTIONS
7373
.comm __comm_vma : {
7474
. = ALIGN(4);
7575
KEEP(*(.vector))
76+
*(.irq.cache)
7677
*(.irq*)
77-
/*applications**.o (.text .rodata)*/
78-
*hal_libraries*ab32vg1_hal**.o (.text .rodata)
79-
*(.text.unlikely)
80-
*(.text.startup)
81-
*hal_drivers**.o (.rodata)
82-
*audio*drv_sound.o (.rodata)
83-
*system_ab32vgx.o (.rodata)
84-
EXCLUDE_FILE(*lib_a**.o *cp-demangle.o *cp-demangle.o
85-
*src*mem.o *src*memheap.o *dfs**.o *components.o *drivers*sdio**.o *cmd.o *msh_file.o
86-
*drv_sdio.o *drv_wdt.o) *(.rodata.str1.4)
87-
EXCLUDE_FILE(*lib_a**.o *unwind*.o) *(.srodata)
78+
*components*src**.o (.text* .rodata*)
79+
*ab32vg1_hal**.o (.text* .rodata*)
80+
*drv_gpio.o (.text* .rodata*)
81+
*drv_usart.o (.rodata*)
82+
EXCLUDE_FILE(*lib_a**.o *unwind*.o) *(.srodata*)
8883
*(.rela*)
8984
*(.data*)
9085
*(.sdata*)
86+
*(.com_text*)
9187
} > comm AT > flash
9288

9389
.bss (NOLOAD):

bsp/bluetrum/ab32vg1-ab-prougen/rtconfig.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
#define RT_USING_CONSOLE
4747
#define RT_CONSOLEBUF_SIZE 128
4848
#define RT_CONSOLE_DEVICE_NAME "uart0"
49-
#define RT_VER_NUM 0x40003
49+
#define RT_VER_NUM 0x40004
5050

5151
/* RT-Thread Components */
5252

@@ -90,6 +90,7 @@
9090
/* POSIX layer and C standard library */
9191

9292
#define RT_USING_LIBC
93+
#define RT_LIBC_FIXED_TIMEZONE 8
9394

9495
/* Network */
9596

@@ -111,6 +112,9 @@
111112
/* Utilities */
112113

113114

115+
/* RT-Thread Utestcases */
116+
117+
114118
/* RT-Thread online packages */
115119

116120
/* IoT - internet of things */
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#ifndef FMRX_H__
2+
#define FMRX_H__
3+
4+
/**
5+
* @brief Synchronize between FMRX and DAC
6+
*
7+
* @param buf_size Size of audio buffer.
8+
*/
9+
void fmrx_dac_sync(uint32_t buf_size);
10+
11+
/**
12+
* @brief FMRX power on.
13+
*
14+
* @param val Make it zero now.
15+
*/
16+
void fmrx_power_on(uint32_t val);
17+
18+
/**
19+
* @brief FMRX power off.
20+
*
21+
*/
22+
void fmrx_power_off(void);
23+
24+
/**
25+
* @brief FMRX digital start.
26+
*
27+
*/
28+
void fmrx_digital_start(void);
29+
30+
/**
31+
* @brief FMRX digital stop.
32+
*
33+
*/
34+
void fmrx_digital_stop(void);
35+
36+
/**
37+
* @brief FMRX dma to aubuf enable.
38+
*
39+
* @param enable RT_TRUE or RT_FALSE.
40+
*/
41+
void fmrx_dma_to_aubuf(uint8_t enable);
42+
43+
#endif
32.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)