未验证 提交 98a997c5 编写于 作者: 杭州_燕十三's avatar 杭州_燕十三 提交者: GitHub

[bsp]add new bsp-bl808 (#6824)

* add new bsp-bl808

* support ARCH_RISCV_FPU_S && update rtconfig.py
上级 3dffc78f
# 博流智能 BL808板级支持包说明
## 1. 简介
BL808 是高度集成的 AIoT 芯片组,具有 Wi-Fi/BT/BLE/Zigbee 等无线互联单元,包含多个 CPU 以及音频编码译码器、视频编码译码器和 AI 硬件加速器,适用于各种高性能和低功耗应用领域。
BL808 系列芯片主要包含无线和多媒体两个子系统。
无线子系统包含一颗 RISC-V 32-bit 高性能 CPU(m0),集成 Wi-Fi/BT/Zigbee 无线子系统,可以实现多种无线连接和数据传输,提供多样化的连接与传输体验。
多媒体子系统包含一颗 RISC-V 64-bit 超高性能 CPU(d0),集成 DVP/CSI/ H264/NPU 等视频处理模块,可以广泛应用于视频监控/智能音箱等多种 AI 领域
多媒体子系统组成部分如下:
- NPU HW NN 协处理器 (BLAI-100),适用于人工智能应用领域
- 摄像头接口
- 音频编码译码器
- 视频编码解码器
- 传感器
- 显示接口
电源管理单元控制低功耗模式。此外,还支持各种安全功能。
外围接口包括 USB2.0、 Ethernet、 SD/MMC、 SPI、 UART、 I2C、 I2S、 PWM、 GPDAC/GPADC、 ACOMP、 PIR、 Touch、
IR remote、 Display 和 GPIO。
支持灵活的 GPIO 配置, BL808 最多可达 40 个 GPIO。
芯片规格包括如下:
| 硬件 | 描述 |
| -- | -- |
|芯片型号| bl808 |
|CPU| 三核异构RISC-V CPUs: <br />RV64GCV 480MHz<br/>RV32GCP 320MHz<br/>RV32EMC 160MHz |
|RAM| 768KB SRAM + 64MB UHS PSRAM |
| 外设 | 内嵌AES与SHA256算法加速器 |
| AI NN 通用硬件加速器 | BLAI-100 用于视频/音频检测/识别,100GOPS 算力 |
| 摄像头接口 | DVP 和 MIPI-CSI |
| 显示接口 | SPI、DBI、DPI(RGB) |
| 无线 | 支持 Wi-Fi 802.11 b/g/n<br/>支持 Bluetooth 5.x Dual-mode(BT+BLE)<br/>支持 Wi-Fi / 蓝牙 共存 |
## 2. 编译说明
BL808是多核异构架构,每个核需要单独编译,并烧录到对应的位置。
Windows下推荐使用[env工具][1],然后在console下进入bsp/bl808目录中,选择需要编译的核心,m0或d0,运行:
cd bsp/bl808/m0
menuconfig
pkgs --update
如果在Linux平台下,可以先执行
scons --menuconfig
它会自动下载env相关脚本到~/.env目录,然后执行
source ~/.env/env.sh
cd bsp/bl808/m0
pkgs --update
下载risc-v的工具链,[下载地址](https://occ.t-head.cn/community/download?id=4073475960903634944)[下载地址](https://dl.sipeed.com/shareURL/others/toolchain)
更新完软件包后,在`rtconfig.py`中将risc-v工具链的本地路径加入文档。
然后执行scons编译:
```
set RTT_EXEC_PATH=C:\Users\xxxx\Downloads\Xuantie-900-gcc-elf-newlib-x86_64-V2.6.1/bin
scons
```
来编译这个板级支持包。
或者通过 `scons --exec-path="GCC工具链路径"` 命令,在指定工具链位置的同时直接编译。
如果编译正确无误,会产生rtthread.elf、rtthread_m0.bin文件。其中rtthread_m0.bin需要烧写到设备中进行运行。
## 3. 烧写及执行
连接好串口,然后使用[Bouffalo Lab Dev Cube](https://dev.bouffalolab.com/download)工具进行烧写bin文件。
![Bouffalo Lab Dev Cube](figures/program.jpg)
### 3.1 运行结果
如果编译 & 烧写无误,当复位设备后,会在串口上看到RT-Thread的启动logo信息:
![terminal](figures/bl808.jpg)
## 4. 驱动支持情况及计划
| 驱动 | 支持情况 | 备注 |
| ------ | ---- | :------: |
| UART | 支持 | UART0,用于shell,默认波特率2000000 |
## 5. 联系人信息
维护人:[flyingcys](https://github.com/flyingcys)
## 6. 支持开发板列表
| | 开发板型号 |
| ------ | ---------- |
| Sipeed | M1s Dock |
| | |
## 7. 参考
* 芯片[datasheet][2]
[1]: https://www.rt-thread.org/page/download.html
[2]: https://github.com/bouffalolab/bl_docs
此差异已折叠。
mainmenu "RT-Thread Project Configuration"
config BSP_DIR
string
option env="BSP_ROOT"
default "."
config RTT_DIR
string
option env="RTT_ROOT"
default "../../.."
config PKGS_DIR
string
option env="PKGS_ROOT"
default "packages"
source "$RTT_DIR/Kconfig"
source "$PKGS_DIR/Kconfig"
source "drivers/Kconfig"
# for module compiling
import os
from building import *
cwd = GetCurrentDir()
objs = []
list = os.listdir(cwd)
for d in list:
path = os.path.join(cwd, d)
if os.path.isfile(os.path.join(path, 'SConscript')):
objs = objs + SConscript(os.path.join(d, 'SConscript'))
Return('objs')
import os
import sys
import rtconfig
from rtconfig import RTT_ROOT
sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
from building import *
TARGET = 'rtthread.' + rtconfig.TARGET_EXT
DefaultEnvironment(tools=[])
env = Environment(tools = ['mingw'],
AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
CC = rtconfig.CC, CFLAGS = rtconfig.CFLAGS,
CXX = rtconfig.CXX, CXXFLAGS = rtconfig.CXXFLAGS,
AR = rtconfig.AR, ARFLAGS = '-rc',
LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
env['ASCOM'] = env['ASPPCOM']
Export('RTT_ROOT')
Export('rtconfig')
# prepare building environment
objs = PrepareBuilding(env, RTT_ROOT, has_libcpu = False)
stack_size = 4096
stack_lds = open('link_stacksize.lds', 'w')
if GetDepend('__STACKSIZE__'): stack_size = GetDepend('__STACKSIZE__')
stack_lds.write('__STACKSIZE__ = %d;' % stack_size)
stack_lds.close()
# make a building
DoBuilding(TARGET, objs)
from building import *
cwd = GetCurrentDir()
src = Glob('*.c') + Glob('*.cpp')
CPPPATH = [cwd]
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)
Return('group')
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022/12/25 flyingcys first version
*/
#include <rtthread.h>
#include <stdio.h>
int main(void)
{
rt_kprintf("Hello, world\n");
return 0;
}
\ No newline at end of file
menu "BL808_M0 Hardware Drivers Config"
config SOC_BL808
bool
select RT_USING_COMPONENTS_INIT
select RT_USING_USER_MAIN
select ARCH_RISCV_FPU_S
default y
config BSP_USING_JTAG_M0
bool "Enable M0 JTAG "
default n
menu "On-chip Peripheral Drivers"
config BSP_USING_GPIO
bool "Enable GPIO"
select RT_USING_PIN
default y
menuconfig BSP_USING_UART
bool "Enable UART"
default y
select RT_USING_SERIAL
if BSP_USING_UART
config BSP_USING_UART0
bool "Enable UART0"
default y
if BSP_USING_UART0
config BSP_UART0_TXD_PIN
int "uart0 TXD pin number"
default 14
config BSP_UART0_RXD_PIN
int "uart0 RXD pin number"
default 15
endif
endif
endmenu
endmenu
# RT-Thread building script for component
from building import *
cwd = GetCurrentDir()
src = Split('''
board.c
''')
CPPPATH = [cwd]
if GetDepend(['RT_USING_SERIAL']):
if GetDepend(['RT_USING_SERIAL_V2']):
src += ['drv_uart_v2.c']
else:
src += ['drv_uart.c']
# if GetDepend('RT_USING_PIN'):
# src += ['drv_gpio.c']
# if GetDepend('BSP_USING_LCD'):
# src += ['drv_lcd.c']
# src += ['drv_mpylcd.c']
# if GetDepend('RT_USING_HWTIMER'):
# src += ['drv_hw_timer.c']
# if GetDepend('RT_USING_CPUTIME'):
# src += ['drv_cputime.c']
# if GetDepend('RT_USING_I2C'):
# src += ['drv_i2c.c']
# if GetDepend('RT_USING_SPI'):
# src += ['drv_spi.c']
# if GetDepend('RT_USING_PWM'):
# src += ['drv_pwm.c']
# if GetDepend('RT_USING_WDT'):
# src += ['drv_wdt.c']
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH)
objs = [group]
list = os.listdir(cwd)
for item in list:
if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
objs = objs + SConscript(os.path.join(item, 'SConscript'))
Return('objs')
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022/12/25 flyingcys first version
*/
#include <rthw.h>
#include <rtthread.h>
#include "board.h"
#include "drv_uart.h"
static void sipeed_bl_sys_enabe_jtag(int cpuid)
{
GLB_GPIO_Cfg_Type gpio_cfg;
gpio_cfg.drive = 0;
gpio_cfg.smtCtrl = 1;
gpio_cfg.pullType = GPIO_PULL_NONE;
gpio_cfg.gpioMode = GPIO_MODE_AF;
switch (cpuid) {
case 0: {
gpio_cfg.gpioFun = GPIO_FUN_JTAG_M0;
} break;
case 1: {
gpio_cfg.gpioFun = GPIO_FUN_JTAG_D0;
} break;
default: {
} break;
}
gpio_cfg.gpioPin = GLB_GPIO_PIN_0;
GLB_GPIO_Init(&gpio_cfg);
gpio_cfg.gpioPin = GLB_GPIO_PIN_1;
GLB_GPIO_Init(&gpio_cfg);
gpio_cfg.gpioPin = GLB_GPIO_PIN_2;
GLB_GPIO_Init(&gpio_cfg);
gpio_cfg.gpioPin = GLB_GPIO_PIN_3;
GLB_GPIO_Init(&gpio_cfg);
}
static void cmd_jtag_m0(void)
{
sipeed_bl_sys_enabe_jtag(0);
}
static void cmd_jtag_cpu0(void)
{
sipeed_bl_sys_enabe_jtag(1);
}
/* This is the timer interrupt service routine. */
static void mtime_handler(void)
{
rt_tick_increase();
csi_coret_config(CPU_Get_MTimer_Clock() / RT_TICK_PER_SECOND, MTIME_IRQn);
}
void rt_hw_board_init(void)
{
bl_sys_lowlevel_init();
csi_coret_config(CPU_Get_MTimer_Clock() / RT_TICK_PER_SECOND, MTIME_IRQn);
bl_irq_register(MTIME_IRQn, mtime_handler);
bl_irq_enable(MTIME_IRQn);
#ifdef RT_USING_HEAP
/* initialize memory system */
rt_system_heap_init(RT_HW_HEAP_BEGIN, RT_HW_HEAP_END);
#endif
/* UART driver initialization is open by default */
#ifdef RT_USING_SERIAL
rt_hw_uart_init();
#endif
/* Set the shell console output device */
#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#endif
#ifdef RT_USING_COMPONENTS_INIT
rt_components_board_init();
#endif
#ifdef BSP_USING_JTAG_M0
cmd_jtag_m0();
#endif
}
void rt_hw_cpu_reset(void)
{
bl_sys_reset_por();
while(1);
}
MSH_CMD_EXPORT_ALIAS(rt_hw_cpu_reset, reboot, reset machine);
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022/12/25 flyingcys first version
*/
#ifndef BOARD_H__
#define BOARD_H__
#include <rtconfig.h>
#include "core_rv32.h"
#include "bl_sys.h"
#include "bl_irq.h"
#include "bl808_clock.h"
#ifdef BL808
#include "bl808.h"
#elif defined(BL606P)
#include "bl606p.h"
#endif
extern uint8_t _heap_start;
extern uint8_t _heap_size;
#define RT_HW_HEAP_BEGIN (void*)&_heap_start
#define RT_HW_HEAP_END (void*)(&_heap_start + (rt_ubase_t)&_heap_size)
void rt_hw_board_init(void);
#endif
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022/12/25 flyingcys first version
*/
#include <rthw.h>
#include <rtthread.h>
#include <rtdevice.h>
#include "board.h"
#include "drv_uart.h"
struct device_uart
{
struct rt_serial_device serial;
uint8_t port;
uint8_t tx_pin;
uint8_t rx_pin;
};
static void _uart_rx_irq(void *param)
{
struct device_uart *uart = (struct device_uart *)param;;
struct rt_serial_device *serial = &uart->serial;
rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_IND);
}
static int uart_signal_get(uint8_t pin)
{
//TODO no magic number is allowed here
if (pin >= 12 && pin <=23) {
return (pin + 6) % 12;
} else if (pin >= 36 && pin <=45) {
return (pin + 6) % 12;
}
return (pin % 12);
}
static int uart_func_get(uint8_t id, GLB_UART_SIG_FUN_Type uartfunc)
{
switch (id) {
case 0:
return uartfunc;
case 1:
return (GLB_UART_SIG_FUN_UART1_RTS - GLB_UART_SIG_FUN_UART0_RTS) * 1 + uartfunc;
case 2:
return (GLB_UART_SIG_FUN_UART1_RTS - GLB_UART_SIG_FUN_UART0_RTS) * 1 + uartfunc;
default:
/*empty here*/
//TODO should assert here?
return uartfunc;
}
}
static void uart_gpio_demo(uint8_t id, uint8_t tx_pin, uint8_t rx_pin, uint8_t cts_pin, uint8_t rts_pin)
{
GLB_GPIO_Cfg_Type gpio_cfg;
uint8_t uart_func, uart_sig;
//FIXME SWAP set is NOT put here
GLB_UART_Sig_Swap_Set(GLB_UART_SIG_SWAP_GRP_GPIO12_GPIO23, 1);
GLB_UART_Sig_Swap_Set(GLB_UART_SIG_SWAP_GRP_GPIO36_GPIO45, 1);
//common GPIO cfg
gpio_cfg.drive = 0;
gpio_cfg.smtCtrl = 1;
gpio_cfg.gpioMode = GPIO_MODE_AF;
gpio_cfg.pullType = GPIO_PULL_UP;
gpio_cfg.gpioFun = GPIO_FUN_UART;
//cfg for UART Tx
gpio_cfg.gpioPin = GLB_GPIO_PIN_0 + tx_pin;
uart_func = uart_func_get(id, GLB_UART_SIG_FUN_UART0_TXD);
uart_sig = uart_signal_get(gpio_cfg.gpioPin);
GLB_UART_Fun_Sel((GLB_UART_SIG_Type)uart_sig, (GLB_UART_SIG_FUN_Type)uart_func);
GLB_UART_Fun_Sel((GLB_UART_SIG_Type)uart_func, (GLB_UART_SIG_FUN_Type)uart_sig);
GLB_GPIO_Init(&gpio_cfg);
//cfg for UART Rx
gpio_cfg.gpioPin = GLB_GPIO_PIN_0 + rx_pin;
uart_func = uart_func_get(id, GLB_UART_SIG_FUN_UART0_RXD);
uart_sig = uart_signal_get(gpio_cfg.gpioPin);
GLB_UART_Fun_Sel((GLB_UART_SIG_Type)uart_sig, (GLB_UART_SIG_FUN_Type)uart_func);
GLB_UART_Fun_Sel((GLB_UART_SIG_Type)uart_func, (GLB_UART_SIG_FUN_Type)uart_sig);
GLB_GPIO_Init(&gpio_cfg);
//Enable UART clock
GLB_Set_UART_CLK(1, 0, 0);
}
static rt_err_t _uart_configure(struct rt_serial_device *serial, struct serial_configure *cfg)
{
struct device_uart *uart;
uint8_t id;
RT_ASSERT(serial != RT_NULL);
RT_ASSERT(cfg != RT_NULL);
uart = serial->parent.user_data;
RT_ASSERT(uart != RT_NULL);
id = uart->port;
UART_CFG_Type uart_cfg = {
80*1000*1000, /*UART clock from XTAL*/
2000000, /* baudrate */
UART_DATABITS_8, /* data bits */
UART_STOPBITS_1, /* stop bits */
UART_PARITY_NONE, /* parity */
DISABLE, /* Disable auto flow control */
DISABLE, /* Disable rx input de-glitch function */
DISABLE, /* Disable RTS output SW control mode */
DISABLE, /* Disable tx output SW control mode */
DISABLE, /* Disable tx lin mode */
DISABLE, /* Disable rx lin mode */
0, /* Tx break bit count for lin mode */
UART_LSB_FIRST, /* UART each data byte is send out LSB-first */
};
UART_FifoCfg_Type fifoCfg = {
16, /* TX FIFO threshold */
16, /* RX FIFO threshold */
DISABLE, /* Disable tx dma req/ack interface */
DISABLE /* Disable rx dma req/ack interface */
};
/* init debug uart gpio first */
uart_gpio_demo(id, uart->tx_pin, uart->rx_pin, 0xff, 0xff);
/* disable all interrupt */
UART_IntMask(id, UART_INT_ALL, MASK);
/* disable uart before config */
UART_Disable(id, UART_TXRX);
uart_cfg.baudRate = cfg->baud_rate;
switch (cfg->data_bits)
{
case DATA_BITS_5:
uart_cfg.dataBits = UART_DATABITS_5;
break;
case DATA_BITS_6:
uart_cfg.dataBits = UART_DATABITS_6;
break;
case DATA_BITS_7:
uart_cfg.dataBits = UART_DATABITS_7;
break;
case DATA_BITS_8:
uart_cfg.dataBits = UART_DATABITS_8;
break;
default:
uart_cfg.dataBits = UART_DATABITS_8;
break;
}
switch (cfg->stop_bits)
{
case STOP_BITS_1:
uart_cfg.stopBits = UART_STOPBITS_1;
break;
case STOP_BITS_2:
uart_cfg.stopBits = UART_STOPBITS_2;
break;
default:
uart_cfg.stopBits = UART_STOPBITS_1;
break;
}
switch (cfg->parity)
{
case PARITY_NONE:
uart_cfg.parity = UART_PARITY_NONE;
break;
case PARITY_ODD:
uart_cfg.parity = UART_PARITY_ODD;
break;
case PARITY_EVEN:
uart_cfg.parity = UART_PARITY_EVEN;
break;
default:
uart_cfg.parity = UART_PARITY_NONE;
break;
}
/* uart init with configuration */
UART_Init(id, &uart_cfg);
/* UART fifo configuration */
UART_FifoConfig(id, &fifoCfg);
/* Enable tx free run mode */
UART_TxFreeRun(id, ENABLE);
/* Set rx time-out value */
UART_SetRxTimeoutValue(id, UART_DEFAULT_RTO_TIMEOUT);
/* enable uart */
UART_AutoBaudDetection(id, 0);
UART_Enable(id, UART_TXRX);
return RT_EOK;
}
static rt_err_t _uart_control(struct rt_serial_device *serial, int cmd, void *arg)
{
struct device_uart *uart;
RT_ASSERT(serial != RT_NULL);
uart = serial->parent.user_data;
RT_ASSERT(uart != RT_NULL);
switch (cmd)
{
/* disable interrupt */
case RT_DEVICE_CTRL_CLR_INT:
bl_uart_int_disable(uart->port);
bl_uart_int_rx_notify_unregister(uart->port, _uart_rx_irq, uart);
break;
/* enable interrupt */
case RT_DEVICE_CTRL_SET_INT:
bl_uart_int_rx_notify_register(uart->port, _uart_rx_irq, uart);
bl_uart_int_enable(uart->port);
break;
}
return RT_EOK;
}
static int _uart_putc(struct rt_serial_device *serial, char c)
{
struct device_uart *uart;
RT_ASSERT(serial != RT_NULL);
uart = serial->parent.user_data;
RT_ASSERT(uart != RT_NULL);
bl_uart_data_send(uart->port, c);
return 1;
}
static int _uart_getc(struct rt_serial_device *serial)
{
int ch = -1;
struct device_uart *uart;
RT_ASSERT(serial != RT_NULL);
uart = serial->parent.user_data;
RT_ASSERT(uart != RT_NULL);
ch = bl_uart_data_recv(uart->port);
return ch;
}
static const struct rt_uart_ops _uart_ops =
{
.configure = _uart_configure,
.control = _uart_control,
.putc = _uart_putc,
.getc = _uart_getc,
.dma_transmit = RT_NULL
};
/*
* UART Initiation
*/
int rt_hw_uart_init(void)
{
rt_err_t result = 0;
struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT;
struct rt_serial_device *serial;
struct device_uart *uart;
#ifdef BSP_USING_UART0
static struct device_uart uart0;
serial = &uart0.serial;
uart = &uart0;
serial->ops = &_uart_ops;
serial->config = config;
serial->config.baud_rate = 2000000;
uart->port = 0;
uart->tx_pin = BSP_UART0_TXD_PIN;
uart->rx_pin = BSP_UART0_RXD_PIN;
/* register USART device */
result = rt_hw_serial_register(serial,
"uart0",
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
uart);
RT_ASSERT(result == RT_EOK);
#endif
return 0;
}
\ No newline at end of file
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022/12/25 flyingcys first version
*/
#ifndef __DRV_USART_H__
#define __DRV_USART_H__
#include <rtthread.h>
#include "rtdevice.h"
#include <rthw.h>
#include "bl_uart.h"
#include "bl808_uart.h"
#include "uart_config.h"
int rt_hw_uart_init(void);
#endif /* __DRV_USART_H__ */
import os
from building import *
cwd = GetCurrentDir()
# add general drivers
src = Split('''
platform/soc/bl808/startup_bl808/evb/src/startup_interrupt.c
platform/soc/bl808/startup_bl808/evb/src/startup_bl606p.c
platform/soc/bl808/startup_bl808/evb/src/debug.c
platform/soc/bl808/startup_bl808/evb/src/boot/gcc/start_load.c
platform/soc/bl808/startup_bl808/evb/src/boot/gcc/startup.S
''')
path = [cwd,
cwd + r'/platform/soc/bl808/bl808_e907_std/bl808_bsp_driver/regs',
cwd + r'/platform/soc/bl808/bl808_e907_std/bl808_bsp_driver/startup/m0/source',
cwd + r'/platform/soc/bl808/bl808_e907_std/bl808_bsp_driver/std_drv/inc',
cwd + r'/platform/soc/bl808/bl808_e907_std/bl808_bsp_driver/risc-v/Core/Include',
cwd + r'/platform/soc/bl808/bl808_e907_std/bl808_bsp_driver/hal_drv/default_config',
cwd + r'/platform/soc/bl808/bl808_e907_std/common/misc',
cwd + r'/platform/soc/bl808/bl808_e907_std/common/soft_crc']
src += Split("""
stage/blog/blog.c
utils/src/utils_log.c
stage/blfdt/src/fdt.c
stage/blfdt/src/fdt_ro.c
stage/blfdt/src/fdt_wip.c
stage/blfdt/src/fdt_sw.c
stage/blfdt/src/fdt_rw.c
stage/blfdt/src/fdt_strerror.c
stage/blfdt/src/fdt_empty_tree.c
stage/blfdt/src/fdt_addresses.c
stage/blfdt/src/fdt_overlay.c
""")
path += [cwd + r'/stage/blog',
cwd + r'/stage/blfdt/inc',
cwd + r'/utils/include'
]
# platform/hosal/bl808_e907_hal/bl_pm.c
# platform/hosal/bl808_e907_hal/bl_sec.c
# platform/hosal/bl808_e907_hal/bl_timer.c
# platform/hosal/bl808_e907_hal/hal_board.c
# platform/hosal/bl808_e907_hal/hal_sdh.c
# platform/hosal/bl808_e907_hal/hosal_adc.c
# platform/hosal/bl808_e907_hal/hosal_dma.c
# platform/hosal/bl808_e907_hal/hosal_pwm.c
# platform/hosal/bl808_e907_hal/hosal_spi.c
# platform/hosal/bl808_e907_hal/hosal_uart.c
# platform/hosal/bl808_e907_hal/hal_sdh.c
src += Split("""
platform/hosal/bl808_e907_hal/bl_uart.c
platform/hosal/bl808_e907_hal/bl_irq.c
platform/hosal/bl808_e907_hal/bl_chip.c
platform/hosal/bl808_e907_hal/bl_flash.c
platform/hosal/bl808_e907_hal/bl_wifi.c
platform/hosal/bl808_e907_hal/bl_efuse.c
platform/hosal/bl808_e907_hal/bl_sys.c
platform/hosal/bl808_e907_hal/bl_boot2.c
platform/hosal/bl808_e907_hal/bl_ipc.c
platform/hosal/bl808_e907_hal/bl_cam.c
platform/hosal/bl808_e907_hal/bl_audio.c
platform/hosal/bl808_e907_hal/bl_sdh.c
platform/hosal/bl808_e907_hal/hal_boot2.c
platform/hosal/bl808_e907_hal/hal_sys.c
platform/hosal/bl808_e907_hal/bl_psram.c
platform/hosal/bl808_e907_hal/bl_mm_clock.c
platform/hosal/bl808_e907_hal/hal_board.c
platform/soc/bl808/bl808_e907_std/common/misc/misc.c
platform/soc/bl808/bl808_e907_std/common/soft_crc/softcrc.c
""")
src += Split("""
platform/soc/bl808/bl808_e907_std/bl808_bsp_driver/std_drv/src/bl808_common.c
platform/soc/bl808/bl808_e907_std/bl808_bsp_driver/std_drv/src/bl808_clock.c
platform/soc/bl808/bl808_e907_std/bl808_bsp_driver/std_drv/src/bl808_uart.c
platform/soc/bl808/bl808_e907_std/bl808_bsp_driver/std_drv/src/bl808_glb.c
platform/soc/bl808/bl808_e907_std/bl808_bsp_driver/std_drv/src/bl808_glb_gpio.c
platform/soc/bl808/bl808_e907_std/bl808_bsp_driver/std_drv/src/bl808_pds.c
platform/soc/bl808/bl808_e907_std/bl808_bsp_driver/std_drv/src/bl808_hbn.c
platform/soc/bl808/bl808_e907_std/bl808_bsp_driver/std_drv/src/bl808_sflash.c
platform/soc/bl808/bl808_e907_std/bl808_bsp_driver/std_drv/src/bl808_xip_sflash.c
platform/soc/bl808/bl808_e907_std/bl808_bsp_driver/std_drv/src/bl808_sf_cfg.c
platform/soc/bl808/bl808_e907_std/bl808_bsp_driver/std_drv/src/bl808_ef_ctrl.c
platform/soc/bl808/bl808_e907_std/bl808_bsp_driver/std_drv/src/bl808_sf_ctrl.c
""")
path += [cwd + r'/platform/hosal/bl808_e907_hal']
libpath = []
libs = []
group = DefineGroup('Libraries', src, depend = [''], CPPPATH = path, LIBS = libs, LIBPATH = libpath)
Return('group')
/*
* Copyright (c) 2016-2022 Bouffalolab.
*
* This file is part of
* *** Bouffalolab Software Dev Kit ***
* (see www.bouffalolab.com).
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of Bouffalo Lab nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _HOSAL_ADAPTER_H_
#define _HOSAL_ADAPTER_H_
#include <stdint.h>
uintptr_t hosal_adpt_critical_enter(void);
void hosal_adpt_critical_exit(uintptr_t);
#endif
/*
* Copyright (c) 2016-2022 Bouffalolab.
*
* This file is part of
* *** Bouffalolab Software Dev Kit ***
* (see www.bouffalolab.com).
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of Bouffalo Lab nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "hosal_adapter.h"
#include "FreeRTOS.h"
#include "task.h"
uintptr_t hosal_adpt_critical_enter(void)
{
taskENTER_CRITICAL();
return 0;
}
void hosal_adpt_critical_exit(uintptr_t irq_state)
{
(void)irq_state;
taskEXIT_CRITICAL();
}
/*
* Copyright (c) 2016-2022 Bouffalolab.
*
* This file is part of
* *** Bouffalolab Software Dev Kit ***
* (see www.bouffalolab.com).
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of Bouffalo Lab nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "bl_audio.h"
#include "bl808.h"
#include "bl808_audio.h"
#include "bl808_glb.h"
#include "bl808_hbn.h"
#include "bl808_dma.h"
#include "bl_irq.h"
// #include <FreeRTOS.h>
// #include <portable.h>
static bl_audio_dev_t *gp_audio_dac_dev = NULL;
#define AUDIO_DMA_ID DMA0_ID
#define AUDIO_TX_DMA_CHANNLE DMA_CH0
#define AUDIO_RX_DMA_CHANNLE DMA_CH1
static struct DMA_Control_Reg dmaCtrlRegVal={
.TransferSize = 1000,
.SBSize = DMA_BURST_SIZE_8,
.DBSize = DMA_BURST_SIZE_8,
.SWidth = DMA_TRNS_WIDTH_16BITS,
.DWidth = DMA_TRNS_WIDTH_16BITS,
.SI = DMA_MINC_ENABLE,
.DI = DMA_MINC_DISABLE,
.dst_min_mode = DISABLE,
.dst_add_mode = DISABLE,
.fix_cnt = 0,
.I = 1,
};
static DMA_LLI_Cfg_Type lliCfg={
DMA_TRNS_M2P,
DMA_REQ_NONE,
DMA_REQ_AUDIO_TX,
};
static int __hw_init(bl_audio_dev_t *p_dev)
{
Audio_FifoCfg_Type audioFifoCfg;
Audio_Clock_CFG_Type audioClockCfg = {
AUDIO_ADC_16_KHZ,
AUDIO_DAC_16_KHZ,
DISABLE,
DISABLE,
DISABLE,
};
Audio_Volume_Cfg_Type audioVolumeCfg = {
AUIDO_MUTE_DIRECTLY,
AUIDO_RAMP_RATE_2_FS,
AUIDO_RAMP_RATE_2_FS,
AUIDO_VOLUME_UPDATE_FORCE,
AUIDO_ZERO_CROSS_RATE_2_FS,
AUIDO_RAMP_RATE_2_FS,
AUIDO_ZERO_CROSS_RATE_2_FS,
};
GLB_Config_AUDIO_PLL(GLB_XTAL_40M, audioPllCfg_451P584M);
/* ungate audio */
GLB_PER_Clock_UnGate(GLB_AHB_CLOCK_AUDIO);
/* enable dac clock*/
GLB_Set_Audio_DAC_CLK(ENABLE, 19);
/* enable adc clock*/
GLB_Set_Audio_ADC_CLK(ENABLE, 19);
Audio_Poweron();
switch (p_dev->samplerate) {
case AUDIO_8_KHZ:
audioClockCfg.dac_clock = AUDIO_DAC_8_KHZ;
printf("samplerate 8K\r\n");
break;
case AUDIO_16_KHZ:
audioClockCfg.dac_clock = AUDIO_DAC_16_KHZ;
printf("samplerate 16K\r\n");
break;
case AUDIO_24_KHZ:
audioClockCfg.dac_clock = AUDIO_DAC_24_KHZ;
printf("samplerate 24K\r\n");
break;
case AUDIO_32_KHZ:
audioClockCfg.dac_clock = AUDIO_DAC_32_KHZ;
printf("samplerate 32K\r\n");
break;
case AUDIO_48_KHZ:
audioClockCfg.dac_clock = AUDIO_DAC_48_KHZ;
printf("samplerate 48K\r\n");
break;
case AUDIO_96_KHZ:
audioClockCfg.dac_clock = AUDIO_DAC_96_KHZ;
printf("samplerate 96K\r\n");
break;
case AUDIO_192_KHZ:
audioClockCfg.dac_clock = AUDIO_DAC_192_KHZ;
printf("samplerate 192K\r\n");
break;
default:
printf("samplerate NULL\r\n");
break;
}
Audio_Clock_Init(&audioClockCfg);
//set mute ramp
Audio_DAC_Software_Volume_Config(AUDIO_DAC_0, &audioVolumeCfg);
if (p_dev->rx_channel == STEREO_CHANNEL) {
Audio_DAC_Software_Volume_Config(AUDIO_DAC_1, &audioVolumeCfg);
}
Audio_DAC_Set_Volume_Reg(ENABLE, 0, AUDIO_PLAY_DEFAULT_INITIAL_VOLUME);
Audio_DAC_Enable(AUDIO_DAC_0);
if (p_dev->rx_channel == STEREO_CHANNEL) {
Audio_DAC_Enable(AUDIO_DAC_1);
}
Audio_DAC_Set_Mute(ENABLE, 0, AUDIO_UNMUTE);
switch (p_dev->playBitWidth) {
case AUDIO_BIT_WIDTH_16:
audioFifoCfg.resolution = AUDIO_RES_16_BITS;
audioFifoCfg.ailgnMode = AUDIO_FIFO_AILGN_MSB_AT_BIT15;
printf("BitWidth 16\r\n");
break;
case AUDIO_BIT_WIDTH_24:
audioFifoCfg.resolution = AUDIO_RES_20_BITS;
audioFifoCfg.ailgnMode = AUDIO_FIFO_AILGN_MSB_AT_BIT23;
printf("BitWidth 24\r\n");
break;
case AUDIO_BIT_WIDTH_32:
audioFifoCfg.resolution = AUDIO_RES_20_BITS;
audioFifoCfg.ailgnMode = AUDIO_FIFO_AILGN_MSB_AT_BIT31;
printf("BitWidth 32\r\n");
break;
default:
printf("BitWidth NULL\r\n");
break;
}
audioFifoCfg.FifoIntThreshold = AUDIO_DEFAULT_TX_DRQ_THR;
audioFifoCfg.dmaThresholdMode = AUDIO_DRQ_EQUEL_TO_IRQ;
audioFifoCfg.dmaEn = ENABLE;
Audio_TxFifoConfig(&audioFifoCfg);
Audio_TxFifoDisable(p_dev->tx_channel);
if (p_dev->rx_enable) {
Audio_ADC_Software_Volume_Config(AUDIO_ADC_0, &audioVolumeCfg);
if (p_dev->rx_channel == STEREO_CHANNEL) {
Audio_ADC_Software_Volume_Config(AUDIO_ADC_1, &audioVolumeCfg);
}
Audio_ADC_Set_Volume_Reg(ENABLE, 0, AUDIO_PLAY_DEFAULT_INITIAL_VOLUME);
Audio_ADC_Enable(AUDIO_ADC_0);
if (p_dev->rx_channel == STEREO_CHANNEL) {
Audio_ADC_Enable(AUDIO_ADC_1);
}
Audio_ADC_Set_Mute(ENABLE, 0, AUDIO_UNMUTE);
audioFifoCfg.FifoIntThreshold = AUDIO_DEFAULT_RX_DRQ_THR;
Audio_RxFifoConfig(&audioFifoCfg);
Audio_RxFifoDisable(p_dev->rx_channel);
}
Auido_IntMask(AUDIO_INT_NUM_ALL, MASK);
return 0;
}
static void __audio_lli_init(bl_audio_dev_t *p_dev)
{
p_dev->lli_tx_buffer_size = p_dev->lli_tx_buffer_size / 2;
switch (p_dev->playBitWidth) {
case AUDIO_BIT_WIDTH_16:
dmaCtrlRegVal.SWidth = DMA_TRNS_WIDTH_16BITS;
dmaCtrlRegVal.DWidth = DMA_TRNS_WIDTH_16BITS;
dmaCtrlRegVal.SBSize = DMA_BURST_SIZE_8;
dmaCtrlRegVal.DBSize = DMA_BURST_SIZE_8;
dmaCtrlRegVal.TransferSize = p_dev->lli_tx_buffer_size / 2;
break;
case AUDIO_BIT_WIDTH_24:
dmaCtrlRegVal.SWidth = DMA_TRNS_WIDTH_32BITS;
dmaCtrlRegVal.DWidth = DMA_TRNS_WIDTH_32BITS;
dmaCtrlRegVal.SBSize = DMA_BURST_SIZE_4;
dmaCtrlRegVal.DBSize = DMA_BURST_SIZE_4;
dmaCtrlRegVal.TransferSize = p_dev->lli_tx_buffer_size / 4;
break;
case AUDIO_BIT_WIDTH_32:
dmaCtrlRegVal.SWidth = DMA_TRNS_WIDTH_32BITS;
dmaCtrlRegVal.DWidth = DMA_TRNS_WIDTH_32BITS;
dmaCtrlRegVal.SBSize = DMA_BURST_SIZE_4;
dmaCtrlRegVal.DBSize = DMA_BURST_SIZE_4;
dmaCtrlRegVal.TransferSize = p_dev->lli_tx_buffer_size / 4;
break;
default:
//private_bflb_platform_printf("BIT WIDTH Is Invaild\r\n");
break;
}
p_dev->lli_tx_list[0].srcDmaAddr = (uint32_t)p_dev->lli_tx_buffer;
p_dev->lli_tx_list[0].destDmaAddr = AUDIO_TX_FIFO_ADDR;
p_dev->lli_tx_list[0].nextLLI = (uint32_t)&p_dev->lli_tx_list[1];
p_dev->lli_tx_list[0].dmaCtrl= dmaCtrlRegVal;
p_dev->lli_tx_list[1].srcDmaAddr = (uint32_t)p_dev->lli_tx_buffer + p_dev->lli_tx_buffer_size;
p_dev->lli_tx_list[1].destDmaAddr = AUDIO_TX_FIFO_ADDR;
p_dev->lli_tx_list[1].nextLLI=(uint32_t)&p_dev->lli_tx_list[0];
p_dev->lli_tx_list[1].dmaCtrl= dmaCtrlRegVal;
DMA_LLI_Init(AUDIO_DMA_ID, AUDIO_TX_DMA_CHANNLE, &lliCfg);
DMA_LLI_Update(AUDIO_DMA_ID, AUDIO_TX_DMA_CHANNLE, (uint32_t)&gp_audio_dac_dev->lli_tx_list);
if (p_dev->rx_enable) {
p_dev->lli_rx_buffer_size = p_dev->lli_rx_buffer_size / 2;
switch (p_dev->playBitWidth) {
case AUDIO_BIT_WIDTH_16:
dmaCtrlRegVal.SWidth = DMA_TRNS_WIDTH_16BITS;
dmaCtrlRegVal.DWidth = DMA_TRNS_WIDTH_16BITS;
dmaCtrlRegVal.SBSize = DMA_BURST_SIZE_8;
dmaCtrlRegVal.DBSize = DMA_BURST_SIZE_8;
dmaCtrlRegVal.TransferSize = p_dev->lli_rx_buffer_size / 2;
break;
case AUDIO_BIT_WIDTH_24:
dmaCtrlRegVal.SWidth = DMA_TRNS_WIDTH_32BITS;
dmaCtrlRegVal.DWidth = DMA_TRNS_WIDTH_32BITS;
dmaCtrlRegVal.SBSize = DMA_BURST_SIZE_4;
dmaCtrlRegVal.DBSize = DMA_BURST_SIZE_4;
dmaCtrlRegVal.TransferSize = p_dev->lli_rx_buffer_size / 4;
break;
case AUDIO_BIT_WIDTH_32:
dmaCtrlRegVal.SWidth = DMA_TRNS_WIDTH_32BITS;
dmaCtrlRegVal.DWidth = DMA_TRNS_WIDTH_32BITS;
dmaCtrlRegVal.SBSize = DMA_BURST_SIZE_4;
dmaCtrlRegVal.DBSize = DMA_BURST_SIZE_4;
dmaCtrlRegVal.TransferSize = p_dev->lli_rx_buffer_size / 4;
break;
default:
//private_bflb_platform_printf("BIT WIDTH Is Invaild\r\n");
break;
}
dmaCtrlRegVal.SI = DMA_MINC_DISABLE;
dmaCtrlRegVal.DI = DMA_MINC_ENABLE;
p_dev->lli_rx_list[0].srcDmaAddr = AUDIO_RX_FIFO_ADDR;
p_dev->lli_rx_list[0].destDmaAddr = (uint32_t)p_dev->lli_rx_buffer;
p_dev->lli_rx_list[0].nextLLI = (uint32_t)&p_dev->lli_rx_list[1];
p_dev->lli_rx_list[0].dmaCtrl= dmaCtrlRegVal;
p_dev->lli_rx_list[1].srcDmaAddr = AUDIO_RX_FIFO_ADDR;
p_dev->lli_rx_list[1].destDmaAddr = (uint32_t)p_dev->lli_rx_buffer + p_dev->lli_rx_buffer_size;
p_dev->lli_rx_list[1].nextLLI=(uint32_t)&p_dev->lli_rx_list[0];
p_dev->lli_rx_list[1].dmaCtrl= dmaCtrlRegVal;
lliCfg.dir = DMA_TRNS_P2M;
lliCfg.srcPeriph = DMA_REQ_AUDIO_RX;
lliCfg.dstPeriph = DMA_REQ_NONE;
DMA_LLI_Init(AUDIO_DMA_ID, AUDIO_RX_DMA_CHANNLE, &lliCfg);
DMA_LLI_Update(AUDIO_DMA_ID, AUDIO_RX_DMA_CHANNLE, (uint32_t)&gp_audio_dac_dev->lli_rx_list);
}
}
static int __dma_int_clear(DMA_ID_Type dma_id, int ch)
{
uint32_t tmpVal;
uint32_t intClr;
/* Get DMA register */
const uint32_t dmaAddr[] = { DMA0_BASE, DMA1_BASE, DMA2_BASE };
uint32_t DMAChs = dmaAddr[dma_id];
tmpVal = BL_RD_REG(DMAChs, DMA_INTTCSTATUS);
if((BL_GET_REG_BITS_VAL(tmpVal, DMA_INTTCSTATUS) & (1 << ch)) != 0) {
/* Clear interrupt */
tmpVal = BL_RD_REG(DMAChs, DMA_INTTCCLEAR);
intClr = BL_GET_REG_BITS_VAL(tmpVal, DMA_INTTCCLEAR);
intClr |= (1 << ch);
tmpVal = BL_SET_REG_BITS_VAL(tmpVal, DMA_INTTCCLEAR, intClr);
BL_WR_REG(DMAChs, DMA_INTTCCLEAR, tmpVal);
}
tmpVal = BL_RD_REG(DMAChs, DMA_INTERRORSTATUS);
if((BL_GET_REG_BITS_VAL(tmpVal, DMA_INTERRORSTATUS) & (1 << ch)) != 0) {
/*Clear interrupt */
tmpVal = BL_RD_REG(DMAChs, DMA_INTERRCLR);
intClr = BL_GET_REG_BITS_VAL(tmpVal, DMA_INTERRCLR);
intClr |= (1 << ch);
tmpVal = BL_SET_REG_BITS_VAL(tmpVal, DMA_INTERRCLR, intClr);
BL_WR_REG(DMAChs, DMA_INTERRCLR, tmpVal);
}
return 0;
}
static void __dma_irq_handler(void)
{
uint32_t tmpVal, count;
int ret, size;
tmpVal = BL_RD_REG(DMA0_BASE, DMA_INTTCSTATUS);
if ((BL_GET_REG_BITS_VAL(tmpVal, DMA_INTTCSTATUS) & (1 << AUDIO_TX_DMA_CHANNLE)) != 0) {
__dma_int_clear(AUDIO_DMA_ID, AUDIO_TX_DMA_CHANNLE); //clear int first
if ( NULL == gp_audio_dac_dev) {
return;
}
size = gp_audio_dac_dev->lli_tx_buffer_size;
/*FIXME: set dma chain resonable option first 2 chain*/
if (gp_audio_dac_dev->usr_cb) {
/* software count may reliable*/
//if (++gp_audio_dac_dev->pingpang >= 2) {
// gp_audio_dac_dev->pingpang = 0;
//}
count = ((*(volatile uint32_t *)0x2000c110) & (0x3FF << 20)) >> 20;
if (0x01 == (count & 0x01)) {
ret = gp_audio_dac_dev->usr_cb(gp_audio_dac_dev->p_usr_arg,
gp_audio_dac_dev->lli_tx_buffer,
size,
gp_audio_dac_dev->is_underrun);
} else {
ret = gp_audio_dac_dev->usr_cb(gp_audio_dac_dev->p_usr_arg,
gp_audio_dac_dev->lli_tx_buffer + size,
size,
gp_audio_dac_dev->is_underrun);
}
if (ret != 0) {
gp_audio_dac_dev->is_underrun = 1;
} else {
gp_audio_dac_dev->is_underrun = 0;
}
}
}
if((BL_GET_REG_BITS_VAL(tmpVal, DMA_INTTCSTATUS) & (1 << AUDIO_RX_DMA_CHANNLE)) != 0) {
__dma_int_clear(AUDIO_DMA_ID, AUDIO_RX_DMA_CHANNLE); //clear int first
if ( NULL == gp_audio_dac_dev) {
return;
}
size = gp_audio_dac_dev->lli_rx_buffer_size;
if (gp_audio_dac_dev->usr_rx_cb) {
count = ((*(volatile uint32_t *)0x2000c210) & (0x3FF << 20)) >> 20;
/*FIXME: set dma multi chains*/
if (0x01 == (count & 0x01)) {
ret = gp_audio_dac_dev->usr_rx_cb(gp_audio_dac_dev->p_usr_rx_arg,
gp_audio_dac_dev->lli_rx_buffer,
size,
gp_audio_dac_dev->is_overflow);
} else {
ret = gp_audio_dac_dev->usr_rx_cb(gp_audio_dac_dev->p_usr_rx_arg,
gp_audio_dac_dev->lli_rx_buffer + size,
size,
gp_audio_dac_dev->is_overflow);
}
if (ret != 0) {
gp_audio_dac_dev->is_overflow = 1;
} else {
gp_audio_dac_dev->is_overflow = 0;
}
}
}
}
int bl_audio_samplerate_set (bl_audio_dev_t *p_dev, Audio_Samplerate_Type samplerate)
{
p_dev->samplerate = samplerate;
return 0;
}
int bl_audio_tx_ready_config(bl_audio_dev_t *p_dev,
audio_callback_tx_ready_t cb,
void *p_arg)
{
if (NULL == p_dev) {
printf("tx ready config fail dev is null\r\n");
return -1;
}
p_dev->usr_cb = cb;
p_dev->p_usr_arg = p_arg;
return 0;
}
int bl_audio_rx_ready_config(bl_audio_dev_t *p_dev,
audio_callback_rx_ready_t cb,
void *p_arg)
{
if (NULL == p_dev) {
printf("rx ready config fail dev is null\r\n");
return -1;
}
p_dev->usr_rx_cb = cb;
p_dev->p_usr_rx_arg = p_arg;
return 0;
}
int bl_audio_tx_buffer_config (bl_audio_dev_t *p_dev, void **ptr_mem, uint32_t bufsize)
{
if (NULL == p_dev->lli_tx_buffer) {
p_dev->lli_tx_buffer = pvPortMalloc(bufsize);
}
if (NULL == p_dev->lli_tx_buffer) {
printf("malloc tx buffer fail\r\n");
return -1;
}
memset(p_dev->lli_tx_buffer, 0, bufsize);
csi_dcache_clean_range((void *)(p_dev->lli_tx_buffer), bufsize);
*ptr_mem = p_dev->lli_tx_buffer;
p_dev->lli_tx_buffer_size = bufsize;
return 0;
}
int bl_audio_rx_buffer_config (bl_audio_dev_t *p_dev,
void **ptr_mem,
uint32_t bufsize)
{
if (NULL == p_dev->lli_rx_buffer) {
p_dev->lli_rx_buffer = pvPortMalloc(bufsize);
}
if (NULL == p_dev->lli_rx_buffer) {
printf("malloc rx buffer fail\r\n");
return -1;
}
memset(p_dev->lli_rx_buffer, 0, bufsize);
csi_dcache_clean_range((void *)(p_dev->lli_rx_buffer), bufsize);
*ptr_mem = p_dev->lli_rx_buffer;
p_dev->lli_rx_buffer_size = bufsize;
return 0;
}
int bl_audio_start (bl_audio_dev_t *p_dev)
{
if (NULL == p_dev) {
printf("audio start fail dev is NULL\r\n");
return -1;
}
__hw_init(p_dev);
GLB_Set_DMA_CLK(ENABLE, GLB_DMA0_CLK_CH0);
GLB_PER_Clock_UnGate(GLB_AHB_CLOCK_DMA_0);
DMA_Disable(AUDIO_DMA_ID);
DMA_Channel_Disable(AUDIO_DMA_ID, AUDIO_TX_DMA_CHANNLE);
DMA_Channel_Disable(AUDIO_DMA_ID, AUDIO_RX_DMA_CHANNLE);
DMA_IntMask(AUDIO_DMA_ID, AUDIO_TX_DMA_CHANNLE, DMA_INT_ALL, MASK);
DMA_IntMask(AUDIO_DMA_ID, AUDIO_TX_DMA_CHANNLE, DMA_INT_TCOMPLETED, UNMASK);
DMA_IntMask(AUDIO_DMA_ID, AUDIO_RX_DMA_CHANNLE, DMA_INT_ALL, MASK);
DMA_IntMask(AUDIO_DMA_ID, AUDIO_RX_DMA_CHANNLE, DMA_INT_TCOMPLETED, UNMASK);
bl_irq_register(DMA0_ALL_IRQn, __dma_irq_handler);
bl_irq_enable(DMA0_ALL_IRQn);
__audio_lli_init(p_dev);
csi_dcache_clean();
DMA_Enable(AUDIO_DMA_ID);
DMA_Channel_Enable(AUDIO_DMA_ID, AUDIO_TX_DMA_CHANNLE);
Audio_TxFifoEnable(p_dev->tx_channel);
if (p_dev->rx_enable) {
DMA_Channel_Enable(AUDIO_DMA_ID, AUDIO_RX_DMA_CHANNLE);
Audio_RxFifoEnable(p_dev->rx_channel);
}
return 0;
}
int bl_audio_stop (bl_audio_dev_t *p_dev)
{
gp_audio_dac_dev->pingpang = 0;
DMA_Disable(AUDIO_DMA_ID);
DMA_Channel_Disable(AUDIO_DMA_ID, AUDIO_TX_DMA_CHANNLE);
if (p_dev->rx_enable) {
DMA_Channel_Disable(AUDIO_DMA_ID, AUDIO_RX_DMA_CHANNLE);
}
bl_irq_disable(DMA0_ALL_IRQn);
return 0;
}
int bl_audio_init (bl_audio_dev_t *p_dev)
{
if (NULL == p_dev) {
printf("init audio fail dev is null\r\n");
return -1;
}
memset(p_dev, 0, sizeof(bl_audio_dev_t));
gp_audio_dac_dev = p_dev;
return 0;
}
int bl_audio_deinit (bl_audio_dev_t *p_dev)
{
vPortFree(p_dev->lli_tx_buffer);
p_dev->lli_tx_buffer = NULL;
vPortFree(p_dev->lli_rx_buffer);
p_dev->lli_tx_buffer = NULL;
return 0;
}
/*
* Copyright (c) 2016-2022 Bouffalolab.
*
* This file is part of
* *** Bouffalolab Software Dev Kit ***
* (see www.bouffalolab.com).
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of Bouffalo Lab nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __BL_AUDIO_H__
#define __BL_AUDIO_H__
#include <stdint.h>
#include <bl808_dma.h>
#include "bl808_audio.h"
typedef int (*audio_callback_rx_ready_t)(void *usrdata, uint8_t *audiodata, int len, int is_overflow);
typedef int (*audio_callback_tx_ready_t)(void *uerdata, uint8_t *audiodata, int len, int is_underrun);
#define AUDIO_PLAY_DEFAULT_INITIAL_VOLUME 0x0
#define AUDIO_TX_FIFO_ADDR AUDIO_BASE + 0x94
#define AUDIO_RX_FIFO_ADDR AUDIO_BASE + 0x88
#define AUDIO_DEFAULT_TX_DRQ_THR 8
#define AUDIO_DEFAULT_RX_DRQ_THR 8
typedef enum {
LEFT_CHANNEL = 1, /*!< select mono mode left only */
RIGHT_CHANNEL = 2, /*!< select mono mode right only */
STEREO_CHANNEL = 3, /*!< select stereo */
THREE_CHANNEL = 7, /*!< select Three */
} Audio_Channel_Type;
typedef enum {
AUDIO_BIT_WIDTH_16, /*!< 16 bit */
AUDIO_BIT_WIDTH_24, /*!< 24 bit */
AUDIO_BIT_WIDTH_32, /*!< 32 bit */
} Audio_BitWidth_Type;
typedef enum {
AUDIO_8_KHZ, /*!< Audio DAC Clock set as 8KHZ */
AUDIO_16_KHZ, /*!< Audio DAC Clock set as 16KHZ */
AUDIO_24_KHZ, /*!< Audio DAC Clock set as 24KHZ */
AUDIO_32_KHZ, /*!< Audio DAC Clock set as 32KHZ */
AUDIO_48_KHZ, /*!< Audio DAC Clock set as 48KHZ */
AUDIO_96_KHZ, /*!< Audio DAC Clock set as 96KHZ */
AUDIO_192_KHZ, /*!< Audio DAC Clock set as 192KHZ */
} Audio_Samplerate_Type;
typedef struct {
uint8_t pingpang;
DMA_LLI_Ctrl_Type lli_tx_list[2];
DMA_LLI_Ctrl_Type lli_rx_list[2];
uint8_t *lli_tx_buffer;
uint32_t lli_tx_buffer_size;
uint8_t *lli_rx_buffer;
uint32_t lli_rx_buffer_size;
int is_underrun;
int is_overflow;
audio_callback_tx_ready_t usr_cb;
audio_callback_rx_ready_t usr_rx_cb;
void *p_usr_arg;
void *p_usr_rx_arg;
Audio_Samplerate_Type samplerate;
Audio_BitWidth_Type playBitWidth;
Audio_Channel_Type tx_channel;
Audio_Channel_Type rx_channel;
uint8_t rx_enable;
} bl_audio_dev_t;
int bl_audio_init (bl_audio_dev_t *p_dev);
int bl_audio_deinit (bl_audio_dev_t *p_dev);
int bl_audio_start (bl_audio_dev_t *p_dev);
int bl_audio_stop (bl_audio_dev_t *p_dev);
int bl_audio_tx_buffer_config (bl_audio_dev_t *p_dev,
void **ptr_mem,
uint32_t bufsize);
int bl_audio_rx_buffer_config (bl_audio_dev_t *p_dev,
void **ptr_mem,
uint32_t bufsize);
int bl_audio_tx_ready_config(bl_audio_dev_t *p_dev,
audio_callback_tx_ready_t cb,
void *p_arg);
int bl_audio_rx_ready_config(bl_audio_dev_t *p_dev,
audio_callback_rx_ready_t cb,
void *p_arg);
int bl_audio_samplerate_set (bl_audio_dev_t *p_dev,
Audio_Samplerate_Type samplerate);
#endif
/*
* Copyright (c) 2016-2022 Bouffalolab.
*
* This file is part of
* *** Bouffalolab Software Dev Kit ***
* (see www.bouffalolab.com).
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of Bouffalo Lab nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <string.h>
#include <softcrc.h>
#include <bl_flash.h>
#include <bl_boot2.h>
PtTable_Error_Type PtTable_Update_Entry(const SPI_Flash_Cfg_Type *pFlashCfg,
PtTable_ID_Type targetTableID,
PtTable_Stuff_Config *ptStuff,
PtTable_Entry_Config *ptEntry)
{
uint32_t i=0;
BL_Err_Type ret;
uint32_t writeAddr;
uint32_t entriesLen;
PtTable_Config *ptTable;
PtTable_Entry_Config *ptEntries;
uint32_t *pCrc32;
if(ptEntry==NULL||ptStuff==NULL){
return PT_ERROR_PARAMETER;
}
ptTable=&ptStuff->ptTable;
ptEntries=ptStuff->ptEntries;
if(targetTableID==PT_TABLE_ID_INVALID){
return PT_ERROR_TABLE_NOT_VALID;
}
if(targetTableID==PT_TABLE_ID_0){
writeAddr=BFLB_PT_TABLE0_ADDRESS;
}else{
writeAddr=BFLB_PT_TABLE1_ADDRESS;
}
for (i=0; i < ptTable->entryCnt; i++) {
if (ptEntries[i].type == ptEntry->type){
memcpy(&ptEntries[i],ptEntry,sizeof(PtTable_Entry_Config));
break;
}
}
if(i==ptTable->entryCnt){
/* Not found this entry ,add new one */
if(ptTable->entryCnt<PT_ENTRY_MAX){
memcpy(&ptEntries[ptTable->entryCnt],ptEntry,sizeof(PtTable_Entry_Config));
ptTable->entryCnt++;
}else{
return PT_ERROR_ENTRY_UPDATE_FAIL;
}
}
/* Prepare write back to flash */
/* Update age */
ptTable->age++;
ptTable->crc32=BFLB_Soft_CRC32((uint8_t*)ptTable,sizeof(PtTable_Config)-4);
/* Update entries CRC */
entriesLen=ptTable->entryCnt*sizeof(PtTable_Entry_Config);
pCrc32=(uint32_t *)((uint32_t)ptEntries+entriesLen);
*pCrc32=BFLB_Soft_CRC32((uint8_t *)&ptEntries[0],entriesLen);
/* Write back to flash */
/* Erase flash first */
ret=bl_flash_erase(writeAddr,sizeof(PtTable_Config)+entriesLen+4);
if(ret!=SUCCESS){
//MSG_ERR("Flash Erase error\r\n");
return PT_ERROR_FALSH_WRITE;
}
/* Write flash */
ret=bl_flash_write(writeAddr,(uint8_t *)ptStuff,sizeof(PtTable_Stuff_Config));
if(ret!=SUCCESS){
//MSG_ERR("Flash Write error\r\n");
return PT_ERROR_FALSH_WRITE;
}
return PT_ERROR_SUCCESS;
}
PtTable_Error_Type PtTable_Get_Active_Entries(PtTable_Stuff_Config *ptStuff,
PtTable_Entry_Type type,
PtTable_Entry_Config *ptEntry)
{
uint32_t i=0;
if(ptStuff==NULL||ptEntry==NULL){
return PT_ERROR_PARAMETER;
}
for (i=0; i < ptStuff->ptTable.entryCnt; i++) {
if (ptStuff->ptEntries[i].type == type){
memcpy(ptEntry,&ptStuff->ptEntries[i],sizeof(PtTable_Entry_Config));
return PT_ERROR_SUCCESS;
}
}
return PT_ERROR_ENTRY_NOT_FOUND;
}
PtTable_Error_Type PtTable_Get_Active_Entries_By_Name(PtTable_Stuff_Config *ptStuff,
uint8_t *name,
PtTable_Entry_Config *ptEntry)
{
uint32_t i=0;
uint32_t len=strlen((char *)name);
if(ptStuff==NULL||ptEntry==NULL){
return PT_ERROR_PARAMETER;
}
for (i=0; i < ptStuff->ptTable.entryCnt; i++) {
if (strlen((char *)ptStuff->ptEntries[i].name) == len &&
memcmp((char *)ptStuff->ptEntries[i].name,(char *)name,len) == 0){
//BL602_MemCpy_Fast(ptEntry,&ptStuff->ptEntries[i],sizeof(PtTable_Entry_Config));
/*FIXME :need fast memory copy*/
memcpy(ptEntry,&ptStuff->ptEntries[i],sizeof(PtTable_Entry_Config));
return PT_ERROR_SUCCESS;
}
}
return PT_ERROR_ENTRY_NOT_FOUND;
}
/*
* Copyright (c) 2016-2022 Bouffalolab.
*
* This file is part of
* *** Bouffalolab Software Dev Kit ***
* (see www.bouffalolab.com).
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of Bouffalo Lab nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __BL606_PARTITION_H__
#define __BL606_PARTITION_H__
#include <stdint.h>
//FIXME no BL808/BL606p header file including is Allowed here
#ifdef BL808
#include <bl808_common.h>
#include <bl808_sflash.h>
#elif defined(BL606P)
#include <bl606p_common.h>
#include <bl606p_sflash.h>
#else
#error "Use CHIP BL808/BL606P for this module"
#endif
/** @addtogroup BL606_Common_Driver
* @{
*/
/** @addtogroup PARTITION
* @{
*/
/** @defgroup PARTITION_Public_Types
* @{
*/
/**
* @brief Partition table error type definition
*/
typedef enum {
PT_ERROR_SUCCESS, /*!< Partition table error type:success */
PT_ERROR_TABLE_NOT_VALID, /*!< Partition table error type:entry not found */
PT_ERROR_ENTRY_NOT_FOUND, /*!< Partition table error type:entry not found */
PT_ERROR_ENTRY_UPDATE_FAIL, /*!< Partition table error type:entry update fail */
PT_ERROR_CRC32, /*!< Partition table error type:crc32 error */
PT_ERROR_PARAMETER, /*!< Partition table error type:input parameter error */
PT_ERROR_FALSH_READ, /*!< Partition table error type:flash read error */
PT_ERROR_FALSH_WRITE, /*!< Partition table error type:flash write error */
PT_ERROR_FALSH_ERASE, /*!< Partition table error type:flash erase error */
}PtTable_Error_Type;
/**
* @brief Partition id type definition
*/
typedef enum {
PT_TABLE_ID_0, /*!< Partition table ID 0 */
PT_TABLE_ID_1, /*!< Partition table ID 1 */
PT_TABLE_ID_INVALID, /*!< Partition table ID invalid */
}PtTable_ID_Type;
/**
* @brief Partition id type definition
*/
typedef enum {
PT_ENTRY_FW_CPU0, /*!< Partition entry type:CPU0 firmware */
PT_ENTRY_FW_CPU1, /*!< Partition entry type:CPU1 firmware */
PT_ENTRY_MAX=16, /*!< Partition entry type:Max */
}PtTable_Entry_Type;
/**
* @brief Partition table config definition
*/
typedef struct {
uint32_t magicCode; /*!< Partition table magic code */
uint16_t version; /*!< Partition table verdion */
uint16_t entryCnt; /*!< Partition table entry count */
uint32_t age; /*!< Partition table age */
uint32_t crc32; /*!< Partition table CRC32 value */
}PtTable_Config;
/**
* @brief Partition table entry config definition
*/
typedef struct {
uint8_t type; /*!< Partition entry type */
uint8_t device; /*!< Partition entry device */
uint8_t activeIndex; /*!< Partition entry active index */
uint8_t name[9]; /*!< Partition entry name */
uint32_t Address[2]; /*!< Partition entry start address */
uint32_t maxLen[2]; /*!< Partition entry max length */
uint32_t len; /*!< Partition entry length */
uint32_t age; /*!< Partition entry age */
}PtTable_Entry_Config;
/**
* @brief Partition table stuff config definition
*/
typedef struct {
PtTable_Config ptTable; /*!< Partition table */
PtTable_Entry_Config ptEntries[PT_ENTRY_MAX]; /*!< Partition entries */
uint32_t crc32; /*!< Partition entries crc32 */
}PtTable_Stuff_Config;
/*@} end of group PARTITION_Public_Types */
/** @defgroup PARTITION_Public_Constants
* @{
*/
/** @defgroup PTTABLE_ERROR_TYPE
* @{
*/
#define IS_PTTABLE_ERROR_TYPE(type) (((type) == PT_ERROR_SUCCESS) || \
((type) == PT_ERROR_TABLE_NOT_VALID) || \
((type) == PT_ERROR_ENTRY_NOT_FOUND) || \
((type) == PT_ERROR_ENTRY_UPDATE_FAIL) || \
((type) == PT_ERROR_CRC32) || \
((type) == PT_ERROR_PARAMETER) || \
((type) == PT_ERROR_FALSH_READ) || \
((type) == PT_ERROR_FALSH_WRITE) || \
((type) == PT_ERROR_FALSH_ERASE))
/** @defgroup PTTABLE_ID_TYPE
* @{
*/
#define IS_PTTABLE_ID_TYPE(type) (((type) == PT_TABLE_ID_0) || \
((type) == PT_TABLE_ID_1) || \
((type) == PT_TABLE_ID_INVALID))
/** @defgroup PTTABLE_ENTRY_TYPE
* @{
*/
#define IS_PTTABLE_ENTRY_TYPE(type) (((type) == PT_ENTRY_FW_CPU0) || \
((type) == PT_ENTRY_FW_CPU1) || \
((type) == PT_ENTRY_MAX))
/*@} end of group PARTITION_Public_Constants */
/** @defgroup PARTITION_Public_Macros
* @{
*/
#define BFLB_PT_TABLE0_ADDRESS 0xE000
#define BFLB_PT_TABLE1_ADDRESS 0xF000
#define BFLB_PT_MAGIC_CODE 0x54504642
typedef BL_Err_Type (*pPtTable_Flash_Erase)(uint32_t startaddr,uint32_t endaddr);
typedef BL_Err_Type (*pPtTable_Flash_Write)(uint32_t addr,uint8_t *data, uint32_t len);
typedef BL_Err_Type (*pPtTable_Flash_Read)(uint32_t addr,uint8_t *data, uint32_t len);
/*@} end of group PARTITION_Public_Macros */
/** @defgroup PARTITION_Public_Functions
* @{
*/
void PtTable_Set_Flash_Operation(pPtTable_Flash_Erase erase,pPtTable_Flash_Write write);
PtTable_ID_Type PtTable_Get_Active_Partition(const SPI_Flash_Cfg_Type *pFlashCfg,
PtTable_Stuff_Config ptStuff[2]);
PtTable_Error_Type PtTable_Get_Active_Entries(PtTable_Stuff_Config *ptStuff,
PtTable_Entry_Type type,
PtTable_Entry_Config *ptEntry);
PtTable_Error_Type PtTable_Update_Entry(const SPI_Flash_Cfg_Type *pFlashCfg,
PtTable_ID_Type targetTableID,
PtTable_Stuff_Config *ptStuff,
PtTable_Entry_Config *ptEntry);
PtTable_Error_Type PtTable_Create(const SPI_Flash_Cfg_Type *pFlashCfg,PtTable_ID_Type ptID);
PtTable_Error_Type PtTable_Get_Active_Entries_By_Name(PtTable_Stuff_Config *ptStuff,
uint8_t *name,
PtTable_Entry_Config *ptEntry);
/*@} end of group PARTITION_Public_Functions */
/*@} end of group PARTITION */
/*@} end of group BL606_Common_Driver */
#endif /* __BL606_PARTITION_H__ */
/*
* Copyright (c) 2016-2022 Bouffalolab.
*
* This file is part of
* *** Bouffalolab Software Dev Kit ***
* (see www.bouffalolab.com).
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of Bouffalo Lab nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <string.h>
#include <stdio.h>
#include <bl808_mjpeg.h>
#include "bl_cam.h"
#define MJPEG_DEFAULT_ADDR 0x80400000
int bl_cam_mjpeg_buffer_info_get(uint32_t *mjpeg_addr, uint32_t *mjpeg_size)
{
int ret = 0;
uint32_t tmpVal;
*mjpeg_addr = BL_RD_REG(MJPEG_BASE, MJPEG_JPEG_FRAME_ADDR);
if (*mjpeg_addr == MJPEG_DEFAULT_ADDR) {
*mjpeg_addr = 0;
ret = -1;
goto exit;
}
tmpVal = BL_RD_REG(MJPEG_BASE, MJPEG_CONTROL_1);
tmpVal = BL_GET_REG_BITS_VAL(tmpVal, MJPEG_REG_W_XLEN);
/*get memory brust size 0 sigle; 1 INCR4; 2 INCR8; 3 INCR16*/
*mjpeg_size = BL_RD_REG(MJPEG_BASE, MJPEG_JPEG_STORE_MEMORY);
*mjpeg_size = *mjpeg_size << (3 + tmpVal + (tmpVal > 0 ? 1 : 0));
exit:
return ret;
}
int bl_cam_mjpeg_get(uint8_t **ptr, uint32_t *len)
{
int ret = 0;
MJPEG_Frame_Info mjpeg_info;
MJPEG_Get_Frame_Info(&mjpeg_info);
if (mjpeg_info.validFrames > 0) {
*ptr = (uint8_t *)(uintptr_t)mjpeg_info.curFrameAddr;
*len = mjpeg_info.curFrameBytes;
} else {
ret = -1;
}
return ret;
}
int bl_cam_mjpeg_pop(void)
{
MJPEG_Pop_Frame();
return 0;
}
/*
* Copyright (c) 2016-2022 Bouffalolab.
*
* This file is part of
* *** Bouffalolab Software Dev Kit ***
* (see www.bouffalolab.com).
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of Bouffalo Lab nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __BL_CAM_H__
#define __BL_CAM_H__
int bl_cam_mjpeg_get(uint8_t **ptr, uint32_t *len);
int bl_cam_mjpeg_pop();
int bl_cam_mjpeg_buffer_info_get(uint32_t *mjpeg_addr, uint32_t *mjpeg_size);
#endif
/*
* Copyright (c) 2016-2022 Bouffalolab.
*
* This file is part of
* *** Bouffalolab Software Dev Kit ***
* (see www.bouffalolab.com).
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of Bouffalo Lab nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdint.h>
#include <string.h>
#include "bl_chip.h"
static unsigned long _risc_isa_info(void)
{
volatile unsigned long misa = 0;
__asm volatile( "csrr %0, misa" : "=r"( misa ) );
return misa;
}
int bl_chip_info(char *info)
{
unsigned long misa;
int i;
i = sizeof(misa) * 8 - 2; // MXL field pos
misa = _risc_isa_info();
/*Get base ISA*/
i = (misa >> i);
switch (i) {
case 1:
{
memcpy(info, "RV32", 4);
info += 4;
}
break;
case 2:
{
memcpy(info, "RV64", 4);
info += 4;
}
break;
case 3:
{
memcpy(info, "RV128", 5);
info += 5;
}
break;
default:
{
memcpy(info, "RVxx", 4);
info += 4;
}
break;
}
/*add switch*/
*(info++) = '-';
/*add feature set*/
for (i = 0; i < 26; i++) {
if (misa & (1 << i)) {
/*Feature bit is set*/
*(info++) = ('A' + i);
}
}
*info = '\0';
return 0;
}
static const char bannder_shadow_bl602[] = {
0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88,
0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x95, 0x97, 0x20, 0xe2, 0x96,
0x88, 0xe2, 0x96, 0x88, 0xe2, 0x95, 0x97, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x96,
0x88, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x95, 0x97, 0x20, 0x20,
0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88,
0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x95, 0x97, 0x20, 0xe2, 0x96,
0x88, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x96,
0x88, 0xe2, 0x96, 0x88, 0xe2, 0x95, 0x97, 0x0a, 0x0d, 0xe2, 0x96, 0x88, 0xe2,
0x96, 0x88, 0xe2, 0x95, 0x94, 0xe2, 0x95, 0x90, 0xe2, 0x95, 0x90, 0xe2,
0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x95, 0x97, 0xe2, 0x96, 0x88, 0xe2,
0x96, 0x88, 0xe2, 0x95, 0x91, 0x20, 0x20, 0x20, 0x20, 0x20, 0xe2, 0x96,
0x88, 0xe2, 0x96, 0x88, 0xe2, 0x95, 0x94, 0xe2, 0x95, 0x90, 0xe2, 0x95,
0x90, 0xe2, 0x95, 0x90, 0xe2, 0x95, 0x90, 0xe2, 0x95, 0x9d, 0x20, 0xe2,
0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x95, 0x94, 0xe2, 0x95, 0x90, 0xe2,
0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2,
0x95, 0x97, 0xe2, 0x95, 0x9a, 0xe2, 0x95, 0x90, 0xe2, 0x95, 0x90, 0xe2,
0x95, 0x90, 0xe2, 0x95, 0x90, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2,
0x95, 0x97, 0x0a, 0x0d, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88,
0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x95, 0x94,
0xe2, 0x95, 0x9d, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x95, 0x91,
0x20, 0x20, 0x20, 0x20, 0x20, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2,
0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2,
0x96, 0x88, 0xe2, 0x95, 0x97, 0x20, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88,
0xe2, 0x95, 0x91, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x95, 0x94,
0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x95, 0x91, 0x20, 0xe2, 0x96,
0x88, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x96,
0x88, 0xe2, 0x95, 0x94, 0xe2, 0x95, 0x9d, 0x0a, 0x0d, 0xe2, 0x96, 0x88, 0xe2,
0x96, 0x88, 0xe2, 0x95, 0x94, 0xe2, 0x95, 0x90, 0xe2, 0x95, 0x90, 0xe2,
0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x95, 0x97, 0xe2, 0x96, 0x88, 0xe2,
0x96, 0x88, 0xe2, 0x95, 0x91, 0x20, 0x20, 0x20, 0x20, 0x20, 0xe2, 0x96,
0x88, 0xe2, 0x96, 0x88, 0xe2, 0x95, 0x94, 0xe2, 0x95, 0x90, 0xe2, 0x95,
0x90, 0xe2, 0x95, 0x90, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x95,
0x97, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x96,
0x88, 0xe2, 0x95, 0x94, 0xe2, 0x95, 0x9d, 0xe2, 0x96, 0x88, 0xe2, 0x96,
0x88, 0xe2, 0x95, 0x91, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x95,
0x94, 0xe2, 0x95, 0x90, 0xe2, 0x95, 0x90, 0xe2, 0x95, 0x90, 0xe2, 0x95,
0x9d, 0x0a, 0x0d, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2,
0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x95, 0x94, 0xe2,
0x95, 0x9d, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2,
0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2,
0x95, 0x97, 0xe2, 0x95, 0x9a, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2,
0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2,
0x95, 0x94, 0xe2, 0x95, 0x9d, 0xe2, 0x95, 0x9a, 0xe2, 0x96, 0x88, 0xe2,
0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2,
0x96, 0x88, 0xe2, 0x95, 0x94, 0xe2, 0x95, 0x9d, 0xe2, 0x96, 0x88, 0xe2,
0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2,
0x96, 0x88, 0xe2, 0x96, 0x88, 0xe2, 0x95, 0x97, 0x0a, 0x0d, 0xe2, 0x95, 0x9a,
0xe2, 0x95, 0x90, 0xe2, 0x95, 0x90, 0xe2, 0x95, 0x90, 0xe2, 0x95, 0x90,
0xe2, 0x95, 0x90, 0xe2, 0x95, 0x9d, 0x20, 0xe2, 0x95, 0x9a, 0xe2, 0x95,
0x90, 0xe2, 0x95, 0x90, 0xe2, 0x95, 0x90, 0xe2, 0x95, 0x90, 0xe2, 0x95,
0x90, 0xe2, 0x95, 0x90, 0xe2, 0x95, 0x9d, 0x20, 0xe2, 0x95, 0x9a, 0xe2,
0x95, 0x90, 0xe2, 0x95, 0x90, 0xe2, 0x95, 0x90, 0xe2, 0x95, 0x90, 0xe2,
0x95, 0x90, 0xe2, 0x95, 0x9d, 0x20, 0x20, 0xe2, 0x95, 0x9a, 0xe2, 0x95,
0x90, 0xe2, 0x95, 0x90, 0xe2, 0x95, 0x90, 0xe2, 0x95, 0x90, 0xe2, 0x95,
0x90, 0xe2, 0x95, 0x9d, 0x20, 0xe2, 0x95, 0x9a, 0xe2, 0x95, 0x90, 0xe2,
0x95, 0x90, 0xe2, 0x95, 0x90, 0xe2, 0x95, 0x90, 0xe2, 0x95, 0x90, 0xe2,
0x95, 0x90, 0xe2, 0x95, 0x9d, 0x0a, 0x0d, 0x00
};
int bl_chip_banner(const char **banner)
{
*banner = bannder_shadow_bl602;
return 0;
}
int bl_chip_memory_ram(int *num, unsigned int addr[], unsigned int size[], char desc[][6])
{
return -1;
#if 0
if (*num < 3) {
/*only one block memory*/
return -1;
}
*num = 3;
extern uint8_t _ld_ram_size0, _ld_ram_addr0;
extern uint8_t _ld_ram_size1, _ld_ram_addr1;
extern uint8_t _ld_ram_size2, _ld_ram_addr2;
addr[0] = (unsigned int)&_ld_ram_addr0;
size[0] = (unsigned int)&_ld_ram_size0;
strcpy(desc[0], "flash");
addr[1] = (unsigned int)&_ld_ram_addr1;
size[1] = (unsigned int)&_ld_ram_size1;
strcpy(desc[1], "tcm");
addr[2] = (unsigned int)&_ld_ram_addr2;
size[2] = (unsigned int)&_ld_ram_size2;
strcpy(desc[2], "wifi");
return 0;
#endif
}
/*
* Copyright (c) 2016-2022 Bouffalolab.
*
* This file is part of
* *** Bouffalolab Software Dev Kit ***
* (see www.bouffalolab.com).
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of Bouffalo Lab nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __BL_CHIP_H__
#define __BL_CHIP_H__
int bl_chip_info(char *info);
int bl_chip_banner(const char **banner);
int bl_chip_memory_ram(int *num, unsigned int addr[], unsigned int size[], char desc[][6]);
#endif
/*
* Copyright (c) 2016-2022 Bouffalolab.
*
* This file is part of
* *** Bouffalolab Software Dev Kit ***
* (see www.bouffalolab.com).
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of Bouffalo Lab nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "bl_efuse.h"
#ifdef BL808
#include <bl808_ef_ctrl.h>
#include "bl808_mfg_media.h"
#include "bl808_glb.h"
#endif
int bl_efuse_read_mac(uint8_t mac[6])
{
EF_Ctrl_Read_MAC_Address(mac);
return 0;
}
int bl_efuse_read_mac_factory(uint8_t mac[6])
{
// if (0 == mfg_media_read_macaddr(mac, 1)) {
// return 0;
//zys }
return -1;
}
int bl_efuse_read_capcode(uint8_t *capcode)
{
// if (0 == mfg_media_read_xtal_capcode(capcode, 1)) {
// return 0;
//zys }
return -1;
}
int bl_efuse_read_pwroft(int8_t poweroffset[14])
{
// if (0 == mfg_media_read_poweroffset(poweroffset, 1)) {
// return 0;
//}
return -1;
}
int bl_efuse_ctrl_program_R0(uint32_t index, uint32_t *data, uint32_t len)
{
uint8_t hdiv=0, bdiv=0;
HBN_MCU_ROOT_CLK_Type rtClk=(HBN_MCU_ROOT_CLK_Type)HBN_Get_MCU_Root_CLK_Sel();
// bdiv=GLB_Get_BCLK_Div();
// hdiv=GLB_Get_HCLK_Div();
hdiv = BL_GET_REG_BITS_VAL(BL_RD_REG(GLB_BASE, GLB_SYS_CFG0), GLB_REG_HCLK_DIV);
bdiv = BL_GET_REG_BITS_VAL(BL_RD_REG(GLB_BASE, GLB_SYS_CFG0), GLB_REG_BCLK_DIV);
HBN_Set_MCU_Root_CLK_Sel(HBN_MCU_ROOT_CLK_XCLK);
EF_Ctrl_Program_Direct_R0(index, data, len);
GLB_Set_System_CLK_Div(hdiv, bdiv);
HBN_Set_MCU_Root_CLK_Sel(rtClk);
return 0;
}
int bl_efuse_ctrl_read_R0(uint32_t index, uint32_t *data, uint32_t len)
{
uint8_t hdiv=0, bdiv=0;
HBN_MCU_ROOT_CLK_Type rtClk=(HBN_MCU_ROOT_CLK_Type)HBN_Get_MCU_Root_CLK_Sel();
// bdiv=GLB_Get_BCLK_Div();
// hdiv=GLB_Get_HCLK_Div();
hdiv = BL_GET_REG_BITS_VAL(BL_RD_REG(GLB_BASE, GLB_SYS_CFG0), GLB_REG_HCLK_DIV);
bdiv = BL_GET_REG_BITS_VAL(BL_RD_REG(GLB_BASE, GLB_SYS_CFG0), GLB_REG_BCLK_DIV);
HBN_Set_MCU_Root_CLK_Sel(HBN_MCU_ROOT_CLK_XCLK);
EF_Ctrl_Read_Direct_R0(index, data, len);
GLB_Set_System_CLK_Div(hdiv, bdiv);
HBN_Set_MCU_Root_CLK_Sel(rtClk);
return 0;
}
int bl_efuse_read_mac_opt(uint8_t slot, uint8_t mac[6], uint8_t reload)
{
uint8_t hdiv=0, bdiv=0;
HBN_MCU_ROOT_CLK_Type rtClk=(HBN_MCU_ROOT_CLK_Type)HBN_Get_MCU_Root_CLK_Sel();
// bdiv=GLB_Get_BCLK_Div();
// hdiv=GLB_Get_HCLK_Div();
hdiv = BL_GET_REG_BITS_VAL(BL_RD_REG(GLB_BASE, GLB_SYS_CFG0), GLB_REG_HCLK_DIV);
bdiv = BL_GET_REG_BITS_VAL(BL_RD_REG(GLB_BASE, GLB_SYS_CFG0), GLB_REG_BCLK_DIV);
HBN_Set_MCU_Root_CLK_Sel(HBN_MCU_ROOT_CLK_XCLK);
// EF_Ctrl_Read_MAC_Address_Opt(slot, mac, reload);
EF_Ctrl_Read_MAC_Address_Raw(mac);
GLB_Set_System_CLK_Div(hdiv, bdiv);
HBN_Set_MCU_Root_CLK_Sel(rtClk);
return 0;
}
/*
* Copyright (c) 2016-2022 Bouffalolab.
*
* This file is part of
* *** Bouffalolab Software Dev Kit ***
* (see www.bouffalolab.com).
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of Bouffalo Lab nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __BL_EFUSE_H__
#define __BL_EFUSE_H__
#include <stdint.h>
int bl_efuse_read_mac(uint8_t mac[6]);
int bl_efuse_read_mac_factory(uint8_t mac[6]);
int bl_efuse_read_capcode(uint8_t *capcode);
int bl_efuse_read_pwroft(int8_t poweroffset[14]);
int bl_efuse_ctrl_program_R0(uint32_t index, uint32_t *data, uint32_t len);
int bl_efuse_ctrl_read_R0(uint32_t index, uint32_t *data, uint32_t len);
int bl_efuse_read_mac_opt(uint8_t slot, uint8_t mac[6], uint8_t reload);
#endif
/*
* Copyright (c) 2016-2022 Bouffalolab.
*
* This file is part of
* *** Bouffalolab Software Dev Kit ***
* (see www.bouffalolab.com).
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of Bouffalo Lab nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __ETHERNETIF_H__
#define __ETHERNETIF_H__
#include "hal_emac.h"
#if CTX_TYPE
#include <utils_list.h>
#endif
#include "lwip/err.h"
#include "lwip/netif.h"
#include "ethernet_phy.h"
#define DHCP_OFF (uint8_t)0
#define DHCP_START (uint8_t)1
#define DHCP_WAIT_ADDRESS (uint8_t)2
#define DHCP_ADDRESS_ASSIGNED (uint8_t)3
#define DHCP_TIMEOUT (uint8_t)4
#define DHCP_LINK_DOWN (uint8_t)5
#if CTX_TYPE
#define ETH_MAX_BUFFER_SIZE (ETH_MAX_PACKET_SIZE)
#define EMAC_TX_COMMON_FLAGS (EMAC_BD_FIELD_MSK(TX_RD) | \
EMAC_BD_FIELD_MSK(TX_IRQ) | \
EMAC_BD_FIELD_MSK(TX_PAD) | \
EMAC_BD_FIELD_MSK(TX_CRC) | \
EMAC_BD_FIELD_MSK(TX_EOF) )
struct unsent_item{
struct utils_list_hdr hdr;
struct pbuf *p;
};
typedef struct {
struct utils_list unsent;
uint8_t Tx_free_bd_num;
uint8_t Rx_free_bd_num;
volatile uint16_t unsent_num;
uint32_t tx_pkt_cnt;
uint32_t rx_pkt_cnt;
uint32_t out_tmr;
uint32_t done_tmr;
}eth_context;
#endif
/* Exported types ------------------------------------------------------------*/
err_t ethernetif_init(struct netif *netif);
void ethernet_link_check_state(struct netif *netif);
void ethernet_link_status_updated(struct netif *netif);
#endif
/*
* Copyright (c) 2016-2022 Bouffalolab.
*
* This file is part of
* *** Bouffalolab Software Dev Kit ***
* (see www.bouffalolab.com).
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of Bouffalo Lab nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <blog.h>
#ifdef BL808
#include <bl808_glb.h>
#include <bl808_xip_sflash.h>
#include <bl808_sf_cfg.h>
#include <bl808_romdriver_e907.h>
#elif defined(BL606P)
#include <bl606p_glb.h>
#include <bl606p_xip_sflash.h>
#include <bl606p_sf_cfg.h>
#include <bl606p_sf_cfg_ext.h>
#include <bl606p_romdriver_e907.h>
#else
#error "Use CHIP BL808/BL606P for this module"
#endif
#include "bl_irq.h"
#define XIP_START_ADDR (0x58000000)
#define ADDR_LIMIT (0x1000000)
#define USER_UNUSED(a) ((void)(a))
static SPI_Flash_Cfg_Type g_flash_cfg;
/**
* @brief flash read data
*
* @param addr
* @param data
* @param len
* @return BL_Err_Type
*/
int ATTR_TCM_SECTION bl_flash_read(uint32_t startaddr, void *data, uint32_t len)
{
BL_Err_Type stat;
uint8_t isAesEnable=0;
GLOBAL_IRQ_SAVE();
XIP_SFlash_Opt_Enter(&isAesEnable);
stat = XIP_SFlash_Read_Need_Lock(&g_flash_cfg, startaddr, data, len, 0, 0);
XIP_SFlash_Opt_Exit(isAesEnable);
GLOBAL_IRQ_RESTORE();
return stat;
}
/**
* @brief flash write data
*
* @param addr
* @param data
* @param len
* @return BL_Err_Type
*/
int ATTR_TCM_SECTION bl_flash_write(uint32_t startaddr, void *data, uint32_t len)
{
BL_Err_Type stat;
uint8_t isAesEnable=0;
GLOBAL_IRQ_SAVE();
XIP_SFlash_Opt_Enter(&isAesEnable);
stat = XIP_SFlash_Write_Need_Lock(&g_flash_cfg, startaddr, data, len, 0, 0);
XIP_SFlash_Opt_Exit(isAesEnable);
GLOBAL_IRQ_RESTORE();
return stat;
}
/**
* @brief flash erase
*
* @param startaddr
* @param endaddr
* @return BL_Err_Type
*/
int ATTR_TCM_SECTION bl_flash_erase(uint32_t startaddr, uint32_t len)
{
BL_Err_Type stat;
uint8_t isAesEnable=0;
GLOBAL_IRQ_SAVE();
XIP_SFlash_Opt_Enter(&isAesEnable);
stat = XIP_SFlash_Erase_Need_Lock(&g_flash_cfg, startaddr, len-1, 0, 0);
XIP_SFlash_Opt_Exit(isAesEnable);
GLOBAL_IRQ_RESTORE();
return stat;
}
/**
* @brief flash read from xip
*
* @param xip addr
* @param dst
* @param len
* @return BL_Err_Type
*/
int bl_flash_read_byxip(uint32_t addr, uint8_t *dst, int len)
{
uint32_t offset;
uint32_t xipaddr;
offset = RomDriver_SF_Ctrl_Get_Flash_Image_Offset(0, 0);
if ((addr < offset) || (addr >= ADDR_LIMIT)) {
// not support or arg err ?
return -1;
}
xipaddr = XIP_START_ADDR - offset + addr;
memcpy(dst, (void *)xipaddr, len);
return 0;
}
/**
* @brief multi flash adapter
*
* @return BL_Err_Type
*/
int ATTR_TCM_SECTION bl_flash_init(void)
{
uint8_t isAesEnable=0;
/* Get flash config identify */
GLOBAL_IRQ_SAVE();
XIP_SFlash_Opt_Enter(&isAesEnable);
SF_Cfg_Flash_Identify_Ext(1, 0x80, 0, &g_flash_cfg, 0, 0);
XIP_SFlash_Opt_Exit(isAesEnable);
GLOBAL_IRQ_RESTORE();
return 0;
}
static void _dump_flash_config()
{
extern uint8_t __boot2_flashCfg_src;
USER_UNUSED(__boot2_flashCfg_src);
blog_info("======= FlashCfg magiccode @%p=======\r\n", &__boot2_flashCfg_src);
blog_info("mid \t\t0x%X\r\n", g_flash_cfg.mid);
blog_info("clkDelay \t0x%X\r\n", g_flash_cfg.clkDelay);
blog_info("clkInvert \t0x%X\r\n", g_flash_cfg.clkInvert);
blog_info("sector size\t%uKBytes\r\n", g_flash_cfg.sectorSize);
blog_info("page size\t%uBytes\r\n", g_flash_cfg.pageSize);
blog_info("---------------------------------------------------------------\r\n");
}
int bl_flash_config_update(void)
{
_dump_flash_config();
return 0;
}
/*
* Copyright (c) 2016-2022 Bouffalolab.
*
* This file is part of
* *** Bouffalolab Software Dev Kit ***
* (see www.bouffalolab.com).
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of Bouffalo Lab nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __BL_FLASH_H__
#define __BL_FLASH_H__
#include <stdint.h>
int bl_flash_erase(uint32_t addr, int len);
int bl_flash_write(uint32_t addr, void *src, int len);
int bl_flash_read(uint32_t addr, void *dst, int len);
int bl_flash_config_update(void);
void* bl_flash_get_flashCfg(void);
int bl_flash_read_byxip(uint32_t addr, uint8_t *dst, int len);
int bl_flash_init(void);
#endif
/*
* Copyright (c) 2016-2022 Bouffalolab.
*
* This file is part of
* *** Bouffalolab Software Dev Kit ***
* (see www.bouffalolab.com).
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of Bouffalo Lab nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "bl_ipc.h"
//FIXME no BL808/BL606p header file including is Allowed here
#ifdef BL808
#include <bl808_glb.h>
#include <bl808_ipc.h>
#elif defined(BL606P)
#include <bl606p_glb.h>
#include <bl606p_ipc.h>
#else
#error "Use CHIP BL808/BL606P for this module"
#endif
extern void IPC_Common_Interrupt_Handler(uint32_t irqStatus, ipcIntCallback *callBack[GLB_CORE_ID_MAX -1]);
extern ipcIntCallback *m0IpcIntCbfArra[GLB_CORE_ID_MAX - 1];
static void ipc_m0_handler(void)
{
uint32_t irqStatus;
irqStatus = IPC_M0_Get_Int_Raw_Status();
IPC_Common_Interrupt_Handler(irqStatus, m0IpcIntCbfArra);
IPC_M0_Clear_Int_By_Word(irqStatus);
}
//FIXME no BL808/BL606p header file including is Allowed here
#ifdef BL808
#include <bl808_glb.h>
#elif defined(BL606P)
#include <bl606p_glb.h>
#else
#error "Use CHIP BL808/BL606P for this module"
#endif
void ipc_m0_init(ipcIntCallback *onLPTriggerCallBack,
ipcIntCallback *onD0TriggerCallBack)
{
IPC_M0_Init(onLPTriggerCallBack, onD0TriggerCallBack);
#ifdef BFLB_USE_HAL_DRIVER
Interrupt_Handler_Register(IPC_M0_IRQn, ipc_m0_handler);
#endif
System_NVIC_SetPriority(IPC_M0_IRQn, 5, 0);
}
/*
* Copyright (c) 2016-2022 Bouffalolab.
*
* This file is part of
* *** Bouffalolab Software Dev Kit ***
* (see www.bouffalolab.com).
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of Bouffalo Lab nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __BL_IPC_H__
#define __BL_IPC_H__
#include <stdint.h>
typedef void(ipcIntCallback)(uint32_t src);
void ipc_m0_init(ipcIntCallback *onLPTriggerCallBack, ipcIntCallback *onD0TriggerCallBack);
#endif
/*
* Copyright (c) 2016-2022 Bouffalolab.
*
* This file is part of
* *** Bouffalolab Software Dev Kit ***
* (see www.bouffalolab.com).
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of Bouffalo Lab nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __BL_IRQ_H__
#define __BL_IRQ_H__
void bl_irq_enable(unsigned int source);
void bl_irq_disable(unsigned int source);
typedef enum {
BL_IRQ_EXCEPTION_TYPE_LOAD_MISALIGN,
BL_IRQ_EXCEPTION_TYPE_STORE_MISALIGN,
BL_IRQ_EXCEPTION_TYPE_ACCESS_ILLEGAL,
BL_IRQ_EXCEPTION_TYPE_ILLEGAL_INSTRUCTION,
} BL_IRQ_EXCEPTION_TYPE_T;
struct irq_ctx {
char *name;
int irqnum;
uint64_t irq_run_time;
};
struct irq_ctx **bl_irq_ctx_list(int *num);
void bl_irq_exception_trigger(BL_IRQ_EXCEPTION_TYPE_T type, void *ptr);
void bl_irq_init(void);
/*The following section define the IRQ handler for other files*/
void bl_sec_aes_IRQHandler(void);
void bl_sec_sha_IRQHandler(void);
void bl_sec_pka_IRQHandler(void);
void bl_dma_IRQHandler(void);
void intc_irq(void);//MAC IRQ
void bl_irq_handler(void);//IPC host IRQ
void bl_irq_register_with_ctx(int irqnum, void *handler, void *ctx);
void bl_irq_register(int irqnum, void *handler);
void bl_irq_unregister(int irqnum, void *handler);
void bl_irq_ctx_get(int irqnum, void **ctx);
int bl_irq_save(void);
void bl_irq_restore(int flags);
void __attribute__((noreturn)) bl_sys_abort(const char *details);
#define GLOBAL_IRQ_SAVE() if (1) { \
int ____global_prev_mie_irq____ = bl_irq_save();
#define GLOBAL_IRQ_RESTORE() \
bl_irq_restore(____global_prev_mie_irq____ ); \
}
#endif
/*
* Copyright (c) 2016-2022 Bouffalolab.
*
* This file is part of
* *** Bouffalolab Software Dev Kit ***
* (see www.bouffalolab.com).
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of Bouffalo Lab nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdint.h>
#include <stdio.h>
#include "bl_mm_clock.h"
//FIXME no BL808/BL606p header file including is Allowed here
#ifdef BL808
#include <bl808_glb.h>
#include <mm_glb_reg.h>
#elif defined(BL606P)
//TODO BL606P H FILE
#include <bl606p_glb.h>
#include <mm_glb_reg.h>
#else
#error "Use CHIP BL808/BL606P for this module"
#endif
static void get_mm_xclk(uint32_t reg_val)
{
uint32_t cpu_pll_clk = 0;
cpu_pll_clk = BL_GET_REG_BITS_VAL(reg_val, MM_GLB_REG_XCLK_CLK_SEL);
switch (cpu_pll_clk) {
case 0:
printf("XCLK select RC32M\r\n");
break;
case 1:
printf("XCLK select XTAL\r\n");
break;
default:
break;
}
}
static void get_mm_cpu_pll_clk(uint32_t reg_val)
{
uint32_t cpu_pll_clk = 0;
cpu_pll_clk = BL_GET_REG_BITS_VAL(reg_val, MM_GLB_REG_CPU_CLK_SEL);
switch (cpu_pll_clk) {
case 0:
printf("MM CPU select 240Mhz\r\n");
break;
case 1:
printf("MM CPU select 320Mhz\r\n");
break;
case 2:
printf("MM CPU select 400Mhz\r\n");
break;
default:
break;
}
}
static void dump_mm_cpu_clk(void)
{
uint32_t tmpVal = 0, cpu_root_clk = 0;
tmpVal = BL_RD_REG(CLKRST_CTRL_BASE, MM_GLB_MM_CLK_CTRL_CPU);
cpu_root_clk = BL_GET_REG_BITS_VAL(tmpVal, MM_GLB_REG_CPU_ROOT_CLK_SEL);
switch (cpu_root_clk) {
case 0:
printf("MM CPU select XCLK--->");
get_mm_xclk(tmpVal);
break;
case 1:
printf("MM CPU select PLL--->");
get_mm_cpu_pll_clk(tmpVal);
break;
default:
break;
}
}
static void dump_mm_bus_clk(void)
{
uint32_t tmpVal = 0, mm_bus_clk = 0;
tmpVal = BL_RD_REG(CLKRST_CTRL_BASE, MM_GLB_MM_CLK_CTRL_CPU);
mm_bus_clk = BL_GET_REG_BITS_VAL(tmpVal, MM_GLB_REG_BCLK1X_SEL);
switch (mm_bus_clk) {
case 0:
printf("MM BUS CLK select XCLK--->");
get_mm_xclk(tmpVal);
break;
case 2:
printf("MM BUS CLK select 160Mhz\r\n");
break;
case 3:
printf("MM BUS CLK select 240Mhz\r\n");
break;
default:
break;
}
}
static void dump_mm_xclk(void)
{
uint32_t tmpVal = 0;
tmpVal = BL_RD_REG(CLKRST_CTRL_BASE, MM_GLB_MM_CLK_CTRL_CPU);
get_mm_xclk(tmpVal);
}
static void dump_mm_uart_clk(void)
{
uint32_t tmpVal = 0, mm_uart_clk = 0;
tmpVal = BL_RD_REG(CLKRST_CTRL_BASE, MM_GLB_MM_CLK_CTRL_CPU);
mm_uart_clk = BL_GET_REG_BITS_VAL(tmpVal, MM_GLB_REG_UART_CLK_SEL);
switch (mm_uart_clk) {
case 0:
printf("UART CLK select MM BUS CLK--->");
dump_mm_bus_clk();
break;
case 1:
printf("UART CLK select 160Mhz\r\n");
break;
case 2:
case 3:
printf("UART CLK select MM XCLK--->");
get_mm_xclk(tmpVal);
break;
default:
break;
}
}
static void dump_mm_i2c_clk(void)
{
uint32_t tmpVal = 0, mm_i2c_clk = 0;
tmpVal = BL_RD_REG(CLKRST_CTRL_BASE, MM_GLB_MM_CLK_CTRL_CPU);
mm_i2c_clk = BL_GET_REG_BITS_VAL(tmpVal, MM_GLB_REG_I2C_CLK_SEL);
switch (mm_i2c_clk) {
case 0:
printf("I2C CLK select MM BUS CLK--->");
dump_mm_bus_clk();
break;
case 1:
printf("I2C CLK select MM XCLK--->");
get_mm_xclk(tmpVal);
break;
default:
break;
}
}
static void dump_mm_spi_clk(void)
{
uint32_t tmpVal = 0, mm_spi_clk = 0;
tmpVal = BL_RD_REG(CLKRST_CTRL_BASE, MM_GLB_MM_CLK_CTRL_CPU);
mm_spi_clk = BL_GET_REG_BITS_VAL(tmpVal, MM_GLB_REG_SPI_CLK_SEL);
switch (mm_spi_clk) {
case 0:
printf("SPI CLK select 160Mhz\r\n");
break;
case 1:
printf("SPI CLK select MM XCLK--->");
get_mm_xclk(tmpVal);
break;
default:
break;
}
}
void bl_mm_clk_dump(void)
{
dump_mm_cpu_clk();
dump_mm_uart_clk();
dump_mm_i2c_clk();
dump_mm_spi_clk();
dump_mm_bus_clk();
dump_mm_xclk();
}
void bl_mm_xclk_config(mm_xclk_type xclk_num)
{
uint32_t tmpVal;
tmpVal = BL_RD_REG(CLKRST_CTRL_BASE, MM_GLB_MM_CLK_CTRL_CPU);
tmpVal = BL_SET_REG_BITS_VAL(tmpVal, MM_GLB_REG_XCLK_CLK_SEL, xclk_num);
BL_WR_REG(CLKRST_CTRL_BASE, MM_GLB_MM_CLK_CTRL_CPU, tmpVal);
}
void bl_mm_bclk_config(mm_bclk_type bclk_num)
{
uint32_t tmpVal;
tmpVal = BL_RD_REG(CLKRST_CTRL_BASE, MM_GLB_MM_CLK_CTRL_CPU);
tmpVal = BL_SET_REG_BITS_VAL(tmpVal, MM_GLB_REG_BCLK1X_SEL, bclk_num);
BL_WR_REG(CLKRST_CTRL_BASE, MM_GLB_MM_CLK_CTRL_CPU, tmpVal);
}
void bl_mm_cpu_root_clk_config(mm_cpu_root_clk_type cpu_root_clk_num)
{
uint32_t tmpVal;
tmpVal = BL_RD_REG(CLKRST_CTRL_BASE, MM_GLB_MM_CLK_CTRL_CPU);
tmpVal = BL_SET_REG_BITS_VAL(tmpVal, MM_GLB_REG_CPU_ROOT_CLK_SEL, cpu_root_clk_num);
BL_WR_REG(CLKRST_CTRL_BASE, MM_GLB_MM_CLK_CTRL_CPU, tmpVal);
}
void bl_mm_cpu_clk_config(mm_cpu_clk_type cpu_clk_num)
{
uint32_t tmpVal;
tmpVal = BL_RD_REG(CLKRST_CTRL_BASE, MM_GLB_MM_CLK_CTRL_CPU);
tmpVal = BL_SET_REG_BITS_VAL(tmpVal, MM_GLB_REG_CPU_CLK_SEL, cpu_clk_num);
BL_WR_REG(CLKRST_CTRL_BASE, MM_GLB_MM_CLK_CTRL_CPU, tmpVal);
}
void bl_mm_spi_clk_config(mm_spi_clk_type spi_clk_num)
{
uint32_t tmpVal;
tmpVal = BL_RD_REG(CLKRST_CTRL_BASE, MM_GLB_MM_CLK_CTRL_CPU);
tmpVal = BL_SET_REG_BITS_VAL(tmpVal, MM_GLB_REG_SPI_CLK_SEL, spi_clk_num);
BL_WR_REG(CLKRST_CTRL_BASE, MM_GLB_MM_CLK_CTRL_CPU, tmpVal);
}
void bl_mm_i2c_clk_config(mm_i2c_clk_type i2c_clk_num)
{
uint32_t tmpVal;
tmpVal = BL_RD_REG(CLKRST_CTRL_BASE, MM_GLB_MM_CLK_CTRL_CPU);
tmpVal = BL_SET_REG_BITS_VAL(tmpVal, MM_GLB_REG_I2C_CLK_SEL, i2c_clk_num);
BL_WR_REG(CLKRST_CTRL_BASE, MM_GLB_MM_CLK_CTRL_CPU, tmpVal);
}
void bl_mm_uart_clk_config(mm_uart_clk_type uart_clk_num)
{
uint32_t tmpVal;
tmpVal = BL_RD_REG(CLKRST_CTRL_BASE, MM_GLB_MM_CLK_CTRL_CPU);
tmpVal = BL_SET_REG_BITS_VAL(tmpVal, MM_GLB_REG_UART_CLK_SEL, uart_clk_num);
BL_WR_REG(CLKRST_CTRL_BASE, MM_GLB_MM_CLK_CTRL_CPU, tmpVal);
}
/*
* Copyright (c) 2016-2022 Bouffalolab.
*
* This file is part of
* *** Bouffalolab Software Dev Kit ***
* (see www.bouffalolab.com).
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of Bouffalo Lab nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __BL_PSRAM_H__
#define __BL_PSRAM_H__
int bl_psram_init(void);
#endif
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册