初始提交
This commit is contained in:
67
dtest/emac_test_kl2/Makefile
Normal file
67
dtest/emac_test_kl2/Makefile
Normal file
@@ -0,0 +1,67 @@
|
||||
|
||||
# OUTPUT type
|
||||
# 1 - .out
|
||||
# 2 - .a
|
||||
# 3 - .so
|
||||
OUTPUT_TYPE = 1
|
||||
OUTPUT_NAME = emac_test
|
||||
|
||||
SUB_DIRS =
|
||||
|
||||
# .h files dir
|
||||
ADD_INCLUDE += $(TOPDIR)/plc/halphy/inc $(TOPDIR)/inc/compiler/gcc $(TOPDIR)/inc $(TOPDIR)/inc/io_lib $(TOPDIR)/inc/driver $(TOPDIR)/inc/uart $(TOPDIR)/inc/plc_lib $(TOPDIR)/inc/ipc $(TOPDIR)/inc/os_shim $(TOPDIR)/inc/pkt $(TOPDIR)/inc/utils $(TOPDIR)/plc/inc $(TOPDIR)/inc/cli $(TOPDIR)/cli/communicator $(TOPDIR)/inc/dbglog $(TOPDIR)/inc/ftm $(TOPDIR)/plc/halmac/inc $(TOPDIR)/plc/halmac/hw/inc/desc $(TOPDIR)/driver/inc $(TOPDIR)/export/inc/gpio
|
||||
|
||||
# predefined macro
|
||||
PRE_MARCO +=
|
||||
|
||||
ifeq ($(gcc), arm)
|
||||
ADD_INCLUDE += $(TOPDIR)/os/freertos/src/portable/ARM_CM3
|
||||
else
|
||||
ADD_INCLUDE += $(TOPDIR)/os/freertos/src/portable/RISCV
|
||||
endif
|
||||
|
||||
ifeq ($(gcc),arm)
|
||||
ADD_LIB = cm3
|
||||
ADD_LIBDIR = $(TOPDIR)/startup/cm3
|
||||
else
|
||||
ifeq ($(target), kunlun2)
|
||||
LD_SCRIPT = link.lds
|
||||
ADD_LIB = riscv
|
||||
ADD_LIBDIR =$(TOPDIR)/startup/riscv2
|
||||
ADD_INCLUDE += $(TOPDIR)/driver/src/hw2/inc
|
||||
else
|
||||
ADD_LIB = riscv
|
||||
ADD_LIBDIR =$(TOPDIR)/startup/riscv
|
||||
ADD_INCLUDE += $(TOPDIR)/driver/src/hw/inc
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
|
||||
# lib dir
|
||||
ADD_LIBDIR += $(TOPDIR)/plc $(TOPDIR)/driver $(TOPDIR)/common $(TOPDIR)/os
|
||||
# lib need to ld together
|
||||
ADD_LIB += plc os driver common
|
||||
|
||||
#####################################################
|
||||
|
||||
ifdef TOPDIR
|
||||
include $(TOPDIR)/build/makefile.cfg
|
||||
else
|
||||
include $(CURDIR)/build/makefile.cfg
|
||||
TOPDIR = $(CURDIR)
|
||||
export TOPDIR
|
||||
endif
|
||||
|
||||
dump:
|
||||
$(OBJDUMP) -D -S -l $(OUTPUT_FULL_NAME) > $(OUTPUT_FULL_NAME).dump
|
||||
|
||||
# display the obj files and output name
|
||||
debug:
|
||||
@echo TOPDIR=$(TOPDIR)
|
||||
@echo OUTPUT_LIB=$(OUTPUT_FULL_NAME)
|
||||
@echo DEPS=$(DEPS)
|
||||
@echo OBJECTS=$(OBJECTS)
|
||||
@echo SRCS=$(SRCS)
|
||||
@echo OBJECTS folder=$(foreach dirname, $(SUB_DIRS), $(addprefix $(BIN_DIR)/, $(dirname)))
|
||||
@echo output_name=$(OUTPUT_FULL_NAME)
|
431
dtest/emac_test_kl2/emac_test.c
Normal file
431
dtest/emac_test_kl2/emac_test.c
Normal file
@@ -0,0 +1,431 @@
|
||||
/****************************************************************************
|
||||
|
||||
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;
|
||||
os_task_h test_send_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!");
|
||||
}
|
||||
}
|
||||
|
||||
int eth_gpio_rst(uint8_t gpio)
|
||||
{
|
||||
uint8_t r = 1;
|
||||
iot_printf("reset gpio start\n");
|
||||
r = iot_gpio_open_as_output(gpio);
|
||||
|
||||
if(r != 0)
|
||||
{
|
||||
iot_printf("\ngpio_set_direction failed!\n");
|
||||
}
|
||||
|
||||
if (0 != iot_gpio_value_set(gpio, 1)) {
|
||||
iot_printf("\n WRITE 0 FAILED\n");
|
||||
r = 1;
|
||||
} else {
|
||||
os_delay(100);
|
||||
if (0 != iot_gpio_value_set(gpio, 0)) {
|
||||
iot_printf("\n WRITE 1 FAILED\n");
|
||||
r = 1;
|
||||
} else {
|
||||
r = 0;
|
||||
}
|
||||
os_delay(100);
|
||||
if (0 != iot_gpio_value_set(gpio, 1)) {
|
||||
iot_printf("\n WRITE 1 FAILED\n");
|
||||
r = 1;
|
||||
} else {
|
||||
r = 0;
|
||||
}
|
||||
}
|
||||
iot_printf("reset gpio\n");
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
void test_send_packet()
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
mdelay(20);
|
||||
eth_test_send_ping();
|
||||
}
|
||||
}
|
||||
|
||||
void send_pack_task(void *arg)
|
||||
{
|
||||
iot_printf("task 2 entry....\n");
|
||||
|
||||
for(;;) {
|
||||
test_send_packet();
|
||||
os_delete_task(test_send_handle);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
eth_gpio_rst(45);
|
||||
|
||||
dwc_eth_init();
|
||||
|
||||
g_emac_ctrl = dwc_eth_open(EMAC_TEST_UNIT, eth_test_rcv);
|
||||
dwc_eth_restart(g_emac_ctrl);
|
||||
dwc_eth_start(g_emac_ctrl);
|
||||
#if 1
|
||||
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();
|
||||
|
||||
dwc_gpio_bind(EMAC_TEST_UNIT);
|
||||
// eth_test_send_ping();
|
||||
|
||||
#if 1
|
||||
/* start plc lib task */
|
||||
test_send_handle = os_create_task(send_pack_task, NULL, 9);
|
||||
|
||||
//create the tasks;
|
||||
if(test_send_handle != NULL) {
|
||||
iot_printf("task 2 init successfully...\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user