Commit f56e9305 authored by Federico Vaga's avatar Federico Vaga

wrtd:*: remove serializer

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>


NOTE
This commit has been created by `git subtree` on the Mock Turtle repository
on tag mock-turtle-2.0

This commit will not compile
parent ce26863b
/*
* This work is part of the White Rabbit Node Core project.
*
* Copyright (C) 2013-2014 CERN (www.cern.ch)
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* Released according to the GNU GPL, version 2 or any later version.
*/
/*.
* White Rabbit Trigge Distribution
*
* wrtd-serializers.h: API for serializing HMQ messages specific for WR Trigger Distribution system.
*/
#ifndef __WRTD_SERIALIZERS_H
#define __WRTD_SERIALIZERS_H
#include "wrtd-common.h"
#ifdef WRNODE_RT
#include "rt-message.h"
#endif
static inline int _trtl_msg_check_buffer( struct trtl_msg *buf, int n_words )
{
#ifndef WRNODE_RT
if(buf->error)
return -1;
if(buf->direction == WRNC_MSG_DIR_SEND &&
buf->datalen + n_words > buf->max_size)
{
#ifdef DEBUG
pp_printf("Error: HMQ buffer send overflow: %d vs %d\n", buf->datalen + n_words, buf->max_size );
#endif
buf->error = 1;
return -1;
} else if (buf->direction == WRNC_MSG_DIR_RECEIVE &&
buf->offset + n_words > buf->datalen ) {
#ifdef DEBUG
pp_printf("Error: HMQ buffer recv overflow: %d vs %d\n", buf->offset + n_words, buf->datalen );
#endif
buf->error = 1;
return -1;
}
#endif
return 0;
}
static inline int trtl_msg_int32 ( struct trtl_msg *buf, int *value )
{
if ( _trtl_msg_check_buffer ( buf, 1 ) < 0 )
return -1;
if (buf->direction == WRNC_MSG_DIR_SEND)
{
buf->data[buf->datalen] = *value;
buf->datalen++;
} else {
*value = buf->data[buf->offset];
buf->offset++;
}
return 0;
}
static inline int trtl_msg_int16 ( struct trtl_msg *buf, int16_t *value )
{
if ( _trtl_msg_check_buffer ( buf, 1 ) < 0 )
return -1;
if (buf->direction == WRNC_MSG_DIR_SEND)
{
buf->data[buf->datalen] = *value;
buf->datalen++;
} else {
*value = (int16_t) buf->data[buf->offset];
buf->offset++;
}
return 0;
}
static inline int trtl_msg_uint32 ( struct trtl_msg *buf, uint32_t *value )
{
return trtl_msg_int32( buf, (int *) value);
}
static inline int trtl_msg_uint16 ( struct trtl_msg *buf, uint16_t *value )
{
return trtl_msg_int16( buf, (int16_t *) value);
}
static inline int trtl_msg_header ( struct trtl_msg *buf, uint32_t *id, uint32_t *seq_no )
{
if (_trtl_msg_check_buffer ( buf, 2 ) < 0)
return -1;
if (buf->direction == WRNC_MSG_DIR_SEND)
{
buf->data[buf->datalen + 0] = *id;
buf->data[buf->datalen + 1] = *seq_no;
buf->datalen += 2;
} else {
*id = buf->data[buf->offset + 0];
*seq_no = buf->data[buf->offset + 1];
buf->offset += 2;
}
return 0;
}
static inline void trtl_msg_skip ( struct trtl_msg *buf, int n_words )
{
_trtl_msg_check_buffer ( buf, n_words );
if (buf->direction == WRNC_MSG_DIR_SEND)
buf->datalen += n_words;
else
buf->offset += n_words;
}
static inline void trtl_msg_seek ( struct trtl_msg *buf, int pos )
{
buf->offset = pos;
buf->datalen = pos;
}
static inline int wrtd_msg_timestamp ( struct trtl_msg *buf, struct wr_timestamp *ts )
{
if (_trtl_msg_check_buffer ( buf, 4 ) < 0)
return -1;
if (buf->direction == WRNC_MSG_DIR_SEND)
{
buf->data[buf->datalen + 0] = (ts->seconds >> 32) & 0xFFFFFFFF;
buf->data[buf->datalen + 1] = ts->seconds & 0xFFFFFFFF;
buf->data[buf->datalen + 2] = ts->ticks;
buf->data[buf->datalen + 3] = ts->frac;
buf->datalen += 4;
} else {
ts->seconds = ((uint64_t)buf->data[buf->offset + 0]) << 32;
ts->seconds |= buf->data[buf->offset + 1];
ts->ticks = buf->data[buf->offset + 2];
ts->frac = buf->data[buf->offset + 3];
buf->offset += 4;
}
return 0;
}
static inline int wrtd_msg_trig_id ( struct trtl_msg *buf, struct wrtd_trig_id *id )
{
if (_trtl_msg_check_buffer ( buf, 3 ) < 0)
return -1;
if (buf->direction == WRNC_MSG_DIR_SEND)
{
buf->data[buf->datalen + 0] = id->system;
buf->data[buf->datalen + 1] = id->source_port;
buf->data[buf->datalen + 2] = id->trigger;
buf->datalen += 3;
} else {
id->system = buf->data[buf->offset + 0];
id->source_port = buf->data[buf->offset + 1];
id->trigger = buf->data[buf->offset + 2];
buf->offset += 3;
}
return 0;
}
static inline int wrtd_msg_trigger_entry ( struct trtl_msg *buf, struct wrtd_trigger_entry *ent )
{
if (wrtd_msg_timestamp (buf, &ent->ts) < 0)
return -1;
if (wrtd_msg_trig_id (buf, &ent->id) < 0)
return -1;
return trtl_msg_int32 (buf, (int *) &ent->seq);
}
static inline struct trtl_msg trtl_msg_init(int max_size)
{
struct trtl_msg b;
b.direction = WRNC_MSG_DIR_SEND;
b.max_size = max_size;
b.offset = 0;
b.datalen = 0;
b.error = 0;
return b;
}
static inline int trtl_msg_check_error (struct trtl_msg *buf)
{
return buf->error;
}
#endif
......@@ -10,7 +10,6 @@
#include <errno.h>
#include <libmockturtle.h>
#include <libwrtd-internal.h>
#include <wrtd-serializers.h>
static const uint32_t application_id[] = {
0x115790de,
......
......@@ -29,6 +29,11 @@ struct wrtd_desc {
uint32_t n_cpu; /**< Number of CPUs */
};
#define WRTD_OUT_CHANNEL_PUBLIC_SIZE (sizeof(struct wrtd_out_channel) \
- sizeof(struct wrtd_out_channel_private))
/**
* @file libwrtd-interal.c
*/
......
......@@ -11,7 +11,6 @@
#include <poll.h>
#include <libmockturtle.h>
#include <libwrtd-internal.h>
#include <wrtd-serializers.h>
/**
* It returns a human readable string that describe a given log level
......@@ -167,7 +166,6 @@ int wrtd_log_read(struct trtl_hmq *hmq_log, struct wrtd_log_entry *log,
struct pollfd p;
int remaining = count;
int n_read = 0, ret;
uint32_t id = 0, seq = 0;
p.fd = hmq_log->fd;
p.events = POLLIN;
......@@ -177,7 +175,6 @@ int wrtd_log_read(struct trtl_hmq *hmq_log, struct wrtd_log_entry *log,
than expected */
errno = 0;
while (remaining) {
struct wrtd_trigger_entry ent;
ret = poll(&p, 1, poll_timeout);
if (ret <= 0 || !(p.revents & POLLIN))
break;
......@@ -186,41 +183,14 @@ int wrtd_log_read(struct trtl_hmq *hmq_log, struct wrtd_log_entry *log,
if (!msg)
break;
if (hmq_log->index == WRTD_OUT_FD_LOGGING) {
/* Output */
trtl_msg_header (msg, &id, &seq);
if (id != WRTD_REP_LOG_MESSAGE)
{
free(msg);
errno = EWRTD_INVALID_ANSWER_STATE;
break;
}
trtl_msg_uint32 (msg, &cur->type);
trtl_msg_int32 (msg, &cur->channel);
trtl_msg_uint32 (msg, &cur->miss_reason);
wrtd_msg_trigger_entry(msg, &ent);
cur->ts = ent.ts;
cur->seq = ent.seq;
cur->id = ent.id;
if ( trtl_msg_check_error(msg) ) {
free(msg);
errno = EWRTD_INVALID_ANSWER_STATE;
break;
}
} else {
/* Input */
trtl_message_unpack(msg, &hdr, cur);
if (hdr.msg_id != WRTD_IN_ACTION_LOG) {
free(msg);
errno = EWRTD_INVALID_ANSWER_STATE;
break;
}
wrtd_timestamp_endianess_fix(&cur->ts);
trtl_message_unpack(msg, &hdr, cur);
if (hdr.msg_id != WRTD_IN_ACTION_LOG &&
hdr.msg_id != WRTD_OUT_ACTION_LOG) {
free(msg);
errno = EWRTD_INVALID_ANSWER_STATE;
break;
}
wrtd_timestamp_endianess_fix(&cur->ts);
remaining--;
n_read++;
......@@ -265,7 +235,7 @@ static int wrtd_log_level_set(struct wrtd_node *dev, unsigned int channel,
}
tlv.index = OUT_STRUCT_CHAN_0 + channel;
tlv.size = sizeof(struct wrtd_out_channel);
tlv.size = WRTD_OUT_CHANNEL_PUBLIC_SIZE;
tlv.structure = &ochan;
hdr.slot_io = (WRTD_IN_FD_CONTROL << 4) |
(WRTD_OUT_FD_CONTROL & 0xF);
......
......@@ -11,10 +11,6 @@
#include <libmockturtle.h>
#include <libwrtd-internal.h>
#include "wrtd-serializers.h"
#define WRTD_OUT_CHANNEL_PUBLIC_SIZE (sizeof(struct wrtd_out_channel) \
- sizeof(struct wrtd_out_channel_private))
/* Basic header for synchronous messages */
static const struct trtl_proto_header hdr_base_sync = {
......
......@@ -31,6 +31,7 @@
static const uint32_t version = GIT_VERSION;
static uint32_t promiscuous_mode = 0;
struct rt_application app;
#define WR_LINK_OFFLINE 1
......@@ -192,11 +193,12 @@ static void ts_adjust_delay(struct wr_timestamp *ts, uint32_t cycles, uint32_t f
/**
* Puts a trigger message in the log buffer
*/
static void log_trigger(int type, int miss_reason, struct wrtd_out_channel *out,
static void log_trigger(int type, int miss_reason,
struct wrtd_out_channel *out,
struct wrtd_trigger_entry *ent)
{
struct trtl_proto_header hdr = {
.rt_app_id = 0,
.rt_app_id = app.version.rt_id,
.msg_id = WRTD_OUT_ACTION_LOG,
.slot_io = WRTD_OUT_FD_LOGGING,
.seq = ent->seq,
......
......@@ -41,6 +41,7 @@ enum wrtd_in_wr_link {
static struct wrtd_in wrtd_in_dev;
static struct wrtd_in_channel wrtd_in_channels[TDC_NUM_CHANNELS];
struct rt_application app;
uint32_t seq = 0; /**< global sequence number */
uint32_t sent_packets = 0; /**< Total number of packets sent */
......@@ -80,7 +81,7 @@ static int wrtd_in_trigger_log(int type, int miss_reason,
struct trtl_msg out_buf;
struct wrtd_log_entry *log;
struct trtl_proto_header hdr = {
.rt_app_id = 0,
.rt_app_id = app.version.rt_id,
.msg_id = WRTD_IN_ACTION_LOG,
.slot_io = WRTD_OUT_TDC_LOGGING,
.seq = seq,
......
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