Kinetis Bootloader Host  2.0.0
Host Tools for Kinetis devices
SimPacketizer.h
1 /*
2  * Copyright (c) 2013-14, Freescale Semiconductor, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * o Redistributions of source code must retain the above copyright notice, this list
9  * of conditions and the following disclaimer.
10  *
11  * o Redistributions in binary form must reproduce the above copyright notice, this
12  * list of conditions and the following disclaimer in the documentation and/or
13  * other materials provided with the distribution.
14  *
15  * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16  * contributors may be used to endorse or promote products derived from this
17  * software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef _sim_packetizer_h_
32 #define _sim_packetizer_h_
33 
34 #include "Packetizer.h"
35 #include "SimPeripheral.h"
36 #include "packet/command_packet.h"
37 
38 namespace blfwk
39 {
40 // Forward declarations.
41 class Peripheral;
42 
46 class SimPacketizer : public Packetizer
47 {
48 public:
51  {
52  kSimReadTimeoutMs = 5000
53  };
54 
55 public:
57  SimPacketizer(SimPeripheral *peripheral);
58 
60  virtual ~SimPacketizer();
61 
63  virtual SimPeripheral *getPeripheral() { return dynamic_cast<SimPeripheral *>(m_peripheral); }
70  virtual status_t readPacket(uint8_t **packet, uint32_t *packetLength, packet_type_t packetType);
71 
76  virtual status_t writePacket(const uint8_t *packet, uint32_t byteCount, packet_type_t packetType);
77 
79  virtual void abortPacket() { setAborted(true); }
81  virtual void sync(){};
82 
84  virtual void finalize();
85 
87  virtual void enableSimulatorPump() { m_isPumpEnabled = true; }
89  virtual void pumpSimulator();
90 
94  virtual void setAborted(bool aborted) { m_isAborted = aborted; }
96  virtual uint32_t getMaxPacketSize() { return kDefaultMaxPacketSize; }
97 protected:
99  bool m_isAborted;
100  uint8_t m_buffer[kDefaultMaxPacketSize];
101 };
102 
103 } // namespace blfwk
104 
105 #endif // _sim_packetizer_h_
106 
108 // EOF
Interface class for packetization of commands and data.
Definition: Packetizer.h:59
bool m_isPumpEnabled
True if simulator pump enabled.
Definition: SimPacketizer.h:98
Definition: BlfwkErrors.h:16
_simPacketizer_contants
Constants.
Definition: SimPacketizer.h:50
Peripheral that operates in the simulation space.
Definition: SimPeripheral.h:45
virtual void sync()
Send framing packet ack.
Definition: SimPacketizer.h:81
virtual ~SimPacketizer()
Destructor.
Definition: SimPacketizer.cpp:51
virtual void enableSimulatorPump()
Enable simulator command processor pump.
Definition: SimPacketizer.h:87
uint8_t m_buffer[kDefaultMaxPacketSize]
Buffer for bytes used to build read packet.
Definition: SimPacketizer.h:100
virtual SimPeripheral * getPeripheral()
Peripheral accessor.
Definition: SimPacketizer.h:63
virtual status_t readPacket(uint8_t **packet, uint32_t *packetLength, packet_type_t packetType)
Read a packet.
Definition: SimPacketizer.cpp:88
virtual uint32_t getMaxPacketSize()
Return the max packet size.
Definition: SimPacketizer.h:96
virtual void abortPacket()
Abort data phase.
Definition: SimPacketizer.h:79
SimPacketizer(SimPeripheral *peripheral)
Default Constructor.
Definition: SimPacketizer.cpp:43
Provides source and sink for packets in the simulator space.
Definition: SimPacketizer.h:46
virtual void pumpSimulator()
Pump simulator command processor.
Definition: SimPacketizer.cpp:125
virtual void setAborted(bool aborted)
Set aborted flag.
Definition: SimPacketizer.h:94
virtual status_t writePacket(const uint8_t *packet, uint32_t byteCount, packet_type_t packetType)
Write a packet.
Definition: SimPacketizer.cpp:62
bool m_isAborted
Data phase abort requested by receiver.
Definition: SimPacketizer.h:99
Peripheral * m_peripheral
Peripheral to send/receive bytes on.
Definition: Packetizer.h:113
virtual void finalize()
Finalize.
Definition: SimPacketizer.cpp:57