Loading...
Searching...
No Matches
trc_pkt_proc_stm.h
Go to the documentation of this file.
/*
* \file trc_pkt_proc_stm.h
* \brief OpenCSD : STM packet processing
*
* \copyright Copyright (c) 2015, ARM Limited. All Rights Reserved.
*/
/*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef ARM_TRC_PKT_PROC_STM_H_INCLUDED
#define ARM_TRC_PKT_PROC_STM_H_INCLUDED
#include <vector>
#include "trc_pkt_types_stm.h"
#include "common/trc_pkt_proc_base.h"
#include "trc_pkt_elem_stm.h"
#include "trc_cmp_cfg_stm.h"
class TrcPktProcStm : public TrcPktProcBase<StmTrcPacket, ocsd_stm_pkt_type, STMConfig>
{
public:
TrcPktProcStm();
TrcPktProcStm(int instIDNum);
virtual ~TrcPktProcStm();
protected:
/* implementation packet processing interface */
virtual ocsd_datapath_resp_t processData( const ocsd_trc_index_t index,
const uint32_t dataBlockSize,
const uint8_t *pDataBlock,
uint32_t *numBytesProcessed);
virtual ocsd_datapath_resp_t onEOT();
virtual ocsd_datapath_resp_t onReset();
virtual ocsd_datapath_resp_t onFlush();
virtual ocsd_err_t onProtocolConfig();
virtual const bool isBadPacket() const;
typedef enum _process_state {
WAIT_SYNC,
PROC_HDR,
PROC_DATA,
SEND_PKT
} process_state;
process_state m_proc_state;
private:
void initObj();
void initProcessorState();
void initNextPacket();
void waitForSync(const ocsd_trc_index_t blk_st_index);
ocsd_datapath_resp_t outputPacket();
void sendPacket();
void setProcUnsynced();
void throwBadSequenceError(const char *pszMessage = "");
void throwReservedHdrError(const char *pszMessage = "");
// packet processing routines
// 1 nibble opcodes
void stmPktReserved();
void stmPktNull();
void stmPktM8();
void stmPktMERR();
void stmPktC8();
void stmPktD4();
void stmPktD8();
void stmPktD16();
void stmPktD32();
void stmPktD64();
void stmPktD4MTS();
void stmPktD8MTS();
void stmPktD16MTS();
void stmPktD32MTS();
void stmPktD64MTS();
void stmPktFlagTS();
void stmPktFExt();
// 2 nibble opcodes 0xFn
void stmPktReservedFn();
void stmPktF0Ext();
void stmPktGERR();
void stmPktC16();
void stmPktD4TS();
void stmPktD8TS();
void stmPktD16TS();
void stmPktD32TS();
void stmPktD64TS();
void stmPktD4M();
void stmPktD8M();
void stmPktD16M();
void stmPktD32M();
void stmPktD64M();
void stmPktFlag();
void stmPktASync();
// 3 nibble opcodes 0xF0n
void stmPktReservedF0n();
void stmPktVersion();
void stmPktNullTS();
void stmPktTrigger();
void stmPktTriggerTS();
void stmPktFreq();
void stmExtractTS(); // extract a TS in packets that require it.
void stmExtractVal8(uint8_t nibbles_to_val);
void stmExtractVal16(uint8_t nibbles_to_val);
void stmExtractVal32(uint8_t nibbles_to_val);
void stmExtractVal64(uint8_t nibbles_to_val);
uint64_t bin_to_gray(uint64_t bin_value);
uint64_t gray_to_bin(uint64_t gray_value);
void pktNeedsTS(); // init the TS extraction routines
// data processing op function tables
void buildOpTables();
typedef void (TrcPktProcStm::*PPKTFN)(void);
PPKTFN m_pCurrPktFn; // current active processing function.
PPKTFN m_1N_ops[0x10];
PPKTFN m_2N_ops[0x10];
PPKTFN m_3N_ops[0x10];
// read a nibble from the input data - may read a byte and set spare or return spare.
// handles setting up packet data block and end of input
bool readNibble();
const bool dataToProcess() const;
void savePacketByte(const uint8_t val);
// packet data
StmTrcPacket m_curr_packet;
bool m_bNeedsTS;
bool m_bIsMarker;
bool m_bStreamSync;
// input data handling
uint8_t m_num_nibbles;
uint8_t m_nibble;
uint8_t m_nibble_2nd;
bool m_nibble_2nd_valid;
uint8_t m_num_data_nibbles;
const uint8_t *m_p_data_in;
uint32_t m_data_in_size;
uint32_t m_data_in_used;
ocsd_trc_index_t m_packet_index;
std::vector<uint8_t> m_packet_data;
bool m_bWaitSyncSaveSuppressed;
// payload data
uint8_t m_val8;
uint16_t m_val16;
uint32_t m_val32;
uint64_t m_val64;
// timestamp handling
uint8_t m_req_ts_nibbles;
uint8_t m_curr_ts_nibbles;
uint64_t m_ts_update_value;
bool m_ts_req_set;
// sync handling - need to spot sync mid other packet in case of wrap / discontinuity
uint8_t m_num_F_nibbles;
bool m_sync_start;
bool m_is_sync;
ocsd_trc_index_t m_sync_index;
void checkSyncNibble();
void clearSyncCount();
class monAttachNotify : public IComponentAttachNotifier
{
public:
monAttachNotify() { m_bInUse = false; };
virtual ~monAttachNotify() {};
virtual void attachNotify(const int num_attached) { m_bInUse = (num_attached > 0); };
const bool usingMonitor() const { return m_bInUse; };
private:
bool m_bInUse;
} mon_in_use;
};
inline const bool TrcPktProcStm::dataToProcess() const
{
// data to process if
// 1) not processed all the input bytes
// 2) there is still a nibble available from the last byte.
// 3) bytes processed, but there is a full packet to send
return (m_data_in_used < m_data_in_size) || m_nibble_2nd_valid || (m_proc_state == SEND_PKT);
}
inline void TrcPktProcStm::checkSyncNibble()
{
if(m_nibble != 0xF)
{
if(!m_sync_start)
return;
if((m_nibble == 0) && (m_num_F_nibbles >= 21))
{
m_is_sync = true; //this nibble marks a sync sequence
m_num_F_nibbles = 21; // set the F nibble count - lose any extra as unsynced data.
}
else
{
clearSyncCount(); // clear all sync counters
}
return;
}
m_num_F_nibbles++;
if(!m_sync_start)
{
m_sync_start = true;
m_sync_index = m_packet_index + ((m_num_nibbles - 1) / 2);
}
}
inline void TrcPktProcStm::clearSyncCount()
{
m_num_F_nibbles = 0;
m_sync_start = false;
m_is_sync = false;
}
inline void TrcPktProcStm::sendPacket()
{
m_proc_state = SEND_PKT;
}
inline void TrcPktProcStm::setProcUnsynced()
{
m_proc_state = WAIT_SYNC;
m_bStreamSync = false;
}
inline void TrcPktProcStm::savePacketByte(const uint8_t val)
{
// save packet data if using monitor and synchronised.
if(mon_in_use.usingMonitor() && !m_bWaitSyncSaveSuppressed)
m_packet_data.push_back(val);
}
#endif // ARM_TRC_PKT_PROC_STM_H_INCLUDED
/* End of File trc_pkt_proc_stm.h */
IComponentAttachNotifier
Definition comp_attach_notifier_i.h:46
StmTrcPacket
STM trace packet with packet printing functionality.
Definition trc_pkt_elem_stm.h:54
TrcPktProcStm::process_state
enum TrcPktProcStm::_process_state process_state
TrcPktProcStm::m_proc_state
process_state m_proc_state
Definition trc_pkt_proc_stm.h:75
TrcPktProcStm::onProtocolConfig
virtual ocsd_err_t onProtocolConfig()
Called when the configuration object is passed to the decoder.
TrcPktProcStm::TrcPktProcStm
TrcPktProcStm()
TrcPktProcStm::onReset
virtual ocsd_datapath_resp_t onReset()
Implementation function for the OCSD_OP_RESET operation.
TrcPktProcStm::processData
virtual ocsd_datapath_resp_t processData(const ocsd_trc_index_t index, const uint32_t dataBlockSize, const uint8_t *pDataBlock, uint32_t *numBytesProcessed)
Implementation function for the OCSD_OP_DATA operation.
TrcPktProcStm::onEOT
virtual ocsd_datapath_resp_t onEOT()
Implementation function for the OCSD_OP_EOT operation.
TrcPktProcStm::_process_state
_process_state
Definition trc_pkt_proc_stm.h:68
TrcPktProcStm::SEND_PKT
@ SEND_PKT
Definition trc_pkt_proc_stm.h:72
TrcPktProcStm::WAIT_SYNC
@ WAIT_SYNC
Definition trc_pkt_proc_stm.h:69
TrcPktProcStm::PROC_HDR
@ PROC_HDR
Definition trc_pkt_proc_stm.h:70
TrcPktProcStm::PROC_DATA
@ PROC_DATA
Definition trc_pkt_proc_stm.h:71
TrcPktProcStm::TrcPktProcStm
TrcPktProcStm(int instIDNum)
TrcPktProcStm::isBadPacket
virtual const bool isBadPacket() const
check if the current packet is an error / bad packet
TrcPktProcStm::~TrcPktProcStm
virtual ~TrcPktProcStm()
TrcPktProcStm::onFlush
virtual ocsd_datapath_resp_t onFlush()
Implementation function for the OCSD_OP_FLUSH operation.
ocsd_trc_index_t
uint32_t ocsd_trc_index_t
Definition ocsd_if_types.h:59
ocsd_datapath_resp_t
enum _ocsd_datapath_resp_t ocsd_datapath_resp_t
ocsd_err_t
enum _ocsd_err_t ocsd_err_t
TrcPktProcBase< StmTrcPacket, ocsd_stm_pkt_type, STMConfig >::TrcPktProcBase
TrcPktProcBase(const char *component_name)
Definition trc_pkt_proc_base.h:220
trc_cmp_cfg_stm.h
trc_pkt_elem_stm.h
OpenCSD : STM packet class.
trc_pkt_proc_base.h
OpenCSD : Trace packet processor base class.
trc_pkt_types_stm.h