Commit ce9576b4 authored by Joanne Hugé's avatar Joanne Hugé

Choose GPIO to emit signal on in server

parent 2ed3e6df
...@@ -42,7 +42,7 @@ typedef struct thread_param { ...@@ -42,7 +42,7 @@ typedef struct thread_param {
int affinity_cpu; int affinity_cpu;
uint64_t latency_threshold; uint64_t latency_threshold;
int emit_signal; int emit_signal_gpio;
int enable_diff_ts; int enable_diff_ts;
int enable_receive_tracemark; int enable_receive_tracemark;
...@@ -91,11 +91,8 @@ static uint64_t high_diff_ts = 0; ...@@ -91,11 +91,8 @@ static uint64_t high_diff_ts = 0;
static int debug_latencies = 0; static int debug_latencies = 0;
static int interval_us; static int interval_us;
static int gpio86_fd; static int gpio_fd;
static int gpio84_fd; static int gpio_state;
static int gpio86_state;
static int gpio84_state;
static int received_reverse_motor = 0;
static char ts_tracemark_buf[64]; static char ts_tracemark_buf[64];
...@@ -110,7 +107,7 @@ static void help(char *argv[]) { ...@@ -110,7 +107,7 @@ static void help(char *argv[]) {
" -i USEC RT thread wake-up interval (default: 10ms)\n" " -i USEC RT thread wake-up interval (default: 10ms)\n"
" -r USEC non-RT main thread refresh interval\n" " -r USEC non-RT main thread refresh interval\n"
" -d BUF_LEN Set the length of tx buffer\n" " -d BUF_LEN Set the length of tx buffer\n"
" -c Receive timestamp and emit signal\n" " -c GPIO Receive timestamp and emit signal on given GPIO\n"
" -s NS Common start time reference\n" " -s NS Common start time reference\n"
" -C Receive timestamp and print difference with current time\n" " -C Receive timestamp and print difference with current time\n"
" -b CLIENT_IP Server side RTT\n" " -b CLIENT_IP Server side RTT\n"
...@@ -135,7 +132,6 @@ static void *emit_signal_thread(void *p) { ...@@ -135,7 +132,6 @@ static void *emit_signal_thread(void *p) {
int64_t emit_diff, ts_diff; int64_t emit_diff, ts_diff;
int latency_spike = 0; int latency_spike = 0;
int ret; int ret;
int reverse_motor = 0;
// Set thread CPU affinity // Set thread CPU affinity
if (thread_params.affinity_cpu) { if (thread_params.affinity_cpu) {
...@@ -151,27 +147,13 @@ static void *emit_signal_thread(void *p) { ...@@ -151,27 +147,13 @@ static void *emit_signal_thread(void *p) {
for (int i = 0;;i++) { for (int i = 0;;i++) {
pthread_cond_wait(&emit_signal_ts_received, &emit_signal_mutex); pthread_cond_wait(&emit_signal_ts_received, &emit_signal_mutex);
if(received_reverse_motor) {
received_reverse_motor = 0;
reverse_motor = 1;
continue;
}
ret = clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &emit_signal_next, NULL); ret = clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &emit_signal_next, NULL);
if (ret) { if (ret) {
fprintf(stderr, "clock_nanosleep returned error: %d, aborting...\n", ret); fprintf(stderr, "clock_nanosleep returned error: %d, aborting...\n", ret);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if(reverse_motor) { gpio_state = toggle_gpio(gpio_fd, gpio_state);
gpio84_state = toggle_gpio(gpio84_fd, gpio84_state);
reverse_motor = 0;
}
else {
gpio86_state = toggle_gpio(gpio86_fd, gpio86_state);
usleep(3);
gpio86_state = toggle_gpio(gpio86_fd, gpio86_state);
}
clock_gettime(CLOCK_REALTIME, &current); clock_gettime(CLOCK_REALTIME, &current);
...@@ -273,7 +255,7 @@ static void *tsn_thread(void *p) { ...@@ -273,7 +255,7 @@ static void *tsn_thread(void *p) {
} }
// Get signal timestamp // Get signal timestamp
if (thread_params.emit_signal) { if (thread_params.emit_signal_gpio) {
uint64_t emit_signal_t; uint64_t emit_signal_t;
if(tsn_task == XDP_TASK) if(tsn_task == XDP_TASK)
...@@ -281,13 +263,10 @@ static void *tsn_thread(void *p) { ...@@ -281,13 +263,10 @@ static void *tsn_thread(void *p) {
else else
emit_signal_t = decode(ingress_stats.data); emit_signal_t = decode(ingress_stats.data);
if(emit_signal_t < UINT64_C(1576800000000000000) && emit_signal_t != 17) if(emit_signal_t < UINT64_C(1576800000000000000))
continue; continue;
pthread_mutex_lock(&emit_signal_mutex); pthread_mutex_lock(&emit_signal_mutex);
if(emit_signal_t == 17)
received_reverse_motor = 1;
else
emit_signal_next = uint_to_ts(emit_signal_t); emit_signal_next = uint_to_ts(emit_signal_t);
pthread_cond_signal(&emit_signal_ts_received); pthread_cond_signal(&emit_signal_ts_received);
pthread_mutex_unlock(&emit_signal_mutex); pthread_mutex_unlock(&emit_signal_mutex);
...@@ -424,7 +403,7 @@ int main(int argc, char *argv[]) { ...@@ -424,7 +403,7 @@ int main(int argc, char *argv[]) {
// Default configuration values // Default configuration values
thread_params.interval = 100000 * 1000; thread_params.interval = 100000 * 1000;
thread_params.priority = 98; thread_params.priority = 98;
thread_params.emit_signal = 0; thread_params.emit_signal_gpio = 0;
thread_params.affinity_cpu = 0; thread_params.affinity_cpu = 0;
thread_params.enable_diff_ts = 0; thread_params.enable_diff_ts = 0;
thread_params.enable_receive_tracemark = 0; thread_params.enable_receive_tracemark = 0;
...@@ -473,12 +452,11 @@ int main(int argc, char *argv[]) { ...@@ -473,12 +452,11 @@ int main(int argc, char *argv[]) {
if (tsn_task == RTT_TASK) if (tsn_task == RTT_TASK)
init_udp_send(&egress_info, 0, 0); init_udp_send(&egress_info, 0, 0);
if (thread_params.emit_signal) { if (thread_params.emit_signal_gpio) {
pthread_mutex_init(&emit_signal_mutex, NULL); pthread_mutex_init(&emit_signal_mutex, NULL);
pthread_cond_init(&emit_signal_ts_received, NULL); pthread_cond_init(&emit_signal_ts_received, NULL);
gpio86_state = enable_gpio(&gpio86_fd, 86); gpio_state = enable_gpio(&gpio_fd, thread_params.emit_signal_gpio);
gpio84_state = enable_gpio(&gpio84_fd, 84);
} }
create_thread(tsn_thread); create_thread(tsn_thread);
...@@ -610,7 +588,7 @@ static void process_options(int argc, char *argv[]) { ...@@ -610,7 +588,7 @@ static void process_options(int argc, char *argv[]) {
int network_if_specified = 0; int network_if_specified = 0;
for (;;) { for (;;) {
int c = getopt(argc, argv, "a:b:cCs:d:f:ghi:p:r:tvxDXT:GMS"); int c = getopt(argc, argv, "a:b:c:Cs:d:f:ghi:p:r:tvxDXT:GMS");
if (c == -1) break; if (c == -1) break;
...@@ -623,7 +601,7 @@ static void process_options(int argc, char *argv[]) { ...@@ -623,7 +601,7 @@ static void process_options(int argc, char *argv[]) {
strcpy(egress_params.server_ip, optarg); strcpy(egress_params.server_ip, optarg);
break; break;
case 'c': case 'c':
thread_params.emit_signal = 1; thread_params.emit_signal_gpio = atoi(optarg);
break; break;
case 'C': case 'C':
thread_params.enable_diff_ts = 1; thread_params.enable_diff_ts = 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment