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