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

SPI Programming Examples
SPI Programming Manual427506-006
E-42
Example E-10: A Simple SPI Requester in C
l_status = WRITEREADX (srvr_file_num, (char *) &req_buffer[0],
max_bufsize, sizeof (req_buffer), &read_count);
if (l_status != CCE) get_file_error (srvr_file_num);
file_num = -1; /* Don’t Cancel */
l_status = AWAITIOX (&file_num, /*buffer*/, &read_count,
/*tag*/, time_to_wait);
if (l_status == CCL)
{
get_file_error (file_num);
}
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");
STOP (process_id); /* Stop the server. */
STOP();
}
/* Get and display the BANNER. */
if (err = SSGETTKN (req_buffer, ZSPI_TKN_SERVER_BANNER,
(char *) &server_banner, 1))
{
printf ("No Server Banner found! \n");
} else
{
printf ("Using: %.50s\n", (char*) &server_banner);
}
do /* Do forever */
{
get_string (in_string.data, &in_string.len);
/* Send a SPI message */
if (err = SSINIT (req_buffer, max_bufsize, (short *) &my_ssid,
ZSPI_VAL_CMDHDR, spi_command))
display_spi_error (err, ZSPI_VAL_SSINIT, 0L, true);
if (err = SSPUTTKN (req_buffer, ZSPI_TKN_COMMENT,
(char *) &in_string))
display_spi_error (err, ZSPI_VAL_SSPUTTKN,
ZSPI_TKN_COMMENT, true);
/* Save the original buffer in case of continuation. */
memcpy(sav_buffer, req_buffer, max_bufsize);
SEND_IT:
if (display_spi_buffer)
{
printf ("SPI buffer sent:\n");
dump_buf (req_buffer);
}
Example E-10. C File: A Simple SPI Requester (page 6 of 8)