From: Martin Hořeňovský Date: Wed, 21 Aug 2013 14:32:42 +0000 (+0200) Subject: Commit adding basic ethernet capability to the GW application - responding to pings. X-Git-Tag: fix-allnoconfig~156 X-Git-Url: http://rtime.felk.cvut.cz/gitweb/can-benchmark.git/commitdiff_plain/b29b333865c98b5e48073731980fa6c3cc58f1eb?hp=b3c271b232e8f73e50efb422b844167550267024 Commit adding basic ethernet capability to the GW application - responding to pings. Ethernet driver needs to be activated first with "startNET", this will probably be changed in the future to autoactiva tion (pending discussion about whether the (extremely minor) overhead matters in the benchmarking of CAN GW.) --- diff --git a/rtems/gw/cangw/Makefile.omk b/rtems/gw/cangw/Makefile.omk index 6316958..abea9eb 100644 --- a/rtems/gw/cangw/Makefile.omk +++ b/rtems/gw/cangw/Makefile.omk @@ -6,5 +6,10 @@ bin_PROGRAMS = cangw #lib_LIBRARIES = #include_HEADERS = + +#I am not entirely sure these two are needed, but according to documentation, they are. +CFLAGS_LD += HeapSize=0x80000 +MANAGERS = io event semaphore cangw_SOURCES += init.c gw.c helpers.c + diff --git a/rtems/gw/cangw/app_def.h b/rtems/gw/cangw/app_def.h index c2f13eb..79a8a28 100644 --- a/rtems/gw/cangw/app_def.h +++ b/rtems/gw/cangw/app_def.h @@ -13,14 +13,6 @@ extern "C" { #endif -COND_EXTERN rtems_id CAN_A_to_B_id; /* task listening on A, sends through B */ -COND_EXTERN rtems_id CAN_B_to_A_id; /* task listening on B, sends through A */ -COND_EXTERN rtems_name CAN_A_to_B_name; /* First task's name */ -COND_EXTERN rtems_name CAN_B_to_A_name; /* Seconds task's name */ - -rtems_task CAN_GW_1(rtems_task_argument arg); -rtems_task CAN_GW_2(rtems_task_argument arg); - void bad_rtems_status(rtems_status_code status, int fail_level, const char *text); static inline @@ -30,7 +22,6 @@ void check_rtems_status(rtems_status_code status, int fail_level, const char *te bad_rtems_status(status, fail_level, text); } -#define CANGW_PRIORITY 30 #define SHELL_TASK_PRIORITY 50 #ifdef __cplusplus diff --git a/rtems/gw/cangw/helpers.c b/rtems/gw/cangw/helpers.c index 0f94242..117c469 100644 --- a/rtems/gw/cangw/helpers.c +++ b/rtems/gw/cangw/helpers.c @@ -17,6 +17,9 @@ #include "helpers.h" #include "gw.h" +#include +#include "networkconfig.h" + extern unsigned long int total_1, total_2, succ_1, succ_2, err_1, err_2; @@ -87,4 +90,29 @@ int start_can(int argc, char** argv){ int end_can(int argc, char** argv){ return end_GW(); +} + +int show_net(int argc, char** argv){ + rtems_bsdnet_show_if_stats(); + rtems_bsdnet_show_ip_stats(); + rtems_bsdnet_show_icmp_stats(); + rtems_bsdnet_show_tcp_stats(); + rtems_bsdnet_show_udp_stats(); + rtems_bsdnet_show_mbuf_stats(); + rtems_bsdnet_show_inet_routes(); + return 0; +} + +int start_net(int argc, char** argv){ + int res; + printf("Initializing Network\n"); + res = rtems_bsdnet_initialize_network (); + if (res < 0){ + printf("Error while initializing network: %d %s\n", errno, strerror(errno)); + return 1; + } + printf("Success\n"); + printf("About to show routes.\n"); + rtems_bsdnet_show_inet_routes (); + return 0; } \ No newline at end of file diff --git a/rtems/gw/cangw/helpers.h b/rtems/gw/cangw/helpers.h index 0c3a0d0..efda330 100644 --- a/rtems/gw/cangw/helpers.h +++ b/rtems/gw/cangw/helpers.h @@ -1,20 +1,11 @@ -#include -#include "system.h" -#include "app_def.h" -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - +#ifndef __HELPERS_H_ +#define __HELPERS_H_ int start_can(int argc, char** argv); int end_can(int argc, char** argv); int print_regs(int argc, char** argv); -int print_can_totals(int argc, char** argv); \ No newline at end of file +int print_can_totals(int argc, char** argv); +int start_net(int argc, char** argv); +int show_net(int argc, char** argv); + +#endif \ No newline at end of file diff --git a/rtems/gw/cangw/init.c b/rtems/gw/cangw/init.c index c7209d1..63e00ea 100644 --- a/rtems/gw/cangw/init.c +++ b/rtems/gw/cangw/init.c @@ -58,50 +58,51 @@ void bad_rtems_status(rtems_status_code status, int fail_level, const char *text } - - -rtems_task Init( - rtems_task_argument ignored -) -{ - rtems_status_code status; - - printf( "\n\nRTEMS v " - BUILD_VERSION_STRING(__RTEMS_MAJOR__ ,__RTEMS_MINOR__ ,__RTEMS_REVISION__) - "\n"); - - rtems_monitor_init(RTEMS_MONITOR_SUSPEND|RTEMS_MONITOR_GLOBAL); - /*rtems_capture_cli_init (0);*/ - - printf( "Starting application " SW_VER_ID " v " - BUILD_VERSION_STRING(SW_VER_MAJOR,SW_VER_MINOR,SW_VER_PATCH) - "\n" ); - - - rtems_shell_init("SHLL",RTEMS_MINIMUM_STACK_SIZE+0x1000, - SHELL_TASK_PRIORITY,"/dev/console",1,0, NULL); - rtems_shell_add_cmd("startGW", "app", - "initialize can driver and startGW", - start_can); - - rtems_shell_add_cmd("stopGW", "app", - "stops GW", - end_can); - - rtems_shell_add_cmd("printvar", "app", - "prints info from vars", - print_regs); - - rtems_shell_add_cmd("printcan", "app", - "prints error rate from CANs", - print_can_totals); - - - //rtems_monitor_wakeup(); - - status = rtems_task_delete( RTEMS_SELF ); - - exit( 0 ); +rtems_task Init(rtems_task_argument ignored){ + rtems_status_code status; + + printf( "\n\nRTEMS v " + BUILD_VERSION_STRING(__RTEMS_MAJOR__ ,__RTEMS_MINOR__ ,__RTEMS_REVISION__) + "\n"); + + rtems_monitor_init(RTEMS_MONITOR_SUSPEND|RTEMS_MONITOR_GLOBAL); + /*rtems_capture_cli_init (0);*/ + + printf( "Starting application " SW_VER_ID " v " + BUILD_VERSION_STRING(SW_VER_MAJOR,SW_VER_MINOR,SW_VER_PATCH) + "\n" ); + + + rtems_shell_init("SHLL", RTEMS_MINIMUM_STACK_SIZE+0x1000, + SHELL_TASK_PRIORITY, "/dev/console", 1, 0, NULL); + + rtems_shell_add_cmd("startGW", "app", + "initialize can driver and startGW", + start_can); + + rtems_shell_add_cmd("stopGW", "app", + "stops GW", + end_can); + + rtems_shell_add_cmd("printvar", "app", + "prints info from vars", + print_regs); + + rtems_shell_add_cmd("printcan", "app", + "prints error rate from CANs", + print_can_totals); + + rtems_shell_add_cmd("startNET", "app", + "tries to start network adapter", + start_net); + + rtems_shell_add_cmd("showNET", "app", + "prints some diagnostic info from network adapter/driver", + show_net); + + status = rtems_task_delete( RTEMS_SELF ); + + exit( 0 ); } diff --git a/rtems/gw/cangw/system.h b/rtems/gw/cangw/system.h index 7279551..0673310 100644 --- a/rtems/gw/cangw/system.h +++ b/rtems/gw/cangw/system.h @@ -23,7 +23,7 @@ rtems_task Init( /* configuration information */ -#include /* for device driver prototypes */ +#include /* for device driver prototypes */ #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER @@ -39,6 +39,7 @@ rtems_task Init( #define CONFIGURE_MAXIMUM_USER_EXTENSIONS 2 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32 #define CONFIGURE_MAXIMUM_DRIVERS (CONFIGURE_NUMBER_OF_DRIVERS+10) + #ifdef RTEMS_POSIX_API #define CONFIGURE_MAXIMUM_POSIX_THREADS 32 diff --git a/rtems/gw/system_opt/Makefile.omk b/rtems/gw/system_opt/Makefile.omk index ab511ae..532eb88 100644 --- a/rtems/gw/system_opt/Makefile.omk +++ b/rtems/gw/system_opt/Makefile.omk @@ -1,3 +1,3 @@ #SUBDIRS = -include_HEADERS = system_def.h +include_HEADERS = system_def.h networkconfig.h diff --git a/rtems/gw/system_opt/networkconfig.h b/rtems/gw/system_opt/networkconfig.h new file mode 100644 index 0000000..a162114 --- /dev/null +++ b/rtems/gw/system_opt/networkconfig.h @@ -0,0 +1,57 @@ +#ifndef __NETWORKCONFIG_H__ +#define __NETWORKCONFIG_H__ + +#include +#include + +/* This was taken from existing example, driver failed to provide its own, so why not. */ +static char ethernet_address[6] = {0x00, 0x04, 0x9F, 0x00, 0x27, 0x50 }; + +extern void rtems_bsdnet_loopattach(); + +/* config for loopback device */ +static struct rtems_bsdnet_ifconfig loopback_config = { + "lo0", + rtems_bsdnet_loopattach, + NULL, + "127.0.0.1", + "255.0.0.0" + /* Rest of the struct is set to 0 (is defaulted) */ +}; + +/* config for ethernet */ +static struct rtems_bsdnet_ifconfig netdriver_config = { + RTEMS_BSP_NETWORK_DRIVER_NAME, + RTEMS_BSP_NETWORK_DRIVER_ATTACH, + &loopback_config, /* link to next interface */ + "192.168.2.3", /* IP address */ + "255.255.255.0", /* IP address net mask */ + ethernet_address /* ethernet hardware address, 0 - supplied by driver according to documentation, but it caused error when tested */ + + /* rest of the struct is set to 0 (is defaulted) */ +}; + +/* Main config. */ +struct rtems_bsdnet_config rtems_bsdnet_config = { + &netdriver_config, /* This entry points to the head of the ifconfig chain. */ + NULL, /* rtems_bsdnet_do_bootp if it should use bootp, null otherwise */ + /* From here on, zero means default value. */ + 100, /* network task priority (default 100) */ + 65792, /* mbuf bytecount (default 64kbytes) */ + /* Using default sizes stops RTEMS from answering to pings. (Probably because it allocates too few buffer for an answer.). */ + 263168, //180584, /* mbuf cluster bytecount (default 128kbytes) */ + "midam_deska", /* hostname (default BOOTP) */ + "testdomain", /* domain name (default BOOTP) */ + "192.168.2.2", /* gateway (default BOOTP) */ + "192.168.2.2", /* log_host (default BOOTP) */ + { "192.168.2.2", }, /* name_server[3] (default BOOTP) */ + { "192.168.2.2", }, /* ntp_server[3] (default BOOTP) */ + 0, /* sb efficiency (default 2) */ + 0, /* udp tx buf size (default 9216 bytes) */ + 0, /* udp rx buf size (default 40 * (1024 + sizeof(struct sockaddr_in) bytes) */ + 0, /* tcp tx buf size (default 16 * 1024 bytes) */ + 0 /* tcp rx buf size (default 16 * 1024 bytes) */ +}; + +#endif + diff --git a/rtems/gw/system_opt/system_def.h b/rtems/gw/system_opt/system_def.h index 0ae03aa..49c60ed 100644 --- a/rtems/gw/system_opt/system_def.h +++ b/rtems/gw/system_opt/system_def.h @@ -7,19 +7,19 @@ /* Software version */ #define SW_VER_ID "CANGW" #define SW_VER_MAJOR 0 -#define SW_VER_MINOR 1 +#define SW_VER_MINOR 3 #define SW_VER_PATCH 0 #define SW_VER_CODE VER_CODE(SW_VER_MAJOR,SW_VER_MINOR,SW_VER_PATCH) /* Hardware version */ #define HW_VER_ID "RYU" -#define HW_VER_MAJOR 1 +#define HW_VER_MAJOR 0 #define HW_VER_MINOR 0 -#define HW_VER_PATCH 2 +#define HW_VER_PATCH 0 #define HW_VER_CODE VER_CODE(HW_VER_MAJOR,HW_VER_MINOR,HW_VER_PATCH) /* Version of mechanical */ #define MECH_VER_ID "???" #define MECH_VER_MAJOR 0 -#define MECH_VER_MINOR 1 +#define MECH_VER_MINOR 0 #define MECH_VER_PATCH 0 #define MECH_VER_CODE VER_CODE(MECH_VER_MAJOR,MECH_VER_MINOR,MECH_VER_PATCH)