SPI Programming Manual (H06.24+, J06.13+)

SPI Programming Examples
SPI Programming Manual427506-007
E-53
Example E-11: A Simple SPI Server in TAL
tkn^code := zspi^tkn^context;
context^count := context^count + tkn^count;
IF context^count <> 1 THEN
BEGIN
RETURN (zcom^err^tkn^dup);
END ELSE
BEGIN
! retrieve and validate the context
IF err := ssgettkn (req^buffer, zspi^tkn^context, the^context) THEN
CALL display^spi^error (err, zspi^val^ssgettkn,
zspi^tkn^context, true);
IF (the^context.len > $len(context^template)) OR
(the^context.len <> ($offset(context^template.con^string) +
the^context.con^string.len + 2)) OR
(the^context.command <> spi^command) OR
(the^context.index > the^context.con^string.len) THEN
BEGIN
RETURN (zcom^err^tkn^cntxt^code^inv);
END;
END;
OTHERWISE ->
RETURN (zcom^err^tkn^code^inv);
END; -- of CASE
END; -- of WHILE LOOP
RETURN (zspi^err^ok); ! no errors found, RETURN ok
END; ! validate^tokens
PAGE "INT PROC verify^msg"
!======================================================================!
! Proc : verify^msg !
! Function : This procedure will determine if a valid SPI buffer was !
! received. !
! Returns : An error code indicating the error found, !
! or zspi^err^ok (0) which indicates no error was found. !
!======================================================================!
INT PROC verify^msg (p^count);
INT p^count; !size of data read must be at least 6!
BEGIN
IF p^count < 6 THEN
RETURN (zspi^err^invbuf);
! Reset the buffer
tkn^count := 1;
IF err := ssputtkn (req^buffer, zspi^tkn^reset^buffer,
bufsize) THEN
BEGIN
CALL display^spi^error (err, zspi^val^ssputtkn,
zspi^tkn^reset^buffer, false);
RETURN (zspi^err^invbuf);
END;
Example E-11. TAL File: A Simple SPI Server (page 9 of 10)