315 lines
6.1 KiB
C
315 lines
6.1 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 "uart.h"
|
|
#include "apb_dma.h"
|
|
#include "dma_hw.h"
|
|
|
|
/* cli includes */
|
|
#include "iot_cli.h"
|
|
#include "iot_uart_h.h"
|
|
|
|
/* debug includes*/
|
|
#include "dbg_io.h"
|
|
/* driver includes */
|
|
#include "cpu.h"
|
|
#include "iot_gpio_api.h"
|
|
#include "hw_reg_api.h"
|
|
#include "pin_rf.h"
|
|
#include "dtest_printf.h"
|
|
#include "iot_share_task.h"
|
|
#include "ahb.h"
|
|
#include "rtc.h"
|
|
|
|
extern int platform_init();
|
|
|
|
os_task_h test_init_handle;
|
|
|
|
static const iot_pkt_config_t test_pkt_config =
|
|
{
|
|
{
|
|
{
|
|
256,
|
|
1,
|
|
PKT_OWNER_ALL,
|
|
},
|
|
{
|
|
600,
|
|
1,
|
|
PKT_OWNER_ALL,
|
|
},
|
|
{
|
|
1100,
|
|
1,
|
|
PKT_OWNER_ALL,
|
|
},
|
|
{
|
|
2200,
|
|
1,
|
|
PKT_OWNER_ALL,
|
|
},
|
|
{
|
|
0,
|
|
0,
|
|
PKT_OWNER_NONE,
|
|
},
|
|
{
|
|
0,
|
|
0,
|
|
PKT_OWNER_NONE,
|
|
},
|
|
{
|
|
0,
|
|
0,
|
|
PKT_OWNER_NONE,
|
|
},
|
|
{
|
|
0,
|
|
0,
|
|
PKT_OWNER_NONE,
|
|
},
|
|
}
|
|
};
|
|
|
|
#define GPIO_FUNC_MASK 0x70
|
|
|
|
#define TEST_OUTPUT 34
|
|
#define TEST_INPUT 35
|
|
#define TEST_INT 33
|
|
|
|
int int_mode = GPIO_INT_LEVEL_LOW;
|
|
|
|
static void gpio_func_set(uint8_t gpio_no, uint8_t func)
|
|
{
|
|
uint32_t tmp;
|
|
uint32_t addr;
|
|
|
|
addr = CFG_GPIO00_PIN_CFG_ADDR + (gpio_no << 2);
|
|
|
|
tmp = DIG_PIN_READ_REG(addr);
|
|
/* Set function */
|
|
tmp &= ~(GPIO_FUNC_MASK);
|
|
tmp |= (func<<4)&GPIO_FUNC_MASK;
|
|
/* Set pull-up */
|
|
tmp &= ~0x40;
|
|
tmp |= 0x80;
|
|
DIG_PIN_WRITE_REG(addr, tmp);
|
|
|
|
return ;
|
|
}
|
|
|
|
void gpio_task_hander(int pin)
|
|
{
|
|
dprintf("GPIO%02d has been triggered!, tri_mode:%d\n", pin, int_mode);
|
|
os_delay(500);
|
|
iot_gpio_interrupt_enable(pin, 1);
|
|
}
|
|
|
|
void test_task_gpio(){
|
|
int v=0, r;
|
|
(void)v;
|
|
|
|
dprintf("test_task....\n");
|
|
gpio_func_set(TEST_INT, 0);
|
|
gpio_func_set(TEST_OUTPUT, 0);
|
|
gpio_func_set(TEST_INPUT, 0);
|
|
|
|
r = iot_gpio_open_as_output(TEST_OUTPUT);
|
|
r |= iot_gpio_set_pull_mode(TEST_OUTPUT, GPIO_PULL_UP);
|
|
r |= iot_gpio_open_as_input(TEST_INPUT);
|
|
if(r != 0)
|
|
{
|
|
dprintf("\ngpio config failed!\n");
|
|
}
|
|
r = iot_gpio_open_as_interrupt(TEST_INT);
|
|
dprintf("\ngpio int open ret = %d\n", r);
|
|
|
|
r = iot_gpio_interrupt_config
|
|
(TEST_INT, int_mode, (iot_gpio_isr_func)gpio_task_hander, TEST_INT, 1);
|
|
dprintf("\ngpio int config ret = %d\n", r);
|
|
|
|
r = iot_gpio_interrupt_enable(TEST_INT, 1);
|
|
dprintf("\ngpio int config ret = %d\n", r);
|
|
|
|
for(;;) {
|
|
|
|
if(v)
|
|
{
|
|
dprintf("\nSet low!");
|
|
v = 0;
|
|
}
|
|
else
|
|
{
|
|
dprintf("\nSet High!");
|
|
v = 1;
|
|
}
|
|
|
|
if(0 != iot_gpio_value_set(TEST_OUTPUT, v))
|
|
{
|
|
dprintf("!!! WRITE FAILED !!!\n");
|
|
}
|
|
r = iot_gpio_value_get(TEST_INPUT);
|
|
if(r)
|
|
{
|
|
dprintf("Get High\n");
|
|
}
|
|
else
|
|
{
|
|
dprintf("Get Low\n");
|
|
}
|
|
|
|
os_delay(3000);
|
|
|
|
}
|
|
}
|
|
|
|
void test_init()
|
|
{
|
|
/* init common modules */
|
|
iot_bitops_init();
|
|
|
|
/* init os related modules and utilities */
|
|
os_utils_init();
|
|
|
|
/* init dbglog module */
|
|
iot_dbglog_init();
|
|
|
|
/* init pkt module */
|
|
iot_pkt_init(&test_pkt_config);
|
|
|
|
/* init ipc module */
|
|
//iot_ipc_init();
|
|
|
|
/*init uart module*/
|
|
iot_uart_init(1);
|
|
|
|
iot_share_task_init();
|
|
|
|
/* init gpio module */
|
|
iot_gpio_module_init();
|
|
|
|
test_task_gpio();
|
|
}
|
|
|
|
|
|
void iot_task_1(void *arg)
|
|
{
|
|
dprintf("task 1 entry....\n");
|
|
test_init();
|
|
|
|
for(;;) {
|
|
os_delete_task(test_init_handle);
|
|
dprintf("task 1 running....\n");
|
|
os_delay(1000);
|
|
}
|
|
|
|
}
|
|
|
|
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) {
|
|
dprintf("task 1 init successfully...\n");
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int32_t iot_task_start()
|
|
{
|
|
//start the tasks;
|
|
os_start_kernel();
|
|
|
|
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();
|
|
|
|
/* rtc init, idle used rtc lock */
|
|
iot_rtc_init();
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
int32_t iot_module_init(void)
|
|
{
|
|
//platform intialization;
|
|
iot_platform_init();
|
|
|
|
//create all the tasks;
|
|
iot_task_init();
|
|
|
|
dprintf("starting...\n");
|
|
|
|
return 0;
|
|
}
|
|
|
|
int32_t iot_module_start(void)
|
|
{
|
|
int32_t res = 0;
|
|
|
|
res = iot_task_start();
|
|
|
|
return res;
|
|
}
|
|
#include "apb_dma.h"
|
|
int main(void)
|
|
{
|
|
//module init;
|
|
iot_module_init();
|
|
iot_module_start();
|
|
return 0;
|
|
}
|