2 * \file trc_pkt_proc_stm.cpp
5 * \copyright Copyright (c) 2015, ARM Limited. All Rights Reserved.
9 * Redistribution and use in source and binary forms, with or without modification,
10 * are permitted provided that the following conditions are met:
12 * 1. Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
19 * 3. Neither the name of the copyright holder nor the names of its contributors
20 * may be used to endorse or promote products derived from this software without
21 * specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include "opencsd/stm/trc_pkt_proc_stm.h"
38 // processor object construction
39 // ************************
42 // G++ doesn't like the ## pasting
43 #define STM_PKTS_NAME "PKTP_STM"
45 #define STM_PKTS_NAME OCSD_CMPNAME_PREFIX_PKTPROC##"_STM"
48 static const uint32_t STM_SUPPORTED_OP_FLAGS = OCSD_OPFLG_PKTPROC_COMMON;
50 TrcPktProcStm::TrcPktProcStm() : TrcPktProcBase(STM_PKTS_NAME)
55 TrcPktProcStm::TrcPktProcStm(int instIDNum) : TrcPktProcBase(STM_PKTS_NAME, instIDNum)
60 TrcPktProcStm::~TrcPktProcStm()
62 getRawPacketMonAttachPt()->set_notifier(0);
65 void TrcPktProcStm::initObj()
67 m_supported_op_flags = STM_SUPPORTED_OP_FLAGS;
69 getRawPacketMonAttachPt()->set_notifier(&mon_in_use);
73 // implementation packet processing interface overrides
74 // ************************
75 ocsd_datapath_resp_t TrcPktProcStm::processData( const ocsd_trc_index_t index,
76 const uint32_t dataBlockSize,
77 const uint8_t *pDataBlock,
78 uint32_t *numBytesProcessed)
80 ocsd_datapath_resp_t resp = OCSD_RESP_CONT;
81 m_p_data_in = pDataBlock;
82 m_data_in_size = dataBlockSize;
85 // while there is data and a continue response on the data path
86 while( dataToProcess() && OCSD_DATA_RESP_IS_CONT(resp) )
97 m_packet_index = index + m_data_in_used;
100 m_proc_state = PROC_DATA; // read the header nibble, next if any has to be data
101 m_pCurrPktFn = m_1N_ops[m_nibble]; // set packet function and fall through
107 (this->*m_pCurrPktFn)();
109 // if we have enough to send, fall through, otherwise stop
110 if(m_proc_state != SEND_PKT)
114 resp = outputPacket();
118 catch(ocsdError &err)
121 if( ((err.getErrorCode() == OCSD_ERR_BAD_PACKET_SEQ) ||
122 (err.getErrorCode() == OCSD_ERR_INVALID_PCKT_HDR)) &&
123 !(getComponentOpMode() & OCSD_OPFLG_PKTPROC_ERR_BAD_PKTS))
125 // send invalid packets up the pipe to let the next stage decide what to do.
126 resp = outputPacket();
127 if(getComponentOpMode() & OCSD_OPFLG_PKTPROC_UNSYNC_ON_BAD_PKTS)
128 m_proc_state = WAIT_SYNC;
132 // bail out on any other error.
133 resp = OCSD_RESP_FATAL_INVALID_DATA;
138 /// vv bad at this point.
139 resp = OCSD_RESP_FATAL_SYS_ERR;
140 ocsdError fatal = ocsdError(OCSD_ERR_SEV_ERROR,OCSD_ERR_FAIL,m_packet_index,m_config->getTraceID());
141 fatal.setMessage("Unknown System Error decoding trace.");
146 *numBytesProcessed = m_data_in_used;
151 ocsd_datapath_resp_t TrcPktProcStm::onEOT()
153 ocsd_datapath_resp_t resp = OCSD_RESP_CONT;
154 if(m_num_nibbles > 0) // there is a partial packet in flight
156 m_curr_packet.updateErrType(STM_PKT_INCOMPLETE_EOT); // re mark as incomplete
157 resp = outputPacket();
162 ocsd_datapath_resp_t TrcPktProcStm::onReset()
164 initProcessorState();
165 return OCSD_RESP_CONT;
168 ocsd_datapath_resp_t TrcPktProcStm::onFlush()
170 // packet processor never holds on to flushable data (may have partial packet,
171 // but any full packets are immediately sent)
172 return OCSD_RESP_CONT;
175 ocsd_err_t TrcPktProcStm::onProtocolConfig()
177 return OCSD_OK; // nothing to do on config for this processor
180 const bool TrcPktProcStm::isBadPacket() const
182 return m_curr_packet.isBadPacket();
185 ocsd_datapath_resp_t TrcPktProcStm::outputPacket()
187 ocsd_datapath_resp_t resp = OCSD_RESP_CONT;
188 resp = outputOnAllInterfaces(m_packet_index,&m_curr_packet,&m_curr_packet.type,m_packet_data);
189 m_packet_data.clear();
191 if(m_nibble_2nd_valid)
192 savePacketByte(m_nibble_2nd << 4); // put the unused nibble back on to the data stack and pad for output next time.
193 m_proc_state = m_bStreamSync ? PROC_HDR : WAIT_SYNC;
197 void TrcPktProcStm::throwBadSequenceError(const char *pszMessage /*= ""*/)
199 m_curr_packet.updateErrType(STM_PKT_BAD_SEQUENCE);
200 throw ocsdError(OCSD_ERR_SEV_ERROR,OCSD_ERR_BAD_PACKET_SEQ,m_packet_index,this->m_config->getTraceID(),pszMessage);
203 void TrcPktProcStm::throwReservedHdrError(const char *pszMessage /*= ""*/)
205 m_curr_packet.setPacketType(STM_PKT_RESERVED,false);
206 throw ocsdError(OCSD_ERR_SEV_ERROR,OCSD_ERR_INVALID_PCKT_HDR,m_packet_index,this->m_config->getTraceID(),pszMessage);
209 // processor / packet init
210 // ************************
212 void TrcPktProcStm::initProcessorState()
214 // clear any state that persists between packets
217 m_curr_packet.initStartState();
218 m_nibble_2nd_valid = false;
220 m_bWaitSyncSaveSuppressed = false;
222 m_packet_data.clear();
225 void TrcPktProcStm::initNextPacket()
227 // clear state that is unique to each packet
231 m_num_data_nibbles = 0;
232 m_curr_packet.initNextPacket();
235 // search remaining buffer for a start of sync or full sync packet
236 void TrcPktProcStm::waitForSync(const ocsd_trc_index_t blk_st_index)
238 bool bGotData = true;
239 uint32_t start_offset = m_data_in_used; // record the offset into the buffer at start of this fn.
242 // out of sync - either at start of input stream, or due to bad packet.
243 // m_data_in_used -> bytes already processed
244 // m_sync_start -> seen potential start of sync in current stream
246 // set a packet index for the start of the data
247 m_packet_index = blk_st_index + m_data_in_used;
248 m_num_nibbles = m_is_sync ? m_num_F_nibbles + 1 : m_num_F_nibbles; // sending unsync data may have cleared down num_nibbles.
250 m_bWaitSyncSaveSuppressed = true; // no need to save bytes until we want to send data.
252 while(bGotData && !m_is_sync)
254 bGotData = readNibble(); // read until we have a sync or run out of data
257 m_bWaitSyncSaveSuppressed = false;
259 // no data from first attempt to read
260 if(m_num_nibbles == 0)
263 // we have found a sync or run out of data
264 // five possible scenarios
265 // a) all data none sync data.
266 // b) some none sync data + start of sync sequence
267 // c) some none sync data + full sync sequence in this frame
268 // d) full sync sequence @ start of this frame followed by ???
269 // e) completion of sync sequence in this frame (from b)).
271 if(!bGotData || m_num_nibbles > 22)
273 // for a), b), c) send the none sync data then re-enter
274 // if out of data, or sync with some previous data, this is sent as unsynced.
276 m_curr_packet.setPacketType(STM_PKT_NOTSYNC,false);
277 if(mon_in_use.usingMonitor())
279 uint8_t nibbles_to_send = m_num_nibbles - (m_is_sync ? 22 : m_num_F_nibbles);
280 uint8_t bytes_to_send = (nibbles_to_send / 2) + (nibbles_to_send % 2);
281 for(uint8_t i = 0; i < bytes_to_send; i++)
282 savePacketByte(m_p_data_in[start_offset+i]);
285 // if we have found a sync then we will re-enter this function with no pre data,
286 // but the found flags set.
290 // send the async packet
291 m_curr_packet.setPacketType(STM_PKT_ASYNC,false);
292 m_bStreamSync = true; // mark the stream as synchronised
294 m_packet_index = m_sync_index;
295 if(mon_in_use.usingMonitor())
297 // we may not have the full sync packet still in the local buffer so synthesise it.
298 for(int i = 0; i < 10; i++)
299 savePacketByte(0xFF);
300 savePacketByte(0x0F);
303 sendPacket(); // mark packet for sending
306 // packet processing routines
307 // ************************
309 void TrcPktProcStm::stmPktReserved()
311 uint16_t bad_opcode = (uint16_t)m_nibble;
312 m_curr_packet.setD16Payload(bad_opcode);
313 throwReservedHdrError("STM: Unsupported or Reserved STPv2 Header");
316 void TrcPktProcStm::stmPktNull()
318 m_curr_packet.setPacketType(STM_PKT_NULL,false);
321 m_pCurrPktFn = &TrcPktProcStm::stmExtractTS;
322 (this->*m_pCurrPktFn)();
330 void TrcPktProcStm::stmPktNullTS()
333 m_pCurrPktFn = &TrcPktProcStm::stmPktNull;
334 (this->*m_pCurrPktFn)();
337 void TrcPktProcStm::stmPktM8()
339 if(m_num_nibbles == 1) // 1st nibble - header - set type
340 m_curr_packet.setPacketType(STM_PKT_M8,false);
343 if(m_num_nibbles == 3)
345 m_curr_packet.setMaster(m_val8);
350 void TrcPktProcStm::stmPktMERR()
352 if(m_num_nibbles == 1) // 1st nibble - header - set type
353 m_curr_packet.setPacketType(STM_PKT_MERR,false);
356 if(m_num_nibbles == 3)
358 m_curr_packet.setChannel(0,false); // MERR resets channel for current master to 0.
359 m_curr_packet.setD8Payload(m_val8);
365 void TrcPktProcStm::stmPktC8()
367 if(m_num_nibbles == 1) // 1st nibble - header - set type
368 m_curr_packet.setPacketType(STM_PKT_C8,false);
370 if(m_num_nibbles == 3)
372 m_curr_packet.setChannel((uint16_t)m_val8,true);
377 void TrcPktProcStm::stmPktD4()
379 if(m_num_nibbles == 1) // 1st nibble - header - set type
381 m_curr_packet.setPacketType(STM_PKT_D4,m_bIsMarker);
382 m_num_data_nibbles = 2; // need 2 nibbles to complete data
385 if(m_num_nibbles != m_num_data_nibbles)
389 m_curr_packet.setD4Payload(m_nibble);
392 m_pCurrPktFn = &TrcPktProcStm::stmExtractTS;
393 (this->*m_pCurrPktFn)();
401 void TrcPktProcStm::stmPktD8()
403 if(m_num_nibbles == 1) // 1st nibble - header - set type
405 m_curr_packet.setPacketType(STM_PKT_D8,m_bIsMarker);
406 m_num_data_nibbles = 3; // need 3 nibbles in total to complete data
409 stmExtractVal8(m_num_data_nibbles);
410 if(m_num_nibbles == m_num_data_nibbles)
412 m_curr_packet.setD8Payload(m_val8);
415 m_pCurrPktFn = &TrcPktProcStm::stmExtractTS;
416 (this->*m_pCurrPktFn)();
425 void TrcPktProcStm::stmPktD16()
427 if(m_num_nibbles == 1) // 1st nibble - header - set type
429 m_curr_packet.setPacketType(STM_PKT_D16,m_bIsMarker);
430 m_num_data_nibbles = 5;
433 stmExtractVal16(m_num_data_nibbles);
434 if(m_num_nibbles == m_num_data_nibbles)
436 m_curr_packet.setD16Payload(m_val16);
439 m_pCurrPktFn = &TrcPktProcStm::stmExtractTS;
440 (this->*m_pCurrPktFn)();
449 void TrcPktProcStm::stmPktD32()
451 if(m_num_nibbles == 1) // 1st nibble - header - set type
453 m_curr_packet.setPacketType(STM_PKT_D32,m_bIsMarker);
454 m_num_data_nibbles = 9;
457 stmExtractVal32(m_num_data_nibbles);
458 if(m_num_nibbles == m_num_data_nibbles)
460 m_curr_packet.setD32Payload(m_val32);
463 m_pCurrPktFn = &TrcPktProcStm::stmExtractTS;
464 (this->*m_pCurrPktFn)();
473 void TrcPktProcStm::stmPktD64()
475 if(m_num_nibbles == 1) // 1st nibble - header - set type
477 m_curr_packet.setPacketType(STM_PKT_D64,m_bIsMarker);
478 m_num_data_nibbles = 17;
481 stmExtractVal64(m_num_data_nibbles);
482 if(m_num_nibbles == m_num_data_nibbles)
484 m_curr_packet.setD64Payload(m_val64);
487 m_pCurrPktFn = &TrcPktProcStm::stmExtractTS;
488 (this->*m_pCurrPktFn)();
497 void TrcPktProcStm::stmPktD4MTS()
501 m_pCurrPktFn = &TrcPktProcStm::stmPktD4;
502 (this->*m_pCurrPktFn)();
505 void TrcPktProcStm::stmPktD8MTS()
509 m_pCurrPktFn = &TrcPktProcStm::stmPktD8;
510 (this->*m_pCurrPktFn)();
513 void TrcPktProcStm::stmPktD16MTS()
517 m_pCurrPktFn = &TrcPktProcStm::stmPktD16;
518 (this->*m_pCurrPktFn)();
521 void TrcPktProcStm::stmPktD32MTS()
525 m_pCurrPktFn = &TrcPktProcStm::stmPktD32;
526 (this->*m_pCurrPktFn)();
529 void TrcPktProcStm::stmPktD64MTS()
533 m_pCurrPktFn = &TrcPktProcStm::stmPktD64;
534 (this->*m_pCurrPktFn)();
537 void TrcPktProcStm::stmPktFlagTS()
540 m_curr_packet.setPacketType(STM_PKT_FLAG,false);
541 m_pCurrPktFn = &TrcPktProcStm::stmExtractTS;
542 (this->*m_pCurrPktFn)();
545 void TrcPktProcStm::stmPktFExt()
547 // no type, look at the next nibble
550 // switch in 2N function
551 m_pCurrPktFn = m_2N_ops[m_nibble];
552 (this->*m_pCurrPktFn)();
556 // ************************
557 // 2 nibble opcodes 0xFn
558 void TrcPktProcStm::stmPktReservedFn()
560 uint16_t bad_opcode = 0x00F;
561 bad_opcode |= ((uint16_t)m_nibble) << 4;
562 m_curr_packet.setD16Payload(bad_opcode);
563 throwReservedHdrError("STM: Unsupported or Reserved STPv2 Header");
566 void TrcPktProcStm::stmPktF0Ext()
568 // no type yet, look at the next nibble
571 // switch in 3N function
572 m_pCurrPktFn = m_3N_ops[m_nibble];
573 (this->*m_pCurrPktFn)();
577 void TrcPktProcStm::stmPktGERR()
579 if(m_num_nibbles == 2) // 2nd nibble - header - set type
580 m_curr_packet.setPacketType(STM_PKT_GERR,false);
582 if(m_num_nibbles == 4)
584 m_curr_packet.setD8Payload(m_val8);
585 m_curr_packet.setMaster(0); // GERR sets current master to 0.
590 void TrcPktProcStm::stmPktC16()
592 if(m_num_nibbles == 2) // 2nd nibble - header - set type
593 m_curr_packet.setPacketType(STM_PKT_C16,false);
595 if(m_num_nibbles == 6)
597 m_curr_packet.setChannel(m_val16,false);
602 void TrcPktProcStm::stmPktD4TS()
605 m_curr_packet.setPacketType(STM_PKT_D4,false); // 2nd nibble, set type here
606 m_num_data_nibbles = 3; // one more nibble for data
607 m_pCurrPktFn = &TrcPktProcStm::stmPktD4;
608 (this->*m_pCurrPktFn)();
611 void TrcPktProcStm::stmPktD8TS()
614 m_curr_packet.setPacketType(STM_PKT_D8,false); // 2nd nibble, set type here
615 m_num_data_nibbles = 4;
616 m_pCurrPktFn = &TrcPktProcStm::stmPktD8;
617 (this->*m_pCurrPktFn)();
620 void TrcPktProcStm::stmPktD16TS()
623 m_curr_packet.setPacketType(STM_PKT_D16,false); // 2nd nibble, set type here
624 m_num_data_nibbles = 6;
625 m_pCurrPktFn = &TrcPktProcStm::stmPktD16;
626 (this->*m_pCurrPktFn)();
629 void TrcPktProcStm::stmPktD32TS()
632 m_curr_packet.setPacketType(STM_PKT_D32,false); // 2nd nibble, set type here
633 m_num_data_nibbles = 10;
634 m_pCurrPktFn = &TrcPktProcStm::stmPktD32;
635 (this->*m_pCurrPktFn)();
638 void TrcPktProcStm::stmPktD64TS()
641 m_curr_packet.setPacketType(STM_PKT_D64,false); // 2nd nibble, set type here
642 m_num_data_nibbles = 18;
643 m_pCurrPktFn = &TrcPktProcStm::stmPktD64;
644 (this->*m_pCurrPktFn)();
647 void TrcPktProcStm::stmPktD4M()
649 m_curr_packet.setPacketType(STM_PKT_D4,true); // 2nd nibble, set type here
650 m_num_data_nibbles = 3; // one more nibble for data
651 m_pCurrPktFn = &TrcPktProcStm::stmPktD4;
652 (this->*m_pCurrPktFn)();
655 void TrcPktProcStm::stmPktD8M()
657 m_curr_packet.setPacketType(STM_PKT_D8,true); // 2nd nibble, set type here
658 m_num_data_nibbles = 4;
659 m_pCurrPktFn = &TrcPktProcStm::stmPktD8;
660 (this->*m_pCurrPktFn)();
663 void TrcPktProcStm::stmPktD16M()
665 m_curr_packet.setPacketType(STM_PKT_D16,true);
666 m_num_data_nibbles = 6;
667 m_pCurrPktFn = &TrcPktProcStm::stmPktD16;
668 (this->*m_pCurrPktFn)();
671 void TrcPktProcStm::stmPktD32M()
673 m_curr_packet.setPacketType(STM_PKT_D32,true);
674 m_num_data_nibbles = 10;
675 m_pCurrPktFn = &TrcPktProcStm::stmPktD32;
676 (this->*m_pCurrPktFn)();
679 void TrcPktProcStm::stmPktD64M()
681 m_curr_packet.setPacketType(STM_PKT_D64,true);
682 m_num_data_nibbles = 18;
683 m_pCurrPktFn = &TrcPktProcStm::stmPktD64;
684 (this->*m_pCurrPktFn)();
687 void TrcPktProcStm::stmPktFlag()
689 m_curr_packet.setPacketType(STM_PKT_FLAG,false);
693 // ************************
694 // 3 nibble opcodes 0xF0n
695 void TrcPktProcStm::stmPktReservedF0n()
697 uint16_t bad_opcode = 0x00F;
698 bad_opcode |= ((uint16_t)m_nibble) << 8;
699 m_curr_packet.setD16Payload(bad_opcode);
700 throwReservedHdrError("STM: Unsupported or Reserved STPv2 Header");
703 void TrcPktProcStm::stmPktVersion()
705 if(m_num_nibbles == 3)
706 m_curr_packet.setPacketType(STM_PKT_VERSION,false);
710 m_curr_packet.setD8Payload(m_nibble); // record the version number
714 m_curr_packet.onVersionPkt(STM_TS_NATBINARY); break;
716 m_curr_packet.onVersionPkt(STM_TS_GREY); break;
718 // not a version we support.
719 throwBadSequenceError("STM VERSION packet : unrecognised version number.");
725 void TrcPktProcStm::stmPktTrigger()
727 if(m_num_nibbles == 3)
728 m_curr_packet.setPacketType(STM_PKT_TRIG,false);
730 if(m_num_nibbles == 5)
732 m_curr_packet.setD8Payload(m_val8);
735 m_pCurrPktFn = &TrcPktProcStm::stmExtractTS;
736 (this->*m_pCurrPktFn)();
745 void TrcPktProcStm::stmPktTriggerTS()
748 m_pCurrPktFn = &TrcPktProcStm::stmPktTrigger;
749 (this->*m_pCurrPktFn)();
752 void TrcPktProcStm::stmPktFreq()
754 if(m_num_nibbles == 3)
756 m_curr_packet.setPacketType(STM_PKT_FREQ,false);
760 if(m_num_nibbles == 11)
762 m_curr_packet.setD32Payload(m_val32);
767 void TrcPktProcStm::stmPktASync()
769 // 2 nibbles - 0xFF - must be an async or error.
773 bCont = readNibble();
778 bCont = false; // stop reading nibbles
779 m_bStreamSync = true; // mark stream in sync
780 m_curr_packet.setPacketType(STM_PKT_ASYNC,false);
784 else if(!m_sync_start) // no longer valid sync packet
786 throwBadSequenceError("STM: Invalid ASYNC sequence");
792 // ************************
793 // general data processing
795 // return false if no more data
796 // in an STM byte, 3:0 is 1st nibble in protocol order, 7:4 is 2nd nibble.
797 bool TrcPktProcStm::readNibble()
799 bool dataFound = true;
800 if(m_nibble_2nd_valid)
802 m_nibble = m_nibble_2nd;
803 m_nibble_2nd_valid = false;
807 else if(m_data_in_used < m_data_in_size )
809 m_nibble = m_p_data_in[m_data_in_used++];
810 savePacketByte(m_nibble);
811 m_nibble_2nd = (m_nibble >> 4) & 0xF;
812 m_nibble_2nd_valid = true;
818 dataFound = false; // no data available
822 void TrcPktProcStm::pktNeedsTS()
825 m_req_ts_nibbles = 0;
826 m_curr_ts_nibbles = 0;
827 m_ts_update_value = 0;
828 m_ts_req_set = false;
831 void TrcPktProcStm::stmExtractTS()
837 m_req_ts_nibbles = m_nibble;
839 m_req_ts_nibbles = 14;
840 else if(m_nibble == 0xE)
841 m_req_ts_nibbles = 16;
844 throwBadSequenceError("STM: Invalid timestamp size 0xF");
851 // if we do not have all the nibbles for the TS, get some...
852 if(m_req_ts_nibbles != m_curr_ts_nibbles)
854 // extract the correct amount of nibbles for the ts value.
856 while(bCont && (m_curr_ts_nibbles < m_req_ts_nibbles))
858 bCont = readNibble();
861 m_ts_update_value <<= 4;
862 m_ts_update_value |= m_nibble;
868 // at this point we have the correct amount of nibbles, or have run out of data to process.
869 if(m_req_ts_nibbles == m_curr_ts_nibbles)
871 uint8_t new_bits = m_req_ts_nibbles * 4;
872 if(m_curr_packet.getTSType() == STM_TS_GREY)
874 uint64_t gray_val = bin_to_gray(m_curr_packet.getTSVal());
877 gray_val = m_ts_update_value;
881 uint64_t mask = (0x1ULL << new_bits) - 1;
883 gray_val |= m_ts_update_value & mask;
885 m_curr_packet.setTS(gray_to_bin(gray_val),new_bits);
887 else if(m_curr_packet.getTSType() == STM_TS_NATBINARY)
889 m_curr_packet.setTS(m_ts_update_value, new_bits);
892 throwBadSequenceError("STM: unknown timestamp encoding");
899 // pass in number of nibbles needed to extract the value
900 void TrcPktProcStm::stmExtractVal8(uint8_t nibbles_to_val)
903 while(bCont && (m_num_nibbles < nibbles_to_val))
905 bCont = readNibble();
906 if(bCont) // got a nibble
914 void TrcPktProcStm::stmExtractVal16(uint8_t nibbles_to_val)
917 while(bCont && (m_num_nibbles < nibbles_to_val))
919 bCont = readNibble();
920 if(bCont) // got a nibble
928 void TrcPktProcStm::stmExtractVal32(uint8_t nibbles_to_val)
931 while(bCont && (m_num_nibbles < nibbles_to_val))
933 bCont = readNibble();
934 if(bCont) // got a nibble
942 void TrcPktProcStm::stmExtractVal64(uint8_t nibbles_to_val)
945 while(bCont && (m_num_nibbles < nibbles_to_val))
947 bCont = readNibble();
948 if(bCont) // got a nibble
956 uint64_t TrcPktProcStm::bin_to_gray(uint64_t bin_value)
958 uint64_t gray_value = 0;
959 gray_value = (1ull << 63) & bin_value;
961 for (; i >= 0; i--) {
962 uint64_t gray_arg_1 = ((1ull << (i+1)) & bin_value) >> (i+1);
963 uint64_t gray_arg_2 = ((1ull << i) & bin_value) >> i;
964 gray_value |= ((gray_arg_1 ^ gray_arg_2) << i);
969 uint64_t TrcPktProcStm::gray_to_bin(uint64_t gray_value)
971 uint64_t bin_value = 0;
973 for (; bin_bit < 64; bin_bit++) {
974 uint8_t bit_tmp = ((1ull << bin_bit) & gray_value) >> bin_bit;
975 uint8_t gray_bit = bin_bit + 1;
976 for (; gray_bit < 64; gray_bit++)
977 bit_tmp ^= (((1ull << gray_bit) & gray_value) >> gray_bit);
979 bin_value |= (bit_tmp << bin_bit);
986 void TrcPktProcStm::buildOpTables()
989 for(int i = 0; i < 0x10; i++)
991 m_1N_ops[i] = &TrcPktProcStm::stmPktReserved;
992 m_2N_ops[i] = &TrcPktProcStm::stmPktReservedFn;
993 m_3N_ops[i] = &TrcPktProcStm::stmPktReservedF0n;
996 // set the 1N operations
997 m_1N_ops[0x0] = &TrcPktProcStm::stmPktNull;
998 m_1N_ops[0x1] = &TrcPktProcStm::stmPktM8;
999 m_1N_ops[0x2] = &TrcPktProcStm::stmPktMERR;
1000 m_1N_ops[0x3] = &TrcPktProcStm::stmPktC8;
1001 m_1N_ops[0x4] = &TrcPktProcStm::stmPktD8;
1002 m_1N_ops[0x5] = &TrcPktProcStm::stmPktD16;
1003 m_1N_ops[0x6] = &TrcPktProcStm::stmPktD32;
1004 m_1N_ops[0x7] = &TrcPktProcStm::stmPktD64;
1005 m_1N_ops[0x8] = &TrcPktProcStm::stmPktD8MTS;
1006 m_1N_ops[0x9] = &TrcPktProcStm::stmPktD16MTS;
1007 m_1N_ops[0xA] = &TrcPktProcStm::stmPktD32MTS;
1008 m_1N_ops[0xB] = &TrcPktProcStm::stmPktD64MTS;
1009 m_1N_ops[0xC] = &TrcPktProcStm::stmPktD4;
1010 m_1N_ops[0xD] = &TrcPktProcStm::stmPktD4MTS;
1011 m_1N_ops[0xE] = &TrcPktProcStm::stmPktFlagTS;
1012 m_1N_ops[0xF] = &TrcPktProcStm::stmPktFExt;
1014 // set the 2N operations 0xFn
1015 m_2N_ops[0x0] = &TrcPktProcStm::stmPktF0Ext;
1016 // 0x1 unused in CS STM
1017 m_2N_ops[0x2] = &TrcPktProcStm::stmPktGERR;
1018 m_2N_ops[0x3] = &TrcPktProcStm::stmPktC16;
1019 m_2N_ops[0x4] = &TrcPktProcStm::stmPktD8TS;
1020 m_2N_ops[0x5] = &TrcPktProcStm::stmPktD16TS;
1021 m_2N_ops[0x6] = &TrcPktProcStm::stmPktD32TS;
1022 m_2N_ops[0x7] = &TrcPktProcStm::stmPktD64TS;
1023 m_2N_ops[0x8] = &TrcPktProcStm::stmPktD8M;
1024 m_2N_ops[0x9] = &TrcPktProcStm::stmPktD16M;
1025 m_2N_ops[0xA] = &TrcPktProcStm::stmPktD32M;
1026 m_2N_ops[0xB] = &TrcPktProcStm::stmPktD64M;
1027 m_2N_ops[0xC] = &TrcPktProcStm::stmPktD4TS;
1028 m_2N_ops[0xD] = &TrcPktProcStm::stmPktD4M;
1029 m_2N_ops[0xE] = &TrcPktProcStm::stmPktFlag;
1030 m_2N_ops[0xF] = &TrcPktProcStm::stmPktASync;
1032 // set the 3N operations 0xF0n
1033 m_3N_ops[0x0] = &TrcPktProcStm::stmPktVersion;
1034 m_3N_ops[0x1] = &TrcPktProcStm::stmPktNullTS;
1035 // 0x2 .. 0x5 not used by CS STM
1036 m_3N_ops[0x6] = &TrcPktProcStm::stmPktTrigger;
1037 m_3N_ops[0x7] = &TrcPktProcStm::stmPktTriggerTS;
1038 m_3N_ops[0x8] = &TrcPktProcStm::stmPktFreq;
1039 // 0x9 .. 0xF not used by CS STM
1043 /* End of File trc_pkt_proc_stm.cpp */