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