]> rtime.felk.cvut.cz Git - can-benchmark.git/blob - rtems/gw/cangw/helpers.c
Adds conditional compilation for benchmarking and shell initialization cleanup.
[can-benchmark.git] / rtems / gw / cangw / helpers.c
1 #include <system_def.h>\r
2 #include <unistd.h>\r
3 #include <fcntl.h>\r
4 #include <stdio.h>\r
5 #include <errno.h>\r
6 #include <stdlib.h>\r
7 #include <rtems/error.h>\r
8 #include <rtems/monitor.h>\r
9 #include <rtems/shell.h>\r
10 \r
11 #include <bsp/mscan.h>\r
12 #include <bsp/mscan-base.h>\r
13 \r
14 #include "helpers.h"\r
15 #include "gw.h"\r
16 #include "load.h"\r
17 \r
18 #include <rtems/rtems_bsdnet.h>\r
19 #include "networkconfig.h" \r
20 \r
21 \r
22 static rtems_device_major_number mscan_major;\r
23 static rtems_driver_address_table mscan_driver_table=MSCAN_DRIVER_TABLE_ENTRY;\r
24 \r
25 /*\r
26 * Prints can stats. (Used in debugging)\r
27 */\r
28 int print_can_totals(int argc, char** argv){\r
29     printf("Total 1: %"PRIu32", Total 2: %"PRIu32"\n", total_1, total_2);\r
30     printf("Success 1: %"PRIu32", Success 2: %"PRIu32"\n", succ_1, succ_2);\r
31     printf("Errors 1: %"PRIu32", Errors 2: %"PRIu32"\n", err_1, err_2);\r
32     return 0;\r
33 }\r
34 \r
35 /*\r
36 * Prints clocks as given by the uboot. (Used in debugging)\r
37 */\r
38 int print_clocks(int argc, char** argv){\r
39     printf("IPB_CLOCK: %lu\n", bsp_uboot_board_info.bi_ipbfreq);\r
40     printf("XLB_CLOCK: %lu\n", bsp_uboot_board_info.bi_busfreq);\r
41     printf("G2_CLOCK: %lu\n", bsp_uboot_board_info.bi_intfreq);\r
42     printf("BAUD: %lu\n", bsp_uboot_board_info.bi_baudrate);\r
43     return 0;\r
44 }\r
45 \r
46 /*\r
47 * Single function to prepare CAN devices for read/write operation.\r
48 *\r
49 * Sets up baud rate at 1M, opens fda and fdb and checks for errors.\r
50 */\r
51 static int init_CAN(){\r
52     rtems_status_code status;\r
53     \r
54     printf("Initializing CAN bus.\n");\r
55     \r
56     printf("Changing gpiopcr setting...\n");    \r
57     //Clear PCR_CHIP_SELECT bits and sets them to ALT_CAN.\r
58     mpc5200.gpiopcr = (mpc5200.gpiopcr & (~GPIO_PCR_CHIP_SELECT_1)) | GPIO_PCR_CHIP_ALTS_CAN;\r
59 \r
60     printf("Registering CAN drivers...\n");\r
61     status = rtems_io_register_driver(0, &mscan_driver_table, &mscan_major);\r
62     if (status != RTEMS_SUCCESSFUL){\r
63         printf("caninit: rtems_io_register_driver %s\n",rtems_status_text(status));\r
64         return 1;\r
65     }\r
66     \r
67     return 0;\r
68 }\r
69 \r
70 int start_can(int argc, char** argv){\r
71     int res;\r
72     static char inited = 0;\r
73     if (!inited){\r
74         res = init_CAN();\r
75         inited = 1;\r
76         if (res != 0){\r
77             //TODO\r
78             printf("Error while initializing CAN\n");\r
79             return res;\r
80         }\r
81         printf("CAN inited\n");\r
82     }\r
83     res = start_GW();\r
84     return 0;\r
85 }\r
86 \r
87 int end_can(int argc, char** argv){\r
88     return end_GW();\r
89 }\r
90 \r
91 int show_net(int argc, char** argv){\r
92     rtems_bsdnet_show_if_stats();\r
93     rtems_bsdnet_show_ip_stats();\r
94     rtems_bsdnet_show_icmp_stats();\r
95     rtems_bsdnet_show_mbuf_stats();\r
96     rtems_bsdnet_show_inet_routes();\r
97     return 0;\r
98 }\r
99 \r
100 int start_net(int argc, char** argv){\r
101     int res;\r
102     printf("Initializing Network\n");\r
103     res = rtems_bsdnet_initialize_network ();\r
104     if (res < 0){\r
105         printf("Error while initializing network: %d    %s\n", errno, strerror(errno));\r
106         return 1;\r
107     }\r
108     printf("Success\n");\r
109     printf("Found routes.\n");\r
110     rtems_bsdnet_show_inet_routes (); \r
111     return 0;\r
112 }\r
113 \r
114 int start_load(int argc, char** argv){\r
115     return start_thread_load();\r
116 }\r
117 \r
118 int stop_load(int argc, char** argv){\r
119     return end_thread_load();\r
120 }\r