ngscopeclient 0.1-dev+51fbda87c
SPIFlashDecoder.h
Go to the documentation of this file.
1/***********************************************************************************************************************
2* *
3* libscopeprotocols *
4* *
5* Copyright (c) 2012-2022 Andrew D. Zonenberg and contributors *
6* All rights reserved. *
7* *
8* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
9* following conditions are met: *
10* *
11* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
12* following disclaimer. *
13* *
14* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
15* following disclaimer in the documentation and/or other materials provided with the distribution. *
16* *
17* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
18* derived from this software without specific prior written permission. *
19* *
20* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
21* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
22* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
24* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
25* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
26* POSSIBILITY OF SUCH DAMAGE. *
27* *
28***********************************************************************************************************************/
29
35#ifndef SPIFlashDecoder_h
36#define SPIFlashDecoder_h
37
38#include "../scopehal/PacketDecoder.h"
39
41{
42public:
43
44 enum FlashType
45 {
46 //Generic
47 TYPE_COMMAND,
48 TYPE_ADDRESS,
49 TYPE_DATA,
50
51 TYPE_DUMMY,
52
53 //ID codes
54 TYPE_VENDOR_ID,
55 TYPE_PART_ID,
56
57 //Winbond W25N specific
58 TYPE_W25N_BLOCK_ADDR,
59 TYPE_W25N_SR_ADDR, //address of a status register
60 TYPE_W25N_SR_STATUS,
61 TYPE_W25N_SR_CONFIG,
62 TYPE_W25N_SR_PROT
63
64 } m_type;
65
66 enum FlashCommand
67 {
68 CMD_READ_STATUS_REGISTER,
69 CMD_READ_STATUS_REGISTER_1,
70 CMD_READ_STATUS_REGISTER_2,
71 CMD_READ_STATUS_REGISTER_3,
72 CMD_WRITE_STATUS_REGISTER,
73 CMD_READ_JEDEC_ID,
74 CMD_READ, //Read, SPI address, SPI data
75 CMD_FAST_READ, //Fast read, SPI mode, with pipeline delay
76 CMD_READ_1_1_4, //Fast read, SPI address, QSPI data
77 CMD_READ_1_4_4, //Fast read, QSPI address, QSPI data
78 CMD_RESET,
79 CMD_WRITE_ENABLE,
80 CMD_WRITE_DISABLE,
81 CMD_BLOCK_ERASE,
82 CMD_PAGE_PROGRAM,
83 CMD_QUAD_PAGE_PROGRAM,
84 CMD_READ_SFDP, //read serial flash discovery parameters
85 CMD_ADDR_32BIT,
86 CMD_ADDR_24BIT,
87 CMD_RELEASE_PD,
88 CMD_ENABLE_RESET,
89
90 //Winbond W25N specific
91 CMD_W25N_READ_PAGE,
92 CMD_W25N_PROGRAM_EXECUTE,
93
94 CMD_UNKNOWN
95 } m_cmd;
96
97 uint32_t m_data;
98
100 {}
101
102 SPIFlashSymbol(FlashType type, FlashCommand cmd, uint32_t data)
103 : m_type(type)
104 , m_cmd(cmd)
105 , m_data(data)
106 {}
107
108 bool operator== (const SPIFlashSymbol& s) const
109 {
110 return (m_type == s.m_type) && (m_cmd == s.m_cmd) && (m_data == s.m_data);
111 }
112};
113
114class SPIFlashWaveform : public SparseWaveform<SPIFlashSymbol>
115{
116public:
118 virtual std::string GetText(size_t) override;
119 virtual std::string GetColor(size_t) override;
120};
121
123{
124public:
125 SPIFlashDecoder(const std::string& color);
126 virtual ~SPIFlashDecoder();
127
128 virtual void Refresh() override;
129
130 std::vector<std::string> GetHeaders() override;
131
132 static std::string GetProtocolName();
133
134 virtual bool ValidateChannel(size_t i, StreamDescriptor stream) override;
135
136 enum VendorIDs
137 {
138 VENDOR_ID_CYPRESS = 0x01,
139 VENDOR_ID_MICRON = 0x20,
140 VENDOR_ID_WINBOND = 0xef
141 };
142
143 enum FlashType
144 {
145 FLASH_TYPE_GENERIC_3BYTE_ADDRESS,
146 FLASH_TYPE_GENERIC_4BYTE_ADDRESS,
147 FLASH_TYPE_WINBOND_W25N
148 };
149
150 virtual bool CanMerge(Packet* first, Packet* cur, Packet* next) override;
151 virtual Packet* CreateMergedHeader(Packet* pack, size_t i) override;
152
153 PROTOCOL_DECODER_INITPROC(SPIFlashDecoder)
154
155
156 static std::string GetPartID(SPIFlashWaveform* cap, const SPIFlashSymbol& s, int i);
157
158protected:
159 std::string m_typename;
160 std::string m_outfile;
161
162 std::string m_cachedfname;
163 FILE* m_fpOut;
164};
165
166#endif
Definition: PacketDecoder.h:85
Definition: PacketDecoder.h:40
Definition: SPIFlashDecoder.h:123
virtual Packet * CreateMergedHeader(Packet *pack, size_t i) override
Creates a summary packet for one or more merged packets.
Definition: SPIFlashDecoder.cpp:1311
virtual bool CanMerge(Packet *first, Packet *cur, Packet *next) override
Checks if multiple packets can be merged under a single heading in the protocol analyzer view.
Definition: SPIFlashDecoder.cpp:1302
virtual void Refresh() override
Evaluates a filter graph node.
Definition: SPIFlashDecoder.cpp:110
Definition: SPIFlashDecoder.h:41
Definition: SPIFlashDecoder.h:115
virtual std::string GetColor(size_t) override
Returns the displayed color (in HTML #rrggbb or #rrggbbaa notation) of a given protocol sample.
Definition: SPIFlashDecoder.cpp:1011
virtual std::string GetText(size_t) override
Returns the text representation of a given protocol sample.
Definition: SPIFlashDecoder.cpp:1041
A waveform sampled at irregular intervals.
Definition: Waveform.h:460
Descriptor for a single stream coming off a channel.
Definition: StreamDescriptor.h:46