Add Freescale Nexus decoder implementation
[babeltrace.git] / converter / nexus / MSEState.h
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 #ifndef MSESTATE_H
24 #define MSESTATE_H
25
26 #include <inttypes.h>
27 #include "AUXMessageProtocol.h"
28 #include "NxPacketSet.h"
29
30 #include <string>
31 using std::string;
32
33 // Abstract MSEState to contain the transition tables
34 // and the state specific outcomes.
35 class MSEState
36 {
37 public:
38
39 // Constructor to allow initialization of the state information
40 MSEState(AUXMessageProtocol::Outcome outcome, const char *name) :
41 outcome_(outcome), state_name_(name)
42 {
43 }
44 virtual ~MSEState()
45 {
46 }
47
48 // update to the next state
49 virtual MSEState *nextState(uint32_t mse);
50
51 // return the outcome for this state
52 virtual AUXMessageProtocol::Outcome outcome() const
53 {
54 return outcome_;
55 }
56
57 // perform the action on the MDO for this state
58 virtual bool act(uint32_t mdo, NxPacketSet &pkt_set) = 0;
59
60 // initialize the state transition table
61 void initialize_transitions(MSEState *new_state_00,
62 MSEState *new_state_01, MSEState *new_state_10,
63 MSEState *new_state_11);
64
65 // state name
66 const char* name() const
67 {
68 return state_name_.c_str();
69 }
70
71 // indicates if an optimized single beat message is being processed
72 // shared across all states
73 static bool start_optimized_message_;
74
75 private:
76 // Number of possible transitions from every state
77 static const uint32_t MAX_STATE_TRANSITIONS = 4;
78
79 // table of next states based on MSE value
80 MSEState *next_state_[MAX_STATE_TRANSITIONS];
81
82 // The result of being in a state
83 AUXMessageProtocol::Outcome outcome_;
84
85 // name of the state
86 const string state_name_;
87 };
88
89 // MSEIdle
90 class MSEIdle: public MSEState
91 {
92 public:
93
94 MSEIdle() :
95 MSEState(AUXMessageProtocol::DISCARD, "IDLE")
96 {
97 }
98 virtual ~MSEIdle()
99 {
100 }
101
102 // update to the next state
103 virtual MSEState *nextState(uint32_t mse);
104
105 // perform the action on the MDO for this state
106 virtual bool act(uint32_t mdo, NxPacketSet &pkt_set);
107
108 };
109
110 // MSEStartMessage
111 class MSEStartMessage: public MSEState
112 {
113 public:
114
115 MSEStartMessage() :
116 MSEState(AUXMessageProtocol::ADD_NEW_MESSAGE, "START_MESSAGE")
117 {
118 }
119 virtual ~MSEStartMessage()
120 {
121 }
122
123 // perform the action on the MDO for this state
124 virtual bool act(uint32_t mdo, NxPacketSet &pkt_set);
125 };
126
127 // MSENormalTransfer
128 class MSENormalTransfer: public MSEState
129 {
130 public:
131
132 MSENormalTransfer() :
133 MSEState(AUXMessageProtocol::ADD_CURRENT, "NORMAL_TRANSFER")
134 {
135 }
136 virtual ~MSENormalTransfer()
137 {
138 }
139
140 // perform the action on the MDO for this state
141 virtual bool act(uint32_t mdo, NxPacketSet &pkt_set);
142 };
143
144 // MSEEndPacket
145 class MSEEndPacket: public MSEState
146 {
147 public:
148
149 MSEEndPacket() :
150 MSEState(AUXMessageProtocol::ADD_LAST_PACKET, "END_PACKET")
151 {
152 }
153 virtual ~MSEEndPacket()
154 {
155 }
156
157 // perform the action on the MDO for this state
158 virtual bool act(uint32_t mdo, NxPacketSet &pkt_set);
159 };
160
161 // MSEEndMessage
162 class MSEEndMessage: public MSEState
163 {
164 public:
165
166 MSEEndMessage() :
167 MSEState(AUXMessageProtocol::ADD_LAST_MESSAGE, "END_MESSAGE")
168 {
169 }
170 virtual ~MSEEndMessage()
171 {
172 }
173
174 // update to the next state
175 virtual MSEState *nextState(uint32_t mse);
176
177 // perform the action on the MDO for this state
178 virtual bool act(uint32_t mdo, NxPacketSet &pkt_set);
179 };
180
181 #endif // MSESTATE_H
This page took 0.039184 seconds and 4 git commands to generate.