[update][bsp_common][examples] sync demo and bsp common with hal driver"

This commit is contained in:
jzlv 2022-01-13 16:34:24 +08:00
parent b6c09e3e2b
commit 1f4fd9061d
27 changed files with 386 additions and 2288 deletions

View File

@ -115,6 +115,10 @@ void spi0_init(void)
DMA_DEV(dma_ch3)->transfer_mode = DMA_LLI_ONCE_MODE;
DMA_DEV(dma_ch3)->src_req = DMA_REQUEST_NONE;
DMA_DEV(dma_ch3)->dst_req = DMA_REQUEST_SPI0_TX;
DMA_DEV(dma_ch3)->src_addr_inc = DMA_ADDR_INCREMENT_ENABLE;
DMA_DEV(dma_ch3)->dst_addr_inc = DMA_ADDR_INCREMENT_DISABLE;
DMA_DEV(dma_ch3)->src_burst_size = DMA_BURST_1BYTE;
DMA_DEV(dma_ch3)->dst_burst_size = DMA_BURST_1BYTE;
DMA_DEV(dma_ch3)->src_width = DMA_TRANSFER_WIDTH_8BIT;
DMA_DEV(dma_ch3)->dst_width = DMA_TRANSFER_WIDTH_8BIT;
device_open(dma_ch3, 0);
@ -136,6 +140,10 @@ void spi0_init(void)
DMA_DEV(dma_ch4)->transfer_mode = DMA_LLI_ONCE_MODE;
DMA_DEV(dma_ch4)->src_req = DMA_REQUEST_SPI0_RX;
DMA_DEV(dma_ch4)->dst_req = DMA_REQUEST_NONE;
DMA_DEV(dma_ch4)->src_addr_inc = DMA_ADDR_INCREMENT_DISABLE;
DMA_DEV(dma_ch4)->dst_addr_inc = DMA_ADDR_INCREMENT_ENABLE;
DMA_DEV(dma_ch4)->src_burst_size = DMA_BURST_1BYTE;
DMA_DEV(dma_ch4)->dst_burst_size = DMA_BURST_1BYTE;
DMA_DEV(dma_ch4)->src_width = DMA_TRANSFER_WIDTH_8BIT;
DMA_DEV(dma_ch4)->dst_width = DMA_TRANSFER_WIDTH_8BIT;
device_open(dma_ch4, 0);

View File

