Files
kunlun/dtest/dtest3/kl3_clock_tree_test/main.c
2024-09-28 14:24:04 +08:00

270 lines
6.2 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_ipc.h"
#include "iot_dbglog_api.h"
#include "iot_config.h"
/* driver includes */
#include "iot_clock.h"
#include "iot_uart.h"
#include "iot_uart_h.h"
#include "iot_dma.h"
#include "cpu.h"
#include "uart.h"
#include "apb_hw.h"
#include "apb.h"
#include "iot_adc_api.h"
#include "iot_gpio_api.h"
/* debug includes*/
#include "dbg_io.h"
#include "rtc.h"
#include "ahb.h"
#include "gpio.h"
#include "gpio_mtx_hw.h"
#include "gpio_mtx.h"
#include "smc_rf.h"
#include "smc.h"
#include "sfc.h"
#include "flash.h"
#include "clk.h"
#include "hw_reg_api.h"
#include "apb_hw.h"
#include "apb.h"
#include "sar_adc_reg.h"
#include "bond_reg.h"
#include "cpu.h"
#include "ana_dig_wrap_rf.h"
#include "mac_reset.h"
extern int platform_init();
static os_task_h test_init_handle;
uint32_t clk_debug_output_set(uint32_t type, uint32_t div, uint32_t gpio);
static const iot_pkt_config_t test_pkt_config =
{
{
{
256,
25,
PKT_OWNER_ALL,
},
{
600,
25,
PKT_OWNER_ALL,
},
{
1100,
10,
PKT_OWNER_ALL,
},
{
2200,
3,
PKT_OWNER_ALL,
},
{
0,
0,
PKT_OWNER_NONE,
},
{
0,
0,
PKT_OWNER_NONE,
},
{
0,
0,
PKT_OWNER_NONE,
},
{
0,
0,
PKT_OWNER_NONE,
},
}
};
static void iot_sub_system_init()
{
/* init common modules */
iot_bitops_init();
/* init os related modules and utilities */
os_utils_init();
/* init pkt module */
iot_pkt_init(&test_pkt_config);
/* init ipc module */
iot_ipc_init();
}
static void iot_task_1(void *arg)
{
uint8_t test_case = 2;
uint8_t test_pin = 33;
/* tpye : 1-XTAL, 2-APB, 3-MPLL, 4-WPHY_FCLK, 5-PLC_ADC, 6-PLC_DAC,
7-TPID, 8-METER, 9-AHB, 10-PLC_50, 11-PLC_75, 12-PLC_150.
*/
uint8_t test_clk_type = 9;
iot_sub_system_init();
if (0) {
iot_gpio_open_as_output(test_pin);
while (1) {
os_delay(1000);
iot_gpio_value_set(test_pin, 1);
os_delay(1000);
iot_gpio_value_set(test_pin, 0);
}
}
iot_printf("clock tree test\n");
apb_enable(APB_GMTX);
gpio_pin_select(test_pin, 0);
//CLK_FRQ_75M CLK_FRQ_150M
//clk_core_freq_set(CLK_FRQ_25M);
/*
CLK_FRQ_GP_IDX_XTAL = 0,
CLK_FRQ_GP_IDX_LOW_POWER = 1,
CLK_FRQ_GP_IDX_SLOW = 2,
CLK_FRQ_GP_IDX_MEDIUM_SPEED = 3,
CLK_FRQ_GP_IDX_FAST = 4,
CLK_FRQ_GP_IDX_PERFORMANCE = 5,
CLK_FRQ_GP_IDX_MAX
*/
clk_system_clock_tree_config(CLK_FRQ_GP_IDX_FAST);
if (8 == test_clk_type) {
//HW module read/write macro
int data = DTOP_ANA_INF_READ_REG(CFG_ANA_DIG_REG_CFG23_ADDR);
REG_FIELD_SET(D_METER_ADC_EN, data, 1);
DTOP_ANA_INF_WRITE_REG(CFG_ANA_DIG_REG_CFG23_ADDR, data);
} else if (7 == test_clk_type) {
//HW module read/write macro
int data = DTOP_ANA_INF_READ_REG(CFG_ANA_DIG_REG_CFG24_ADDR);
REG_FIELD_SET(D_TPID_ADC_EN, data, 1);
DTOP_ANA_INF_WRITE_REG(CFG_ANA_DIG_REG_CFG24_ADDR, data);
} else if (5 == test_clk_type || 6 == test_clk_type) {
ahb_phy_mac_enable();
mac_sw_trig_need_en(false);
}
switch (test_case) {
case 0:
//sfc_clk_div_set(0);
hal_qspi_cfg_sfc_clk_out(true);
gpio_mtx_sig_out(GPIO_MTX_SFC_SPI_CLK_OUT_MON, test_pin);
break;
case 1:
//hal_smc_clk_div_set(0);
hal_smc_clk_out(true);
gpio_mtx_sig_out(GPIO_MTX_SMC_SPI_CLK_OUT_MON, test_pin);
break;
case 2:
// div : 0x1 - DIV2, 0x3 - DIV4, 0x7 - DIV8, 0xF - DIV16.
clk_debug_output_set(test_clk_type, 1, test_pin);
break;
case 3:
break;
default:break;
}
for (;;) {
os_delay(1000);
iot_printf(".");
}
}
static int32_t iot_task_init()
{
/* start plc lib task */
test_init_handle = os_create_task(iot_task_1, NULL, 9);
/* create the tasks */
if (test_init_handle != NULL) {
iot_printf("task create successfully...\n");
}
return 0;
}
static void cache_init()
{
cache_enable(AHB_CACHE_D0);
cache_set_buffer_mode(AHB_CACHE_D0, 1);
cache_enable(AHB_CACHE_D1);
cache_set_buffer_mode(AHB_CACHE_D1, 1);
}
static int32_t iot_platform_init()
{
cache_init();
/* platform intialization */
platform_init();
/* resource initializations */
system_clock_init();
system_uart_init();
dbg_uart_init();
dbg_uart_stage1_init();
iot_printf("iot platform init successfully...\n");
/* rtc init, idle used rtc lock */
iot_rtc_init();
return 0;
}
static int32_t iot_task_start()
{
//start the tasks;
os_start_kernel();
return 0;
}
int main(void)
{
//platform intialization;
iot_platform_init();
//create all the tasks;
iot_task_init();
iot_task_start();
return 0;
}