This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS570LC4357: SafetyLib example in HALCoGen 4.06.01 : while(1) loop in main execution flow

Part Number: TMS570LC4357
Other Parts Discussed in Thread: HALCOGEN

In the example file example_SafetyLib.c , there's this part of code in the main process flow:

/* USER CODE BEGIN (13) */
#if STC_ENABLE == 1
       {
            SL_STC_Config stcSelfTestConfig;

            stcSelfTestConfig.stcClockDiv        = 2;             /* STC Clock divider = 1 */
            stcSelfTestConfig.intervalCount     = 1;             /* One interval only */
            stcSelfTestConfig.restartInterval0     = TRUE;         /* Start from interval 0 */
            stcSelfTestConfig.timeoutCounter     = 0xFFFFFFFF;     /* Timeout counter*/
            SL_SelfTest_STC(STC1_COMPARE_SELFCHECK, TRUE, &stcSelfTestConfig);
            while(1); /* STC failed to start */
        }
#endif
/* USER CODE END */

The while(1) will be reached and spin forever when the code reaches this point, without a test point up front that makes this happen.

Am I missing something?

  • Hi Jan,

    the while(1) should never be reached because the STC is kicked off. When the STC is completed, it will generate a CPU reset and startup begins again, but the STC is skipped the second time. If the while(1) is reached it is a critical error in the system/device which should be handled. In a safety system when the while(1) is reached, it would eventually trigger a watchdog failure. Although I don't have a big hearburn over this method of coding, a better implementation might have to make this a user code section with the while loop so customers could customize the behavior to their application. i.e., enter some safe state, communicate something is wrong, toggle a GPIO, or whatever is appropriate in their system. This can still be done with customer customization, but it will need to be managed because of potential overwrite by halcogen.
  • Thank you, got it.