Skip to content

Axi2Tlm bridge does not support narrow bursts #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jnbrq opened this issue Oct 22, 2024 · 0 comments
Open

Axi2Tlm bridge does not support narrow bursts #26

jnbrq opened this issue Oct 22, 2024 · 0 comments

Comments

@jnbrq
Copy link

jnbrq commented Oct 22, 2024

GetData and FillData functions in axi2tlm bridge shall be modified as the following (a similar problem was reported by #20 as well):

        template<typename T1, typename T2>
        void FillData(T1& wdata, T2& wstrb) {
            unsigned char* gp_data = m_gp->get_data_ptr();
            unsigned char* be = m_gp->get_byte_enable_ptr();
            std::uint64_t address = m_gp->get_address();
            std::uint8_t numberBytes = m_genattr->get_burst_width();
            std::uint64_t alignedAddress;

            unsigned int lower_byte_lane;
            unsigned int upper_byte_lane;
            unsigned int i;

            alignedAddress = Align(address, numberBytes);

            if (m_burstType == AXI_BURST_FIXED) {
                lower_byte_lane = address - Align(address, DATA_BUS_BYTES);
                upper_byte_lane = alignedAddress + (numberBytes - 1) - Align(address, DATA_BUS_BYTES);

                for (i = 0; i < DATA_BUS_BYTES; i++) {
                    if (i >= lower_byte_lane && i <= upper_byte_lane) {
                        int firstbit = i * 8;
                        int lastbit = firstbit + 8 - 1;

                        if (wstrb.read().bit(i)) {
                            be[m_dataIdx] = TLM_BYTE_ENABLED;
                            gp_data[m_dataIdx] = wdata.read().range(lastbit, firstbit).to_uint();
                        } else {
                            be[m_dataIdx] = TLM_BYTE_DISABLED;
                        }

                        m_dataIdx++;
                    }
                }
            } else {
                if (m_beat == 1) {
                    lower_byte_lane = address - Align(address, DATA_BUS_BYTES);
                    upper_byte_lane = alignedAddress + (numberBytes - 1) - Align(address, DATA_BUS_BYTES);
                } else {
                    std::uint64_t address = alignedAddress + ((m_beat - 1) * numberBytes);

                    lower_byte_lane = address - Align(address, DATA_BUS_BYTES);
                    upper_byte_lane = lower_byte_lane + (numberBytes - 1);
                }

                assert(lower_byte_lane < DATA_BUS_BYTES);
                assert(upper_byte_lane < DATA_BUS_BYTES);

                // Set data
                for (i = 0; i < DATA_BUS_BYTES; i++) {
                    if (i >= lower_byte_lane && i <= upper_byte_lane) {
                        if (wstrb.read().bit(i)) {
                            int firstbit = i * 8;
                            int lastbit = firstbit + 8 - 1;

                            assert(m_dataIdx < m_gp->get_data_length());
                            be[m_dataIdx] = TLM_BYTE_ENABLED;
                            gp_data[m_dataIdx++] = wdata.read().range(lastbit, firstbit).to_uint();
                        } else {
                            be[m_dataIdx++] = TLM_BYTE_DISABLED;
                        }
                    }
                }

            }
        }

        template<typename T>
        void GetData(T& data) {
            unsigned char* gp_data = m_gp->get_data_ptr();
            std::uint64_t address = m_gp->get_address();
            std::uint8_t numberBytes = m_genattr->get_burst_width();
            std::uint64_t alignedAddress;
            unsigned int lower_byte_lane;
            unsigned int upper_byte_lane;
            unsigned int i;

            alignedAddress = Align(address, numberBytes);

            if (m_burstType == AXI_BURST_FIXED) {
                lower_byte_lane = address - Align(address, DATA_BUS_BYTES);
                upper_byte_lane = alignedAddress + (numberBytes - 1) - Align(address, DATA_BUS_BYTES);

                for (i = 0; i < DATA_BUS_BYTES; i++) {
                    if (i >= lower_byte_lane && i <= upper_byte_lane) {
                        int firstbit = i * 8;
                        int lastbit = firstbit + 8 - 1;

                        data.range(lastbit, firstbit) = gp_data[m_dataIdx++];
                    }
                }
            } else {
                if (m_beat == 1) {
                    lower_byte_lane = address - Align(address, DATA_BUS_BYTES);
                    upper_byte_lane = alignedAddress + (numberBytes - 1) - Align(address, DATA_BUS_BYTES);
                } else {
                    std::uint64_t address = alignedAddress + ((m_beat - 1) * numberBytes);

                    lower_byte_lane = address - Align(address, DATA_BUS_BYTES);
                    upper_byte_lane = lower_byte_lane + (numberBytes - 1);
                }

                // Set data
                for (i = 0; i < DATA_BUS_BYTES; i++) {
                    if (i >= lower_byte_lane && i <= upper_byte_lane) {
                        int firstbit = i * 8;
                        int lastbit = firstbit + 8 - 1;

                        data.range(lastbit, firstbit) = gp_data[m_dataIdx++];
                    }
                }
            }
        }

A similar might appear in tlm2axi bridges; however, I have not checked them yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant