2 * \file pkt_printer_t.h
3 * \brief OpenCSD : Test packet printer.
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 #ifndef ARM_PKT_PRINTER_T_H_INCLUDED
36 #define ARM_PKT_PRINTER_T_H_INCLUDED
46 class PacketPrinter : public IPktDataIn<P>, public IPktRawDataMon<P>, public ItemPrinter
49 PacketPrinter(const uint8_t trcID);
50 PacketPrinter(const uint8_t trcID, ocsdMsgLogger *pMsgLogger);
51 virtual ~PacketPrinter();
54 virtual ocsd_datapath_resp_t PacketDataIn( const ocsd_datapath_op_t op,
55 const ocsd_trc_index_t index_sop,
56 const P *p_packet_in);
58 virtual void RawPacketDataMon( const ocsd_datapath_op_t op,
59 const ocsd_trc_index_t index_sop,
62 const uint8_t *p_data);
66 void printIdx_ID(const ocsd_trc_index_t index_sop);
70 std::ostringstream m_oss;
71 ocsd_datapath_resp_t m_last_resp;
75 template<class P> PacketPrinter<P>::PacketPrinter(uint8_t trcID) :
78 m_last_resp(OCSD_RESP_CONT)
82 template<class P> PacketPrinter<P>::PacketPrinter(const uint8_t trcID, ocsdMsgLogger *pMsgLogger) :
85 m_last_resp(OCSD_RESP_CONT)
87 setMessageLogger(pMsgLogger);
90 template<class P> PacketPrinter<P>::~PacketPrinter()
94 template<class P> ocsd_datapath_resp_t PacketPrinter<P>::PacketDataIn( const ocsd_datapath_op_t op,
95 const ocsd_trc_index_t index_sop,
99 ocsd_datapath_resp_t resp = OCSD_RESP_CONT;
101 // wait / flush test verification
102 if(!m_bRawPrint && (m_last_resp == OCSD_RESP_WAIT))
104 // expect a flush or a complete reset after a wait.
105 if((op != OCSD_OP_FLUSH) || (op != OCSD_OP_RESET))
107 m_oss <<"ID:"<< std::hex << (uint32_t)m_trcID << "\tERROR: FLUSH operation expected after wait on trace decode path\n";
108 itemPrintLine(m_oss.str());
110 return OCSD_RESP_FATAL_INVALID_OP;
117 p_packet_in->toString(pktstr);
119 printIdx_ID(index_sop);
120 m_oss << ";\t" << pktstr << std::endl;
122 // test the wait/flush response mechnism
123 if(getTestWaits() && !m_bRawPrint)
126 resp = OCSD_RESP_WAIT;
131 m_oss <<"ID:"<< std::hex << (uint32_t)m_trcID << "\tEND OF TRACE DATA\n";
135 m_oss <<"ID:"<< std::hex << (uint32_t)m_trcID << "\tFLUSH operation on trace decode path\n";
139 m_oss <<"ID:"<< std::hex << (uint32_t)m_trcID << "\tRESET operation on trace decode path\n";
144 itemPrintLine(m_oss.str());
149 template<class P> void PacketPrinter<P>::RawPacketDataMon( const ocsd_datapath_op_t op,
150 const ocsd_trc_index_t index_sop,
153 const uint8_t *p_data)
158 printIdx_ID(index_sop);
160 if((size > 0) && (p_data != 0))
163 for(uint32_t i = 0; i < size; i++)
165 data = (uint32_t)(p_data[i] & 0xFF);
166 m_oss << "0x" << std::hex << std::setw(2) << std::setfill('0') << data << " ";
171 PacketDataIn(op,index_sop,pkt);
176 PacketDataIn(op,index_sop,pkt);
182 template<class P> void PacketPrinter<P>::printIdx_ID(const ocsd_trc_index_t index_sop)
184 m_oss << "Idx:" << std::dec << index_sop << "; ID:"<< std::hex << (uint32_t)m_trcID;
187 #endif // ARM_PKT_PRINTER_T_H_INCLUDED
189 /* End of File pkt_printer_t.h */