SPI protocol confusing variable name

Thread Starter

Alexa19

Joined Jun 16, 2023
9
Hi!

I have been struggling a lot to understand the SPI protocol.
It is used in an embedded project and the previous developers have no documentation on the code, so I have to struggle to find out what is happening.

In a c file named spi_protocol.c, we have the code for the SPI functionality.

The problem arose when I got over the name "srts" and I have no clue to what it can be related.

The code looks something like this:

C:
extern xSemaphoreHandle SPI_SRTS_DOWN;
extern xSemaphoreHandle SPI_SRTS_TOGGLE;

static inline uint8_t spi_srts_down(uint32_t delayTime) {
    uint16_t srts_status = RZA_IO_RegRead_16(&g_usbx_function_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE);
    if(1 == srts_status){
        if(pdFALSE == xSemaphoreTake(SPI_SRTS_DOWN, delayTime)) {
            return pdFALSE;
        } else {
            return xSemaphoreTake(SPI_SRTS_TOGGLE, delayTime);
        }
    } else {
        xSemaphoreTake(SPI_SRTS_DOWN, 0);
        xSemaphoreTake(SPI_SRTS_TOGGLE, 0);
        return pdTRUE;
    }
}
My question is what could srts mean:

status register
slave request to send
or something about reading the data?


Thank you so much for your time!
 

Poyntat

Joined May 24, 2022
60
Could it be the status of a hardware handshake line such as the RTS ( request to send ) sometimes found in asynchronous USART comms as It appears to originate from an IO register read.
 

camerart

Joined Feb 25, 2013
3,643
HI A,
I only 'speak' BASIC, I'm afraid.
In my latest CODEs I have to use a different method to how I'm used to, and I find it difficult.
I think to the average CODER SPI is pretty easy.
In my type of CODE, it looks like this: (Note this isn't proper CODE, but a kind of example as a guide)
-------------------------------------
SSPBUF = READ_ADDRESS [The address that is being READ ]
While Not SSPSTAT.BF 'PIC [ Wait for the BIT that shows the BUFFER is full ]
Wend
SSPBUF = 0 'Dummy BYTE (Send a dummy BYTE so the SLAVE witl return the BYTE being READ }
While Not SSPSTAT.BF 'PIC [ Check their is a BYTE to READ }
Wend
READ = SSPBUF [ READ the revived BYTE ]
----------------------------------
I'm not the best at CODING, but I hope it helps a little.
C
 

MrChips

Joined Oct 2, 2009
30,465
SPI_SRTS_DOWN and SPI_SRTS_TOGGLE are names given to xSemaphoreHandles by the programmer.
These were defined and created in another file. Search other files to find how they were created. (This is FreeRTOS.)
 

camerart

Joined Feb 25, 2013
3,643
SPI_SRTS_DOWN and SPI_SRTS_TOGGLE are names given to xSemaphoreHandles by the programmer.
These were defined and created in another file. Search other files to find how they were created. (This is FreeRTOS.)
Hi Mr C,
I looked up SPI_SRTS_DOWN and SPI_SRTS_TOGGLE in the Oshonsoft help file, but it isn't there, I presume this is in 'C' which I don't speak, but thanks.
C
 

MrChips

Joined Oct 2, 2009
30,465
Hi Mr C,
I looked up SPI_SRTS_DOWN and SPI_SRTS_TOGGLE in the Oshonsoft help file, but it isn't there, I presume this is in 'C' which I don't speak, but thanks.
C
This is neither BASIC nor C. This is a user defined name that can apply to any computer programming language.
 

Thread Starter

Alexa19

Joined Jun 16, 2023
9
Could it be the status of a hardware handshake line such as the RTS ( request to send ) sometimes found in asynchronous USART comms as It appears to originate from an IO register read.
Hello!
First of all, thank you very much for your answer and your time.
I really appreciate it.
I think it is the answer I was looking for. I will continue to try and figure out what is happening in the code.:p
 

Thread Starter

Alexa19

Joined Jun 16, 2023
9
HI A,
I only 'speak' BASIC, I'm afraid.
In my latest CODEs I have to use a different method to how I'm used to, and I find it difficult.
I think to the average CODER SPI is pretty easy.
In my type of CODE, it looks like this: (Note this isn't proper CODE, but a kind of example as a guide)
-------------------------------------
SSPBUF = READ_ADDRESS [The address that is being READ ]
While Not SSPSTAT.BF 'PIC [ Wait for the BIT that shows the BUFFER is full ]
Wend
SSPBUF = 0 'Dummy BYTE (Send a dummy BYTE so the SLAVE witl return the BYTE being READ }
While Not SSPSTAT.BF 'PIC [ Check their is a BYTE to READ }
Wend
READ = SSPBUF [ READ the revived BYTE ]
----------------------------------
I'm not the best at CODING, but I hope it helps a little.
C
EDIT: Just realised this isn't addressed to me really.
C

Hello!
Thank your for taking the time to answer. I have read your comment and it was like a refresh for the SPI theory. :)
 

Thread Starter

Alexa19

Joined Jun 16, 2023
9
SPI_SRTS_DOWN and SPI_SRTS_TOGGLE are names given to xSemaphoreHandles by the programmer.
These were defined and created in another file. Search other files to find how they were created. (This is FreeRTOS.)
Hello!
Yes, this is FreeRTOS.
They were created in another file this way:
C:
volatile uint8_t slave_spi_SRTS_previous_state = 0;
uint16_t srts_status = RZA_IO_RegRead_16(&g_usbx_function_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE);
        if ((0 == srts_status) && (1 == slave_spi_SRTS_previous_state)) {
            slave_spi_SRTS_previous_state = srts_status;
            xSemaphoreGiveFromISR(SPI_SRTS_DOWN, &flag);
            xSemaphoreGiveFromISR(SPI_SRTS_TOGGLE, &flag);
        }
      else if((1 == srts_status) && (0 == slave_spi_SRTS_previous_state)) {
            slave_spi_SRTS_previous_state = srts_status;
            xSemaphoreGiveFromISR(SPI_SRTS_UP, &flag);
        }
    }
