Commit 1cb92354 authored by Oscar Olsson's avatar Oscar Olsson
Browse files

Merge branch 'patch_xeno'

Conflicts:
	cmake_modules/FindRTNet.cmake
	src/transport/firefly_transport_eth_xeno.c
parents 237d144e d7a338d9
......@@ -4,6 +4,12 @@
#include <transport/firefly_transport.h>
#include <sys/time.h>
/**
* @brief The default read timeout (in nanoseconds, i.e. 500ms) between
* resending important packets.
*/
#define FIREFLY_TRANSPORT_ETH_XENO_DEFAULT_TIMEOUT (500000000)
/**
* @brief This callback will be called when a new connection is received.
*
......@@ -91,6 +97,32 @@ struct firefly_transport_connection *firefly_transport_connection_eth_xeno_new(
void firefly_transport_eth_xeno_read(struct firefly_transport_llp *llp,
int64_t *timeout);
/**
* @brief Start reader and resend thread. Both will run until stopped with
* firefly_transport_eth_xeno_stop().
*
* @param llp The LLP to run.
* @return Integer indicating success or failure.
* @retval 0 if successfull.
* @retval <0 upon error.
* @see #firefly_transport_eth_xeno_stop()
*/
int firefly_transport_eth_xeno_run(struct firefly_transport_llp *llp);
/**
* @brief Stop reader and resend thread. Any thread to be stopped must have been
* started with firefly_transport_eth_xeno_run(), if not the result is
* undefined.
*
* @param llp The LLP to stop.
* @return Integer indicating success or failure.
* @retval 0 if successfull.
* @retval <0 upon error.
* @see #firefly_transport_eth_xeno_run()
*/
int firefly_transport_eth_xeno_stop(struct firefly_transport_llp *llp);
/**
* @brief Get the struct with implementations of each memory function as
* specified by #firefly_memory_funcs.
......
......@@ -21,6 +21,7 @@ if(NOT CMAKE_CROSSCOMPILING)
add_library(transport-eth-xenomai
${Firefly_SOURCE_DIR}/transport/firefly_transport.c
${Firefly_SOURCE_DIR}/transport/firefly_transport_eth_xeno.c
${Firefly_SOURCE_DIR}/utils/firefly_event_queue_xeno.c
)
set_target_properties(transport-eth-xenomai
PROPERTIES COMPILE_FLAGS "-std=gnu99 -D_GNU_SOURCE -D_REENTRANT -D__XENO__"
......
......@@ -16,6 +16,7 @@
#include <native/task.h>
#include <rtnet.h>
#include <native/timer.h>
#include <native/mutex.h>
#include <rtdm/rtdm.h>
#include <sys/select.h> // defines fd_set
......@@ -38,6 +39,9 @@
#define ERROR_STR_MAX_LEN (256)
#define XENO_HEAP_SIZE (1024)
#define EVENT_LOOP_PRIO (55)
#define READER_TASK_PRIO (50)
struct firefly_transport_llp *firefly_transport_llp_eth_xeno_new(
const char *iface_name,
firefly_on_conn_recv_eth_xeno on_conn_recv,
......@@ -305,7 +309,6 @@ void firefly_transport_eth_xeno_write(unsigned char *data, size_t data_size,
(struct sockaddr *)conn_eth->remote_addr,
sizeof(*conn_eth->remote_addr));
if (err < 0) {
FFL(FIREFLY_ERROR_SOCKET);
firefly_connection_raise_later(conn,
FIREFLY_ERROR_TRANS_WRITE, "rt_dev_sendto() failed");
}
......@@ -378,8 +381,8 @@ void firefly_transport_eth_xeno_read(struct firefly_transport_llp *llp,
} else if (res < 0) {
char err_buf[ERROR_STR_MAX_LEN];
strerror_r(-res, err_buf, ERROR_STR_MAX_LEN);
firefly_error(FIREFLY_ERROR_SOCKET, 4,
"recvfrom() failed in %s().\n%s, %s\n",
firefly_error(FIREFLY_ERROR_SOCKET, 3,
"recvfrom() failed in %s().\n%s\n",
__FUNCTION__, err_buf);
return;
}
......@@ -405,6 +408,78 @@ void firefly_transport_eth_xeno_read(struct firefly_transport_llp *llp,
firefly_transport_eth_xeno_read_event, ev_arg, 0, NULL);
}
static void read_thread_run(void *arg)
{
struct firefly_transport_llp *llp;
struct transport_llp_eth_xeno *llp_eth;
int64_t timeout;
bool running;
llp = arg;
llp_eth = llp->llp_platspec;
timeout = FIREFLY_TRANSPORT_ETH_XENO_DEFAULT_TIMEOUT;
running = true;
do {
firefly_transport_eth_xeno_read(llp, &timeout);
rt_mutex_acquire(&llp_eth->run_mutex, TM_INFINITE);
running = llp_eth->running;
rt_mutex_release(&llp_eth->run_mutex);
} while (running);
}
int firefly_transport_eth_xeno_run(struct firefly_transport_llp *llp)
{
int res;
struct transport_llp_eth_xeno *llp_eth;
// TODO: Add resend loop
/* struct firefly_resend_loop_args *largs;*/
llp_eth = llp->llp_platspec;
llp_eth->running = true;
res = rt_task_create(&llp_eth->read_thread, "reader_task", 0,
READER_TASK_PRIO, T_FPU|T_JOINABLE);
if (res < 0)
return res;
res = rt_mutex_create(&llp_eth->run_mutex, "run_mutex");
if (res < 0) {
llp_eth->running = false;
rt_task_delete(&llp_eth->read_thread);
return res;
}
res = rt_task_start(&llp_eth->read_thread, read_thread_run, llp);
/* largs = malloc(sizeof(*largs));*/
/* if (!largs) {*/
/* llp_eth->running = false;*/
/* return -1;*/
/* }*/
/* largs->rq = llp_eth->resend_queue;*/
/* largs->on_no_ack = resend_on_no_ack;*/
/* res = pthread_create(&llp_eth->resend_thread, NULL,*/
/* firefly_resend_run, largs);*/
return res;
}
int firefly_transport_eth_xeno_stop(struct firefly_transport_llp *llp)
{
int res;
struct transport_llp_eth_xeno *llp_eth;
llp_eth = llp->llp_platspec;
rt_mutex_acquire(&llp_eth->run_mutex, TM_INFINITE);
llp_eth->running = false;
rt_mutex_release(&llp_eth->run_mutex);
res = rt_task_join(&llp_eth->read_thread);
return res;
}
void get_mac_addr(struct sockaddr_ll *addr, char *mac_addr)
{
char temp_addr[18];
......
......@@ -8,6 +8,8 @@
#include <netpacket/packet.h> // defines sockaddr_ll
#include <signal.h>
#include <native/heap.h>
#include <native/task.h>
#include <native/mutex.h>
/**
* @brief The protocol specified in every firefly packet. This is used to filter
......@@ -31,6 +33,14 @@ struct transport_llp_eth_xeno {
firefly_on_conn_recv_eth_xeno on_conn_recv; /**< The callback to be
called when a new
connection is received. */
struct resend_queue *resend_queue; /**< The resend queue managing important
packets. */
RT_TASK read_thread; /**< The handle to the thread running the read loop. */
RT_MUTEX run_mutex;
RT_TASK resend_thread; /**< The handle to the thread running the resend
loop. */
bool running; /**< Whether or not the read loop should exit. */
RT_HEAP dyn_mem; /**< The heap implementing real time allocation of dynamic
memory. */
};
......
Supports Markdown
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