Skip to content
Snippets Groups Projects
Commit 6210cbed authored by Pieter Donker's avatar Pieter Donker
Browse files

Merge branch 'L2SDP-413' into 'master'

L2SDP-413, removed some memcpy functions.

See merge request !22
parents fbf359a1 9dd90898
Branches
Tags
1 merge request!22L2SDP-413, removed some memcpy functions.
......@@ -225,7 +225,6 @@ bool Fpga::point(TermOutput& termout, const char cmd, const string addr,
termout.clear();
string relative_addr = pointMap->getRelativeName(addr);
string type = "fpga";
string instance = "";
try {
if (cmd == 'R') {
......@@ -267,8 +266,7 @@ bool Fpga::point(TermOutput& termout, const char cmd, const string addr,
if (cmd == 'W') {
didx = idx * nof_values * reg_format_size_in_bytes(format);
}
if ((ret = node->exec_cmd(cmd, relative_addr, type, instance,
&data[didx], nof_values, format))) {
if ((ret = node->exec_cmd(cmd, relative_addr, type, &data[didx], nof_values, format))) {
retcnt++;
exec_cnt++;
}
......
......@@ -44,33 +44,34 @@ using namespace std;
extern int debug;
volatile bool WorkersRunning = true;
typedef struct {
char cmdId;
char relative_addr[100];
char type[100];
char instance[100];
uint nvalues;
int format;
char data[32800];
} pread_cmd_struct;
typedef struct {
char cmdId;
uint retval;
char val[32800];
int nof_vals;
int datatype;
} pread_reply_struct;
cCmd::cCmd() { init(); }
void cCmd::init()
{
cmdId = ' ';
memset(relative_addr, 0, sizeof(relative_addr));
memset(type, 0, sizeof(type));
nvalues = 0;
format = REG_FORMAT_UNKNOWN;
memset(data, 0, sizeof(data));
}
cCmd::~cCmd() {}
cReply::cReply() { init(); }
void cReply::init()
{
cmdId = ' ';
retval = 0;
memset(data, 0, sizeof(data));
nvalues = 0;
format = REG_FORMAT_UNKNOWN;
}
cReply::~cReply() {}
void Node::worker()
{
TermOutput termout;
pread_reply_struct r;
array<unsigned char, cmd_buf_size> inbuf = {0};
array<unsigned char, reply_buf_size> outbuf = {0};
cout << "Node::worker thread for client"
<< " Uniboard=" << UniboardNr
<< " New node IP=" << myIPaddr
......@@ -78,49 +79,45 @@ void Node::worker()
<< " localnr=" << LocalNr
<< " globalnr=" << GlobalNr << endl;
cout << " sizeof(pread_cmd_struct)=" << sizeof(pread_reply_struct)
<< " sizeof(pread_reply_struct)=" << sizeof(pread_cmd_struct) << endl;
while (WorkersRunning) {
inbuf.fill({0});
if (cmd_queue.Pop(inbuf) == false) {
cCmd p;
if (cmd_queue.Pop(p) == false) {
continue;
}
pread_cmd_struct *p = (pread_cmd_struct *)inbuf.data();
// cout << " p.relative_addr=" << p->relative_addr << endl;
// cout << " p.type=" << p->type << endl;
// cout << " p.instance=" << p->instance << endl;
// cout << " p.nvalues=" << p->nvalues << endl;
// cout << " p.format=" << p->format << endl;
// cout << " p.cmd=" << p->cmdId << endl;
termout.clear();
memset((void *)&r, 0, sizeof(pread_reply_struct));
r.cmdId = p->cmdId;
cReply r;
r.cmdId = p.cmdId;
try {
switch (p->cmdId) {
switch (p.cmdId) {
case 'S': {
printf("Node::worker job for Uniboard=%d New node IP=%s shutdown!!\n", UniboardNr, myIPaddr.c_str());
WorkersRunning = false;
r.format = p.format;
continue; // shutdown worker thread
} break;
case 'M': {
r.retval = periph_fpga->monitor(termout);
r.format = p.format;
continue; // monitor points
} break;
case 'R': { // read
if (strcmp(p->type, "fpga") == 0 || strcmp(p->type, "mm") == 0) {
r.retval = periph_fpga->read(termout, p->relative_addr, p->type, p->data, p->nvalues, p->format);
r.nof_vals = termout.nof_vals;
r.datatype = termout.datatype;
if (strcmp(p.type, "fpga") == 0 || strcmp(p.type, "mm") == 0) {
r.retval = periph_fpga->read(termout, p.relative_addr, p.type, p.data, p.nvalues, p.format);
r.nvalues = termout.nof_vals;
r.format = termout.datatype;
}
} break;
case 'W': { // write
if (strcmp(p->type, "fpga") == 0 || strcmp(p->type, "mm") == 0) {
r.retval = periph_fpga->write(termout, p->relative_addr, p->type, p->data, p->nvalues, p->format);
r.nof_vals = p->nvalues;
r.datatype = p->format;
if (strcmp(p.type, "fpga") == 0 || strcmp(p.type, "mm") == 0) {
r.retval = periph_fpga->write(termout, p.relative_addr, p.type, p.data, p.nvalues, p.format);
r.nvalues = p.nvalues;
r.format = p.format;
}
} break;
default: {
......@@ -136,24 +133,16 @@ void Node::worker()
r.retval = 0;
//cerr << "Node::worker '...' exception" << endl;
}
// r.nof_vals = termout.nof_vals;
// r.datatype = termout.datatype;
// cout << " p.relative_addr=" << p->relative_addr << endl;
// cout << " p.type=" << p->type << endl;
// cout << " p.instance=" << p->instance << endl;
// cout << " r.nvalues=" << r.nof_vals << endl;
// cout << " r.format=" << r.datatype << endl;
// cout << " r.nvalues=" << r.nvalues << endl;
// cout << " r.format=" << r.format << endl;
// cout << " p.cmd=" << p->cmdId << endl;
int sz = reg_format_size_in_bytes(r.datatype);
memcpy((void *)r.val, (void *)termout.val, termout.nof_vals * sz);
int sz = reg_format_size_in_bytes(r.format);
memcpy((void *)r.data, (void *)termout.val, termout.nof_vals * sz);
outbuf.fill({0});
memcpy(outbuf.data(), (void *)&r, sizeof(pread_reply_struct));
reply_queue.Push(outbuf);
reply_queue.Push(r);
}
// cout << "Node::worker job"
// << " Uniboard=" << UniboardNr
......@@ -195,15 +184,9 @@ Node::~Node()
{
WorkersRunning = false;
pread_cmd_struct p;
memset((void *)&p, 0, sizeof(pread_cmd_struct));
cCmd p;
p.cmdId = 'S';
array<unsigned char, cmd_buf_size> outbuf;
outbuf.fill({0});
memcpy(outbuf.data(), (void *)&p, sizeof(pread_cmd_struct));
cmd_queue.Push(outbuf);
cmd_queue.Push(p);
cout << "Joining threads" << endl;
worker_thread->join();
......@@ -218,15 +201,9 @@ Node::~Node()
bool Node::monitor(TermOutput& termout) {
pread_cmd_struct p;
memset((void *)&p, 0, sizeof(pread_cmd_struct));
cCmd p;
p.cmdId = 'M';
array<unsigned char, cmd_buf_size> outbuf;
outbuf.fill({0});
memcpy(outbuf.data(), (void *)&p, sizeof(pread_cmd_struct));
cmd_queue.Push(outbuf);
cmd_queue.Push(p);
return true;
}
......@@ -256,15 +233,13 @@ uint32_t Node::ppsOffsetCnt(void) {
bool Node::exec_cmd(const char cmd, const string relative_addr,
const string type, const string instance, const char *data,
const string type, const char *data,
const int nvalues, const int format)
{
pread_cmd_struct p;
memset((void *)&p, 0, sizeof(pread_cmd_struct));
cCmd p;
p.cmdId = cmd;
strcpy(p.relative_addr, relative_addr.c_str());
strcpy(p.type, type.c_str());
strcpy(p.instance, instance.c_str());
p.nvalues = nvalues;
p.format = format;
if (cmd == 'W') {
......@@ -274,33 +249,26 @@ bool Node::exec_cmd(const char cmd, const string relative_addr,
// << " p.format=" << p.format << endl;
}
array<unsigned char, cmd_buf_size> outbuf;
outbuf.fill({0});
memcpy(outbuf.data(), (void *)&p, sizeof(pread_cmd_struct));
cmd_queue.Push(outbuf);
cmd_queue.Push(p);
return true;
}
bool Node::exec_reply(TermOutput& termout)
{
array<unsigned char, reply_buf_size> inbuf;
inbuf.fill({0});
if (reply_queue.Pop(inbuf) == false) {
cReply r;
if (reply_queue.Pop(r) == false) {
return false;
}
pread_reply_struct *r = (pread_reply_struct *)inbuf.data();
termout.nof_vals = r->nof_vals;
termout.datatype = r->datatype;
termout.nof_vals = r.nvalues;
termout.datatype = r.format;
// cout << "received " << r->nof_vals << " bytes from worker node=" << GlobalNr
// << " retval=" << r->retval << " datatype=" << r->datatype << endl;
if (isOnline() && r->retval) {
int sz = reg_format_size_in_bytes(r->datatype);
memcpy((void *)termout.val, (void *)r->val, r->nof_vals * sz);
if (isOnline() && r.retval) {
int sz = reg_format_size_in_bytes(r.format);
memcpy((void *)termout.val, (void *)r.data, r.nvalues * sz);
}
return r->retval;
return r.retval;
}
......@@ -50,6 +50,44 @@ public:
int n_beamsets;
};
#define MAX_DATA_SIZE 32800 // Size of data array in cCmd and cReply.
#define MAX_ADDR_SIZE 128 // Size of rel_addr in cCmd.
#define MAX_TYPE_SIZE 8 // Size of rel_addr in cCmd.
/*
* cCmd class used for sending messages to the worker thread.
* init() is used to clear all values.
*/
class cCmd {
public:
cCmd();
~cCmd();
void init();
char cmdId; // Requested cmd: 'R', 'W', 'S' or 'M' task. (Read, Write, Monitor or Stop).
char relative_addr[MAX_ADDR_SIZE]; // fpga register address to access.
char type[MAX_TYPE_SIZE]; // "fpga" or "mm" task. (fpga = function, mm = direct).
uint nvalues; // Number of values of type format in data.
int format; // data format in data, see REG_FORMAT_* in register.h for all available types
char data[MAX_DATA_SIZE]; // data array.
};
/*
* cReply class used for return value from the worker thread.
* init() is used to clear all values.
*/
class cReply {
public:
cReply();
~cReply();
void init();
char cmdId; // processed cmd: 'R', 'W', 'S' or 'M' task. (Read, Write, Monitor or Stop)
uint retval; // return value of executed cmd, true = success, false = failure.
char data[MAX_DATA_SIZE]; // data array.
int nvalues; // Number of values of type format in data.
int format; // data format in data, see REG_FORMAT_* in register.h
};
#define GLOBALNODE_to_UNB(n) (n>>2)
#define GLOBALNODE_to_TYPE(n) ("pn")
#define GLOBALNODE_to_NODE(n) (n&0x3)
......@@ -66,8 +104,8 @@ class Node {
std::string Type;
std::thread *worker_thread;
CMessageQueue<std::array<unsigned char, cmd_buf_size>> cmd_queue;
CMessageQueue<std::array<unsigned char, reply_buf_size>> reply_queue;
CMessageQueue<cCmd> cmd_queue;
CMessageQueue<cReply> reply_queue;
Periph_fpga *periph_fpga;
......@@ -96,7 +134,7 @@ class Node {
void worker();
bool exec_cmd(const char cmd, const std::string relative_addr,
const std::string type, const std::string instance, const char *data,
const std::string type, const char *data,
const int nvalues, const int format);
bool exec_reply(TermOutput& t);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment