示例#1
0
        private void Send()
        {
            // Reset until they are needed
            controlB.Enabled = false;

            ////////////// BUFFER code
            // if we are receiving stuff from the memory, save it to the buffer
            if (memory_receiving)
            {
                int  buffer = buffer_calc.SaveData();
                byte data   = readResultB.Data;
                tempSendRingBuffer.data   = data;
                tempSendRingBuffer.length = buffer_calc.MetadataCurrentSaveSegment().accum_len;
                send_buffer[buffer]       = tempSendRingBuffer;
                Logging.log.Trace($"Got memory. goes to buffer:{buffer} data:0x{data:X2}");
                buffer_calc.FinishFillingCurrentSaveSegment();
                memory_receiving = false;
            }

            // If the last clock had an request, we know that the next clock has
            // to be receiving stuff.
            if (memory_requested)
            {
                memory_receiving = true;
                memory_requested = false;
            }

            // If there are no avaliable next segments, we cannot save data
            if (buffer_calc.NextSegmentReady())
            {
                // Get the address for the current focus element
                int addr = mem_calc.LoadData();

                // If we actually can get the address(If buffer empty etc)
                if (addr != -1)
                {
                    Logging.log.Trace($"Requesting memory from addr: {addr}");
                    // Request the data
                    controlB.Enabled   = true;
                    controlB.IsWriting = false;
                    controlB.Address   = addr;

                    // we now have an request from memory
                    memory_requested = true;

                    tmp_send_ip_info = mem_calc.MetadataCurrentLoadSegment();

                    tmp_send_ip_info.accum_len = (ushort)mem_calc.LoadDataBytesLeft();
                    // test if the total size is missing
                    if (tmp_send_ip_info.total_len == 0)
                    {
                        tmp_send_ip_info.total_len = tmp_send_ip_info.accum_len;
                        mem_calc.MetadataCurrentLoadSegment(tmp_send_ip_info);
                    }
                    if (tmp_send_ip_info.accum_len == 0)
                    {
                        mem_calc.FinishReadingCurrentLoadSegment();
                    }

                    // We save the metadata onto the buffer
                    buffer_calc.NextSegment(tmp_send_ip_info);
                }
            }

            ///////////// Sending code
            // They are ready, we submit stuff

            Logging.log.Info($"The load segment status: {buffer_calc.LoadSegmentReady()} ready: {packetOutBufferConsumerControlBusIn.ready}");


            packetOutBufferProducerControlBusOut.valid = buffer_calc.LoadSegmentReady();

            if (packetOutBufferConsumerControlBusIn.ready)
            {
                send_preload = true;
            }

            if (send_preload && buffer_calc.LoadSegmentReady())
            {
                int  addr       = buffer_calc.LoadData();
                byte data       = send_buffer[addr].data;
                int  bytes_left = send_buffer[addr].length;
                packetOut.data          = data;
                packetOut.ip_dst_addr_0 = buffer_calc.MetadataCurrentLoadSegment().ip_dst_addr_0;
                packetOut.ip_dst_addr_1 = buffer_calc.MetadataCurrentLoadSegment().ip_dst_addr_1;
                packetOut.ip_src_addr_0 = buffer_calc.MetadataCurrentLoadSegment().ip_src_addr_0;
                packetOut.ip_src_addr_1 = buffer_calc.MetadataCurrentLoadSegment().ip_src_addr_1;
                packetOut.frame_number  = buffer_calc.MetadataCurrentLoadSegment().frame_number;
                packetOut.data_length   = buffer_calc.MetadataCurrentLoadSegment().total_len;
                //packetOut.fragment_offset = 0;
                packetOut.ip_id    = buffer_calc.MetadataCurrentLoadSegment().ip_id;
                packetOut.protocol = buffer_calc.MetadataCurrentLoadSegment().protocol;



                packetOutBufferProducerControlBusOut.valid      = true;
                packetOutBufferProducerControlBusOut.bytes_left = (uint)bytes_left;

                buffer_calc.FinishReadingCurrentLoadSegment();

                send_preload = false;

                Logging.log.Info($"Sending: data: 0x{data:X2} " +
                                 $"buffer_addr: {addr} " +
                                 $"bytes left: {bytes_left} " +
                                 $"total length : {buffer_calc.MetadataCurrentLoadSegment().total_len}");
            }
        }