/**************************************************************************** * * 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_led.h" #include "iot_gpio_api.h" #include "iot_mic_array_api.h" #include "gpio.h" #include "apb_glb_reg.h" #include "hw_reg_api.h" #include "gpio_mtx_reg.h" #include "pin_rf.h" #include "apb.h" #include "gpio_mtx.h" #include "i2s_reg.h" #include "apb_dma.h" #include "dma_hw.h" #include "i2s.h" #include "dma_i2s.h" /* cli includes */ #include "iot_uart_h.h" /* debug includes*/ #include "dbg_io.h" #include "iot_share_task.h" os_task_h test_init_handle; extern int platform_init(); 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, }, } }; //#define I2S_PDM_MODE_TEST #ifdef I2S_PDM_MODE_TEST #define BUF_SIZE 192 #else #define BUF_SIZE 640 #endif void i2s_test_i2s_func(); #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); for(uint8_t i = 0; i < 4; i++) { //iot_printf("%02x", *(buf+i)); } if (port != 0) { return 0; } if (g_recv_len < 0x100000) { 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; } uint32_t iot_dtest_dma_send(unsigned char port, uint8_t *buf, uint32_t len, uint8_t seq) { #if 0 iot_printf("send buf: %x %x %x %x len: %d\n", buf[0], buf[1], buf[2], buf[3], len); iot_printf("send buf len: %d, address : %x\n", len, (uint32_t)buf); #endif return 0; } #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); } } } void test_mic_array_func() { iot_printf("start test mic\n"); iot_mic_array_cfg_t mic_cfg = {0}; mic_cfg.num = 2; mic_cfg.phase = 1; mic_cfg.hp_bypass = 0; mic_cfg.sinc16 = 1; mic_cfg.rx_hp_dsample = 0; mic_cfg.clk = 16000; mic_cfg.lphp_filter = 0x44444444; mic_cfg.recv = iot_dtest_dma_recv; mic_cfg.mic_cfg[0].port = I2S_0; mic_cfg.mic_cfg[0].bck_pin = 60; mic_cfg.mic_cfg[0].data_pin = 59; mic_cfg.mic_cfg[1].port = I2S_1; mic_cfg.mic_cfg[1].bck_pin = 60; mic_cfg.mic_cfg[1].data_pin = 61; iot_mic_array_init(&mic_cfg); os_delay(100); iot_mic_array_start(I2S_0); test_get_mic_data(I2S_0); while(1); } uint16_t test_data[320] = {0}; void test_pdm_mic_func() { iot_printf("start pdm\n"); #if 1 i2s_config_t i2s_cfg = {0}; i2s_cfg.clk = 16000; i2s_cfg.type = /*I2S_TYPE_MSTR_TX |*/ I2S_TYPE_SLAV_RX; i2s_cfg.bit_mode = I2S_BITS_16BIT; i2s_cfg.msb_right = I2S_MSB_RIGHT_BIT1; i2s_cfg.port = I2S_0; #if 0 i2s_cfg.tx_cfg.data_fmt = I2S_DATA_FMT_DUAL_BIT16; i2s_cfg.tx_cfg.chl_sel = I2S_CHL_SEL_DUAL; i2s_cfg.tx_cfg.msb_shift = I2S_SHIFT_PHILIPS_DIS; i2s_cfg.tx_cfg.tx_desc_num = 8; i2s_cfg.tx_cfg.send = iot_dtest_dma_send; #endif #if 1 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; #endif //i2s_pin_sel_t pin_master = {1, 3, 5}; i2s_pin_sel_t pin_slave = {0, 32, 4}; //i2s_cfg.pin_master = &pin_master; i2s_cfg.pin_slave = &pin_slave; if (iot_i2s_module_init(&i2s_cfg)) { iot_printf("i2s module init failed\n"); } else { iot_printf("i2s module init success\n"); } #endif while(1) { os_delay(1000); } } void mic_test_task() { dma_hw_init(NULL); //test_pdm_mic_func(); test_mic_array_func(); } int32_t iot_task_init() { /* init pkt module */ iot_pkt_init(&test_pkt_config); /* start plc lib task */ test_init_handle = os_create_task(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(); iot_led_init(); 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; }