]> jspc29.x-matter.uni-frankfurt.de Git - trbnet.git/commitdiff
iobuf and ACK creation working, Ingo
authorhades <hades>
Fri, 10 Mar 2006 13:17:42 +0000 (13:17 +0000)
committerhades <hades>
Fri, 10 Mar 2006 13:17:42 +0000 (13:17 +0000)
Makefile
basic.h
hubtest.cc
ibufcx.cc [new file with mode: 0644]
ibufcx.h [new file with mode: 0644]
iobufcx.cc [new file with mode: 0644]
iobufcx.h [new file with mode: 0644]
obufcx.cc [new file with mode: 0644]
obufcx.h [new file with mode: 0644]

index 366263c4e0825d755c33b348553a6fee183129f0..85b3f03fdae1f680e006c80b0ced469e4ee4fc33 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
 .SUFFIXES: .cc
 
-OBJS            = bufcx.o hubtest.o
+OBJS            = ibufcx.o obufcx.o iobufcx.o hubtest.o basic.o
 
 CXX           = g++
 CXXFLAGS      = -g -O3 -Wall -fPIC
diff --git a/basic.h b/basic.h
index 457c200f60f6b3f0343220c7b45d4bacc2571b37..d2c6de596063ae4ec8748b8fca93afd0db5bf4c4 100644 (file)
--- a/basic.h
+++ b/basic.h
@@ -40,6 +40,11 @@ using namespace std;
 
 #define ERRORMODE   7
 
+#define OBUF_FREEMODE         1
+#define OBUF_CLEARMODE        2
+#define OBUF_WAITINGMODE      3
+
+
 #define STATUSBITS    24,26
 #define HEADER_HEADER 0x0
 #define HEADER_TERM   0x1
