453 lines
10 KiB
C
453 lines
10 KiB
C
/****************************************************************************
|
|
*
|
|
* Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
|
|
*
|
|
* This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
|
|
* be copied by any method or incorporated into another program without
|
|
* the express written consent of Aerospace C.Power. This Information or any portion
|
|
* thereof remains the property of Aerospace C.Power. The Information contained herein
|
|
* is believed to be accurate and Aerospace C.Power assumes no responsibility or
|
|
* liability for its use in any way and conveys no license or title under
|
|
* any patent or copyright and makes no representation or warranty that this
|
|
* Information is free from patent or copyright infringement.
|
|
*
|
|
* ****************************************************************************/
|
|
|
|
/* os shim includes */
|
|
#include "os_types.h"
|
|
#include "os_task.h"
|
|
#include "os_utils.h"
|
|
|
|
/* common includes */
|
|
#include "iot_io.h"
|
|
#include "iot_bitops.h"
|
|
#include "iot_pkt.h"
|
|
#include "iot_config.h"
|
|
#include "iot_errno_api.h"
|
|
|
|
/* driver includes */
|
|
#include "iot_clock.h"
|
|
#include "iot_uart.h"
|
|
#include "iot_gpio_api.h"
|
|
#include "iot_i2c_api.h"
|
|
#include "iot_mic_array_api.h"
|
|
#include "apb_dma.h"
|
|
#include "iot_share_task.h"
|
|
|
|
/* debug includes*/
|
|
#include "dbg_io.h"
|
|
|
|
#include "es7210.h"
|
|
|
|
#define AEC_IO_IIC_SCL 56
|
|
#define AEC_IO_IIC_SDA 57
|
|
#define AEC_IO_IIS_MCLK 58
|
|
#define AEC_IO_IIS_BCK 59
|
|
#define AEC_IO_IIS_CLK 60
|
|
#define AEC_IO_IIS_DATA 61
|
|
#define AEC_IO_IIS_DATA2 62
|
|
|
|
extern int platform_init();
|
|
|
|
os_task_h test_init_handle;
|
|
|
|
uint8_t g_es7210_addr = 0x43;
|
|
uint8_t g_pcf8574_addr[4] = {0x24, 0x25, 0x26, 0x27};
|
|
iot_i2c_module_cfg_t g_aec_i2c_cfg = {0};
|
|
|
|
static const iot_pkt_config_t test_pkt_config =
|
|
{
|
|
{
|
|
{
|
|
256,
|
|
50,
|
|
PKT_OWNER_ALL,
|
|
},
|
|
{
|
|
600,
|
|
50,
|
|
PKT_OWNER_ALL,
|
|
},
|
|
{
|
|
1100,
|
|
15,
|
|
PKT_OWNER_ALL,
|
|
},
|
|
{
|
|
2200,
|
|
6,
|
|
PKT_OWNER_ALL,
|
|
},
|
|
{
|
|
0,
|
|
0,
|
|
PKT_OWNER_NONE,
|
|
},
|
|
{
|
|
0,
|
|
0,
|
|
PKT_OWNER_NONE,
|
|
},
|
|
{
|
|
0,
|
|
0,
|
|
PKT_OWNER_NONE,
|
|
},
|
|
{
|
|
0,
|
|
0,
|
|
PKT_OWNER_NONE,
|
|
},
|
|
}
|
|
};
|
|
|
|
int pcf8574_write_command(uint8_t addr, uint8_t value)
|
|
{
|
|
uint8_t ret = 0;
|
|
char buf[4] = {0};
|
|
buf[0] = value;
|
|
|
|
ret = iot_i2c_write(g_aec_i2c_cfg.port, addr, buf, 1);
|
|
|
|
os_delay(2);
|
|
|
|
return ret;
|
|
}
|
|
|
|
int pcf8574_read_command(uint8_t addr, uint8_t *data)
|
|
{
|
|
uint8_t ret = 0;
|
|
|
|
ret = iot_i2c_read(g_aec_i2c_cfg.port, addr, (char *)data, 1);
|
|
if (ret) {
|
|
iot_printf("ov9282_read_command get value error\n");
|
|
return ret;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
int es7210_write_command(uint8_t addr, uint8_t reg, uint8_t val)
|
|
{
|
|
uint8_t ret = 0;
|
|
char buf[4] = {0};
|
|
buf[0] = reg;
|
|
buf[1] = val;
|
|
|
|
ret = iot_i2c_write(g_aec_i2c_cfg.port, addr, buf, 2);
|
|
|
|
os_delay(2);
|
|
|
|
return ret;
|
|
}
|
|
|
|
int es7210_read_command(uint8_t addr, uint8_t reg, uint8_t *data, uint8_t len)
|
|
{
|
|
uint8_t ret = 0;
|
|
char buf[4] = {0};
|
|
buf[0] = reg;
|
|
|
|
ret = iot_i2c_write(g_aec_i2c_cfg.port, addr, buf, 1);
|
|
|
|
if (ret) {
|
|
iot_printf("ov9282_read_command write addr error\n");
|
|
return ret;
|
|
}
|
|
os_delay(2);
|
|
ret = iot_i2c_read(g_aec_i2c_cfg.port, addr, (char *)data, len);
|
|
if (ret) {
|
|
iot_printf("ov9282_read_command get value error\n");
|
|
return ret;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
uint32_t g_recv_cnt = 0;
|
|
uint32_t g_send_cnt = 0;
|
|
#define RECV_ADDR 0x10500000
|
|
uint32_t g_recv_len = 0;
|
|
uint32_t iot_dtest_dma_recv(unsigned char port, uint8_t *buf, uint32_t len)
|
|
{
|
|
#if 0
|
|
//iot_printf("recv port: %d, buf: 0x%08x, len: %d\n", port, buf, len);
|
|
if (g_recv_len < 0x80000) {
|
|
//uint32_t *tmp = (uint32_t *) buf;
|
|
//iot_printf("recv: %08x\n", *tmp);
|
|
os_mem_cpy((uint8_t *) (RECV_ADDR+g_recv_len), buf, len);
|
|
g_recv_len = g_recv_len + len;
|
|
} else {
|
|
//g_recv_len = 0;
|
|
iot_printf("over size\n");
|
|
}
|
|
#endif
|
|
|
|
return 0;
|
|
}
|
|
|
|
void aec_mic_adc_init()
|
|
{
|
|
iot_printf("aec mic adc init...\n");
|
|
|
|
#if 1
|
|
// disbable flash gpio 56 57
|
|
volatile uint32_t *reg = (volatile uint32_t *) 0x440204e0;
|
|
*reg = 0xff;
|
|
*(reg+1) = 0xff;
|
|
// init iic
|
|
g_aec_i2c_cfg.port = IOT_I2C_PORT_0;
|
|
g_aec_i2c_cfg.nack_wait_num = 1;
|
|
g_aec_i2c_cfg.baud = 50;
|
|
g_aec_i2c_cfg.gpio.scl = AEC_IO_IIC_SCL;
|
|
g_aec_i2c_cfg.gpio.sda = AEC_IO_IIC_SDA;
|
|
iot_i2c_module_init(&g_aec_i2c_cfg);
|
|
|
|
#if 1 // adc enable
|
|
uint32_t cnt = 0;
|
|
uint32_t i = 0;
|
|
|
|
cnt = sizeof(g_es7210_iic_cfg) / sizeof(es7210_iic_cfg_t);
|
|
|
|
iot_printf("cnt: %d\n", cnt);
|
|
uint8_t read = 0;
|
|
for(i = 0; i < 0x4d; i++) {
|
|
es7210_read_command(g_es7210_addr, \
|
|
i, &read, 1);
|
|
iot_printf("0x%02x 0x%02x\n", i, read);
|
|
}
|
|
|
|
for(i = 0; i < cnt; i++) {
|
|
es7210_write_command(g_es7210_addr, \
|
|
g_es7210_iic_cfg[i].reg, g_es7210_iic_cfg[i].value);
|
|
}
|
|
|
|
iot_printf("write finish...\n");
|
|
|
|
read = 0;
|
|
for(i = 0; i < cnt; i++) {
|
|
es7210_read_command(g_es7210_addr, \
|
|
g_es7210_iic_cfg[i].reg, &read, 1);
|
|
iot_printf("0x%02x 0x%02x\n", g_es7210_iic_cfg[i].reg, read);
|
|
}
|
|
|
|
iot_printf("read finish...\n");
|
|
#endif
|
|
#endif
|
|
}
|
|
|
|
#define TEST_RAM_ADDR 0x10400000
|
|
uint8_t *g_test_addr = ( uint8_t *) TEST_RAM_ADDR;
|
|
uint32_t g_test_len = 0;
|
|
void test_get_mic_data(uint8_t port)
|
|
{
|
|
while(1) {
|
|
uint32_t a,a_size,b,b_size;
|
|
int ret=0;
|
|
|
|
ret = iot_get_i2s_mic_array_data(port, 0x1000, &a, &a_size, &b, &b_size);
|
|
if (ret != ERR_OK) {
|
|
os_delay(1);
|
|
continue;
|
|
}
|
|
iot_printf("a: %08x, size: %08x, b: %08x, size: %08x\n", a, a_size, b, b_size);
|
|
iot_printf("cnt:%08x, value: %08x\n", g_test_len, *(uint32_t *)a);
|
|
|
|
if (b_size) {
|
|
iot_printf(" value: %08x\n", *(uint32_t *)b);
|
|
}
|
|
if (b_size != 0) {
|
|
uint8_t *src = (uint8_t *) a;
|
|
os_mem_cpy(g_test_addr, src, a_size);
|
|
g_test_addr += a_size;
|
|
src = (uint8_t *) b;
|
|
os_mem_cpy(g_test_addr, src, b_size);
|
|
g_test_addr += b_size;
|
|
} else {
|
|
uint8_t *src = (uint8_t *) a;
|
|
os_mem_cpy(g_test_addr, src, 0x1000);
|
|
g_test_addr += 0x1000;
|
|
}
|
|
g_test_len += 0x1000;
|
|
if (g_test_len > 0x100000) {
|
|
iot_printf("end................");
|
|
//return;
|
|
while(1);
|
|
}
|
|
}
|
|
}
|
|
|
|
static void aec_mic_mclk_init()
|
|
{
|
|
iot_printf("set mclk to 4096KHz\n");
|
|
if(iot_i2s_set_mclk(AEC_IO_IIS_MCLK, 4096*1000)) {
|
|
iot_printf("set mclk failed\n");
|
|
IOT_ASSERT(0);
|
|
}
|
|
}
|
|
|
|
void aec_mic_i2s_init()
|
|
{
|
|
iot_printf("aec mic i2s_init\n");
|
|
#if 1
|
|
// i2s master rx mode
|
|
i2s_config_t i2s_cfg = {0};
|
|
i2s_cfg.clk = 16000;
|
|
i2s_cfg.type = I2S_TYPE_MSTR_RX;
|
|
i2s_cfg.bit_mode = I2S_BITS_16BIT;
|
|
i2s_cfg.msb_right = I2S_MSB_RIGHT_BIT1;
|
|
i2s_cfg.port = I2S_0;
|
|
|
|
i2s_cfg.rx_cfg.data_fmt = I2S_DATA_FMT_DUAL_BIT16;
|
|
i2s_cfg.rx_cfg.chl_sel = I2S_CHL_SEL_DUAL;
|
|
i2s_cfg.rx_cfg.msb_shift = I2S_SHIFT_PHILIPS_DIS;
|
|
i2s_cfg.rx_cfg.rx_eof_len = 160;
|
|
i2s_cfg.rx_cfg.recv = iot_dtest_dma_recv;
|
|
|
|
i2s_pin_sel_t pin_master = {AEC_IO_IIS_BCK, AEC_IO_IIS_CLK, AEC_IO_IIS_DATA};
|
|
|
|
i2s_cfg.pin_master = &pin_master;
|
|
|
|
if (iot_i2s_module_init(&i2s_cfg)) {
|
|
iot_printf("i2s module init failed\n");
|
|
} else {
|
|
iot_printf("i2s module init success\n");
|
|
}
|
|
|
|
aec_mic_mclk_init();
|
|
#endif
|
|
}
|
|
|
|
void aec_mic_array_init()
|
|
{
|
|
iot_printf("aec mic array init\n");
|
|
iot_ana_mic_cfg_t array_cfg = {0};
|
|
|
|
array_cfg.num = 2;
|
|
array_cfg.clk = 16000;
|
|
array_cfg.bit_mode = I2S_BITS_16BIT;
|
|
array_cfg.msb_right = I2S_MSB_RIGHT_BIT1;
|
|
|
|
array_cfg.rx_cfg.data_fmt = I2S_DATA_FMT_DUAL_BIT16;
|
|
array_cfg.rx_cfg.chl_sel = I2S_CHL_SEL_DUAL;
|
|
array_cfg.rx_cfg.msb_shift = I2S_SHIFT_PHILIPS_DIS;
|
|
array_cfg.rx_cfg.rx_eof_len = 960;
|
|
|
|
array_cfg.recv = iot_dtest_dma_recv;
|
|
|
|
array_cfg.mic_cfg[0].port = I2S_0;
|
|
array_cfg.mic_cfg[0].bck_pin = AEC_IO_IIS_BCK;
|
|
array_cfg.mic_cfg[0].lrck_pin = AEC_IO_IIS_CLK;
|
|
array_cfg.mic_cfg[0].data_pin = AEC_IO_IIS_DATA;
|
|
array_cfg.mic_cfg[1].port = I2S_1;
|
|
array_cfg.mic_cfg[1].bck_pin = AEC_IO_IIS_BCK;
|
|
array_cfg.mic_cfg[1].lrck_pin = AEC_IO_IIS_CLK;
|
|
array_cfg.mic_cfg[1].data_pin = AEC_IO_IIS_DATA2;
|
|
|
|
iot_ana_mic_array_init(&array_cfg);
|
|
|
|
aec_mic_mclk_init();
|
|
|
|
os_delay(100);
|
|
|
|
iot_mic_array_start(I2S_0);
|
|
|
|
test_get_mic_data(I2S_0);
|
|
}
|
|
|
|
void aec_mic_test_task()
|
|
{
|
|
|
|
// init es7210 adc
|
|
aec_mic_adc_init();
|
|
|
|
// init mic i2s
|
|
//aec_mic_i2s_init();
|
|
|
|
aec_mic_array_init();
|
|
|
|
// test led
|
|
uint8_t value = 0;
|
|
while(1) {
|
|
for(uint8_t i = 0; i < 4; i++) {
|
|
//pcf8574_write_command(g_pcf8574_addr[i], value);
|
|
}
|
|
value++;
|
|
os_delay(100);
|
|
}
|
|
}
|
|
|
|
int32_t iot_task_init()
|
|
{
|
|
/* init pkt module */
|
|
iot_pkt_init(&test_pkt_config);
|
|
|
|
/* start plc lib task */
|
|
test_init_handle = os_create_task(aec_mic_test_task, NULL, 9);
|
|
|
|
//create the tasks;
|
|
if(test_init_handle != NULL) {
|
|
iot_printf("Task 1 created successfully .. \r\n");
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int32_t iot_task_start()
|
|
{
|
|
//start the tasks;
|
|
os_start_kernel();
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int32_t iot_platform_init()
|
|
{
|
|
/*platform intialization*/
|
|
platform_init();
|
|
|
|
//resource initializations;
|
|
system_clock_init();
|
|
|
|
system_uart_init();
|
|
|
|
dbg_uart_init();
|
|
dbg_uart_stage1_init();
|
|
|
|
iot_share_task_init();
|
|
|
|
dma_hw_init(NULL);
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
int32_t iot_module_init(void)
|
|
{
|
|
//platform intialization;
|
|
iot_platform_init();
|
|
|
|
//create all the tasks;
|
|
iot_task_init();
|
|
|
|
iot_printf("starting...\n");
|
|
|
|
return 0;
|
|
}
|
|
|
|
int32_t iot_module_start(void)
|
|
{
|
|
int32_t res = 0;
|
|
|
|
res = iot_task_start();
|
|
|
|
return res;
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
//module init;
|
|
iot_module_init();
|
|
iot_module_start();
|
|
|
|
return 0;
|
|
}
|
|
|