2 * \file trc_pkt_elem_stm.h
3 * \brief OpenCSD : STM packet class.
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_TRC_PKT_ELEM_STM_H_INCLUDED
36 #define ARM_TRC_PKT_ELEM_STM_H_INCLUDED
38 #include "trc_pkt_types_stm.h"
39 #include "common/trc_printable_elem.h"
40 #include "common/trc_pkt_elem_base.h"
44 * @brief STM trace packet with packet printing functionality
46 * This class allows for the update and access of the current STM trace
47 * packet, implementing the STM protocol rules as appropriate. Maintains
48 * the intra packet state as well as updates on a per packet basis.
50 * Based on data structure ocsd_stm_pkt.
53 class StmTrcPacket : public TrcPacketBase, public ocsd_stm_pkt, public trcPrintableElem
59 StmTrcPacket &operator =(const ocsd_stm_pkt *p_pkt);
61 virtual const void *c_pkt() const { return (const ocsd_stm_pkt *)this; };
63 void initStartState(); //!< Initialise packet state at start of decoder.
64 void initNextPacket(); //!< Initialise state for next packet.
66 void setPacketType(const ocsd_stm_pkt_type type, const bool bMarker);
67 void updateErrType(const ocsd_stm_pkt_type err_type);
68 void setMaster(const uint8_t master);
69 void setChannel(const uint16_t channel, const bool b8Bit);
70 void setTS(const uint64_t ts_val, const uint8_t updatedBits);
71 void onVersionPkt(const ocsd_stm_ts_type type);
73 void setD4Payload(const uint8_t value);
74 void setD8Payload(const uint8_t value);
75 void setD16Payload(const uint16_t value);
76 void setD32Payload(const uint32_t value);
77 void setD64Payload(const uint64_t value);
79 const bool isMarkerPkt() const;
80 const bool isTSPkt() const;
82 const ocsd_stm_pkt_type getPktType() const;
83 const ocsd_stm_pkt_type getPktErrType() const;
84 const uint8_t getMaster() const;
85 const uint16_t getChannel() const;
86 const ocsd_stm_ts_type getTSType() const;
87 const uint64_t getTSVal() const;
89 const uint8_t getD4Val() const;
90 const uint8_t getD8Val() const;
91 const uint16_t getD16Val() const;
92 const uint32_t getD32Val() const;
93 const uint64_t getD64Val() const;
95 const bool isBadPacket() const;
98 virtual void toString(std::string &str) const;
99 virtual void toStringFmt(const uint32_t fmtFlags, std::string &str) const;
103 void pktTypeName(const ocsd_stm_pkt_type pkt_type, std::string &name, std::string &desc) const;
106 inline void StmTrcPacket::setPacketType(const ocsd_stm_pkt_type type, const bool bMarker)
113 inline void StmTrcPacket::updateErrType(const ocsd_stm_pkt_type err_type)
115 this->err_type = this->type; // original type is the err type;
116 this->type = err_type; // mark main type as an error.
119 inline void StmTrcPacket::setMaster(const uint8_t master)
121 this->master = master;
122 channel = 0; // M8 forces current channel to 0.
125 inline void StmTrcPacket::setChannel(const uint16_t channel, const bool b8Bit)
128 this->channel = (this->channel & 0xFF00) | (channel & 0xFF);
130 this->channel = channel;
133 inline void StmTrcPacket::onVersionPkt(const ocsd_stm_ts_type type)
135 this->ts_type = type;
140 inline void StmTrcPacket::setD4Payload(const uint8_t value)
142 payload.D8 = value & 0xF;
145 inline void StmTrcPacket::setD8Payload(const uint8_t value)
150 inline void StmTrcPacket::setD16Payload(const uint16_t value)
155 inline void StmTrcPacket::setD32Payload(const uint32_t value)
160 inline void StmTrcPacket::setD64Payload(const uint64_t value)
165 inline const bool StmTrcPacket::isMarkerPkt() const
167 return (pkt_has_marker != 0);
170 inline const bool StmTrcPacket::isTSPkt() const
172 return (pkt_has_ts != 0);
175 inline const ocsd_stm_pkt_type StmTrcPacket::getPktType() const
180 inline const ocsd_stm_pkt_type StmTrcPacket::getPktErrType() const
185 inline const uint8_t StmTrcPacket::getMaster() const
190 inline const uint16_t StmTrcPacket::getChannel() const
195 inline const ocsd_stm_ts_type StmTrcPacket::getTSType() const
200 inline const uint64_t StmTrcPacket::getTSVal() const
205 inline const uint8_t StmTrcPacket::getD4Val() const
210 inline const uint8_t StmTrcPacket::getD8Val() const
215 inline const uint16_t StmTrcPacket::getD16Val() const
220 inline const uint32_t StmTrcPacket::getD32Val() const
225 inline const uint64_t StmTrcPacket::getD64Val() const
230 inline const bool StmTrcPacket::isBadPacket() const
232 return (bool)(type >= STM_PKT_BAD_SEQUENCE);
236 #endif // ARM_TRC_PKT_ELEM_STM_H_INCLUDED
238 /* End of File trc_pkt_elem_stm.h */