361 lines
7.1 KiB
C
361 lines
7.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_plc_lib.h"
|
|
#include "iot_dbglog_api.h"
|
|
#include "iot_config.h"
|
|
|
|
/* driver includes */
|
|
#include "iot_clock.h"
|
|
#include "iot_uart.h"
|
|
#include "iot_led.h"
|
|
|
|
/* cli includes */
|
|
#include "iot_cli.h"
|
|
#include "iot_uart_h.h"
|
|
|
|
/* debug includes*/
|
|
#include "dbg_io.h"
|
|
|
|
#include "iot_gpio_api.h"
|
|
|
|
#include "apb_glb_reg.h"
|
|
#include "hw_reg_api.h"
|
|
|
|
#include "gpio_mtx_reg.h"
|
|
#include "pin_rf.h"
|
|
#include "gpio_mtx.h"
|
|
#include "iot_share_task.h"
|
|
|
|
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,
|
|
},
|
|
}
|
|
};
|
|
|
|
void mdelay(uint32_t m)
|
|
{
|
|
volatile int i= 0;
|
|
|
|
for(int j = 0 ; j < m; j++){
|
|
for(i = 0; i < 1000000; i++);
|
|
}
|
|
}
|
|
|
|
#include "iot_pkt.h"
|
|
#include "dwc_eth.h"
|
|
|
|
t_dwc_ctrl *g_emac_ctrl = NULL;
|
|
#define EMAC_TEST_UNIT 0
|
|
|
|
char arp_str[] = {0xff,0xff,0xff,0xff,0xff,0xff, 0x00,0x11,0x22,0x33,
|
|
0x44,0x55, 0x08,0x06,0x00,0x01,0x08,0x00,0x06,0x04,
|
|
0x00,0x01, 0x00,0x11,0x22,0x33,0x44,0x55, 0xc0,0xa8,
|
|
0x04,0xa3, 0x00,0x00,0x00,0x00,0x00,0x00, 0xc0,0xa8,
|
|
0x04,0x01, 0x00,0x00,0x00,0x00};
|
|
|
|
char dst_ip[] = {192, 168, 4, 163};
|
|
char src_ip[] = {192, 168, 4, 28};
|
|
os_task_h test_init_handle;
|
|
extern int platform_init();
|
|
|
|
void signal_dump(int sig)
|
|
{
|
|
int data;
|
|
if(sig < 57)
|
|
{
|
|
data = *(volatile int*)(0x44020000 + 0x4*sig);
|
|
iot_printf("\r\nSIGN#%02d(CORE#%02d, DEFT#%02d) <- GPIO#%03d.",
|
|
sig, (data&0x1000)?1:0, (data&0x300)>>8, data&0xFF);
|
|
}
|
|
else
|
|
{
|
|
iot_printf("\r\nSIGN#%02d INVALID!");
|
|
}
|
|
}
|
|
|
|
void gpio_dump(int g)
|
|
{
|
|
int data, data2, addr;
|
|
if(g < 47)
|
|
{
|
|
if(g < 29){
|
|
addr = 0x44007000 + 0x24 + (g << 2);
|
|
} else if(g < 37 ){
|
|
addr = 0x44007000 + 0x4 + ((g-29)<<2);
|
|
}
|
|
else if(g < 43){
|
|
addr = 0x44007000 + 0xa8 + ((g-37)<<2);
|
|
}
|
|
else if( g < 47){
|
|
addr =0x44007000 + 0x98 + ((g-43)<< 2);
|
|
}
|
|
data = *(volatile int*)addr;
|
|
data2 = *(volatile int*)(0x44020400 + 0x4*g);
|
|
iot_printf("\r\nGPIO#%02d(FUNC#%02d, PULL#%c%c) <- SIGN#%03d.",
|
|
g, (data&0x30)>>4, (data&0x80)?'U':'-', (data&0x40)?'D':'-', data2&0xFF);
|
|
}
|
|
else
|
|
{
|
|
iot_printf("\r\nGPIO#%02d INVALID!");
|
|
}
|
|
}
|
|
|
|
void eth_gpio_dump(void)
|
|
{
|
|
int g;
|
|
for(g = 8; g < 15; g++)
|
|
{
|
|
gpio_dump(g);
|
|
}
|
|
|
|
gpio_dump(18);
|
|
gpio_dump(19);
|
|
|
|
signal_dump(43);
|
|
}
|
|
|
|
extern void dwc_gpio_bind(int unit);
|
|
void eth_test_send_ping(void)
|
|
{
|
|
iot_pkt_ls lst;
|
|
uint8_t * data, p_mac[6];
|
|
|
|
lst.pkt = iot_pkt_alloc(52, 0);
|
|
lst.next = NULL;
|
|
|
|
os_mem_cpy(lst.pkt->head, arp_str, sizeof(arp_str));
|
|
iot_pkt_set_data(lst.pkt, lst.pkt->head);
|
|
iot_pkt_set_tail(lst.pkt, lst.pkt->data + sizeof(arp_str));
|
|
|
|
data = lst.pkt->data;
|
|
|
|
dwc_mac_addr_get(g_emac_ctrl, p_mac);
|
|
|
|
data[6] = p_mac[0];
|
|
data[7] = p_mac[1];
|
|
data[8] = p_mac[2];
|
|
data[9] = p_mac[3];
|
|
data[10] = p_mac[4];
|
|
data[11] = p_mac[5];
|
|
|
|
data[22] = p_mac[0];
|
|
data[23] = p_mac[1];
|
|
data[24] = p_mac[2];
|
|
data[25] = p_mac[3];
|
|
data[26] = p_mac[4];
|
|
data[27] = p_mac[5];
|
|
|
|
data[28] = src_ip[0];
|
|
data[29] = src_ip[1];
|
|
data[30] = src_ip[2];
|
|
data[31] = src_ip[3];
|
|
|
|
data[38] = dst_ip[0];
|
|
data[39] = dst_ip[1];
|
|
data[40] = dst_ip[2];
|
|
data[41] = dst_ip[3];
|
|
|
|
dwc_eth_send_frame(g_emac_ctrl, &lst);
|
|
|
|
return;
|
|
}
|
|
|
|
void eth_test_rcv(t_dwc_ctrl* p_ctrl, uint8_t * data, uint32_t len)
|
|
{
|
|
int i;
|
|
|
|
iot_printf("\r\nEth rcv (port=%d, pack_len=%d),packet dump :\r\n", p_ctrl->unit, len);
|
|
|
|
for(i=0; i<len; i++)
|
|
{
|
|
iot_printf("%2.2x ", data[i]);
|
|
if((i+1)%16 == 0)
|
|
iot_printf("\r\n");
|
|
}
|
|
|
|
iot_printf("\r\n");
|
|
|
|
mdelay(20);
|
|
|
|
eth_test_send_ping();
|
|
}
|
|
|
|
int eth_init(void)
|
|
{
|
|
|
|
|
|
/* init common modules */
|
|
iot_bitops_init();
|
|
|
|
/* init os related modules and utilities */
|
|
os_utils_init();
|
|
|
|
/* init dbglog module */
|
|
//iot_dbglog_init();
|
|
|
|
/* init ipc module */
|
|
iot_ipc_init();
|
|
|
|
dbg_uart_init();
|
|
|
|
iot_pkt_init(&test_pkt_config);
|
|
|
|
iot_share_task_init();
|
|
|
|
dwc_eth_init();
|
|
|
|
g_emac_ctrl = dwc_eth_open(EMAC_TEST_UNIT, eth_test_rcv);
|
|
dwc_eth_start(g_emac_ctrl);
|
|
#if 0
|
|
int cnt = 60;
|
|
iot_printf("\r\n\r\nWait for initailization ");
|
|
while(cnt--)
|
|
{
|
|
mdelay(1);/* Phy need time to reset. */
|
|
iot_printf(".");
|
|
}
|
|
iot_printf("\r\n");
|
|
#endif
|
|
eth_gpio_dump();
|
|
eth_test_send_ping();
|
|
dwc_gpio_bind(EMAC_TEST_UNIT);
|
|
|
|
return 0;
|
|
}
|
|
|
|
void init_task(void *arg)
|
|
{
|
|
iot_printf("task 1 entry....\n");
|
|
|
|
for(;;) {
|
|
eth_init();
|
|
os_delete_task(test_init_handle);
|
|
}
|
|
|
|
}
|
|
|
|
int32_t iot_task_init()
|
|
{
|
|
/* start plc lib task */
|
|
test_init_handle = os_create_task(init_task, NULL, 9);
|
|
|
|
|
|
//create the tasks;
|
|
if(test_init_handle != NULL) {
|
|
iot_printf("task 1 init successfully...\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();
|
|
|
|
return 0;
|
|
}
|
|
|
|
int32_t iot_module_init(void)
|
|
{
|
|
//platform intialization;
|
|
iot_platform_init();
|
|
|
|
//create all the tasks;
|
|
iot_task_init();
|
|
|
|
iot_printf("starting OS...\n");
|
|
|
|
return 0;
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
//module init;
|
|
iot_module_init();
|
|
|
|
//module start;
|
|
iot_task_start();
|
|
|
|
return 0;
|
|
}
|
|
|
|
|