Kinetis Bootloader Host  2.0.0
Host Tools for Kinetis devices
Packetizer.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 _Packetizer_h_
32 #define _Packetizer_h_
33 
34 #include "bootloader_common.h"
35 #include "bootloader/bl_peripheral.h"
36 
37 #include <time.h>
38 
41 
42 namespace blfwk
43 {
44 // Forward declarations.
45 class Peripheral;
46 
48 enum _packetizer_status
49 {
50  kStatus_NoPingResponse = MAKE_STATUS(kStatusGroup_Packetizer, 0),
51  kStatus_InvalidPacketType = MAKE_STATUS(kStatusGroup_Packetizer, 1),
52  kStatus_InvalidCRC = MAKE_STATUS(kStatusGroup_Packetizer, 2),
53  kStatus_NoCommandResponse = MAKE_STATUS(kStatusGroup_Packetizer, 3)
54 };
55 
60 {
61 public:
62  Packetizer(Peripheral *peripheral, uint32_t packetTimeoutMs)
63  : m_peripheral(peripheral)
64  , m_packetTimeoutMs(packetTimeoutMs)
65  , m_version()
66  , m_options(0)
67  , m_isAbortEnabled(false)
68  {
69  }
70 
71  virtual ~Packetizer(){};
72 
74  virtual status_t readPacket(uint8_t **packet, uint32_t *packetLength, packet_type_t packetType) = 0;
75 
77  virtual status_t writePacket(const uint8_t *packet, uint32_t byteCount, packet_type_t packetType) = 0;
78 
80  virtual void abortPacket() = 0;
81 
83  virtual void sync() = 0;
84 
86  virtual void finalize() = 0;
87 
89  virtual void enableSimulatorPump() = 0;
90 
92  virtual void pumpSimulator() = 0;
93 
97  virtual void setAborted(bool aborted) = 0;
98 
100  virtual uint32_t getMaxPacketSize() = 0;
101 
103  virtual Peripheral *getPeripheral() { return m_peripheral; }
107  uint16_t getOptions() { return m_options; }
109  void setAbortEnabled(bool isEnabled) { m_isAbortEnabled = isEnabled; }
111  bool isAbortEnabled() { return m_isAbortEnabled; }
112 protected:
115  uint16_t m_options;
116  clock_t m_startTime;
117  uint32_t m_packetTimeoutMs;
119 };
120 
121 } // namespace blfwk
122 
124 
125 #endif // _Packetizer_h_
126 
128 // EOF
clock_t m_startTime
Beginning time of packet transaction.
Definition: Packetizer.h:116
Interface class for packetization of commands and data.
Definition: Packetizer.h:59
virtual void pumpSimulator()=0
Pump simulator command processor.
virtual void setAborted(bool aborted)=0
Set aborted flag.
Definition: BlfwkErrors.h:16
bool m_isAbortEnabled
True if allowing abort packet. Not used by all packetizers.
Definition: Packetizer.h:118
void setAbortEnabled(bool isEnabled)
Set abort packet check enable.
Definition: Packetizer.h:109
virtual void abortPacket()=0
Abort data phase.
standard_version_t m_version
Framing protocol version.
Definition: Packetizer.h:114
virtual void sync()=0
Send framing packet ack.
virtual status_t writePacket(const uint8_t *packet, uint32_t byteCount, packet_type_t packetType)=0
Write a packet.
Definition: qspi_config_block_generator.c:101
virtual status_t readPacket(uint8_t **packet, uint32_t *packetLength, packet_type_t packetType)=0
Read a packet.
bool isAbortEnabled()
Check if abort data phase is enabled.
Definition: Packetizer.h:111
virtual uint32_t getMaxPacketSize()=0
Return the max packet size.
virtual void finalize()=0
Finalize.
uint16_t m_options
Framing protocol options bitfield.
Definition: Packetizer.h:115
Represents a peripheral.
Definition: Peripheral.h:48
uint16_t getOptions()
Get Framing Protocol Options.
Definition: Packetizer.h:107
virtual Peripheral * getPeripheral()
Peripheral accessor.
Definition: Packetizer.h:103
virtual void enableSimulatorPump()=0
Enable simulator command processor pump.
standard_version_t getVersion()
Get Framing Protocol Version.
Definition: Packetizer.h:105
Peripheral * m_peripheral
Peripheral to send/receive bytes on.
Definition: Packetizer.h:113