]> rtime.felk.cvut.cz Git - can-benchmark.git/blob - rtems/gw/cangw/helpers.c
0f9424224a7a0e9c116970fcbe85915bfa62d817
[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 \r
21 extern unsigned long int total_1, total_2, succ_1, succ_2, err_1, err_2;\r
22 \r
23 static rtems_device_major_number mscan_major;\r
24 static rtems_driver_address_table mscan_driver_table=MSCAN_DRIVER_TABLE_ENTRY;\r
25 \r
26 \r
27 int print_can_totals(int argc, char** argv){\r
28     printf("Total 1: %lu, Total 2: %lu\n", total_1, total_2);\r
29     printf("Success 1: %lu, Success 2: %lu\n", succ_1, succ_2);\r
30     printf("Errors 1: %lu, Errors 2: %lu\n", err_1, err_2);\r
31     return 0;\r
32 }\r
33 \r
34 int print_regs(int argc, char** argv){\r
35     printf("IPB_CLOCK: %lu\n", bsp_uboot_board_info.bi_ipbfreq);\r
36     printf("XLB_CLOCK: %lu\n", bsp_uboot_board_info.bi_busfreq);\r
37     printf("G2_CLOCK: %lu\n", bsp_uboot_board_info.bi_intfreq);\r
38     printf("BAUD: %lu\n", bsp_uboot_board_info.bi_baudrate);\r
39     printf("BIT 27 set to 1: 0x%08lx\n", MPC5200_BIT32(27));\r
40     printf("GPIO_PCR_CHIP_ALTS_CAN: 0x%08x\n", GPIO_PCR_CHIP_ALTS_CAN);    \r
41     printf("GPIO_PCR_CHIP_SELECT_1: 0x%08x\n", GPIO_PCR_CHIP_SELECT_1);\r
42     return 0;\r
43 }\r
44 \r
45 \r
46 \r
47 /*\r
48 * Single function to prepare CAN devices for read/write operation.\r
49 *\r
50 * Sets up baud rate at 1M, opens fda and fdb and checks for errors.\r
51 */\r
52 static int init_CAN(){\r
53     rtems_status_code status;\r
54     \r
55     printf("Initializing CAN bus.\n");\r
56     \r
57     printf("Changing gpiopcr setting...\n");    \r
58     //Clear PCR_CHIP_SELECT bits and sets them to ALT_CAN.\r
59     mpc5200.gpiopcr = (mpc5200.gpiopcr & (~GPIO_PCR_CHIP_SELECT_1)) | GPIO_PCR_CHIP_ALTS_CAN;\r
60 \r
61     printf("Registering CAN drivers...\n");\r
62     status = rtems_io_register_driver(0, &mscan_driver_table, &mscan_major);\r
63     if (status != RTEMS_SUCCESSFUL){\r
64         printf("caninit: rtems_io_register_driver %s\n",rtems_status_text(status));\r
65         return 1;\r
66     }\r
67     \r
68     return 0;\r
69 }\r
70 \r
71 int start_can(int argc, char** argv){\r
72     int res;\r
73     static char inited = 0;\r
74     if (!inited){\r
75         res = init_CAN();\r
76         inited = 1;\r
77         if (res != 0){\r
78             //TODO\r
79             printf("Error while initializing CAN\n");\r
80             return res;\r
81         }\r
82         printf("CAN inited\n");\r
83     }\r
84     res = start_GW();\r
85     return 0;\r
86 }\r
87 \r
88 int end_can(int argc, char** argv){\r
89     return end_GW();\r
90 }