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

SPI Programming Examples
SPI Programming Manual427506-006
E-64
Example E-12: A Simple SPI Server in C
/* walk through the buffer pulling out tokens */
while (err = SSGETTKN (req_buffer, ZSPI_TKN_NEXTCODE,
(char *) &tkn_code,, &tkn_count) == ZSPI_ERR_OK)
{
switch (tkn_code)
{
case ZSPI_TKN_COMMENT :
/* Check the entire token code, just to be sure. */
if (tkn_code != ZSPI_TKN_COMMENT)
return (ZCOM_ERR_TKN_CODE_INV);
if (err = SSGETTKN (req_buffer, ZSPI_TKN_COMMENT,
(char *) &in_string))
display_spi_error (err, ZSPI_VAL_SSGETTKN,
ZSPI_TKN_COMMENT, true);
break;
case ZSPI_TKN_CONTEXT :
/* Check the entire token code, just to be sure. */
if (tkn_code != ZSPI_TKN_CONTEXT)
return (ZCOM_ERR_TKN_CODE_INV);
tkn_code = ZSPI_TKN_CONTEXT;
context_count = context_count + tkn_count;
if (context_count != 1)
{
return (ZCOM_ERR_TKN_DUP);
} else
{
/* retrieve and validate the context */
if (err = SSGETTKN (req_buffer, ZSPI_TKN_CONTEXT,
(char *) &the_context))
display_spi_error (err, ZSPI_VAL_SSGETTKN,
ZSPI_TKN_CONTEXT, true);
if ((the_context.len > sizeof(context_template)) ||
(the_context.len != (offsetof (context_template, con_string) +
the_context.con_string.len + 2)) ||
(the_context.command != spi_command) ||
(the_context.index > the_context.con_string.len))
{
return (ZCOM_ERR_TKN_CNTXT_CODE_INV);
}
}
break;
default :
return (ZCOM_ERR_TKN_CODE_INV);
break;
} /* of switch */
} /* of while */
return (ZSPI_ERR_OK); /* no errors found, return ok */
} /* validate_tokens */
Example E-12. C File: A Simple SPI Server (page 10 of 12)