From 39f38eb0dfafd4ea5270ccc62582d677a18e7c48 Mon Sep 17 00:00:00 2001 From: hades Date: Thu, 30 Mar 2006 10:17:53 +0000 Subject: [PATCH] first hubtest, Ingo --- Makefile | 2 +- basic.h | 9 +++- hubtest.cc | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++-- iobufc2.cc | 90 +++++++++++++++++++++++++++++++++++++ iobufc2.h | 68 ++++++++++++++++++++++++++++ iobufcx.cc | 2 + iobufcx.h | 3 +- obufcx.cc | 3 ++ obufcx.h | 1 + 9 files changed, 300 insertions(+), 7 deletions(-) create mode 100644 iobufc2.cc create mode 100644 iobufc2.h diff --git a/Makefile b/Makefile index 8c15b61..5f5d48d 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ .SUFFIXES: .cc -OBJS = ibufcx.o obufcx.o iobufcx.o iofifo.o hubtest.o basic.o +OBJS = ibufcx.o obufcx.o iobufcx.o iobufc2.o iofifo.o hubtest.o basic.o CXX = g++ CXXFLAGS = -g -O3 -Wall -fPIC diff --git a/basic.h b/basic.h index 5f3f56b..229067a 100644 --- a/basic.h +++ b/basic.h @@ -46,11 +46,16 @@ using namespace std; #define STATUSBITS 24,26 -#define HEADER_HEADER 0x1 -#define HEADER_TERM 0x2 +#define HEADER_INIT_HEADER 0x1 +#define HEADER_INIT_TERM 0x2 #define HEADER_BUF 0x3 #define HEADER_DATA 0x4 #define HEADER_ACK 0x5 +#define HEADER_REPLY_HEADER 0x6 +#define HEADER_REPLY_TERM 0x7 + + + // diff --git a/hubtest.cc b/hubtest.cc index 69a0fab..e05d065 100644 --- a/hubtest.cc +++ b/hubtest.cc @@ -1,4 +1,5 @@ #include "iobufcx.h" +#include "iobufc2.h" #include "iofifo.h" int acktest(void) { @@ -66,11 +67,34 @@ void connect(IOBUFCX * a, IOBUFCX * b) { } + +void connect2(IOBUFCX * a1, IOBUFCX * a2, IOBUFC2 * b) { + //cross-connect 2 buffers to 1 fan-in + //this is what the OSI_LINK_LAYER should do + + b->SIGIN_PORT1 = a1->SIGOUT; + a1->SIGIN = b->SIGOUT_PORT1; + b->SIGIN_PORT2 = a2->SIGOUT; + a2->SIGIN = b->SIGOUT_PORT2; + + b->READ_PORT1 = b->DATAREADY_PORT1; + b->READ_PORT2 = b->DATAREADY_PORT2; + a1->READ = a1->DATAREADY; + a2->READ = a2->DATAREADY; + + b->WRITE_PORT1 = a1->DATAREADY; + b->WRITE_PORT2 = a2->DATAREADY; + a1->WRITE = b->DATAREADY_PORT1; + a2->WRITE = b->DATAREADY_PORT2; + +} + + int iofifotest(void) { IOFIFO send,end; - for (int i=0; i<15; i++) { + for (int i=0; i<20; i++) { //TESTBENCH if (i==0) { @@ -85,6 +109,10 @@ int iofifotest(void) { else if (i==2) { send.WRITE=1; send.SIGIN.set(0x01212u); // data word + } + else if (i==5) { + send.WRITE=1; + send.SIGIN.set(0x02000000u); // data word } else { send.WRITE=0; } @@ -137,10 +165,105 @@ int iofifotest(void) { + + + + + +int fan_in_test(void) { + + IOFIFO send1,send2; + IOBUFC2 fan_in; + + for (int i=0; i<20; i++) { + + //TESTBENCH + if (i==0) { + //write a word into send + send1.WRITE=1; + send2.WRITE=1; + send1.SIGIN.set(0x00adfaceu); + send2.SIGIN.set(0x00affeu); + } + else if (i==1) { + send1.WRITE=1; + send2.WRITE=0; + send1.SIGIN.set(0x00345678u); // data word + } + else if (i==2) { + send1.WRITE=1; + send1.SIGIN.set(0x01212u); // data word + } + else if (i==5) { + send1.WRITE=1; + send1.SIGIN.set(0x02000000u); // data word + } else { + send1.WRITE=0; + } + + //HEADER activate + if (i==3) { + send1.WRITE_SENDER_HEADER=1; + send1.SENDER_HEADER.set(0x01000000u); + send2.WRITE_SENDER_HEADER=1; + send2.SENDER_HEADER.set(0x01000000u); + } else { + send1.WRITE_SENDER_HEADER=0; + send2.WRITE_SENDER_HEADER=0; + } + + for (int l=0;l<100;l++) { + //simulate READER + if (fan_in.DATAREADY_OUT_INT) fan_in.READ_IN_INT=1; + else fan_in.READ_IN_INT=0; + send1.Logic(); + send2.Logic(); + fan_in.Logic(); + connect2(&send1.iobuffer, &send2.iobuffer, &fan_in); + + } + + // + if (send1.iobuffer.DATAREADY) + cout << "DOWN MEDIA1 SIGOUT " << std::hex << send1.iobuffer.SIGOUT.get_value(0,27) << endl; + else cout << "NO DOWN MEDIA1 DATA" << endl; + + if (send2.iobuffer.DATAREADY) + cout << "DOWN MEDIA2 SIGOUT " << std::hex << send2.iobuffer.SIGOUT.get_value(0,27) << endl; + else cout << "NO DOWN MEDIA2 DATA" << endl; + + if (fan_in.DATAREADY_PORT1) + cout << "UP MEDIA1 SIGOUT " << std::hex << fan_in.SIGOUT_PORT1.get_value(0,27) << endl; + else cout << "NO UP MEDIA1 DATA" << endl; + + if (fan_in.DATAREADY_PORT2) + cout << "UP MEDIA2 SIGOUT " << std::hex << fan_in.SIGOUT_PORT2.get_value(0,27) << endl; + else cout << "NO UP MEDIA2 DATA" << endl; + + if (fan_in.DATAREADY_OUT_INT) + cout << "FAN MEDIA SIGOUT " << std::hex << fan_in.SIGOUT_INT.get_value(0,27) << endl; + else cout << "NO FAN MEDIA DATA" << endl; + + //fan_in.Dump(); + //fan_in.myiobuf_port1.myibuf.Dump(); + + send1.NextCLK(); + send2.NextCLK(); + fan_in.NextCLK(); + cout << "--------------------" << endl; + } + + +} + + + + int main(void) { //acktest(); - iofifotest(); - + //iofifotest(); + + fan_in_test(); } diff --git a/iobufc2.cc b/iobufc2.cc new file mode 100644 index 0000000..723fbf5 --- /dev/null +++ b/iobufc2.cc @@ -0,0 +1,90 @@ +#include "iobufc2.h" + + +void IOBUFC2::Logic(void){ + + //trivial connections + myiobuf_port1.SIGIN_INT = SIGIN_INT; + myiobuf_port2.SIGIN_INT = SIGIN_INT; + myiobuf_port1.SIGIN = SIGIN_PORT1; + myiobuf_port2.SIGIN = SIGIN_PORT2; + SIGOUT_PORT1 = myiobuf_port1.SIGOUT; + SIGOUT_PORT2 = myiobuf_port2.SIGOUT; + + //forward read request to the correct IOBUF + if (read_pointer == 0) { + SIGOUT_INT = myiobuf_port1.SIGOUT_INT; + myiobuf_port1.READ_IN_INT = READ_IN_INT; + myiobuf_port2.READ_IN_INT = 0; + DATAREADY_OUT_INT = myiobuf_port1.DATAREADY_OUT_INT; + } else if (read_pointer == 1) { + SIGOUT_INT = myiobuf_port2.SIGOUT_INT; + myiobuf_port1.READ_IN_INT = 0; + myiobuf_port2.READ_IN_INT = READ_IN_INT; + DATAREADY_OUT_INT = myiobuf_port2.DATAREADY_OUT_INT; + } + + if (myiobuf_port1.FREE_FOR_OUT_TRANSFER + && myiobuf_port2.FREE_FOR_OUT_TRANSFER) { + myiobuf_port1.DATAREADY_IN_INT = 1; + myiobuf_port2.DATAREADY_IN_INT = 1; + } //all 2 obufs are ready + else { + myiobuf_port1.DATAREADY_IN_INT = 0; + myiobuf_port2.DATAREADY_IN_INT = 0; + } + DATAREADY_PORT1 = myiobuf_port1.DATAREADY; + DATAREADY_PORT2 = myiobuf_port2.DATAREADY; + + myiobuf_port1.READ = READ_PORT1; + myiobuf_port2.READ = READ_PORT2; + + myiobuf_port1.WRITE = WRITE_PORT1; + myiobuf_port2.WRITE = WRITE_PORT2; + + myiobuf_port1.RESENDHEADER_IN_INT = RESENDHEADER_IN_INT; + myiobuf_port2.RESENDHEADER_IN_INT = RESENDHEADER_IN_INT; + + //if one of the output ports has to take a new header + //just do it for both + if (myiobuf_port1.RESENDHEADER_OUT_INT || myiobuf_port2.RESENDHEADER_OUT_INT) + RESENDHEADER_OUT_INT = 1; + else + RESENDHEADER_OUT_INT = 0; + + //the state machine to control the input + if (mystate==IOBUF2_FREEMODE) { //no preferred input + if (myiobuf_port1.DATAREADY_OUT_INT) { + next_read_pointer = 0; + nextstate = IOBUF2_LOCKEDMODE; + } + else if (myiobuf_port2.DATAREADY_OUT_INT) { + next_read_pointer = 1; + nextstate = IOBUF2_LOCKEDMODE; + } + else { + next_read_pointer = 0; + nextstate = IOBUF2_FREEMODE; + } + } else if (mystate==IOBUF2_LOCKEDMODE) { + //wait is IBUF is terminated... + + } + + myiobuf_port1.Logic(); + myiobuf_port2.Logic(); + +}; + +void IOBUFC2::NextCLK(void){ + read_pointer = next_read_pointer; + mystate = nextstate; + myiobuf_port1.NextCLK(); + myiobuf_port2.NextCLK(); +} + + +void IOBUFC2::Dump(void) { + cout << "ST: " << mystate << " rpoint: " << read_pointer << " D_O_I1 " << myiobuf_port1.DATAREADY_OUT_INT + << " D_O_I2 " << myiobuf_port2.DATAREADY_OUT_INT << endl; +} diff --git a/iobufc2.h b/iobufc2.h new file mode 100644 index 0000000..9c66cfa --- /dev/null +++ b/iobufc2.h @@ -0,0 +1,68 @@ +#ifndef IOBUFC2_H +#define IOBUFC2_H + + + +#include "basic.h" +#include "iobufcx.h" + + +#define IOBUF2_FREEMODE 1 +#define IOBUF2_LOCKEDMODE 2 + +// +// output buffer for ONE channel and TWO ports +// + +class IOBUFC2 { + public: + IOBUFC2() {RESET();}; + void RESET() { + read_pointer =0; + mystate = IOBUF2_FREEMODE; + }; + + void Logic(void); + + in_vector28 SIGIN_INT; //internal data + out_vector28 SIGOUT_INT; + + //declarations for PORT1 + in_vector28 SIGIN_PORT1; + out_vector28 SIGOUT_PORT1; + in WRITE_PORT1; //media is putting data into IBUF + out READ_PORT1; //media is reading data + out DATAREADY_PORT1; //media knows that I have somthing to offer + + + //declarations for PORT2 + in_vector28 SIGIN_PORT2; + out_vector28 SIGOUT_PORT2; + in WRITE_PORT2; //media is putting data into IBUF + out READ_PORT2; //media is reading data + out DATAREADY_PORT2; //media knows that I have somthing to offer + + + //this looks like a normal iobufcx + in READ_IN_INT; //Internal logic can read buffer + out READ_OUT_INT; //IOBUF is activating internal logic + out DATAREADY_OUT_INT; //means that data can be transferred + in DATAREADY_IN_INT; //from other IBUF (stream partner) + + in RESENDHEADER_IN_INT; //in-streaming have to resend header + out RESENDHEADER_OUT_INT; //internal logic has to resend header + + + + void NextCLK(void); + + void Dump(void); + + IOBUFCX myiobuf_port1, myiobuf_port2; + + private: + unsigned int read_pointer, next_read_pointer; + unsigned int mystate, nextstate; +}; + +#endif diff --git a/iobufcx.cc b/iobufcx.cc index 79537fe..a5e2991 100644 --- a/iobufcx.cc +++ b/iobufcx.cc @@ -14,6 +14,8 @@ void IOBUFCX::Logic(void){ myibuf.READ = READ_IN_INT; myibuf.RESENDHEADER = RESENDHEADER_IN_INT; DATAREADY_OUT_INT = myibuf.DATAREADY; + SIGOUT_INT = myibuf.SIGOUT; + FREE_FOR_OUT_TRANSFER = myobuf.FREE_FOR_TRANSFER; //connect to media diff --git a/iobufcx.h b/iobufcx.h index 2523877..4dc1ef5 100644 --- a/iobufcx.h +++ b/iobufcx.h @@ -12,7 +12,7 @@ // //hardcoded, later to be made with LSYNC -#define MAX_WORD 3 +#define MAX_WORD 32 #define MAX_BLOCKS 2 class IOBUFCX { @@ -43,6 +43,7 @@ class IOBUFCX { out READ; //media is reading data out DATAREADY; //media knows that I have somthing to offer + out FREE_FOR_OUT_TRANSFER; //OBUF is transparent, and has no internal data void NextCLK(void); diff --git a/obufcx.cc b/obufcx.cc index 97f6a0f..ea21a9c 100644 --- a/obufcx.cc +++ b/obufcx.cc @@ -13,6 +13,7 @@ void OBUFCX::Logic(void){ DATAREADY = 1; READ_OUT = 0; CLEAR_OUT = 0; + FREE_FOR_TRANSFER = 0; //block the fan-out } else { //simply forward what I got @@ -21,6 +22,7 @@ void OBUFCX::Logic(void){ DATAREADY = DATAREADY_IN; READ_OUT = READ; CLEAR_OUT = 0; + FREE_FOR_TRANSFER = 1; } } else if (mystate==OBUF_CLEARMODE) { //simply forward what I got @@ -29,6 +31,7 @@ void OBUFCX::Logic(void){ DATAREADY = DATAREADY_IN; READ_OUT = READ; CLEAR_OUT = 1; //In addition, clear my partner + FREE_FOR_TRANSFER = 1; //I'm free to transfer now } }; diff --git a/obufcx.h b/obufcx.h index 8dab8e1..42339b8 100644 --- a/obufcx.h +++ b/obufcx.h @@ -27,6 +27,7 @@ class OBUFCX { in DATAREADY_IN; //from other IBUF (stream partner) out READ_OUT; //read from other IBUF (stream partner) out CLEAR_OUT; //clear my direct partner + out FREE_FOR_TRANSFER; void NextCLK(void); -- 2.43.0