AnsweredAssumed Answered

How to throw critical exception to test the functionality of exception handlers.

Question asked by Arpit Yadav on Jul 31, 2017
Latest reply on Sep 6, 2017 by Arpit Yadav

In our project we are using the chip MPC5648G and would like to test the functionality of the exception unit(exception handlers). We would like to throw some critical exceptions to our application and record how they can be handled. We tried the exception : divide by zero but it doesnt work, maybe it is not a critical exception for the processor unit. 

Now we are trying the dummy exception code which is written below to generate a critical exception.

 

 void Func1_TestException(void);

void Func1_TestException(void) {

 

const uint8_T memory[] = {1,2,3,4};

 

   if (TRUE == activateException)

   {

        pt = (void*) &memory[0] ;

                               pt[0]=2;

                               pt[2] = 34;

                               pt[23] = 34;

                              

                               {

                               char crash_instructions[4];

                               void (*fp) (void);

                              

                               /*

                               * Fill crash_instructions with arbitrary data.

                               */

                               crash_instructions[0] = 0;

                               crash_instructions[1] = 1;

                               crash_instructions[2] = 2;

                               crash_instructions[3] = 3;

                               /*

         * Branch to address of the array crash_instructions[]

                               * (which contains only data, not valid instructions)

                               */

                               fp = (void*)crash_instructions; (*fp)();

                               }

   }

}

 

Do anyone have any idea or sample code to throw an exception which is critical and how to test if the exception handlers are working correctly or not?

 

 

Thanks and Regards

Arpit

Outcomes