390 lines
12 KiB
C
390 lines
12 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.
|
|||
|
|
|||
|
****************************************************************************/
|
|||
|
#include "chip_reg_base.h"
|
|||
|
#include "hw_reg_api.h"
|
|||
|
#include "sram.h"
|
|||
|
#include "irq.h"
|
|||
|
|
|||
|
#if HW_PLATFORM > HW_PLATFORM_SIMU
|
|||
|
#include "dbg_io.h"
|
|||
|
#endif
|
|||
|
#include "iot_io.h"
|
|||
|
|
|||
|
#include "watchdog.h"
|
|||
|
#include "ahb.h"
|
|||
|
#include "cpu.h"
|
|||
|
#include "gp_timer.h"
|
|||
|
#include "os_mem_api.h"
|
|||
|
#include "uart.h"
|
|||
|
#include "apb_hw.h"
|
|||
|
#include "apb.h"
|
|||
|
#include "os_utils_api.h"
|
|||
|
#include "iot_errno_api.h"
|
|||
|
#include "dtest_printf.h"
|
|||
|
#include "iot_mem.h"
|
|||
|
#include "iot_string.h"
|
|||
|
#include "gpio.h"
|
|||
|
#include "gpio_mtx.h"
|
|||
|
#include "chip_reg_base.h"
|
|||
|
#include "ahb_rf_s.h"
|
|||
|
#include "iot_string_api.h"
|
|||
|
#include "encoding.h"
|
|||
|
#include "iot_gpio.h"
|
|||
|
|
|||
|
#define DTEST_GPIO_PIN 58
|
|||
|
|
|||
|
#define CORE0_TEST_PIN 58
|
|||
|
#define CORE1_TEST_PIN 62
|
|||
|
#define CORE2_TEST_PIN 63
|
|||
|
|
|||
|
|
|||
|
#define ITEM_NUM(items) sizeof(items) / sizeof(items[0])
|
|||
|
#define _NEXTLINE_ "\r\n"
|
|||
|
|
|||
|
|
|||
|
#define DTEST_GPIO_INPUT (1u << 0)
|
|||
|
#define DTEST_GPIO_OUTPUT (1u << 1)
|
|||
|
#define DTEST_GPIO_INT (1u << 2)
|
|||
|
|
|||
|
|
|||
|
extern iot_gpio_op_t hw_gpio_api_table;
|
|||
|
|
|||
|
|
|||
|
extern void _core_start(void);
|
|||
|
extern void _start(void);
|
|||
|
|
|||
|
|
|||
|
static void dtest_dummy_delay(uint32_t tick)
|
|||
|
{
|
|||
|
volatile uint32_t loop;
|
|||
|
|
|||
|
loop = tick;
|
|||
|
while(loop--);
|
|||
|
}
|
|||
|
|
|||
|
static void dtest_start_init(void)
|
|||
|
{
|
|||
|
dbg_uart_init();
|
|||
|
apb_enable(APB_GMTX);
|
|||
|
apb_enable(APB_GPIO);
|
|||
|
gp_timer_init();
|
|||
|
}
|
|||
|
|
|||
|
int dtest_gpio_input(void)
|
|||
|
{
|
|||
|
int8_t ret = ERR_OK;
|
|||
|
|
|||
|
dcase_start("GPIO input test:high and low!"_NEXTLINE_);
|
|||
|
|
|||
|
hw_gpio_api_table.gpio_init();
|
|||
|
gpio_pin_select(DTEST_GPIO_PIN,0);
|
|||
|
hw_gpio_api_table.set_gpio_mode(DTEST_GPIO_PIN,GPIO_INPUT);
|
|||
|
hw_gpio_api_table.set_value(DTEST_GPIO_PIN,0);
|
|||
|
|
|||
|
if (hw_gpio_api_table.get_value(DTEST_GPIO_PIN)) {
|
|||
|
dprintf("pls set GPIO%d level low."_NEXTLINE_, DTEST_GPIO_PIN);
|
|||
|
dtest_dummy_delay(0xFFFF);
|
|||
|
while(hw_gpio_api_table.get_value(DTEST_GPIO_PIN));
|
|||
|
dprintf("GPIO%d set level low succeed."_NEXTLINE_, DTEST_GPIO_PIN);
|
|||
|
|
|||
|
dprintf("pls set GPIO%d level high."_NEXTLINE_, DTEST_GPIO_PIN);
|
|||
|
dtest_dummy_delay(0xFFFF);
|
|||
|
while(!hw_gpio_api_table.get_value(DTEST_GPIO_PIN));
|
|||
|
dprintf("GPIO%d set level high succeed."_NEXTLINE_, DTEST_GPIO_PIN);
|
|||
|
} else {
|
|||
|
dprintf("pls set GPIO%d level low."_NEXTLINE_, DTEST_GPIO_PIN);
|
|||
|
dtest_dummy_delay(0xFFFF);
|
|||
|
while(hw_gpio_api_table.get_value(DTEST_GPIO_PIN));
|
|||
|
dprintf("GPIO%d set level low succeed."_NEXTLINE_, DTEST_GPIO_PIN);
|
|||
|
|
|||
|
dprintf("pls set GPIO%d level high."_NEXTLINE_, DTEST_GPIO_PIN);
|
|||
|
dtest_dummy_delay(0xFFFF);
|
|||
|
while(!hw_gpio_api_table.get_value(DTEST_GPIO_PIN));
|
|||
|
dprintf("GPIO%d set level high succeed."_NEXTLINE_, DTEST_GPIO_PIN);
|
|||
|
}
|
|||
|
|
|||
|
if (ret == ERR_FAIL){
|
|||
|
dcase_failed();
|
|||
|
}else {
|
|||
|
dcase_success();
|
|||
|
}
|
|||
|
return ret;
|
|||
|
}
|
|||
|
|
|||
|
int dtest_gpio_output(void)
|
|||
|
{
|
|||
|
int8_t ret = ERR_OK;
|
|||
|
uint32_t count = 0;
|
|||
|
|
|||
|
dcase_start("GPIO output test:high and low!"_NEXTLINE_);
|
|||
|
|
|||
|
hw_gpio_api_table.gpio_init();
|
|||
|
gpio_pin_select(DTEST_GPIO_PIN,0);
|
|||
|
hw_gpio_api_table.set_gpio_mode(DTEST_GPIO_PIN,GPIO_OUTPUT);
|
|||
|
|
|||
|
while(++count < 1000){
|
|||
|
dprintf("GPIO%d is set output low."_NEXTLINE_, DTEST_GPIO_PIN);
|
|||
|
hw_gpio_api_table.set_value(DTEST_GPIO_PIN,0);
|
|||
|
dtest_dummy_delay(0xFFFF);
|
|||
|
|
|||
|
dprintf("GPIO%d is set output high."_NEXTLINE_, DTEST_GPIO_PIN);
|
|||
|
hw_gpio_api_table.set_value(DTEST_GPIO_PIN,0);
|
|||
|
dtest_dummy_delay(0xFFFF);
|
|||
|
}
|
|||
|
if (ret == ERR_FAIL){
|
|||
|
dcase_failed();
|
|||
|
}else {
|
|||
|
dcase_success();
|
|||
|
}
|
|||
|
return ret;
|
|||
|
}
|
|||
|
uint32_t IRAM_ATTR gpio_int_handler0(uint32_t vector, iot_addrword_t data)
|
|||
|
{
|
|||
|
uint32_t cur_cpu = cpu_get_mhartid();
|
|||
|
if (0 == cur_cpu) {
|
|||
|
if (hw_gpio_api_table.get_interrupt_status(CORE0_TEST_PIN)) {
|
|||
|
iot_printf("Core0 irq enter...."_NEXTLINE_);
|
|||
|
hw_gpio_api_table.clear_interrupt_status(CORE0_TEST_PIN);
|
|||
|
}
|
|||
|
}
|
|||
|
else if (1 == cur_cpu){
|
|||
|
if (hw_gpio_api_table.get_interrupt_status(CORE1_TEST_PIN)) {
|
|||
|
g_uart_ctrl.puts(UART_PT2,(uint8_t *)"Core1 irq enter.....\r\n",iot_strlen("Core1 irq enter.....\r\n"));
|
|||
|
hw_gpio_api_table.clear_interrupt_status(CORE1_TEST_PIN);
|
|||
|
}
|
|||
|
}
|
|||
|
else if (2 == cur_cpu){
|
|||
|
if (hw_gpio_api_table.get_interrupt_status(CORE2_TEST_PIN))
|
|||
|
{
|
|||
|
g_uart_ctrl.puts(UART_PT3,(uint8_t *)"Core2 irq enter.....\r\n",iot_strlen("Core2 irq enter.....\r\n"));
|
|||
|
hw_gpio_api_table.clear_interrupt_status(CORE2_TEST_PIN);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
uint32_t IRAM_ATTR gpio_int_handler1(uint32_t vector, iot_addrword_t data)
|
|||
|
{
|
|||
|
uint32_t cur_cpu = cpu_get_mhartid();
|
|||
|
if (0 == cur_cpu) {
|
|||
|
if (hw_gpio_api_table.get_interrupt_status(CORE0_TEST_PIN)) {
|
|||
|
iot_printf("Core0 irq enter...."_NEXTLINE_);
|
|||
|
hw_gpio_api_table.clear_interrupt_status(CORE0_TEST_PIN);
|
|||
|
}
|
|||
|
}
|
|||
|
else if (1 == cur_cpu){
|
|||
|
if (hw_gpio_api_table.get_interrupt_status(CORE1_TEST_PIN)) {
|
|||
|
g_uart_ctrl.puts(UART_PT2,(uint8_t *)"Core1 irq enter.....\r\n",iot_strlen("Core1 irq enter.....\r\n"));
|
|||
|
hw_gpio_api_table.clear_interrupt_status(CORE1_TEST_PIN);
|
|||
|
}
|
|||
|
}
|
|||
|
else if (2 == cur_cpu){
|
|||
|
if (hw_gpio_api_table.get_interrupt_status(CORE2_TEST_PIN))
|
|||
|
{
|
|||
|
g_uart_ctrl.puts(UART_PT3,(uint8_t *)"Core2 irq enter.....\r\n",iot_strlen("Core2 irq enter.....\r\n"));
|
|||
|
hw_gpio_api_table.clear_interrupt_status(CORE2_TEST_PIN);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
uint32_t IRAM_ATTR gpio_int_handler2(uint32_t vector, iot_addrword_t data)
|
|||
|
{
|
|||
|
uint32_t cur_cpu = cpu_get_mhartid();
|
|||
|
if (0 == cur_cpu) {
|
|||
|
if (hw_gpio_api_table.get_interrupt_status(CORE0_TEST_PIN)) {
|
|||
|
iot_printf("Core0 irq enter...."_NEXTLINE_);
|
|||
|
hw_gpio_api_table.clear_interrupt_status(CORE0_TEST_PIN);
|
|||
|
}
|
|||
|
}
|
|||
|
else if (1 == cur_cpu){
|
|||
|
if (hw_gpio_api_table.get_interrupt_status(CORE1_TEST_PIN)) {
|
|||
|
g_uart_ctrl.puts(UART_PT2,(uint8_t *)"Core1 irq enter.....\r\n",iot_strlen("Core1 irq enter.....\r\n"));
|
|||
|
hw_gpio_api_table.clear_interrupt_status(CORE1_TEST_PIN);
|
|||
|
}
|
|||
|
}
|
|||
|
else if (2 == cur_cpu){
|
|||
|
if (hw_gpio_api_table.get_interrupt_status(CORE2_TEST_PIN))
|
|||
|
{
|
|||
|
g_uart_ctrl.puts(UART_PT3,(uint8_t *)"Core2 irq enter.....\r\n",iot_strlen("Core2 irq enter.....\r\n"));
|
|||
|
hw_gpio_api_table.clear_interrupt_status(CORE2_TEST_PIN);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
void gpio_core0_test_loop(void)
|
|||
|
{
|
|||
|
dcase_start("GPIO core0 interrupt test!"_NEXTLINE_);
|
|||
|
|
|||
|
hw_gpio_api_table.gpio_init();
|
|||
|
gpio_pin_select(CORE0_TEST_PIN,0);
|
|||
|
/* attach irq */
|
|||
|
iot_irq_t gpio_irq_h =
|
|||
|
iot_interrupt_create(HAL_VECTOR_GPIO, HAL_INTR_PRI_6, CORE0_TEST_PIN, gpio_int_handler0);
|
|||
|
iot_interrupt_attach(gpio_irq_h);
|
|||
|
iot_interrupt_unmask(gpio_irq_h);
|
|||
|
hw_gpio_api_table.set_gpio_mode(CORE0_TEST_PIN,GPIO_INTERRUPT);
|
|||
|
hw_gpio_api_table.set_interrupt_mode(CORE0_TEST_PIN,GPIO_INT_EDGE_FALLING);
|
|||
|
|
|||
|
while(1) {
|
|||
|
dtest_dummy_delay(0xFFFFF);
|
|||
|
iot_printf("Core 0 running.....\r\n");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void gpio_core1_test_loop(void)
|
|||
|
{
|
|||
|
/* init uart device */
|
|||
|
g_uart_ctrl.init(UART_PT2);
|
|||
|
/* uart IO remap */
|
|||
|
iot_uart_set_pin(UART_PT2, 0xFF, 8);
|
|||
|
/* config uart:115200,8N1 */
|
|||
|
g_uart_ctrl.config(UART_PT2, 115200, UART_DATA_8_BITS,
|
|||
|
UART_STOP_BITS_1, UART_PARITY_DISABLE);
|
|||
|
|
|||
|
hw_gpio_api_table.gpio_init();
|
|||
|
gpio_pin_select(CORE1_TEST_PIN,0);
|
|||
|
/* attach irq */
|
|||
|
iot_irq_t gpio_irq_h =
|
|||
|
iot_interrupt_create(HAL_VECTOR_GPIO1, HAL_INTR_PRI_6, CORE1_TEST_PIN, gpio_int_handler1);
|
|||
|
iot_interrupt_attach(gpio_irq_h);
|
|||
|
iot_interrupt_unmask(gpio_irq_h);
|
|||
|
hw_gpio_api_table.set_gpio_mode(CORE1_TEST_PIN,GPIO_INTERRUPT);
|
|||
|
hw_gpio_api_table.set_interrupt_mode(CORE1_TEST_PIN,GPIO_INT_EDGE_FALLING);
|
|||
|
while(1) {
|
|||
|
dtest_dummy_delay(0xFFFFF);
|
|||
|
g_uart_ctrl.puts(UART_PT2,(uint8_t *)"Core 1 running.....\r\n",iot_strlen("Core 1 running.....\r\n"));
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
void gpio_core2_test_loop(void)
|
|||
|
{
|
|||
|
|
|||
|
/* init uart device */
|
|||
|
g_uart_ctrl.init(UART_PT3);
|
|||
|
/* uart IO remap */
|
|||
|
iot_uart_set_pin(UART_PT3, 0xFF, 36);
|
|||
|
/* config uart:115200,8N1 */
|
|||
|
g_uart_ctrl.config(UART_PT3, 115200, UART_DATA_8_BITS,
|
|||
|
UART_STOP_BITS_1, UART_PARITY_DISABLE);
|
|||
|
|
|||
|
hw_gpio_api_table.gpio_init();
|
|||
|
gpio_pin_select(CORE2_TEST_PIN,0);
|
|||
|
/* attach irq */
|
|||
|
iot_irq_t gpio_irq_h =
|
|||
|
iot_interrupt_create(HAL_VECTOR_GPIO2, HAL_INTR_PRI_6, CORE2_TEST_PIN, gpio_int_handler2);
|
|||
|
iot_interrupt_attach(gpio_irq_h);
|
|||
|
iot_interrupt_unmask(gpio_irq_h);
|
|||
|
hw_gpio_api_table.set_gpio_mode(CORE2_TEST_PIN,GPIO_INTERRUPT);
|
|||
|
hw_gpio_api_table.set_interrupt_mode(CORE2_TEST_PIN,GPIO_INT_EDGE_FALLING);
|
|||
|
|
|||
|
while(1) {
|
|||
|
dtest_dummy_delay(0xFFFFF);
|
|||
|
g_uart_ctrl.puts(UART_PT3,(uint8_t *)"Core 2 running.....\r\n",iot_strlen("Core 2 running.....\r\n"));
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
int dtest_gpio_interrupt(void)
|
|||
|
{
|
|||
|
int8_t ret = ERR_OK;
|
|||
|
uint32_t cur_cpu = cpu_get_mhartid();
|
|||
|
|
|||
|
if (0 == cur_cpu) {
|
|||
|
dbg_uart_init();
|
|||
|
ahb_core1_set_start((uint32_t) _core_start);
|
|||
|
ahb_core1_enable();
|
|||
|
ahb_core1_reset();
|
|||
|
gpio_core0_test_loop();
|
|||
|
while(1);
|
|||
|
|
|||
|
} else if (1 == cur_cpu) {
|
|||
|
ahb_core2_set_start((uint32_t) _core_start);
|
|||
|
ahb_core2_enable();
|
|||
|
ahb_core2_reset();
|
|||
|
gpio_core1_test_loop();
|
|||
|
while(1);
|
|||
|
|
|||
|
} else {
|
|||
|
/*
|
|||
|
* 这里要开启core2中断,需要手动把iot_interrupt_init函数如下修改:
|
|||
|
* if (cpu != 2)
|
|||
|
hal_interrupt_handlers[i] = (iot_addr_t)hal_default_isr;
|
|||
|
*/
|
|||
|
extern void _init();
|
|||
|
_init();
|
|||
|
gpio_core2_test_loop();
|
|||
|
}
|
|||
|
|
|||
|
if (ret == ERR_FAIL){
|
|||
|
dcase_failed();
|
|||
|
}else {
|
|||
|
dcase_success();
|
|||
|
}
|
|||
|
return ret;
|
|||
|
}
|
|||
|
|
|||
|
static void dtest_gpio_main(void)
|
|||
|
{
|
|||
|
uint32_t case_group = 0, failed_cnt = 0;
|
|||
|
|
|||
|
dconfig();
|
|||
|
dstart();
|
|||
|
dversion();
|
|||
|
|
|||
|
//if (dtest_get_case_group(&case_group) < 0) {
|
|||
|
case_group = 0xffffffff;
|
|||
|
// }
|
|||
|
|
|||
|
dprintf("dtest_uart case group:0x%08x\n", case_group);
|
|||
|
#if 0
|
|||
|
if (case_group & DTEST_GPIO_INPUT) {
|
|||
|
if (dtest_gpio_input() != ERR_OK) {
|
|||
|
failed_cnt++;
|
|||
|
}
|
|||
|
}
|
|||
|
if (case_group & DTEST_GPIO_OUTPUT) {
|
|||
|
if (dtest_gpio_output() != ERR_OK) {
|
|||
|
failed_cnt++;
|
|||
|
}
|
|||
|
}
|
|||
|
#endif
|
|||
|
if (case_group & DTEST_GPIO_INT) {
|
|||
|
if (dtest_gpio_interrupt() != ERR_OK) {
|
|||
|
failed_cnt++;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (failed_cnt) {
|
|||
|
dprintf("uart dtest failed\n");
|
|||
|
} else {
|
|||
|
dprintf("uart dtest succeed\n");
|
|||
|
}
|
|||
|
dend();
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
int main(void) {
|
|||
|
dtest_start_init();
|
|||
|
dtest_gpio_main();
|
|||
|
return 0;
|
|||
|
}
|