Adds conditional compilation for benchmarking and shell initialization cleanup.
authorMartin Hořeňovský <Martin.Horenovsky@gmail.com>
Mon, 16 Sep 2013 14:33:46 +0000 (16:33 +0200)
committerMartin Hořeňovský <Martin.Horenovsky@gmail.com>
Mon, 16 Sep 2013 14:33:46 +0000 (16:33 +0200)
Original code for shell initialization was a mess, now it uses RTEMS standard way
and adds user defined commands properly.

rtems/gw/cangw/helpers.c
rtems/gw/cangw/helpers.h
rtems/gw/cangw/init.c

index c5f9022..d994a55 100644 (file)
@@ -1,6 +1,4 @@
 #include <system_def.h>\r
-#include "system.h"\r
-#include "app_def.h"\r
 #include <unistd.h>\r
 #include <fcntl.h>\r
 #include <stdio.h>\r
 #include "networkconfig.h" \r
 \r
 \r
-\r
 static rtems_device_major_number mscan_major;\r
 static rtems_driver_address_table mscan_driver_table=MSCAN_DRIVER_TABLE_ENTRY;\r
 \r
-\r
+/*\r
+* Prints can stats. (Used in debugging)\r
+*/\r
 int print_can_totals(int argc, char** argv){\r
-    printf("Total 1: %lu, Total 2: %lu\n", total_1, total_2);\r
-    printf("Success 1: %lu, Success 2: %lu\n", succ_1, succ_2);\r
-    printf("Errors 1: %lu, Errors 2: %lu\n", err_1, err_2);\r
+    printf("Total 1: %"PRIu32", Total 2: %"PRIu32"\n", total_1, total_2);\r
+    printf("Success 1: %"PRIu32", Success 2: %"PRIu32"\n", succ_1, succ_2);\r
+    printf("Errors 1: %"PRIu32", Errors 2: %"PRIu32"\n", err_1, err_2);\r
     return 0;\r
 }\r
 \r
