X-Git-Url: http://rtime.felk.cvut.cz/gitweb/can-benchmark.git/blobdiff_plain/8eef03acb9747a40aaf92175c49e43397b872404..ddc40c70cfce8c93b228bc28a3144da45acd6708:/rtems/gw/cangw/helpers.c diff --git a/rtems/gw/cangw/helpers.c b/rtems/gw/cangw/helpers.c index d994a55..f128951 100644 --- a/rtems/gw/cangw/helpers.c +++ b/rtems/gw/cangw/helpers.c @@ -1,120 +1,120 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "helpers.h" -#include "gw.h" -#include "load.h" - -#include -#include "networkconfig.h" - - -static rtems_device_major_number mscan_major; -static rtems_driver_address_table mscan_driver_table=MSCAN_DRIVER_TABLE_ENTRY; - -/* -* Prints can stats. (Used in debugging) -*/ -int print_can_totals(int argc, char** argv){ - printf("Total 1: %"PRIu32", Total 2: %"PRIu32"\n", total_1, total_2); - printf("Success 1: %"PRIu32", Success 2: %"PRIu32"\n", succ_1, succ_2); - printf("Errors 1: %"PRIu32", Errors 2: %"PRIu32"\n", err_1, err_2); - return 0; -} - -/* -* Prints clocks as given by the uboot. (Used in debugging) -*/ -int print_clocks(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); - 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(); -} - -int show_net(int argc, char** argv){ - rtems_bsdnet_show_if_stats(); - rtems_bsdnet_show_ip_stats(); - rtems_bsdnet_show_icmp_stats(); - rtems_bsdnet_show_mbuf_stats(); - rtems_bsdnet_show_inet_routes(); - return 0; -} - -int start_net(int argc, char** argv){ - int res; - printf("Initializing Network\n"); - res = rtems_bsdnet_initialize_network (); - if (res < 0){ - printf("Error while initializing network: %d %s\n", errno, strerror(errno)); - return 1; - } - printf("Success\n"); - printf("Found routes.\n"); - rtems_bsdnet_show_inet_routes (); - return 0; -} - -int start_load(int argc, char** argv){ - return start_thread_load(); -} - -int stop_load(int argc, char** argv){ - return end_thread_load(); -} +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "helpers.h" +#include "gw.h" +#include "load.h" + +#include +#include "networkconfig.h" + + +static rtems_device_major_number mscan_major; +static rtems_driver_address_table mscan_driver_table=MSCAN_DRIVER_TABLE_ENTRY; + +/* +* Prints can stats. (Used in debugging) +*/ +int print_can_totals(int argc, char** argv){ + printf("Total 1: %"PRIu32", Total 2: %"PRIu32"\n", total_1, total_2); + printf("Success 1: %"PRIu32", Success 2: %"PRIu32"\n", succ_1, succ_2); + printf("Errors 1: %"PRIu32", Errors 2: %"PRIu32"\n", err_1, err_2); + return 0; +} + +/* +* Prints clocks as given by the uboot. (Used in debugging) +*/ +int print_clocks(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); + 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(); +} + +int show_net(int argc, char** argv){ + rtems_bsdnet_show_if_stats(); + rtems_bsdnet_show_ip_stats(); + rtems_bsdnet_show_icmp_stats(); + rtems_bsdnet_show_mbuf_stats(); + rtems_bsdnet_show_inet_routes(); + return 0; +} + +int start_net(int argc, char** argv){ + int res; + printf("Initializing Network\n"); + res = rtems_bsdnet_initialize_network (); + if (res < 0){ + printf("Error while initializing network: %d %s\n", errno, strerror(errno)); + return 1; + } + printf("Success\n"); + printf("Found routes.\n"); + rtems_bsdnet_show_inet_routes (); + return 0; +} + +int start_load(int argc, char** argv){ + return start_thread_load(); +} + +int stop_load(int argc, char** argv){ + return end_thread_load(); +}