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

SPI Programming Examples
SPI Programming Manual427506-006
E-7
Example E-2: Basic Buffer Manipulations in C
Example E-2: Basic Buffer Manipulations in C
The C source file in Example E-2 demonstrates the basic buffer manipulation activities
illustrated in Figure 2-4
on page 2-18. The program uses DSM Template Services to
display the contents of the buffer after each manipulation. Run the program to see the
effect of SPI procedure calls on the contents of the buffer and the locations of the
buffer pointers.
Source File
SEC0204C
Object File
SEC0204O
Example E-2. C File: Basic Buffer Manipulations (page 1 of 2)
/* File name: sec0204c
* SPI EXAMPLE C 2-4
* Figure 2-4. Pointer Manipulation
*/
#pragma symbols
#pragma inspect
#pragma nomap
#pragma nolmap
#define max_bufsize 256 /* in bytes */
#include "secc.h"
#pragma list
#include "seccutlc"
#pragma page "MAIN"
main(/* int argc, char *argv[] */)
{
bufsize = max_bufsize;
/*
* Initialize the SPI buffer "b1"
*/
if (err = SSINIT (b1, bufsize, (short *) &ssid, ZSPI_VAL_CMDHDR))
display_spi_error (err, ZSPI_VAL_SSINIT, 0L, true);
printf ("After SSINIT: \n");
dump_buf (b1);
/*
* Put four tokens in the SPI buffer "b1"
*/
val = 'A';
if (err = SSPUTTKN (b1, tkn_1, &val))
display_spi_error (err, ZSPI_VAL_SSPUTTKN, tkn_1, true);
val = 'B';
if (err = SSPUTTKN (b1, tkn_2, &val))
display_spi_error (err, ZSPI_VAL_SSPUTTKN, tkn_2, true);
val = 'C';