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

SPI Programming Examples
SPI Programming Manual427506-006
E-51
Example E-11: A Simple SPI Server in TAL
PROC process^requests;
BEGIN
! Read in the spi^command received
CALL readupdatex (rcv^file^num, req^buffer, max^bufsize,
spi^buffer^size);
CALL fileinfo (rcv^file^num, last^file^err);
CASE (last^file^err) OF ! data was found in the buffer
BEGIN
6 -> ! system message
! first word of req^buffer is message type.
CASE (req^buffer[0]) OF
BEGIN
-30 -> ! OPEN message
!Don’t reject the OPEN for sending the STARTUP msg.
IF (req^buffer [9] <> "#ZSPI ") AND
(startup^recvd := -1) THEN
BEGIN
! Reject the open with file error 11.
file^error := 11;
END;
OTHERWISE ->
res^buffer ':=' req^buffer FOR max^bufsize/2 WORDS;
END;
0 -> ! non-system message
! first word of msg (Z^MSGCODE) is a -28 for a SPI msg.
CASE (req^buffer[0]) OF
BEGIN
-1 -> ! Process Startup message
res^buffer ':=' req^buffer FOR max^bufsize/2 WORDS;
startup^recvd := -1;
-28 ->
CALL process^spi^buffer;
OTHERWISE ->
res^buffer ':=' req^buffer FOR max^bufsize/2 WORDS;
END;
OTHERWISE -> !unexpected message not a SPI or system message
res^buffer ':=' req^buffer FOR max^bufsize/2 WORDS;
continue := false;
END; -- of CASE (last^file^err)
END; -- of PROC process^requests
?PAGE "INT PROC 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.!
!==========================================================================!
Example E-11. TAL File: A Simple SPI Server (page 7 of 10)