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

SPI Programming Examples
SPI Programming Manual427506-006
E-60
Example E-12: A Simple SPI Server in C
case 1 : /* string to reverse. */
l_len = in_string.len;
for (l_idx = l_start_idx; l_idx < l_len; l_idx++)
{
out_string.data [l_len - l_idx - 1] = in_string.data [l_idx];
}
out_string.len = in_string.len;
if (err = SSPUTTKN (res_buffer, ZSPI_TKN_COMMENT,
(char *) &out_string))
display_spi_error (err, ZSPI_VAL_SSPUTTKN,
ZSPI_TKN_COMMENT, true);
break;
case 2 : /* Shift string to uppercase */
/*
* This could be done in one operation, but to show the use of
* the CONTEXT token, it will be done one character at a time.
*/
l_len = in_string.len;
out_string.data [l_start_idx] = in_string.data [l_start_idx];
SHIFTSTRING (&out_string.data [l_start_idx],
1 /* only one byte at a time */,
0 /*upshift*/); /* Change to upper-case */
l_start_idx = l_start_idx + 1;
out_string.len = l_start_idx;
if (out_string.len < in_string.len)
{
/* update the context and add it to the returned buffer.
*/
the_context.command = spi_command;
the_context.index = l_start_idx;
the_context.con_string.len = out_string.len;
memcpy (the_context.con_string.data, out_string.data,
out_string.len);
the_context.len = offsetof (context_template, con_string) +
out_string.len + 2;
if (err = SSPUTTKN (res_buffer, ZSPI_TKN_CONTEXT,
(char *) &the_context))
display_spi_error (err, ZSPI_VAL_SSPUTTKN,
ZSPI_TKN_CONTEXT, true);
}
Example E-12. C File: A Simple SPI Server (page 6 of 12)