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