#include <system_def.h>\r
-#include "system.h"\r
#include "app_def.h"\r
+#include "system.h"\r
#include <stdio.h>\r
#include <stdlib.h>\r
#include <rtems/untar.h>\r
#define CAN_GW_A_TO_B_MODE 1\r
#define CAN_GW_B_TO_A_MODE 2\r
#define CAN_GW_BAUDRATE 1000000\r
+#define CAN_GW_TASK_HIGH_PRIO 250 /* POSIX API actually has priorities the "right way around" that is, higher is indeed more important */\r
\r
/* counters for informational purposes */\r
unsigned long int total_1 = 0, total_2 = 0;\r
static void* CAN_GW_thread(void* arg){\r
int fd_in, fd_out;\r
int res;\r
- unsigned long int *total, *succ, *err;\r
+#ifndef BENCH_BUILD\r
+ unsigned long int *total = NULL, *succ = NULL, *err = NULL; /* Makes compiler shut up about warnings. */\r
+#endif\r
\r
struct can_message canmsg;\r
struct mscan_rx_parms rxparms;\r
if (((int)arg) == CAN_GW_A_TO_B_MODE){\r
fd_in = open(MSCAN_A_DEV_NAME, O_RDWR);\r
fd_out = open(MSCAN_B_DEV_NAME, O_RDWR);\r
- total = &total_1;\r
- succ = &succ_1;\r
- err = &err_1;\r
} else if (((int)arg) == CAN_GW_B_TO_A_MODE){\r
fd_in = open(MSCAN_B_DEV_NAME, O_RDWR);\r
fd_out = open(MSCAN_A_DEV_NAME, O_RDWR);\r
+ } else {\r
+ /* Invalid argument, terminate self. */\r
+ return NULL;\r
+ }\r
+\r
+#ifndef BENCH_BUILD /* Overhead decrease for benching builds.*/\r
+ if (((int)arg) == CAN_GW_A_TO_B_MODE){\r
+ total = &total_1;\r
+ succ = &succ_1;\r
+ err = &err_1;\r
+ } else {\r
total = &total_2;\r
succ = &succ_2;\r
err = &err_2;\r
- } else {\r
- /* Invalid argument, terminates itself. */\r
- rtems_task_delete(RTEMS_SELF);\r
}\r
+#endif\r
\r
/* CANs are set to proper baudrate outside of these task due to potential race condition. */\r
\r
txparms.tx_idx = canmsg.mess_id;\r
res = write(fd_out, &txparms, sizeof(txparms));\r
if (res < 0) {\r
+#ifndef BENCH_BUILD /* This is the simplest way to remove all the counting */\r
/* Retry? Decide later. */\r
(*err)++;\r
} else {\r
(*succ)++;\r
}\r
(*total)++;\r
+#else\r
+ } /* Turns it into empty loop. */\r
+#endif\r
+\r
}\r
}\r
return NULL;\r
\r
static int start_tasks(){\r
int res;\r
+\r
\r
- res = pthread_create(&CAN_A_to_B_thread, NULL, CAN_GW_thread, (void*)CAN_GW_A_TO_B_MODE);\r
+ pthread_attr_t attributes;\r
+ struct sched_param parm; \r
+ parm.sched_priority = CAN_GW_TASK_HIGH_PRIO;\r
+ pthread_attr_init(&attributes);\r
+#ifdef HIGH_PRIO /* Without setting PTHREAD_EXPLICIT_SCHED, thread is created with parameters inherited from this thread. */\r
+ res = pthread_attr_setinheritsched(&attributes, PTHREAD_EXPLICIT_SCHED);\r
+#endif\r
+ pthread_attr_setschedparam(&attributes, &parm);\r
+\r
+ res = pthread_create(&CAN_A_to_B_thread, &attributes, CAN_GW_thread, (void*)CAN_GW_A_TO_B_MODE);\r
if (res != 0){\r
/* No cleanup is needed here. */\r
return 1;\r
}\r
\r
- res = pthread_create(&CAN_B_to_A_thread, NULL, CAN_GW_thread, (void*)CAN_GW_B_TO_A_MODE);\r
+ res = pthread_create(&CAN_B_to_A_thread, &attributes, CAN_GW_thread, (void*)CAN_GW_B_TO_A_MODE);\r
if (res != 0){\r
/* First thread needs to be aborted before return. */\r
pthread_cancel(CAN_A_to_B_thread);\r
return 1;\r
}\r
\r
+ pthread_attr_destroy(&attributes);\r
+ \r
/* detach is needed so that the threads call clean up handlers automatically. */\r
pthread_detach(CAN_B_to_A_thread);\r
pthread_detach(CAN_A_to_B_thread);\r
memset(&ctrl_parms, 0, sizeof(ctrl_parms));\r
ctrl_parms.ctrl_can_bitrate = baudrate;\r
\r
- printf("Attempting to set bitrate %u for fd.\n", ctrl_parms.ctrl_can_bitrate);\r
+ printf("Attempting to set bitrate %"PRIu32" for fd.\n", ctrl_parms.ctrl_can_bitrate);\r
\r
fd = open(MSCAN_A_DEV_NAME, O_RDWR);\r
if (fd < 0){\r