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