In this post, I want to show that capability of Simulink in checking of MISRA-C standard.

MISRA-C standard is an international standard that has been used by many industries in the world. It mostly used in Embedded system code generation. In these systems, the developer often uses the C/C++ programming language.

The standard contains the principle of how to document embedded C code based of over 200 rules. The MISRA rules are often used in the automotive industry for safety-critical systems. These rules allow us to verify the program before the execution and minimize the risk of unexpected behaviour of the software. 

Some developer read all of these rules and follow its design guidelines. It needs a lot of time to read and understand all of these rules completely. Please pay attention to it that I do not want to say that you must not read all of these rules. Reading these rules help you very much to write more efficient C/C++ code, but sometimes you want to focus on your design and its parameters. In this situation, You can use Simulink.

Simulink help software developer to speed up the development process. You can generate C/C++ code for the automotive industry hardware just by one click. We will show the process in the Simulink by a simple example.

MISRA C standard simulink

In this Simulink model, we have two blocks (Controller and plant). I am going to generate code for the controller and download it to my target hardware.

In beginning, I must check my model. Simulink simplifies this process with a powerful tool (Model Advisor). 

Open the controller model :

model advisor

 

Click on the green icon on the right side, then click on the model advisor.

blank

 

This window is divided into two section (By Product, By Task).

If you click on the By Task, You will see an extensive list of task that can be done by Model Advisor.

 

blank

 

As you see in the top figure, we can do many standards check such as (ISO 26262, MISRA C: 2012, CERT C, CWE, ISO/IEC TS 17961, MAAB, JMAAB, AUTOSAR).

In this example, we are going to check MISRA C:2012, so I click on this task.

 

model advisor MISRA C

 

Select all the check, then click on the Run selected checks.

 

blank

 

The process is started and a window will appear :

blank

 

After completion, the report is shown.

 

report model advisor

 

Run Summary section shows that the final result of the check. It has five parts: Pass, Fail, Warning, Not Run, Total. it shows that 13 checks have been done. 12 checks have been passed and there is not Fail and there is just one warning. 

There is a description for each warning, you can come down and see the reason for this warning. 

I come back to the model and create an error in this model. At now, I do the check again.

 

blank

in this check, there are four fails. The reason for these fails is shown in the report windows.