@@ -52,59 +57,19 @@ using namespace std;
 
 class STD_LOGIC_ARRAY {
  public:
-    STD_LOGIC_ARRAY(int mysize) {
-       cont= new int[mysize];
-       size=mysize;
-    };
-    STD_LOGIC_ARRAY() {
-       size=0;
-    }
-
-    unsigned int get_value(int a, int b) {
-       unsigned int bla=0;
-
-       for (int i=a,j=1;i<=b;i++,j*=2) {
-           //cout << "cont" << cont[i] << endl;
-           if (cont[i]==1) bla+=j;
-       }
-       return bla;
-    };
-
-    //void operator=(const unsigned int & bla){
-//     for (int i=0;i<size;i++)
-//         cont[i]=bla;
-//    };
-
-    void set(unsigned int bla) {
-       unsigned int val = (unsigned int) pow(2.,size-1);
-       for (int i=(size-1);i>=0;i--) {
-           if (bla >= val) {
-               bla -= val;
-               cont[i]=1;
-               //cout << 1;
-           } else {
-               cont[i]=0;
-               //cout << 0;
-           }
-           //cout << endl;
-           val /=2;
-       }
-
-    }
-
-    void operator=(const STD_LOGIC_ARRAY & other){
-       for (int i=0;i<size;i++)
-           cont[i]=other.cont[i];
-    };
+    STD_LOGIC_ARRAY(int mysize);
+
+    STD_LOGIC_ARRAY();
+
+    unsigned int get_value(int a, int b);
+    void set(unsigned int bla);
+
+    void operator=(const STD_LOGIC_ARRAY & other);
     
-    int operator()(int ar) const {
-       return cont[ar];
-    };
+    int operator()(int ar) const;
+
+    int & operator()(int ar);
 
-    int & operator()(int ar) {
-       return cont[ar];
-    };
 
  protected:
     
@@ -114,18 +79,12 @@ class STD_LOGIC_ARRAY {
 
 class vector28 : public STD_LOGIC_ARRAY {
  public:
-    vector28(){
-       cont= new int[28];
-       size=28;
-    };
+    vector28();
 };
 
 class vector8 : public STD_LOGIC_ARRAY {
  public:
-    vector8(){
-       cont= new int[28];
-       size=8;
-    };
+    vector8();
 };
 
 //
@@ -134,11 +93,11 @@ class vector8 : public STD_LOGIC_ARRAY {
 
 class FLIPFLOP {
 public:
-    FLIPFLOP() {RESET();};
+    FLIPFLOP();
     in SIGIN;
     out SIGOUT;
-    void RESET() {SIGIN=SIGOUT=0;};
-    void NextCLK(void){SIGOUT=SIGIN;};
+    void RESET(void); 
+    void NextCLK(void);
 };
 
 //
@@ -146,17 +105,12 @@ public:
 //
 class REG28 {
 public:
-    REG28() {RESET();};
+    REG28();
     in_vector28 SIGIN;
     in WRITE;
     out_vector28 SIGOUT;
-    void RESET() {
-       for (int i=0; i<28; i++) (SIGIN(i))=(SIGOUT(i))=0;
-    };
-    void NextCLK(void) {
-       for (int i=0; i<28; i++) 
-           if (WRITE) (SIGOUT(i))=(SIGIN(i));
-    };
+    void RESET(void);
+    void NextCLK(void);
     void Logic(void){};
 };
 
@@ -165,17 +119,11 @@ public:
 //
 class COUNTER8 {
 public:
-    COUNTER8() {RESET();};
+    COUNTER8();
     out_vector8 SIGOUT;
-    void RESET() {
-       for (int i=0; i<8; i++) 
-           (SIGOUT(i))=0;counter=0;
-    };
-    void NextCLK(void){
-       counter++; 
-       for (int i=0; i<8; i++) 
-           (SIGOUT(i))=((counter << i) & 0x1);
-    };
+    void RESET(void);
+    void NextCLK(void);
+    void Logic(void){};
  private:
     unsigned int counter;
 };
@@ -188,61 +136,21 @@ public:
 // BUGBUG fifo full missing
 // This would be an error condition
 //
-// Special feature: If fifo is emtpy, output is input
+
 class FIFO28 {
 public:
-    FIFO28(int mydepth) {
-       RESET();
-       depth=mydepth;
-       regarray = new REG28[depth];
-    };
-    
-    void RESET() {
-       counter=WRITE=READ=0;
-       pointer_write=pointer_read=0;
-       EMPTY=1;
-    };
+    FIFO28(int mydepth);
+    void RESET();
     
     in WRITE,READ;
     out EMPTY;
     in_vector28 SIGIN;
     out_vector28 SIGOUT;
     
-    void Logic(void){
-       regarray[pointer_write].WRITE=WRITE;
-       if (counter) EMPTY=0; else EMPTY=1;
-       for (int i=0;i<28;i++) {
-           (regarray[pointer_write].SIGIN(i))=(SIGIN(i));
-           (SIGOUT(i))=(regarray[pointer_read].SIGOUT(i));
-       }       
-
-       //cout << pointer_write << ":" << pointer_read << ":" << SIGIN.get_value(0,27)  << endl;
-
-    }
+    void Logic(void);
     
-    void NextCLK(void){
-
-       for (unsigned int i=0;i<depth;i++) regarray[i].NextCLK();
-       
-       //cout << pointer_write << ":" << pointer_read << ":" << SIGIN.get_value(0,27)  << endl;
-       //cout << regarray[pointer_write].SIGIN.get_value(0,27) << ":" << regarray[pointer_read].SIGOUT.get_value(0,27) << endl;
-       if (WRITE) {            
-           counter++;
-           //cout << "ac=" << counter << endl;
-           pointer_write++;
-           if (pointer_write == depth) pointer_write=0;
-       }
-       if (READ && !EMPTY) {
-           counter--;  
-           //cout << "ec=" << counter << endl;
-           pointer_read++;
-           if (pointer_read == depth) pointer_read=0;
-       }
-
-
-       
-
-    }
+    void NextCLK(void);
+
  private:
     unsigned int counter, depth;
     unsigned int pointer_write,pointer_read;
index 992644312752eb2ad284b5a44f79c8c8f5573a60..bcc1c2338cb63d8a6fb90838c4516b11c9229e94 100644 (file)
@@ -1,8 +1,8 @@
-#include "bufcx.h"
+#include "iobufcx.h"
 
-int main(void) {
+int acktest(void) {
 
-    IBUFCX buf;
+    IOBUFCX buf;
 
     for (int i=0; i<10; i++) {
         
@@ -18,29 +18,45 @@ int main(void) {
        }
        else if (i==2) { 
            buf.WRITE=1;
-           buf.SIGIN.set(0x01000000u); // term word
+           //buf.SIGIN.set(0x01000000u); // term word
+           buf.SIGIN.set(0x02000000u); // EOB word
        } 
        
 
        else buf.WRITE=0; 
 
        if (i==2) 
-           buf.READ=1;
+           buf.READ_IN_INT=1;
        else if (i==4) 
-           buf.READ=1;
-       else if (i==6) 
-           buf.READ=1;
-       else buf.READ=0;
-
+           buf.READ_IN_INT=1;
+       else buf.READ_IN_INT=0;
 
+       if (i==7)
+           buf.READ=1;
+       else
+           buf.READ=0;
+       
 
        for (int l=0;l<100;l++) buf.Logic();
 
-       buf.Dump();
+       //
+       cout << "SIGOUT " << std::hex << buf.SIGOUT.get_value(0,27) << endl;
+
+       buf.myibuf.Dump();
+       //buf.myobuf.Dump();
        //asign CLK
        buf.NextCLK();
        cout << "next CLK" << endl;
     }
 
 
+}
+
+
+void main(void) {
+
+    //acktest();
+
+
+
 }
diff --git a/ibufcx.cc b/ibufcx.cc
new file mode 100644 (file)
index 0000000..25d1489
--- /dev/null
+++ b/ibufcx.cc
@@ -0,0 +1,139 @@
+#include "ibufcx.h"
+
+
+void IBUFCX::Logic(void){
+    STATEOUT=mystate;     //forward internal state to outer world
+    header.SIGIN = SIGIN; //input lines for the header
+    SIGOUT = buffer->SIGOUT;
+    buffer->SIGIN = SIGIN;
+
+    if (WRITE == 1) { //BUGBUG check if fifo is not full
+       buffer->WRITE = 1;
+    } else{ //BUGBUG check if fifo is not full
+       buffer->WRITE = 0;
+    }
+       
+    if ((!(buffer->EMPTY))) { //BUFFER has data 
+       if (mystate==FREEMODE) {            
+           if (buffer->SIGOUT.get_value(STATUSBITS) == HEADER_HEADER) {  //word to be read is a header
+               buffer->READ =  READ;  //yes, read header
+               header.WRITE =  1;  
+               headerterm.WRITE =  0;
+               DATAREADY = 1;
+               if (READ)
+                   nextstate = TRANSFERMODE;
+               else
+                   nextstate = FREEMODE;
+           } else if (buffer->SIGOUT.get_value(STATUSBITS) == HEADER_TERM) { //TERM transfer
+               buffer->READ =  1;  //clean TERM
+               header.WRITE =  0; 
+               headerterm.WRITE =  1;  //
+               DATAREADY = 0;
+               if (READ)
+                   nextstate = TERMMODE;
+               else
+                   nextstate = FREEMODE;
+           } else  { //something is wrong...first word MUST be header or TERM
+               buffer->READ =  1;  //clean wrong word
+               header.WRITE =  0; 
+               headerterm.WRITE =  0;  
+               DATAREADY = 0;
+               nextstate = ERRORMODE;
+           }       
+       } //FREEMODE
+       else if (mystate==TRANSFERMODE) {
+           if (buffer->SIGOUT.get_value(STATUSBITS) == HEADER_HEADER) {  //word to be read is a header
+               buffer->READ =  READ;  //yes, read header
+               //cout << "a" << endl;
+               header.WRITE =  1;  
+               headerterm.WRITE =  0;
+               DATAREADY = 1;
+               nextstate = TRANSFERMODE;
+           } else if (buffer->SIGOUT.get_value(STATUSBITS) == HEADER_TERM) { //TERM transfer
+               //cout << buffer->SIGOUT.get_value(STATUSBITS) << endl;
+               buffer->READ =  1;  //clean TERM
+               header.WRITE =  0; 
+               headerterm.WRITE =  1;  //
+               DATAREADY = 0;
+               nextstate = TERMMODE;
+           } else if (buffer->SIGOUT.get_value(STATUSBITS) == HEADER_BUF) { //ask for new buffer
+               buffer->READ =  1;  //clean TERM
+               header.WRITE =  0; 
+               headerterm.WRITE =  0;  //I do not keep BUF header?
+               DATAREADY = 0;
+               nextstate = WAITINGMODE;
+           } else if (buffer->SIGOUT.get_value(STATUSBITS) == HEADER_DATA) {
+               buffer->READ =  READ;  
+               header.WRITE =  0; 
+               headerterm.WRITE =  0;  
+               DATAREADY = 1;
+               nextstate = TRANSFERMODE;
+           }
+       }//TRANSFER
+       else if ((mystate==TERMMODE) || (mystate==WAITINGMODE)) {  //after TERM, wait for CLEAR
+           buffer->READ =  0;  
+           header.WRITE =  0; 
+           headerterm.WRITE =  0;  //I do not keep BUF header?
+           DATAREADY = 0;
+           if (CLEAR)
+               nextstate = FREEMODE;
+           else
+               nextstate = mystate;
+       }
+    } // BUFFER is not EMPTY
+    else { //BUFFER IS EMPTY
+       if (mystate==FREEMODE) {            
+           buffer->READ =  0;
+           header.WRITE =  0;  
+           headerterm.WRITE =  0;
+           DATAREADY = 0;
+           nextstate = FREEMODE;
+       } else if (mystate==TRANSFERMODE) {         
+           buffer->READ =  0;
+           header.WRITE =  0;  
+           headerterm.WRITE =  0;
+           DATAREADY = 0;
+           nextstate = TRANSFERMODE;
+       } else if (mystate==WAITINGMODE) {          
+           buffer->READ =  0;
+           header.WRITE =  0;  
+           headerterm.WRITE =  0;
+           DATAREADY = 0;
+           if (CLEAR) 
+               nextstate = FREEMODE;
+           else
+               nextstate = WAITINGMODE;
+       } else if (mystate==TERMMODE) {     
+           buffer->READ =  0;
+           header.WRITE =  0;  
+           headerterm.WRITE =  0;
+           DATAREADY = 0;
+           if (CLEAR) 
+               nextstate = FREEMODE;
+           else
+               nextstate = TERMMODE;
+       }
+    }
+
+
+    buffer->Logic();
+    header.Logic();
+    headerterm.Logic();
+};
+
+void IBUFCX::NextCLK(void){
+    mystate = nextstate;
+    buffer->NextCLK();
+    header.NextCLK();
+    headerterm.NextCLK();
+}
+
+
+void IBUFCX::Dump(void) {
+    
+    cout << "W=" << WRITE << " R=" << READ << " DR=" << DATAREADY << " st=" << mystate 
+        << " EMP=" <<  buffer->EMPTY
+        << " buf=" << std::hex <<  buffer->SIGOUT.get_value(0,27)
+       
+        << endl;
+}
diff --git a/ibufcx.h b/ibufcx.h
new file mode 100644 (file)
index 0000000..4a51f9d
--- /dev/null
+++ b/ibufcx.h
@@ -0,0 +1,47 @@
+#ifndef BUFCX
+#define BUFCX
+
+
+#include "basic.h"
+
+//
+// input buffer for ONE channel and ONE port
+//
+
+
+class IBUFCX {
+public:
+    IBUFCX() {RESET();};
+    void RESET() {
+       buffer = new FIFO28(16);
+       buffer->RESET();
+       WRITE=READ=DATAREADY=CLEAR=0;
+       mystate=FREEMODE;
+    };
+    in WRITE,READ,RESENDHEADER,CLEAR;
+    out DATAREADY; //means that data can be transferred
+    //   out TERM;  //TERM header arrived
+    //   out BUFFEREND;  //ACK cycle has to be done
+
+    void Logic(void);
+    
+    in STATEIN;
+    out STATEOUT;
+    in_vector28 SIGIN;
+    out_vector28 SIGOUT,HEADER,TERMHEADER;
+
+
+    void NextCLK(void);
+    
+    void Dump(void);
+    
+
+    FIFO28 * buffer;
+ private:
+
+    state mystate, nextstate;
+    REG28 header, headerterm;
+
+};
+
+#endif
diff --git a/iobufcx.cc b/iobufcx.cc
new file mode 100644 (file)
index 0000000..f5a316f
--- /dev/null
@@ -0,0 +1,40 @@
+#include "iobufcx.h"
+
+
+void IOBUFCX::Logic(void){
+
+    //connect ibuf to obuf direct partner
+    myobuf.IBUF_STATEIN = myibuf.STATEOUT;
+    myibuf.CLEAR = myobuf.CLEAR_OUT;
+
+    //connect obuf to streaming partner
+    myobuf.SIGIN = SIGIN_INT;
+    myobuf.DATAREADY_IN = DATAREADY_IN_INT;
+    READ_OUT_INT = myobuf.READ_OUT;
+    myibuf.READ  = READ_IN_INT;
+    myibuf.RESENDHEADER = RESENDHEADER_IN_INT;
+    DATAREADY_OUT_INT = myibuf.DATAREADY;
+    
+
+    //connect to media
+    SIGOUT = myobuf.SIGOUT;
+    myibuf.SIGIN = SIGIN;
+    myobuf.READ = READ;
+    DATAREADY = myobuf.DATAREADY;
+    myibuf.WRITE = WRITE;
+
+
+    myibuf.Logic();
+    myobuf.Logic();
+    
+};
+
+void IOBUFCX::NextCLK(void){
+    myibuf.NextCLK();
+    myobuf.NextCLK();
+}
+
+
+void IOBUFCX::Dump(void) {
+
+}
diff --git a/iobufcx.h b/iobufcx.h
new file mode 100644 (file)
index 0000000..2ec451d
--- /dev/null
+++ b/iobufcx.h
@@ -0,0 +1,54 @@
+#ifndef IOBUFCX_H
+#define IOBUFCX_H
+
+
+
+#include "basic.h"
+#include "ibufcx.h"
+#include "obufcx.h"
+
+//
+// output buffer for ONE channel and ONE port
+//
+
+
+class IOBUFCX {
+ public:
+    IOBUFCX() {RESET();};
+    void RESET() {
+    };
+
+    void Logic(void);
+    
+    in_vector28 SIGIN_INT;  //internal data
+    out_vector28 SIGOUT_INT;
+
+    in_vector28 SIGIN;
+    out_vector28 SIGOUT;
+
+    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)
+    out READ_OUT;  //read from other IBUF (stream partner)
+    
+    in RESENDHEADER_IN_INT; //in-streaming have to resend header
+    in WRITE;               //media is putting data into IBUF
+    out READ;               //media is reading data
+    out DATAREADY;          //media knows that I have somthing to offer
+    
+
+    void NextCLK(void);
+    
+    void Dump(void);
+    
+    IBUFCX myibuf;
+    OBUFCX myobuf;
+
+
+ private:
+
+
+};
+
+#endif
diff --git a/obufcx.cc b/obufcx.cc
new file mode 100644 (file)
index 0000000..1db71db
--- /dev/null
+++ b/obufcx.cc
@@ -0,0 +1,43 @@
+#include "obufcx.h"
+
+
+void OBUFCX::Logic(void){
+    if ((mystate==OBUF_FREEMODE) || (mystate==OBUF_WAITINGMODE)) {
+       if (IBUF_STATEIN == WAITINGMODE) {
+           //partner has got EOB and we should send an ACK         
+           SIGOUT.set(HEADER_TERM << 24);  //prepare ACK
+           if (READ) 
+               nextstate = OBUF_CLEARMODE;
+           else 
+               nextstate = OBUF_WAITINGMODE;
+           DATAREADY = 1;
+           READ_OUT =  0;
+           CLEAR_OUT = 0;
+       }
+       else {
+           //simply forward what I got
+           SIGOUT = SIGIN;
+           nextstate = OBUF_FREEMODE;
+           DATAREADY = DATAREADY_IN;
+           READ_OUT = READ;
+           CLEAR_OUT = 0;
+       }
+    } else if (mystate==OBUF_CLEARMODE) {
+       //simply forward what I got
+       SIGOUT = SIGIN;
+       nextstate = OBUF_FREEMODE;
+       DATAREADY = DATAREADY_IN;
+       READ_OUT = READ;
+       CLEAR_OUT = 1; //In addition, clear my partner
+    }
+
+};
+
+void OBUFCX::NextCLK(void){
+    mystate = nextstate;
+}
+
+
+void OBUFCX::Dump(void) {
+    cout << "ST: " << mystate << " R " << READ << " DR "<< DATAREADY << endl;
+}
diff --git a/obufcx.h b/obufcx.h
new file mode 100644 (file)
index 0000000..8dab8e1
--- /dev/null
+++ b/obufcx.h
@@ -0,0 +1,39 @@
+#ifndef OBUFCX_H
+#define OBUFCX_H
+
+
+#include "basic.h"
+
+//
+// output buffer for ONE channel and ONE port
+//
+
+
+class OBUFCX {
+ public:
+    OBUFCX() {RESET();};
+    void RESET() {
+       mystate=OBUF_FREEMODE;
+       READ=DATAREADY=READ_OUT=CLEAR_OUT=0;
+    };
+
+    void Logic(void);
+    
+    in IBUF_STATEIN;  //I have to know what my partner is doing
+    in_vector28 SIGIN;
+    out_vector28 SIGOUT;
+    in READ;
+    out DATAREADY; //means that data can be transferred
+    in  DATAREADY_IN;   //from other IBUF (stream partner)
+    out READ_OUT;  //read from other IBUF (stream partner)
+    out CLEAR_OUT;     //clear my direct partner
+
+    void NextCLK(void);
+    
+    void Dump(void);
+    
+ private:
+    state mystate, nextstate;
+};
+
+#endif