1 /* 2 * \file trc_frame_decoder_impl.h 3 * \brief OpenCSD : Trace Deformatter implementation. 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_FRAME_DECODER_IMPL_H_INCLUDED 36 #define ARM_TRC_FRAME_DECODER_IMPL_H_INCLUDED 37 38 #include "opencsd/ocsd_if_types.h" 39 #include "common/comp_attach_pt_t.h" 40 #include "interfaces/trc_data_raw_in_i.h" 41 #include "interfaces/trc_data_rawframe_in_i.h" 42 #include "interfaces/trc_indexer_src_i.h" 43 #include "common/trc_component.h" 44 45 //! output data fragment from the current frame - collates bytes associated with an ID. 46 typedef struct _out_chan_data { 47 ocsd_trc_index_t index; //!< trace source index for start of these bytes 48 uint8_t id; //!< Id for these bytes 49 uint8_t data[15]; //!< frame data bytes for this ID 50 uint32_t valid; //!< Valid data bytes. 51 uint32_t used; //!< Data bytes output (used by attached processor). 52 } out_chan_data; 53 54 class TraceFmtDcdImpl : public TraceComponent, ITrcDataIn 55 { 56 private: 57 TraceFmtDcdImpl(); 58 TraceFmtDcdImpl(int instNum); 59 virtual ~TraceFmtDcdImpl(); 60 61 /* the data input interface from the reader */ 62 virtual ocsd_datapath_resp_t TraceDataIn( const ocsd_datapath_op_t op, 63 const ocsd_trc_index_t index, 64 const uint32_t dataBlockSize, 65 const uint8_t *pDataBlock, 66 uint32_t *numBytesProcessed); 67 68 /* enable / disable ID streams - default as all enabled */ 69 ocsd_err_t OutputFilterIDs(std::vector<uint8_t> &id_list, bool bEnable); 70 ocsd_err_t OutputFilterAllIDs(bool bEnable); 71 72 /* decode control */ 73 ocsd_datapath_resp_t Reset(); /* reset the decode to the start state, drop partial data - propogate to attached components */ 74 ocsd_datapath_resp_t Flush(); 75 ocsd_err_t DecodeConfigure(uint32_t flags); 76 ocsd_err_t SetForcedSyncIndex(ocsd_trc_index_t index, bool bSet); 77 78 private: 79 ocsd_datapath_resp_t executeNoneDataOpAllIDs(ocsd_datapath_op_t op, const ocsd_trc_index_t index = 0); 80 ocsd_datapath_resp_t processTraceData(const ocsd_trc_index_t index, 81 const uint32_t dataBlockSize, 82 const uint8_t *pDataBlock, 83 uint32_t *numBytesProcessed); 84 // process phases 85 bool checkForSync(); // find the sync point in the incoming block 86 bool extractFrame(); // extract the frame data from incoming stream 87 bool unpackFrame(); // process a complete frame. 88 bool outputFrame(); // output data to channels. 89 90 91 // managing data path responses. InitCollateDataPathResp()92 void InitCollateDataPathResp() { m_highestResp = OCSD_RESP_CONT; }; 93 void CollateDataPathResp(const ocsd_datapath_resp_t resp); highestDataPathResp()94 const ocsd_datapath_resp_t highestDataPathResp() const { return m_highestResp; }; dataPathCont()95 const bool dataPathCont() const { return (bool)(m_highestResp < OCSD_RESP_WAIT); }; 96 97 // deformat state 98 void resetStateParams(); 99 100 // synchronisation 101 uint32_t findfirstFSync(); 102 void outputUnsyncedBytes(uint32_t num_bytes); // output bytes as unsynced from current buffer position. 103 104 // output bytes to raw frame monitor 105 void outputRawMonBytes(const ocsd_datapath_op_t op, 106 const ocsd_trc_index_t index, 107 const ocsd_rawframe_elem_t frame_element, 108 const int dataBlockSize, 109 const uint8_t *pDataBlock, 110 const uint8_t traceID); 111 112 113 void setRawChanFilterAll(bool bEnable); 114 const bool rawChanEnabled(const uint8_t id) const; 115 116 int checkForResetFSyncPatterns(); 117 118 friend class TraceFormatterFrameDecoder; 119 120 // attachment points 121 122 componentAttachPt<ITrcDataIn> m_IDStreams[128]; 123 componentAttachPt<ITrcRawFrameIn> m_RawTraceFrame; 124 125 componentAttachPt<ITrcSrcIndexCreator> m_SrcIndexer; 126 127 128 ocsd_datapath_resp_t m_highestResp; 129 130 /* static configuration */ 131 uint32_t m_cfgFlags; /* configuration flags */ 132 ocsd_trc_index_t m_force_sync_idx; 133 bool m_use_force_sync; 134 uint32_t m_alignment; 135 136 /* dynamic state */ 137 ocsd_trc_index_t m_trc_curr_idx; /* index of current trace data */ 138 bool m_frame_synced; 139 bool m_first_data; 140 uint8_t m_curr_src_ID; 141 142 // incoming frame buffer 143 uint8_t m_ex_frm_data[OCSD_DFRMTR_FRAME_SIZE]; // buffer the current frame in case we have to stop part way through 144 int m_ex_frm_n_bytes; // number of valid bytes in the current frame (extraction) 145 ocsd_trc_index_t m_trc_curr_idx_sof; // trace source index at start of frame. 146 147 // channel output data - can never be more than a frame of data for a single ID. 148 out_chan_data m_out_data[7]; // can only be 8 ID changes in a frame, but last on has no associated data so 7 possible data blocks 149 int m_out_data_idx; // number of out_chan_data frames used. 150 int m_out_processed; // number of complete out_chan_data frames output. 151 152 /* local copy of input buffer pointers*/ 153 const uint8_t *m_in_block_base; 154 uint32_t m_in_block_size; 155 uint32_t m_in_block_processed; 156 157 /* raw output options */ 158 bool m_b_output_packed_raw; 159 bool m_b_output_unpacked_raw; 160 161 bool m_raw_chan_enable[128]; 162 }; 163 164 165 #endif // ARM_TRC_FRAME_DECODER_IMPL_H_INCLUDED 166 167 /* End of File trc_frame_decoder_impl.h */ 168