当前位置: 首页>>代码示例>>C++>>正文


C++ stream::read_nb方法代码示例

本文整理汇总了C++中hls::stream::read_nb方法的典型用法代码示例。如果您正苦于以下问题:C++ stream::read_nb方法的具体用法?C++ stream::read_nb怎么用?C++ stream::read_nb使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hls::stream的用法示例。


在下文中一共展示了stream::read_nb方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: receive

void receive(
             hls::stream<t_s_xgmii> &s_xgmii,
             hls::stream<t_axis> &m_axis,
             hls::stream<t_rx_status> &rx_status
             )
{
#ifdef RELEASE
#pragma HLS interface ap_ctrl_none port=return
#pragma HLS data_pack variable=s_xgmii
#endif

#pragma HLS INTERFACE axis port=m_axis
#pragma HLS data_pack variable=rx_status

    int i;
    t_s_xgmii cur = {0, 0};
    t_s_xgmii precur = {0, 0};
    t_s_xgmii last_word;
    ap_uint<32> crc_state = 0xffffffff;
    ap_uint<16> frm_cnt = 0;
    int data_err = 0;
    ap_uint<16> len_type = 0xffff;
    int last_user_byte_lane_before_frame_end;
    int user_data_end_detected = 0;
    int last_user_word_pos;
    ap_uint<3> last_user_byte_lane;

 MAIN: while (1) {

        if (user_data_end_detected) {
            int fcs_err = (crc_state != 0x00000000);
            int len_err = 0;
            int frm_byte_cnt = frm_cnt*8 + last_user_byte_lane_before_frame_end + 1 + 4;
            int under = (frm_byte_cnt < 64);
            int over = (frm_byte_cnt > 1500);

            if (is_len(len_type)) {
                if (len_type > 2) {
                    len_err = (len_type != ((last_user_word_pos - 2) * 8 + 2 + last_user_byte_lane + 1));
                } else {
                    len_err = (len_type != ((last_user_word_pos - 2) * 8 + 2 + 8 - (last_user_byte_lane + 1)));
                }
            }

            int good = !(fcs_err | len_err | data_err | under | over);

            m_axis.write((t_axis){last_word.rxd, mask_up_to_bit(8, last_user_byte_lane), !good, 1});
            rx_status.write((t_rx_status) {frm_cnt, good, 0, 0, under, len_err, fcs_err, data_err, 0, over});
        }

        cur = precur;
        if (!s_xgmii.read_nb(precur)) return;

        frm_cnt = 0;
        crc_state = 0xffffffff;
        len_type = 0xffff;

    IDLE_AND_PREAMBLE: while (!((cur.rxc == 0x01) && (cur.rxd == 0xd5555555555555fb))) {
#pragma HLS LATENCY max=0 min=0
    		cur = precur;
    		if (!s_xgmii.read_nb(precur)) return;
            // printf("RXD 0x%016lx, RXC 0x%02x\n", cur.rxd.to_long(), cur.rxc.to_int());
        }

		cur = precur;
		if (!s_xgmii.read_nb(precur)) return;
        // printf("RXD 0x%016lx, RXC 0x%02x\n", cur.rxd.to_long(), cur.rxc.to_int());

        user_data_end_detected = 0;
        int frame_end_detected = 0;
    USER_DATA: do {
#pragma HLS LATENCY max=0 min=0
            ap_uint<8> crc_field_mask;
    		// END-OF-FRAME detection
            if (cur.rxc != 0x00) {
                switch(cur.rxc) {
                case 0xe0 : last_user_byte_lane_before_frame_end = 0; crc_field_mask = 0x1e; break;
                case 0xc0 : last_user_byte_lane_before_frame_end = 1; crc_field_mask = 0x3c; break;
                case 0x80 : last_user_byte_lane_before_frame_end = 2; crc_field_mask = 0x78; break;
                default: crc_field_mask = 0xff; break;
                }
                frame_end_detected = 1;
                if (!user_data_end_detected) {
                    last_word = cur;
                    last_user_byte_lane = last_user_byte_lane_before_frame_end;
                }
                user_data_end_detected = 1;
            } else if ((precur.rxc != 0x00) && ((ap_uint<8>) ~precur.rxc <= 0x0f)) {
                switch(precur.rxc) {
                case 0xf0 : last_user_byte_lane_before_frame_end = 7; break;
                case 0xf8 : last_user_byte_lane_before_frame_end = 6; crc_field_mask = 0x80; break;
                case 0xfc : last_user_byte_lane_before_frame_end = 5; crc_field_mask = 0xc0; break;
                case 0xfe : last_user_byte_lane_before_frame_end = 4; crc_field_mask = 0xe0; break;
                case 0xff : last_user_byte_lane_before_frame_end = 3; crc_field_mask = 0xf0; frame_end_detected = 1; break;
                }
                if (!user_data_end_detected) {
                    last_word = cur;
                    last_user_byte_lane = last_user_byte_lane_before_frame_end;
                }
                user_data_end_detected = 1;
//.........这里部分代码省略.........
开发者ID:bogdanvuk,项目名称:hls10gmac,代码行数:101,代码来源:receive.cpp


注:本文中的hls::stream::read_nb方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。