Add Freescale Nexus decoder implementation
[babeltrace.git] / converter / nexus / MSEState.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 "MSEState.h"
24 #include <assert.h>
25
26 // globally initialized
27 bool MSEState::start_optimized_message_ = false;
28
29 // initialize the state transition table
30 void MSEState::initialize_transitions(MSEState *new_state_00,
31 MSEState *new_state_01, MSEState *new_state_10, MSEState *new_state_11)
32 {
33 next_state_[0] = new_state_00;
34 next_state_[1] = new_state_01;
35 next_state_[2] = new_state_10;
36 next_state_[3] = new_state_11;
37 }
38
39 // update to the next state
40 MSEState *MSEState::nextState(uint32_t index)
41 {
42 assert(index < MAX_STATE_TRANSITIONS);
43
44 // set the next state
45 return next_state_[index];
46 }
47
48 // update to the next state
49 MSEState * MSEIdle::nextState(uint32_t mse)
50 {
51 if (mse == 0x1 || mse == 0x2) {
52 MSEState::start_optimized_message_ = true;
53 }
54 // set the next state
55 return MSEState::nextState(mse);
56 }
57 // perform the action on the MDO for this state
58 bool MSEIdle::act(uint32_t mdo, NxPacketSet &pkt_set)
59 {
60 if (MSEState::start_optimized_message_) {
61 pkt_set.reset();
62 MSEState::start_optimized_message_ = false;
63 }
64 return true;
65 }
66
67 bool MSEStartMessage::act(uint32_t mdo, NxPacketSet &pkt_set)
68 {
69 pkt_set.reset();
70 bool ret = pkt_set.addToCurrent(mdo);
71 return ret;
72 }
73
74 bool MSENormalTransfer::act(uint32_t mdo, NxPacketSet &pkt_set)
75 {
76 bool ret = pkt_set.addToCurrent(mdo);
77 return ret;
78 }
79
80 bool MSEEndPacket::act(uint32_t mdo, NxPacketSet &pkt_set)
81 {
82 if (MSEState::start_optimized_message_) {
83 pkt_set.reset();
84 MSEState::start_optimized_message_ = false;
85 }
86 bool ret = pkt_set.addToCurrent(mdo);
87 if (ret) {
88 ret = pkt_set.nextPacket();
89 }
90 return ret;
91 }
92 bool MSEEndMessage::act(uint32_t mdo, NxPacketSet &pkt_set)
93 {
94 if (MSEState::start_optimized_message_) {
95 pkt_set.reset();
96 MSEState::start_optimized_message_ = false;
97 }
98 bool ret = pkt_set.addToCurrent(mdo);
99 return ret;
100 }
101
102 // update to the next state
103 MSEState *MSEEndMessage::nextState(uint32_t mse)
104 {
105 if (mse == 0x1 || mse == 0x2) {
106 MSEState::start_optimized_message_ = true;
107 }
108 // set the next state
109 return MSEState::nextState(mse);
110 }
This page took 0.032429 seconds and 4 git commands to generate.