ModusToolbox Safety Test Library
Loading...
Searching...
No Matches

General Description

Functions

uint8_t SelfTest_PC (void)
 This function performs the test of the PC register.
uint8_t SelfTest_CPU_Registers (void)
 This function performs the checkerboard test for all CPU registers except the PC register.
uint8_t SelfTest_CPU_Registers_Fast (uint8_t *lastTestedStep)
 Checks one register per call (SP, R8-R12, LR, R0-R7), using both checkerboard patterns.
uint8_t SelfTest_PROGRAM_FLOW (void)
 This function tests the program flow.

Function Documentation

◆ SelfTest_PC()

uint8_t SelfTest_PC ( void )

This function performs the test of the PC register.

The function calls SelfTest_PC5555() and SelfTest_PCAAAA(), which are placed at addresses in Flash that match the 0x5555... and 0xAAAA... pattern most closely. These functions must return unique values to SelfTestA, SelfTestB, and SelfTestC variables if PC is working correctly.

Note
The linker script must place the helper functions used by this test at the required device-specific Flash addresses. Do not use this API before the application linker script reserves those sections; otherwise the test can fail because of integration layout, not because of a PC register fault.
Returns
OK_STATUS (0) - Test passed
ERROR_STATUS (1) - Test failed

◆ SelfTest_CPU_Registers()

uint8_t SelfTest_CPU_Registers ( void )

This function performs the checkerboard test for all CPU registers except the PC register.

Returns
OK_STATUS (0) - Test passed
ERROR_STATUS (1) - Test failed

◆ SelfTest_CPU_Registers_Fast()

uint8_t SelfTest_CPU_Registers_Fast ( uint8_t * lastTestedStep)

Checks one register per call (SP, R8-R12, LR, R0-R7), using both checkerboard patterns.

It then checks PRIMASK and CONTROL.SPSEL; with DSP, APSR is last. Initialize *lastTestedStep to 0xFFu before the first call. Each phase stores its step (0-17 with DSP, 0-16 otherwise) on PASS or FAIL. After a FAIL, stop testing and enter a safe state; another call would advance to the next step. NULL pointers and invalid step values return FAIL without changing the state. The PRIMASK test briefly enables maskable interrupts. Supported by GCC_ARM, ARM and IAR. Each phase's unique success signature is checked before reporting PASS. For targets whose linker copies .cy_ramfunc to RAM, define STL_CPU_FAST_RUN_FROM_RAM in the assembler build to run this test from RAM. For a target whose linker copies .cy_itcm to ITCM, define STL_CPU_FAST_RUN_FROM_ITCM instead. These options are mutually exclusive.

Note
Call this function only from privileged Thread mode. In unprivileged Thread mode, the PRIMASK step fails; in Handler mode, the CONTROL step fails. Both return ERROR_STATUS, the same value as a detected register fault.
The CONTROL step sets CONTROL.SPSEL = 1 for a short time, so the process stack pointer (PSP) becomes the active stack pointer. Before the first call, set PSP (for example, with __set_PSP()) to the top of a writable, 8-byte aligned RAM area that the application doesn't use for other data. If PSP is 0, the CONTROL step returns ERROR_STATUS. A non-zero PSP isn't checked further. The test itself doesn't write to this area, but an NMI or HardFault in this window stacks its exception frame below PSP: 32 bytes, or 104 bytes with an active FP context. On Armv8-M Mainline cores, PSPLIM must also allow this frame. The test doesn't change PSP or PSPLIM.
Parameters
lastTestedStepPointer to the caller-owned last attempted step. Must refer to writable storage and initially contain 0xFFu.
Returns
OK_STATUS (0) - Current register passed
ERROR_STATUS (1) - Test failed or invalid step

◆ SelfTest_PROGRAM_FLOW()

uint8_t SelfTest_PROGRAM_FLOW ( void )

This function tests the program flow.

For every critical execution code block, this function adds to or subtracts from complementary counters before the block execution and immediately after execution. This procedure allows verification of whether the code block is correctly called from the main program flow and to check if the block is correctly executed. Provided there are the same numbers of exit and entry points, the counter pair will always be complementary after each tested block.

Returns
OK_STATUS (0) - Test passed
ERROR_STATUS (1) - Test failed