191 lines
5.1 KiB
C
191 lines
5.1 KiB
C
#include "cmds.h"
|
|
#include "Drivers/EthDrv/phy_drv/phy_common.h"
|
|
#include "cliutils/cli.h"
|
|
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include "FreeRTOS.h"
|
|
#include "cmsis_os2.h"
|
|
|
|
#include "etherlib/global_state.h"
|
|
#include "etherlib/timer.h"
|
|
#include "etherlib/utils.h"
|
|
#include "portable.h"
|
|
#include "standard_output/standard_output.h"
|
|
|
|
#include <stm32h7xx.h>
|
|
|
|
|
|
CMD_FUNCTION(os_info) {
|
|
osVersion_t kVersion;
|
|
char kId[32];
|
|
kId[sizeof(kId) - 1] = 0;
|
|
osKernelGetInfo(&kVersion, kId, sizeof(kId) - 1);
|
|
MSG("OS: %s\n Kernel version: %d\n API version: %d\n", kId, kVersion.kernel, kVersion.api);
|
|
|
|
HeapStats_t stats;
|
|
vPortGetHeapStats(&stats);
|
|
MSG("Free OS memory: %u bytes\n", stats.xAvailableHeapSpaceInBytes);
|
|
|
|
return 0;
|
|
}
|
|
|
|
CMD_FUNCTION(phy_info) {
|
|
phy_print_full_name();
|
|
return 0;
|
|
}
|
|
|
|
CMD_FUNCTION(print_ip) {
|
|
MSGraw("IP: " ANSI_COLOR_BYELLOW);
|
|
PRINT_IPv4(E.ethIntf->ip);
|
|
MSGraw(ANSI_COLOR_RESET "\r\n");
|
|
return 0;
|
|
}
|
|
|
|
CMD_FUNCTION(eth_tmr) {
|
|
timer_report(E.tmr);
|
|
return 0;
|
|
}
|
|
|
|
CMD_FUNCTION(eth_conns) {
|
|
packsieve_report_full(&E.ethIntf->sieve);
|
|
return 0;
|
|
}
|
|
|
|
CMD_FUNCTION(eth_mem) {
|
|
mp_report(E.mp);
|
|
return 0;
|
|
}
|
|
|
|
CMD_FUNCTION(eth_arpc) {
|
|
arpc_dump(E.ethIntf->arpc);
|
|
return 0;
|
|
}
|
|
|
|
CMD_FUNCTION(eth_cbdt) {
|
|
cbdt_report(E.cbdt);
|
|
return 0;
|
|
}
|
|
|
|
CMD_FUNCTION(eth_dhcp_onoff) {
|
|
EthInterface *intf = get_default_interface();
|
|
|
|
if (argc > 0) {
|
|
if (ONOFF(ppArgs[0])) {
|
|
ethinf_set_automatic_dhcp_management(intf, true);
|
|
if ((intf->dhcp != NULL) && (ethinf_get_link_state(intf))) { // start DHCP if link is up
|
|
dhcp_start(intf->dhcp);
|
|
}
|
|
} else {
|
|
ethinf_set_automatic_dhcp_management(intf, false);
|
|
if (intf->dhcp != NULL) {
|
|
dhcp_stop(intf->dhcp);
|
|
}
|
|
}
|
|
}
|
|
|
|
ethinf_print_info(intf);
|
|
|
|
return 0;
|
|
}
|
|
|
|
CMD_FUNCTION(eth_addresses) {
|
|
EthInterface *intf = get_default_interface();
|
|
|
|
if (argc > 1) {
|
|
const char *kind = ppArgs[0];
|
|
const char *value = ppArgs[1];
|
|
ip4_addr *dest = NULL;
|
|
|
|
// select destination field
|
|
if (!strcmp(kind, "ip")) {
|
|
dest = &(intf->ip);
|
|
} else if (!strcmp(kind, "router")) {
|
|
dest = &(intf->router);
|
|
} else if (!strcmp(kind, "netmask")) {
|
|
dest = &(intf->netmask);
|
|
} else if (!strcmp(kind, "dns")) {
|
|
dest = &(intf->dns);
|
|
}
|
|
|
|
// fill-in the value
|
|
*dest = atoip(value);
|
|
}
|
|
|
|
// print info
|
|
ethinf_print_info(intf);
|
|
|
|
return 0;
|
|
}
|
|
|
|
CMD_FUNCTION(eth_alladdr) {
|
|
EthInterface *intf = get_default_interface();
|
|
|
|
// set all addresses at once
|
|
intf->ip = atoip(ppArgs[0]);
|
|
intf->router = atoip(ppArgs[1]);
|
|
intf->netmask = atoip(ppArgs[2]);
|
|
intf->dns = atoip(ppArgs[3]);
|
|
|
|
// print info
|
|
ethinf_print_info(intf);
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
#define HWA_SEMI ANSI_COLOR_RESET ":" ANSI_COLOR_BYELLOW
|
|
|
|
CMD_FUNCTION(print_hwa) {
|
|
MSGraw("Hardware address:\r\n" ANSI_COLOR_BYELLOW);
|
|
uint8_t * hwa = E.ethIntf->mac;
|
|
MSG("%02X" HWA_SEMI "%02X" HWA_SEMI "%02X" HWA_SEMI "%02X" HWA_SEMI "%02X" HWA_SEMI "%02X", hwa[0], hwa[1], hwa[2], hwa[3], hwa[4], hwa[5]);
|
|
MSGraw(ANSI_COLOR_RESET "\r\n\n");
|
|
return 0;
|
|
}
|
|
|
|
CMD_FUNCTION(read_all_phy_regs) {
|
|
phy_read_all_regs();
|
|
return 0;
|
|
}
|
|
|
|
CMD_FUNCTION(read_phy_reg) {
|
|
const char *strAddr = ppArgs[0];
|
|
uint32_t addr = strtol(strAddr, NULL, 0);
|
|
uint32_t value;
|
|
phy_read_reg(addr, &value);
|
|
MSG("%04X: %04X\n", addr, value);
|
|
return 0;
|
|
}
|
|
|
|
CMD_FUNCTION(write_phy_reg) {
|
|
const char *strAddr = ppArgs[0];
|
|
const char *strData = ppArgs[1];
|
|
uint32_t addr = strtol(strAddr, NULL, 0);
|
|
uint32_t data = strtol(strData, NULL, 0);
|
|
phy_write_reg(addr, data);
|
|
MSG("%04X: %04X\n", addr, data);
|
|
return 0;
|
|
}
|
|
|
|
void cmd_init() {
|
|
cli_register_command("osinfo \t\t\tPrint OS-related information", 1, 0, os_info);
|
|
cli_register_command("phyinfo \t\t\tPrint Ethernet PHY information", 1, 0, phy_info);
|
|
|
|
cli_register_command("ip \t\t\tPrint IP-address", 1, 0, print_ip);
|
|
cli_register_command("eth tmr \t\t\tPrint EtherLib timer report", 2, 0, eth_tmr);
|
|
cli_register_command("eth conns \t\t\tPrint active connections", 2, 0, eth_conns);
|
|
cli_register_command("eth mem \t\t\tPrint EtherLib memory pool state", 2, 0, eth_mem);
|
|
cli_register_command("eth arpc \t\t\tPrint EtherLib ARP cache", 2, 0, eth_arpc);
|
|
cli_register_command("eth cbdt \t\t\tPrint EtherLib CBD table", 2, 0, eth_cbdt);
|
|
cli_register_command("eth dhcp [<on|off>] \t\t\tTurn DHCP ON/OFF", 2, 0, eth_dhcp_onoff);
|
|
cli_register_command("eth addr [ip|router|netmask|dns] [a.b.c.d] \t\t\tSet or query network addresses", 2, 0, eth_addresses);
|
|
cli_register_command("eth alladdr <ip> <router> <netmask> <dns> \t\t\tSet all four network addresses", 2, 4, eth_alladdr);
|
|
|
|
|
|
cli_register_command("phy readall \t\t\tRead all PHY registers", 2, 0, read_all_phy_regs);
|
|
cli_register_command("phy read <address>\t\t\tRead a single PHY register", 2, 1, read_phy_reg);
|
|
cli_register_command("phy write <address> <data>\t\t\tWrite a single PHY register", 2, 2, write_phy_reg);
|
|
|
|
} |