Search code examples
ckeilfunction-prototypesmisra

Where are Cortex-specific functions like __wfi() defined in Keil?


I'm working on an industrial code for Cortex-M0 controller, using uVision Keil 4.71.0.0 IDE. Our code is supposed to respect MISRA rules and is routinely checked with QA-C.

My problem is that some controller-specific functions like __wfi(), __current_sp() etc. don't seem to be defined anywhere, and QA-C is complaining about them:

340:                __wfi();
                       ^
Msg(5:3335) No function declaration.
Implicit declaration inserted: 'extern int __wfi();'.
CC Coding Rule 6 <next>

Right-clicking on the function name in Keil and selecting "Go to definition" confirms that the function is not defined:

Source Browser: '__wfi' - undefined Definition/Reference!

Does Keil provide an official header file with prototypes of such functions? Hardcoding such prototypes in our project's code or creating QA-C exceptions will require a formal review process which I would like to avoid.


Solution

  • I don't believe those are regular functions, but rather non-standard built-in functions that get in the generated binary get replaced with assembler code. See this.

    There are 3 MISRA rules to consider here and they are not necessarily harmonized with each other:

    • All code must follow ISO C.
    • All functions must have prototypes.
    • All use of assembly language must be encapsulated and documented.

    What I would do is to move all these "function calls" to a separate file and document that this file contains all invokations of inline assembly in your program. You probably need such a file to sate other MISRA rules regarding inline assembly. State that these functions are used to encapsulate assembler. Then exclude it from your static code analysis, unless the static analyser has support for the given assembler and/or "ARM intrinsics".

    If you do like this, I think you will conform 100% to MISRA without the need of raising a deviation. Simply state that the ARM intrinsics are your way of encapsulating inline assembly.