SPI Programming Manual (G06.24+, H06.03+, J06.03+)

SPI Programming Examples
SPI Programming Manual427506-006
E-43
Example E-10: A Simple SPI Requester in C
write_read_server ();
if (display_spi_buffer)
{
printf ("SPI buffer received:\n");
dump_buf (req_buffer);
}
/* Reset the buffer */
buflen = max_bufsize;
if (err = SSPUTTKN (req_buffer, ZSPI_TKN_RESET_BUFFER,
(char *) &buflen))
{
display_spi_error (err, ZSPI_VAL_SSPUTTKN,
ZSPI_TKN_RESET_BUFFER, false);
printf ("Bad SPI buffer returned! Cannot reset the buffer.\n");
}
if (! err)
{
tkn_retcode = 0;
if (err = SSGETTKN (req_buffer, ZSPI_TKN_RETCODE,
(char *) &tkn_retcode, 1))
{
display_spi_error (err, ZSPI_VAL_SSGETTKN,
ZSPI_TKN_RETCODE, false);
printf ("Bad SPI buffer returned! Missing RETCODE.\n");
} else
{
err = tkn_retcode; /* To simplify the error checking code. */
if (tkn_retcode)
{
printf ("Error returned. RETCODE = (%d)\n", tkn_retcode);
}
}
}
if (! err)
{
/* retrieve and validate the context, if any */
if ((err = SSGETTKN (req_buffer, ZSPI_TKN_CONTEXT,
(char *) &the_context, 1) == ZSPI_ERR_OK))
{ /* This message has a context. Add it to the original message
* and send it again.
*
* This is what is happening. "sav_buffer" has the original msg sent.
* I will move the "context" token from the "req_buffer" to the
* "sav_buffer". Then, I will move "sav_buffer" to "req_buffer".
* Now "req_buffer" is ready to send, but "sav_buffer" has the
* "context" token added to the original msg sent. Thus, I will
* delete the "context" token from "sav_buffer".
*/
source_idx = 1;
dest_idx = 1;
tkn_count = 1;
SSMOVETKN (ZSPI_TKN_CONTEXT, req_buffer, source_idx,
sav_buffer, dest_idx, &tkn_count);
Example E-10. C File: A Simple SPI Requester (page 7 of 8)