But I am not sure I truly understand it. I have read the documentation for xSemaphoreGiveFromISR
 

MrChips

Joined Oct 2, 2009
30,465
SPI hardware protocol requires four signals:

SCLK
MOSI
MISO
/SS (or NSS)

Names in question are:

SPI_SRTS_UP
SPI_SRTS_DOWN
SPI_SRTS_TOGGLE

These are not system or library names. These are names created by the programmer.

I can only guess that these user names refer to handles pointing to SPI SCLK functions (or even any one of the four SPI data and control signals).
 

Thread Starter

Alexa19

Joined Jun 16, 2023
9
MrChips,
Thank you. Yes, they are names given by the programmer and I was struggling to find out the meaning as I am still new to this embedded world.
I think the answer I was looking for was given by Poyntat.
Sorry if my question was not too straight. :oops:
 

Thread Starter

Alexa19

Joined Jun 16, 2023
9
Then, what would srts stand for? I thought that maybe the programmer used it here as he thought it was necessary. I know that UART and SPI are not the same:).
 

MrChips

Joined Oct 2, 2009
30,465
Then, what would srts stand for? I thought that maybe the programmer used it here as he thought it was necessary. I know that UART and SPI are not the same.:)
You have to ask the programmer what SRTS means.
Or you can check what the code does. Eventually it has to link with hardware.
 

Thread Starter

Alexa19

Joined Jun 16, 2023
9
MrChips,
The programmer is not on the project anymore. I tried to ask a few other devs, but no one seemed to know.
Maybe in the end I will figure it out.
Thanks :)
 

Ian Rogers

Joined Dec 12, 2012
1,136
My 2 peneth..

Semaphore is a flag.. Used to be used on ships to relay information to other boats. RTS has always been "Ready To Send"

Semaphore Ready To Send set flag up, down or toggle condition.. t even has its own SRTS status byte..
 

WBahn

Joined Mar 31, 2012
29,854
One approach is to start at the hardware side of things and work backwards.

Look at the hardware schematic and identify which pins are used for the SPI interface and which SPI signal is connected to each of them.

Then look in the code to determine which variables are mapped to those hardware pins.

Then start finding those variables in the code and start pulling together all of the functions that interact with them.

When all is said and done, if nothing else, you will walk away with a much greater appreciation for the value of adequate documentation and why team leadership should demand that it be done and kept current as a project develops, not thrown together haphazardly at the end of a project when people are under pressure to move on to the next one.
 
Top