-int print_regs(int argc, char** argv){\r
+/*\r
+* Prints clocks as given by the uboot. (Used in debugging)\r
+*/\r
+int print_clocks(int argc, char** argv){\r
     printf("IPB_CLOCK: %lu\n", bsp_uboot_board_info.bi_ipbfreq);\r
     printf("XLB_CLOCK: %lu\n", bsp_uboot_board_info.bi_busfreq);\r
     printf("G2_CLOCK: %lu\n", bsp_uboot_board_info.bi_intfreq);\r
     printf("BAUD: %lu\n", bsp_uboot_board_info.bi_baudrate);\r
-    printf("BIT 27 set to 1: 0x%08lx\n", MPC5200_BIT32(27));\r
-    printf("GPIO_PCR_CHIP_ALTS_CAN: 0x%08x\n", GPIO_PCR_CHIP_ALTS_CAN);    \r
-    printf("GPIO_PCR_CHIP_SELECT_1: 0x%08x\n", GPIO_PCR_CHIP_SELECT_1);\r
     return 0;\r
 }\r
 \r
-\r
-\r
 /*\r
 * Single function to prepare CAN devices for read/write operation.\r
 *\r
index 2705078..95dcf39 100644 (file)
@@ -3,11 +3,78 @@
 \r
 int start_can(int argc, char** argv);\r
 int end_can(int argc, char** argv);\r
-int print_regs(int argc, char** argv);\r
+int print_clocks(int argc, char** argv);\r
 int print_can_totals(int argc, char** argv);\r
 int start_net(int argc, char** argv);\r
 int show_net(int argc, char** argv);\r
 int start_load(int argc, char** argv);\r
 int stop_load(int argc, char** argv);\r
 \r
+/* chain of shell command descriptors */\r
+static rtems_shell_cmd_t shell_command_stop_load = {\r
+    "stop_load", /* name */\r
+    "stops cpu loading threads", /* usage */\r
+    "user", /* topic */\r
+    stop_load, /* command */\r
+    NULL, /* alias */\r
+    NULL /* next */\r
+};\r
+static rtems_shell_cmd_t shell_command_start_load = {\r
+    "start_load", /* name */\r
+    "starts cpu loading threads", /* usage */\r
+    "user", /* topic */\r
+    start_load, /* command */\r
+    NULL, /* alias */\r
+    &shell_command_stop_load /* next */\r
+};\r
+static rtems_shell_cmd_t shell_command_start_net = {\r
+    "startNET", /* name */\r
+    "starts ethernet driver", /* usage */\r
+    "user", /* topic */\r
+    start_net, /* command */\r
+    NULL, /* alias */\r
+    &shell_command_start_load /* next */\r
+};\r
+static rtems_shell_cmd_t shell_command_stop_gw = {\r
+    "stopGW", /* name */\r
+    "stops CAN gateway", /* usage */\r
+    "user", /* topic */\r
+    end_can, /* command */\r
+    NULL, /* alias */\r
+    &shell_command_start_net /* next */\r
+};\r
+static rtems_shell_cmd_t shell_command_start_gw = {\r
+    "startGW", /* name */\r
+    "starts CAN gateway", /* usage */\r
+    "user", /* topic */\r
+    start_can, /* command */\r
+    NULL, /* alias */\r
+    &shell_command_stop_gw /* next */\r
+};\r
+static rtems_shell_cmd_t shell_command_print_net = {\r
+    "show_net", /* name */\r
+    "shows some debug information about bsdnet", /* usage */\r
+    "user", /* topic */\r
+    show_net, /* command */\r
+    NULL, /* alias */\r
+    &shell_command_start_gw /* next */\r
+};\r
+static rtems_shell_cmd_t shell_command_print_clocks = {\r
+    "print_clocks", /* name */\r
+    "prints clock as taken from uboot", /* usage */\r
+    "user", /* topic */\r
+    print_clocks, /* command */\r
+    NULL, /* alias */\r
+    &shell_command_print_net /* next */\r
+};\r
+static rtems_shell_cmd_t shell_command_print_can_totals = {\r
+    "printcan", /* name */\r
+    "prints can stats", /* usage */\r
+    "user", /* topic */\r
+    print_can_totals, /* command */\r
+    NULL, /* alias */\r
+    &shell_command_print_clocks /* next */\r
+};\r
+\r
+\r
 #endif
\ No newline at end of file
index 2398a87..c8057b2 100644 (file)
@@ -23,7 +23,7 @@
 #define CONFIGURE_INIT
 #include <system_def.h>
 #include "system.h"
-#include "app_def.h"
+#include "app_def.h"\r
 #include <unistd.h>
 #include <fcntl.h>
 #include <stdio.h>
         __XSTRING(major) "." __XSTRING(minor) "." __XSTRING(patch)
 
 #define RTEMS_VER_CODE VER_CODE(__RTEMS_MAJOR__ ,__RTEMS_MINOR__ ,__RTEMS_REVISION__)
-
-#if RTEMS_VER_CODE < VER_CODE(4,7,99)
-  #define rtems_shell_add_cmd shell_add_cmd
-  #define rtems_shell_init(m_task_name,m_task_stacksize,m_task_priority,m_devname,m_forever,m_wait,m_login_check) \
-                shell_init(m_task_name,m_task_stacksize,m_task_priority,m_devname,B19200 | CS8,m_forever)
-#elif RTEMS_VER_CODE < VER_CODE(4,9,99)
-  #define rtems_shell_init(m_task_name,m_task_stacksize,m_task_priority,m_devname,m_forever,m_wait,m_login_check) \
-          rtems_shell_init(m_task_name,m_task_stacksize,m_task_priority,m_devname,m_forever,m_wait)
-#endif
-
-void bad_rtems_status(rtems_status_code status, int fail_level, const char *text){
-  printf("ERROR: %s status %s", text, rtems_status_text(status));
-  status = rtems_task_delete( RTEMS_SELF );
-}
-
-
+\r
+\r
+#define CONFIGURE_SHELL_USER_COMMANDS &shell_command_print_can_totals\r
+#define CONFIGURE_SHELL_COMMANDS_INIT\r
+#define CONFIGURE_SHELL_COMMANDS_ALL\r
+\r
+#include <rtems/shellconfig.h>\r
+#include <rtems/shell.h>\r
 \r
 
 rtems_task Init(rtems_task_argument ignored){
@@ -68,48 +60,32 @@ rtems_task Init(rtems_task_argument ignored){
         "\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" );
+\r
+    /* Inits */\r
+#ifdef BENCH_BUILD\r
+    start_can(0, NULL);\r
+    start_net(0, NULL);\r
+#ifdef LOAD_BUILD\r
+    start_load(0, NULL);\r
+#endif\r
+#endif\r
+\r
+#ifndef BENCH_BUILD        \r
+    rtems_shell_init(\r
+        "SHLL", /* task name */\r
+        RTEMS_MINIMUM_STACK_SIZE * 4, /* task stack size */\r
+        100, /* task priority */\r
+        "/dev/console", /* device name */\r
+        true, /* run forever */\r
+        false, /* wait for shell to terminate */\r
+        NULL /* login check function, use NULL to disable a login check */\r
+    );  \r
+#endif    \r
     \r
-    
-    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);\r
-                    \r
-    rtems_shell_add_cmd("printcan", "app",\r
-                    "prints error rate from CANs",\r
-                    print_can_totals);
-    \r
-    rtems_shell_add_cmd("startNET", "app",\r
-                    "tries to start network adapter",\r
-                    start_net);\r
-    \r
-    rtems_shell_add_cmd("showNET", "app",\r
-                    "prints some diagnostic info from network adapter/driver",\r
-                    show_net);\r
-    \r
-    rtems_shell_add_cmd("start_load", "app",\r
-                    "starts loading threads",\r
-                    start_load);\r
-                    \r
-    rtems_shell_add_cmd("stop_load", "app",\r
-                    "stops loading threads",\r
-                    stop_load);\r
-    
     status = rtems_task_delete( RTEMS_SELF );
     
     exit( 0 );