--- /dev/null
+#include <stdio.h> // perror
+#include <stdlib.h> // exit
+#include <time.h>
+#include "frescan.h"
+
+#define PUT_ERROR(s) {perror (s); exit (-1);}
+
+#define NETWORK 0
+
+#define SENDER
+// #define ENABLE_LOGGING
+#define ENABLE_PARALLEL_PORT_TRACER
+
+#ifdef ENABLE_PARALLEL_PORT_TRACER
+#include <sys/pio.h>
+#define PP_BASE_REG 0x378
+#define PP_DATA_REG 0 // Data port offset
+#endif
+
+#if 0
+#include <stdio.h>
+#define DEBUG(x,args...) printf("%s: " x, __func__ , ##args)
+#else
+#define DEBUG(x,args...)
+#endif
+
+#ifdef SENDER
+
+#define LOCAL_NODE 1
+
+#ifdef ENABLE_LOGGING
+
+#include <drivers/console_switcher.h>
+#include <misc/logger.h>
+#include <assert.h>
+#define LOG_DEVICE LOG_ETHERNET
+
+#endif
+
+int main ()
+{
+ int i, ret;
+ frescan_send_params_t params;
+ char msg[200];
+ int written;
+ frescan_init_params_t init_params;
+ struct timespec my_period, next_activation;
+
+ init_params.net = NETWORK;
+ init_params.node = LOCAL_NODE;
+ init_params.tx_fp_max_prio = 10;
+ init_params.rx_num_of_channels = 5;
+ init_params.rx_channel_max_prio = NULL;
+
+#ifdef ENABLE_LOGGING
+ ret = logger_init(LOG_DEVICE);
+ assert(ret == 0);
+
+ DEBUG("Changing to membuffer console\n");
+ MEMBUFFER_CONSOLE_INIT();
+#endif
+ ret = frescan_init(&init_params);
+ if (ret != 0) PUT_ERROR ("could not init FRESCAN");
+
+ DEBUG("FRESCAN initialized (local node: %u)\n", LOCAL_NODE);
+
+ params.net = NETWORK;
+ params.to = 0;
+ params.channel = 0;
+ params.flags = FRESCAN_FP | FRESCAN_ASYNC;
+ params.prio = 7;
+
+ my_period.tv_sec = 0;
+ my_period.tv_nsec = 100000000;
+
+ outb_p (PP_BASE_REG + PP_DATA_REG, 0x00);
+
+ for(i=0; 1; i++) {
+ incr_timespec (next_activation, my_period); // the fosa one
+ clock_nanosleep(CLOCK_MONOTONIC,
+ TIMER_ABSTIME,
+ &next_activation, NULL);
+
+ written = snprintf(msg, sizeof(msg), "his number is... %d", i);
+#ifdef ENABLE_PARALLEL_PORT_TRACER
+ outb_p (PP_BASE_REG + PP_DATA_REG, 0xFF);
+#endif
+ ret = frescan_send(¶ms, (uint8_t *)msg, 32);
+ if (ret != 0) PUT_ERROR ("could not send message\n");
+
+#ifdef ENABLE_PARALLEL_PORT_TRACER
+ outb_p (PP_BASE_REG + PP_DATA_REG, 0x00);
+#endif
+ DEBUG("SENT: %d\n", i);
+#ifdef ENABLE_LOGGING
+ while (logger_manual_call() > 0);
+#endif
+ }
+
+ return 0;
+}
+
+#else
+
+#define LOCAL_NODE 0
+
+int main ()
+{
+ int ret;
+ frescan_recv_params_t params;
+ uint8_t msg[3000];
+ size_t recv_bytes;
+ frescan_node_t from;
+ frescan_init_params_t init_params;
+ frescan_prio_t prio;
+ struct timespec pulse_width = {0, 100000};
+
+ init_params.net = NETWORK;
+ init_params.node = LOCAL_NODE;
+ init_params.tx_fp_max_prio = 10;
+ init_params.rx_num_of_channels = 5;
+ init_params.rx_channel_max_prio = NULL;
+
+ ret = frescan_init(&init_params);
+ if (ret != 0) PUT_ERROR ("could not init FRESCAN");
+
+ DEBUG("FRESCAN initialized (local node: %u)\n", LOCAL_NODE);
+
+ params.net = NETWORK;
+ params.channel = 0;
+ params.flags = FRESCAN_SYNC;
+
+ outb_p (PP_BASE_REG + PP_DATA_REG, 0x00);
+
+ while (1) {
+ DEBUG("RECEIVING...\n");
+ ret = frescan_recv(¶ms, (uint8_t *)msg, sizeof(msg),
+ &recv_bytes, &from, &prio);
+ if (ret != 0) PUT_ERROR ("could not send message");
+#ifdef ENABLE_PARALLEL_PORT_TRACER
+ outb_p (PP_BASE_REG + PP_DATA_REG, 0xFF);
+ nanosleep(&pulse_width, NULL);
+ outb_p (PP_BASE_REG + PP_DATA_REG, 0x00);
+#endif
+ msg[recv_bytes] = '\0';
+ DEBUG("RECEIVED: %s with prio:%u from:%u\n", msg, prio, from);
+ }
+
+ return 0;
+}
+
+#endif