]> rtime.felk.cvut.cz Git - can-benchmark.git/blobdiff - rtems/gw/cangw/helpers.c
Initial commit of simple (just forwarding from CAN0 to CAN1 and back) CAN gateway...
[can-benchmark.git] / rtems / gw / cangw / helpers.c
diff --git a/rtems/gw/cangw/helpers.c b/rtems/gw/cangw/helpers.c
new file mode 100644 (file)
index 0000000..0f94242
--- /dev/null
@@ -0,0 +1,90 @@
+#include <system_def.h>\r
+#include "system.h"\r
+#include "app_def.h"\r
+#include <unistd.h>\r
+#include <fcntl.h>\r
+#include <stdio.h>\r
+#include <errno.h>\r
+#include <stdlib.h>\r
+#include <rtems/error.h>\r
+#include <rtems/monitor.h>\r
+#include <rtems/shell.h>\r
+\r
+#include <bsp/mscan.h>\r
+#include <bsp/mscan-base.h>\r
+\r
+\r
+#include "helpers.h"\r
+#include "gw.h"\r
+\r
+\r
+extern unsigned long int total_1, total_2, succ_1, succ_2, err_1, err_2;\r
+\r
+static rtems_device_major_number mscan_major;\r
+static rtems_driver_address_table mscan_driver_table=MSCAN_DRIVER_TABLE_ENTRY;\r
+\r
+\r
+int print_can_totals(int argc, char** argv){\r
+    printf("Total 1: %lu, Total 2: %lu\n", total_1, total_2);\r
+    printf("Success 1: %lu, Success 2: %lu\n", succ_1, succ_2);\r
+    printf("Errors 1: %lu, Errors 2: %lu\n", err_1, err_2);\r
+    return 0;\r
+}\r
+\r
+int print_regs(int argc, char** argv){\r
+    printf("IPB_CLOCK: %lu\n", bsp_uboot_board_info.bi_ipbfreq);\r
+    printf("XLB_CLOCK: %lu\n", bsp_uboot_board_info.bi_busfreq);\r
+    printf("G2_CLOCK: %lu\n", bsp_uboot_board_info.bi_intfreq);\r
+    printf("BAUD: %lu\n", bsp_uboot_board_info.bi_baudrate);\r
+    printf("BIT 27 set to 1: 0x%08lx\n", MPC5200_BIT32(27));\r
+    printf("GPIO_PCR_CHIP_ALTS_CAN: 0x%08x\n", GPIO_PCR_CHIP_ALTS_CAN);    \r
+    printf("GPIO_PCR_CHIP_SELECT_1: 0x%08x\n", GPIO_PCR_CHIP_SELECT_1);\r
+    return 0;\r
+}\r
+\r
+\r
+\r
+/*\r
+* Single function to prepare CAN devices for read/write operation.\r
+*\r
+* Sets up baud rate at 1M, opens fda and fdb and checks for errors.\r
+*/\r
+static int init_CAN(){\r
+    rtems_status_code status;\r
+    \r
+    printf("Initializing CAN bus.\n");\r
+    \r
+    printf("Changing gpiopcr setting...\n");    \r
+    //Clear PCR_CHIP_SELECT bits and sets them to ALT_CAN.\r
+    mpc5200.gpiopcr = (mpc5200.gpiopcr & (~GPIO_PCR_CHIP_SELECT_1)) | GPIO_PCR_CHIP_ALTS_CAN;\r
+\r
+    printf("Registering CAN drivers...\n");\r
+    status = rtems_io_register_driver(0, &mscan_driver_table, &mscan_major);\r
+    if (status != RTEMS_SUCCESSFUL){\r
+        printf("caninit: rtems_io_register_driver %s\n",rtems_status_text(status));\r
+        return 1;\r
+    }\r
+    \r
+    return 0;\r
+}\r
+\r
+int start_can(int argc, char** argv){\r
+    int res;\r
+    static char inited = 0;\r
+    if (!inited){\r
+        res = init_CAN();\r
+        inited = 1;\r
+        if (res != 0){\r
+            //TODO\r
+            printf("Error while initializing CAN\n");\r
+            return res;\r
+        }\r
+        printf("CAN inited\n");\r
+    }\r
+    res = start_GW();\r
+    return 0;\r
+}\r
+\r
+int end_can(int argc, char** argv){\r
+    return end_GW();\r
+}
\ No newline at end of file