@ -23,6 +23,8 @@
#ifndef __TFT_LCD_H__
#define __TFT_LCD_H__
#include "hal_gpio.h"
/** @addtogroup BL702_Peripheral_Driver
* @{
@ -71,6 +73,10 @@
/**
* @brief Tft_lcd Functions
*/
#ifdef __cplusplus
extern "C"{
#endif
void LCD_WR_Cmd(uint8_t command);
void LCD_WR_Byte(uint8_t data);
void LCD_WR_HalfWord(uint16_t data);
@ -91,6 +97,10 @@ void LCD_WR_SPI_DMA(uint16_t *img, uint32_t len);
void LCD_DrawChinese(uint16_t x, uint16_t y, uint8_t *character, uint16_t bColor, uint16_t cColor);
void LCD_DrawFont(uint16_t x, uint16_t y, uint16_t color, uint16_t bk_color, uint8_t *str, uint8_t num);
void LCD_DrawFont_64x32(uint16_t x, uint16_t y, uint16_t color, uint16_t bk_color, uint8_t *str, uint8_t num);
#ifdef __cplusplus
}
#endif
/*@} end of group TFT_LCD_Public_Functions */
/*@} end of group TFT_LCD */
@ -98,3 +108,4 @@ void LCD_DrawFont_64x32(uint16_t x, uint16_t y, uint16_t color, uint16_t bk_colo
/*@} end of group BL702_Peripheral_Driver */
#endif /* __TFT_LCD_H__ */

View File

@ -87,7 +87,7 @@ static int ili9341_spi_init(void)
SPI_DEV(spi0)->clk_polaraity = SPI_POLARITY_LOW;
SPI_DEV(spi0)->datasize = SPI_DATASIZE_8BIT;
SPI_DEV(spi0)->clk_phase = SPI_PHASE_1EDGE;
SPI_DEV(spi0)->fifo_threshold = 1;
SPI_DEV(spi0)->fifo_threshold = 4;
device_open(spi0, DEVICE_OFLAG_STREAM_TX);
} else {
@ -106,10 +106,12 @@ static int ili9341_spi_init(void)
DMA_DEV(dma_ch3)->transfer_mode = DMA_LLI_ONCE_MODE;
DMA_DEV(dma_ch3)->src_req = DMA_REQUEST_NONE;
DMA_DEV(dma_ch3)->dst_req = DMA_REQUEST_SPI0_TX;
DMA_DEV(dma_ch3)->src_width = DMA_TRANSFER_WIDTH_8BIT;
DMA_DEV(dma_ch3)->dst_width = DMA_TRANSFER_WIDTH_8BIT;
DMA_DEV(dma_ch3)->src_addr_inc = DMA_ADDR_INCREMENT_ENABLE;
DMA_DEV(dma_ch3)->dst_addr_inc = DMA_ADDR_INCREMENT_DISABLE;
DMA_DEV(dma_ch3)->src_burst_size = DMA_BURST_1BYTE;
DMA_DEV(dma_ch3)->dst_burst_size = DMA_BURST_1BYTE;
DMA_DEV(dma_ch3)->src_width = DMA_TRANSFER_WIDTH_8BIT;
DMA_DEV(dma_ch3)->dst_width = DMA_TRANSFER_WIDTH_8BIT;
device_open(dma_ch3, 0);
device_set_callback(dma_ch3, NULL);
device_control(spi0, DEVICE_CTRL_ATTACH_TX_DMA, dma_ch3);
@ -193,7 +195,7 @@ static int ili9341_write_data_4byte(uint32_t data)
*/
int ili9341_draw_is_busy(void)
{
if (device_control(SPI_DEV(spi0)->tx_dma, DMA_CHANNEL_GET_STATUS, NULL)) {
if (dma_channel_check_busy(SPI_DEV(spi0)->tx_dma)) {
return 1;
} else {
device_control(spi0, DEVICE_CTRL_TX_DMA_SUSPEND, NULL);
@ -358,6 +360,7 @@ void ili9341_draw_area(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint1
*/
void ili9341_draw_picture_nonblocking(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t *picture)
{
uint8_t ret = 0;
size_t picture_size = (x2 - x1 + 1) * (y2 - y1 + 1);
/* 数据高低位切换 */
@ -365,11 +368,18 @@ void ili9341_draw_picture_nonblocking(uint16_t x1, uint16_t y1, uint16_t x2, uin
lcd_swap_color_data16(picture, picture, picture_size);
}
// DMA_DEV(dma_ch3)->src_width = DMA_TRANSFER_WIDTH_32BIT;
// DMA_DEV(dma_ch3)->src_burst_size = DMA_BURST_1BYTE;
// DMA_DEV(dma_ch3)->dst_burst_size = DMA_BURST_4BYTE;
ili9341_set_draw_window(x1, y1, x2, y2);
ILI9341_DC_HIGH;
ILI9341_CS_LOW;
device_control(spi0, DEVICE_CTRL_TX_DMA_RESUME, NULL);
device_write(spi0, 0, picture, picture_size * 2);
ret = device_write(spi0, 0, picture, picture_size * 2);
if (ret != 0) {
MSG("device write fail!\r\n");
}
}
/**

View File

@ -106,10 +106,12 @@ static int st7735s_spi_init(void)
DMA_DEV(dma_ch3)->transfer_mode = DMA_LLI_ONCE_MODE;
DMA_DEV(dma_ch3)->src_req = DMA_REQUEST_NONE;
DMA_DEV(dma_ch3)->dst_req = DMA_REQUEST_SPI0_TX;
DMA_DEV(dma_ch3)->src_width = DMA_TRANSFER_WIDTH_8BIT;
DMA_DEV(dma_ch3)->dst_width = DMA_TRANSFER_WIDTH_8BIT;
DMA_DEV(dma_ch3)->src_addr_inc = DMA_ADDR_INCREMENT_ENABLE;
DMA_DEV(dma_ch3)->dst_addr_inc = DMA_ADDR_INCREMENT_DISABLE;
DMA_DEV(dma_ch3)->src_burst_size = DMA_BURST_1BYTE;
DMA_DEV(dma_ch3)->dst_burst_size = DMA_BURST_1BYTE;
DMA_DEV(dma_ch3)->src_width = DMA_TRANSFER_WIDTH_8BIT;
DMA_DEV(dma_ch3)->dst_width = DMA_TRANSFER_WIDTH_8BIT;
device_open(dma_ch3, 0);
device_set_callback(dma_ch3, NULL);
device_control(spi0, DEVICE_CTRL_ATTACH_TX_DMA, dma_ch3);
@ -193,7 +195,7 @@ static int st7735s_write_data_4byte(uint32_t data)
*/
int st7735s_draw_is_busy(void)
{
if (device_control(SPI_DEV(spi0)->tx_dma, DMA_CHANNEL_GET_STATUS, NULL)) {
if (dma_channel_check_busy(SPI_DEV(spi0)->tx_dma)) {
return 1;
} else {
device_control(spi0, DEVICE_CTRL_TX_DMA_SUSPEND, NULL);

View File

@ -108,10 +108,12 @@ static int st7789v_spi_init(void)
DMA_DEV(dma_ch3)->transfer_mode = DMA_LLI_ONCE_MODE;
DMA_DEV(dma_ch3)->src_req = DMA_REQUEST_NONE;
DMA_DEV(dma_ch3)->dst_req = DMA_REQUEST_SPI0_TX;
DMA_DEV(dma_ch3)->src_width = DMA_TRANSFER_WIDTH_8BIT;
DMA_DEV(dma_ch3)->dst_width = DMA_TRANSFER_WIDTH_8BIT;
DMA_DEV(dma_ch3)->src_addr_inc = DMA_ADDR_INCREMENT_ENABLE;
DMA_DEV(dma_ch3)->dst_addr_inc = DMA_ADDR_INCREMENT_DISABLE;
DMA_DEV(dma_ch3)->src_burst_size = DMA_BURST_1BYTE;
DMA_DEV(dma_ch3)->dst_burst_size = DMA_BURST_1BYTE;
DMA_DEV(dma_ch3)->src_width = DMA_TRANSFER_WIDTH_8BIT;
DMA_DEV(dma_ch3)->dst_width = DMA_TRANSFER_WIDTH_8BIT;
device_open(dma_ch3, 0);
device_set_callback(dma_ch3, NULL);
device_control(spi0, DEVICE_CTRL_ATTACH_TX_DMA, dma_ch3);
@ -195,7 +197,7 @@ static int st7789v_write_data_4byte(uint32_t data)
*/
int st7789v_draw_is_busy(void)
{
if (device_control(SPI_DEV(spi0)->tx_dma, DMA_CHANNEL_GET_STATUS, NULL)) {
if (dma_channel_check_busy(SPI_DEV(spi0)->tx_dma)) {
return 1;
} else {
device_control(spi0, DEVICE_CTRL_TX_DMA_SUSPEND, NULL);

View File

@ -21,6 +21,7 @@
*
*/
#include "hal_uart.h"
#include "hal_flash.h"
#include "hal_mtimer.h"
#include "drv_mmheap.h"
#include "hal_common.h"
@ -51,12 +52,42 @@ __WEAK__ enum uart_index_type board_get_debug_uart_index(void)
return 0;
}
void bl_show_flashinfo(void)
{
SPI_Flash_Cfg_Type flashCfg;
uint8_t *pFlashCfg = NULL;
uint32_t flashCfgLen = 0;
uint32_t flashJedecId = 0;
flashJedecId = flash_get_jedecid();
flash_get_cfg(&pFlashCfg, &flashCfgLen);
arch_memcpy((void *)&flashCfg, pFlashCfg, flashCfgLen);
MSG("show flash cfg:\r\n");
MSG("jedec id 0x%06X\r\n", flashJedecId);
MSG("mid 0x%02X\r\n", flashCfg.mid);
MSG("iomode 0x%02X\r\n", flashCfg.ioMode);
MSG("clk delay 0x%02X\r\n", flashCfg.clkDelay);
MSG("clk invert 0x%02X\r\n", flashCfg.clkInvert);
MSG("read reg cmd0 0x%02X\r\n", flashCfg.readRegCmd[0]);
MSG("read reg cmd1 0x%02X\r\n", flashCfg.readRegCmd[1]);
MSG("write reg cmd0 0x%02X\r\n", flashCfg.writeRegCmd[0]);
MSG("write reg cmd1 0x%02X\r\n", flashCfg.writeRegCmd[1]);
MSG("qe write len 0x%02X\r\n", flashCfg.qeWriteRegLen);
MSG("cread support 0x%02X\r\n", flashCfg.cReadSupport);
MSG("cread code 0x%02X\r\n", flashCfg.cReadMode);
MSG("burst wrap cmd 0x%02X\r\n", flashCfg.burstWrapCmd);
MSG("-------------------\r\n");
}
void bflb_platform_init(uint32_t baudrate)
{
static uint8_t initialized = 0;
BL_Err_Type ret = ERROR;
cpu_global_irq_disable();
ret = flash_init();
board_init();
if (!uart_dbg_disable) {
@ -82,6 +113,10 @@ void bflb_platform_init(uint32_t baudrate)
MSG("dynamic memory init success,heap size = %d Kbyte \r\n", system_mmheap[0].mem_size / 1024);
initialized = 1;
if (ret != SUCCESS) {
MSG("flash init fail!!!\r\n");
}
bl_show_flashinfo();
}
cpu_global_irq_enable();
@ -135,7 +170,7 @@ uint8_t bflb_platform_print_get(void)
void bflb_platform_deinit(void)
{
if (!uart_dbg_disable){
if (!uart_dbg_disable) {
struct device *uart = device_find("debug_log");
if (uart) {
device_close(uart);

View File

@ -64,6 +64,10 @@ uint8_t SD_SPI_Init(void)
DMA_DEV(dma_ch3)->transfer_mode = DMA_LLI_ONCE_MODE;
DMA_DEV(dma_ch3)->src_req = DMA_REQUEST_NONE;
DMA_DEV(dma_ch3)->dst_req = DMA_REQUEST_SPI0_TX;
DMA_DEV(dma_ch3)->src_addr_inc = DMA_ADDR_INCREMENT_ENABLE;
DMA_DEV(dma_ch3)->dst_addr_inc = DMA_ADDR_INCREMENT_DISABLE;
DMA_DEV(dma_ch3)->src_burst_size = DMA_BURST_1BYTE;
DMA_DEV(dma_ch3)->dst_burst_size = DMA_BURST_1BYTE;
DMA_DEV(dma_ch3)->src_width = DMA_TRANSFER_WIDTH_8BIT;
DMA_DEV(dma_ch3)->dst_width = DMA_TRANSFER_WIDTH_8BIT;
device_open(dma_ch3, 0);
@ -84,6 +88,10 @@ uint8_t SD_SPI_Init(void)
DMA_DEV(dma_ch4)->transfer_mode = DMA_LLI_ONCE_MODE;
DMA_DEV(dma_ch4)->src_req = DMA_REQUEST_SPI0_RX;
DMA_DEV(dma_ch4)->dst_req = DMA_REQUEST_NONE;
DMA_DEV(dma_ch4)->src_addr_inc = DMA_ADDR_INCREMENT_DISABLE;
DMA_DEV(dma_ch4)->dst_addr_inc = DMA_ADDR_INCREMENT_ENABLE;
DMA_DEV(dma_ch4)->src_burst_size = DMA_BURST_1BYTE;
DMA_DEV(dma_ch4)->dst_burst_size = DMA_BURST_1BYTE;
DMA_DEV(dma_ch4)->src_width = DMA_TRANSFER_WIDTH_8BIT;
DMA_DEV(dma_ch4)->dst_width = DMA_TRANSFER_WIDTH_8BIT;
device_open(dma_ch4, 0);
@ -95,7 +103,7 @@ uint8_t SD_SPI_Init(void)
BL_Err_Type SPI_ReadWriteByte(uint8_t *txBuff, uint8_t *rxBuff, uint32_t length)
{
while (device_control(dma_ch3, DMA_CHANNEL_GET_STATUS, NULL) || device_control(dma_ch4, DMA_CHANNEL_GET_STATUS, NULL))
while (dma_channel_check_busy(dma_ch3) || dma_channel_check_busy(dma_ch4))
;
if (length < 500) {
@ -109,7 +117,7 @@ BL_Err_Type SPI_ReadWriteByte(uint8_t *txBuff, uint8_t *rxBuff, uint32_t length)
dma_channel_start(dma_ch4);
dma_channel_start(dma_ch3);
while (device_control(dma_ch3, DMA_CHANNEL_GET_STATUS, NULL) || device_control(dma_ch4, DMA_CHANNEL_GET_STATUS, NULL))
while (dma_channel_check_busy(dma_ch3) || dma_channel_check_busy(dma_ch4))
;
device_control(spi0, DEVICE_CTRL_TX_DMA_SUSPEND, NULL);
@ -381,7 +389,6 @@ uint8_t SD_SendBlock(uint8_t *buf, uint8_t cmd)
return 0;
}
/****************************************************************************/ /**
* @brief SD_Get_CardInfo
*

View File

@ -29,8 +29,12 @@
#ifdef TOUCH_CONTROLLER_XPT2046
#include "xpt2046.h"
#endif
#ifdef __cplusplus
extern "C"{
#endif
void touch_init(void);
uint8_t touch_read(int16_t *x, int16_t *y);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -43,8 +43,12 @@
#define XPT2046_Y_MAX 3700
extern struct device *touch_spi;
#ifdef __cplusplus
extern "C"{
#endif
void xpt2046_init(void);
uint8_t xpt2046_read(int16_t *x, int16_t *y);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -74,6 +74,16 @@ void uart1_init(void)
dma_ch2 = device_find("ch2");
if (dma_ch2) {
DMA_DEV(dma_ch2)->direction = DMA_MEMORY_TO_PERIPH;
DMA_DEV(dma_ch2)->transfer_mode = DMA_LLI_ONCE_MODE;
DMA_DEV(dma_ch2)->src_req = DMA_REQUEST_NONE;
DMA_DEV(dma_ch2)->dst_req = DMA_REQUEST_UART1_TX;
DMA_DEV(dma_ch2)->src_addr_inc = DMA_ADDR_INCREMENT_ENABLE;
DMA_DEV(dma_ch2)->dst_addr_inc = DMA_ADDR_INCREMENT_DISABLE;
DMA_DEV(dma_ch2)->src_burst_size = DMA_BURST_1BYTE;
DMA_DEV(dma_ch2)->dst_burst_size = DMA_BURST_1BYTE;
DMA_DEV(dma_ch2)->src_width = DMA_TRANSFER_WIDTH_8BIT;
DMA_DEV(dma_ch2)->dst_width = DMA_TRANSFER_WIDTH_8BIT;
device_open(dma_ch2, 0);
}
}
@ -167,14 +177,14 @@ static dma_lli_ctrl_t uart_lli_list = {
void uart_send_from_ringbuffer(void)
{
if (Ring_Buffer_Get_Length(&usb_rx_rb)) {
if (!device_control(dma_ch2, DMA_CHANNEL_GET_STATUS, NULL)) {
if (!dma_channel_check_busy(dma_ch2)) {
uint32_t avalibleCnt = Ring_Buffer_Read(&usb_rx_rb, src_buffer, UART_TX_DMA_SIZE);
if (avalibleCnt) {
dma_channel_stop(dma_ch2);
uart_dma_ctrl_cfg.bits.TransferSize = avalibleCnt;
memcpy(&uart_lli_list.cfg, &uart_dma_ctrl_cfg, sizeof(dma_control_data_t));
device_control(dma_ch2, DMA_CHANNEL_UPDATE, (void *)((uint32_t)&uart_lli_list));
dma_channel_update(dma_ch2, (void *)((uint32_t)&uart_lli_list));
dma_channel_start(dma_ch2);
}
}

View File

@ -40,20 +40,23 @@ int main(void)
pm_hbn_out1_irq_register();
acomp_device_t acomp_device;
acomp_device.id = 1;
acomp_device.pos_ch = ACOMP_CHANNEL_ADC_CHANNEL6; //GPIO7
acomp_device.neg_ch = ACOMP_CHANNEL_0P375VBAT;
acomp_device.pos_hysteresis_vol = ACOMP_HYSTERESIS_VOLT_50MV;
acomp_device.neg_hysteresis_vol = ACOMP_HYSTERESIS_VOLT_50MV;
acomp_init(&acomp_device);
acomp_init(0, &acomp_device);
acomp_device.id = 0;
acomp_device.pos_ch = ACOMP_CHANNEL_ADC_CHANNEL2; //GPIO17
acomp_device.neg_ch = ACOMP_CHANNEL_0P375VBAT;
acomp_device.pos_hysteresis_vol = ACOMP_HYSTERESIS_VOLT_50MV;
acomp_device.neg_hysteresis_vol = ACOMP_HYSTERESIS_VOLT_50MV;
acomp_init(&acomp_device);
acomp_init(1, &acomp_device);
acomp_enable(0);
acomp_interrupt_unmask(0, ACOMP_POSITIVE_IT | ACOMP_NEGATIVE_IT);
acomp_enable(1);
acomp_interrupt_unmask(1, ACOMP_POSITIVE_IT | ACOMP_NEGATIVE_IT);
while (1) {
bflb_platform_delay_ms(100);
}

View File

@ -1,9 +0,0 @@
set(BSP_COMMON_DIR ${CMAKE_SOURCE_DIR}/bsp/bsp_common)
set(TARGET_REQUIRED_PRIVATE_INCLUDE ${BSP_COMMON_DIR}/es8388 )
set(TARGET_REQUIRED_SRCS ${BSP_COMMON_DIR}/es8388/bsp_es8388.c data_protocol.c wav_play_from_isp.c)
set(mains main.c)
generate_bin()

View File

@ -1,750 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<Project Name="audio_cube" Version="1" Language="C">
<Description>CPU: RV32IMAFC
Chip: bl70x
Board: bl70x_iot
</Description>
<Dependencies Name="Debug"/>
<VirtualDirectory Name="app">
<File Name="../main.c">
<FileOption/>
</File>
<File Name="../wav_play_from_isp.c">
<FileOption/>
</File>
<File Name="../data_protocol.c">
<FileOption/>
</File>
</VirtualDirectory>
<VirtualDirectory Name="chip">
<VirtualDirectory Name="riscv">
<File Name="../../../drivers/bl702_driver/startup/interrupt.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/startup/system_bl702.c">
<FileOption/>
</File>
</VirtualDirectory>
<VirtualDirectory Name="startup">
<File Name="../../../drivers/bl702_driver/startup/GCC/entry.S">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/startup/GCC/start_load.c">
<FileOption/>
</File>
</VirtualDirectory>
</VirtualDirectory>
<VirtualDirectory Name="hal">
<File Name="../../../drivers/bl702_driver/hal_drv/src/hal_acomp.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/hal_drv/src/hal_adc.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/hal_drv/src/hal_boot2.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/hal_drv/src/hal_cam.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/hal_drv/src/hal_clock.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/hal_drv/src/hal_common.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/hal_drv/src/hal_dac.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/hal_drv/src/hal_dma.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/hal_drv/src/hal_emac.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/hal_drv/src/hal_flash.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/hal_drv/src/hal_gpio.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/hal_drv/src/hal_i2c.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/hal_drv/src/hal_i2s.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/hal_drv/src/hal_keyscan.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/hal_drv/src/hal_mjpeg.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/hal_drv/src/hal_mtimer.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/hal_drv/src/hal_pm.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/hal_drv/src/hal_pwm.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/hal_drv/src/hal_qdec.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/hal_drv/src/hal_rtc.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/hal_drv/src/hal_sec_aes.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/hal_drv/src/hal_sec_dsa.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/hal_drv/src/hal_sec_ecdsa.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/hal_drv/src/hal_sec_hash.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/hal_drv/src/hal_spi.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/hal_drv/src/hal_timer.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/hal_drv/src/hal_uart.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/hal_drv/src/hal_usb.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/hal_drv/src/hal_wdt.c">
<FileOption/>
</File>
</VirtualDirectory>
<VirtualDirectory Name="std">
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_acomp.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_adc.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_aon.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_cam.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_clock.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_dac.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_dma.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_ef_ctrl.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_emac.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_glb.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_hbn.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_i2c.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_i2c_gpio_sim.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_i2s.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_ir.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_common.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_kys.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_l1c.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_mjpeg.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_pds.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_psram.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_pwm.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_qdec.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_romapi.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_sec_dbg.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_sec_eng.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_sf_cfg.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_sf_cfg_ext.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_sf_ctrl.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_sflash.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_sflash_ext.c" ExcludeProjConfig="">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_spi.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_timer.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_uart.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_usb.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_xip_sflash.c">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/std_drv/src/bl702_xip_sflash_ext.c">
<FileOption/>
</File>
</VirtualDirectory>
<VirtualDirectory Name="bsp">
<VirtualDirectory Name="board">
<File Name="../../../bsp/board/bl702/board.c">
<FileOption/>
</File>
</VirtualDirectory>
<VirtualDirectory Name="bsp_common">
<File Name="../../../bsp/bsp_common/platform/bflb_platform.c">
<FileOption/>
</File>
<File Name="../../../bsp/bsp_common/platform/syscalls.c">
<FileOption/>
</File>
<File Name="../../../bsp/bsp_common/es8388/bsp_es8388.c">
<FileOption/>
</File>
</VirtualDirectory>
</VirtualDirectory>
<VirtualDirectory Name="common">
<File Name="../../../common/device/drv_device.c">
<FileOption/>
</File>
<File Name="../../../common/memheap/drv_mmheap.c">
<FileOption/>
</File>
<File Name="../../../common/ring_buffer/ring_buffer.c">
<FileOption/>
</File>
<File Name="../../../common/soft_crc/softcrc.c">
<FileOption/>
</File>
<File Name="../../../common/misc/misc.c">
<FileOption/>
</File>
</VirtualDirectory>
<VirtualDirectory Name="script">
<File Name="../../../tools/openocd/bl70x_gdb.init">
<FileOption/>
</File>
<File Name="../../../drivers/bl702_driver/regs/bl70x_reg.svc">
<FileOption/>
</File>
</VirtualDirectory>
<MonitorProgress>
<DebugLaunch>83</DebugLaunch>
<FlashOperate>107</FlashOperate>
</MonitorProgress>
<VirtualDirectory Name="components">
<VirtualDirectory Name="fatfs">
<File Name="../../../components/fatfs/diskio.c">
<FileOption/>
</File>
<File Name="../../../components/fatfs/ff.c">
<FileOption/>
</File>
<File Name="../../../components/fatfs/ffsystem.c">
<FileOption/>
</File>
<File Name="../../../components/fatfs/ffunicode.c">
<FileOption/>
</File>
</VirtualDirectory>
<VirtualDirectory Name="shell">
<File Name="../../../components/shell/shell.c">
<FileOption/>
</File>
</VirtualDirectory>
<VirtualDirectory Name="usb_stack">
<VirtualDirectory Name="class">
<VirtualDirectory Name="cdc">
<File Name="../../../components/usb_stack/class/cdc/usbd_cdc.c">
<FileOption/>
</File>
</VirtualDirectory>
<VirtualDirectory Name="hid">
<File Name="../../../components/usb_stack/class/hid/usbd_hid.c">
<FileOption/>
</File>
</VirtualDirectory>
<VirtualDirectory Name="msc">
<File Name="../../../components/usb_stack/class/msc/usbd_msc.c">
<FileOption/>
</File>
</VirtualDirectory>
</VirtualDirectory>
<VirtualDirectory Name="core">
<File Name="../../../components/usb_stack/core/usbd_core.c">
<FileOption/>
</File>
</VirtualDirectory>
</VirtualDirectory>
</VirtualDirectory>
<Dependencies Name="BuildSet"/>
<Dependencies Name="CK_Link_Debug"/>
<Dependencies Name="OpenOCD_Debug"/>
<DebugSessions>
<watchExpressions>audio_isp_test:1;isp_obj_uart:1;audio_test:4;time_node:1;Wav_Information:1</watchExpressions>
<memoryExpressions>0x4201D700;;;</memoryExpressions>
<statistics>;;MHZ;</statistics>
<peripheralTabs>
<Tab disFormat="Hex">glb</Tab>
<Tab disFormat="Hex">uart</Tab>
</peripheralTabs>
<WatchDisplayFormat>1</WatchDisplayFormat>
<LocalDisplayFormat>1</LocalDisplayFormat>
<debugLayout/>
<memoryTabColSizeExpressions>72:4;100:8;100:8;100:8;</memoryTabColSizeExpressions>
</DebugSessions>
<DebugSessions>
<watchExpressions/>
<memoryExpressions>;;;</memoryExpressions>
<statistics>;;MHZ;</statistics>
<peripheralTabs>
<Tab disFormat="Hex">glb</Tab>
<Tab disFormat="Hex">uart</Tab>
</peripheralTabs>
<WatchDisplayFormat>1</WatchDisplayFormat>
<LocalDisplayFormat>1</LocalDisplayFormat>
<debugLayout/>
<memoryTabColSizeExpressions>100:8;100:8;100:8;100:8;</memoryTabColSizeExpressions>
</DebugSessions>
<BuildConfigs>
<BuildConfig Name="OpenOCD_Debug">
<Target>
<ROMBank Selected="1">
<ROM1>
<InUse>no</InUse>
<Start>0x23000000</Start>
<Size>0x100000</Size>
</ROM1>
<ROM2>
<InUse>no</InUse>
<Start>0x22014000</Start>
<Size>0x4000</Size>
</ROM2>
<ROM3>
<InUse>no</InUse>
<Start>0x42018000</Start>
<Size>0x8000</Size>
</ROM3>
<ROM4>
<InUse>no</InUse>
<Start/>
<Size/>
</ROM4>
<ROM5>
<InUse>no</InUse>
<Start/>
<Size/>
</ROM5>
</ROMBank>
<RAMBank>
<RAM1>
<InUse>yes</InUse>
<Start>0x42020000</Start>
<Size>0xc000</Size>
<Init>yes</Init>
</RAM1>
<RAM2>
<InUse>no</InUse>
<Start/>
<Size/>
<Init>yes</Init>
</RAM2>
<RAM3>
<InUse>no</InUse>
<Start/>
<Size/>
<Init>yes</Init>
</RAM3>
<RAM4>
<InUse>no</InUse>
<Start/>
<Size/>
<Init>yes</Init>
</RAM4>
<RAM5>
<InUse>no</InUse>
<Start/>
<Size/>
<Init>yes</Init>
</RAM5>
</RAMBank>
<CPU>rv32imafc</CPU>
<UseMiniLib>yes</UseMiniLib>
<Endian>little</Endian>
<UseHardFloat>no</UseHardFloat>
<UseEnhancedLRW>no</UseEnhancedLRW>
<UseContinueBuild>no</UseContinueBuild>
<UseSemiHost>no</UseSemiHost>
</Target>
<Output>
<OutputName>$(ProjectName)</OutputName>
<Type>Executable</Type>
<CreateHexFile>no</CreateHexFile>
<CreateBinFile>yes</CreateBinFile>
<Preprocessor>no</Preprocessor>
<Disassmeble>yes</Disassmeble>
<CallGraph>no</CallGraph>
<Map>yes</Map>
</Output>
<User>
<BeforeCompile>
<RunUserProg>no</RunUserProg>
<UserProgName/>
</BeforeCompile>
<BeforeMake>
<RunUserProg>no</RunUserProg>
<UserProgName/>
</BeforeMake>
<AfterMake>
<RunUserProg>no</RunUserProg>
<UserProgName>$(ProjectPath)../../../tools/bflb_flash_tool/bflb_mcu_tool.exe --chipname=bl702 --interface=openocd --firmware="$(ProjectPath)/Obj/$(ProjectName).bin" </UserProgName>
</AfterMake>
</User>
<Compiler>
<Define>ARCH_RISCV;BFLB_USE_HAL_DRIVER;BFLB_USE_ROM_DRIVER;bl706_iot</Define>
<Undefine/>
<Optim>Optimize more (-O2)</Optim>
<DebugLevel>Default (-g)</DebugLevel>
<IncludePath>$(ProjectPath);$(ProjectPath)../;$(ProjectPath)../../../components/fatfs;$(ProjectPath)../../../components/freertos/Source/include;$(ProjectPath)../../../components/shell;$(ProjectPath)../../../components/usb_stack/class/audio;$(ProjectPath)../../../components/usb_stack/class/cdc;$(ProjectPath)../../../components/usb_stack/class/hid;$(ProjectPath)../../../components/usb_stack/class/msc;$(ProjectPath)../../../components/usb_stack/class/video;$(ProjectPath)../../../components/usb_stack/class/webusb;$(ProjectPath)../../../components/usb_stack/class/winusb;$(ProjectPath)../../../components/usb_stack/common;$(ProjectPath)../../../components/usb_stack/core;$(ProjectPath)../../../bsp/board/bl702;$(ProjectPath)../../../bsp/bsp_common/platform;$(ProjectPath)../../../bsp/bsp_common/es8388;$(ProjectPath)../../../common/device;$(ProjectPath)../../../common/list;$(ProjectPath)../../../common/memheap;$(ProjectPath)../../../common/misc;$(ProjectPath)../../../common/ring_buffer;$(ProjectPath)../../../common/soft_crc;$(ProjectPath)../../../components/shell;$(ProjectPath)../../../drivers/bl702_driver;$(ProjectPath)../../../drivers/bl702_driver/hal_drv/default_config;$(ProjectPath)../../../drivers/bl702_driver/hal_drv/inc;$(ProjectPath)../../../drivers/bl702_driver/regs;$(ProjectPath)../../../drivers/bl702_driver/startup;$(ProjectPath)../../../drivers/bl702_driver/std_drv/inc</IncludePath>
<OtherFlags>-fshort-enums -fno-common -fms-extensions -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -Wall -Wshift-negative-value -Wchar-subscripts -Wformat -Wuninitialized -Winit-self -Wignored-qualifiers -Wunused -Wundef -msmall-data-limit=4 -std=c99</OtherFlags>
<Verbose>no</Verbose>
<Ansi>no</Ansi>
<Syntax>no</Syntax>
<Pedantic>no</Pedantic>
<PedanticErr>no</PedanticErr>
<InhibitWarn>no</InhibitWarn>
<AllWarn>yes</AllWarn>
<WarnErr>no</WarnErr>
<OneElfS>yes</OneElfS>
<OneElfSPerData>no</OneElfSPerData>
<Fstrict>no</Fstrict>
</Compiler>
<Asm>
<Define/>
<Undefine/>
<IncludePath>$(ProjectPath);$(ProjectPath)../;$(ProjectPath)../../../components/fatfs;$(ProjectPath)../../../components/freertos/Source/include;$(ProjectPath)../../../components/shell;$(ProjectPath)../../../components/usb_stack/class/audio;$(ProjectPath)../../../components/usb_stack/class/cdc;$(ProjectPath)../../../components/usb_stack/class/hid;$(ProjectPath)../../../components/usb_stack/class/msc;$(ProjectPath)../../../components/usb_stack/class/video;$(ProjectPath)../../../components/usb_stack/class/webusb;$(ProjectPath)../../../components/usb_stack/class/winusb;$(ProjectPath)../../../components/usb_stack/common;$(ProjectPath)../../../components/usb_stack/core;$(ProjectPath)../../../bsp/board/bl702;$(ProjectPath)../../../bsp/bsp_common/platform;$(ProjectPath)../../../bsp/bsp_common/es8388;$(ProjectPath)../../../common/device;$(ProjectPath)../../../common/list;$(ProjectPath)../../../common/memheap;$(ProjectPath)../../../common/misc;$(ProjectPath)../../../common/ring_buffer;$(ProjectPath)../../../common/soft_crc;$(ProjectPath)../../../components/shell;$(ProjectPath)../../../drivers/bl702_driver;$(ProjectPath)../../../drivers/bl702_driver/hal_drv/default_config;$(ProjectPath)../../../drivers/bl702_driver/hal_drv/inc;$(ProjectPath)../../../drivers/bl702_driver/regs;$(ProjectPath)../../../drivers/bl702_driver/startup;$(ProjectPath)../../../drivers/bl702_driver/std_drv/inc;$(ProjectPath)../../../drivers/bl602_driver/risc-v/Core/Include;$(ProjectPath)../../../drivers/bl602_driver/startup;$(ProjectPath)../../../drivers/bl602_driver/hal_drv/inc;$(ProjectPath)../../../drivers/bl602_driver/hal_drv/default_config;$(ProjectPath)../../../drivers/bl602_driver/regs;$(ProjectPath)../../../drivers/bl602_driver/std_drv/inc</IncludePath>
<OtherFlags/>
<DebugLevel>gdwarf2</DebugLevel>
</Asm>
<Linker>
<Garbage>yes</Garbage>
<Garbage2>yes</Garbage2>
<LDFile>$(ProjectPath)../../../drivers/bl702_driver/bl702_flash.ld</LDFile>
<LibName>c</LibName>
<LibPath/>
<OtherFlags>--specs=nano.specs</OtherFlags>
<AutoLDFile>no</AutoLDFile>
<LinkType/>
</Linker>
<Debug>
<LoadApplicationAtStartup>yes</LoadApplicationAtStartup>
<Connector>OpenOCD</Connector>
<StopAt>yes</StopAt>
<StopAtText>main</StopAtText>
<InitFile/>
<AfterLoadFile>$(ProjectPath)/../../../tools/openocd/bl70x_gdb.init</AfterLoadFile>
<AutoRun>yes</AutoRun>
<ResetType>Hard Reset</ResetType>
<SoftResetVal>23000000</SoftResetVal>
<ResetAfterLoad>no</ResetAfterLoad>
<AfterResetFile/>
<Dumpcore>no</Dumpcore>
<DumpcoreText>$(ProjectPath)/$(ProjectName).cdkcore</DumpcoreText>
<ConfigICE>
<IP>localhost</IP>
<PORT>1025</PORT>
<CPUNumber>0</CPUNumber>
<Clock>2000</Clock>
<Delay>10</Delay>
<WaitReset>50</WaitReset>
<DDC>yes</DDC>
<TRST>no</TRST>
<DebugPrint>no</DebugPrint>
<Connect>Normal</Connect>
<ResetType>Hard Reset</ResetType>
<SoftResetVal>21000000</SoftResetVal>
<RTOSType>Bare Metal</RTOSType>
<DownloadToFlash>yes</DownloadToFlash>
<ResetAfterConnect>yes</ResetAfterConnect>
<GDBName/>
<GDBServerType>Local</GDBServerType>
<OtherFlags>-arch riscv</OtherFlags>
</ConfigICE>
<ConfigSIM>
<SIMTarget/>
<OtherFlags/>
<NoGraphic>yes</NoGraphic>
<Log>no</Log>
<SimTrace>no</SimTrace>
</ConfigSIM>
<ConfigOpenOCD>
<OpenOCDExecutablePath>openocd-hifive</OpenOCDExecutablePath>
<OpenOCDTelnetPortEnable>no</OpenOCDTelnetPortEnable>
<OpenOCDTelnetPort>4444</OpenOCDTelnetPort>
<OpenOCDTclPortEnable>no</OpenOCDTclPortEnable>
<OpenOCDTclPort>6666</OpenOCDTclPort>
<OpenOCDConfigOptions>-f ../../../tools/openocd/if_rv_dbg_plus.cfg -f ../../../tools/openocd/tgt_702.cfg</OpenOCDConfigOptions>
<OpenOCDTimeout>5000</OpenOCDTimeout>
</ConfigOpenOCD>
</Debug>
<Flash>
<InitFile/>
<Erase>Erase Sectors</Erase>
<Algorithms Path="">bl70x_flasher.elf</Algorithms>
<Program>yes</Program>
<Verify>yes</Verify>
<ResetAndRun>no</ResetAndRun>
<ResetType>Hard Reset</ResetType>
<SoftResetVal/>
<External>no</External>
<Command/>
<Arguments/>
</Flash>
</BuildConfig>
<BuildConfig Name="CK_Link_Debug">
<Target>
<ROMBank Selected="1">
<ROM1>
<InUse>no</InUse>
<Start>0x23000000</Start>
<Size>0x100000</Size>
</ROM1>
<ROM2>
<InUse>no</InUse>
<Start>0x22014000</Start>
<Size>0x4000</Size>
</ROM2>
<ROM3>
<InUse>no</InUse>
<Start>0x42018000</Start>
<Size>0x8000</Size>
</ROM3>
<ROM4>
<InUse>no</InUse>
<Start/>
<Size/>
</ROM4>
<ROM5>
<InUse>no</InUse>
<Start/>
<Size/>
</ROM5>
</ROMBank>
<RAMBank>
<RAM1>
<InUse>yes</InUse>
<Start>0x42020000</Start>
<Size>0xc000</Size>
<Init>yes</Init>
</RAM1>
<RAM2>
<InUse>no</InUse>
<Start/>
<Size/>
<Init>yes</Init>
</RAM2>
<RAM3>
<InUse>no</InUse>
<Start/>
<Size/>
<Init>yes</Init>
</RAM3>
<RAM4>
<InUse>no</InUse>
<Start/>
<Size/>
<Init>yes</Init>
</RAM4>
<RAM5>
<InUse>no</InUse>
<Start/>
<Size/>
<Init>yes</Init>
</RAM5>
</RAMBank>
<CPU>rv32imafc</CPU>
<UseMiniLib>yes</UseMiniLib>
<Endian>little</Endian>
<UseHardFloat>no</UseHardFloat>
<UseEnhancedLRW>no</UseEnhancedLRW>
<UseContinueBuild>no</UseContinueBuild>
<UseSemiHost>no</UseSemiHost>
</Target>
<Output>
<OutputName>$(ProjectName)</OutputName>
<Type>Executable</Type>
<CreateHexFile>no</CreateHexFile>
<CreateBinFile>yes</CreateBinFile>
<Preprocessor>no</Preprocessor>
<Disassmeble>yes</Disassmeble>
<CallGraph>no</CallGraph>
<Map>yes</Map>
</Output>
<User>
<BeforeCompile>
<RunUserProg>no</RunUserProg>
<UserProgName/>
</BeforeCompile>
<BeforeMake>
<RunUserProg>no</RunUserProg>
<UserProgName/>
</BeforeMake>
<AfterMake>
<RunUserProg>no</RunUserProg>
<UserProgName>$(ProjectPath)../../../tools/bflb_flash_tool/bflb_mcu_tool.exe --chipname=bl702 --interface=openocd --firmware="$(ProjectPath)/Obj/$(ProjectName).bin" </UserProgName>
</AfterMake>
</User>
<Compiler>
<Define>ARCH_RISCV;BFLB_USE_HAL_DRIVER;BFLB_USE_ROM_DRIVER;bl706_iot</Define>
<Undefine/>
<Optim>Optimize more (-O2)</Optim>
<DebugLevel>Default (-g)</DebugLevel>
<IncludePath>$(ProjectPath);$(ProjectPath)../;$(ProjectPath)../../../components/fatfs;$(ProjectPath)../../../components/freertos/Source/include;$(ProjectPath)../../../components/shell;$(ProjectPath)../../../components/usb_stack/class/audio;$(ProjectPath)../../../components/usb_stack/class/cdc;$(ProjectPath)../../../components/usb_stack/class/hid;$(ProjectPath)../../../components/usb_stack/class/msc;$(ProjectPath)../../../components/usb_stack/class/video;$(ProjectPath)../../../components/usb_stack/class/webusb;$(ProjectPath)../../../components/usb_stack/class/winusb;$(ProjectPath)../../../components/usb_stack/common;$(ProjectPath)../../../components/usb_stack/core;$(ProjectPath)../../../bsp/board/bl702;$(ProjectPath)../../../bsp/bsp_common/platform;$(ProjectPath)../../../bsp/bsp_common/es8388;$(ProjectPath)../../../common/device;$(ProjectPath)../../../common/list;$(ProjectPath)../../../common/memheap;$(ProjectPath)../../../common/misc;$(ProjectPath)../../../common/ring_buffer;$(ProjectPath)../../../common/soft_crc;$(ProjectPath)../../../components/shell;$(ProjectPath)../../../drivers/bl702_driver;$(ProjectPath)../../../drivers/bl702_driver/hal_drv/default_config;$(ProjectPath)../../../drivers/bl702_driver/hal_drv/inc;$(ProjectPath)../../../drivers/bl702_driver/regs;$(ProjectPath)../../../drivers/bl702_driver/startup;$(ProjectPath)../../../drivers/bl702_driver/std_drv/inc;$(ProjectPath)../../../drivers/bl602_driver/risc-v/Core/Include;$(ProjectPath)../../../drivers/bl602_driver/hal_drv/inc;$(ProjectPath)../../../drivers/bl602_driver/hal_drv/default_config;$(ProjectPath)../../../drivers/bl602_driver/regs;$(ProjectPath)../../../drivers/bl602_driver/std_drv/inc</IncludePath>
<OtherFlags>-fshort-enums -fno-common -fms-extensions -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -Wall -Wshift-negative-value -Wchar-subscripts -Wformat -Wuninitialized -Winit-self -Wignored-qualifiers -Wunused -Wundef -msmall-data-limit=4 -std=c99</OtherFlags>
<Verbose>no</Verbose>
<Ansi>no</Ansi>
<Syntax>no</Syntax>
<Pedantic>no</Pedantic>
<PedanticErr>no</PedanticErr>
<InhibitWarn>no</InhibitWarn>
<AllWarn>yes</AllWarn>
<WarnErr>no</WarnErr>
<OneElfS>yes</OneElfS>
<OneElfSPerData>no</OneElfSPerData>
<Fstrict>no</Fstrict>
</Compiler>
<Asm>
<Define/>
<Undefine/>
<IncludePath>$(ProjectPath);$(ProjectPath)../;$(ProjectPath)../../../components/fatfs;$(ProjectPath)../../../components/freertos/Source/include;$(ProjectPath)../../../components/shell;$(ProjectPath)../../../components/usb_stack/class/audio;$(ProjectPath)../../../components/usb_stack/class/cdc;$(ProjectPath)../../../components/usb_stack/class/hid;$(ProjectPath)../../../components/usb_stack/class/msc;$(ProjectPath)../../../components/usb_stack/class/video;$(ProjectPath)../../../components/usb_stack/class/webusb;$(ProjectPath)../../../components/usb_stack/class/winusb;$(ProjectPath)../../../components/usb_stack/common;$(ProjectPath)../../../components/usb_stack/core;$(ProjectPath)../../../bsp/board/bl702;$(ProjectPath)../../../bsp/bsp_common/platform;$(ProjectPath)../../../common/device;$(ProjectPath)../../../common/list;$(ProjectPath)../../../common/memheap;$(ProjectPath)../../../common/misc;$(ProjectPath)../../../common/ring_buffer;$(ProjectPath)../../../common/soft_crc;$(ProjectPath)../../../components/shell;$(ProjectPath)../../../drivers/bl702_driver/hal_drv/default_config;$(ProjectPath)../../../drivers/bl702_driver/hal_drv/inc;$(ProjectPath)../../../drivers/bl702_driver/risc-v/Core/Include;$(ProjectPath)../../../drivers/bl702_driver/regs;$(ProjectPath)../../../drivers/bl702_driver/startup;$(ProjectPath)../../../drivers/bl702_driver/std_drv/inc;$(ProjectPath)../../../drivers/bl602_driver/risc-v/Core/Include;$(ProjectPath)../../../drivers/bl602_driver/startup;$(ProjectPath)../../../drivers/bl602_driver/hal_drv/inc;$(ProjectPath)../../../drivers/bl602_driver/hal_drv/default_config;$(ProjectPath)../../../drivers/bl602_driver/regs;$(ProjectPath)../../../drivers/bl602_driver/std_drv/inc</IncludePath>
<OtherFlags/>
<DebugLevel>gdwarf2</DebugLevel>
</Asm>
<Linker>
<Garbage>yes</Garbage>
<Garbage2>yes</Garbage2>
<LDFile>$(ProjectPath)../../../drivers/bl702_driver/bl702_flash.ld</LDFile>
<LibName>c</LibName>
<LibPath/>
<OtherFlags>--specs=nano.specs</OtherFlags>
<AutoLDFile>no</AutoLDFile>
<LinkType/>
</Linker>
<Debug>
<LoadApplicationAtStartup>yes</LoadApplicationAtStartup>
<Connector>Remote ICE</Connector>
<StopAt>yes</StopAt>
<StopAtText>main</StopAtText>
<InitFile/>
<AfterLoadFile>$(ProjectPath)/../../../tools/openocd/bl70x_gdb.init</AfterLoadFile>
<AutoRun>yes</AutoRun>
<ResetType>Hard Reset</ResetType>
<SoftResetVal>23000000</SoftResetVal>
<ResetAfterLoad>no</ResetAfterLoad>
<AfterResetFile/>
<Dumpcore>no</Dumpcore>
<DumpcoreText>$(ProjectPath)/$(ProjectName).cdkcore</DumpcoreText>
<ConfigICE>
<IP>localhost</IP>
<PORT>1025</PORT>
<CPUNumber>0</CPUNumber>
<Clock>2000</Clock>
<Delay>10</Delay>
<WaitReset>50</WaitReset>
<DDC>yes</DDC>
<TRST>no</TRST>
<DebugPrint>no</DebugPrint>
<Connect>Normal</Connect>
<ResetType>Hard Reset</ResetType>
<SoftResetVal>21000000</SoftResetVal>
<RTOSType>Bare Metal</RTOSType>
<DownloadToFlash>yes</DownloadToFlash>
<ResetAfterConnect>yes</ResetAfterConnect>
<GDBName/>
<GDBServerType>Local</GDBServerType>
<OtherFlags>-arch riscv</OtherFlags>
</ConfigICE>
<ConfigSIM>
<SIMTarget/>
<OtherFlags/>
<NoGraphic>yes</NoGraphic>
<Log>no</Log>
<SimTrace>no</SimTrace>
</ConfigSIM>
<ConfigOpenOCD>
<OpenOCDExecutablePath>openocd-hifive</OpenOCDExecutablePath>
<OpenOCDTelnetPortEnable>no</OpenOCDTelnetPortEnable>
<OpenOCDTelnetPort>4444</OpenOCDTelnetPort>
<OpenOCDTclPortEnable>no</OpenOCDTclPortEnable>
<OpenOCDTclPort>6666</OpenOCDTclPort>
<OpenOCDConfigOptions>-f ../../../tools/openocd/if_rv_dbg_plus.cfg -f ../../../tools/openocd/tgt_702.cfg</OpenOCDConfigOptions>
<OpenOCDTimeout>5000</OpenOCDTimeout>
</ConfigOpenOCD>
</Debug>
<Flash>
<InitFile/>
<Erase>Erase Sectors</Erase>
<Algorithms Path="">bl70x_flasher.elf</Algorithms>
<Program>yes</Program>
<Verify>yes</Verify>
<ResetAndRun>no</ResetAndRun>
<ResetType>Hard Reset</ResetType>
<SoftResetVal/>
<External>no</External>
<Command/>
<Arguments/>
</Flash>
</BuildConfig>
</BuildConfigs>
</Project>

View File

@ -1,400 +0,0 @@
/**
* @file ips.c
* @brief
*
* Copyright (c) 2021 Bouffalolab team
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
*/
#include "drv_mmheap.h"
#include "hal_uart.h"
#include "hal_dma.h"
#include "data_protocol.h"
struct device *uart;
static isp_obj_t *isp_obj_uart;
void ips_obj_init(isp_obj_t *isp_obj_p)
{
if (!isp_obj_p)
return;
isp_obj_p->cmd_id = 0;
isp_obj_p->check = 0;
isp_obj_p->length = 0;
isp_obj_p->file_type = 0;
isp_obj_p->auot_ack = 1;
isp_obj_p->status.isp_state_mode = 0;
isp_obj_p->status.already_steps = 0;
}
/**
* @brief uart tx dma irq, ch0
*
* @param dev
* @param args
* @param size
* @param state
*/
void dma_ch0_irq_callback(struct device *dev, void *args, uint32_t size, uint32_t state)
{
if (isp_obj_uart == NULL) {
return;
}
/* close dma and dma irq */
device_control(uart, DEVICE_CTRL_TX_DMA_SUSPEND, NULL);
device_control(UART_DEV(uart)->tx_dma, DEVICE_CTRL_CLR_INT, NULL);
if (isp_obj_uart->status.isp_state_mode == SEND_DATA) {
isp_obj_uart->status.isp_state_mode = SEND_WAIT_ACK;
isp_obj_uart->isp_callback(isp_obj_uart, ISP_CALLBACK_SEND_ACK_WAIT);
}
}
// void dma_ch1_irq_callback(struct device *dev, void *args, uint32_t size, uint32_t state)
// {
// if (isp_obj_uart == NULL) {
// return;
// }
// if (isp_obj_uart->status.isp_state_mode == RECEIVE_DATA) {
// isp_obj_uart->status.isp_state_mode = RECEIVE_WAIT_ACK;
// isp_obj_uart->isp_callback(isp_obj_uart, ISP_CALLBACK_RECEIVE_ACK_WAIT);
// }
// device_control(uart, DEVICE_CTRL_RX_DMA_SUSPEND, 0);
// isp_obj_uart->status.already_steps = 0;
// device_control(uart, DEVICE_CTRL_SET_INT, (void *)(UART_RX_FIFO_IT));
// MSG("tx dma init\r\n");
// }
uint8_t isp_check(isp_obj_t *isp_obj)
{
if (isp_obj == NULL) {
return 0;
}
uint8_t check = isp_obj->cmd_id + (isp_obj->length & 0x00FF) + ((isp_obj->length >> 8) & 0x00FF);
if (isp_obj->length && isp_obj->file_data) {
for (uint16_t i = 0; i < isp_obj->length; i++) {
check += isp_obj->file_data[i];
}
}
return check;
}
/**
* @brief
*
* @param isp_obj_uart
* @return int
*/
int isp_uart_send_data(isp_obj_t *isp_obj_uart)
{
if (isp_obj_uart == NULL || isp_obj_uart->cmd_id == 0) {
return -1;
}
if ((isp_obj_uart->cmd_id & 0xF0) != 0x50)
return -2;
if (isp_obj_uart->status.isp_state_mode != NO_TASK)
return -3;
isp_obj_uart->check = isp_check(isp_obj_uart);
/* use tx blocking */
device_write(uart, 0, (void *)isp_obj_uart, sizeof(isp_cmd_id_t) + sizeof(uint8_t) + sizeof(uint16_t) + sizeof(isp_file_type_t));
/* use DMA tx non-blocking */
device_control(uart, DEVICE_CTRL_TX_DMA_RESUME, NULL);
device_control(UART_DEV(uart)->tx_dma, DEVICE_CTRL_SET_INT, NULL);
device_write(uart, 0, isp_obj_uart->file_data, isp_obj_uart->length);
isp_obj_uart->status.already_steps = 0;
isp_obj_uart->status.isp_state_mode = SEND_DATA;
return 0;
}
/**
* @brief
*
* @param isp_obj_uart
* @return int
*/
int isp_uart_send_ack(isp_obj_t *isp_obj_uart, ips_reply_t ips_reply)
{
if (isp_obj_uart == NULL || isp_obj_uart->cmd_id == 0) {
return -1;
}
// if (isp_obj_uart->status.isp_state_mode != RECEIVE_WAIT_ACK) {
// return -2;
// }
/* use DMA tx blocking */
device_write(uart, 0, (uint8_t *)&ips_reply, 2);
return 0;
}
/**
* @brief
*
* @param isp_obj
* @param buff
* @param size
*/
void isp_task_handler(isp_obj_t *isp_obj, uint8_t *buff, uint32_t size)
{
static uint32_t time_last = 0;
uint32_t time_now = bflb_platform_get_time_ms();
/* debug information */
// MSG("hand:%d, len:%d, mode:%d\r\n", isp_obj_uart->status.already_steps, isp_obj_uart->status.receive_length, isp_obj_uart->status.isp_state_mode);
if (size == 0) {
if ((time_now - time_last > isp_obj->time_out) && isp_obj->time_out) {
/* time out */
}
}
for (uint32_t i = 0; i < size; i++) {
/* receive 状态机 */
switch (isp_obj_uart->status.already_steps) {
case 0:
if (isp_obj_uart->status.isp_state_mode == NO_TASK) {
isp_obj_uart->status.isp_state_mode = OTHER_STATE;
} else if (isp_obj_uart->status.isp_state_mode != SEND_WAIT_ACK) {
return;
}
isp_obj_uart->cmd_id = *buff;
isp_obj_uart->status.already_steps++;
break;
case 1:
isp_obj_uart->check = *buff;
isp_obj_uart->status.already_steps++;
if (isp_obj_uart->status.isp_state_mode == SEND_WAIT_ACK) {
isp_obj_uart->status.isp_state_mode = NO_TASK;
if (isp_obj_uart->cmd_id == 0X4F && isp_obj_uart->check == 0X4B) {
isp_obj_uart->status.ips_reply = REPLY_SUCCES;
isp_obj_uart->isp_callback(isp_obj_uart, ISP_CALLBACK_SEND_SUCCES_ACK);
isp_obj_uart->status.isp_state_mode = NO_TASK;
isp_obj_uart->status.already_steps = 0;
} else if (isp_obj_uart->cmd_id == 0X52 && isp_obj_uart->check == 0X45) {
isp_obj_uart->status.ips_reply = REPLY_ERROR;
isp_obj_uart->isp_callback(isp_obj_uart, ISP_CALLBACK_SEND_ERROR_ACK);
isp_obj_uart->status.isp_state_mode = NO_TASK;
isp_obj_uart->status.already_steps = 0;
}
}
break;
case 2:
isp_obj_uart->length = *buff;
isp_obj_uart->status.already_steps++;
break;
case 3:
isp_obj_uart->length += *buff << 8;
isp_obj_uart->status.already_steps++;
break;
case 4:
isp_obj_uart->file_type = *buff;
isp_obj_uart->status.already_steps++;
if ((isp_obj_uart->cmd_id & 0xF0) == 0x50) {
isp_obj_uart->status.isp_state_mode = RECEIVE_DATA;
isp_obj_uart->status.receive_length = 0;
} else {
isp_obj_uart->status.already_steps = 0;
/* 等待ACK的时候收到命令同时代表 命令 与 成功ACK */
if (isp_obj_uart->status.isp_state_mode == SEND_WAIT_ACK) {
/* 响应 CMD 含义 */
isp_obj_uart->status.isp_state_mode = RECEIVE_WAIT_ACK;
isp_obj_uart->isp_callback(isp_obj_uart, ISP_CALLBACK_CMD_);
/* 响应 ACK 含义 */
isp_obj_uart->status.ips_reply = REPLY_SUCCES;
isp_obj_uart->isp_callback(isp_obj_uart, ISP_CALLBACK_SEND_SUCCES_ACK);
isp_obj_uart->status.isp_state_mode = NO_TASK;
} else {
/* 正常空闲收到命令 */
isp_obj_uart->status.isp_state_mode = RECEIVE_WAIT_ACK;
isp_obj_uart->isp_callback(isp_obj_uart, ISP_CALLBACK_CMD_);
}
//isp_obj_uart->status.isp_state_mode = NO_TASK;
}
break;
case 5:
if (isp_obj_uart->status.receive_length < isp_obj_uart->length) {
isp_obj_uart->file_data[isp_obj_uart->status.receive_length] = *buff;
isp_obj_uart->status.receive_length++;
}
if (isp_obj_uart->status.receive_length >= isp_obj_uart->length) {
isp_obj_uart->status.isp_state_mode = RECEIVE_WAIT_ACK;
uint8_t check_data = isp_check(isp_obj_uart);
//MSG("check:%X\r\n", check);
if (isp_obj_uart->check == check_data) {
isp_obj_uart->isp_callback(isp_obj_uart, ISP_CALLBACK_RECEIVE_ACK_WAIT);
/* auot send ack */
if (isp_obj_uart->auot_ack == 0) {
isp_uart_send_ack(isp_obj_uart, REPLY_SUCCES);
isp_obj_uart->status.isp_state_mode = NO_TASK;
}
} else {
isp_obj_uart->isp_callback(isp_obj_uart, ISP_CALLBACK_RECEIVE_NACK_WAIT);
/* auot send Nack */
if (isp_obj_uart->auot_ack == 0) {
isp_uart_send_ack(isp_obj_uart, REPLY_ERROR);
isp_obj_uart->status.isp_state_mode = NO_TASK;
}
}
isp_obj_uart->status.receive_length = 0;
isp_obj_uart->status.already_steps = 0;
}
break;
default:
break;
}
buff++;
}
time_last = time_now;
}
/**
* @brief uart_irq_callback
*
* @param dev
* @param args
* @param size
* @param state
*/
void uart_irq_callback(struct device *dev, void *args, uint32_t size, uint32_t state)
{
static uint8_t fer_err_flag = 0;
if (state == UART_EVENT_RX_FIFO || state == UART_EVENT_RTO) {
if (isp_obj_uart == NULL) {
return;
}
/* Tx fifo overflow, send nack*/
if(fer_err_flag){
if(state == UART_EVENT_RX_FIFO){
}else if(state == UART_EVENT_RTO){
isp_obj_uart->status.isp_state_mode = NO_TASK;
isp_uart_send_ack(isp_obj_uart, REPLY_ERROR);
fer_err_flag = 0;
}
return;
}
isp_task_handler(isp_obj_uart, args, size);
}
else if(state == UART_EVENT_RX_FER){
/* Tx fifo overflow, baud rate should be reduced */
fer_err_flag = 1;
device_control(dev,DEVICE_CTRL_UART_CLEAR_RX_FIFO,NULL);
}
}
/**
* @brief
*
*/
uint8_t isp_uart_init(isp_obj_t *isp_obj)
{
if (isp_obj == NULL)
return 1;
uart = device_find("debug_log");
if(uart){
device_close(uart);
}else{
uart_register(UART0_INDEX, "debug_log");
uart = device_find("debug_log");
}
if (uart) {
UART_DEV(uart)->id = 0;
UART_DEV(uart)->baudrate = 3000000;
UART_DEV(uart)->databits = UART_DATA_LEN_8;
UART_DEV(uart)->stopbits = UART_STOP_ONE;
UART_DEV(uart)->parity = UART_PAR_NONE;
UART_DEV(uart)->fifo_threshold = 16;
device_open(uart, DEVICE_OFLAG_DMA_TX | DEVICE_OFLAG_INT_RX);
bflb_platform_delay_ms(5);
device_set_callback(uart, uart_irq_callback);
device_control(uart, DEVICE_CTRL_SET_INT, (void *)(UART_RX_FIFO_IT | UART_RTO_IT));
}
dma_register(DMA0_CH0_INDEX, "ch0");
struct device *dma_ch0 = device_find("ch0");
if (dma_ch0) {
DMA_DEV(dma_ch0)->direction = DMA_MEMORY_TO_PERIPH;
DMA_DEV(dma_ch0)->transfer_mode = DMA_LLI_ONCE_MODE;
DMA_DEV(dma_ch0)->src_req = DMA_REQUEST_NONE;
DMA_DEV(dma_ch0)->dst_req = DMA_REQUEST_UART0_TX;
DMA_DEV(dma_ch0)->src_addr_inc = DMA_ADDR_INCREMENT_ENABLE;
DMA_DEV(dma_ch0)->dst_addr_inc = DMA_ADDR_INCREMENT_DISABLE;
DMA_DEV(dma_ch0)->src_burst_size = DMA_BURST_1BYTE;
DMA_DEV(dma_ch0)->dst_burst_size = DMA_BURST_1BYTE;
DMA_DEV(dma_ch0)->src_width = DMA_TRANSFER_WIDTH_8BIT;
DMA_DEV(dma_ch0)->dst_width = DMA_TRANSFER_WIDTH_8BIT;
device_open(dma_ch0, 0);
device_control(uart, DEVICE_CTRL_ATTACH_TX_DMA, dma_ch0);
device_set_callback(dma_ch0, dma_ch0_irq_callback);
/* close dma irq */
//device_control(UART_DEV(uart)->tx_dma, DEVICE_CTRL_CLR_INT, NULL);
}
// dma_register(DMA0_CH1_INDEX, "ch1");
// struct device *dma_ch1 = device_find("ch1");
// if (dma_ch1) {
// DMA_DEV(dma_ch1)->direction = DMA_PERIPH_TO_MEMORY;
// DMA_DEV(dma_ch1)->transfer_mode = DMA_LLI_ONCE_MODE;
// DMA_DEV(dma_ch1)->src_req = DMA_REQUEST_UART0_RX;
// DMA_DEV(dma_ch1)->dst_req = DMA_REQUEST_NONE;
// DMA_DEV(dma_ch1)->src_addr_inc = DMA_ADDR_INCREMENT_DISABLE;
// DMA_DEV(dma_ch1)->dst_addr_inc = DMA_ADDR_INCREMENT_ENABLE;
// DMA_DEV(dma_ch1)->src_burst_size = DMA_BURST_1BYTE;
// DMA_DEV(dma_ch1)->dst_burst_size = DMA_BURST_1BYTE;
// DMA_DEV(dma_ch1)->src_width = DMA_TRANSFER_WIDTH_8BIT;
// DMA_DEV(dma_ch1)->dst_width = DMA_TRANSFER_WIDTH_8BIT;
// device_open(dma_ch1, 0);
// device_control(uart, DEVICE_CTRL_ATTACH_RX_DMA, dma_ch1);
// device_set_callback(dma_ch1, dma_ch1_irq_callback);
// device_control(dma_ch1, DEVICE_CTRL_SET_INT, NULL);
// }
device_control(uart, DEVICE_CTRL_TX_DMA_SUSPEND, NULL);
isp_obj_uart = isp_obj;
return 0;
}

View File

@ -1,104 +0,0 @@
/**
* @file ips.h
* @brief
*
* Copyright (c) 2021 Bouffalolab team
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
*/
#include "bflb_platform.h"
//#include "drv_list.h"
typedef enum {
FILE_START = 0x50,
FILE_DATA = 0X51,
FILE_END = 0X52,
CMD_PLAY_START = 0X40,
CMD_PLAY_PAUSE = 0X41,
CMD_PLAY_STOP = 0X42,
CMD_VOLUME_INCREASE = 0x43,
CMD_VOLUME_DECREASE = 0x44,
CMD_VOLUME_SET = 0x45,
CMD_VOLUME_GET = 0x46,
CMD_SAMPLING_RATE = 0x47,
CMD_CHANNEL_NUM = 0X48,
CMD_RECORD_START = 0x49,
CMD_RECORD_STOP = 0x4A,
} isp_cmd_id_t;
typedef enum {
DATA_UVVV = 0X53,
DATA_VUVV = 0X54,
} isp_file_type_t;
typedef enum {
REPLY_SUCCES = 0x4B4Fu,
REPLY_ERROR = 0x4552u,
} ips_reply_t;
/* 内部状态类型 */
typedef enum {
NO_TASK = 0,
SEND_DATA = 1, /* 发数据中 */
RECEIVE_DATA, /* 接收数据中 */
SEND_WAIT_ACK, /* 发送后等待 ack */
RECEIVE_WAIT_ACK, /* 接收后对方在等待 ack */
OTHER_STATE, /*其他状态,一般是接收数据或命令的帧头过程中 */
} isp_state_mode_t;
typedef struct {
isp_state_mode_t isp_state_mode; /* 单帧状态 */
uint8_t already_steps; /* 状态机控制 */
uint16_t buff_length_max; /* buff 最大长度 */
ips_reply_t ips_reply; /* ack 状态 */
uint16_t receive_length; /* 已经接收数量 */
} isp_status_t;
/* 回调触发原因 */
typedef enum {
ISP_CALLBACK_SEND_SUCCES_ACK, /* 发送后收到正确的ACK */
ISP_CALLBACK_SEND_ERROR_ACK, /* 发送后收到错误的ACK */
ISP_CALLBACK_RECEIVE_ACK_WAIT, /* 数据已经收到,校验正确对方在等待ACK */
ISP_CALLBACK_RECEIVE_NACK_WAIT, /* 数据已经收到,校验错误对方在等待NACK */
ISP_CALLBACK_SEND_ACK_WAIT, /* 数据已经发出等待对面ACK */
ISP_CALLBACK_CMD_, /* 收到命令,对方在等待ACK */
} isp_callback_reason_t;
typedef struct __attribute__((packed)) isp_obj_struct {
isp_cmd_id_t cmd_id;
uint8_t check;
uint16_t length;
isp_file_type_t file_type;
uint8_t *file_data;
uint8_t auot_ack; /* 数据包自动回ack0自动非零不自动*/
uint32_t time_out;
isp_status_t status; /* 中间变量,用以状态机控制 */
void (*isp_callback)(struct isp_obj_struct *isp_obj, isp_callback_reason_t isp_callback_reason);
} isp_obj_t;
int isp_uart_send_data(isp_obj_t *isp_obj_uart);
uint8_t isp_uart_init(isp_obj_t *isp_obj);
int isp_uart_send_ack(isp_obj_t *isp_obj_uart, ips_reply_t ips_reply);

View File

@ -1,238 +0,0 @@
/**
* @file main.c
* @brief
*
* Copyright (c) 2021 Bouffalolab team
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
*/
#include "bflb_platform.h"
#include "hal_i2s.h"
#include "hal_dma.h"
#include "data_protocol.h"
#include "wav_play_from_isp.h"
audio_dev_t audio_test;
isp_obj_t isp_obj_uart;
struct device *uart_isp;
/**
* @brief isp Event callbacks, normally run in interrupts, do not block operations
*
* @param isp_obj
* @param isp_callback_reason
*/
void isp_uart_callback(isp_obj_t *isp_obj, isp_callback_reason_t isp_callback_reason)
{
int vol;
switch (isp_callback_reason) {
case ISP_CALLBACK_RECEIVE_ACK_WAIT:
/* receive data information */
if (isp_obj->cmd_id == 0x50) {
/* receive data information */
if (isp_obj->file_type == 0x59 && audio_test.audio_state)
audio_test.audio_state = 1;
isp_obj->auot_ack = 0; /* auto ack */
} else if (isp_obj->cmd_id == 0x51) {
if (audio_test.audio_state == 0) { /* Not allowed to play */
isp_obj->auot_ack = 0;
} else if (audio_test.audio_state < 4) { /* start play */
audio_test.buff_using = (isp_obj->file_data == audio_test.buff[0]) ? 1 : 0;
audio_test.buff_data_size[!audio_test.buff_using] = isp_obj->length;
/* Parsing file Information, Initialize the peripheral*/
if (audio_test.audio_state == 1) {
if (audio_test.audio_init(&audio_test, 0, isp_obj->file_data)) {
break;
}
}
audio_test.audio_control(&audio_test, AUDIO_CMD_PLAY_START, NULL);
isp_obj->file_data = audio_test.buff[!audio_test.buff_using];
audio_test.buff_data_size[!audio_test.buff_using] = 0;
isp_obj->auot_ack = 0;
} else if (audio_test.audio_state == 4) { /* play ing */
if (isp_obj->file_data == audio_test.buff[0])
audio_test.buff_data_size[0] = isp_obj->length;
else
audio_test.buff_data_size[1] = isp_obj->length;
/* not auto ack , send ack in audio callback */
isp_obj->auot_ack = 1;
}
}
// MSG("ISP_CALLBACK_RECEIVE_ACK_WAIT\r\n");
break;
case ISP_CALLBACK_RECEIVE_NACK_WAIT:
/* receive data err */
// MSG("ISP_CALLBACK_RECEIVE_NACK_WAIT\r\n");
isp_obj->auot_ack = 0; /* auto ack */
break;
case ISP_CALLBACK_SEND_ACK_WAIT:
/* receive data end,wait ack */
// MSG("ISP_CALLBACK_SEND_ACK_WAIT\r\n");
break;
case ISP_CALLBACK_SEND_SUCCES_ACK:
/* send ok,send file next data */
if (audio_test.audio_state == 11) {
/* Continue to the recording */
audio_test.audio_control(&audio_test, AUDIO_CMD_RECORD_START, NULL);
isp_obj_uart.file_data = audio_test.buff[!audio_test.buff_using];
isp_obj_uart.length = audio_test.buff_data_size[!audio_test.buff_using];
isp_uart_send_data(&isp_obj_uart);
audio_test.buff_data_size[!audio_test.buff_using] = 0;
audio_test.audio_state = 12;
}
// MSG("ISP_CALLBACK_SEND_SUCCES_ACK\r\n");
break;
case ISP_CALLBACK_SEND_ERROR_ACK:
/* send err,resend last data */
// MSG("ISP_CALLBACK_SEND_ERROR_ACK\r\n");
break;
case ISP_CALLBACK_CMD_:
// MSG("ISP_CALLBACK_CMD_\r\n");
switch (isp_obj->cmd_id) {
case CMD_PLAY_START: /* play */
if (audio_test.audio_state == 0)
audio_test.audio_state = 1;
isp_obj->status.isp_state_mode = NO_TASK;
isp_uart_send_ack(isp_obj, REPLY_SUCCES);
break;
case CMD_PLAY_PAUSE: /* pause */
// if (audio_test.audio_state == 3)
// audio_test.audio_state = 2;
isp_obj->status.isp_state_mode = NO_TASK;
isp_uart_send_ack(isp_obj, REPLY_SUCCES);
break;
case CMD_PLAY_STOP: /* stop */
if (audio_test.audio_state)
audio_test.audio_state = 0;
// device_close(i2s);
isp_obj->status.isp_state_mode = NO_TASK;
isp_uart_send_ack(isp_obj, REPLY_SUCCES);
break;
case CMD_VOLUME_INCREASE: /* volume +1 */
vol = audio_test.audio_control(&audio_test, AUDIO_CMD_GET_VOLUME, NULL);
if (vol >= 100)
vol = 99;
audio_test.audio_control(&audio_test, AUDIO_CMD_SET_VOLUME, (void *)(vol + 1));
isp_obj->status.isp_state_mode = NO_TASK;
isp_uart_send_ack(isp_obj, REPLY_SUCCES);
break;
case CMD_VOLUME_DECREASE: /* volume -1 */
vol = audio_test.audio_control(&audio_test, AUDIO_CMD_GET_VOLUME, NULL);
if (vol <= 0)
vol = 1;
audio_test.audio_control(&audio_test, AUDIO_CMD_SET_VOLUME, (void *)(vol - 1));
isp_obj->status.isp_state_mode = NO_TASK;
isp_uart_send_ack(isp_obj, REPLY_SUCCES);
break;
case CMD_VOLUME_SET: /* volume set */
vol = isp_obj->file_type;
if (vol <= 0)
vol = 0;
else if (vol >= 100)
vol = 100;
audio_test.audio_control(&audio_test, AUDIO_CMD_SET_VOLUME, (void *)vol);
isp_obj->status.isp_state_mode = NO_TASK;
isp_uart_send_ack(isp_obj, REPLY_SUCCES);
break;
case CMD_VOLUME_GET: /* volume get */
vol = audio_test.audio_control(&audio_test, AUDIO_CMD_GET_VOLUME, NULL);
isp_obj->status.isp_state_mode = NO_TASK;
isp_uart_send_ack(isp_obj, (vol << 8) & 0xFF00);
break;
case CMD_SAMPLING_RATE: /* sampling_rate */
audio_test.record_config->sampl_freq = isp_obj->file_type;
isp_obj->status.isp_state_mode = NO_TASK;
isp_uart_send_ack(isp_obj, REPLY_SUCCES);
break;
case CMD_CHANNEL_NUM: /* channel */
audio_test.record_config->channel_num = isp_obj->file_type;
isp_obj->status.isp_state_mode = NO_TASK;
isp_uart_send_ack(isp_obj, REPLY_SUCCES);
break;
case CMD_RECORD_START: /* record */
if (audio_test.audio_state == 4 || /* play ing */
audio_test.audio_init(&audio_test, 1, isp_obj->file_data)) {
isp_obj->status.isp_state_mode = NO_TASK;
isp_uart_send_ack(isp_obj, REPLY_ERROR);
break;
}
isp_obj->status.isp_state_mode = NO_TASK;
isp_uart_send_ack(isp_obj, REPLY_SUCCES);
audio_test.audio_state = 10;
audio_test.audio_control(&audio_test, AUDIO_CMD_RECORD_START, NULL);
break;
case CMD_RECORD_STOP: /* stop record */
audio_test.audio_control(&audio_test, AUDIO_CMD_PLAY_STOP, NULL);
audio_test.audio_state = 10;
isp_obj->status.isp_state_mode = NO_TASK;
isp_uart_send_ack(isp_obj, REPLY_SUCCES);
break;
default:
isp_obj->status.isp_state_mode = NO_TASK;
isp_uart_send_ack(isp_obj, REPLY_SUCCES);
break;
}
break;
default:
break;
}
}
int main(void)
{
/* Disable log output */
bflb_platform_print_set(1);
bflb_platform_init(0);
/* register audio fun*/
isp_wav_play_register(&audio_test);
audio_test.audio_control(&audio_test, AUDIO_CMD_SET_VOLUME, (void *)40);
/* init isp uart */
isp_uart_init(&isp_obj_uart);
isp_obj_uart.isp_callback = isp_uart_callback;
isp_obj_uart.file_data = audio_test.buff[!audio_test.buff_using];
while (1) {
bflb_platform_delay_ms(100);
/* code */
if (isp_obj_uart.status.isp_state_mode == NO_TASK) {
/* code */
}
}
}

View File

@ -1,8 +0,0 @@
**board/bl706_avb/pinmux_config.h** 中 **PINMUX_SELECT** 选择 **PINMUX_LVGL**
```bash
$ make APP=audiocube_firmware_for_sph0645 BOARD=bl706_avb
```

View File

@ -1,484 +0,0 @@
/**
* @file wav_play_form_sd_card.c
* @brief
*
* Copyright (c) 2021 Bouffalolab team
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
*/
// #include "bsp_es8388.h"
#include "hal_i2s.h"
#include "hal_dma.h"
#include "data_protocol.h"
#include "wav_play_from_isp.h"
extern isp_obj_t isp_obj_uart;
static int wav_data_parser(uint8_t *buff, uint16_t max_size, wav_information_t *wav_information);
static uint32_t pcm_24bit_to_32bit(uint8_t *buff, uint32_t data_size);
static int isp_wav_play_init(struct audio_dev *audio_dev, uint8_t mode, uint8_t *buff);
static int isp_wav_play_control(struct audio_dev *audio_dev, AUDIO_CMD_t cmd, void *args);
static int isp_wav_play_callback(audio_dev_t *audio_dev);
uint8_t audio_buff[2][4 * 1024] __attribute__((section(".system_ram"), aligned(4)));
// static ES8388_Cfg_Type ES8388Cfg = {
// .work_mode = ES8388_CODEC_MDOE, /*!< ES8388 work mode */
// .role = ES8388_SLAVE, /*!< ES8388 role */
// .mic_input_mode = ES8388_DIFF_ENDED_MIC, /*!< ES8388 mic input mode */
// .mic_pga = ES8388_MIC_PGA_3DB, /*!< ES8388 mic PGA */
// .i2s_frame = ES8388_LEFT_JUSTIFY_FRAME, /*!< ES8388 I2S frame */
// .data_width = ES8388_DATA_LEN_16, /*!< ES8388 I2S dataWitdh */
// };
static wav_information_t Wav_Information;
static record_config_t record_config;
static audio_dev_t *p_Audio_Dev = NULL;
static void dma_ch2_irq_callback(struct device *dev, void *args, uint32_t size, uint32_t state)
{
if (p_Audio_Dev && p_Audio_Dev->audio_callback) {
p_Audio_Dev->audio_callback(p_Audio_Dev);
}
}
static void dma_ch3_irq_callback(struct device *dev, void *args, uint32_t size, uint32_t state)
{
if (p_Audio_Dev && p_Audio_Dev->audio_callback) {
p_Audio_Dev->audio_callback(p_Audio_Dev);
}
}
/* get File pointer from top of file*/
static int wav_data_parser(uint8_t *buff, uint16_t max_size, wav_information_t *wav_information)
{
uint32_t offset = 0;
uint32_t chunk_id;
if (buff == NULL)
return 1;
/* RIFF WAVE Chunk */
chunk_id = ((chunk_riff_t *)&buff[offset])->chunk_id;
if (chunk_id == 0x46464952) {
wav_information->chunk_riff_offset = offset;
wav_information->chunk_riff = *((chunk_riff_t *)&buff[offset]);
offset += sizeof(chunk_riff_t);
} else {
wav_information->chunk_riff_offset = -1;
return 1;
}
/* Format Chunk */
chunk_id = ((chunk_format_t *)&buff[offset])->chunk_id;
if (chunk_id == 0x20746D66 && offset < max_size) /* fmt */
{
wav_information->chunk_format_offset = offset;
wav_information->chunk_format = *((chunk_format_t *)&buff[offset]);
offset += ((chunk_format_t *)&buff[offset])->chunk_size + 8;
} else {
wav_information->chunk_format_offset = -1;
return 1;
}
/* Fact/list Chunk */
chunk_id = ((chunk_fact_t *)&buff[offset])->chunk_id;
if ((chunk_id == 0X74636166 || chunk_id == 0X5453494C) && offset < max_size) /*fact or list*/
{
wav_information->chunk_fact_offset = offset;
wav_information->chunk_fact = *((chunk_fact_t *)&buff[offset]);
offset += ((chunk_fact_t *)&buff[offset])->chunk_size + 8;
} else {
wav_information->chunk_fact_offset = -1;
}
/* Data Chunk */
chunk_id = ((chunk_data_t *)&buff[offset])->chunk_id;
if (chunk_id == 0X61746164 && offset < max_size) {
wav_information->chunk_data_offset = offset;
wav_information->chunk_data = *((chunk_data_t *)&buff[offset]);
} else {
wav_information->chunk_data_offset = -1;
return 1;
}
return 0;
}
static uint32_t pcm_24bit_to_32bit(uint8_t *buff, uint32_t data_size)
{
/* The buff size should be more than four thirds of the data_size */
for (uint16_t i = data_size / 3; i > 0; i--) {
buff[i * 4 - 1] = buff[i * 3 - 1];
buff[i * 4 - 2] = buff[i * 3 - 2];
buff[i * 4 - 3] = buff[i * 3 - 3];
buff[i * 4 - 4] = 0;
}
return data_size / 3 * 4;
}
static int isp_wav_play_init(struct audio_dev *audio_dev, uint8_t mode, uint8_t *buff)
{
int res;
struct device *dma_ch2 = device_find("i2s_ch2");
struct device *dma_ch3 = device_find("i2s_ch3");
audio_dev->device = device_find("I2S");
if (audio_dev->device) {
device_close(audio_dev->device);
} else {
i2s_register(I2S0_INDEX, "I2S");
audio_dev->device = device_find("I2S");
}
if (mode == 1) {
goto record_conf;
}
/* play config */
if (dma_ch2) {
device_close(dma_ch2);
} else {
dma_register(DMA0_CH2_INDEX, "i2s_ch2");
dma_ch2 = device_find("i2s_ch2");
}
/* Parse the WAV file */
res = wav_data_parser(buff, 1000, &Wav_Information);
if (!res) {
audio_dev->wav_information = &Wav_Information;
} else {
return 1;
}
if ((audio_dev->device) && dma_ch2) {
/* I2S Config */
I2S_DEV(audio_dev->device)->interface_mode = I2S_MODE_STD;
I2S_DEV(audio_dev->device)->sampl_freq_hz = audio_dev->wav_information->chunk_format.sample_rate;
I2S_DEV(audio_dev->device)->channel_num = audio_dev->wav_information->chunk_format.num_of_channels;
uint8_t pcm_w = audio_dev->wav_information->chunk_format.bits_per_sample / 8;
if (pcm_w <= 2) {
I2S_DEV(audio_dev->device)->frame_size = I2S_FRAME_LEN_16;
} else {
I2S_DEV(audio_dev->device)->frame_size = I2S_FRAME_LEN_32;
}
I2S_DEV(audio_dev->device)->data_size = I2S_DEV(audio_dev->device)->frame_size;
I2S_DEV(audio_dev->device)->fifo_threshold = 3;
res = device_open((audio_dev->device), DEVICE_OFLAG_DMA_TX);
/* ES8388 Config */
// switch (I2S_DEV(audio_dev->device)->data_size) {
// case I2S_FRAME_LEN_16:
// ES8388Cfg.data_width = ES8388_DATA_LEN_16;
// break;
// case I2S_FRAME_LEN_24:
// ES8388Cfg.data_width = ES8388_DATA_LEN_24;
// break;
// case I2S_FRAME_LEN_32:
// ES8388Cfg.data_width = ES8388_DATA_LEN_32;
// break;
// default:
// return 1;
// break;
// }
// ES8388_Init(&ES8388Cfg);
// ES8388_Set_Voice_Volume(50);
/* DMA Config */
DMA_DEV(dma_ch2)->direction = DMA_MEMORY_TO_PERIPH;
DMA_DEV(dma_ch2)->transfer_mode = DMA_LLI_ONCE_MODE;
DMA_DEV(dma_ch2)->src_req = DMA_REQUEST_NONE;
DMA_DEV(dma_ch2)->dst_req = DMA_REQUEST_I2S_TX;
DMA_DEV(dma_ch2)->src_addr_inc = DMA_ADDR_INCREMENT_ENABLE;
DMA_DEV(dma_ch2)->dst_addr_inc = DMA_ADDR_INCREMENT_DISABLE;
DMA_DEV(dma_ch2)->src_burst_size = DMA_BURST_4BYTE;
DMA_DEV(dma_ch2)->dst_burst_size = DMA_BURST_4BYTE;
DMA_DEV(dma_ch2)->src_width = DMA_TRANSFER_WIDTH_8BIT;
DMA_DEV(dma_ch2)->dst_width = DMA_TRANSFER_WIDTH_8BIT;
switch (I2S_DEV(audio_dev->device)->data_size * I2S_DEV(audio_dev->device)->channel_num) {
case 1:
DMA_DEV(dma_ch2)->src_width = DMA_TRANSFER_WIDTH_8BIT;
DMA_DEV(dma_ch2)->dst_width = DMA_TRANSFER_WIDTH_8BIT;
break;
case 2:
DMA_DEV(dma_ch2)->src_width = DMA_TRANSFER_WIDTH_16BIT;
DMA_DEV(dma_ch2)->dst_width = DMA_TRANSFER_WIDTH_16BIT;
break;
default:
DMA_DEV(dma_ch2)->src_width = DMA_TRANSFER_WIDTH_32BIT;
DMA_DEV(dma_ch2)->dst_width = DMA_TRANSFER_WIDTH_32BIT;
break;
}
device_open(dma_ch2, 0);
device_set_callback(dma_ch2, dma_ch2_irq_callback);
device_control(dma_ch2, DEVICE_CTRL_SET_INT, NULL);
device_control((audio_dev->device), DEVICE_CTRL_ATTACH_TX_DMA, (void *)dma_ch2);
/* Delete the information data*/
uint32_t data_size = audio_dev->buff_data_size[!audio_dev->buff_using];
data_size = data_size - audio_dev->wav_information->chunk_data_offset;
audio_dev->buff_data_size[!audio_dev->buff_using] = data_size;
uint8_t *p_dst = audio_dev->buff[!audio_dev->buff_using];
uint8_t *p_src = &(audio_dev->buff[!audio_dev->buff_using][audio_dev->wav_information->chunk_data_offset]);
memcpy(p_dst, p_src, data_size);
if (audio_dev->wav_information->chunk_format.bits_per_sample / 8 == 3) {
audio_dev->buff_data_size[!audio_dev->buff_using] = pcm_24bit_to_32bit(audio_dev->buff[!audio_dev->buff_using], data_size);
} else {
}
} else {
return 1;
}
return 0;
/* record mode config */
record_conf:
if (dma_ch3) {
device_close(dma_ch3);
} else {
dma_register(DMA0_CH3_INDEX, "i2s_ch3");
dma_ch3 = device_find("i2s_ch3");
}
if ((audio_dev->device) && dma_ch3) {
I2S_DEV(audio_dev->device)->iis_mode = I2S_MODE_MASTER;
I2S_DEV(audio_dev->device)->interface_mode = I2S_MODE_STD;
I2S_DEV(audio_dev->device)->channel_num = audio_dev->record_config->channel_num;
I2S_DEV(audio_dev->device)->data_size = audio_dev->record_config->data_size;
I2S_DEV(audio_dev->device)->fifo_threshold = 4;
switch (audio_dev->record_config->sampl_freq) {
case SAMPL_FREQ_8000:
I2S_DEV(audio_dev->device)->sampl_freq_hz = 8000;
break;
case SAMPL_FREQ_16000:
I2S_DEV(audio_dev->device)->sampl_freq_hz = 16000;
break;
case SAMPL_FREQ_44100:
I2S_DEV(audio_dev->device)->sampl_freq_hz = 44100;
break;
case SAMPL_FREQ_48000:
I2S_DEV(audio_dev->device)->sampl_freq_hz = 48000;
break;
default:
break;
}
I2S_DEV(audio_dev->device)->frame_size = I2S_FRAME_LEN_32;
device_open(audio_dev->device, DEVICE_OFLAG_DMA_RX);
/* ES8388 Config */
// switch (I2S_DEV(audio_dev->device)->data_size) {
// case I2S_FRAME_LEN_16:
// ES8388Cfg.data_width = ES8388_DATA_LEN_16;
// break;
// case I2S_FRAME_LEN_24:
// ES8388Cfg.data_width = ES8388_DATA_LEN_24;
// break;
// case I2S_FRAME_LEN_32:
// ES8388Cfg.data_width = ES8388_DATA_LEN_32;
// break;
// default:
// return 1;
// break;
// }
// ES8388_Init(&ES8388Cfg);
/* DMA Config */
DMA_DEV(dma_ch3)->direction = DMA_PERIPH_TO_MEMORY;
DMA_DEV(dma_ch3)->transfer_mode = DMA_LLI_ONCE_MODE;
DMA_DEV(dma_ch3)->src_req = DMA_REQUEST_I2S_RX;
DMA_DEV(dma_ch3)->dst_req = DMA_REQUEST_NONE;
DMA_DEV(dma_ch3)->src_addr_inc = DMA_ADDR_INCREMENT_DISABLE;
DMA_DEV(dma_ch3)->dst_addr_inc = DMA_ADDR_INCREMENT_ENABLE;
DMA_DEV(dma_ch3)->src_burst_size = DMA_BURST_4BYTE;
DMA_DEV(dma_ch3)->dst_burst_size = DMA_BURST_4BYTE;
DMA_DEV(dma_ch3)->src_width = DMA_TRANSFER_WIDTH_8BIT;
DMA_DEV(dma_ch3)->dst_width = DMA_TRANSFER_WIDTH_8BIT;
switch (I2S_DEV(audio_dev->device)->data_size * I2S_DEV(audio_dev->device)->channel_num) {
case 1:
DMA_DEV(dma_ch3)->src_width = DMA_TRANSFER_WIDTH_8BIT;
DMA_DEV(dma_ch3)->dst_width = DMA_TRANSFER_WIDTH_8BIT;
break;
case 2:
DMA_DEV(dma_ch3)->src_width = DMA_TRANSFER_WIDTH_16BIT;
DMA_DEV(dma_ch3)->dst_width = DMA_TRANSFER_WIDTH_16BIT;
break;
default:
DMA_DEV(dma_ch3)->src_width = DMA_TRANSFER_WIDTH_32BIT;
DMA_DEV(dma_ch3)->dst_width = DMA_TRANSFER_WIDTH_32BIT;
break;
}
device_open(dma_ch3, 0);
device_set_callback(dma_ch3, dma_ch3_irq_callback);
device_control(dma_ch3, DEVICE_CTRL_SET_INT, NULL);
device_control((audio_dev->device), DEVICE_CTRL_ATTACH_RX_DMA, (void *)dma_ch3);
}
return 0;
}
static int isp_wav_play_control(struct audio_dev *audio_dev, AUDIO_CMD_t cmd, void *args)
{
static uint32_t volume = 50;
int res = -1;
switch (cmd) {
case AUDIO_CMD_PLAY_START:
if (audio_dev->audio_state) {
audio_dev->buff_using = !audio_dev->buff_using;
res = device_write(audio_dev->device, 0, audio_dev->buff[audio_dev->buff_using], audio_dev->buff_data_size[audio_dev->buff_using]);
audio_dev->audio_state = 4;
res = 0;
}
break;
case AUDIO_CMD_PLAY_STOP:
if (audio_dev->audio_state) {
audio_dev->audio_state = 1;
res = 0;
}
break;
case AUDIO_CMD_RECORD_START:
if (audio_dev->audio_state >= 10) {
audio_dev->buff_using = !audio_dev->buff_using;
res = device_read(audio_dev->device, 0, audio_dev->buff[audio_dev->buff_using], audio_dev->buff_size_max);
audio_dev->audio_state = 12;
}
break;
case AUDIO_CMD_RECORD_STOP:
if (audio_dev->audio_state > 10) {
audio_dev->audio_state = 10;
res = 0;
}
break;
case AUDIO_CMD_SET_VOLUME:
if (audio_dev->audio_state) {
// res = ES8388_Set_Voice_Volume((uint32_t)args);
res = 0;
volume = (uint32_t)args;
}
break;
case AUDIO_CMD_GET_VOLUME:
if (audio_dev->audio_state) {
res = (int)volume;
}
break;
default:
break;
}
return res;
}
static int isp_wav_play_callback(audio_dev_t *audio_dev)
{
if (audio_dev->audio_state < 10) { /* play*/
if (audio_dev->buff_data_size[!audio_dev->buff_using] > 0 && isp_obj_uart.status.isp_state_mode == RECEIVE_WAIT_ACK) {
/* data ready, switch buff */
audio_dev->buff_using = !audio_dev->buff_using;
device_write(audio_dev->device, 0, audio_dev->buff[audio_dev->buff_using], audio_dev->buff_data_size[audio_dev->buff_using]);
audio_dev->buff_data_size[audio_dev->buff_using] = 0;
audio_dev->buff_data_size[!audio_dev->buff_using] = isp_obj_uart.length;
isp_obj_uart.file_data = audio_dev->buff[!audio_dev->buff_using];
isp_obj_uart.status.isp_state_mode = NO_TASK;
isp_uart_send_ack(&isp_obj_uart, REPLY_SUCCES);
} else {
/* Data not ready, wait data receive*/
audio_dev->audio_state = 3;
}
} else { /* record */
audio_dev->buff_data_size[audio_dev->buff_using] = audio_dev->buff_size_max;
if (audio_dev->audio_state == 12) {
if (isp_obj_uart.status.isp_state_mode == NO_TASK) {
/* Continue to the recording */
audio_dev->buff_using = !audio_dev->buff_using;
device_read(audio_dev->device, 0, audio_dev->buff[audio_dev->buff_using], audio_dev->buff_size_max);
/* send data to PC */
isp_obj_uart.file_data = audio_dev->buff[!audio_dev->buff_using];
isp_obj_uart.length = audio_dev->buff_data_size[!audio_dev->buff_using];
isp_obj_uart.cmd_id = FILE_DATA;
isp_obj_uart.file_type = 0x58;
isp_uart_send_data(&isp_obj_uart);
audio_dev->buff_data_size[!audio_dev->buff_using] = 0;
} else {
/* Data not ready, wait data transmit*/
audio_dev->audio_state = 11;
}
}
}
return 0;
}
int isp_wav_play_register(audio_dev_t *audio_dev)
{
p_Audio_Dev = audio_dev;
audio_dev->audio_init = isp_wav_play_init,
audio_dev->audio_control = isp_wav_play_control,
audio_dev->audio_callback = isp_wav_play_callback,
audio_dev->buff[0] = audio_buff[0];
audio_dev->buff[1] = audio_buff[1];
audio_dev->buff_data_size[0] = 0;
audio_dev->buff_data_size[1] = 0;
audio_dev->audio_state = 0;
audio_dev->buff_size_max = sizeof(audio_buff) / 2;
record_config.data_size = 2;
record_config.channel_num = 1;
record_config.sampl_freq = SAMPL_FREQ_16000;
audio_dev->record_config = &record_config;
return 0;
}

View File

@ -1,132 +0,0 @@
/**
* @file wav_play_form_sd_card.h
* @brief
*
* Copyright (c) 2021 Bouffalolab team
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
*/
#ifndef __MAV_PLAY_H__
#define __MAV_PLAY_H__
#include "hal_i2s.h"
//WAV文件块定义
/* RIFF (RIFF WAVE Chunk) */
typedef struct __attribute__((packed)) {
uint32_t chunk_id; /*chunk id:"RIFF",(0X46464952) */
uint32_t chunk_size; /*file size -8 */
uint32_t format; /* "WAVE" (0X45564157) */
} chunk_riff_t;
/* fmt (Format Chunk)*/
typedef struct __attribute__((packed)) {
uint32_t chunk_id; /* chunk id:"fmt",(0X20746D66) */
uint32_t chunk_size; /* fmt size -8 = 20*/
uint16_t audio_format; /* 音频格式;0X10,表示线性 PCM; 0X11 表示 IMA ADPCM */
uint16_t num_of_channels; /* 通道数量;1,表示单声道;2,表示双声道*/
uint32_t sample_rate; /* 采样率;0X1F40,表示 8Khz */
uint32_t byte_rate; /* 字节速率 */
uint16_t block_align; /*块对齐(字节)*/
uint16_t bits_per_sample; /*单个采样数据大小;4 位 ADPCM,设置为 4*/
} chunk_format_t;
//fact (Fact Chunk)
typedef struct __attribute__((packed)) {
uint32_t chunk_id; //chunk id;这里固定为"fact",即 0X74636166;
uint32_t chunk_size; //子集合大小(不包括 ID 和 Size);这里为:4.
uint32_t data_fact_size; //数据转换为 PCM 格式后的大小
} chunk_fact_t;
//data (Data Chunk)
typedef struct __attribute__((packed)) {
uint32_t chunk_id; //chunk id;这里固定为"data",即 0X61746164
uint32_t chunk_size; //子集合大小(不包括 ID 和 Size);文件大小-60.
} chunk_data_t;
//
typedef enum {
CHUNK_RIFF,
CHUNK_FORMAT,
CHUNK_FACT,
CHUNK_DATA,
} mav_chunk_t;
//.wav information
typedef struct
{
int chunk_riff_offset; //在数据里的位置偏移,-1表示没有此块
chunk_riff_t chunk_riff;
int chunk_format_offset;
chunk_format_t chunk_format;
int chunk_fact_offset;
chunk_fact_t chunk_fact;
int chunk_data_offset;
chunk_data_t chunk_data;
} wav_information_t;
typedef enum {
AUDIO_CMD_PLAY_START,
AUDIO_CMD_PLAY_STOP,
AUDIO_CMD_RECORD_START,
AUDIO_CMD_RECORD_STOP,
AUDIO_CMD_GET_VOLUME,
AUDIO_CMD_SET_VOLUME,
} AUDIO_CMD_t;
/* 频率索引*/
typedef enum {
SAMPL_FREQ_8000 = 0,
SAMPL_FREQ_16000 = 1,
SAMPL_FREQ_44100 = 2,
SAMPL_FREQ_48000 = 3,
} sampl_freq_t;
/* 录音设置参数 */
typedef struct
{
uint16_t data_size;
uint16_t channel_num;
sampl_freq_t sampl_freq;
} record_config_t;
/* 播放控制块 */
typedef struct audio_dev {
uint8_t *buff[2];
uint32_t buff_data_size[2]; //buff内数据长度
uint32_t buff_size_max; //buff的大小
uint8_t buff_using; //正在使用的buff
uint8_t audio_state; //状态 0:stop 1:暂停中,如果要播放,需要重新解析wav信息头 2:暂停中,可以接着播放(不用重新解析wav信息) 3:播放中,但在等待数据(数据不及时) 4:正常播放中,数据正常
// 11:录音模式(数据堆积,未及时发送完,在等待上位机ACK) 12录音模式(正常,数据及时发送)
uint8_t audio_type; //类型
int (*audio_init)(struct audio_dev *audio_dev, uint8_t mode, uint8_t *buff); //初始化函数播放需要传入wav文件头地址
int (*audio_control)(struct audio_dev *audio_dev, AUDIO_CMD_t cmd, void *args);
int (*audio_callback)(struct audio_dev *audio_dev); //中断回调函数用来重新装载buff
struct device *device; //i2s的device可以考虑换成指向其他外设
wav_information_t *wav_information; //播放wav信息结构体
record_config_t *record_config; //录音配置结构体
} audio_dev_t;
int isp_wav_play_register(audio_dev_t *audio_dev);
#endif

View File

@ -77,13 +77,16 @@ int main(void)
struct device *dac_dma = device_find("dac_dma");
if (dac_dma) {
((dma_device_t *)dac_dma)->direction = DMA_MEMORY_TO_PERIPH;
((dma_device_t *)dac_dma)->transfer_mode = DMA_LLI_ONCE_MODE;
((dma_device_t *)dac_dma)->src_req = DMA_REQUEST_NONE;
((dma_device_t *)dac_dma)->dst_req = DMA_REQUEST_DAC0;
((dma_device_t *)dac_dma)->src_width = DMA_TRANSFER_WIDTH_16BIT;
((dma_device_t *)dac_dma)->dst_width = DMA_TRANSFER_WIDTH_16BIT;
DMA_DEV(dac_dma)->direction = DMA_MEMORY_TO_PERIPH;
DMA_DEV(dac_dma)->transfer_mode = DMA_LLI_ONCE_MODE;
DMA_DEV(dac_dma)->src_req = DMA_REQUEST_NONE;
DMA_DEV(dac_dma)->dst_req = DMA_REQUEST_DAC0;
DMA_DEV(dac_dma)->src_addr_inc = DMA_ADDR_INCREMENT_ENABLE;
DMA_DEV(dac_dma)->dst_addr_inc = DMA_ADDR_INCREMENT_DISABLE;
DMA_DEV(dac_dma)->src_burst_size = DMA_BURST_1BYTE;
DMA_DEV(dac_dma)->dst_burst_size = DMA_BURST_1BYTE;
DMA_DEV(dac_dma)->src_width = DMA_TRANSFER_WIDTH_16BIT;
DMA_DEV(dac_dma)->dst_width = DMA_TRANSFER_WIDTH_16BIT;
device_open(dac_dma, 0);
}

View File

@ -47,13 +47,16 @@ int main(void)
struct device *dac_dma = device_find("dac_dma");
if (dac_dma) {
((dma_device_t *)dac_dma)->direction = DMA_MEMORY_TO_PERIPH;
((dma_device_t *)dac_dma)->transfer_mode = DMA_LLI_ONCE_MODE;
((dma_device_t *)dac_dma)->src_req = DMA_REQUEST_NONE;
((dma_device_t *)dac_dma)->dst_req = DMA_REQUEST_DAC0;
((dma_device_t *)dac_dma)->src_width = DMA_TRANSFER_WIDTH_16BIT;
((dma_device_t *)dac_dma)->dst_width = DMA_TRANSFER_WIDTH_16BIT;
DMA_DEV(dac_dma)->direction = DMA_MEMORY_TO_PERIPH;
DMA_DEV(dac_dma)->transfer_mode = DMA_LLI_ONCE_MODE;
DMA_DEV(dac_dma)->src_req = DMA_REQUEST_NONE;
DMA_DEV(dac_dma)->dst_req = DMA_REQUEST_DAC0;
DMA_DEV(dac_dma)->src_addr_inc = DMA_ADDR_INCREMENT_ENABLE;
DMA_DEV(dac_dma)->dst_addr_inc = DMA_ADDR_INCREMENT_DISABLE;
DMA_DEV(dac_dma)->src_burst_size = DMA_BURST_1BYTE;
DMA_DEV(dac_dma)->dst_burst_size = DMA_BURST_1BYTE;
DMA_DEV(dac_dma)->src_width = DMA_TRANSFER_WIDTH_16BIT;
DMA_DEV(dac_dma)->dst_width = DMA_TRANSFER_WIDTH_16BIT;
device_open(dac_dma, 0);
}

View File

@ -46,14 +46,24 @@ int main(void)
{
bflb_platform_init(0);
dma_register(DMA0_CH0_INDEX, "DMA");
dma_register(DMA0_CH0_INDEX, "dma_ch0");
struct device *dma = device_find("DMA");
struct device *dma_ch0 = device_find("dma_ch0");
if (dma) {
device_open(dma, 0);
device_set_callback(dma, dma_transfer_done);
device_control(dma, DEVICE_CTRL_SET_INT, NULL);
if (dma_ch0) {
DMA_DEV(dma_ch0)->direction = DMA_MEMORY_TO_MEMORY;
DMA_DEV(dma_ch0)->transfer_mode = DMA_LLI_ONCE_MODE;
DMA_DEV(dma_ch0)->src_req = DMA_REQUEST_NONE;
DMA_DEV(dma_ch0)->dst_req = DMA_REQUEST_NONE;
DMA_DEV(dma_ch0)->src_addr_inc = DMA_ADDR_INCREMENT_ENABLE;
DMA_DEV(dma_ch0)->dst_addr_inc = DMA_ADDR_INCREMENT_ENABLE;
DMA_DEV(dma_ch0)->src_burst_size = DMA_BURST_4BYTE;
DMA_DEV(dma_ch0)->dst_burst_size = DMA_BURST_4BYTE;
DMA_DEV(dma_ch0)->src_width = DMA_TRANSFER_WIDTH_32BIT;
DMA_DEV(dma_ch0)->dst_width = DMA_TRANSFER_WIDTH_32BIT;
device_open(dma_ch0, 0);
device_set_callback(dma_ch0, dma_transfer_done);
device_control(dma_ch0, DEVICE_CTRL_SET_INT, NULL);
}
/* prepare test memory src as 0xff but dest as 0x0 */
@ -61,11 +71,10 @@ int main(void)
memset(dma_src_buffer, 0xff, 8000);
memset(dma_dst_buffer, 0, 8000);
dma_reload(dma, (uint32_t)dma_src_buffer, (uint32_t)dma_dst_buffer, 8000);
dma_reload(dma_ch0, (uint32_t)dma_src_buffer, (uint32_t)dma_dst_buffer, 8000);
dma_channel_start(dma);
dma_channel_start(dma_ch0);
BL_CASE_SUCCESS;
while (1) {
bflb_platform_delay_ms(100);
}

View File

@ -52,8 +52,10 @@ void shell_irq_callback(struct device *dev, void *args, uint32_t size, uint32_t
{
uint8_t data;
if (state == UART_EVENT_RX_FIFO) {
data = *(uint8_t *)args;
shell_handler(data);
for (size_t i = 0; i < size; i++) {
data = *(uint8_t *)(args + i);
shell_handler(data);
}
}
}
#endif

View File

@ -64,126 +64,228 @@
/** @defgroup SEC_ECDH_Private_Functions
* @{
*/
#define ALGORITHM_TYPE 0
/* We use following two case to show how ECDH works*/
//==========================
//Alice's secret key: 1672493697407246559549867004310108600574958080780180188771300643695147736525
//Alice's public key: (8186931993451804108690395451499266320135437983074928011404785122795116228120L, 42583342814291813019381020879433259376088942101048764740128506039642196631017L)
//Bob's secret key: 80820894835688796582966945354468122770925276582929501754975915934762303146292
//Bob's public key: (110419239604359817300303235482162221248952850592986847629047641306847745620659L, 19394459839852358891515335116028197103691369259799083720249515230794728385441L)
//==========================
//Alice's shared key: (89478371667134321617252675049711550685663874249668539239111908843552332917927L, 817906898059826893312335918167859928021104862259509866199871605894193053448L)
//Bob's shared key: (89478371667134321617252675049711550685663874249668539239111908843552332917927L, 817906898059826893312335918167859928021104862259509866199871605894193053448L)
//==========================
//The shared value is the x-value: 89478371667134321617252675049711550685663874249668539239111908843552332917927
uint8_t secp256r1_ecdh_private_key1[32] = { 0x03, 0xb2, 0x99, 0xf, 0x18, 0x16, 0x38, 0x78, 0x88, 0xb1, 0x9, 0xfd, 0xd4, 0x33, 0x94, 0x1a,
0x1f, 0x7e, 0x7c, 0x8b, 0xf7, 0xf2, 0x34, 0x15, 0xb0, 0xc1, 0x21, 0x61, 0xc0, 0xe9, 0xdd, 0xcd };
uint8_t secp256r1_ecdh_public_keyx1[32] = { 0x12, 0x19, 0xa3, 0xa9, 0xd, 0xbf, 0xfa, 0xf3, 0xd5, 0x1b, 0x8c, 0xa0, 0xa6, 0xec, 0xd9, 0xa8,
0xca, 0xf0, 0x6, 0xaf, 0x3b, 0x52, 0x4b, 0x9f, 0x93, 0x96, 0xcb, 0xa, 0xe6, 0xa6, 0xee, 0x18 };
uint8_t secp256r1_ecdh_public_keyy1[32] = { 0x5e, 0x25, 0x51, 0x62, 0xd6, 0x5, 0x89, 0xe3, 0x65, 0x3d, 0xde, 0xf1, 0x59, 0xcb, 0xee, 0x70,
0x56, 0x40, 0x71, 0x55, 0x9e, 0xec, 0xe0, 0x4, 0x81, 0xa4, 0xfc, 0x7a, 0xf, 0xe5, 0x5d, 0xe9 };
uint8_t secp256r1_ecdh_shared_keyx1[32] = { 0xc5, 0xd2, 0xf6, 0xb1, 0x69, 0x8c, 0x4f, 0xff, 0x1b, 0x4a, 0x9d, 0x4, 0x4d, 0x7a, 0x3d, 0xbf,
0xa5, 0xed, 0xfc, 0xd6, 0xc9, 0x12, 0xe7, 0x67, 0x32, 0x1e, 0x3f, 0x31, 0x4b, 0xf1, 0x2c, 0xa7 };
uint8_t secp256r1_ecdh_private_key2[32] = { 0xb2, 0xaf, 0x1, 0x62, 0x49, 0x36, 0x12, 0xee, 0x36, 0xfb, 0x72, 0x20, 0xc9, 0xcc, 0xba, 0xe7,
0x86, 0x5, 0x11, 0x84, 0x72, 0xed, 0x1c, 0xa4, 0xf8, 0x2c, 0x3a, 0xb, 0xf6, 0x9e, 0xc9, 0x34 };
uint8_t secp256r1_ecdh_public_keyx2[32] = { 0xf4, 0x1f, 0x13, 0x2a, 0xf2, 0x7b, 0x67, 0x22, 0xcb, 0x6a, 0x73, 0xb5, 0x21, 0x17, 0x32, 0x32,
0x7d, 0x8c, 0x42, 0x71, 0x3, 0x9d, 0x54, 0xc, 0x68, 0xdc, 0xac, 0x8b, 0x1d, 0x63, 0x3a, 0xb3 };
uint8_t secp256r1_ecdh_public_keyy2[32] = { 0x2a, 0xe0, 0xe0, 0x11, 0x45, 0xbc, 0x5e, 0x1b, 0x30, 0x4, 0x1b, 0xc3, 0x45, 0x3b, 0xb9, 0xb6,
0x77, 0x64, 0x6b, 0x7e, 0x96, 0x1a, 0xad, 0x22, 0xd2, 0xe4, 0x9f, 0x29, 0x8e, 0x64, 0xab, 0xa1 };
uint8_t secp256r1_ecdh_shared_keyx2[32] = { 0xc5, 0xd2, 0xf6, 0xb1, 0x69, 0x8c, 0x4f, 0xff, 0x1b, 0x4a, 0x9d, 0x4, 0x4d, 0x7a, 0x3d, 0xbf,
0xa5, 0xed, 0xfc, 0xd6, 0xc9, 0x12, 0xe7, 0x67, 0x32, 0x1e, 0x3f, 0x31, 0x4b, 0xf1, 0x2c, 0xa7 };
uint8_t secp256r1_ecdh_private_key[32] = { 0xba, 0x25, 0xf6, 0xc1, 0xa7, 0x82, 0x9a, 0x18, 0x51, 0x08, 0x0c, 0xa8, 0x79, 0x50, 0xb9, 0xd5,
0x17, 0x7a, 0x8a, 0x65, 0x72, 0xd3, 0x12, 0x87, 0x07, 0x04, 0x9c, 0x74, 0x95, 0x3e, 0xf6, 0x11 };
uint8_t secp256r1_ecdh_public_keyx[32] = { 0xbe, 0xbb, 0x36, 0x3c, 0xfd, 0x53, 0x8d, 0x94, 0x86, 0x7c, 0xf5, 0xbb, 0x35, 0xd8, 0xb6, 0x7b,
0x74, 0x8c, 0x7a, 0xcf, 0x05, 0xa4, 0x5c, 0x70, 0x79, 0xb4, 0x78, 0x50, 0x8e, 0x87, 0xea, 0x4c };
uint8_t secp256r1_ecdh_public_keyy[32] = { 0x84, 0x3c, 0x5b, 0x9c, 0x9c, 0x6b, 0x6c, 0xca, 0xe0, 0xfe, 0x1b, 0x2b, 0xdc, 0xce, 0xb0, 0x24,
0x3b, 0x4c, 0xc3, 0x58, 0x4c, 0x59, 0x28, 0x4c, 0xda, 0x26, 0x8d, 0x67, 0x9e, 0x8c, 0x29, 0xd4 };
uint8_t secp256r1_ecdh_shared_keyx[32] = { 0x58, 0xa7, 0x3b, 0x0f, 0x15, 0x58, 0x4e, 0x3a, 0xed, 0x9e, 0x01, 0x3c, 0xbc, 0xdd, 0x9f, 0x56,
0x16, 0xac, 0x5f, 0xe4, 0x8f, 0x2f, 0xad, 0x38, 0x98, 0x50, 0x43, 0x5e, 0x4e, 0xed, 0x74, 0x53 };
uint8_t secp256k1_ecdh_private_key1[32] = { 0x85, 0xE6, 0xDC, 0xDB, 0x9D, 0x9C, 0x00, 0x72,
0xC0, 0xB7, 0x7C, 0x85, 0xF3, 0x34, 0x83, 0xFC,
0x8A, 0x3A, 0xDF, 0xC5, 0xAC, 0x64, 0xB5, 0xA0,
0xC2, 0xFA, 0xD6, 0xDA, 0xAA, 0x51, 0x04, 0xEE };
uint8_t secp256k1_ecdh_public_keyx1[32] = { 0x10, 0xC8, 0x99, 0xD4, 0x8B, 0xA1, 0x23, 0x90,
0xBC, 0x54, 0xE3, 0x1F, 0x32, 0x09, 0x7B, 0x3F,
0xFF, 0xF2, 0x50, 0xB2, 0xBA, 0xBA, 0x82, 0xFB,
0x64, 0x58, 0x12, 0xDD, 0x14, 0x17, 0x89, 0x53 };
uint8_t secp256k1_ecdh_public_keyy1[32] = { 0xC3, 0x71, 0x10, 0x3B, 0xF3, 0x00, 0x4B, 0x6E,
0x4E, 0x6A, 0x95, 0xF1, 0xAB, 0xCE, 0xDE, 0x10,
0x91, 0x38, 0x7A, 0x9C, 0xCF, 0x0D, 0x9B, 0x67,
0x55, 0x79, 0xFD, 0x16, 0x30, 0xFB, 0x0B, 0xC4 };
uint8_t secp256k1_ecdh_shared_keyx1[32] = { 0x4B, 0xA5, 0xE0, 0xFD, 0x2C, 0x36, 0xC4, 0xA4,
0xB5, 0xAA, 0x6D, 0x05, 0xF6, 0x3D, 0xAF, 0x99,
0x58, 0x38, 0x84, 0x6A, 0xE1, 0xD3, 0x0E, 0x2E,
0xE6, 0x2D, 0xCF, 0x3C, 0x96, 0x70, 0xC0, 0x86 };
uint8_t secp256k1_ecdh_private_key2[32] = { 0x07, 0xDF, 0xAB, 0x47, 0x68, 0xA1, 0x2B, 0x99,
0xDF, 0x8F, 0xE0, 0x1A, 0x5D, 0x04, 0x83, 0xB2,
0xB1, 0x64, 0x45, 0xB5, 0xB5, 0xC7, 0x7B, 0x09,
0x17, 0xC9, 0x07, 0x04, 0x2C, 0xFB, 0xBF, 0x40 };
uint8_t secp256k1_ecdh_public_keyx2[32] = { 0xBD, 0x50, 0xB9, 0x7C, 0x60, 0xB5, 0x23, 0x6B,
0xDA, 0xCD, 0xA8, 0xB6, 0xCF, 0x9F, 0x01, 0xDF,
0xAC, 0x00, 0x5D, 0x23, 0xA3, 0x21, 0xEC, 0xDB,
0xC2, 0x0C, 0x03, 0x70, 0x9B, 0x2B, 0x15, 0x7B };
uint8_t secp256k1_ecdh_public_keyy2[32] = { 0x95, 0xE3, 0x6C, 0x9C, 0xE2, 0xB3, 0x08, 0x8B,
0x80, 0x95, 0x54, 0xFD, 0x73, 0x6D, 0xF5, 0xB4,
0x3B, 0xDE, 0x5B, 0xD7, 0x90, 0x5C, 0x89, 0x73,
0xF0, 0x08, 0xF5, 0x23, 0x7B, 0x2D, 0x31, 0xD3 };
uint8_t secp256k1_ecdh_shared_keyx2[32] = { 0x4B, 0xA5, 0xE0, 0xFD, 0x2C, 0x36, 0xC4, 0xA4,
0xB5, 0xAA, 0x6D, 0x05, 0xF6, 0x3D, 0xAF, 0x99,
0x58, 0x38, 0x84, 0x6A, 0xE1, 0xD3, 0x0E, 0x2E,
0xE6, 0x2D, 0xCF, 0x3C, 0x96, 0x70, 0xC0, 0x86 };
uint8_t secp256k1_ecdh_private_key[32] = { 0x07, 0xDF, 0xAB, 0x47, 0x68, 0xA1, 0x2B, 0x99,
0xDF, 0x8F, 0xE0, 0x1A, 0x5D, 0x04, 0x83, 0xB2,
0xB1, 0x64, 0x45, 0xB5, 0xB5, 0xC7, 0x7B, 0x09,
0x17, 0xC9, 0x07, 0x04, 0x2C, 0xFB, 0xBF, 0x40 };
uint8_t secp256k1_ecdh_public_keyx[32] = { 0xBD, 0x50, 0xB9, 0x7C, 0x60, 0xB5, 0x23, 0x6B,
0xDA, 0xCD, 0xA8, 0xB6, 0xCF, 0x9F, 0x01, 0xDF,
0xAC, 0x00, 0x5D, 0x23, 0xA3, 0x21, 0xEC, 0xDB,
0xC2, 0x0C, 0x03, 0x70, 0x9B, 0x2B, 0x15, 0x7B };
uint8_t secp256k1_ecdh_public_keyy[32] = { 0x95, 0xE3, 0x6C, 0x9C, 0xE2, 0xB3, 0x08, 0x8B,
0x80, 0x95, 0x54, 0xFD, 0x73, 0x6D, 0xF5, 0xB4,
0x3B, 0xDE, 0x5B, 0xD7, 0x90, 0x5C, 0x89, 0x73,
0xF0, 0x08, 0xF5, 0x23, 0x7B, 0x2D, 0x31, 0xD3 };
uint8_t secp256k1_ecdh_shared_keyx[32] = { 0x15, 0x5C, 0x1B, 0x6F, 0xE7, 0xF9, 0x99, 0xCC,
0xBD, 0x9E, 0x1E, 0x3B, 0x71, 0xA0, 0x10, 0x5F,
0xA7, 0x74, 0x9C, 0xAF, 0xE9, 0x92, 0xFB, 0xE8,
0x9E, 0x9C, 0x54, 0x6B, 0x23, 0x39, 0x22, 0xEE };
#define BUFF_COPY(G) \
{ \
memcpy(ecdh_private_key1, G##_ecdh_private_key1, 32); \
memcpy(ecdh_public_keyx1, G##_ecdh_public_keyx1, 32); \
memcpy(ecdh_public_keyy1, G##_ecdh_public_keyy1, 32); \
memcpy(ecdh_shared_keyx1, G##_ecdh_shared_keyx1, 32); \
memcpy(ecdh_private_key2, G##_ecdh_private_key2, 32); \
memcpy(ecdh_public_keyx2, G##_ecdh_public_keyx2, 32); \
memcpy(ecdh_public_keyy2, G##_ecdh_public_keyy2, 32); \
memcpy(ecdh_shared_keyx2, G##_ecdh_shared_keyx2, 32); \
memcpy(ecdh_private_key, G##_ecdh_private_key, 32); \
memcpy(ecdh_public_keyx, G##_ecdh_public_keyx, 32); \
memcpy(ecdh_public_keyy, G##_ecdh_public_keyy, 32); \
memcpy(ecdh_shared_keyx, G##_ecdh_shared_keyx, 32); \
}
int main(void)
{
/* We use following two case to show how ECDH works*/
//==========================
//Alice's secret key: 1672493697407246559549867004310108600574958080780180188771300643695147736525
//Alice's public key: (8186931993451804108690395451499266320135437983074928011404785122795116228120L, 42583342814291813019381020879433259376088942101048764740128506039642196631017L)
//Bob's secret key: 80820894835688796582966945354468122770925276582929501754975915934762303146292
//Bob's public key: (110419239604359817300303235482162221248952850592986847629047641306847745620659L, 19394459839852358891515335116028197103691369259799083720249515230794728385441L)
//==========================
//Alice's shared key: (89478371667134321617252675049711550685663874249668539239111908843552332917927L, 817906898059826893312335918167859928021104862259509866199871605894193053448L)
//Bob's shared key: (89478371667134321617252675049711550685663874249668539239111908843552332917927L, 817906898059826893312335918167859928021104862259509866199871605894193053448L)
//==========================
//The shared value is the x-value: 89478371667134321617252675049711550685663874249668539239111908843552332917927
uint8_t ecdh_private_key1[32];
uint8_t ecdh_public_keyx1[32];
uint8_t ecdh_public_keyy1[32];
uint8_t ecdh_shared_keyx1[32];
uint8_t ecdh_private_key1[32] = { 0x03, 0xb2, 0x99, 0xf, 0x18, 0x16, 0x38, 0x78, 0x88, 0xb1, 0x9, 0xfd, 0xd4, 0x33, 0x94, 0x1a,
0x1f, 0x7e, 0x7c, 0x8b, 0xf7, 0xf2, 0x34, 0x15, 0xb0, 0xc1, 0x21, 0x61, 0xc0, 0xe9, 0xdd, 0xcd };
uint8_t ecdh_public_keyx1[32] = { 0x12, 0x19, 0xa3, 0xa9, 0xd, 0xbf, 0xfa, 0xf3, 0xd5, 0x1b, 0x8c, 0xa0, 0xa6, 0xec, 0xd9, 0xa8,
0xca, 0xf0, 0x6, 0xaf, 0x3b, 0x52, 0x4b, 0x9f, 0x93, 0x96, 0xcb, 0xa, 0xe6, 0xa6, 0xee, 0x18 };
uint8_t ecdh_public_keyy1[32] = { 0x5e, 0x25, 0x51, 0x62, 0xd6, 0x5, 0x89, 0xe3, 0x65, 0x3d, 0xde, 0xf1, 0x59, 0xcb, 0xee, 0x70,
0x56, 0x40, 0x71, 0x55, 0x9e, 0xec, 0xe0, 0x4, 0x81, 0xa4, 0xfc, 0x7a, 0xf, 0xe5, 0x5d, 0xe9 };
uint8_t ecdh_shared_keyx1[32] = { 0xc5, 0xd2, 0xf6, 0xb1, 0x69, 0x8c, 0x4f, 0xff, 0x1b, 0x4a, 0x9d, 0x4, 0x4d, 0x7a, 0x3d, 0xbf,
0xa5, 0xed, 0xfc, 0xd6, 0xc9, 0x12, 0xe7, 0x67, 0x32, 0x1e, 0x3f, 0x31, 0x4b, 0xf1, 0x2c, 0xa7 };
uint8_t ecdh_private_key2[32];
uint8_t ecdh_public_keyx2[32];
uint8_t ecdh_public_keyy2[32];
uint8_t ecdh_shared_keyx2[32];
uint8_t ecdh_private_key2[32] = { 0xb2, 0xaf, 0x1, 0x62, 0x49, 0x36, 0x12, 0xee, 0x36, 0xfb, 0x72, 0x20, 0xc9, 0xcc, 0xba, 0xe7,
0x86, 0x5, 0x11, 0x84, 0x72, 0xed, 0x1c, 0xa4, 0xf8, 0x2c, 0x3a, 0xb, 0xf6, 0x9e, 0xc9, 0x34 };
uint8_t ecdh_public_keyx2[32] = { 0xf4, 0x1f, 0x13, 0x2a, 0xf2, 0x7b, 0x67, 0x22, 0xcb, 0x6a, 0x73, 0xb5, 0x21, 0x17, 0x32, 0x32,
0x7d, 0x8c, 0x42, 0x71, 0x3, 0x9d, 0x54, 0xc, 0x68, 0xdc, 0xac, 0x8b, 0x1d, 0x63, 0x3a, 0xb3 };
uint8_t ecdh_public_keyy2[32] = { 0x2a, 0xe0, 0xe0, 0x11, 0x45, 0xbc, 0x5e, 0x1b, 0x30, 0x4, 0x1b, 0xc3, 0x45, 0x3b, 0xb9, 0xb6,
0x77, 0x64, 0x6b, 0x7e, 0x96, 0x1a, 0xad, 0x22, 0xd2, 0xe4, 0x9f, 0x29, 0x8e, 0x64, 0xab, 0xa1 };
uint8_t ecdh_shared_keyx2[32] = { 0xc5, 0xd2, 0xf6, 0xb1, 0x69, 0x8c, 0x4f, 0xff, 0x1b, 0x4a, 0x9d, 0x4, 0x4d, 0x7a, 0x3d, 0xbf,
0xa5, 0xed, 0xfc, 0xd6, 0xc9, 0x12, 0xe7, 0x67, 0x32, 0x1e, 0x3f, 0x31, 0x4b, 0xf1, 0x2c, 0xa7 };
uint8_t ecdh_private_key[32];
uint8_t ecdh_public_keyx[32];
uint8_t ecdh_public_keyy[32];
uint8_t ecdh_shared_keyx[32];
/* Another case */
uint8_t ecdh_private_key[32] = { 0xba, 0x25, 0xf6, 0xc1, 0xa7, 0x82, 0x9a, 0x18, 0x51, 0x08, 0x0c, 0xa8, 0x79, 0x50, 0xb9, 0xd5,
0x17, 0x7a, 0x8a, 0x65, 0x72, 0xd3, 0x12, 0x87, 0x07, 0x04, 0x9c, 0x74, 0x95, 0x3e, 0xf6, 0x11 };
uint8_t ecdh_public_keyx[32] = { 0xbe, 0xbb, 0x36, 0x3c, 0xfd, 0x53, 0x8d, 0x94, 0x86, 0x7c, 0xf5, 0xbb, 0x35, 0xd8, 0xb6, 0x7b,
0x74, 0x8c, 0x7a, 0xcf, 0x05, 0xa4, 0x5c, 0x70, 0x79, 0xb4, 0x78, 0x50, 0x8e, 0x87, 0xea, 0x4c };
uint8_t ecdh_public_keyy[32] = { 0x84, 0x3c, 0x5b, 0x9c, 0x9c, 0x6b, 0x6c, 0xca, 0xe0, 0xfe, 0x1b, 0x2b, 0xdc, 0xce, 0xb0, 0x24,
0x3b, 0x4c, 0xc3, 0x58, 0x4c, 0x59, 0x28, 0x4c, 0xda, 0x26, 0x8d, 0x67, 0x9e, 0x8c, 0x29, 0xd4 };
uint8_t ecdh_shared_keyx[32] = { 0x58, 0xa7, 0x3b, 0x0f, 0x15, 0x58, 0x4e, 0x3a, 0xed, 0x9e, 0x01, 0x3c, 0xbc, 0xdd, 0x9f, 0x56,
0x16, 0xac, 0x5f, 0xe4, 0x8f, 0x2f, 0xad, 0x38, 0x98, 0x50, 0x43, 0x5e, 0x4e, 0xed, 0x74, 0x53 };
uint32_t ecdh_keyx[8];
uint32_t ecdh_keyy[8];
int32_t i;
uint8_t *p;
sec_ecdh_handle_t ecdh_handle;
uint32_t time1, time2;
bflb_platform_init(2000000);
MSG("ECDH Case\r\n");
sec_ecdh_init(&ecdh_handle, ECP_SECP256R1);
for (int type_id = 0; type_id < 2; type_id++) {
if (type_id == 0) {
sec_ecdh_init(&ecdh_handle, ECP_SECP256R1);
MSG("ECP_SECP256R1\r\n");
BUFF_COPY(secp256r1);
} else if (type_id == 1) {
sec_ecdh_init(&ecdh_handle, ECP_SECP256K1);
MSG("ECP_SECP256K1\r\n");
BUFF_COPY(secp256k1);
}
MSG("Bob calculate encrypt key\r\n");
bflb_platform_clear_time();
sec_ecdh_get_encrypt_key(&ecdh_handle, (uint32_t *)ecdh_public_keyx1, (uint32_t *)ecdh_public_keyy1, (uint32_t *)ecdh_private_key2, ecdh_keyx, ecdh_keyy);
MSG("Get encrypt key time=%dms\r\n", (unsigned int)bflb_platform_get_time_ms());
MSG("Bob calculate encrypt key\r\n");
time1 = (unsigned int)bflb_platform_get_time_us();
sec_ecdh_get_encrypt_key(&ecdh_handle, (uint32_t *)ecdh_public_keyx1, (uint32_t *)ecdh_public_keyy1, (uint32_t *)ecdh_private_key2, ecdh_keyx, ecdh_keyy);
time2 = (unsigned int)bflb_platform_get_time_us();
MSG("Get encrypt key time=%dus\r\n", (time2 - time1));
p = (uint8_t *)ecdh_keyx;
p = (uint8_t *)ecdh_keyx;
for (i = 0; i < 32; i++) {
if (ecdh_shared_keyx2[i] != p[i]) {
MSG("ECDH Compare fail\r\n");
BL_CASE_FAIL;
for (i = 0; i < 32; i++) {
if (ecdh_shared_keyx2[i] != p[i]) {
MSG("ECDH Compare fail\r\n");
MSG("p[%d]=0x%x\r\n", i, p[i]);
BL_CASE_FAIL;
}
}
MSG("Alice calculate encrypt key\r\n");
time1 = (unsigned int)bflb_platform_get_time_us();
sec_ecdh_get_encrypt_key(&ecdh_handle, (uint32_t *)ecdh_public_keyx2, (uint32_t *)ecdh_public_keyy2, (uint32_t *)ecdh_private_key1, ecdh_keyx, ecdh_keyy);
time2 = (unsigned int)bflb_platform_get_time_us();
MSG("Get encrypt key time=%dus\r\n", (time2 - time1));
p = (uint8_t *)ecdh_keyx;
for (i = 0; i < 32; i++) {
if (ecdh_shared_keyx1[i] != p[i]) {
MSG("ECDH Compare fail\r\n");
MSG("p[%d]=0x%x\r\n", i, p[i]);
BL_CASE_FAIL;
}
}
MSG("Another case\r\n");
MSG("Get Public key\r\n");
time1 = (unsigned int)bflb_platform_get_time_us();
sec_ecdh_get_public_key(&ecdh_handle, (uint32_t *)ecdh_private_key, ecdh_keyx, ecdh_keyy);
time2 = (unsigned int)bflb_platform_get_time_us();
MSG("Get public key time=%dus\r\n", (time2 - time1));
p = (uint8_t *)ecdh_keyx;
for (i = 0; i < 32; i++) {
if (ecdh_public_keyx[i] != p[i]) {
MSG("ECDH Compare fail\r\n");
MSG("p[%d]=0x%x\r\n", i, p[i]);
BL_CASE_FAIL;
}
}
p = (uint8_t *)ecdh_keyy;
for (i = 0; i < 32; i++) {
if (ecdh_public_keyy[i] != p[i]) {
MSG("ECDH Compare fail\r\n");
MSG("p[%d]=0x%x\r\n", i, p[i]);
BL_CASE_FAIL;
}
}
MSG("Get shared key\r\n");
bflb_platform_clear_time();
time1 = (unsigned int)bflb_platform_get_time_us();
sec_ecdh_get_encrypt_key(&ecdh_handle, ecdh_keyx, ecdh_keyy, (uint32_t *)ecdh_private_key, ecdh_keyx, ecdh_keyy);
time2 = (unsigned int)bflb_platform_get_time_us();
MSG("Get share key time=%dus\r\n", (time2 - time1));
p = (uint8_t *)ecdh_keyx;
for (i = 0; i < 32; i++) {
if (ecdh_shared_keyx[i] != p[i]) {
MSG("ECDH Compare fail\r\n");
MSG("p[%d]=0x%x\r\n", i, p[i]);
BL_CASE_FAIL;
}
}
}
MSG("Alice calculate encrypt key\r\n");
bflb_platform_clear_time();
sec_ecdh_get_encrypt_key(&ecdh_handle, (uint32_t *)ecdh_public_keyx2, (uint32_t *)ecdh_public_keyy2, (uint32_t *)ecdh_private_key1, ecdh_keyx, ecdh_keyy);
MSG("Get encrypt key time=%dms\r\n", (unsigned int)bflb_platform_get_time_ms());
p = (uint8_t *)ecdh_keyx;
for (i = 0; i < 32; i++) {
if (ecdh_shared_keyx1[i] != p[i]) {
MSG("ECDH Compare fail\r\n");
BL_CASE_FAIL;
}
}
MSG("Another case\r\n");
MSG("Get Public key\r\n");
bflb_platform_clear_time();
sec_ecdh_get_public_key(&ecdh_handle, (uint32_t *)ecdh_private_key, ecdh_keyx, ecdh_keyy);
MSG("Get public key time=%dms\r\n", (unsigned int)bflb_platform_get_time_ms());
p = (uint8_t *)ecdh_keyx;
for (i = 0; i < 32; i++) {
if (ecdh_public_keyx[i] != p[i]) {
MSG("ECDH Compare fail\r\n");
BL_CASE_FAIL;
}
}
p = (uint8_t *)ecdh_keyy;
for (i = 0; i < 32; i++) {
if (ecdh_public_keyy[i] != p[i]) {
MSG("ECDH Compare fail\r\n");
BL_CASE_FAIL;
}
}
MSG("Get shared key\r\n");
bflb_platform_clear_time();
sec_ecdh_get_encrypt_key(&ecdh_handle, ecdh_keyx, ecdh_keyy, (uint32_t *)ecdh_private_key, ecdh_keyx, ecdh_keyy);
MSG("Get share key time=%dms\r\n", (unsigned int)bflb_platform_get_time_ms());
p = (uint8_t *)ecdh_keyx;
for (i = 0; i < 32; i++) {
if (ecdh_shared_keyx[i] != p[i]) {
MSG("ECDH Compare fail\r\n");
BL_CASE_FAIL;
}
}
BL_CASE_SUCCESS;
while (1) {
bflb_platform_delay_ms(100);

View File

@ -30,8 +30,10 @@ void shell_irq_callback(struct device *dev, void *args, uint32_t size, uint32_t
{
uint8_t data;
if (state == UART_EVENT_RX_FIFO) {
data = *(uint8_t *)args;
shell_handler(data);
for (size_t i = 0; i < size; i++) {
data = *(uint8_t *)(args + i);
shell_handler(data);
}
}
}
@ -45,6 +47,13 @@ int main(void)
device_control(uart, DEVICE_CTRL_SET_INT, (void *)(UART_RX_FIFO_IT));
}
acomp_device_t acomp_device;
acomp_device.pos_ch = ACOMP_CHANNEL_ADC_CHANNEL3; /*from gpio11 adc func*/
acomp_device.neg_ch = ACOMP_CHANNEL_0P375VBAT;
acomp_device.pos_hysteresis_vol = ACOMP_HYSTERESIS_VOLT_50MV;
acomp_device.neg_hysteresis_vol = ACOMP_HYSTERESIS_VOLT_50MV;
acomp_init(0, &acomp_device);
while (1) {
bflb_platform_delay_ms(100);
}
@ -52,17 +61,12 @@ int main(void)
int hbn0_enter(int argc, char *argv[])
{
acomp_device_t acomp_device;
acomp_device.id = 0;
acomp_device.pos_ch = ACOMP_CHANNEL_ADC_CHANNEL3; /*from gpio11 adc func*/
acomp_device.neg_ch = ACOMP_CHANNEL_0P375VBAT;
acomp_device.pos_hysteresis_vol = ACOMP_HYSTERESIS_VOLT_50MV;
acomp_device.neg_hysteresis_vol = ACOMP_HYSTERESIS_VOLT_50MV;
acomp_init(&acomp_device);
acomp_enable(0);
acomp_interrupt_unmask(0,ACOMP_POSITIVE_IT|ACOMP_NEGATIVE_IT);
bflb_platform_delay_ms(50); /*delay for acomp*/
for (uint32_t i = 0; i < 30; i++) {
MSG("status:%d\r\n", acomp_get_result(&acomp_device));
MSG("status:%d\r\n", acomp_get_result(0));
bflb_platform_delay_ms(100);
}

View File

@ -30,8 +30,10 @@ void shell_irq_callback(struct device *dev, void *args, uint32_t size, uint32_t
{
uint8_t data;
if (state == UART_EVENT_RX_FIFO) {
data = *(uint8_t *)args;
shell_handler(data);
for (size_t i = 0; i < size; i++) {
data = *(uint8_t *)(args + i);
shell_handler(data);
}
}
}

View File

@ -28,8 +28,10 @@ void shell_irq_callback(struct device *dev, void *args, uint32_t size, uint32_t
{
uint8_t data;
if (state == UART_EVENT_RX_FIFO) {
data = *(uint8_t *)args;
shell_handler(data);
for (size_t i = 0; i < size; i++) {
data = *(uint8_t *)(args + i);
shell_handler(data);
}
}
}