1*b6aadd18SAndrew Turner /*
2*b6aadd18SAndrew Turner * \file ocsd_gen_elem_stack.h
3*b6aadd18SAndrew Turner * \brief OpenCSD : Generic element output stack.
4*b6aadd18SAndrew Turner *
5*b6aadd18SAndrew Turner * \copyright Copyright (c) 2020, ARM Limited. All Rights Reserved.
6*b6aadd18SAndrew Turner */
7*b6aadd18SAndrew Turner
8*b6aadd18SAndrew Turner /*
9*b6aadd18SAndrew Turner * Redistribution and use in source and binary forms, with or without modification,
10*b6aadd18SAndrew Turner * are permitted provided that the following conditions are met:
11*b6aadd18SAndrew Turner *
12*b6aadd18SAndrew Turner * 1. Redistributions of source code must retain the above copyright notice,
13*b6aadd18SAndrew Turner * this list of conditions and the following disclaimer.
14*b6aadd18SAndrew Turner *
15*b6aadd18SAndrew Turner * 2. Redistributions in binary form must reproduce the above copyright notice,
16*b6aadd18SAndrew Turner * this list of conditions and the following disclaimer in the documentation
17*b6aadd18SAndrew Turner * and/or other materials provided with the distribution.
18*b6aadd18SAndrew Turner *
19*b6aadd18SAndrew Turner * 3. Neither the name of the copyright holder nor the names of its contributors
20*b6aadd18SAndrew Turner * may be used to endorse or promote products derived from this software without
21*b6aadd18SAndrew Turner * specific prior written permission.
22*b6aadd18SAndrew Turner *
23*b6aadd18SAndrew Turner * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
24*b6aadd18SAndrew Turner * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25*b6aadd18SAndrew Turner * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26*b6aadd18SAndrew Turner * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27*b6aadd18SAndrew Turner * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28*b6aadd18SAndrew Turner * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29*b6aadd18SAndrew Turner * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30*b6aadd18SAndrew Turner * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31*b6aadd18SAndrew Turner * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32*b6aadd18SAndrew Turner * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33*b6aadd18SAndrew Turner */
34*b6aadd18SAndrew Turner
35*b6aadd18SAndrew Turner #include "trc_gen_elem.h"
36*b6aadd18SAndrew Turner #include "comp_attach_pt_t.h"
37*b6aadd18SAndrew Turner #include "interfaces/trc_gen_elem_in_i.h"
38*b6aadd18SAndrew Turner
39*b6aadd18SAndrew Turner /* element stack to handle cases where a trace element can generate multiple output packets
40*b6aadd18SAndrew Turner
41*b6aadd18SAndrew Turner maintains the "current" element, which might be sent independently of this stack, and also
42*b6aadd18SAndrew Turner ensures that persistent data in the output elements is maintained between elements.
43*b6aadd18SAndrew Turner */
44*b6aadd18SAndrew Turner class OcsdGenElemStack
45*b6aadd18SAndrew Turner {
46*b6aadd18SAndrew Turner public:
47*b6aadd18SAndrew Turner OcsdGenElemStack();
48*b6aadd18SAndrew Turner ~OcsdGenElemStack();
49*b6aadd18SAndrew Turner
50*b6aadd18SAndrew Turner void initSendIf(componentAttachPt<ITrcGenElemIn> *pGenElemIf);
initCSID(const uint8_t CSID)51*b6aadd18SAndrew Turner void initCSID(const uint8_t CSID) { m_CSID = CSID; };
52*b6aadd18SAndrew Turner
53*b6aadd18SAndrew Turner OcsdTraceElement &getCurrElem(); //!< get the current element.
54*b6aadd18SAndrew Turner ocsd_err_t resetElemStack(); //!< set pointers to base of stack
55*b6aadd18SAndrew Turner ocsd_err_t addElem(const ocsd_trc_index_t trc_pkt_idx); //!< add elem to stack and set current.
56*b6aadd18SAndrew Turner void setCurrElemIdx(const ocsd_trc_index_t trc_pkt_idx); //!< packet index for this element
57*b6aadd18SAndrew Turner ocsd_err_t addElemType(const ocsd_trc_index_t trc_pkt_idx, ocsd_gen_trc_elem_t elem_type);
58*b6aadd18SAndrew Turner
59*b6aadd18SAndrew Turner ocsd_datapath_resp_t sendElements(); //!< send elements on the stack
60*b6aadd18SAndrew Turner const int numElemToSend() const;
61*b6aadd18SAndrew Turner
62*b6aadd18SAndrew Turner private:
63*b6aadd18SAndrew Turner typedef struct _elemPtr {
64*b6aadd18SAndrew Turner OcsdTraceElement *pElem; //!< pointer to the listed trace element
65*b6aadd18SAndrew Turner ocsd_trc_index_t trc_pkt_idx; //!< packet index in the trace stream
66*b6aadd18SAndrew Turner } elemPtr_t;
67*b6aadd18SAndrew Turner
68*b6aadd18SAndrew Turner const bool isInit(); //!< check correctly initialised.
69*b6aadd18SAndrew Turner
70*b6aadd18SAndrew Turner ocsd_err_t growArray();
71*b6aadd18SAndrew Turner void copyPersistentData(int src, int dst); //!< copy across persistent state data between elements
72*b6aadd18SAndrew Turner void resetIndexes(); //!< clear down all indexes - reset or send complete.
73*b6aadd18SAndrew Turner
74*b6aadd18SAndrew Turner elemPtr_t *m_pElemArray; //!< an array of pointers to elements.
75*b6aadd18SAndrew Turner int m_elemArraySize; //!< number of element pointers in the array
76*b6aadd18SAndrew Turner
77*b6aadd18SAndrew Turner int m_elem_to_send; //!< number of live elements in the stack - init to 1.
78*b6aadd18SAndrew Turner int m_curr_elem_idx; //!< index into the element array.
79*b6aadd18SAndrew Turner int m_send_elem_idx; //!< next element to send.
80*b6aadd18SAndrew Turner
81*b6aadd18SAndrew Turner //!< send packet info
82*b6aadd18SAndrew Turner uint8_t m_CSID;
83*b6aadd18SAndrew Turner componentAttachPt<ITrcGenElemIn> *m_sendIf; //!< element send interface.
84*b6aadd18SAndrew Turner
85*b6aadd18SAndrew Turner bool m_is_init;
86*b6aadd18SAndrew Turner };
87*b6aadd18SAndrew Turner
numElemToSend()88*b6aadd18SAndrew Turner inline const int OcsdGenElemStack::numElemToSend() const
89*b6aadd18SAndrew Turner {
90*b6aadd18SAndrew Turner return m_elem_to_send;
91*b6aadd18SAndrew Turner }
92*b6aadd18SAndrew Turner
initSendIf(componentAttachPt<ITrcGenElemIn> * pGenElemIf)93*b6aadd18SAndrew Turner inline void OcsdGenElemStack::initSendIf(componentAttachPt<ITrcGenElemIn> *pGenElemIf)
94*b6aadd18SAndrew Turner {
95*b6aadd18SAndrew Turner m_sendIf = pGenElemIf;
96*b6aadd18SAndrew Turner }
97*b6aadd18SAndrew Turner
setCurrElemIdx(const ocsd_trc_index_t trc_pkt_idx)98*b6aadd18SAndrew Turner inline void OcsdGenElemStack::setCurrElemIdx(const ocsd_trc_index_t trc_pkt_idx)
99*b6aadd18SAndrew Turner {
100*b6aadd18SAndrew Turner m_pElemArray[m_curr_elem_idx].trc_pkt_idx = trc_pkt_idx;
101*b6aadd18SAndrew Turner }
102*b6aadd18SAndrew Turner
getCurrElem()103*b6aadd18SAndrew Turner inline OcsdTraceElement &OcsdGenElemStack::getCurrElem()
104*b6aadd18SAndrew Turner {
105*b6aadd18SAndrew Turner return *(m_pElemArray[m_curr_elem_idx].pElem);
106*b6aadd18SAndrew Turner }
107*b6aadd18SAndrew Turner
108*b6aadd18SAndrew Turner
109*b6aadd18SAndrew Turner /* End of File ocsd_gen_elem_stack.h */
110