1 /*! 2 * \file trc_pkt_elem_stm.h 3 * \brief OpenCSD : STM packet class. 4 * 5 * \copyright Copyright (c) 2015, ARM Limited. All Rights Reserved. 6 */ 7 8 /* 9 * Redistribution and use in source and binary forms, with or without modification, 10 * are permitted provided that the following conditions are met: 11 * 12 * 1. Redistributions of source code must retain the above copyright notice, 13 * this list of conditions and the following disclaimer. 14 * 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. 18 * 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. 22 * 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. 33 */ 34 35 #ifndef ARM_TRC_PKT_ELEM_STM_H_INCLUDED 36 #define ARM_TRC_PKT_ELEM_STM_H_INCLUDED 37 38 #include "trc_pkt_types_stm.h" 39 #include "common/trc_printable_elem.h" 40 #include "common/trc_pkt_elem_base.h" 41 42 /*! 43 * @class StmTrcPacket 44 * @brief STM trace packet with packet printing functionality 45 * 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. 49 * 50 * Based on data structure ocsd_stm_pkt. 51 * 52 */ 53 class StmTrcPacket : public TrcPacketBase, public ocsd_stm_pkt, public trcPrintableElem 54 { 55 public: 56 StmTrcPacket(); 57 ~StmTrcPacket() {}; 58 59 StmTrcPacket &operator =(const ocsd_stm_pkt *p_pkt); 60 61 virtual const void *c_pkt() const { return (const ocsd_stm_pkt *)this; }; 62 63 void initStartState(); //!< Initialise packet state at start of decoder. 64 void initNextPacket(); //!< Initialise state for next packet. 65 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); 72 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); 78 79 const bool isMarkerPkt() const; 80 const bool isTSPkt() const; 81 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; 88 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; 94 95 const bool isBadPacket() const; 96 97 // printing 98 virtual void toString(std::string &str) const; 99 virtual void toStringFmt(const uint32_t fmtFlags, std::string &str) const; 100 101 102 private: 103 void pktTypeName(const ocsd_stm_pkt_type pkt_type, std::string &name, std::string &desc) const; 104 }; 105 106 inline void StmTrcPacket::setPacketType(const ocsd_stm_pkt_type type, const bool bMarker) 107 { 108 this->type = type; 109 if(bMarker) 110 pkt_has_marker = 1; 111 } 112 113 inline void StmTrcPacket::updateErrType(const ocsd_stm_pkt_type err_type) 114 { 115 this->err_type = this->type; // original type is the err type; 116 this->type = err_type; // mark main type as an error. 117 } 118 119 inline void StmTrcPacket::setMaster(const uint8_t master) 120 { 121 this->master = master; 122 channel = 0; // M8 forces current channel to 0. 123 } 124 125 inline void StmTrcPacket::setChannel(const uint16_t channel, const bool b8Bit) 126 { 127 if(b8Bit) 128 this->channel = (this->channel & 0xFF00) | (channel & 0xFF); 129 else 130 this->channel = channel; 131 } 132 133 inline void StmTrcPacket::onVersionPkt(const ocsd_stm_ts_type type) 134 { 135 this->ts_type = type; 136 master = 0; 137 channel = 0; 138 } 139 140 inline void StmTrcPacket::setD4Payload(const uint8_t value) 141 { 142 payload.D8 = value & 0xF; 143 } 144 145 inline void StmTrcPacket::setD8Payload(const uint8_t value) 146 { 147 payload.D8 = value; 148 } 149 150 inline void StmTrcPacket::setD16Payload(const uint16_t value) 151 { 152 payload.D16 = value; 153 } 154 155 inline void StmTrcPacket::setD32Payload(const uint32_t value) 156 { 157 payload.D32 = value; 158 } 159 160 inline void StmTrcPacket::setD64Payload(const uint64_t value) 161 { 162 payload.D64 = value; 163 } 164 165 inline const bool StmTrcPacket::isMarkerPkt() const 166 { 167 return (pkt_has_marker != 0); 168 } 169 170 inline const bool StmTrcPacket::isTSPkt() const 171 { 172 return (pkt_has_ts != 0); 173 } 174 175 inline const ocsd_stm_pkt_type StmTrcPacket::getPktType() const 176 { 177 return type; 178 } 179 180 inline const ocsd_stm_pkt_type StmTrcPacket::getPktErrType() const 181 { 182 return err_type; 183 } 184 185 inline const uint8_t StmTrcPacket::getMaster() const 186 { 187 return master; 188 } 189 190 inline const uint16_t StmTrcPacket::getChannel() const 191 { 192 return channel; 193 } 194 195 inline const ocsd_stm_ts_type StmTrcPacket::getTSType() const 196 { 197 return ts_type; 198 } 199 200 inline const uint64_t StmTrcPacket::getTSVal() const 201 { 202 return timestamp; 203 } 204 205 inline const uint8_t StmTrcPacket::getD4Val() const 206 { 207 return payload.D8; 208 } 209 210 inline const uint8_t StmTrcPacket::getD8Val() const 211 { 212 return payload.D8; 213 } 214 215 inline const uint16_t StmTrcPacket::getD16Val() const 216 { 217 return payload.D16; 218 } 219 220 inline const uint32_t StmTrcPacket::getD32Val() const 221 { 222 return payload.D32; 223 } 224 225 inline const uint64_t StmTrcPacket::getD64Val() const 226 { 227 return payload.D64; 228 } 229 230 inline const bool StmTrcPacket::isBadPacket() const 231 { 232 return (bool)(type >= STM_PKT_BAD_SEQUENCE); 233 } 234 235 236 #endif // ARM_TRC_PKT_ELEM_STM_H_INCLUDED 237 238 /* End of File trc_pkt_elem_stm.h */ 239