2 * Copyright (C) 2013 Freescale Semiconductor, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23 #include "NxPacketSet.h"
31 NxPacketSet::NxPacketSet() :
37 void NxPacketSet::reset()
39 // pointer to the first packet
40 current_packet_index_
= 0;
41 current_packet_
= &packet_
[current_packet_index_
];
43 for (uint32_t i
= 0; i
< MAX_NUM_PACKETS
; ++i
) {
48 // add len bits of mdo to the current packet
49 bool NxPacketSet::addToCurrent(uint32_t mdo
)
51 bool ret
= current_packet_
->add(mdo
);
54 for (uint32_t i
= 0; i
<= current_packet_index_
; ++i
) {
55 cout
<< "Packet[" << i
<< "]: "
56 << packet_
[i
].packet_
<< endl
;
59 cout
<< "Error adding MDO to Packet["
60 << current_packet_index_
<< "]" << endl
;
66 // advance to the next packet
67 bool NxPacketSet::nextPacket()
69 assert(current_packet_index_
< (MAX_NUM_PACKETS
- 1));
71 bool ret
= current_packet_index_
< (MAX_NUM_PACKETS
- 1);
73 current_packet_index_
++;
74 current_packet_
= &packet_
[current_packet_index_
];
79 // get the value of len size from start (LSB) pos from packet at index
80 uint32_t NxPacketSet::getField32(uint32_t index
, uint32_t start_pos
,
83 assert(index
< MAX_NUM_PACKETS
);
84 return packet_
[index
].getField32(start_pos
, len
);
88 // get the value of len size from start (LSB) pos from packet at index
89 uint64_t NxPacketSet::getField64(uint32_t index
, uint32_t start_pos
,
92 assert(index
< MAX_NUM_PACKETS
);
93 return packet_
[index
].getField64(start_pos
, len
);
96 // get the number of MDO from packet at index
97 uint32_t NxPacketSet::getNumMDO(uint32_t index
) const
99 assert(index
< MAX_NUM_PACKETS
);
100 return packet_
[index
].getNumMDO();
103 bool NxPacketSet::packetAtIndexExists(uint32_t index
) const
105 assert(index
< MAX_NUM_PACKETS
);
106 return index
<= current_packet_index_
;
110 uint32_t NxPacketSet::tcode() const
112 // index=0, start_pos=0, length=6
113 uint32_t ret
= getField32(0, 0, 6);
118 uint32_t NxPacketSet::src() const
120 // index=0, start_pos=6, length=6
121 uint32_t ret
= getField32(0, 6, 6);
132 // return the packet to the initial state
133 void NxPacket::reset()
140 // add len bits of mdo to the packet
141 bool NxPacket::add(uint32_t mdo
)
143 assert((mdo
& 0xc0000000) == 0);
144 assert(num_mdo_
<= MAX_NUM_MDO_PER_PACKET
);
147 PktBits
mdo_bits(mdo
);
148 mdo_bits
<<= current_pos_
;
150 current_pos_
+= MAX_NUM_MDO_BITS
;
156 // get the value of len size from start (LSB) pos from packet
157 uint32_t NxPacket::getField32(uint32_t start_pos
, uint32_t len
) const
159 assert(start_pos
+ len
< MAX_NUM_PACKET_BITS
);
163 uint32_t pos
= start_pos
+ len
- 1;
164 for (uint32_t i
= 0; i
< len
; ++i
) {
172 // get the value of len size from start (LSB) pos from packet
173 uint64_t NxPacket::getField64(uint32_t start_pos
, uint32_t len
) const
175 assert(start_pos
+ len
< MAX_NUM_PACKET_BITS
);
179 uint32_t pos
= start_pos
+ len
- 1;
180 for (uint32_t i
= 0; i
< len
; ++i
) {
This page took 0.041382 seconds and 4 git commands to generate.