|
@@ -2,8 +2,8 @@
|
|
// // /\ /| @File spi_decoder.cc
|
|
// // /\ /| @File spi_decoder.cc
|
|
// // \ V/ @Brief
|
|
// // \ V/ @Brief
|
|
// // | "") @Author lijinwen, ghz005@uni-trend.com.cn
|
|
// // | "") @Author lijinwen, ghz005@uni-trend.com.cn
|
|
-// // / | @Creation 2024-07-16
|
|
|
|
-// // / \\ @Modified 2024-07-16
|
|
|
|
|
|
+// // / | @Creation 2024-07-19
|
|
|
|
+// // / \\ @Modified 2024-07-23
|
|
// // *(__\_\
|
|
// // *(__\_\
|
|
// // ******************************************************************
|
|
// // ******************************************************************
|
|
|
|
|
|
@@ -21,6 +21,9 @@ namespace Protocol
|
|
{
|
|
{
|
|
is_cancel_ptr_ = options.is_cancel;
|
|
is_cancel_ptr_ = options.is_cancel;
|
|
decode_result = {};
|
|
decode_result = {};
|
|
|
|
+ decode_result.decoder_ptr = reinterpret_cast<intptr_t>(this);
|
|
|
|
+ need_decode_data_ = true;
|
|
|
|
+
|
|
bool checked_params = true;
|
|
bool checked_params = true;
|
|
if (edge_pulse_data_clk.waveform_data_count <= 0
|
|
if (edge_pulse_data_clk.waveform_data_count <= 0
|
|
|| edge_pulse_data_cs.waveform_data_count <= 0
|
|
|| edge_pulse_data_cs.waveform_data_count <= 0
|
|
@@ -45,6 +48,9 @@ namespace Protocol
|
|
{
|
|
{
|
|
need_decode_data_ = false;
|
|
need_decode_data_ = false;
|
|
need_update_view_info_ = true;
|
|
need_update_view_info_ = true;
|
|
|
|
+ /*miso_data.clear();
|
|
|
|
+ mosi_data.clear();*/
|
|
|
|
+ data_packet_info.clear();
|
|
packet_infos_.clear();
|
|
packet_infos_.clear();
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
@@ -52,12 +58,16 @@ namespace Protocol
|
|
{
|
|
{
|
|
if (need_decode_data_)
|
|
if (need_decode_data_)
|
|
{
|
|
{
|
|
|
|
+ /* miso_data.clear();
|
|
|
|
+ mosi_data.clear();*/
|
|
|
|
+ data_packet_info.clear();
|
|
|
|
+ packet_infos_.clear();
|
|
need_decode_data_ = false;
|
|
need_decode_data_ = false;
|
|
need_update_view_info_ = true;
|
|
need_update_view_info_ = true;
|
|
- packet_infos_.clear();
|
|
|
|
|
|
+
|
|
try
|
|
try
|
|
{
|
|
{
|
|
- int32_t packet_index = 0;
|
|
|
|
|
|
+ int32_t packet_index = 0, last_packet_index = 0;
|
|
uint64_t cs_len = edge_pulse_data_cs.waveform_data_count;
|
|
uint64_t cs_len = edge_pulse_data_cs.waveform_data_count;
|
|
uint64_t clk_len = edge_pulse_data_clk.waveform_data_count;
|
|
uint64_t clk_len = edge_pulse_data_clk.waveform_data_count;
|
|
uint64_t miso_len = 0;
|
|
uint64_t miso_len = 0;
|
|
@@ -101,16 +111,16 @@ namespace Protocol
|
|
options.cs_polarity, options.clk_polarity))
|
|
options.cs_polarity, options.clk_polarity))
|
|
{
|
|
{
|
|
WriteLog(LogLevel::Level2, "Not find start node");
|
|
WriteLog(LogLevel::Level2, "Not find start node");
|
|
- return false;
|
|
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
|
|
|
|
- if (packet_index < 0 || *is_cancel_ptr_) break;
|
|
|
|
|
|
+ if (packet_index < 0) break;
|
|
|
|
|
|
SpiPacket packet_info = {};
|
|
SpiPacket packet_info = {};
|
|
- packet_info.data = std::vector<DataPacketInfo>();
|
|
|
|
|
|
+
|
|
packet_info.start_index = cs_start_index;
|
|
packet_info.start_index = cs_start_index;
|
|
packet_info.start_len = 1;
|
|
packet_info.start_len = 1;
|
|
- packet_info.has_start = cs_start_index >= 0;
|
|
|
|
|
|
+ packet_info.has_start = cs_start_index >= 0 ? 1 : 0;
|
|
|
|
|
|
if (!GetCsBitNextIndex(options.cs_polarity == Polarity::POS,
|
|
if (!GetCsBitNextIndex(options.cs_polarity == Polarity::POS,
|
|
packet_index, edge_pulse_data_cs_ptr))
|
|
packet_index, edge_pulse_data_cs_ptr))
|
|
@@ -118,24 +128,31 @@ namespace Protocol
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
const auto cs_end_index = edge_pulse_data_cs_ptr->start_index;
|
|
const auto cs_end_index = edge_pulse_data_cs_ptr->start_index;
|
|
- if (bool need_clear = false; *is_cancel_ptr_ || need_clear) break;
|
|
|
|
|
|
+ if (is_cancel_ptr_ != nullptr && *is_cancel_ptr_)
|
|
|
|
+ {
|
|
|
|
+ WriteLog(LogLevel::Level2, "AsyncFunction canceled");
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ if (bool need_clear = false; need_clear) break;
|
|
|
|
|
|
if (cs_end_index > packet_index)
|
|
if (cs_end_index > packet_index)
|
|
{
|
|
{
|
|
- packet_info.has_end = true;
|
|
|
|
|
|
+ packet_info.has_end = 1;
|
|
packet_info.end_len = 1;
|
|
packet_info.end_len = 1;
|
|
packet_info.end_index = cs_end_index;
|
|
packet_info.end_index = cs_end_index;
|
|
}
|
|
}
|
|
|
|
|
|
std::vector<DataPacketInfo> temp_data_packets;
|
|
std::vector<DataPacketInfo> temp_data_packets;
|
|
|
|
+
|
|
//数据解码
|
|
//数据解码
|
|
while (true)
|
|
while (true)
|
|
{
|
|
{
|
|
DataPacketInfo temp_data_packet = {};
|
|
DataPacketInfo temp_data_packet = {};
|
|
|
|
+ //std::vector<uint8_t> temp_miso_datas = {}, temp_mosi_datas = {};
|
|
temp_data_packet.bit_count = frame_count_;
|
|
temp_data_packet.bit_count = frame_count_;
|
|
temp_data_packet.index = packet_index;
|
|
temp_data_packet.index = packet_index;
|
|
int32_t temp_miso_data = 0, temp_mosi_data = 0;
|
|
int32_t temp_miso_data = 0, temp_mosi_data = 0;
|
|
-
|
|
|
|
|
|
+ bool get_miso_data = false, get_mosi_data = false;
|
|
for (int32_t bit_index = 0; bit_index < frame_count_; ++bit_index)
|
|
for (int32_t bit_index = 0; bit_index < frame_count_; ++bit_index)
|
|
{
|
|
{
|
|
bool miso_bit = false;
|
|
bool miso_bit = false;
|
|
@@ -144,6 +161,7 @@ namespace Protocol
|
|
{
|
|
{
|
|
if (!CommonHelper::GetNodeByIndex(packet_index, edge_pulse_data_miso_ptr))
|
|
if (!CommonHelper::GetNodeByIndex(packet_index, edge_pulse_data_miso_ptr))
|
|
{
|
|
{
|
|
|
|
+ get_miso_data = false;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
miso_bit = edge_pulse_data_miso_ptr->current_level == TwoLevelEdgePulseStatusType::High;
|
|
miso_bit = edge_pulse_data_miso_ptr->current_level == TwoLevelEdgePulseStatusType::High;
|
|
@@ -151,12 +169,14 @@ namespace Protocol
|
|
{
|
|
{
|
|
miso_bit = !miso_bit;
|
|
miso_bit = !miso_bit;
|
|
}
|
|
}
|
|
|
|
+ get_miso_data = true;
|
|
}
|
|
}
|
|
|
|
|
|
if (decode_mosi)
|
|
if (decode_mosi)
|
|
{
|
|
{
|
|
if (!CommonHelper::GetNodeByIndex(packet_index, edge_pulse_data_mosi_ptr))
|
|
if (!CommonHelper::GetNodeByIndex(packet_index, edge_pulse_data_mosi_ptr))
|
|
{
|
|
{
|
|
|
|
+ get_miso_data = false;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
mosi_bit = edge_pulse_data_mosi_ptr->current_level == TwoLevelEdgePulseStatusType::High;
|
|
mosi_bit = edge_pulse_data_mosi_ptr->current_level == TwoLevelEdgePulseStatusType::High;
|
|
@@ -164,6 +184,7 @@ namespace Protocol
|
|
{
|
|
{
|
|
mosi_bit = !mosi_bit;
|
|
mosi_bit = !mosi_bit;
|
|
}
|
|
}
|
|
|
|
+ get_mosi_data = true;
|
|
}
|
|
}
|
|
|
|
|
|
if (options.msb_lsb == SpiEnums::Msblsb::MSB)
|
|
if (options.msb_lsb == SpiEnums::Msblsb::MSB)
|
|
@@ -179,8 +200,7 @@ namespace Protocol
|
|
temp_mosi_data |= (mosi_bit ? 1 : 0) << bit_index;
|
|
temp_mosi_data |= (mosi_bit ? 1 : 0) << bit_index;
|
|
}
|
|
}
|
|
|
|
|
|
- temp_data_packet.miso_data.push_back(static_cast<uint8_t>(temp_miso_data));
|
|
|
|
- temp_data_packet.mosi_data.push_back(static_cast<uint8_t>(temp_mosi_data));
|
|
|
|
|
|
+
|
|
temp_data_packet.real_bit_count = bit_index + 1;
|
|
temp_data_packet.real_bit_count = bit_index + 1;
|
|
|
|
|
|
if (!GetClkEdge(!clk_state, packet_index, edge_pulse_data_clk_ptr))
|
|
if (!GetClkEdge(!clk_state, packet_index, edge_pulse_data_clk_ptr))
|
|
@@ -189,7 +209,7 @@ namespace Protocol
|
|
}
|
|
}
|
|
if ((packet_index > cs_end_index && cs_end_index >= 0) || packet_index == -1)
|
|
if ((packet_index > cs_end_index && cs_end_index >= 0) || packet_index == -1)
|
|
{
|
|
{
|
|
- temp_data_packet.is_last = true;
|
|
|
|
|
|
+ temp_data_packet.is_last = 1;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -214,14 +234,71 @@ namespace Protocol
|
|
{
|
|
{
|
|
temp_data_packet.len = packet_index - temp_data_packet.index;
|
|
temp_data_packet.len = packet_index - temp_data_packet.index;
|
|
}
|
|
}
|
|
- if (temp_data_packet.real_bit_count > 0) temp_data_packets.push_back(temp_data_packet);
|
|
|
|
- if (temp_data_packet.is_last) break;
|
|
|
|
|
|
+ //if (temp_data_packet.real_bit_count > 0) temp_data_packets.push_back(temp_data_packet);
|
|
|
|
+
|
|
|
|
+ //end
|
|
|
|
+ if (temp_data_packet.real_bit_count > 0)
|
|
|
|
+ {
|
|
|
|
+ //miso
|
|
|
|
+ if (decode_miso)
|
|
|
|
+ {
|
|
|
|
+ temp_data_packet.miso_data_count = get_miso_data ? 1 : 0;
|
|
|
|
+ if (temp_data_packet.miso_data_count > 0)
|
|
|
|
+ {
|
|
|
|
+ /* int32_t last_data_count = miso_data.size();
|
|
|
|
+
|
|
|
|
+ miso_data.push_back(temp_miso_data);
|
|
|
|
+ temp_data_packet.miso_data_ptr = miso_data.data() + last_data_count; */
|
|
|
|
+ temp_data_packet.miso_data = static_cast<uint8_t>(temp_miso_data);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //mosi
|
|
|
|
+ if (decode_mosi)
|
|
|
|
+ {
|
|
|
|
+ temp_data_packet.mosi_data_count = get_mosi_data ? 1 : 0;
|
|
|
|
+ if (temp_data_packet.mosi_data_count > 0)
|
|
|
|
+ {
|
|
|
|
+ /*int32_t last_data_count = mosi_data.size();
|
|
|
|
+
|
|
|
|
+ mosi_data.push_back(temp_mosi_data);
|
|
|
|
+ temp_data_packet.mosi_data_ptr = mosi_data.data() + last_data_count;*/
|
|
|
|
+ temp_data_packet.mosi_data = static_cast<uint8_t>(temp_mosi_data);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ temp_data_packets.push_back(temp_data_packet);
|
|
|
|
+ }
|
|
|
|
+ if (temp_data_packet.is_last == 1 || packet_index >= data_len_) break;
|
|
|
|
+ if (last_packet_index == packet_index)
|
|
|
|
+ {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ last_packet_index = packet_index;
|
|
}
|
|
}
|
|
|
|
|
|
- packet_info.data = temp_data_packets;
|
|
|
|
- packet_infos_.push_back(packet_info);
|
|
|
|
|
|
+ //packet
|
|
|
|
+ packet_info.data_count = static_cast<int32_t>(temp_data_packets.size());
|
|
|
|
+ if (packet_info.data_count > 0)
|
|
|
|
+ {
|
|
|
|
+ int32_t last_data_count = static_cast<int32_t>(data_packet_info.size());
|
|
|
|
+ // 复制到末尾
|
|
|
|
+ data_packet_info.insert(data_packet_info.end(),
|
|
|
|
+ std::make_move_iterator(temp_data_packets.begin()),
|
|
|
|
+ std::make_move_iterator(temp_data_packets.end()));
|
|
|
|
+ packet_info.data_ptr = reinterpret_cast<intptr_t>(data_packet_info.data() + last_data_count - 1);
|
|
|
|
+ packet_info.data_info = temp_data_packets[0];
|
|
|
|
+ }
|
|
|
|
|
|
- if (packet_index >= static_cast<int32_t>(miso_len) || packet_index < 0)
|
|
|
|
|
|
+ packet_infos_.push_back(packet_info);
|
|
|
|
+ if (decode_miso && packet_index >= static_cast<int32_t>(miso_len))
|
|
|
|
+ {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ if (decode_mosi && packet_index >= static_cast<int32_t>(mosi_len))
|
|
|
|
+ {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ if (packet_index < 0)
|
|
{
|
|
{
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
@@ -249,9 +326,10 @@ namespace Protocol
|
|
decode_result.decode_event_count = packet_infos_.size();
|
|
decode_result.decode_event_count = packet_infos_.size();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
- bool SpiDecoder::GetClkEdge(const bool state, int32_t& start_index, TwoLevelEdgePulse* node_clk)
|
|
|
|
|
|
+ bool SpiDecoder::GetClkEdge(const bool state, int32_t& start_index, TwoLevelEdgePulse*& node_clk)
|
|
{
|
|
{
|
|
if (!CommonHelper::GetNodeByIndex(start_index, node_clk))
|
|
if (!CommonHelper::GetNodeByIndex(start_index, node_clk))
|
|
{
|
|
{
|
|
@@ -279,8 +357,8 @@ namespace Protocol
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
- bool SpiDecoder::FindStartNode(int32_t& start_index, int32_t& cs_start_index, TwoLevelEdgePulse* node_cs,
|
|
|
|
- TwoLevelEdgePulse* node_clk,
|
|
|
|
|
|
+ bool SpiDecoder::FindStartNode(int32_t& start_index, int32_t& cs_start_index, TwoLevelEdgePulse*& node_cs,
|
|
|
|
+ TwoLevelEdgePulse*& node_clk,
|
|
const Polarity polarity_cs, const Polarity polarity_clk) const
|
|
const Polarity polarity_cs, const Polarity polarity_clk) const
|
|
{
|
|
{
|
|
cs_start_index = -1;
|
|
cs_start_index = -1;
|
|
@@ -353,31 +431,28 @@ namespace Protocol
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- bool SpiDecoder::GetCsBitNextIndex(const bool state, int32_t& start_index, TwoLevelEdgePulse* node_cs)
|
|
|
|
|
|
+ bool SpiDecoder::GetCsBitNextIndex(const bool state, int32_t start_index, TwoLevelEdgePulse*& node_cs)
|
|
{
|
|
{
|
|
if (!CommonHelper::GetNodeByIndex(start_index, node_cs))
|
|
if (!CommonHelper::GetNodeByIndex(start_index, node_cs))
|
|
{
|
|
{
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
+
|
|
if (node_cs->current_level == TwoLevelEdgePulseStatusType::High != state)
|
|
if (node_cs->current_level == TwoLevelEdgePulseStatusType::High != state)
|
|
{
|
|
{
|
|
- if (node_cs->current_level == TwoLevelEdgePulseStatusType::High != state)
|
|
|
|
- {
|
|
|
|
- if (!CommonHelper::FindNextNode(start_index, node_cs))
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- start_index = node_cs->start_index;
|
|
|
|
- }
|
|
|
|
- if (start_index == -1) return false;
|
|
|
|
-
|
|
|
|
if (!CommonHelper::FindNextNode(start_index, node_cs))
|
|
if (!CommonHelper::FindNextNode(start_index, node_cs))
|
|
{
|
|
{
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
start_index = node_cs->start_index;
|
|
start_index = node_cs->start_index;
|
|
- return true;
|
|
|
|
}
|
|
}
|
|
- return false;
|
|
|
|
|
|
+ if (start_index == -1) return false;
|
|
|
|
+
|
|
|
|
+ if (!CommonHelper::FindNextNode(start_index, node_cs))
|
|
|
|
+ {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ //start_index = node_cs->start_index;
|
|
|
|
+ return true;
|
|
}
|
|
}
|
|
}
|
|
}
|