Custom protocol implementation - advice

Hello,

I would like to design a custom protocol analyzer for the debug port of a MPC56 MCU. The port uses serial communication, which is easily interpreted via the SPI protocol, however it can use 35 bits or 9 bits messages. That means I need to have a way of having the analyzer accepting both messages.

Could you point me to the method of designing the analyzer? I suspect that a HLA will not do the job, as it uses the underlying SPI protocol analyzer, which cannot, at least to my knowledge, make a distinction between frames of different size.

Thanks

Hi,
you could build your own C++ analyzer with the Analyzer SDK. The built in SPI analyzer can be taken as a starting point. See here for more info Analyzer SDK & Analyzer Code.
If you have frame sizes of 9 and 35 bits you need to check if after the 9th bit it would take too long until you reach the next transition if you haven’t got any other indicator that the frame is not finished yet. These two functions would be useful for this:
U64 GetSampleOfNextEdge();
bool WouldAdvancingCauseTransition( U32 num_samples );

2 Likes

Thank you for the reply. I’ve downloaded the SPI analyzer and I’m now trying to figure out how to insert the logic I need in the code.

I think I should look into the function void SpiAnalyzer::GetWord(), especially in the loop part:

for( U32 i=0; i<bits_per_transfer; i++ )
....
if (WouldAdvancingCauseTransition() == false && i == 8) 
{
      // We have a 9-bit data transaction, save and exit
     break;
}

Can you tell me if I’m on the right path here? I was not able to find the documentation of the functions you referenced, so I’m doing a bit of guesswork.

EDIT: I managed to have the custom low-level protocol analyzer output correct data for different sized transactions by checking the state of the DSDO line (corresponding to SPI’s MISO) in the SpiAnalyzer::GetWord() loop. However, I’ve noticed that I can’t have a custom High Level Analyzer used with my low level analyzer. Can you please confirm if that’s really the case? I’d like to build a HLA on top of the C++ analyzer.

Also, could you point me how to measure the time between two clock edges?

Thanks

@b.kereziev Glad to hear you’re making progress! Unfortunately, HLAs are only supported on a specific set of prebuilt analyzers. The officially supported list is below:
https://support.saleae.com/extensions/analyzer-frame-types

One thing to note is that, SPI is in fact on the supported list, though I don’t know off the top of my head if a variation of the SPI Analyzer could be supported. In the meantime, I’ll have to review this with the team here and get back to you (in addition to your question about checking the time between clock edges).

@b.kereziev,

We don’t officially support connecting a custom C++ LLA to HLAs yet, although we do want to support that in the future. It is possible to do this today with an undocumented API, but we will break that API in the future, so your custom LLA would stop working completely when that happens and would require code changes to fix. If you want to try that despite the warning, let us know and we can send you an example.

However, I have a simpler suggestion. I had a similar problem when writing a HLA for USB PD, which contains some 8 bit words and some 10 bit words.

A simple solution that would not require modifying the SPI analyzer is to simply modify it to use a word size of 1 bit per word. Then in your HLA, you can just group those bits together however you like. This would let you do the whole project in python, and you wouldn’t need to worry about the API breaking later.

Here is a simple HLA example which combines groups of input frames into a single output frame:

You could model your HLA off of that approach. Let us know if you have any questions about it, or need any help!

Mark

Hi again,
sorry for the late reply. I assume you found the API documentation on the Analyzer SDK website in the meantime.

It’s a pity that one cannot use HLA Analyzers on your own Low Level Analyzer at the moment but you might be still able to implement everything you need directly in your Low Level Analyzer in C++.

The Analyzer base class has a member function called GetSampleRate(), you can use this to calculate the time between two samples. Watch out that you can only move forward in time within your analyzer. You cannot go backwards again. This can be a bit tricky sometimes.

For example (untested code):
mClock->AdvanceToNextEdge();
U64 edgeA = mClock->GetSampleNumber();
U64 edgeB = mClock->GetSampleOfNextEdge();
double bitRate = double(GetSampleRate()) / (2.0 * double(edgeB - edgeA));

If you sum up multiple clock ticks you get a better result. The 1/2 factor is due to the fact that your bitrate is equivalent to the full clock frequency but in this example only half the clock period is measured (e.g. only low phase).

1 Like