Code snippets from the file "VDE_MCU16_ClassB_V240b.zip" as downloaded from
this page:
//classb.h
typedef enum _CLASSBRESULT_
{
CLASSB_TEST_PASS = 0,
CLASSB_TEST_FAIL,
} CLASSBRESULT;
CLASSBRESULT CLASSB_CPUPCTest();
; classb_pc_.s
.global _CLASSB_CPUPCTest
.bss ; uninitialized data section
PCErrorFlag: .space 2 ; program counter error flag
; after POR PCErrorFlag holds a random value
.section function5555, code, address(0x00001554-2)
return ; guard return instruction
PCTestFunction5555:
dec [w0], [w0]
return
.section functionAAAA, code, address(0x00002aaa-2)
return ; guard return instruction
PCTestFunctionAAAA:
dec [w0], [w0]
return
_CLASSB_CPUPCTest:
mov #PCErrorFlag, w0 ; w0 points to PCErrorFlag
inc [w0], [w0] ; PCError Flag now contains a random value + 1 …
call PCTestFunction5555
inc [w0], [w0]
call PCTestFunctionAAAA
mov [w0], w0
return
Most of the times
CLASSB_CPUPCTest will fail, although the calls of both test functions decremented
PCErrorFLag.
PCErrorFlag must be initialized to zero. In the worst case the random value in
PCErrorFLag is 0xFFFE. If both calls fail, the function will return
CLASSB_TEST_PASS.
IMO PCErrorFlag isn’t needed at all.
_CLASSB_CPUPCTest:
mov #1, w0
call PCTestFunction5555
inc w0, w0
call PCTestFunctionAAAA
return
.section functionAAAA, code, address(0x00002aaa-2)
return ; guard return instruction
PCTestFunction5555:
dec w0, w0
return
; …