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

SPI Programming Examples
SPI Programming Manual427506-006
E-63
Example E-12: A Simple SPI Server in C
#pragma PAGE "validate_tokens"
/*
*=====================================================================
* Proc : validate_tokens =
* Function : This procedure will determine if the "req_buffer" =
* contains a valid SPI command. All required tokens =
* must be present. Duplicate tokens, invalid tokens, =
* invalid token values are rejected =
* Returns : An error code indicating the error found in the =
* command buffer or ZSPI_ERR_OK (0) which indicates =
* no error was found. =
*=====================================================================
*/
short validate_tokens(void)
{
zspi_ddl_ssid_def l_ssid;
/* set default token values
* if (any of these have to appear for a command set them to
* null values here & check them in the command_ code
* reset token counts
*/
context_count = 0;
tkn_count = 1;
/* get the header tokens- validate that they were retrieved ok */
if (err = SSGETTKN (req_buffer, ZSPI_TKN_SSID, (char *) &l_ssid))
display_spi_error (err, ZSPI_VAL_SSGETTKN,
ZSPI_TKN_SSID, true);
/* check if the SSID matches mine, but don’t check the version. */
if (memcmp (&l_ssid, &my_ssid, 10) != 0)
{
tkn_code = ZSPI_TKN_SSID;
return (ZSPI_ERR_TKN_VAL_INV);
}
if (err = SSGETTKN (req_buffer, ZSPI_TKN_MAXRESP, (char *) &max_resp))
display_spi_error (err, ZSPI_VAL_SSGETTKN,
ZSPI_TKN_MAXRESP, true);
if (max_resp < -1)
{
tkn_code = ZSPI_TKN_MAXRESP;
return (ZSPI_ERR_TKN_VAL_INV);
}
/* reposition to head of SPI buffer */
tkn_value = 0;
if (err = SSPUTTKN (req_buffer, ZSPI_TKN_INITIAL_POSITION,
(char *) &tkn_value))
display_spi_error (err, ZSPI_VAL_SSPUTTKN,
ZSPI_TKN_INITIAL_POSITION, true);
Example E-12. C File: A Simple SPI Server (page 9 of 12)