cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
fmc.cpp
Go to the documentation of this file.
1 
17 
30 #include <stdio.h>
31 #include <stdint.h>
32 #include <assert.h>
33 #include "ap_int.h"
34 #include "ap_utils.h"
35 
36 #include "fmc.hpp"
37 #include "http.hpp"
38 
39 ap_uint<8> writeErrCnt = 0;
40 ap_uint<8> fifoEmptyCnt = 0;
41 ap_uint<8> fifoFullCnt = 0;
42 ap_uint<4> xmem_page_trans_cnt = 0xF;
43 
44 stream<uint8_t> internal_icap_fifo ("sInternalIcapFifo");
45 stream<uint8_t> icap_hangover_fifo ("sIcapHangoverFifo");
51 
53 uint32_t bufferInPtrWrite = 0x0;
54 uint32_t bufferInPtrMaxWrite = 0x0;
56 uint32_t bufferInPtrNextRead = 0x0;
57 bool tcp_write_only_fifo = false;
58 
60 uint16_t bufferOutPtrWrite = 0x0;
61 uint16_t bufferOutContentLength = 0x0;
62 uint16_t bufferOutPtrNextRead = 0x0;
64 
65 
66 #ifndef __SYNTHESIS__
67 bool use_sequential_hwicap = false;
69 #endif
70 
71 static char* httpNL = "\r\n";
73 
74 ap_uint<32> Display1 = 0, Display2 = 0, Display3 = 0, Display4 = 0, Display5 = 0, Display6 = 0, Display7 = 0, Display8 = 0, Display9 = 0;
75 ap_uint<28> wordsWrittenToIcapCnt = 0;
76 ap_uint<28> tcp_words_received = 0;
77 
78 ap_uint<32> nodeRank = 0;
79 ap_uint<32> clusterSize = 0;
80 
81 ap_uint<1> toDecoup_persistent = 0;
82 
83 ap_uint<8> nal_status_request_cnt = 0;
85 bool nal_status_disabled = false;
86 
89 //bool ctrl_link_transfer_ongoing = false;
90 ap_uint<32> mrt_copy_index = 0;
91 
92 
93 ap_uint<16> current_role_mmio = 0;
94 
95 ap_uint<32> fpga_time_seconds = 0;
96 ap_uint<32> fpga_time_minutes = 0;
97 ap_uint<32> fpga_time_hours = 0;
98 
99 ap_uint<16> nts_udp_drop_cnt = 0;
100 ap_uint<8> nts_tcp_notif_drop_cnt = 0;
101 ap_uint<8> nts_tcp_meta_drop_cnt = 0;
102 ap_uint<8> nts_tcp_data_drop_cnt = 0;
103 ap_uint<8> nts_tcp_crc_drop_cnt = 0;
104 ap_uint<8> nts_tcp_sess_drop_cnt = 0;
105 ap_uint<8> nts_tcp_ooo_drop_cnt = 0;
106 
107 ap_uint<7> lastResponsePageCnt = 0;
108 ap_uint<4> responePageCnt = 0; //for Display 4
109 
110 //persistent states...
112 //bool ongoingTransfer_persistent = false;
116 //bool failedPR_persistent = false;
117 //bool swapBytes_persistent = false;
121 
124 ap_uint<1> tcpModeEnabled = 0;
126 //bool tcp_rx_blocked_by_processing = false;
127 
128 //flags
129 ap_uint<1> flag_check_xmem_pattern = 0;
130 ap_uint<1> flag_silent_skip = 0;
132 ap_uint<1> flag_continuous_tcp_rx = 0;
133 ap_uint<1> flag_enable_fake_hwicap = 0;
134 
135 //TCP FSMs
143 
144 //EOF detection
145 uint8_t last_3_chars[3];
146 ap_uint<2> detected_http_nl_cnt = 0;
147 ap_uint<2> target_http_nl_cnt = 0;
149 
150 //TCP hangover
154 
155 //NRC "Backup"
156 bool tables_initialized = false;
159 ap_uint<32> current_nrc_mrt_version = 0;
163 ap_uint<32> max_discovered_node_id = 0;
164 
165 
166 
167 
168 
169 uint8_t bytesToPages(int len, bool update_global_variables)
170 {
171  printf("bytesToPages: len %d\n",len);
172 
173  uint8_t pageCnt = len/BYTES_PER_PAGE;
174 
175  if(update_global_variables)
176  {
178  printf("lastResponsePageCnt: %d\n", (int) lastResponsePageCnt);
179  }
180 
181  //we need to ceil the page count (if lastResponsePageCnt != 0....)
182  if(len % BYTES_PER_PAGE > 0)
183  {
184  pageCnt++;
185  }
186 
187  if(update_global_variables)
188  { // for Display4
189  responePageCnt = pageCnt;
190  printf("responePageCnt: %d\n", (int) responePageCnt);
191  }
192 
193  assert(pageCnt <= MAX_PAGES);
194 
195  return pageCnt;
196 
197 }
198 
199 
200 //void copyOutBuffer(ap_uint<4> numberOfPages, ap_uint<32> xmem[XMEM_SIZE], ap_uint<1> notToSwap)
201 void copyOutBuffer(ap_uint<4> numberOfPages, ap_uint<32> xmem[XMEM_SIZE])
202 {
203  for(int i = 0; i < numberOfPages*LINES_PER_PAGE; i++)
204  {
205  ap_uint<32> tmp = 0;
206 
207  tmp = ((ap_uint<32>) bufferOut[i*4 + 0]);
208  tmp |= ((ap_uint<32>) bufferOut[i*4 + 1]) << 8;
209  tmp |= ((ap_uint<32>) bufferOut[i*4 + 2]) << 16;
210  tmp |= ((ap_uint<32>) bufferOut[i*4 + 3]) << 24;
211  xmem[XMEM_ANSWER_START + i] = tmp;
212  }
213 
214 }
215 
216 
218 {
219  for(int i = 0; i < IN_BUFFER_SIZE; i++)
220  {
221 //#pragma HLS unroll
222  bufferIn[i] = 0x0;
223  }
224  bufferInPtrWrite = 0x0;
225  bufferInPtrNextRead = 0x0;
226  bufferInPtrMaxWrite = 0x0;
228  hwicap_hangover_present = false;
230  for(int i = 0; i < 3; i++)
231  {
232 #pragma HLS unroll
233  buffer_hangover_bytes[i] = 0x0;
234  }
235  while(!internal_icap_fifo.empty())
236  {
237  internal_icap_fifo.read();
238  }
239  while(!icap_hangover_fifo.empty())
240  {
241  icap_hangover_fifo.read();
242  }
243  tcp_write_only_fifo = false;
246  for(int i = 0; i<8; i++)
247  {
248  fifo_overflow_buffer[i] = 0x0;
249  }
252  printf("\t inBuffer cleaned\n");
253 }
254 
256 {
257  for(int i = 0; i < OUT_BUFFER_SIZE; i++)
258  {
259 //#pragma HLS unroll
260  bufferOut[i] = 0x0;
261  }
262  bufferOutPtrWrite = 0x0;
264  bufferOutPtrNextRead = 0x0;
266  printf("\t outBuffer cleaned\n");
267 }
268 
269 
271 {
272  uint32_t len = 0;
273  //Display1
274  len = writeString("Status Display 1: ");
275  len += writeUnsignedLong((uint32_t) Display1, 16);
276  bufferOut[bufferOutPtrWrite + 0] = '\r';
277  bufferOut[bufferOutPtrWrite + 1] = '\n';
278  bufferOutPtrWrite += 2;
279  len += 2;
280 
281  //Display2
282  len += writeString("Status Display 2: ");
283  len += writeUnsignedLong((uint32_t) Display2, 16);
284  bufferOut[bufferOutPtrWrite + 0] = '\r';
285  bufferOut[bufferOutPtrWrite + 1] = '\n';
286  bufferOutPtrWrite += 2;
287  len += 2;
288 
289  //Display 3 & 4 is less informative outside EMIF Context
290 
291  //insert rank and size
292  len += writeString("Rank: ");
293  len += writeUnsignedLong(nodeRank, 10);
294  bufferOut[bufferOutPtrWrite + 0] = '\r';
295  bufferOut[bufferOutPtrWrite + 1] = '\n';
296  bufferOutPtrWrite += 2;
297  len += 2;
298 
299  len += writeString("Size: ");
300  len += writeUnsignedLong(clusterSize, 10);
301  bufferOut[bufferOutPtrWrite + 0] = '\r';
302  bufferOut[bufferOutPtrWrite + 1] = '\n';
303  bufferOutPtrWrite += 2;
304  len += 2;
305 
306  //NRC status
307  len += writeString("NAL Status (16 lines): \r\n"); //NAL_NUMBER_STATUS_WORDS
308 
309  for(int i = 0; i<NAL_NUMBER_STATUS_WORDS; i++)
310  {
311  if(i<=9)
312  {
313  bufferOut[bufferOutPtrWrite] = '0' + i; //poor mans ascii cast
314  } else {
317  len++;
318  bufferOut[bufferOutPtrWrite] = '0' + (i-10);
319  }
321  len++;
322  len+=writeString(": ");
323  if( nal_status_disabled )
324  {
325  bufferOut[bufferOutPtrWrite + 3] = nal_status[i] & 0xFF;
326  bufferOut[bufferOutPtrWrite + 2] = (nal_status[i] >> 8) & 0xFF;
327  bufferOut[bufferOutPtrWrite + 1] = (nal_status[i] >> 16) & 0xFF;
328  bufferOut[bufferOutPtrWrite + 0] = (nal_status[i] >> 24) & 0xFF;
329  bufferOut[bufferOutPtrWrite + 4] = '\r';
330  bufferOut[bufferOutPtrWrite + 5] = '\n';
331  bufferOutPtrWrite += 6;
332  len += 6;
333  } else {
334  len += writeUnsignedLong((uint32_t) nal_status[i], 16);
335  bufferOut[bufferOutPtrWrite + 0] = '\r';
336  bufferOut[bufferOutPtrWrite + 1] = '\n';
337  bufferOutPtrWrite += 2;
338  len += 2;
339  }
340  }
341 
342  //FPGA status
343  len += writeString("FPGA Status (8 lines): \r\n"); //NUMBER_FPGA_STATE_REGISTERS
344  for(int i = 0; i<NUMBER_FPGA_STATE_REGISTERS; i++)
345  {
346  if(i<=9)
347  {
348  bufferOut[bufferOutPtrWrite] = '0' + i; //poor mans ascii cast
349  } else {
352  len++;
353  bufferOut[bufferOutPtrWrite] = '0' + (i-10);
354  }
356  len++;
357  len+=writeString(": ");
358  //we have a bit size of 8
359  uint8_t val = fpga_status[i];
360  bufferOut[bufferOutPtrWrite] = (val > 9)? (val-10) + 'A' : val + '0'; //is only 8bit
361  bufferOut[bufferOutPtrWrite + 1] = '\r';
362  bufferOut[bufferOutPtrWrite + 2] = '\n';
363  bufferOutPtrWrite += 3;
364  len += 3;
365  }
366 
367  //print uptime
368  len += writeString("FPGA uptime: ");
369  bufferOut[bufferOutPtrWrite + 0] = '0' + (fpga_time_hours / 10);
370  bufferOut[bufferOutPtrWrite + 1] = '0' + (fpga_time_hours % 10);
371  bufferOut[bufferOutPtrWrite + 2] = ':';
372  bufferOutPtrWrite += 3;
373  len += 3;
374  bufferOut[bufferOutPtrWrite + 0] = '0' + (fpga_time_minutes / 10);
375  bufferOut[bufferOutPtrWrite + 1] = '0' + (fpga_time_minutes % 10);
376  bufferOut[bufferOutPtrWrite + 2] = ':';
377  bufferOutPtrWrite += 3;
378  len += 3;
379  bufferOut[bufferOutPtrWrite + 0] = '0' + (fpga_time_seconds / 10);
380  bufferOut[bufferOutPtrWrite + 1] = '0' + (fpga_time_seconds % 10);
381  bufferOut[bufferOutPtrWrite + 2] = '\r';
382  bufferOut[bufferOutPtrWrite + 3] = '\n';
383  bufferOutPtrWrite += 4;
384  len += 3;
385 
386  //print cFDK version
387  len += writeString("cFDK/FMC version: ");
389  bufferOut[bufferOutPtrWrite + 0] = '\r';
390  bufferOut[bufferOutPtrWrite + 1] = '\n';
391  bufferOutPtrWrite += 2;
392  len += 2;
393 
394  //print Role version vector
395  len += writeString("current ROLE version: ");
396  len += writeUnsignedLong((uint16_t) current_role_mmio, 16);
397  bufferOut[bufferOutPtrWrite + 0] = '\r';
398  bufferOut[bufferOutPtrWrite + 1] = '\n';
399  bufferOutPtrWrite += 2;
400  len += 2;
401 
402  //print NTS drop counts
403  len += writeString("UDP RX drop count: ");
404  len += writeUnsignedLong((uint16_t) nts_udp_drop_cnt, 16);
405  bufferOut[bufferOutPtrWrite + 0] = '\r';
406  bufferOut[bufferOutPtrWrite + 1] = '\n';
407  bufferOutPtrWrite += 2;
408  len += 2;
409  len += writeString("TCP RX notif drop count: ");
410  len += writeUnsignedLong((uint8_t) nts_tcp_notif_drop_cnt, 16);
411  bufferOut[bufferOutPtrWrite + 0] = '\r';
412  bufferOut[bufferOutPtrWrite + 1] = '\n';
413  bufferOutPtrWrite += 2;
414  len += 2;
415  len += writeString("TCP RX meta drop count: ");
416  len += writeUnsignedLong((uint8_t) nts_tcp_meta_drop_cnt, 16);
417  bufferOut[bufferOutPtrWrite + 0] = '\r';
418  bufferOut[bufferOutPtrWrite + 1] = '\n';
419  bufferOutPtrWrite += 2;
420  len += 2;
421  len += writeString("TCP RX data drop count: ");
422  len += writeUnsignedLong((uint8_t) nts_tcp_data_drop_cnt, 16);
423  bufferOut[bufferOutPtrWrite + 0] = '\r';
424  bufferOut[bufferOutPtrWrite + 1] = '\n';
425  bufferOutPtrWrite += 2;
426  len += 2;
427  len += writeString("TCP RX CRC drop count: ");
428  len += writeUnsignedLong((uint8_t) nts_tcp_crc_drop_cnt, 16);
429  bufferOut[bufferOutPtrWrite + 0] = '\r';
430  bufferOut[bufferOutPtrWrite + 1] = '\n';
431  bufferOutPtrWrite += 2;
432  len += 2;
433  len += writeString("TCP RX Session drop count: ");
434  len += writeUnsignedLong((uint8_t) nts_tcp_sess_drop_cnt, 16);
435  bufferOut[bufferOutPtrWrite + 0] = '\r';
436  bufferOut[bufferOutPtrWrite + 1] = '\n';
437  bufferOutPtrWrite += 2;
438  len += 2;
439  len += writeString("TCP RX Out-of-Order drop count: ");
440  len += writeUnsignedLong((uint8_t) nts_tcp_ooo_drop_cnt, 16);
441  bufferOut[bufferOutPtrWrite + 0] = '\r';
442  bufferOut[bufferOutPtrWrite + 1] = '\n';
443  bufferOutPtrWrite += 2;
444  len += 2;
445 
446 
447  len += writeString(httpNL);
448  return len;
449 }
450 
451 void setRank(ap_uint<32> newRank)
452 {
453  nodeRank = newRank;
455  //nothing else to do so far
456 }
457 
458 void setSize(ap_uint<32> newSize)
459 {
460  clusterSize = newSize;
461  //nothing else to do so far
462 }
463 
464 ap_uint<4> copyAndCheckBurst(ap_uint<32> xmem[XMEM_SIZE], ap_uint<4> ExpCnt, ap_uint<7> lastPageCnt_in)
465 {
466 
467  ap_uint<8> curHeader = 0;
468  ap_uint<8> curFooter = 0;
469 
470  ap_int<16> buff_pointer = 0-1;
471 
472 
473  for(int i = 0; i<LINES_PER_PAGE; i++)
474  {
475  ap_uint<32> tmp = 0;
476  tmp = xmem[i];
477 
478  if ( i == 0 )
479  {
480  curHeader = tmp & 0xff;
481  } else {
482  buff_pointer++;
483  bufferIn[bufferInPtrWrite + buff_pointer] = (tmp & 0xff);
484  }
485 
486  buff_pointer++;
487  bufferIn[bufferInPtrWrite + buff_pointer] = (tmp >> 8) & 0xff;
488  buff_pointer++;
489  bufferIn[bufferInPtrWrite + buff_pointer] = (tmp >> 16 ) & 0xff;
490 
491  if ( i == LINES_PER_PAGE-1)
492  {
493  curFooter = (tmp >> 24) & 0xff;
494  } else {
495  buff_pointer++;
496  bufferIn[bufferInPtrWrite + buff_pointer] = (tmp >> 24) & 0xff;
497  }
498  }
499 
500 
501  ap_uint<4> curCnt = curHeader & 0xf;
502 
503 
504  if ( curHeader != curFooter)
505  {//we are in the middle of a transfer!
506  return 1;
507  }
508 
509  if(curCnt == xmem_page_trans_cnt)
510  {//page was already transfered
511  return 0;
512  }
513 
514  if (curCnt != ExpCnt)
515  {//we must missed something
516  return 2;
517  }
518 
519  bool lastPage = (curHeader & 0xf0) == 0xf0;
520 
521  //now we have a clean transfer
522  if(lastPage && flag_check_xmem_pattern == 0)
523  { //we didn't received a full page;
524  bufferInPtrWrite += (lastPageCnt_in -1); //-1, because the address is 0 based!
525  printf("lastPageCnt_in %d\n", (int) lastPageCnt_in);
526  } else {
527  bufferInPtrWrite += buff_pointer;// +1;
528  }
531 
533  {
534  bufferInPtrWrite = 0;
535  }
536 
537  if(flag_check_xmem_pattern == 1)
538  {
539  ap_uint<8> ctrlByte = (((ap_uint<8>) ExpCnt) << 4) | ExpCnt;
540 
541  //printf("ctrlByte: %#010x\n",(int) ctrlByte);
542 
543  //for simplicity check only lines in between and skip potentiall hangover
544  for(int i = 3; i< PAYLOAD_BYTES_PER_PAGE -3; i++)
545  {
546  if(bufferIn[bufferInPtrNextRead + i] != ctrlByte)
547  {//data is corrupt
548  //printf("corrupt at %d with %#010x\n",i, (int) bufferIn[bufferInPtrWrite + i]);
549  return 3;
550  }
551  }
552  bufferInPtrNextRead = bufferInPtrWrite; //only for check pattern case
553  }
554 
555  if (lastPage)
556  {
557  return 4;
558  }
559 
560  return 5;
561 }
562 
563 
564 void fmc(
565  //EMIF Registers
566  ap_uint<32> *MMIO_in, ap_uint<32> *MMIO_out,
567  //state of the FPGA
568  ap_uint<1> *layer_4_enabled,
569  ap_uint<1> *layer_6_enabled,
570  ap_uint<1> *layer_7_enabled,
571  ap_uint<1> *nts_ready,
572  //get FPGA time
573  ap_uint<32> *in_time_seconds,
574  ap_uint<32> *in_time_minutes,
575  ap_uint<32> *in_time_hours,
576  //get ROLE version
577  ap_uint<16> *role_mmio_in,
578  //get UOE drop count
579  ap_uint<16> *uoe_drop_cnt_in,
580  //get TOE drop counts
581  ap_uint<8> *toe_notif_drop_cnt_in,
582  ap_uint<8> *toe_meta_drop_cnt_in,
583  ap_uint<8> *toe_data_drop_cnt_in,
584  ap_uint<8> *toe_crc_drop_cnt_in,
585  ap_uint<8> *toe_sess_drop_cnt_in,
586  ap_uint<8> *toe_ooo_drop_cnt_in,
587  //HWICAP and DECOUPLING
588  ap_uint<32> *HWICAP, ap_uint<1> decoupStatus, ap_uint<1> *setDecoup,
589  // Soft Reset
590  ap_uint<1> *setSoftReset,
591  //XMEM
592  ap_uint<32> xmem[XMEM_SIZE],
593  //NRC
594  ap_uint<32> nalCtrl[NAL_CTRL_LINK_SIZE],
595  ap_uint<1> *disable_ctrl_link,
596  stream<TcpWord> &siNAL_Tcp_data,
597  stream<AppMeta> &siNAL_Tcp_SessId,
598  stream<TcpWord> &soNAL_Tcp_data,
599  stream<AppMeta> &soNAL_Tcp_SessId,
600 #ifdef INCLUDE_PYROLINK
601  //Pyrolink
602  stream<Axis<8> > &soPYROLINK,
603  stream<Axis<8> > &siPYROLINK,
604  ap_uint<1> *disable_pyro_link,
605 #endif
606  //TO ROLE
607  ap_uint<32> *role_rank, ap_uint<32> *cluster_size)
608 {
609 //#pragma HLS RESOURCE variable=bufferIn core=RAM_2P_BRAM
610 //#pragma HLS RESOURCE variable=bufferIn core=RAM_S2P_LUTRAM
611 //#pragma HLS RESOURCE variable=bufferOut core=RAM_2P_BRAM
612 #pragma HLS RESOURCE variable=xmem core=RAM_1P_BRAM
613 #pragma HLS INTERFACE m_axi depth=512 port=HWICAP bundle=boHWICAP
614 #pragma HLS INTERFACE ap_ovld register port=MMIO_out name=poMMIO
615 #pragma HLS INTERFACE ap_vld register port=MMIO_in name=piMMIO
616 #pragma HLS INTERFACE ap_vld register port=layer_4_enabled name=piLayer4enabled
617 #pragma HLS INTERFACE ap_vld register port=layer_6_enabled name=piLayer6enabled
618 #pragma HLS INTERFACE ap_vld register port=layer_7_enabled name=piLayer7enabled
619 #pragma HLS INTERFACE ap_vld register port=nts_ready name=piNTS_ready
620 #pragma HLS INTERFACE ap_vld register port=in_time_seconds name=piTime_seconds
621 #pragma HLS INTERFACE ap_vld register port=in_time_minutes name=piTime_minutes
622 #pragma HLS INTERFACE ap_vld register port=in_time_hours name=piTime_hours
623 #pragma HLS INTERFACE ap_vld register port=role_mmio_in name=piRole_mmio
624 #pragma HLS INTERFACE ap_vld register port=uoe_drop_cnt_in name=piUOE_drop_cnt
625 #pragma HLS INTERFACE ap_vld register port=toe_notif_drop_cnt_in name=piTOE_notif_drop_cnt
626 #pragma HLS INTERFACE ap_vld register port=toe_meta_drop_cnt_in name=piTOE_meta_drop_cnt
627 #pragma HLS INTERFACE ap_vld register port=toe_data_drop_cnt_in name=piTOE_data_drop_cnt
628 #pragma HLS INTERFACE ap_vld register port=toe_crc_drop_cnt_in name=piTOE_crc_drop_cnt
629 #pragma HLS INTERFACE ap_vld register port=toe_sess_drop_cnt_in name=piTOE_sess_drop_cnt
630 #pragma HLS INTERFACE ap_vld register port=toe_ooo_drop_cnt_in name=piTOE_ooo_drop_cnt
631 #pragma HLS INTERFACE ap_stable register port=decoupStatus name=piDECOUP_status
632 #pragma HLS INTERFACE ap_ovld register port=setDecoup name=poDECOUP_activate
633 #pragma HLS INTERFACE ap_ovld register port=role_rank name=poROLE_rank
634 #pragma HLS INTERFACE ap_ovld register port=cluster_size name=poROLE_size
635 #pragma HLS INTERFACE m_axi depth=16383 port=nalCtrl bundle=boNAL_ctrlLink
636  //max_read_burst_length=1 max_write_burst_length=1 //0x3fff - 0x2000
637 #pragma HLS INTERFACE ap_stable register port=disable_ctrl_link name=piDisableCtrlLink
638 #pragma HLS INTERFACE ap_ovld register port=setSoftReset name=poSoftReset
639 
640 #ifdef INCLUDE_PYROLINK
641 #pragma HLS INTERFACE ap_fifo register both port=soPYROLINK
642 #pragma HLS INTERFACE ap_fifo register both port=siPYROLINK
643 #pragma HLS INTERFACE ap_stable register port=disable_pyro_link name=piDisablePyroLink
644 #endif
645 
646 #pragma HLS INTERFACE ap_fifo port=siNAL_Tcp_data
647 #pragma HLS INTERFACE ap_fifo port=soNAL_Tcp_data
648 #pragma HLS INTERFACE ap_fifo port=siNAL_Tcp_SessId
649 #pragma HLS INTERFACE ap_fifo port=soNAL_Tcp_SessId
650 //ap_ctrl is default (i.e. ap_hs)
651 //#pragma HLS DATAFLOW TODO: crashes Vivado..
652 
653 #pragma HLS STREAM variable=internal_icap_fifo depth=4096
654 #pragma HLS STREAM variable=icap_hangover_fifo depth=3
655 
656 #pragma HLS reset variable=nal_status_request_cnt
657 #pragma HLS reset variable=httpState
658 #pragma HLS reset variable=bufferInPtrWrite
659 #pragma HLS reset variable=bufferInPtrMaxWrite
660 #pragma HLS reset variable=lastSeenBufferInPtrMaxWrite
661 #pragma HLS reset variable=bufferInPtrNextRead
662 #pragma HLS reset variable=tcp_write_only_fifo
663 #pragma HLS reset variable=bufferOutPtrWrite
664 #pragma HLS reset variable=bufferOutContentLength
665 #pragma HLS reset variable=bufferOutPtrNextRead
666 #pragma HLS reset variable=lastSeenBufferOutPtrNextRead
667 #pragma HLS reset variable=writeErrCnt
668 #pragma HLS reset variable=fifoEmptyCnt
669 #pragma HLS reset variable=fifoFullCnt
670 #pragma HLS reset variable=wordsWrittenToIcapCnt
671 #pragma HLS reset variable=fsmHwicap
672 #pragma HLS reset variable=fifo_operation_in_progress
673 #pragma HLS reset variable=tcp_words_received
674 #pragma HLS reset variable=fifo_overflow_buffer_length
675 #pragma HLS reset variable=process_fifo_overflow_buffer
676 #pragma HLS reset variable=globalOperationDone_persistent
677 #pragma HLS reset variable=transferError_persistent
678 #pragma HLS reset variable=invalidPayload_persistent
679 #pragma HLS reset variable=flag_check_xmem_pattern
680 #pragma HLS reset variable=flag_silent_skip
681 #pragma HLS reset variable=toDecoup_persistent
682 #pragma HLS reset variable=lastResponsePageCnt
683 #pragma HLS reset variable=responePageCnt
684 #pragma HLS reset variable=xmem_page_trans_cnt
685 #pragma HLS reset variable=last_xmem_page_received_persistent
686 #pragma HLS reset variable=flag_continuous_tcp_rx
687 #pragma HLS reset variable=axi_wasnot_ready_persistent
688 #pragma HLS reset variable=global_state_wait_counter_persistent
689 #pragma HLS reset variable=currentTcpSessId
690 #pragma HLS reset variable=TcpSessId_updated_persistent
691 #pragma HLS reset variable=tcpModeEnabled
692 #pragma HLS reset variable=tcp_iteration_count
693 #pragma HLS reset variable=fsmTcpSessId_TX
694 #pragma HLS reset variable=fsmTcpSessId_RX
695 #pragma HLS reset variable=fsmTcpData_TX
696 #pragma HLS reset variable=fsmTcpData_RX
697 #pragma HLS reset variable=run_nested_loop_helper
698 #pragma HLS reset variable=goto_done_if_idle_tcp_rx
699 #pragma HLS reset variable=received_TCP_SessIds_cnt
700 
701 #pragma HLS reset variable=current_nrc_mrt_version
702 #pragma HLS reset variable=current_MRT
703 #pragma HLS reset variable=current_nrc_config
704 #pragma HLS reset variable=nodeRank
705 #pragma HLS reset variable=clusterSize
706 #pragma HLS reset variable=tables_initialized
707 #pragma HLS reset variable=nal_status_disabled
708 #pragma HLS reset variable=need_to_update_nrc_mrt
709 #pragma HLS reset variable=need_to_update_nrc_config
710 #pragma HLS reset variable=ctrl_link_next_check_seconds
711 #pragma HLS reset variable=mrt_copy_index
712 //#pragma HLS reset variable=ctrl_link_transfer_ongoing
713 #pragma HLS reset variable=linkCtrlFSM
714 #pragma HLS reset variable=max_discovered_node_id
715 #pragma HLS reset variable=detected_http_nl_cnt
716 #pragma HLS reset variable=target_http_nl_cnt
717 #pragma HLS reset variable=hwicap_hangover_present
718 #pragma HLS reset variable=hwicap_hangover_size
719 #pragma HLS reset variable=flag_enable_fake_hwicap
720 
721 
722 
723 
724  //===========================================================
725  // Core-wide variables
726  ap_uint<32> SR = 0, HWICAP_Done = 0, EOS = 0, CR = 0, CR_value = 0, ASR = 0;
727  ap_uint<8> ASW1 = 0, ASW2 = 0, ASW3 = 0, ASW4= 0;
728 
729  ap_uint<32> ISR = 0, WFV = 0; // RFO = 0;
730  ap_uint<32> WFV_value = 0, WEMPTY = 0;
731 
732  ap_uint<4> expCnt = 0;
733  ap_uint<4> copyRet = 0;
734 
735 
736  ap_uint<1> pyroSendRequestBit = 0;
737  char msg_buf[4] = {0x49,0x44,0x4C,'\n'}; //IDL
738  char *msg = &msg_buf[0];
739 
740  OprvType lastReturnValue = 0x0;
741  uint8_t currentProgramLength = 0;
742  OpcodeType opcodeProgram[MAX_PROGRAM_LENGTH];
743  OprvType programMask[MAX_PROGRAM_LENGTH];
744 
745  if(!tables_initialized)
746  {
747  for(int i = 0; i < MAX_MRT_SIZE; i++)
748  {
749 //#pragma HLS unroll
750  current_MRT[i] = 0x0;
751  }
752  for(int i = 0; i < NUMBER_CONFIG_WORDS; i++)
753  {
754 //#pragma HLS unroll
755  current_nrc_config[i] = 0x0;
756  }
757  for(int i = 0; i < NUMBER_FPGA_STATE_REGISTERS; i++)
758  {
759 //#pragma HLS unroll
760  fpga_status[i] = 0x0;
761  }
762  for(int i = 0; i < 2; i++)
763  {
764 //#pragma HLS unroll
765  last_3_chars[i] = 0x0;
766  }
767  for(int i = 0; i < 3; i++)
768  {
769 //#pragma HLS unroll
770  buffer_hangover_bytes[i] = 0x0;
772  }
773  tables_initialized = true;
774  }
775 
776  // ++++++++++++++++++ evaluate outside world ++++++++++++++++
777  //===========================================================
778  // Connection to HWICAP
779  // essential data (ask every time)
780  SR = HWICAP[SR_OFFSET];
781  CR = HWICAP[CR_OFFSET];
782  ASR = HWICAP[ASR_OFFSET];
783  ASW1 = ASR & 0xFF;
784  ASW2 = (ASR & 0xFF00) >> 8;
785  ASW3 = (ASR & 0xFF0000) >> 16;
786  ASW4 = (ASR & 0xFF000000) >> 24;
787 
788  HWICAP_Done = SR & 0x1;
789  EOS = (SR & 0x4) >> 2;
790  CR_value = CR & 0x1F;
791 
792  ISR = HWICAP[ISR_OFFSET];
793  WFV = HWICAP[WFV_OFFSET];
794 
795  //RFO = HWICAP[RFO_OFFSET];
796  WEMPTY = (ISR & 0x4) >> 2;
797  WFV_value = WFV & 0x7FF;
798 
799 
800  ap_uint<1> wasAbort = (CR_value & CR_ABORT) >> 4;
801  //Maybe CR_ABORT is not set
802  if( ASW1 != 0x00)
803  {
804  wasAbort = 1;
805  }
806 
807 
808  //MMIO commands
809  ap_uint<32> MMIO_in_LE = 0x0;
810  MMIO_in_LE = (ap_uint<32>) ((*MMIO_in >> 24) & 0xFF);
811  MMIO_in_LE |= (ap_uint<32>) ((*MMIO_in >> 8) & 0xFF00);
812  MMIO_in_LE |= (ap_uint<32>) ((*MMIO_in << 8) & 0xFF0000);
813  MMIO_in_LE |= (ap_uint<32>) ((*MMIO_in << 24) & 0xFF000000);
814 
815  ap_uint<1> checkPattern = (MMIO_in_LE >> CHECK_PATTERN_SHIFT ) & 0b1;
816 
817  ap_uint<1> parseHTTP = (MMIO_in_LE >> PARSE_HTTP_SHIFT) & 0b1;
818 
819  ap_uint<1> notToSwap = (MMIO_in_LE >> SWAP_N_SHIFT) & 0b1;
820  //Turns out: we need to swap => active low
821 
822  ap_uint<1> startXmemTrans = (MMIO_in_LE >> START_SHIFT) & 0b1;
823 
824 
825  ap_uint<1> pyroReadReq = (MMIO_in_LE >> PYRO_READ_REQUEST_SHIFT) & 0b1;
826 
827  ap_uint<1> tcpModeStart = (MMIO_in_LE >> ENABLE_TCP_MODE_SHIFT) & 0b1;
828 
829  ap_uint<1> pyroRecvMode = (MMIO_in_LE >> PYRO_MODE_SHIFT) & 0b1;
830 
831  ap_uint<7> lastPageCnt_in = (MMIO_in_LE >> LAST_PAGE_CNT_SHIFT) & 0x7F;
832 
833  ap_uint<1> manuallyToDecoup = (MMIO_in_LE >> DECOUP_CMD_SHIFT) & 0b1;
834 
835  ap_uint<1> CR_isWriting = CR_value & CR_WRITE;
836 
837  ap_uint<1> reset_from_psoc = (MMIO_in_LE >> RST_SHIFT) & 0b1;
838 
839  ap_uint<1> flag_enable_fake_hwicap = (MMIO_in_LE >> ENABLE_FAKE_HWICAP_SHIFT) & 0b1;
840 
841 #ifdef INCLUDE_PYROLINK
842  if(*disable_pyro_link == 0)
843  {
844  pyroSendRequestBit = siPYROLINK.empty()? 0 : 1;
845  }
846 #else
847  pyroSendRequestBit = 0;
848 #endif
849 
856 
857  fpga_time_seconds = *in_time_seconds;
858  fpga_time_minutes = *in_time_minutes;
859  fpga_time_hours = *in_time_hours;
860 
861  current_role_mmio = *role_mmio_in;
862 
863  nts_udp_drop_cnt = *uoe_drop_cnt_in;
864  nts_tcp_notif_drop_cnt = *toe_notif_drop_cnt_in;
865  nts_tcp_meta_drop_cnt = *toe_meta_drop_cnt_in;
866  nts_tcp_data_drop_cnt = *toe_data_drop_cnt_in;
867  nts_tcp_crc_drop_cnt = *toe_crc_drop_cnt_in;
868  nts_tcp_sess_drop_cnt = *toe_sess_drop_cnt_in;
869  nts_tcp_ooo_drop_cnt = *toe_ooo_drop_cnt_in;
870 
871 
872  // ++++++++++++++++++ IMMEDIATE ACTIONS +++++++++++++++++++
873  //===========================================================
874 
875  // ++++++++++++++++++ MAKE THE PLAN +++++++++++++++++++
876  //===========================================================
877 
878 
879  bool iterate_again = true;
880  while(iterate_again)
881  {
882  iterate_again = false;
883  switch(currentGlobalOperation)
884  {
885  default: //no break, just for default
886  case GLOBAL_IDLE:
887  //general stuff before a new global operation
889  transferError_persistent = false;
894  tcpModeEnabled = 0;
896  if(reset_from_psoc == 1)
897  {
898  printf("[FMC] reset from PSOC!\n");
900  //tcp_rx_blocked_by_processing = false;
901  writeErrCnt = 0;
902  fifoEmptyCnt = 0;
903  fifoFullCnt = 0;
904  //wordsWrittenToIcapCnt = 0;
905  iterate_again = false;
906  //hwicap_waiting_for_tcp = false;
907  break;
908  }
909  //ongoingTransfer_persistent = false;
910  currentProgramLength = 0;
911  //looking for a new job...but with priorities
912  if(tcpModeStart == 1 && parseHTTP == 1)
913  {
916 
918  //reset TX TCP FSMs
921 
922  currentTcpSessId = 0;
924  iterate_again = true;
928 
929  opcodeProgram[0] = OP_CLEAR_IN_BUFFER;
930  programMask[0] = MASK_ALWAYS;
931  opcodeProgram[1] = OP_CLEAR_OUT_BUFFER;
932  programMask[1] = MASK_ALWAYS;
933  opcodeProgram[2] = OP_TCP_CNT_RESET;
934  programMask[2] = MASK_ALWAYS;
935  currentProgramLength = 3;
936  }
937  else if(tcpModeStart == 1)
938  {
939  //This was GLOBAL_TCP_TO_HWICAP, but is now NOP
941  } else if(parseHTTP == 1 && startXmemTrans == 1)
942  {
945  xmem_page_trans_cnt = 0xf;
947 
949  opcodeProgram[0] = OP_CLEAR_IN_BUFFER;
950  programMask[0] = MASK_ALWAYS;
951  opcodeProgram[1] = OP_CLEAR_OUT_BUFFER;
952  programMask[1] = MASK_ALWAYS;
953  currentProgramLength = 2;
954  iterate_again = true;
955  } else if(checkPattern == 1 && startXmemTrans == 1)
956  {
957  xmem_page_trans_cnt = 0xf;
958 
960  //only in the beginning!
961  opcodeProgram[0] = OP_CLEAR_IN_BUFFER;
962  programMask[0] = MASK_ALWAYS;
963  currentProgramLength = 1;
964  iterate_again = true;
965  } else if(startXmemTrans == 1)
966  {
967  xmem_page_trans_cnt = 0xf;
969 
971  opcodeProgram[0] = OP_CLEAR_IN_BUFFER;
972  programMask[0] = MASK_ALWAYS;
973  currentProgramLength = 1;
974  iterate_again = true;
975 #ifdef INCLUDE_PYROLINK
976  } else if(pyroRecvMode == 1 && *disable_pyro_link == 0)
977  {
978  currentGlobalOperation = GLOBAL_PYROLINK_RECV; //i.e. Coaxium to FPGA
979  xmem_page_trans_cnt = 0xf;
980 
981  opcodeProgram[0] = OP_CLEAR_IN_BUFFER;
982  programMask[0] = MASK_ALWAYS;
983  currentProgramLength = 1;
984  iterate_again = true;
985 
986  } else if(pyroReadReq == 1 && *disable_pyro_link == 0)
987  {
988  currentGlobalOperation = GLOBAL_PYROLINK_TRANS; //i.e. FPGA to Coaxium
989 
990  opcodeProgram[0] = OP_CLEAR_OUT_BUFFER;
991  programMask[0] = MASK_ALWAYS;
992  currentProgramLength = 1;
993  iterate_again = true;
994 #endif
995  } else if(manuallyToDecoup == 1)
996  {
998  iterate_again = true;
999  } else {
1000  //else...we just do the daily jobs...
1001  //currentProgramLength = 0;
1002  msg = "BOR"; //BOR..ING
1003  }
1004  //need to break to reevaluate switch-case
1005  break;
1006 
1008  if(reset_from_psoc == 1)
1009  { //reset form counter etc. are done in GLOBAL_IDLE;
1011  //do nothing
1012  currentProgramLength = 0;
1013  //to trigger all resets
1014  iterate_again = true;
1015  break;
1016  }
1018  { // means, we have this operation done and wait for status change
1019  if(startXmemTrans == 0)
1020  {
1022  }
1023  //do nothing
1024  msg="SUC"; //maintain SUC message (for XMEM transfer)
1025  currentProgramLength = 0;
1026  break;
1027  }
1029  {
1030  //do not change state?
1031  msg="ERR";
1032  currentProgramLength=0;
1033  break;
1034  }
1035 
1036  opcodeProgram[currentProgramLength] = OP_ENABLE_XMEM_CHECK_PATTERN;
1037  programMask[currentProgramLength] = MASK_ALWAYS;
1038  currentProgramLength++;
1039  opcodeProgram[currentProgramLength] = OP_XMEM_COPY_DATA;
1040  programMask[currentProgramLength] = MASK_ALWAYS;
1041  currentProgramLength++;
1042 
1043  //execute multiple times if not OPRV_DONE
1044  for(uint8_t i = 0; i<15; i++)
1045  {
1046  opcodeProgram[currentProgramLength] = OP_XMEM_COPY_DATA;
1047  programMask[currentProgramLength] = OPRV_OK | OPRV_PARTIAL_COMPLETE | OPRV_NOT_COMPLETE;
1048  currentProgramLength++;
1049  }
1050 
1051  //to switch from skipped to done
1052  //we skip for FAIL or DONE --> in both cases we won't continue and msg is set accordingly
1053  opcodeProgram[currentProgramLength] = OP_DONE;
1054  programMask[currentProgramLength] = OPRV_SKIPPED;
1055  currentProgramLength++;
1056 
1057  break;
1058 
1059  case GLOBAL_XMEM_TO_HWICAP:
1060  if(reset_from_psoc == 1)
1061  { //reset form counter etc. are done in GLOBAL_IDLE;
1063  //do nothing
1064  currentProgramLength = 0;
1065  //to trigger all resets
1066  iterate_again = true;
1067  break;
1068  }
1070  { // means, we have this operation done and wait for status change
1071  if(startXmemTrans == 0)
1072  {
1074  }
1075  //do nothing else
1076  currentProgramLength=0;
1077  msg="SUC"; //maintain SUC message (for XMEM transfer)
1078  break;
1079  }
1080  if(wasAbort == 1)
1081  {
1082  //do not change state?
1083  msg="ABR";
1084  currentProgramLength=0;
1085  break;
1086  }
1088  {
1089  //do not change state?
1090  msg="ERR";
1091  currentProgramLength=0;
1092  break;
1093  }
1094 
1095  opcodeProgram[currentProgramLength] = OP_ACTIVATE_DECOUP;
1096  programMask[currentProgramLength] = MASK_ALWAYS;
1097  currentProgramLength++;
1098  opcodeProgram[currentProgramLength] = OP_XMEM_COPY_DATA;
1099  programMask[currentProgramLength] = MASK_ALWAYS;
1100  currentProgramLength++;
1101  opcodeProgram[currentProgramLength] = OP_ENABLE_SILENT_SKIP;
1102  programMask[currentProgramLength] = MASK_ALWAYS;
1103  currentProgramLength++;
1104  opcodeProgram[currentProgramLength] = OP_BUFFER_TO_HWICAP;
1105  programMask[currentProgramLength] = OPRV_DONE | OPRV_OK;
1106  currentProgramLength++;
1107  //done for now
1108  opcodeProgram[currentProgramLength] = OP_EXIT;
1109  programMask[currentProgramLength] = OPRV_OK | OPRV_NOT_COMPLETE;
1110  currentProgramLength++;
1111  //done at all or fail (?)
1112  opcodeProgram[currentProgramLength] = OP_DEACTIVATE_DECOUP;
1113  programMask[currentProgramLength] = OPRV_DONE;
1114  currentProgramLength++;
1115  opcodeProgram[currentProgramLength] = OP_CLEAR_ROUTING_TABLE;
1116  programMask[currentProgramLength] = OPRV_DONE;
1117  currentProgramLength++;
1118  opcodeProgram[currentProgramLength] = OP_EXIT;
1119  programMask[currentProgramLength] = OPRV_DONE;
1120  currentProgramLength++;
1121  opcodeProgram[currentProgramLength] = OP_DISABLE_SILENT_SKIP;
1122  programMask[currentProgramLength] = MASK_ALWAYS;
1123  currentProgramLength++;
1124  opcodeProgram[currentProgramLength] = OP_ABORT_HWICAP;
1125  programMask[currentProgramLength] = OPRV_FAIL;
1126  currentProgramLength++;
1127  opcodeProgram[currentProgramLength] = OP_FAIL;
1128  programMask[currentProgramLength] = OPRV_OK;
1129  currentProgramLength++;
1130  opcodeProgram[currentProgramLength] = OP_EXIT;
1131  programMask[currentProgramLength] = OPRV_FAIL;
1132  currentProgramLength++;
1133 
1134  break;
1135 
1136  case GLOBAL_XMEM_HTTP:
1137  if(reset_from_psoc == 1)
1138  { //reset form counter etc. are done in GLOBAL_IDLE;
1140  //do nothing
1141  currentProgramLength = 0;
1142  //to trigger all resets
1143  iterate_again = true;
1144  break;
1145  }
1147  { // means, we have this operation done and wait for status change
1148  if(startXmemTrans == 0)
1149  {
1151  }
1152  //do nothing
1153  currentProgramLength = 0;
1154  msg="SUC"; //maintain SUC message (for XMEM transfer)
1155  break;
1156  }
1157  if(wasAbort == 1)
1158  {
1159  //do not change state?
1160  msg="ABR";
1161  currentProgramLength=0;
1162  break;
1163  }
1165  {
1166  //do not change state?
1167  msg="ERR";
1168  currentProgramLength=0;
1169  break;
1170  }
1171 
1172  if(reqType == POST_ROUTING)
1173  {
1174  opcodeProgram[currentProgramLength] = OP_ENABLE_SILENT_SKIP;
1175  programMask[currentProgramLength] = MASK_ALWAYS;
1176  currentProgramLength++;
1177  opcodeProgram[currentProgramLength] = OP_XMEM_COPY_DATA;
1178  programMask[currentProgramLength] = MASK_ALWAYS;
1179  currentProgramLength++;
1180  opcodeProgram[currentProgramLength] = OP_EXIT; //wait for data or fatal failure
1181  programMask[currentProgramLength] = OPRV_NOT_COMPLETE | OPRV_PARTIAL_COMPLETE | OPRV_FAIL;
1182  currentProgramLength++;
1183  opcodeProgram[currentProgramLength] = OP_BUFFER_TO_ROUTING;
1184  programMask[currentProgramLength] = OPRV_DONE | OPRV_OK;
1185  currentProgramLength++;
1186  opcodeProgram[currentProgramLength] = OP_EXIT;
1187  programMask[currentProgramLength] = OPRV_NOT_COMPLETE;
1188  currentProgramLength++;
1189  opcodeProgram[currentProgramLength] = OP_UPDATE_HTTP_STATE;
1190  programMask[currentProgramLength] = OPRV_DONE | OPRV_FAIL;
1191  currentProgramLength++;
1192  opcodeProgram[currentProgramLength] = OP_DISABLE_SILENT_SKIP;
1193  programMask[currentProgramLength] = MASK_ALWAYS;
1194  currentProgramLength++;
1195  opcodeProgram[currentProgramLength] = OP_HANDLE_HTTP;
1196  programMask[currentProgramLength] = OPRV_OK;
1197  currentProgramLength++;
1198  opcodeProgram[currentProgramLength] = OP_SEND_BUFFER_XMEM;
1199  programMask[currentProgramLength] = OPRV_DONE;
1200  currentProgramLength++;
1201  break;
1202  }
1203  if(reqType == POST_CONFIG)
1204  {//decoup already activated
1205  opcodeProgram[currentProgramLength] = OP_ENABLE_SILENT_SKIP;
1206  programMask[currentProgramLength] = MASK_ALWAYS;
1207  currentProgramLength++;
1208  opcodeProgram[currentProgramLength] = OP_XMEM_COPY_DATA;
1209  programMask[currentProgramLength] = MASK_ALWAYS;
1210  currentProgramLength++;
1211  opcodeProgram[currentProgramLength] = OP_EXIT; //wait for data of fatal failure
1212  programMask[currentProgramLength] = OPRV_NOT_COMPLETE | OPRV_PARTIAL_COMPLETE | OPRV_FAIL;
1213  currentProgramLength++;
1214  opcodeProgram[currentProgramLength] = OP_BUFFER_TO_HWICAP;
1215  programMask[currentProgramLength] = OPRV_DONE | OPRV_OK;
1216  currentProgramLength++;
1217  //wait for next junk
1218  opcodeProgram[currentProgramLength] = OP_EXIT;
1219  programMask[currentProgramLength] = OPRV_OK | OPRV_NOT_COMPLETE;
1220  currentProgramLength++;
1221  opcodeProgram[currentProgramLength] = OP_DISABLE_SILENT_SKIP;
1222  programMask[currentProgramLength] = MASK_ALWAYS;
1223  currentProgramLength++;
1224  //failed?
1225  opcodeProgram[currentProgramLength] = OP_ABORT_HWICAP;
1226  programMask[currentProgramLength] = OPRV_FAIL;
1227  currentProgramLength++;
1228  opcodeProgram[currentProgramLength] = OP_UPDATE_HTTP_STATE;
1229  programMask[currentProgramLength] = OPRV_OK;
1230  currentProgramLength++;
1231  opcodeProgram[currentProgramLength] = OP_HANDLE_HTTP;
1232  programMask[currentProgramLength] = OPRV_OK;
1233  currentProgramLength++;
1234  opcodeProgram[currentProgramLength] = OP_SEND_BUFFER_XMEM;
1235  programMask[currentProgramLength] = OPRV_DONE;
1236  currentProgramLength++;
1237  //restore RV
1238  opcodeProgram[currentProgramLength] = OP_FAIL;
1239  programMask[currentProgramLength] = OPRV_OK;
1240  currentProgramLength++;
1241  opcodeProgram[currentProgramLength] = OP_EXIT;
1242  programMask[currentProgramLength] = OPRV_FAIL;
1243  currentProgramLength++;
1244  //Reconfiguration done
1245  opcodeProgram[currentProgramLength] = OP_DEACTIVATE_DECOUP;
1246  programMask[currentProgramLength] = OPRV_SKIPPED;
1247  currentProgramLength++;
1248  opcodeProgram[currentProgramLength] = OP_CLEAR_ROUTING_TABLE;
1249  programMask[currentProgramLength] = OPRV_OK;
1250  currentProgramLength++;
1251  opcodeProgram[currentProgramLength] = OP_DONE;
1252  programMask[currentProgramLength] = OPRV_OK;
1253  currentProgramLength++;
1254  opcodeProgram[currentProgramLength] = OP_UPDATE_HTTP_STATE;
1255  programMask[currentProgramLength] = OPRV_DONE;
1256  currentProgramLength++;
1257  opcodeProgram[currentProgramLength] = OP_HANDLE_HTTP;
1258  programMask[currentProgramLength] = OPRV_OK;
1259  currentProgramLength++;
1260  opcodeProgram[currentProgramLength] = OP_SEND_BUFFER_XMEM;
1261  programMask[currentProgramLength] = OPRV_DONE;
1262  currentProgramLength++;
1263  break;
1264  }
1265 
1266  //else...first run?
1267  opcodeProgram[currentProgramLength] = OP_XMEM_COPY_DATA;
1268  programMask[currentProgramLength] = MASK_ALWAYS;
1269  currentProgramLength++;
1270  opcodeProgram[currentProgramLength] = OP_ENABLE_SILENT_SKIP;
1271  programMask[currentProgramLength] = MASK_ALWAYS;
1272  currentProgramLength++;
1273  opcodeProgram[currentProgramLength] = OP_EXIT; //wait for data or fatal failure
1274  programMask[currentProgramLength] = OPRV_NOT_COMPLETE | OPRV_PARTIAL_COMPLETE | OPRV_FAIL;
1275  currentProgramLength++;
1276  opcodeProgram[currentProgramLength] = OP_HANDLE_HTTP;
1277  programMask[currentProgramLength] = OPRV_DONE | OPRV_OK;
1278  currentProgramLength++;
1279  opcodeProgram[currentProgramLength] = OP_HANDLE_HTTP; //If we just need to create a response
1280  programMask[currentProgramLength] = OPRV_USER;
1281  currentProgramLength++;
1282  opcodeProgram[currentProgramLength] = OP_SEND_BUFFER_XMEM; //send if necessary
1283  programMask[currentProgramLength] = OPRV_DONE;
1284  currentProgramLength++;
1285  opcodeProgram[currentProgramLength] = OP_EXIT; //exit after send
1286  programMask[currentProgramLength] = OPRV_DONE;
1287  currentProgramLength++;
1288  opcodeProgram[currentProgramLength] = OP_DISABLE_SILENT_SKIP;
1289  programMask[currentProgramLength] = MASK_ALWAYS;
1290  currentProgramLength++;
1291  opcodeProgram[currentProgramLength] = OP_COPY_REQTYPE_TO_RETURN;
1292  programMask[currentProgramLength] = OPRV_PARTIAL_COMPLETE;
1293  currentProgramLength++;
1294  //if skipped --> OK or not complete --> more data, also exit
1295  opcodeProgram[currentProgramLength] = OP_ENABLE_SILENT_SKIP;
1296  programMask[currentProgramLength] = MASK_ALWAYS;
1297  currentProgramLength++;
1298  opcodeProgram[currentProgramLength] = OP_EXIT;
1299  programMask[currentProgramLength] = OPRV_SKIPPED;
1300  currentProgramLength++;
1301  opcodeProgram[currentProgramLength] = OP_DISABLE_SILENT_SKIP;
1302  programMask[currentProgramLength] = MASK_ALWAYS;
1303  currentProgramLength++;
1304  //not exit --> RV is request type, only POST_CONFIG or POST_ROUTING remains
1305  opcodeProgram[currentProgramLength] = OP_BUFFER_TO_ROUTING;
1306  programMask[currentProgramLength] = POST_ROUTING;
1307  currentProgramLength++;
1308  //if done --> send reply
1309  opcodeProgram[currentProgramLength] = OP_UPDATE_HTTP_STATE;
1310  programMask[currentProgramLength] = OPRV_DONE | OPRV_FAIL;
1311  currentProgramLength++;
1312  opcodeProgram[currentProgramLength] = OP_HANDLE_HTTP;
1313  programMask[currentProgramLength] = OPRV_OK;
1314  currentProgramLength++;
1315  opcodeProgram[currentProgramLength] = OP_SEND_BUFFER_XMEM;
1316  programMask[currentProgramLength] = OPRV_DONE;
1317  currentProgramLength++;
1318  opcodeProgram[currentProgramLength] = OP_EXIT;
1319  programMask[currentProgramLength] = OPRV_DONE;
1320  currentProgramLength++;
1321  //here neither routing not complete or post config
1322  opcodeProgram[currentProgramLength] = OP_COPY_REQTYPE_TO_RETURN;
1323  programMask[currentProgramLength] = OPRV_SKIPPED;
1324  currentProgramLength++;
1325  //if routing --> we need more data (and erase the RV)
1326  opcodeProgram[currentProgramLength] = OP_OK;
1327  programMask[currentProgramLength] = POST_ROUTING;
1328  currentProgramLength++;
1329  opcodeProgram[currentProgramLength] = OP_EXIT;
1330  programMask[currentProgramLength] = OPRV_OK;
1331  currentProgramLength++;
1332  //now, it is POST configure
1333  opcodeProgram[currentProgramLength] = OP_ACTIVATE_DECOUP;
1334  programMask[currentProgramLength] = OPRV_SKIPPED;
1335  currentProgramLength++;
1336  // we lost the information of DONE in the RV, but it is also stored in last_xmem_page_received_persistent
1337  opcodeProgram[currentProgramLength] = OP_BUFFER_TO_HWICAP;
1338  programMask[currentProgramLength] = OPRV_OK;
1339  currentProgramLength++;
1340  opcodeProgram[currentProgramLength] = OP_ENABLE_SILENT_SKIP;
1341  programMask[currentProgramLength] = MASK_ALWAYS;
1342  currentProgramLength++;
1343  //wait for next junk
1344  opcodeProgram[currentProgramLength] = OP_EXIT;
1345  programMask[currentProgramLength] = OPRV_OK | OPRV_NOT_COMPLETE;
1346  currentProgramLength++;
1347  //Reconfiguration done
1348  opcodeProgram[currentProgramLength] = OP_DEACTIVATE_DECOUP;
1349  programMask[currentProgramLength] = OPRV_DONE;
1350  currentProgramLength++;
1351  opcodeProgram[currentProgramLength] = OP_CLEAR_ROUTING_TABLE;
1352  programMask[currentProgramLength] = OPRV_DONE;
1353  currentProgramLength++;
1354  opcodeProgram[currentProgramLength] = OP_UPDATE_HTTP_STATE;
1355  programMask[currentProgramLength] = OPRV_DONE;
1356  currentProgramLength++;
1357  opcodeProgram[currentProgramLength] = OP_HANDLE_HTTP;
1358  programMask[currentProgramLength] = OPRV_OK;
1359  currentProgramLength++;
1360  opcodeProgram[currentProgramLength] = OP_SEND_BUFFER_XMEM;
1361  programMask[currentProgramLength] = OPRV_DONE;
1362  currentProgramLength++;
1363  opcodeProgram[currentProgramLength] = OP_EXIT;
1364  programMask[currentProgramLength] = OPRV_DONE;
1365  currentProgramLength++;
1366  opcodeProgram[currentProgramLength] = OP_DISABLE_SILENT_SKIP;
1367  programMask[currentProgramLength] = MASK_ALWAYS;
1368  currentProgramLength++;
1369  //if fail --> abort
1370  opcodeProgram[currentProgramLength] = OP_ABORT_HWICAP;
1371  programMask[currentProgramLength] = OPRV_FAIL;
1372  currentProgramLength++;
1373  opcodeProgram[currentProgramLength] = OP_UPDATE_HTTP_STATE;
1374  programMask[currentProgramLength] = OPRV_OK;
1375  currentProgramLength++;
1376  opcodeProgram[currentProgramLength] = OP_HANDLE_HTTP;
1377  programMask[currentProgramLength] = OPRV_OK;
1378  currentProgramLength++;
1379  opcodeProgram[currentProgramLength] = OP_SEND_BUFFER_XMEM;
1380  programMask[currentProgramLength] = OPRV_DONE;
1381  currentProgramLength++;
1382  //restore RV
1383  opcodeProgram[currentProgramLength] = OP_FAIL;
1384  programMask[currentProgramLength] = OPRV_DONE;
1385  currentProgramLength++;
1386  opcodeProgram[currentProgramLength] = OP_EXIT;
1387  programMask[currentProgramLength] = OPRV_FAIL;
1388  currentProgramLength++;
1389  opcodeProgram[currentProgramLength] = OP_OK;
1390  programMask[currentProgramLength] = OPRV_SKIPPED;
1391  currentProgramLength++;
1392 
1393  break;
1394 
1395  case GLOBAL_TCP_HTTP:
1396  if(reset_from_psoc == 1)
1397  { //reset form counter etc. are done in GLOBAL_IDLE;
1399  //do nothing
1400  currentProgramLength = 0;
1401  tcp_iteration_count = 0;
1402  //to trigger all resets
1403  iterate_again = true;
1404  break;
1405  }
1406  //TODO: implement timeout for NOT complete requests
1407  tcpModeEnabled = 1;
1408  msg="TCP";
1409 
1411  {
1412  //"self reset" --> start over
1413  //but wait until TX TCP FSMs have finished
1416  {
1418  iterate_again = true;
1419  msg="SUC"; //maintain SUC message
1420  //do nothing else
1421  currentProgramLength=0;
1422  } else {
1423  printf("\t\t\tWaiting for TCP FSMs to finish...\n");
1424  msg="WFF"; //Wait for FSM
1425 
1426  //give the FSM the option to update Flags
1427  currentProgramLength=0;
1428  opcodeProgram[currentProgramLength] = OP_SEND_TCP_SESS;
1429  programMask[currentProgramLength] = MASK_ALWAYS;
1430  currentProgramLength++;
1431  opcodeProgram[currentProgramLength] = OP_SEND_BUFFER_TCP;
1432  programMask[currentProgramLength] = MASK_ALWAYS;
1433  currentProgramLength++;
1434  }
1435  break;
1436  }
1437  if(wasAbort == 1)
1438  {
1439  //do not change state?
1440  msg="ABR";
1441  currentProgramLength=0;
1442  break;
1443  }
1445  {
1446  //TODO: self reset?
1447  //do not change state?
1448  msg="ERR";
1449  currentProgramLength=0;
1450  break;
1451  }
1452  printf("GLOBAL_TCP_HTTP: make a plan with REQUEST_TYPE: %d\n", (int) reqType);
1453 
1455  {
1456  opcodeProgram[currentProgramLength] = OP_WAIT_FOR_TCP_SESS;
1457  programMask[currentProgramLength] = MASK_ALWAYS;
1458  currentProgramLength++;
1459  opcodeProgram[currentProgramLength] = OP_EXIT;
1460  programMask[currentProgramLength] = OPRV_NOT_COMPLETE;
1461  currentProgramLength++;
1462  //clearing the buffers is done by the "self reset" above
1463  }
1464 
1465  if(reqType == POST_ROUTING)
1466  {//cont tcp already activated
1467  opcodeProgram[currentProgramLength] = OP_ENABLE_SILENT_SKIP;
1468  programMask[currentProgramLength] = MASK_ALWAYS;
1469  currentProgramLength++;
1470  opcodeProgram[currentProgramLength] = OP_FILL_BUFFER_TCP;
1471  programMask[currentProgramLength] = MASK_ALWAYS;
1472  currentProgramLength++;
1473  opcodeProgram[currentProgramLength] = OP_EXIT; //wait for data or fatal failure
1474  programMask[currentProgramLength] = OPRV_NOT_COMPLETE | OPRV_PARTIAL_COMPLETE | OPRV_FAIL;
1475  currentProgramLength++;
1476  opcodeProgram[currentProgramLength] = OP_BUFFER_TO_ROUTING;
1477  programMask[currentProgramLength] = OPRV_DONE | OPRV_OK;
1478  currentProgramLength++;
1479  opcodeProgram[currentProgramLength] = OP_EXIT;
1480  programMask[currentProgramLength] = OPRV_NOT_COMPLETE;
1481  currentProgramLength++;
1482  opcodeProgram[currentProgramLength] = OP_UPDATE_HTTP_STATE;
1483  programMask[currentProgramLength] = OPRV_DONE | OPRV_FAIL;
1484  currentProgramLength++;
1485  opcodeProgram[currentProgramLength] = OP_DISABLE_SILENT_SKIP;
1486  programMask[currentProgramLength] = MASK_ALWAYS;
1487  currentProgramLength++;
1488  opcodeProgram[currentProgramLength] = OP_HANDLE_HTTP;
1489  programMask[currentProgramLength] = OPRV_OK;
1490  currentProgramLength++;
1491  opcodeProgram[currentProgramLength] = OP_SEND_TCP_SESS;
1492  programMask[currentProgramLength] = OPRV_DONE;
1493  currentProgramLength++;
1494  opcodeProgram[currentProgramLength] = OP_DEACTIVATE_CONT_TCP;
1495  programMask[currentProgramLength] = OPRV_DONE;
1496  currentProgramLength++;
1497  opcodeProgram[currentProgramLength] = OP_SEND_BUFFER_TCP;
1498  programMask[currentProgramLength] = OPRV_DONE;
1499  currentProgramLength++;
1500  break;
1501  }
1502  if(reqType == POST_CONFIG)
1503  {//decoup already activated
1504  //cont tcp already activated
1505  opcodeProgram[currentProgramLength] = OP_ENABLE_SILENT_SKIP;
1506  programMask[currentProgramLength] = MASK_ALWAYS;
1507  currentProgramLength++;
1508  opcodeProgram[currentProgramLength] = OP_FIFO_TO_HWICAP;
1509  programMask[currentProgramLength] = MASK_ALWAYS;
1510  currentProgramLength++;
1511  opcodeProgram[currentProgramLength] = OP_EXIT; //we have smth left to do
1512  programMask[currentProgramLength] = OPRV_OK | OPRV_NOT_COMPLETE;
1513  currentProgramLength++;
1514  opcodeProgram[currentProgramLength] = OP_DISABLE_SILENT_SKIP;
1515  programMask[currentProgramLength] = MASK_ALWAYS;
1516  currentProgramLength++;
1517  //failed?
1518  opcodeProgram[currentProgramLength] = OP_ABORT_HWICAP;
1519  programMask[currentProgramLength] = OPRV_FAIL;
1520  currentProgramLength++;
1521  opcodeProgram[currentProgramLength] = OP_UPDATE_HTTP_STATE;
1522  programMask[currentProgramLength] = OPRV_OK;
1523  currentProgramLength++;
1524  opcodeProgram[currentProgramLength] = OP_HANDLE_HTTP;
1525  programMask[currentProgramLength] = OPRV_OK;
1526  currentProgramLength++;
1527  opcodeProgram[currentProgramLength] = OP_SEND_TCP_SESS;
1528  programMask[currentProgramLength] = OPRV_DONE;
1529  currentProgramLength++;
1530  opcodeProgram[currentProgramLength] = OP_SEND_BUFFER_TCP;
1531  programMask[currentProgramLength] = OPRV_DONE;
1532  currentProgramLength++;
1533  //restore RV
1534  opcodeProgram[currentProgramLength] = OP_FAIL;
1535  programMask[currentProgramLength] = OPRV_OK;
1536  currentProgramLength++;
1537  opcodeProgram[currentProgramLength] = OP_EXIT;
1538  programMask[currentProgramLength] = OPRV_FAIL;
1539  currentProgramLength++;
1540  //Reconfiguration done
1541  opcodeProgram[currentProgramLength] = OP_DEACTIVATE_DECOUP;
1542  programMask[currentProgramLength] = OPRV_SKIPPED;
1543  currentProgramLength++;
1544  opcodeProgram[currentProgramLength] = OP_CLEAR_ROUTING_TABLE;
1545  programMask[currentProgramLength] = OPRV_OK;
1546  currentProgramLength++;
1547  opcodeProgram[currentProgramLength] = OP_DONE;
1548  programMask[currentProgramLength] = OPRV_OK;
1549  currentProgramLength++;
1550  opcodeProgram[currentProgramLength] = OP_UPDATE_HTTP_STATE;
1551  programMask[currentProgramLength] = OPRV_DONE;
1552  currentProgramLength++;
1553  opcodeProgram[currentProgramLength] = OP_HANDLE_HTTP;
1554  programMask[currentProgramLength] = OPRV_OK;
1555  currentProgramLength++;
1556  opcodeProgram[currentProgramLength] = OP_SEND_TCP_SESS;
1557  programMask[currentProgramLength] = OPRV_DONE;
1558  currentProgramLength++;
1559  opcodeProgram[currentProgramLength] = OP_DEACTIVATE_CONT_TCP;
1560  programMask[currentProgramLength] = OPRV_DONE;
1561  currentProgramLength++;
1562  opcodeProgram[currentProgramLength] = OP_SEND_BUFFER_TCP;
1563  programMask[currentProgramLength] = OPRV_DONE;
1564  currentProgramLength++;
1565  opcodeProgram[currentProgramLength] = OP_EXIT;
1566  programMask[currentProgramLength] = OPRV_DONE;
1567  currentProgramLength++;
1568  break;
1569  }
1570 
1571  //else...first run?
1572  opcodeProgram[currentProgramLength] = OP_FILL_BUFFER_TCP;
1573  programMask[currentProgramLength] = MASK_ALWAYS;
1574  currentProgramLength++;
1575  opcodeProgram[currentProgramLength] = OP_ENABLE_SILENT_SKIP;
1576  programMask[currentProgramLength] = MASK_ALWAYS;
1577  currentProgramLength++;
1578  opcodeProgram[currentProgramLength] = OP_EXIT; //wait for data or fatal failure
1579  programMask[currentProgramLength] = OPRV_NOT_COMPLETE | OPRV_PARTIAL_COMPLETE | OPRV_FAIL;
1580  currentProgramLength++;
1581  opcodeProgram[currentProgramLength] = OP_HANDLE_HTTP;
1582  programMask[currentProgramLength] = OPRV_DONE | OPRV_OK;
1583  currentProgramLength++;
1584  opcodeProgram[currentProgramLength] = OP_HANDLE_HTTP; //If we just need to create a response
1585  programMask[currentProgramLength] = OPRV_USER;
1586  currentProgramLength++;
1587  opcodeProgram[currentProgramLength] = OP_SEND_TCP_SESS;
1588  programMask[currentProgramLength] = OPRV_DONE;
1589  currentProgramLength++;
1590  opcodeProgram[currentProgramLength] = OP_SEND_BUFFER_TCP; //send if necessary
1591  programMask[currentProgramLength] = OPRV_DONE;
1592  currentProgramLength++;
1593  opcodeProgram[currentProgramLength] = OP_EXIT; //exit after send
1594  programMask[currentProgramLength] = OPRV_DONE;
1595  currentProgramLength++;
1596  opcodeProgram[currentProgramLength] = OP_DISABLE_SILENT_SKIP;
1597  programMask[currentProgramLength] = MASK_ALWAYS;
1598  currentProgramLength++;
1599  opcodeProgram[currentProgramLength] = OP_COPY_REQTYPE_TO_RETURN;
1600  programMask[currentProgramLength] = OPRV_PARTIAL_COMPLETE;
1601  currentProgramLength++;
1602  //if skipped --> OK or not complete --> more data, also exit
1603  opcodeProgram[currentProgramLength] = OP_ENABLE_SILENT_SKIP;
1604  programMask[currentProgramLength] = MASK_ALWAYS;
1605  currentProgramLength++;
1606  opcodeProgram[currentProgramLength] = OP_EXIT;
1607  programMask[currentProgramLength] = OPRV_SKIPPED;
1608  currentProgramLength++;
1609  opcodeProgram[currentProgramLength] = OP_DISABLE_SILENT_SKIP;
1610  programMask[currentProgramLength] = MASK_ALWAYS;
1611  currentProgramLength++;
1612  //not exit --> RV is request type, only POST_CONFIG or POST_ROUTING remains
1613  opcodeProgram[currentProgramLength] = OP_BUFFER_TO_ROUTING;
1614  programMask[currentProgramLength] = POST_ROUTING;
1615  currentProgramLength++;
1616  //if done --> send reply
1617  opcodeProgram[currentProgramLength] = OP_UPDATE_HTTP_STATE;
1618  programMask[currentProgramLength] = OPRV_DONE | OPRV_FAIL;
1619  currentProgramLength++;
1620  opcodeProgram[currentProgramLength] = OP_HANDLE_HTTP;
1621  programMask[currentProgramLength] = OPRV_OK;
1622  currentProgramLength++;
1623  opcodeProgram[currentProgramLength] = OP_SEND_TCP_SESS;
1624  programMask[currentProgramLength] = OPRV_DONE;
1625  currentProgramLength++;
1626  opcodeProgram[currentProgramLength] = OP_SEND_BUFFER_TCP;
1627  programMask[currentProgramLength] = OPRV_DONE;
1628  currentProgramLength++;
1629  opcodeProgram[currentProgramLength] = OP_EXIT;
1630  programMask[currentProgramLength] = OPRV_DONE;
1631  currentProgramLength++;
1632  //here neither routing not complete or post config
1633  //in all cases: we need continuous TCP and expect a payload
1634  opcodeProgram[currentProgramLength] = OP_ACTIVATE_CONT_TCP;
1635  programMask[currentProgramLength] = MASK_ALWAYS;
1636  currentProgramLength++;
1637  opcodeProgram[currentProgramLength] = OP_TCP_RX_STOP_ON_EOP;
1638  programMask[currentProgramLength] = MASK_ALWAYS;
1639  currentProgramLength++;
1640  opcodeProgram[currentProgramLength] = OP_COPY_REQTYPE_TO_RETURN;
1641  programMask[currentProgramLength] = OPRV_SKIPPED;
1642  currentProgramLength++;
1643  //if routing --> we need more data (and erase the RV)
1644  opcodeProgram[currentProgramLength] = OP_OK;
1645  programMask[currentProgramLength] = POST_ROUTING;
1646  currentProgramLength++;
1647  opcodeProgram[currentProgramLength] = OP_EXIT;
1648  programMask[currentProgramLength] = OPRV_OK;
1649  currentProgramLength++;
1650  //now, it is POST configure
1651  opcodeProgram[currentProgramLength] = OP_ACTIVATE_DECOUP;
1652  programMask[currentProgramLength] = OPRV_SKIPPED;
1653  currentProgramLength++;
1654  // we lost the information of DONE in the RV, but it is also stored in last_xmem_page_received_persistent or in detected_http_nl_cnt
1655  opcodeProgram[currentProgramLength] = OP_FIFO_TO_HWICAP;
1656  programMask[currentProgramLength] = OPRV_OK;
1657  currentProgramLength++;
1658  opcodeProgram[currentProgramLength] = OP_ENABLE_SILENT_SKIP;
1659  programMask[currentProgramLength] = MASK_ALWAYS;
1660  currentProgramLength++;
1661  opcodeProgram[currentProgramLength] = OP_EXIT; //we have smth left to do
1662  programMask[currentProgramLength] = OPRV_OK | OPRV_NOT_COMPLETE;
1663  currentProgramLength++;
1664  //Reconfiguration done
1665  opcodeProgram[currentProgramLength] = OP_DEACTIVATE_DECOUP;
1666  programMask[currentProgramLength] = OPRV_DONE;
1667  currentProgramLength++;
1668  opcodeProgram[currentProgramLength] = OP_CLEAR_ROUTING_TABLE;
1669  programMask[currentProgramLength] = OPRV_DONE;
1670  currentProgramLength++;
1671  opcodeProgram[currentProgramLength] = OP_UPDATE_HTTP_STATE;
1672  programMask[currentProgramLength] = OPRV_DONE;
1673  currentProgramLength++;
1674  opcodeProgram[currentProgramLength] = OP_HANDLE_HTTP;
1675  programMask[currentProgramLength] = OPRV_OK;
1676  currentProgramLength++;
1677  opcodeProgram[currentProgramLength] = OP_SEND_TCP_SESS;
1678  programMask[currentProgramLength] = OPRV_DONE;
1679  currentProgramLength++;
1680  opcodeProgram[currentProgramLength] = OP_SEND_BUFFER_TCP;
1681  programMask[currentProgramLength] = OPRV_DONE;
1682  currentProgramLength++;
1683  opcodeProgram[currentProgramLength] = OP_DEACTIVATE_CONT_TCP;
1684  programMask[currentProgramLength] = OPRV_DONE;
1685  currentProgramLength++;
1686  opcodeProgram[currentProgramLength] = OP_DISABLE_SILENT_SKIP;
1687  programMask[currentProgramLength] = OPRV_DONE;
1688  currentProgramLength++;
1689  opcodeProgram[currentProgramLength] = OP_EXIT;
1690  programMask[currentProgramLength] = OPRV_DONE;
1691  currentProgramLength++;
1692  opcodeProgram[currentProgramLength] = OP_DISABLE_SILENT_SKIP;
1693  programMask[currentProgramLength] = MASK_ALWAYS;
1694  currentProgramLength++;
1695  //if fail --> abort
1696  opcodeProgram[currentProgramLength] = OP_ABORT_HWICAP;
1697  programMask[currentProgramLength] = OPRV_FAIL;
1698  currentProgramLength++;
1699  opcodeProgram[currentProgramLength] = OP_UPDATE_HTTP_STATE;
1700  programMask[currentProgramLength] = OPRV_OK;
1701  currentProgramLength++;
1702  opcodeProgram[currentProgramLength] = OP_HANDLE_HTTP;
1703  programMask[currentProgramLength] = OPRV_OK;
1704  currentProgramLength++;
1705  opcodeProgram[currentProgramLength] = OP_SEND_TCP_SESS;
1706  programMask[currentProgramLength] = OPRV_DONE;
1707  currentProgramLength++;
1708  opcodeProgram[currentProgramLength] = OP_SEND_BUFFER_TCP;
1709  programMask[currentProgramLength] = OPRV_DONE;
1710  currentProgramLength++;
1711  opcodeProgram[currentProgramLength] = OP_DEACTIVATE_CONT_TCP;
1712  programMask[currentProgramLength] = OPRV_DONE;
1713  currentProgramLength++;
1714  //restore RV
1715  opcodeProgram[currentProgramLength] = OP_FAIL;
1716  programMask[currentProgramLength] = OPRV_DONE;
1717  currentProgramLength++;
1718  opcodeProgram[currentProgramLength] = OP_EXIT;
1719  programMask[currentProgramLength] = OPRV_FAIL;
1720  currentProgramLength++;
1721  //in all other cases: we need to wait for data
1722  opcodeProgram[currentProgramLength] = OP_OK;
1723  programMask[currentProgramLength] = OPRV_SKIPPED;
1724  currentProgramLength++;
1725  break;
1726 
1727  case GLOBAL_PYROLINK_RECV: //i.e. Coaxium to FPGA
1728  if(reset_from_psoc == 1)
1729  { //reset form counter etc. are done in GLOBAL_IDLE;
1731  //do nothing
1732  currentProgramLength = 0;
1733  //to trigger all resets
1734  iterate_again = true;
1735  break;
1736  }
1738  { // means, we have this operation done and wait for status change
1739  if(pyroRecvMode == 0)
1740  {
1742  }
1743  //do nothing else
1744  currentProgramLength=0;
1745  msg="SUC"; //maintain SUC message (for XMEM transfer)
1746  break;
1747  }
1749  {
1750  //do not change state?
1751  msg="ERR";
1752  currentProgramLength=0;
1753  break;
1754  }
1755 
1757  {
1758  opcodeProgram[currentProgramLength] = OP_XMEM_COPY_DATA;
1759  programMask[currentProgramLength] = MASK_ALWAYS;
1760  currentProgramLength++;
1761  opcodeProgram[currentProgramLength] = OP_ENABLE_SILENT_SKIP;
1762  programMask[currentProgramLength] = MASK_ALWAYS;
1763  currentProgramLength++;
1764  //done for now
1765  opcodeProgram[currentProgramLength] = OP_EXIT;
1766  programMask[currentProgramLength] = OPRV_NOT_COMPLETE | OPRV_PARTIAL_COMPLETE;
1767  currentProgramLength++;
1768  }
1769  //we have smth to write
1770  opcodeProgram[currentProgramLength] = OP_BUFFER_TO_PYROLINK;
1771  programMask[currentProgramLength] = OPRV_DONE | OPRV_OK;
1772  currentProgramLength++;
1773  //--> if receiver not ready must be handled afterwards
1774  break;
1775 
1776  case GLOBAL_PYROLINK_TRANS: //i.e. FPGA to Coaxium
1777  if(reset_from_psoc == 1)
1778  { //reset form counter etc. are done in GLOBAL_IDLE;
1780  //do nothing
1781  currentProgramLength = 0;
1782  //to trigger all resets
1783  iterate_again = true;
1784  break;
1785  }
1787  { // means, we have this operation done and wait for status change
1788  if(pyroReadReq == 0)
1789  {
1791  }
1792  //do nothing else
1793  currentProgramLength=0;
1794  pyroSendRequestBit = 0; //signal OPRV_DONE
1795  break;
1796  }
1798  {
1800  {
1801  msg = "NOC";
1802  } else {
1803  msg="ERR";
1804  }
1805  currentProgramLength=0;
1806  break;
1807  }
1808 
1810  {//sender didn't send data, we wait for maximum cycles
1813  {
1814  transferError_persistent = true;
1815  msg="NOC";
1816  currentProgramLength = 0;
1817  break;
1818  }
1819  }
1820 
1821  opcodeProgram[currentProgramLength] = OP_PYROLINK_TO_OUTBUFFER;
1822  programMask[currentProgramLength] = MASK_ALWAYS;
1823  currentProgramLength++;
1824  opcodeProgram[currentProgramLength] = OP_ENABLE_SILENT_SKIP;
1825  programMask[currentProgramLength] = MASK_ALWAYS;
1826  currentProgramLength++;
1827  opcodeProgram[currentProgramLength] = OP_SEND_BUFFER_XMEM;
1828  programMask[currentProgramLength] = OPRV_OK | OPRV_DONE;
1829  currentProgramLength++;
1830  opcodeProgram[currentProgramLength] = OP_EXIT;
1831  programMask[currentProgramLength] = OPRV_OK | OPRV_DONE;
1832  currentProgramLength++;
1833  //something isn't done -> leaves OPRV_NOT_COMPLETE and OPRV_FAIL for handling
1834 
1835  break;
1836 
1838  //currentProgramLength = 0;
1839  //toDecoup_persistent = 1;, no, with programms...
1840 
1841  opcodeProgram[0] = OP_ACTIVATE_DECOUP;
1842  programMask[0] = MASK_ALWAYS;
1843  currentProgramLength = 1;
1844 
1845  if(manuallyToDecoup == 0)
1846  {
1848  opcodeProgram[0] = OP_DEACTIVATE_DECOUP;
1849  programMask[0] = MASK_ALWAYS;
1850  currentProgramLength = 1;
1851  }
1852  break;
1853 
1854  }
1855  }
1856 
1857  // ++++++++++++++++++ HANDLE TCP (before executing the plan) ++++++++++++++++
1858 
1859  if(tcpModeEnabled == 1)
1860  {
1861 //#pragma HLS dataflow interval=1 FIXME: causes Vivado HLS 2017.4 to crash...
1862 
1863  switch(fsmTcpSessId_RX) {
1864 
1865  default:
1866  case TCP_FSM_RESET:
1868  break;
1869  case TCP_FSM_IDLE:
1870  //just stay here
1871  break;
1872 
1873  case TCP_FSM_W84_START:
1875  //no break;
1876  case TCP_FSM_PROCESS_DATA:
1877  if(!siNAL_Tcp_SessId.empty())
1878  {
1879  //we assume that the NRC always sends a valid pair of SessId and data (because we control it)
1880  AppMeta tmp = 0x0;
1881  if(siNAL_Tcp_SessId.read_nb(tmp))
1882  {
1885  }
1886  }
1887  break;
1888  case TCP_FSM_DONE:
1889  // just stay here?
1890  break;
1891  }
1892 
1893  switch(fsmTcpSessId_TX) {
1894 
1895  default:
1896  case TCP_FSM_RESET:
1898  currentTcpSessId = 0;
1899  break;
1900  case TCP_FSM_IDLE:
1901  //just stay here
1902  break;
1903 
1904  case TCP_FSM_W84_START:
1906  //no break;
1907  case TCP_FSM_PROCESS_DATA:
1908  if(!soNAL_Tcp_SessId.full())
1909  {
1910  if(soNAL_Tcp_SessId.write_nb(currentTcpSessId))
1911  {
1913  }
1914  }
1915  break;
1916  case TCP_FSM_DONE:
1917  // just stay here?
1918  break;
1919  }
1920 
1921  switch(fsmTcpData_RX) {
1922 
1923  default:
1924  case TCP_FSM_RESET:
1926  break;
1927  case TCP_FSM_IDLE:
1928  //just stay here
1929  break;
1930 
1931  case TCP_FSM_W84_START:
1933  //no break;
1934  case TCP_FSM_PROCESS_DATA:
1935  for(int f = 0; f<IN_BUFFER_SIZE; f++)
1936  {
1937  //if ICAP is blocking, we can't do much...
1938  if( internal_icap_fifo.full() )
1939  {
1940  break;
1941  }
1943  {
1944  printf("try to empty overflow buffer\n");
1945  int new_write_index = 0;
1946  bool once_blocked = false;
1947  for(int i =0; i < fifo_overflow_buffer_length; i++)
1948  {
1949  if(once_blocked || !internal_icap_fifo.write_nb(fifo_overflow_buffer[i]) )
1950  {
1951  once_blocked = true;
1952  if(i != new_write_index)
1953  {
1954  fifo_overflow_buffer[new_write_index] = fifo_overflow_buffer[i];
1955  new_write_index++;
1956  }
1957  }
1958  }
1959  fifo_overflow_buffer_length = new_write_index;
1960  if(!once_blocked)
1961  {
1963  } else {
1964  printf("TCP RX still blocked by hwicap fifo\n");
1965  break;
1966  }
1967  }
1968  //check before we proceed...
1969  if(siNAL_Tcp_data.empty() || internal_icap_fifo.full() )
1970  {
1971  break;
1972  }
1973 
1974  NetworkWord big = NetworkWord();
1975  if(!siNAL_Tcp_data.read_nb(big))
1976  {
1977  break;
1978  }
1979 
1981  for(int i = 0; i < 8; i++)
1982  {
1983 #pragma HLS unroll factor=8
1984  if((big.tkeep >> i) == 0)
1985  {
1986  continue;
1987  }
1988  ap_uint<8> current_byte = (ap_uint<8>) (big.tdata >> i*8);
1989  if(!tcp_write_only_fifo)
1990  {
1991  bufferIn[bufferInPtrWrite] = current_byte;
1992  }
1993  if(detected_http_nl_cnt >= 1)
1994  {
1995  if(!internal_icap_fifo.write_nb(current_byte))
1996  {
2000  }
2001  tcp_words_received++; //TODO: for debugging, count words written to fifo...
2002  }
2003  if(!tcp_write_only_fifo)
2004  {
2005  if(bufferInPtrWrite >= 3)
2006  {
2007  if(bufferIn[bufferInPtrWrite] == 0xa &&
2008  bufferIn[bufferInPtrWrite -1] == 0xd &&
2009  bufferIn[bufferInPtrWrite -2] == 0xa &&
2010  bufferIn[bufferInPtrWrite -3] == 0xd )
2011  {//HTTP EOF/EOP detected
2014  printf("TCP RX: detected %d. HTTP NL at position %d\n",(int) detected_http_nl_cnt, (int) (bufferInPtrWrite - 3));
2015  }
2016  } else if (bufferInPtrMaxWrite >= 3 ) {
2017  //hangover case if _not_ just cleaned
2018  printf("bufferInPtrMaxWrite: %d\n", (int) bufferInPtrMaxWrite);
2019  uint8_t chars_to_compare[4];
2020  uint32_t position = 0;
2021  for(int j = 3; j>=0; j--)
2022  {
2023 #pragma HLS unroll factor=4
2024  int relative_buffer_in_write = ((int) bufferInPtrWrite) - j;
2025  //if( (((int) bufferInPtrWrite) -j) < 0)
2026  if(relative_buffer_in_write < 0)
2027  {
2028  assert(((3-j) >= 0) && ((j-3) < 3));
2029  chars_to_compare[3-j] = last_3_chars[3-j];
2030  } else {
2031  position = IN_BUFFER_SIZE - j + 1;
2032  //assert((bufferInPtrWrite-j) >= 0 && (bufferInPtrWrite-j) < IN_BUFFER_SIZE);
2033  assert(relative_buffer_in_write >= 0 && relative_buffer_in_write < IN_BUFFER_SIZE);
2034  assert(((3-j) >= 0) && ((j-3) < 4));
2035  //chars_to_compare[3-j] = bufferIn[bufferInPtrWrite-j];
2036  chars_to_compare[3-j] = bufferIn[relative_buffer_in_write];
2037  }
2038  }
2039  printf("chars_to_compare: 0x%02x%02x%02x%02x\n", chars_to_compare[0], chars_to_compare[1], chars_to_compare[2], chars_to_compare[3]);
2040  if(chars_to_compare[0] == 0xd && chars_to_compare[1] == 0xa &&
2041  chars_to_compare[2] == 0xd && chars_to_compare[3] == 0xa)
2042  {//HTTP EOF/EOP detected
2045  printf("TCP RX: detected %d. HTTP NL at position %d\n",(int) detected_http_nl_cnt, (int) position);
2046  }
2047  }
2048  //TODO: write explicit poison pill? or use 2nd http nl count?
2049  bufferInPtrWrite++;
2050  }
2051  } //inner for
2052 
2053  //tcp_words_received++; //TODO: for debugging, count words written to fifo...
2054  if(!tcp_write_only_fifo)
2055  {
2058  {
2059  //for hangover detection
2063  //we need to process first
2064  bufferInPtrWrite = 0; //TODO?
2065  tcp_write_only_fifo = true;
2066  printf("\tlast_3_chars: 0x%02x%02x%02x\n", last_3_chars[0], last_3_chars[1], last_3_chars[2]);
2067  break;
2068  }
2069  }
2070 
2073  {
2075  break;
2076  }
2077  } //outer loop
2078  printf("after TCP RX: bufferInPtrWrite %d; bufferInPtrMaxWrite %d;\n", (int) bufferInPtrWrite, (int) bufferInPtrMaxWrite);
2079  break;
2080  case TCP_FSM_DONE:
2081  // just stay here?
2082  break;
2083  case TCP_FSM_ERROR:
2084  //TODO
2085  break;
2086  }
2087 
2088  switch(fsmTcpData_TX) {
2089 
2090  default:
2091  case TCP_FSM_RESET:
2093  break;
2094  case TCP_FSM_IDLE:
2095  //just stay here
2096  break;
2097 
2098  case TCP_FSM_W84_START:
2100  //no break;
2101  case TCP_FSM_PROCESS_DATA:
2102  //if(!soNAL_Tcp_data.full())
2103  run_nested_loop_helper = true;
2104  while(!soNAL_Tcp_data.full() && run_nested_loop_helper)
2105  {
2106  //out = NetworkWord();
2108  out.tdata = 0;
2109  out.tlast = 0;
2110  out.tkeep = 0;
2111 
2112  for(int i = 0; i < 8; i++)
2113  {
2114 #pragma HLS unroll
2115  out.tdata |= ((ap_uint<64>) (bufferOut[bufferOutPtrNextRead + i]) )<< (i*8);
2116  out.tkeep |= (ap_uint<8>) 0x1 << i;
2117 
2119  {
2120  out.tlast = 1;
2122  break;
2123  }
2124 
2125  }
2126  if(soNAL_Tcp_data.write_nb(out))
2127  {
2128  bufferOutPtrNextRead += 8;
2129  //break while
2130  if(out.tlast == 1)
2131  {
2132  run_nested_loop_helper = false;
2133  break;
2134  }
2135  } else {
2136  run_nested_loop_helper = false;
2137  break;
2138  }
2139  } //while
2140  //else {
2141  // printf("\t ----------- soNAL_Tcp_data is full -----------");
2142  //}
2143  break;
2144  case TCP_FSM_DONE:
2145  // just stay here?
2146  break;
2147  }
2148 
2149  printf("fsmTcpSessId_RX: %d; \tfsmTcpSessId_TX %d\n", fsmTcpSessId_RX, fsmTcpSessId_TX);
2150  printf("fsmTcpData_RX: %d; \tfsmTcpData_TX %d\n", fsmTcpData_RX, fsmTcpData_TX);
2151  }
2152 
2153 
2154  // ++++++++++++++++++ HWICAP TCP FSM ++++++++++++++++++++
2155 
2156  switch(fsmHwicap)
2157  {
2158  default:
2159  case ICAP_FSM_RESET:
2161  case ICAP_FSM_IDLE:
2162  //just stay here?
2163  break;
2164 
2165  case ICAP_FSM_WRITE:
2166  {
2167  if( EOS != 1)
2168  {//HWICAP is not accessible
2170  break;
2171  }
2172  CR_isWriting = CR_value & CR_WRITE;
2173  if (CR_isWriting != 1 && flag_enable_fake_hwicap == 0)
2174  {
2176  }
2177  //get current FIFO vaccancies
2178  WFV = HWICAP[WFV_OFFSET];
2179  WFV_value = WFV & 0x7FF;
2180  uint32_t max_words_to_write = WFV_value;
2181  printf("HWICAP FSM: max_words_to_write %d\n", (int) max_words_to_write);
2182  for(int f = 0; f<IN_BUFFER_SIZE; f++)
2183  {
2184  //if(internal_icap_fifo.empty())
2185  //we can't do anything if both are empty...
2186  if(internal_icap_fifo.empty() && icap_hangover_fifo.empty() )
2187  {
2188  break;
2189  }
2190  if(max_words_to_write == 0)
2191  {
2192 #ifndef __SYNTHESIS__
2194  { //for the csim, we need to break in all cases
2195  break;
2196  }
2197 #endif
2198  if(flag_enable_fake_hwicap == 0)
2199  {
2200  //update FIFO vaccancies
2201  WFV = HWICAP[WFV_OFFSET];
2202  WFV_value = WFV & 0x7FF;
2203  }
2204  max_words_to_write = WFV_value;
2205  printf("UPDATE: max_words_to_write %d\n", (int) max_words_to_write);
2206  if(max_words_to_write == 0)
2207  {
2208  break;
2209  }
2210  }
2211  uint8_t bytes_read[4];
2212  uint8_t bytes_read_count = 0;
2213  while(!icap_hangover_fifo.empty())
2214  {
2215  uint8_t read_var = 0x0;
2216  if(icap_hangover_fifo.read_nb(read_var))
2217  {
2218  bytes_read[bytes_read_count] = read_var;
2219  bytes_read_count++;
2220  } else {
2221  break;
2222  }
2223  }
2224  while( (bytes_read_count < 4) && !internal_icap_fifo.empty() )
2225  {
2226  uint8_t read_var = 0x0;
2227  if(internal_icap_fifo.read_nb(read_var))
2228  {
2229  bytes_read[bytes_read_count] = read_var;
2230  bytes_read_count++;
2231  } else {
2232  break;
2233  }
2234  }
2235  if(bytes_read_count != 4)
2236  { //didn't read a full word
2237  printf("FIFO hangover bytes: 0x");
2238  for(int i = 0; i < bytes_read_count; i++)
2239  {
2240  icap_hangover_fifo.write(bytes_read[i]);
2241  printf("%02x ", (int) bytes_read[i]);
2242  }
2243  printf("\nFIFO hangover with size %d\n", (int) bytes_read_count);
2244  break;
2245  } else { //we have a full word
2246  ap_uint<32> tmp = 0;
2247  if (notToSwap == 1)
2248  {
2249  tmp |= (ap_uint<32>) bytes_read[0];
2250  tmp |= (((ap_uint<32>) bytes_read[1]) << 8);
2251  tmp |= (((ap_uint<32>) bytes_read[2]) << 16);
2252  tmp |= (((ap_uint<32>) bytes_read[3]) << 24);
2253  } else {
2254  //default
2255  tmp |= (ap_uint<32>) bytes_read[3];
2256  tmp |= (((ap_uint<32>) bytes_read[2]) << 8);
2257  tmp |= (((ap_uint<32>) bytes_read[1]) << 16);
2258  tmp |= (((ap_uint<32>) bytes_read[0]) << 24);
2259  }
2260 
2261  if ( tmp == 0x0d0a0d0a || tmp == 0x0a0d0a0d )
2262  { //is like a poison pill, we are done for today
2263  printf("HTTP NL received, treat it as Poison Pill...\n");
2265  {
2268  }
2270  break;
2272  { //we are done for today
2273  printf("Poison Pill received...\n");
2275  break;
2276  } else {
2277  if(flag_enable_fake_hwicap == 0)
2278  {
2279 #ifndef __SYNTHESIS__
2281  {
2284  }
2285  //TODO: decrement WFV value of testbench
2286  //for debugging reasons, we write it twice
2287  HWICAP[WF_OFFSET] = tmp;
2288 #else
2289  HWICAP[WF_OFFSET] = tmp;
2290 #endif
2291  } else {
2292  //we do NOT write it to HWICAP
2293  //but update the WFV
2294  WFV_value--;
2295  }
2297  max_words_to_write--;
2298  printf("writing to HWICAP: %#010x\n",(int) tmp);
2299  }
2300  }
2301  } //while
2302 
2303  WFV = HWICAP[WFV_OFFSET];
2304  WFV_value = WFV & 0x7FF;
2305  if (WFV_value >= HWICAP_FIFO_DEPTH && (WFV_value != max_words_to_write) )
2306  {
2307  fifoEmptyCnt++;
2308  //TODO: re-iterate again?
2309  }
2310 
2311  if(WFV_value <= HWICAP_FIFO_NEARLY_FULL_TRIGGER)
2312  {
2313  fifoFullCnt++;
2314  }
2315  }
2316  break;
2317 
2318  case ICAP_FSM_DONE:
2319  //stay here
2320  break;
2321  case ICAP_FSM_ERROR:
2322  //stay here
2323  break;
2324  case ICAP_FSM_DRAIN:
2325  while(!internal_icap_fifo.empty())
2326  {
2327  internal_icap_fifo.read();
2328  }
2329  while(!icap_hangover_fifo.empty())
2330  {
2331  icap_hangover_fifo.read();
2332  }
2334  break;
2335  }
2336  printf("fsmHwicap: %d\n", fsmHwicap);
2337  // ++++++++++++++++++ EXECUTE THE PLAN ++++++++++++++++
2338 
2339  lastReturnValue = OPRV_OK; //allow the first operation to be executed
2340 
2341  //reset flags
2343  flag_silent_skip = 0;
2344 
2345  printf("currentProgramLength: %d\n", (int) currentProgramLength);
2346  printf("currentGlobalOperation: %d\n", (int) currentGlobalOperation);
2347  assert(currentProgramLength < MAX_PROGRAM_LENGTH);
2348 
2349 
2350  //progLoop:
2351  for(uint8_t progCnt = 0; progCnt < currentProgramLength; progCnt++)
2352  {
2353  OprvType currentMask = programMask[progCnt];
2354  OpcodeType currentOpcode = opcodeProgram[progCnt];
2355  printf("PC %d, lst RV %d, opcode %d\n", (int) progCnt, (int) lastReturnValue, (int) currentOpcode);
2356 
2357  OprvType mask_result = currentMask & lastReturnValue;
2358  if(((uint8_t) mask_result) == 0)
2359  {//i.e. we skip this command
2360  if(flag_silent_skip == 0)
2361  {
2362  lastReturnValue = OPRV_SKIPPED;
2363  }
2364  printf("[%d] operation skipped (silent: %d)\n", (int) progCnt, (int) flag_silent_skip);
2365  continue;
2366  }
2367 
2368 
2369  switch(currentOpcode)
2370  {
2371 
2372  default: //NO Break
2373  case OP_NOP: //we do nothing, also leave return value untouched
2374  break;
2375 
2378  lastReturnValue = OPRV_OK;
2379  break;
2380 
2383  lastReturnValue = OPRV_OK;
2384  break;
2385 
2386  case OP_ENABLE_SILENT_SKIP:
2387  flag_silent_skip = 1;
2388  break;
2389 
2391  flag_silent_skip = 0;
2392  break;
2393 
2394  case OP_SET_NOT_TO_SWAP:
2395  notToSwap = 1;
2396  break;
2397 
2398  case OP_UNSET_NOT_TO_SWAP:
2399  notToSwap = 0; //default
2400  break;
2401 
2402  case OP_XMEM_COPY_DATA: //sensitive to FLAG check pattern
2404  //explicit overflow
2405  expCnt = xmem_page_trans_cnt + 1;
2406  if (xmem_page_trans_cnt == 0xf)
2407  {
2408  expCnt = 0;
2409  }
2410  copyRet = copyAndCheckBurst(xmem,expCnt, lastPageCnt_in);
2411 
2412  switch (copyRet) {
2413  default:
2414  case 0:
2415  msg = "UTD"; //Up To Date
2416  lastReturnValue = OPRV_NOT_COMPLETE;
2417  break;
2418  case 1:
2419  msg = "INV"; //Invalid
2420  //We are in the middle of a page transfer
2421  lastReturnValue = OPRV_PARTIAL_COMPLETE;
2422  break;
2423  case 2:
2424  msg = "CMM"; //Counter MisMatch
2425  lastReturnValue = OPRV_FAIL;
2426  break;
2427  case 3:
2428  msg = "COR"; //Corrupt pattern
2429  lastReturnValue = OPRV_FAIL;
2430  break;
2431  case 4:
2432  //we received a lastpage
2433  msg = "SUC"; //success
2434  xmem_page_trans_cnt = expCnt;
2436  lastReturnValue = OPRV_DONE;
2437  break;
2438  case 5: //we received a page, but not the last one
2439  msg= " OK";
2440  xmem_page_trans_cnt = expCnt;
2441  lastReturnValue = OPRV_OK;
2442  break;
2443  }
2444  break;
2445 
2446  case OP_TCP_CNT_RESET:
2447  goto_done_if_idle_tcp_rx = false;
2449  //we reset HTTP EOF detection
2451  target_http_nl_cnt = 0;
2452  for(int i = 0; i < 3; i++)
2453  {
2454 #pragma HLS unroll
2455  last_3_chars[i] = 0x0;
2457  }
2458  tcp_write_only_fifo = false;
2459  break;
2460 
2461  case OP_WAIT_FOR_TCP_SESS:
2463  {
2465  {
2467  lastReturnValue = OPRV_NOT_COMPLETE;
2470  {
2471  lastReturnValue = OPRV_OK;
2473  tcp_words_received = 0;
2474  } else {//we still wait
2475  lastReturnValue = OPRV_NOT_COMPLETE;
2476  }
2477  } else {
2478  lastReturnValue = OPRV_OK;
2479  }
2480  break;
2481 
2482  case OP_ACTIVATE_CONT_TCP:
2484  goto_done_if_idle_tcp_rx = false;
2486  {
2488  }
2489  break;
2490 
2493  target_http_nl_cnt = 0;
2494  goto_done_if_idle_tcp_rx = true;
2495  break;
2496 
2497  case OP_TCP_RX_STOP_ON_EOR:
2498  target_http_nl_cnt = 1;
2499  break;
2500 
2501  case OP_TCP_RX_STOP_ON_EOP:
2502  target_http_nl_cnt = 2;
2503  break;
2504 
2505  case OP_FILL_BUFFER_TCP:
2507  {
2508  goto_done_if_idle_tcp_rx = false;
2510  lastReturnValue = OPRV_NOT_COMPLETE;
2511  } else if(fsmTcpData_RX == TCP_FSM_DONE)
2512  {
2513  lastReturnValue = OPRV_DONE;
2516  && !tcp_write_only_fifo //this isn't increasing the counter
2518  )
2519  { //nothing new
2520  lastReturnValue = OPRV_NOT_COMPLETE;
2521  //printf("tcp_write_only_fifo: %d\n", (int) tcp_write_only_fifo);
2522  } else {
2523  //looks like we get something
2524  //or stuff is still left for processing
2525  lastReturnValue = OPRV_OK;
2526  }
2527  //in any case
2529  break;
2530 
2531  case OP_HANDLE_HTTP:
2532  {
2533  //TODO: break in multiple opcodes?
2534  printf("httpState bevore parseHTTP: %d\n",httpState);
2535  bool rx_done = false;
2536  if(lastReturnValue == OPRV_DONE)
2537  {
2538  rx_done = true;
2539  }
2540 
2542 
2543  printf("reqType after parseHTTP: %d\n", reqType);
2544 
2545  switch (httpState) {
2546  case HTTP_IDLE:
2547  lastReturnValue = OPRV_OK;
2548  break;
2549  case HTTP_PARSE_HEADER:
2550  lastReturnValue = OPRV_OK;
2551  break;
2552  case HTTP_HEADER_PARSED:
2553 
2555  {//corner case
2557  lastReturnValue = OPRV_NOT_COMPLETE;
2558  } else {
2559  lastReturnValue = OPRV_PARTIAL_COMPLETE;
2560  }
2561  //TODO: start of bitfile must be aligned to 4?? do in sender??
2562  break;
2563  case HTTP_READ_PAYLOAD:
2564  // Do nothing?
2565  lastReturnValue = OPRV_PARTIAL_COMPLETE;
2566  break;
2567  case HTTP_REQUEST_COMPLETE:
2569  // no break??
2570  case HTTP_SEND_RESPONSE:
2571  lastReturnValue = OPRV_USER;
2572  break;
2573  case HTTP_INVALID_REQUEST:
2574  //no break
2575  case HTTP_DONE:
2576  lastReturnValue = OPRV_DONE;
2577  break;
2578  }
2579  }
2580  break;
2581 
2582  case OP_UPDATE_HTTP_STATE:
2583  if(lastReturnValue == OPRV_FAIL)
2584  {
2586  }
2587  if(wasAbort == 1 || transferError_persistent == true || invalidPayload_persistent == true)
2588  {
2590  }
2591  if(lastReturnValue == OPRV_DONE)
2592  {
2594  }
2595  lastReturnValue = OPRV_OK;
2596  break;
2597 
2598  case OP_CHECK_HTTP_EOR:
2599  if(detected_http_nl_cnt >= 1)
2600  {
2601  lastReturnValue = OPRV_DONE;
2602  } else {
2603  lastReturnValue = OPRV_NOT_COMPLETE;
2604  }
2605  break;
2606 
2607  case OP_CHECK_HTTP_EOP:
2608  if(detected_http_nl_cnt >= 2)
2609  {
2610  lastReturnValue = OPRV_DONE;
2611  } else {
2612  lastReturnValue = OPRV_NOT_COMPLETE;
2613  }
2614  break;
2615 
2617  lastReturnValue = reqType;
2618  break;
2619 
2620  case OP_BUFFER_TO_HWICAP:
2621  {
2622  if (EOS != 1)
2623  {//HWICAP is not accessible
2624  msg = "INR";
2625  lastReturnValue = OPRV_FAIL;
2626  break;
2627  }
2628  uint32_t maxPayloadWrite = 0;
2629  if(bufferInPtrMaxWrite >= 4)
2630  {
2631  maxPayloadWrite = bufferInPtrMaxWrite - 3;
2632  }
2634  {
2635  if(detected_http_nl_cnt >= 2
2637  {
2638  maxPayloadWrite = positions_of_detected_http_nl[1] - 4; //-4, becauese we have <= in the for
2639  lastReturnValue = OPRV_DONE;
2640  printf("STOP at 2. HTTP NL\n");
2641  }
2642 
2643  }
2644  //printf("Writing Buffer to HWICAP from %d to %d (including); notToSwap = %d, max_bytes_to_write: %d, write_iteration: %d, read_iteration: %d\n", (int) bufferInPtrNextRead, (int) maxPayloadWrite,(int) notToSwap, (int) max_bytes_to_write,(int) bufferIn_write_iteration_cnt, (int) bufferIn_read_iteration_cnt);
2645  printf("Writing Buffer to HWICAP from %d to %d (including); notToSwap = %d\n", (int) bufferInPtrNextRead, (int) maxPayloadWrite,(int) notToSwap);
2646  ap_uint<32> old_bufferInPtrNextRead = bufferInPtrNextRead;
2647  ap_uint<32> old_wordsWrittenToIcapCnt = wordsWrittenToIcapCnt;
2648  //for(i = bufferInPtrNextRead; i <= maxPayloadWrite; i += 4)
2649  uint32_t i = bufferInPtrNextRead;
2650  //while(i <= maxPayloadWrite) //we have substracted -3, so <=
2651  while(i <= maxPayloadWrite && maxPayloadWrite > 0) //we have substracted -3, so <=
2652  {
2653  ap_uint<32> tmp = 0;
2654 
2656  && i == 0) //only for first iteration, if bufferInPtrNextRead = 0
2657  {
2658  for(int j = 0; j < 4; j++)
2659  {
2660 #pragma HLS unroll factor=4
2661  if( notToSwap == 1)
2662  {
2663  if(j - (((int) hwicap_hangover_size) -1) <= 0)
2664  {//from hangover bytes
2665  tmp |= (((ap_uint<32>) buffer_hangover_bytes[j]) << 8*j);
2666  } else {//from buffer
2667  tmp |= (((ap_uint<32>) bufferIn[j - hwicap_hangover_size]) << 8*j); //actually -1 + 1...
2668  }
2669  } else { //default
2670  if(j - (((int) hwicap_hangover_size) -1) <= 0)
2671  {//from hanover bytes
2672  tmp |= (((ap_uint<32>) buffer_hangover_bytes[j]) << 8*(3-j));
2673  } else {//from buffer
2674  assert((j - hwicap_hangover_size) >= 0);
2675  tmp |= (((ap_uint<32>) bufferIn[j - hwicap_hangover_size]) << 8*(3-j)); //actually -1 + 1...
2676  }
2677  }
2678  }
2679  hwicap_hangover_present = false;
2680  i += 4 - hwicap_hangover_size;
2681  printf("hangover of size %d inserted.\n", (int) hwicap_hangover_size);
2682  } else {
2683  if (notToSwap == 1)
2684  {
2685  tmp |= (ap_uint<32>) bufferIn[i + 0];
2686  tmp |= (((ap_uint<32>) bufferIn[i + 1]) << 8);
2687  tmp |= (((ap_uint<32>) bufferIn[i + 2]) << 16);
2688  tmp |= (((ap_uint<32>) bufferIn[i + 3]) << 24);
2689  } else {
2690  //default
2691  tmp |= (ap_uint<32>) bufferIn[i + 3];
2692  tmp |= (((ap_uint<32>) bufferIn[i + 2]) << 8);
2693  tmp |= (((ap_uint<32>) bufferIn[i + 1]) << 16);
2694  tmp |= (((ap_uint<32>) bufferIn[i + 0]) << 24);
2695  }
2696  i += 4;
2697  }
2698 
2699  if ( tmp == 0x0d0a0d0a || tmp == 0x0a0d0a0d )
2700  { //in theory, should never happen...
2701  printf("Error: Tried to write 0d0a0d0a.\n");
2702  writeErrCnt++;
2703  //continue;
2704  } else {
2705 #ifndef __SYNTHESIS__
2707  {
2710  }
2711  //for debugging reasons, we write it twice
2712  HWICAP[WF_OFFSET] = tmp;
2713 #else
2714  HWICAP[WF_OFFSET] = tmp;
2715 #endif
2717  printf("writing to HWICAP: %#010x\n",(int) tmp);
2718  }
2719  } //while
2720 
2721  // printf("bufferInPtrMaxWrite: %d\n", (int) bufferInPtrMaxWrite);
2722  // printf("bufferInPtrNextRead: %d\n", (int) bufferInPtrNextRead);
2723  // printf("wordsWrittenToIcapCnt: %d\n", (int) wordsWrittenToIcapCnt);
2724 
2725  CR_isWriting = CR_value & CR_WRITE;
2726  if (CR_isWriting != 1)
2727  {
2729  }
2730 
2731 
2732  bufferInPtrNextRead = i; //no +4, since it is done as last step in the loop
2733  printf("bufferInPtrNextRead: %d\n", (int) bufferInPtrNextRead);
2734  printf("bufferInPtrMaxWrite: %d\n", (int) bufferInPtrMaxWrite);
2735  //printf("bufferInPtrMaxWrite_old_iteration: %d\n", (int) bufferInPtrMaxWrite_old_iteration);
2736  printf("bufferInPtrWrite: %d\n", (int) bufferInPtrWrite);
2737 
2738  WFV = HWICAP[WFV_OFFSET];
2739  WFV_value = WFV & 0x7FF;
2740  //if (WFV_value == 0x7FF)
2741  if (WFV_value >= HWICAP_FIFO_DEPTH && (bufferInPtrNextRead > old_bufferInPtrNextRead))
2742  {
2743  //printf("FIFO is unexpected empty\n");
2744  fifoEmptyCnt++;
2745  }
2746 
2747  if(WFV_value <= HWICAP_FIFO_NEARLY_FULL_TRIGGER)
2748  {
2749  fifoFullCnt++;
2750  }
2751 
2752 
2754  {
2756  {//should always hit even pages....
2757  if (parseHTTP == 1)
2758  {
2759  ap_int<5> telomere = bufferInPtrMaxWrite - bufferInPtrNextRead + 1; //+1 because MaxWrite is already filled (not next write)
2760  printf("telomere: %d\n", (int) telomere);
2761 
2762  if (telomere != 0)
2763  {
2764  for(int j = 0; j<telomere; j++)
2765  {
2767  }
2768  bufferInPtrWrite = telomere;
2769  }
2770  if (telomere < 0)
2771  {
2772  printf("ERROR negativ telomere!\n");
2773  writeErrCnt++;
2774  }
2775  }
2776 
2777  bufferInPtrNextRead = 0;
2778  }
2779  }
2780 
2782  {
2783  //check for hangover
2785  {
2786  ap_int<5> telomere = bufferInPtrMaxWrite - bufferInPtrNextRead + 1; //+1 because MaxWrite is already filled (not next write)
2787  printf("telomere: %d\n", (int) telomere);
2788  assert(telomere >= 0 && telomere < 4);
2790  if(telomere > 0 && telomere < 4)
2791  {
2792  printf("hangover bytes: 0x");
2793  for(int j = 0; j<telomere; j++)
2794  {
2796  printf("%02x ",(int) buffer_hangover_bytes[j]);
2797  }
2798  hwicap_hangover_present = true;
2799  hwicap_hangover_size = telomere;
2800  printf("\nBuffer hangover with size %d\n", (int) hwicap_hangover_size);
2801  } else if(telomere != 0)
2802  { //in theory, should never happen
2803  printf("invalid telomere count!\n");
2804  writeErrCnt++;
2805  }
2806  //in all cases
2807  bufferInPtrNextRead = 0;
2808  }
2809  }
2810  printf("after UPDATE bufferInPtrNextRead: %d\n", (int) bufferInPtrNextRead);
2811 
2812  if(lastReturnValue == OPRV_DONE || last_xmem_page_received_persistent == 1)
2813  { //pass done
2814  lastReturnValue = OPRV_DONE;
2815  } else if(bufferInPtrNextRead == old_bufferInPtrNextRead)
2816  {
2817  lastReturnValue = OPRV_NOT_COMPLETE;
2818  } else {
2819  lastReturnValue = OPRV_OK;
2820  }
2821  }
2822  break;
2823 
2824  case OP_FIFO_TO_HWICAP:
2825  if(fsmHwicap == ICAP_FSM_IDLE)
2826  {
2829  lastReturnValue = OPRV_NOT_COMPLETE;
2830  printf("started HWICAP FIFO FSM");
2831  } else if(fsmHwicap == ICAP_FSM_DONE)
2832  {
2833  //now, wait for HWICAP
2834  CR = HWICAP[CR_OFFSET];
2835  CR_value = CR & 0x1F;
2836  CR_isWriting = CR_value & CR_WRITE;
2837  WFV = HWICAP[WFV_OFFSET];
2838  WFV_value = WFV & 0x7FF;
2839  if(WFV_value < 0x3FF && CR_isWriting != 1 && flag_enable_fake_hwicap == 0)
2840  {
2841  lastReturnValue = OPRV_NOT_COMPLETE;
2843  } else {
2844  lastReturnValue = OPRV_DONE;
2847  }
2848  } else if(fsmHwicap == ICAP_FSM_ERROR || fsmHwicap == ICAP_FSM_DRAIN)
2849  {
2850  lastReturnValue = OPRV_FAIL;
2853  } else {
2854  //we are doing smth
2855  lastReturnValue = OPRV_OK;
2856  }
2857  break;
2858 
2859  case OP_BUFFER_TO_PYROLINK:
2860 #ifdef INCLUDE_PYROLINK
2861  //TODO handle swapping / Big Endiannes?
2862 
2863  if(*disable_pyro_link == 0) //to avoid blocking...
2864  {
2865  if(lastReturnValue == OPRV_DONE || last_xmem_page_received_persistent == 1)
2866  { //pass done
2867  lastReturnValue = OPRV_DONE;
2868  } else {
2869  lastReturnValue = OPRV_OK; //overwrite later if necessary
2870  }
2871 
2872  //printf("OP_BUFFER_TO_PYROLINK: bufferInPtrNextRead %d, bufferInPtrMaxWrite %d\n", (int) bufferInPtrNextRead, (int) bufferInPtrMaxWrite);
2873  uint32_t i = 0;
2874  for(i = bufferInPtrNextRead; i <= bufferInPtrMaxWrite; i++)
2875  {
2876  if(!soPYROLINK.full())
2877  {
2878  Axis<8> tmp = Axis<8>(bufferIn[i]);
2879  tmp.tkeep = 1;
2880  if( last_xmem_page_received_persistent == 1 && i == bufferInPtrMaxWrite ) //not -1, because both is 0 based
2881  {
2882  tmp.tlast = 1;
2883  //no break necessary, this should anyway be the last rount
2884  } else {
2885  tmp.tlast = 0;
2886  }
2887 
2888  soPYROLINK.write(tmp);
2889 
2890  } else {
2891  lastReturnValue = OPRV_NOT_COMPLETE;
2892  //TODO: must we i--?
2893  break;
2894  }
2895  }
2896  bufferInPtrNextRead = i;
2897  } else {
2898  lastReturnValue = OPRV_FAIL;
2899  }
2900 #endif
2901  break;
2902 
2903  case OP_BUFFER_TO_ROUTING:
2904  if (*disable_ctrl_link == 0)
2905  {
2907 
2908  int i = bufferInPtrNextRead;
2910 
2911  need_to_update_nrc_mrt = true;
2912 
2913  if(bodyLen > 0)
2914  { //body is complete here
2915  maxWhile = bufferInPtrNextRead + bodyLen; //bodyLen is WITHOUT the actual footer
2916  lastReturnValue = OPRV_DONE;
2918  } else {
2919  lastReturnValue = OPRV_NOT_COMPLETE;
2920  }
2921 
2922  printf("nextRead: %d, maxWhile %d, notToSwap %d\n", i, maxWhile, (int) notToSwap);
2923 
2924  while(i<maxWhile)
2925  {
2926  char* intStart = (char*) &bufferIn[i];
2927  int intLen = my_wordlen(intStart);
2928  if(i + intLen + 1 + 4 + 1> bufferInPtrMaxWrite) //1: space, 4: IPv4 address 1: \n (now we know the actual length)
2929  {
2930  //TODO
2931  break;
2932  }
2933  //looks like complete line is here
2934  ap_uint<32> rankID = (unsigned int) my_atoi(intStart, intLen);
2935  printf("intLen: %d, rankdID: %d\n", intLen, (unsigned int) rankID);
2936  i += intLen;
2937  i++; //space
2938  ap_uint<32> tmp = 0;
2939 
2940  if ( notToSwap == 1)
2941  {
2942  tmp |= (ap_uint<32>) bufferIn[i + 0];
2943  tmp |= (((ap_uint<32>) bufferIn[i + 1]) << 8);
2944  tmp |= (((ap_uint<32>) bufferIn[i + 2]) << 16);
2945  tmp |= (((ap_uint<32>) bufferIn[i + 3]) << 24);
2946  } else {
2947  //default
2948  tmp |= (ap_uint<32>) bufferIn[i + 3];
2949  tmp |= (((ap_uint<32>) bufferIn[i + 2]) << 8);
2950  tmp |= (((ap_uint<32>) bufferIn[i + 1]) << 16);
2951  tmp |= (((ap_uint<32>) bufferIn[i + 0]) << 24);
2952  }
2953  i+= 4;
2954 
2955  i++; //newline
2956 
2957  if(rankID >= MAX_CLUSTER_SIZE)
2958  { //ignore and return 422
2960  lastReturnValue = OPRV_DONE;
2961  need_to_update_nrc_mrt = false;
2963  printf("invalid routing table detected.\n");
2964  break;
2965  }
2966  //dont' check for current cluster size!
2967  //it could be that the CFRM want's to override the entries of removed nodes
2968 
2969  //transfer to NRC:
2970  current_MRT[rankID] = tmp;
2971  if(rankID > max_discovered_node_id)
2972  {
2973  max_discovered_node_id = rankID;
2974  printf("max_discovered_node_id: %d\n", (int) max_discovered_node_id);
2975  }
2976  //lastaddressWrittenToNRC = tmp;
2977  //lastNIDWrittentoNRC = rankID;
2978  printf("writing on address %d to NRC: %#010x\n",(unsigned int) rankID, (int) tmp);
2979  }
2980 
2981  bufferInPtrNextRead = i; //NOT i + x, because that is already done by the for loop!
2982  //return value already set!
2983  } else {
2984  lastReturnValue = OPRV_FAIL;
2985  transferError_persistent = true;
2986  }
2987  break;
2988 
2990  need_to_update_nrc_mrt = true;
2992  for(int i = 0; i < max_discovered_node_id; i++)
2993  {
2994  current_MRT[i] = 0x0;
2995  }
2996  //lastReturnValue unchanged
2997  break;
2998 
3000 #ifdef INCLUDE_PYROLINK
3001  if(*disable_pyro_link == 0)
3002  {
3003  int i = 0;
3004  if(!siPYROLINK.empty())
3005  {
3006  lastReturnValue = OPRV_OK; //overwrite if necessary
3007 
3008  //printf("bufferOutPtrWrite: %d\n", (int) bufferOutPtrWrite);
3009 
3010  for(i = bufferOutPtrWrite; i<IN_BUFFER_SIZE; i++)
3011  {
3012  if(!siPYROLINK.empty())
3013  {
3014  Axis<8> tmp = siPYROLINK.read();
3015  if (tmp.tkeep != 1)
3016  {//skip it
3017  i--;
3018  continue;
3019  }
3020  bufferOut[bufferOutPtrWrite + i] = tmp.tdata;
3021  if(tmp.tlast == 1)
3022  {
3023  lastReturnValue = OPRV_DONE;
3024  break;
3025  }
3026  }
3027  }
3028  bufferOutPtrWrite += i + 1; //where to write NEXT
3029  bufferOutContentLength = bufferOutPtrWrite; //still plus 1, because it's a length
3030  } else {
3031  //we didn't receive anything
3032  lastReturnValue = OPRV_NOT_COMPLETE;
3033  }
3034 
3035  } else {
3036  lastReturnValue = OPRV_FAIL;
3037  }
3038 #endif
3039  break;
3040 
3041  case OP_SEND_TCP_SESS:
3042  //if we are in an OPRV_DONE "state": we just start the TX FSM and then go to "success"
3043  //the global state will wait until all TCP FSMs are done before it starts over
3044  //The TX FSMs block on sending, after the FMC ISA finished...so this OP-code is for triggering the FSM to start to work
3046  {
3048  {
3050  if(lastReturnValue != OPRV_DONE)
3051  {
3052  lastReturnValue = OPRV_NOT_COMPLETE;
3053  }
3054  } else if(fsmTcpSessId_TX == TCP_FSM_DONE)
3055  {
3056  if(lastReturnValue != OPRV_DONE)
3057  {
3058  lastReturnValue = OPRV_OK;
3059  }
3063  } else {//we still wait
3064  if(lastReturnValue != OPRV_DONE)
3065  {
3066  lastReturnValue = OPRV_NOT_COMPLETE;
3067  }
3068  }
3069  } else {
3070  if(lastReturnValue != OPRV_DONE)
3071  {
3072  lastReturnValue = OPRV_OK;
3073  }
3074  }
3075  break;
3076 
3077  case OP_SEND_BUFFER_TCP:
3078  //if we are in an OPRV_DONE "state": we just start the TX FSM and then go to "success"
3079  //the global state will wait until all TCP FSMs are done before it starts over
3080  //The TX FSMs block on sending, after the FMC ISA finished...so this OP-code is for triggering the FSM to start to work
3082  {
3084  if(lastReturnValue != OPRV_DONE)
3085  {
3086  lastReturnValue = OPRV_NOT_COMPLETE;
3087  }
3088  } else if(fsmTcpData_TX == TCP_FSM_DONE)
3089  {
3091  lastReturnValue = OPRV_DONE;
3093  {//looks like there are no news
3094  if(lastReturnValue != OPRV_DONE)
3095  {
3096  lastReturnValue = OPRV_NOT_COMPLETE;
3097  }
3098  } else {
3099  if(lastReturnValue != OPRV_DONE)
3100  {
3101  lastReturnValue = OPRV_OK;
3102  }
3103  }
3105  break;
3106 
3107  case OP_SEND_BUFFER_XMEM:
3108  {
3109  uint8_t pageCnt = bytesToPages(bufferOutContentLength, true);
3110  copyOutBuffer(pageCnt,xmem);
3111 
3112  if(lastReturnValue == OPRV_DONE)
3113  { //pass done
3114  lastReturnValue = OPRV_DONE;
3115  } else {
3116  lastReturnValue = OPRV_OK;
3117  }
3118  }
3119  break;
3120 
3121  case OP_CLEAR_IN_BUFFER:
3122  emptyInBuffer();
3123  lastReturnValue = OPRV_OK;
3124  break;
3125 
3126  case OP_CLEAR_OUT_BUFFER:
3127  emptyOutBuffer();
3128  lastReturnValue = OPRV_OK;
3129  break;
3130 
3131  case OP_ACTIVATE_DECOUP:
3132  toDecoup_persistent = 1;
3133  lastReturnValue = OPRV_OK;
3134  break;
3135 
3136  case OP_DEACTIVATE_DECOUP:
3137  toDecoup_persistent = 0;
3138  if(lastReturnValue == OPRV_DONE)
3139  { //pass done
3140  lastReturnValue = OPRV_DONE;
3141  } else {
3142  lastReturnValue = OPRV_OK;
3143  }
3144  break;
3145 
3146  case OP_ABORT_HWICAP:
3148  transferError_persistent = true;
3149  wasAbort = 1;
3150  lastReturnValue = OPRV_OK;
3151  break;
3152 
3153  case OP_FAIL:
3154  lastReturnValue = OPRV_FAIL;
3155  break;
3156 
3157  case OP_DONE:
3158  lastReturnValue = OPRV_DONE;
3159  //break progLoop; //does this work?
3160  break;
3161 
3162  case OP_OK:
3163  lastReturnValue = OPRV_OK;
3164  break;
3165 
3166  case OP_EXIT:
3167  //lastReturnValue unchanged
3168  progCnt = MAX_PROGRAM_LENGTH;
3169  break;
3170 
3171  } //switch
3172  } //prog loop
3173 
3174 
3175  // ++++++++++++++++++ UPDATE OPERATIONS ++++++++++++++++
3176 
3177  switch(currentGlobalOperation)
3178  {
3179  default: //no break, just for default
3180  case GLOBAL_IDLE:
3181  //nothing to do
3182  break;
3183 
3185  //OPRV_NOT_COMPLETE, OPRV_PARTIAL_COMPLETE --> continue
3186  if(lastReturnValue == OPRV_DONE)
3187  {//received last page
3188  //Displays are set in daily task
3189  //ATTENTION: we only change state if input changes
3191  } else if(lastReturnValue == OPRV_FAIL)
3192  {
3193  transferError_persistent = true;
3194  }
3195  break;
3196 
3197  case GLOBAL_XMEM_TO_HWICAP:
3198  if(lastReturnValue == OPRV_DONE)
3199  {//looks like we are done
3200  //Displays are set in daily task
3202  }
3203  if(lastReturnValue == OPRV_FAIL)
3204  {
3205  transferError_persistent = true;
3206  }
3207  break;
3208 
3209  case GLOBAL_XMEM_HTTP:
3210  if(lastReturnValue == OPRV_DONE)
3211  {//looks like we are done
3212  //Displays are set in daily taksk
3214  }
3215  if(lastReturnValue == OPRV_FAIL)
3216  {
3217  transferError_persistent = true;
3218  }
3219  break;
3220 
3221  case GLOBAL_TCP_HTTP:
3222  // continue in this mode when HTTP_IDLE and environment not changed
3223  if(lastReturnValue == OPRV_DONE)
3224  {//looks like we are done
3225  //Displays are set in daily taksk
3227  msg="SUC";
3228  }
3229  if(lastReturnValue == OPRV_FAIL)
3230  {
3231  transferError_persistent = true;
3232  msg="ERR";
3233  }
3234  if(lastReturnValue == OPRV_NOT_COMPLETE)
3235  {
3236  msg="WAT";
3237  }
3238  if(globalOperationDone_persistent && (lastReturnValue != OPRV_DONE))
3239  {//we wait for the TCP FSM's to finish..
3240  msg="WFF";
3241  }
3242  break;
3243 
3244  case GLOBAL_PYROLINK_RECV: //i.e. Coaxium to FPGA
3245  if(lastReturnValue == OPRV_DONE)
3246  {//looks like we are done
3247  //Displays are set in daily tasks
3249  }
3250  if(lastReturnValue == OPRV_FAIL)
3251  {
3252  transferError_persistent = true;
3253  }
3254  if(lastReturnValue == OPRV_NOT_COMPLETE)
3255  {
3257  } else {
3259  }
3260  break;
3261 
3262  case GLOBAL_PYROLINK_TRANS: //i.e. FPGA to Coaxium
3263  if(lastReturnValue == OPRV_DONE)
3264  {//looks like we are done
3265  //Displays are set in daily tasks
3267  pyroSendRequestBit = 0;
3268  }
3269  if(lastReturnValue == OPRV_FAIL)
3270  {
3271  transferError_persistent = true;
3272  }
3273  if(lastReturnValue == OPRV_NOT_COMPLETE)
3274  {
3276  } else {
3278  }
3279  //OPRV_OK --> we need another round
3280  break;
3281 
3283  //nothing to do
3284  break;
3285  }
3286 
3287 
3288  // ++++++++++++++++++ EVERY-DAY JOBS ++++++++++++++++++++
3289 
3290  if( wasAbort == 1)
3291  { //Abort occured in previous cycle
3292  msg = "ABR";
3293  }
3294 
3295  // SOFT RESET
3296  *setSoftReset = (MMIO_in_LE >> SOFT_RST_SHIFT) & 0b1;
3297 
3298  //===========================================================
3299  // Decoupling
3300 
3301  if ( toDecoup_persistent == 1 || wasAbort == 1)
3302  {
3303  *setDecoup = 0b1;
3304 } else {
3305  *setDecoup = 0b0;
3306 }
3307 
3308 //===========================================================
3309 // Set RANK and SIZE
3310 
3311 *role_rank = nodeRank;
3313 
3314 
3315 //===========================================================
3316 // connection to NRC
3317 
3318 //to not overwrite NRC updates
3319 if((*disable_ctrl_link == 0) && (*layer_4_enabled == 0) && tables_initialized )
3320 {
3321  //reset of NTS closes ports
3325  need_to_update_nrc_config = false; //the NRC know this too
3326 }
3327 
3328 if((*disable_ctrl_link == 0) && (*layer_6_enabled == 1) && tables_initialized //to avoid blocking...
3329  && !fifo_operation_in_progress //to avoid delays of PR
3330  )
3331 { //and we need valid tables
3332 
3333  nal_status_disabled = false;
3334 
3335  switch (linkCtrlFSM)
3336  {
3337  case LINKFSM_IDLE:
3340  {
3342  }
3344  break;
3345 
3346  case LINKFSM_WAIT:
3348  {
3350  }
3351  else if(need_to_update_nrc_mrt)
3352  {
3353  mrt_copy_index = 0;
3355  }
3357  {
3360  }
3361  break;
3362 
3363  case LINKFSM_UPDATE_CONFIG:
3364  //e.g. to recover from a reset
3369  need_to_update_nrc_config = false;
3371  break;
3372 
3373  case LINKFSM_UPDATE_MRT:
3374  printf("linkFSM: updating entry %d with value 0x%08x; max_discovered_node_id: %d\n",(int) mrt_copy_index, (int) current_MRT[mrt_copy_index], (int) max_discovered_node_id);
3376  mrt_copy_index++;
3377 
3379  {
3381  need_to_update_nrc_mrt = false;
3383  }
3384  break;
3385 
3386  case LINKFSM_UPDATE_STATE:
3390  {
3392  {
3393  need_to_update_nrc_mrt = true;
3394  need_to_update_nrc_config = true; //better to do both
3396  }
3398  {
3401  } else {
3403  }
3404  }
3405  break;
3407  //indicies don't match: need to to manually
3412  break;
3413  }
3414  printf("ctrlLINK FSM: %d\n", linkCtrlFSM);
3415 
3416  } else {
3417  //ctrlLink disabled
3418  //hex for "DISABLED"
3419  nal_status_disabled = true;
3420  nal_status[0] = 0x44495341;
3421  nal_status[1] = 0x424c4544;
3422  }
3423 
3424 
3425  //===========================================================
3426  // putting displays together
3427 
3428 
3429  ap_uint<4> Dsel = 0;
3430 
3431  Dsel = (MMIO_in_LE >> DSEL_SHIFT) & 0xF;
3432 
3433  Display1 = (WEMPTY << WEMPTY_SHIFT) | (HWICAP_Done << DONE_SHIFT) | EOS;
3434  Display1 |= WFV_value << WFV_V_SHIFT;
3435  Display1 |= ((ap_uint<32>) decoupStatus) << DECOUP_SHIFT;
3436  Display1 |= ((ap_uint<32>) tcpModeEnabled) << TCP_OPERATION_SHIFT;
3437  Display1 |= ((ap_uint<32>) ASW1) << ASW1_SHIFT;
3438  Display1 |= ((ap_uint<32>) CR_value) << CMD_SHIFT;
3439 
3440  Display2 = ((ap_uint<32>) ASW2) << ASW2_SHIFT;
3441  Display2 |= ((ap_uint<32>) ASW3) << ASW3_SHIFT;
3442  Display2 |= ((ap_uint<32>) ASW4) << ASW4_SHIFT;
3443  Display2 |= ((ap_uint<32>) notToSwap) << NOT_TO_SWAP_SHIFT;
3444 
3445  Display3 = ((ap_uint<32>) xmem_page_trans_cnt) << RCNT_SHIFT;
3446  Display3 |= ((ap_uint<32>) msg[0]) << MSG_SHIFT + 16;
3447  Display3 |= ((ap_uint<32>) msg[1]) << MSG_SHIFT + 8;
3448  Display3 |= ((ap_uint<32>) msg[2]) << MSG_SHIFT + 0;
3449 
3450  Display4 = ((ap_uint<32>) responePageCnt) << ANSWER_LENGTH_SHIFT;
3452  Display4 |= ((ap_uint<32>) writeErrCnt) << WRITE_ERROR_CNT_SHIFT;
3453  Display4 |= ((ap_uint<32>) fifoEmptyCnt) << EMPTY_FIFO_CNT_SHIFT;
3454  Display4 |= ((ap_uint<32>) currentGlobalOperation) << GLOBAL_STATE_SHIFT;
3455 
3456  Display5 = (ap_uint<32>) wordsWrittenToIcapCnt;
3457 
3461  Display6 |= ((ap_uint<32>) pyroSendRequestBit) << PYRO_SEND_REQUEST_SHIFT;
3462 
3463  Display7 = ((ap_uint<32>) fsmTcpSessId_RX) << RX_SESS_STATE_SHIFT;
3464  Display7 |= ((ap_uint<32>) fsmTcpData_RX) << RX_DATA_STATE_SHIFT;
3465  Display7 |= ((ap_uint<32>) fsmTcpSessId_TX) << TX_SESS_STATE_SHIFT;
3466  Display7 |= ((ap_uint<32>) fsmTcpData_TX) << TX_DATA_STATE_SHIFT;
3467  Display7 |= ((ap_uint<32>) tcp_iteration_count) << TCP_ITER_COUNT_SHIFT;
3468  Display7 |= ((ap_uint<32>) detected_http_nl_cnt) << DETECTED_HTTPNL_SHIFT;
3469 
3470  Display8 = (ap_uint<32>) tcp_words_received;
3471 
3472  Display9 = (bufferInPtrMaxWrite & 0x000FFFFF) << BUFFER_IN_MAX_SHIFT;
3473  Display9 |= ((ap_uint<32>) fifoFullCnt) << FULL_FIFO_CNT_SHIFT;
3474  Display9 |= ((ap_uint<32>) fsmHwicap) << ICAP_FSM_SHIFT;
3475 
3476  ap_uint<32> MMIO_out_LE = 0x0;
3477 
3478  switch (Dsel) {
3479  case 1:
3480  MMIO_out_LE = (0x1 << DSEL_SHIFT) | Display1;
3481  break;
3482  case 2:
3483  MMIO_out_LE = (0x2 << DSEL_SHIFT) | Display2;
3484  break;
3485  case 3:
3486  MMIO_out_LE = (0x3 << DSEL_SHIFT) | Display3;
3487  break;
3488  case 4:
3489  MMIO_out_LE = (0x4 << DSEL_SHIFT) | Display4;
3490  break;
3491  case 5:
3492  MMIO_out_LE = (0x5 << DSEL_SHIFT) | Display5;
3493  break;
3494  case 6:
3495  MMIO_out_LE = (0x6 << DSEL_SHIFT) | Display6;
3496  break;
3497  case 7:
3498  MMIO_out_LE = (0x7 << DSEL_SHIFT) | Display7;
3499  break;
3500  case 8:
3501  MMIO_out_LE = (0x8 << DSEL_SHIFT) | Display8;
3502  break;
3503  case 9:
3504  MMIO_out_LE = (0x9 << DSEL_SHIFT) | Display9;
3505  break;
3506  default:
3507  MMIO_out_LE = 0xBEBAFECA;
3508  break;
3509  }
3510 
3511  ap_uint<32> MMIO_out_BE = 0x0;
3512  MMIO_out_BE = (ap_uint<32>) ((MMIO_out_LE >> 24) & 0xFF);
3513  MMIO_out_BE |= (ap_uint<32>) ((MMIO_out_LE >> 8) & 0xFF00);
3514  MMIO_out_BE |= (ap_uint<32>) ((MMIO_out_LE << 8) & 0xFF0000);
3515  MMIO_out_BE |= (ap_uint<32>) ((MMIO_out_LE << 24) & 0xFF000000);
3516 
3517  *MMIO_out = MMIO_out_BE;
3518 
3519  return;
3520 }
3521 
3522 
#define CFDK_VERSION_STRING
Definition: cfdk.hpp:30
#define SIZE_SHIFT
Definition: fmc.hpp:72
#define RST_SHIFT
Definition: fmc.hpp:107
#define OPRV_USER
Definition: fmc.hpp:188
#define OUT_BUFFER_SIZE
Definition: fmc.hpp:133
ap_uint< 1 > flag_check_xmem_pattern
Definition: fmc.cpp:129
#define DECOUP_SHIFT
Definition: fmc.hpp:48
ap_uint< 1 > nts_ready
Definition: tb_fmc.cpp:69
#define DONE_SHIFT
Definition: fmc.hpp:46
uint8_t fsmTcpSessId_TX
Definition: fmc.cpp:137
#define LAST_PAGE_WRITE_CNT_SHIFT
Definition: fmc.hpp:73
#define FPGA_STATE_LAYER_4
Definition: fmc.hpp:215
uint8_t currentGlobalOperation
Definition: fmc.cpp:111
#define PYRO_MODE_SHIFT
Definition: fmc.hpp:115
int my_wordlen(char *s)
Definition: http.cpp:63
ap_uint< 8 > writeErrCnt
Definition: fmc.cpp:39
#define RANK_SHIFT
Definition: fmc.hpp:71
#define DETECTED_HTTPNL_SHIFT
Definition: fmc.hpp:82
#define LINES_PER_PAGE
Definition: fmc.hpp:122
#define LAST_PAGE_CNT_SHIFT
Definition: fmc.hpp:119
bool process_fifo_overflow_buffer
Definition: fmc.cpp:49
uint32_t positions_of_detected_http_nl[4]
Definition: fmc.cpp:148
uint8_t bufferOut[1024]
Definition: fmc.cpp:59
uint16_t bufferOutContentLength
Definition: fmc.cpp:61
ap_uint< 4 > received_TCP_SessIds_cnt
Definition: fmc.cpp:142
uint8_t buffer_hangover_bytes[3]
Definition: fmc.cpp:151
uint8_t reqType
Definition: http.cpp:284
bool run_nested_loop_helper
Definition: fmc.cpp:140
uint16_t lastSeenBufferOutPtrNextRead
Definition: fmc.cpp:63
AppMeta currentTcpSessId
Definition: fmc.cpp:122
#define OP_CLEAR_OUT_BUFFER
Definition: fmc.hpp:251
ap_uint< 1 > layer_7_enabled
Definition: tb_fmc.cpp:68
#define RX_SESS_STATE_SHIFT
Definition: fmc.hpp:77
void copyOutBuffer(ap_uint< 4 > numberOfPages, ap_uint< 32 > xmem[(32 *16)])
Definition: fmc.cpp:201
#define POST_ROUTING
Definition: http.hpp:44
ap_uint< 1 > disable_pyro_link
Definition: tb_fmc.cpp:92
ap_uint< 28 > tcp_words_received
Definition: fmc.cpp:76
#define ICAP_FSM_IDLE
Definition: fmc.hpp:203
#define PARSE_HTTP_SHIFT
Definition: fmc.hpp:113
ap_uint< 8 > nts_tcp_crc_drop_cnt
Definition: fmc.cpp:103
#define OP_HANDLE_HTTP
Definition: fmc.hpp:242
#define OP_BUFFER_TO_PYROLINK
Definition: fmc.hpp:246
#define OP_TCP_RX_STOP_ON_EOP
Definition: fmc.hpp:272
ap_uint< 1 > last_xmem_page_received_persistent
Definition: fmc.cpp:131
#define TX_SESS_STATE_SHIFT
Definition: fmc.hpp:79
#define OP_BUFFER_TO_ROUTING
Definition: fmc.hpp:247
uint8_t fsmHwicap
Definition: fmc.cpp:46
ap_uint< 4 > copyAndCheckBurst(ap_uint< 32 > xmem[(32 *16)], ap_uint< 4 > ExpCnt, ap_uint< 7 > lastPageCnt_in)
Definition: fmc.cpp:464
#define HTTP_REQUEST_COMPLETE
Definition: fmc.hpp:162
#define OP_DISABLE_XMEM_CHECK_PATTERN
Definition: fmc.hpp:253
ap_uint< 8 > nts_tcp_notif_drop_cnt
Definition: fmc.cpp:100
#define BYTES_PER_PAGE
Definition: fmc.hpp:125
#define OP_COPY_REQTYPE_TO_RETURN
Definition: fmc.hpp:259
#define IcapFsmState
Definition: fmc.hpp:208
bool nal_status_disabled
Definition: fmc.cpp:85
#define OP_DONE
Definition: fmc.hpp:252
uint8_t linkCtrlFSM
Definition: fmc.cpp:162
uint8_t fsmTcpData_RX
Definition: fmc.cpp:138
#define CHECK_CTRL_LINK_INTERVAL_SECONDS
Definition: fmc.hpp:223
uint32_t bufferInPtrWrite
Definition: fmc.cpp:53
#define OP_DEACTIVATE_DECOUP
Definition: fmc.hpp:255
#define OprvType
Definition: fmc.hpp:181
#define CR_WRITE
Definition: fmc.hpp:141
ap_uint< 8 > nts_tcp_meta_drop_cnt
Definition: fmc.cpp:101
#define OP_SEND_BUFFER_XMEM
Definition: fmc.hpp:249
ap_uint< 32 > clusterSize
Definition: fmc.cpp:79
#define OP_ACTIVATE_CONT_TCP
Definition: fmc.hpp:269
#define OP_BUFFER_TO_HWICAP
Definition: fmc.hpp:245
stream< uint8_t > icap_hangover_fifo("sIcapHangoverFifo")
#define REQ_INVALID
Definition: http.hpp:39
#define HTTP_HEADER_PARSED
Definition: fmc.hpp:160
#define TCP_ITER_COUNT_SHIFT
Definition: fmc.hpp:81
ap_uint< 8 > fifoFullCnt
Definition: fmc.cpp:41
ap_uint< 32 > Display7
Definition: fmc.cpp:74
#define XMEM_SIZE
Definition: fmc.hpp:124
bool tcp_write_only_fifo
Definition: fmc.cpp:57
#define OP_ENABLE_XMEM_CHECK_PATTERN
Definition: fmc.hpp:239
#define OP_TCP_CNT_RESET
Definition: fmc.hpp:273
#define OP_NOP
Definition: fmc.hpp:238
ap_uint< 32 > Display1
Definition: fmc.cpp:74
#define OP_CLEAR_ROUTING_TABLE
Definition: fmc.hpp:275
#define GLOBAL_XMEM_CHECK_PATTERN
Definition: fmc.hpp:170
ap_uint< 1 > flag_silent_skip
Definition: fmc.cpp:130
#define GLOBAL_XMEM_TO_HWICAP
Definition: fmc.hpp:171
#define FULL_FIFO_CNT_SHIFT
Definition: fmc.hpp:89
#define OP_WAIT_FOR_TCP_SESS
Definition: fmc.hpp:265
ap_uint< 32 > max_discovered_node_id
Definition: fmc.cpp:163
#define ENABLE_TCP_MODE_SHIFT
Definition: fmc.hpp:117
#define FPGA_STATE_CONFIG_UPDATE
Definition: fmc.hpp:218
ap_uint< 1 > disable_ctrl_link
Definition: tb_fmc.cpp:91
#define HTTP_IDLE
Definition: fmc.hpp:158
ap_uint< 32 > nal_status[16]
Definition: fmc.cpp:84
#define XMEM_ANSWER_START
Definition: fmc.hpp:134
ap_uint< 32 > mrt_copy_index
Definition: fmc.cpp:90
#define OP_DEACTIVATE_CONT_TCP
Definition: fmc.hpp:270
bool fifo_operation_in_progress
Definition: fmc.cpp:47
#define GLOBAL_PYROLINK_RECV
Definition: fmc.hpp:174
#define OP_SEND_TCP_SESS
Definition: fmc.hpp:266
ap_uint< 16 > current_role_mmio
Definition: fmc.cpp:93
#define FPGA_STATE_MRT_UPDATE
Definition: fmc.hpp:219
ap_uint< 32 > ctrl_link_next_check_seconds
Definition: fmc.cpp:88
#define ICAP_FSM_DONE
Definition: fmc.hpp:205
#define SOFT_RST_SHIFT
Definition: fmc.hpp:114
int my_atoi(char *str, int strlen)
Definition: http.cpp:177
void emptyInBuffer()
Definition: fmc.cpp:217
#define HTTP_SEND_RESPONSE
Definition: fmc.hpp:163
#define RCNT_SHIFT
Definition: fmc.hpp:60
#define PYRO_READ_REQUEST_SHIFT
Definition: fmc.hpp:116
#define HWICAP_FIFO_NEARLY_FULL_TRIGGER
Definition: fmc.hpp:145
ap_uint< 8 > nts_tcp_ooo_drop_cnt
Definition: fmc.cpp:105
#define LinkFsmStateType
Definition: fmc.hpp:232
#define OP_ABORT_HWICAP
Definition: fmc.hpp:256
#define CMD_SHIFT
Definition: fmc.hpp:49
ap_uint< 8 > nts_tcp_data_drop_cnt
Definition: fmc.cpp:102
#define WFV_OFFSET
Definition: fmc.hpp:96
#define WF_OFFSET
Definition: fmc.hpp:100
bool transferError_persistent
Definition: fmc.cpp:114
#define ASW3_SHIFT
Definition: fmc.hpp:55
bool TcpSessId_updated_persistent
Definition: fmc.cpp:123
#define ISR_OFFSET
Definition: fmc.hpp:95
ap_uint< 1 > flag_enable_fake_hwicap
Definition: fmc.cpp:133
uint8_t fsmTcpSessId_RX
Definition: fmc.cpp:136
#define SWAP_N_SHIFT
Definition: fmc.hpp:111
#define ASW4_SHIFT
Definition: fmc.hpp:56
void setRank(ap_uint< 32 > newRank)
Definition: fmc.cpp:451
#define TcpFsmState
Definition: fmc.hpp:199
#define ICAP_FSM_RESET
Definition: fmc.hpp:202
#define MASK_ALWAYS
Definition: fmc.hpp:189
ap_uint< 32 > MMIO_out_BE
Definition: tb_fmc.cpp:65
ap_uint< 32 > Display6
Definition: fmc.cpp:74
#define TCP_FSM_ERROR
Definition: fmc.hpp:197
void parseHttpInput(bool transferErr, ap_uint< 1 > wasAbort, bool invalidPayload, bool rx_done)
Definition: http.cpp:401
#define BUFFER_IN_MAX_SHIFT
Definition: fmc.hpp:88
#define CHECK_PATTERN_SHIFT
Definition: fmc.hpp:112
ap_uint< 8 > fpga_status[8]
Definition: fmc.cpp:87
#define LINKFSM_UPDATE_MRT
Definition: fmc.hpp:228
#define OP_EXIT
Definition: fmc.hpp:260
ap_uint< 8 > fifoEmptyCnt
Definition: fmc.cpp:40
#define GLOBAL_MANUAL_DECOUPLING
Definition: fmc.hpp:176
#define GLOBAL_STATE_SHIFT
Definition: fmc.hpp:68
ap_uint< 1 > flag_continuous_tcp_rx
Definition: fmc.cpp:132
#define MAX_PAGES
Definition: fmc.hpp:123
uint8_t httpState
Definition: fmc.cpp:72
#define POST_CONFIG
Definition: http.hpp:40
ap_uint< 8 > nal_status_request_cnt
Definition: fmc.cpp:83
ap_uint< 32 > fpga_time_hours
Definition: fmc.cpp:97
#define ICAP_FIFO_POISON_PILL
Definition: fmc.hpp:209
#define GLOBAL_TCP_HTTP
Definition: fmc.hpp:173
#define OP_XMEM_COPY_DATA
Definition: fmc.hpp:240
#define TCP_FSM_PROCESS_DATA
Definition: fmc.hpp:195
ap_uint< 32 > xmem[(32 *16)]
Definition: tb_fmc.cpp:89
#define OP_FILL_BUFFER_TCP
Definition: fmc.hpp:241
#define TX_DATA_STATE_SHIFT
Definition: fmc.hpp:80
#define HWICAP_FIFO_DEPTH
Definition: fmc.hpp:143
int writeString(char *s)
Definition: http.cpp:76
#define OP_ACTIVATE_DECOUP
Definition: fmc.hpp:254
ap_uint< 32 > current_nrc_config[16]
Definition: fmc.cpp:158
#define LINKFSM_UPDATE_SAVED_STATE
Definition: fmc.hpp:231
stream< uint8_t > internal_icap_fifo("sInternalIcapFifo")
ap_uint< 1 > layer_4_enabled
Definition: tb_fmc.cpp:66
#define OPRV_OK
Definition: fmc.hpp:182
bool streaming_mode_persistent
Definition: fmc.cpp:113
void fmc(ap_uint< 32 > *MMIO_in, ap_uint< 32 > *MMIO_out, ap_uint< 1 > *layer_4_enabled, ap_uint< 1 > *layer_6_enabled, ap_uint< 1 > *layer_7_enabled, ap_uint< 1 > *nts_ready, ap_uint< 32 > *in_time_seconds, ap_uint< 32 > *in_time_minutes, ap_uint< 32 > *in_time_hours, ap_uint< 16 > *role_mmio_in, ap_uint< 16 > *uoe_drop_cnt_in, ap_uint< 8 > *toe_notif_drop_cnt_in, ap_uint< 8 > *toe_meta_drop_cnt_in, ap_uint< 8 > *toe_data_drop_cnt_in, ap_uint< 8 > *toe_crc_drop_cnt_in, ap_uint< 8 > *toe_sess_drop_cnt_in, ap_uint< 8 > *toe_ooo_drop_cnt_in, ap_uint< 32 > *HWICAP, ap_uint< 1 > decoupStatus, ap_uint< 1 > *setDecoup, ap_uint< 1 > *setSoftReset, ap_uint< 32 > xmem[(32 *16)], ap_uint< 32 > nalCtrl[(0x3ff/4)], ap_uint< 1 > *disable_ctrl_link, stream< TcpWord > &siNAL_Tcp_data, stream< AppMeta > &siNAL_Tcp_SessId, stream< TcpWord > &soNAL_Tcp_data, stream< AppMeta > &soNAL_Tcp_SessId, ap_uint< 32 > *role_rank, ap_uint< 32 > *cluster_size)
Definition: fmc.cpp:564
int writeUnsignedLong(unsigned long num, uint8_t base)
Definition: http.cpp:119
#define ICAP_FSM_DRAIN
Definition: fmc.hpp:207
#define TCP_FSM_RESET
Definition: fmc.hpp:192
#define MAX_PROGRAM_LENGTH
Definition: fmc.hpp:278
#define HTTP_PARSE_HEADER
Definition: fmc.hpp:159
#define PAYLOAD_BYTES_PER_PAGE
Definition: fmc.hpp:126
ap_uint< 32 > Display4
Definition: fmc.cpp:74
#define OP_SET_NOT_TO_SWAP
Definition: fmc.hpp:267
#define MSG_SHIFT
Definition: fmc.hpp:61
#define ASW2_SHIFT
Definition: fmc.hpp:54
#define ENABLE_FAKE_HWICAP_SHIFT
Definition: fmc.hpp:118
#define OPRV_DONE
Definition: fmc.hpp:187
#define TCP_FSM_W84_START
Definition: fmc.hpp:194
#define LINKFSM_UPDATE_CONFIG
Definition: fmc.hpp:229
#define ICAP_FSM_SHIFT
Definition: fmc.hpp:90
#define LINKFSM_WAIT
Definition: fmc.hpp:227
ap_uint< 32 > current_nrc_mrt_version
Definition: fmc.cpp:159
#define OP_TCP_RX_STOP_ON_EOR
Definition: fmc.hpp:271
ap_uint< 1 > tcpModeEnabled
Definition: fmc.cpp:124
ap_uint< 32 > global_state_wait_counter_persistent
Definition: fmc.cpp:120
#define LINKFSM_UPDATE_STATE
Definition: fmc.hpp:230
uint32_t sequential_hwicap_address
Definition: fmc.cpp:68
#define OPRV_NOT_COMPLETE
Definition: fmc.hpp:185
bool need_to_update_nrc_config
Definition: fmc.cpp:161
#define OP_UPDATE_HTTP_STATE
Definition: fmc.hpp:258
#define IN_BUFFER_SIZE
Definition: fmc.hpp:131
ap_uint< 1 > layer_6_enabled
Definition: tb_fmc.cpp:67
ap_uint< 4 > responePageCnt
Definition: fmc.cpp:108
#define GLOBAL_IDLE
Definition: fmc.hpp:169
ap_uint< 4 > xmem_page_trans_cnt
Definition: fmc.cpp:42
#define GLOBAL_XMEM_HTTP
Definition: fmc.hpp:172
#define EMPTY_FIFO_CNT_SHIFT
Definition: fmc.hpp:67
ap_uint< 32 > Display3
Definition: fmc.cpp:74
#define ANSWER_LENGTH_SHIFT
Definition: fmc.hpp:64
bool axi_wasnot_ready_persistent
Definition: fmc.cpp:119
#define OP_SEND_BUFFER_TCP
Definition: fmc.hpp:248
#define CR_ABORT
Definition: fmc.hpp:137
bool invalidPayload_persistent
Definition: fmc.cpp:115
#define ASR_OFFSET
Definition: fmc.hpp:97
#define LINKFSM_IDLE
Definition: fmc.hpp:226
#define OPRV_FAIL
Definition: fmc.hpp:183
#define OP_CHECK_HTTP_EOR
Definition: fmc.hpp:243
uint8_t hwicap_hangover_size
Definition: fmc.cpp:153
ap_uint< 16 > nts_udp_drop_cnt
Definition: fmc.cpp:99
ap_uint< 32 > current_MRT[64]
Definition: fmc.cpp:157
#define OPRV_PARTIAL_COMPLETE
Definition: fmc.hpp:186
bool tables_initialized
Definition: fmc.cpp:156
uint16_t bufferOutPtrWrite
Definition: fmc.cpp:60
#define PYRO_SEND_REQUEST_SHIFT
Definition: fmc.hpp:74
#define TCP_FSM_IDLE
Definition: fmc.hpp:193
ap_uint< 7 > lastResponsePageCnt
Definition: fmc.cpp:107
ap_uint< 32 > nodeRank
Definition: fmc.cpp:78
uint16_t bufferOutPtrNextRead
Definition: fmc.cpp:62
#define FPGA_STATE_LAYER_7
Definition: fmc.hpp:217
#define OP_UNSET_NOT_TO_SWAP
Definition: fmc.hpp:268
ap_uint< 1 > decoupStatus
Definition: tb_fmc.cpp:82
#define DSEL_SHIFT
Definition: fmc.hpp:108
uint8_t fifo_overflow_buffer[8]
Definition: fmc.cpp:48
uint32_t bufferInPtrMaxWrite
Definition: fmc.cpp:54
ap_uint< 28 > wordsWrittenToIcapCnt
Definition: fmc.cpp:75
#define OP_PYROLINK_TO_OUTBUFFER
Definition: fmc.hpp:264
uint32_t writeDisplaysToOutBuffer()
Definition: fmc.cpp:270
#define WFV_V_SHIFT
Definition: fmc.hpp:45
#define GlobalState
Definition: fmc.hpp:178
ap_uint< 1 > toDecoup_persistent
Definition: fmc.cpp:81
ap_uint< 32 > fpga_time_seconds
Definition: fmc.cpp:95
#define ICAP_FIFO_POISON_PILL_REVERSE
Definition: fmc.hpp:210
bool globalOperationDone_persistent
Definition: fmc.cpp:118
ap_uint< 32 > MMIO_in
Definition: tb_fmc.cpp:63
uint8_t fsmTcpData_TX
Definition: fmc.cpp:139
#define WRITE_ERROR_CNT_SHIFT
Definition: fmc.hpp:66
bool need_to_update_nrc_mrt
Definition: fmc.cpp:160
#define WEMPTY_SHIFT
Definition: fmc.hpp:47
uint32_t lastSeenBufferInPtrMaxWrite
Definition: fmc.cpp:55
uint8_t fifo_overflow_buffer_length
Definition: fmc.cpp:50
#define OPRV_SKIPPED
Definition: fmc.hpp:184
uint8_t bytesToPages(int len, bool update_global_variables)
Definition: fmc.cpp:169
uint32_t bufferInPtrNextRead
Definition: fmc.cpp:56
ap_uint< 32 > HWICAP[512]
Definition: tb_fmc.cpp:86
int request_len(ap_uint< 16 > offset, int maxLength)
Definition: http.cpp:286
#define MAX_CLUSTER_SIZE
Definition: fmc.hpp:151
void setSize(ap_uint< 32 > newSize)
Definition: fmc.cpp:458
uint8_t bufferIn[4096]
Definition: fmc.cpp:52
ap_uint< 32 > fpga_time_minutes
Definition: fmc.cpp:96
ap_uint< 32 > Display8
Definition: fmc.cpp:74
#define OP_FAIL
Definition: fmc.hpp:257
#define START_SHIFT
Definition: fmc.hpp:110
#define OP_CHECK_HTTP_EOP
Definition: fmc.hpp:244
#define DECOUP_CMD_SHIFT
Definition: fmc.hpp:106
#define OP_CLEAR_IN_BUFFER
Definition: fmc.hpp:250
#define OP_OK
Definition: fmc.hpp:263
#define ICAP_FSM_ERROR
Definition: fmc.hpp:206
bool hwicap_hangover_present
Definition: fmc.cpp:152
void emptyOutBuffer()
Definition: fmc.cpp:255
ap_uint< 2 > detected_http_nl_cnt
Definition: fmc.cpp:146
#define FPGA_STATE_NTS_READY
Definition: fmc.hpp:220
#define HttpState
Definition: fmc.hpp:166
bool goto_done_if_idle_tcp_rx
Definition: fmc.cpp:141
#define OP_ENABLE_SILENT_SKIP
Definition: fmc.hpp:261
#define HTTP_READ_PAYLOAD
Definition: fmc.hpp:161
#define GLOBAL_MAX_WAIT_COUNT
Definition: fmc.hpp:282
uint8_t tcp_iteration_count
Definition: fmc.cpp:125
#define OpcodeType
Definition: fmc.hpp:237
#define HTTP_DONE
Definition: fmc.hpp:165
#define NUMBER_FPGA_STATE_REGISTERS
Definition: fmc.hpp:214
#define TCP_FSM_DONE
Definition: fmc.hpp:196
ap_uint< 32 > Display9
Definition: fmc.cpp:74
#define SR_OFFSET
Definition: fmc.hpp:94
#define GLOBAL_PYROLINK_TRANS
Definition: fmc.hpp:175
#define HTTP_STATE_SHIFT
Definition: fmc.hpp:65
#define OP_FIFO_TO_HWICAP
Definition: fmc.hpp:274
#define OP_DISABLE_SILENT_SKIP
Definition: fmc.hpp:262
#define FPGA_STATE_LAYER_6
Definition: fmc.hpp:216
#define ICAP_FSM_WRITE
Definition: fmc.hpp:204
ap_uint< 32 > Display2
Definition: fmc.cpp:74
#define NOT_TO_SWAP_SHIFT
Definition: fmc.hpp:57
ap_uint< 8 > nts_tcp_sess_drop_cnt
Definition: fmc.cpp:104
uint8_t last_3_chars[3]
Definition: fmc.cpp:145
#define ASW1_SHIFT
Definition: fmc.hpp:50
ap_uint< 32 > nalCtrl[(0x3ff/4)]
Definition: tb_fmc.cpp:90
#define CR_OFFSET
Definition: fmc.hpp:98
ap_uint< 32 > Display5
Definition: fmc.cpp:74
#define MIN_ROUTING_TABLE_LINE
Definition: fmc.hpp:154
ap_uint< 2 > target_http_nl_cnt
Definition: fmc.cpp:147
#define HTTP_INVALID_REQUEST
Definition: fmc.hpp:164
#define RX_DATA_STATE_SHIFT
Definition: fmc.hpp:78
#define TCP_OPERATION_SHIFT
Definition: fmc.hpp:51
bool use_sequential_hwicap
Definition: fmc.cpp:67
ap_uint< 32 > cluster_size
#define NUMBER_CONFIG_WORDS
Definition: nal.hpp:191
#define NAL_CTRL_LINK_SIZE
Definition: nal.hpp:82
#define NAL_CTRL_LINK_STATUS_START_ADDR
Definition: nal.hpp:85
#define NAL_STATUS_FMC_PORT_PROCESSED
Definition: nal.hpp:224
#define NAL_CONFIG_SAVED_FMC_PORTS
Definition: nal.hpp:219
#define NAL_CONFIG_SAVED_TCP_PORTS
Definition: nal.hpp:218
#define NAL_CTRL_LINK_MRT_START_ADDR
Definition: nal.hpp:87
#define NAL_STATUS_MRT_VERSION
Definition: nal.hpp:221
#define MAX_MRT_SIZE
Definition: nal.hpp:94
#define NAL_CTRL_LINK_CONFIG_START_ADDR
Definition: nal.hpp:83
#define NAL_CONFIG_SAVED_UDP_PORTS
Definition: nal.hpp:217
#define NAL_NUMBER_STATUS_WORDS
Definition: nal.hpp:194
#define NAL_STATUS_OWN_RANK
Definition: nal.hpp:225
#define NAL_CONFIG_MRT_VERSION
Definition: nal.hpp:216
#define NAL_CONFIG_OWN_RANK
Definition: nal.hpp:215
#define NAL_STATUS_OPEN_TCP_PORTS
Definition: nal.hpp:223
#define NAL_STATUS_OPEN_UDP_PORTS
Definition: nal.hpp:222
: The HTTP parsing functions for the FMC.
out
Definition: test.py:12
#define NETWORK_WORD_BYTE_WIDTH
Definition: network.hpp:45
TcpSessId AppMeta
ap_uint< 64 > tdata
Definition: network.hpp:49
ap_uint< 8 > tkeep
Definition: network.hpp:50
ap_uint< 1 > tlast
Definition: network.hpp:51