ngscopeclient v0.1
SPIFlashDecoder.h
Go to the documentation of this file.
1/***********************************************************************************************************************
2* *
3* libscopeprotocols *
4* *
5* Copyright (c) 2012-2025 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_MODE_RESET,
80 CMD_WRITE_ENABLE,
81 CMD_WRITE_DISABLE,
82 CMD_BLOCK_ERASE,
83 CMD_PAGE_PROGRAM,
84 CMD_QUAD_PAGE_PROGRAM,
85 CMD_READ_SFDP, //read serial flash discovery parameters
86 CMD_ADDR_32BIT,
87 CMD_ADDR_24BIT,
88 CMD_RELEASE_PD,
89 CMD_ENABLE_RESET,
90
91 //Winbond W25N specific
92 CMD_W25N_READ_PAGE,
93 CMD_W25N_PROGRAM_EXECUTE,
94
95 CMD_UNKNOWN
96 } m_cmd;
97
98 uint32_t m_data;
99
101 {}
102
103 SPIFlashSymbol(FlashType type, FlashCommand cmd, uint32_t data)
104 : m_type(type)
105 , m_cmd(cmd)
106 , m_data(data)
107 {}
108
109 bool operator== (const SPIFlashSymbol& s) const
110 {
111 return (m_type == s.m_type) && (m_cmd == s.m_cmd) && (m_data == s.m_data);
112 }
113};
114
115class SPIFlashWaveform : public SparseWaveform<SPIFlashSymbol>
116{
117public:
119 virtual std::string GetText(size_t) override;
120 virtual std::string GetColor(size_t) override;
121};
122
124{
125public:
126 SPIFlashDecoder(const std::string& color);
127 virtual ~SPIFlashDecoder();
128
129 virtual void Refresh() override;
130
131 std::vector<std::string> GetHeaders() override;
132
133 static std::string GetProtocolName();
134
135 virtual bool ValidateChannel(size_t i, StreamDescriptor stream) override;
136
137 enum VendorIDs
138 {
139 VENDOR_ID_CYPRESS = 0x01,
140 VENDOR_ID_MICRON = 0x20,
141 VENDOR_ID_WINBOND = 0xef
142 };
143
144 enum FlashType
145 {
146 FLASH_TYPE_GENERIC_3BYTE_ADDRESS,
147 FLASH_TYPE_GENERIC_4BYTE_ADDRESS,
148 FLASH_TYPE_WINBOND_W25N
149 };
150
151 virtual bool CanMerge(Packet* first, Packet* cur, Packet* next) override;
152 virtual Packet* CreateMergedHeader(Packet* pack, size_t i) override;
153
154 PROTOCOL_DECODER_INITPROC(SPIFlashDecoder)
155
156
157 static std::string GetPartID(SPIFlashWaveform* cap, const SPIFlashSymbol& s, int i);
158
159protected:
160 std::string m_typename;
161 std::string m_outfile;
162
163 std::string m_cachedfname;
164 FILE* m_fpOut;
165};
166
167#endif
Definition: PacketDecoder.h:85
Definition: PacketDecoder.h:40
Definition: SPIFlashDecoder.h:124
virtual Packet * CreateMergedHeader(Packet *pack, size_t i) override
Creates a summary packet for one or more merged packets.
Definition: SPIFlashDecoder.cpp:1343
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:1332
virtual void Refresh() override
Evaluates a filter graph node.
Definition: SPIFlashDecoder.cpp:110
Definition: SPIFlashDecoder.h:41
Definition: SPIFlashDecoder.h:116
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:1033
virtual std::string GetText(size_t) override
Returns the text representation of a given protocol sample.
Definition: SPIFlashDecoder.cpp:1063
A waveform sampled at irregular intervals.
Definition: Waveform.h:481
Descriptor for a single stream coming off a channel.
Definition: StreamDescriptor.h:46