Add Freescale Nexus decoder implementation
[babeltrace.git] / converter / nexus / FManDebugLogVisitor.cpp
1 /*
2 * Copyright (C) 2013 Freescale Semiconductor, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 * IN THE SOFTWARE.
21 */
22
23 #include <inttypes.h>
24 #include <sstream>
25 #include <iomanip>
26
27 #include "FManDebugLogVisitor.h"
28 #include "NxMessageVisitor.h"
29 #include "NxMessage.h"
30 #include "FManDebugLog.h"
31
32 using std::ostringstream;
33 using std::endl;
34 using std::hex;
35 using std::dec;
36 using std::setfill;
37 using std::setw;
38
39 FManDebugLogVisitor::FManDebugLogVisitor()
40 {
41 for (int i = 0; i < MAX_FMAN_LOGS; i++) {
42 log_[i] = new FManDebugLog();
43 log_[i]->setFManID(i);
44 already_reported_[i] = false;
45 }
46 }
47
48 FManDebugLogVisitor::~FManDebugLogVisitor()
49 {
50 for (int i = 0; i < MAX_FMAN_LOGS; i++) {
51 delete log_[i];
52 }
53 }
54
55 void FManDebugLogVisitor::visit(NxDPFMInCircuitTraceMessage *m)
56 {
57 // select the correct log
58 int fmsel = m->getFmsel();
59 if ( fmsel < 0 || fmsel >= MAX_FMAN_LOGS) {
60 return;
61 }
62 FManDebugLog *log = log_[fmsel];
63
64 // if this is the first beat then reset the log
65 int beatcnt = m->getBtcnt();
66 if (beatcnt == 0) {
67 already_reported_[fmsel] = false;
68 log->reset();
69 }
70
71 // capture the context data - always 4 words
72 const uint32_t *context = m->getContext();
73 for (int i = 0; i < 4; i++) {
74 log->addContextData(context[i]);
75 }
76
77 // begin parsing the log on the last beat
78 bool lastbeat = m->getLbeat();
79 if (lastbeat) {
80 log->setLastContextData();
81 log->parseContextData();
82 }
83 useful_visit_ = true;
84 }
85
86 // output message information as a string
87 string FManDebugLogVisitor::asString() const
88 {
89 ostringstream os;
90 if (useful_visit_) {
91 for (int i = 0; i < MAX_FMAN_LOGS; i++) {
92 if (log_[i]->logComplete() && !already_reported_[i]) {
93 os << log_[i]->asString();
94 already_reported_[i] = true;
95 }
96 }
97 }
98 return os.str();
99 }
This page took 0.035207 seconds and 4 git commands to generate.