Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 2.1
#4
Quote:Also, please can you give examples where the rule is not violated.

In my understanding, there are the three solutions compliant with MISRA 2.1:

a) Assembler function:
nop.h:
Code:
extern void nop(void);

nop.asm:
Code:
NOP   PROC
   nop
   ret
NOP  ENDP

foo.c
Code:
#include \"nop.h\"

static void function(void)
{
   ... /* do somthing */
    nop();
   ... /* do somthing */

}


b) C-function encapsulation
nop.h:
Code:
extern void nop(void);


nop.c:
Code:
#include \"nop.h\"

void nop(void)
{
/* No code between bracket and pragma */
#pragma ASM
   nop
#pragma ENDASM
/* No code between pragam and bracket */
}

/* No other function in nop.c, except other ASM encapsulation. */

foo.c:
Code:
#include \"nop.h\"

static void function(void)
{
   ... /* do somthing */
    nop();
   ... /* do somthing */

}


In this solution nop.c is not MISRA but the code is isolated.
Foo.c is MISRA.


c) macro-function

nop.h:
Code:
#define nop()\   asm(\"nop\")

/* No other definition in nop.h file, except other assembleur encapsulation */

foo.c:
Code:
#include \"nop.h\"

static void function(void)
{
   ... /* do somthing */
    nop();
   ... /* do somthing */

}

The last solution could have an impact on OBJ file generation.
Some (most of?) compiler requier to compile with a specific option when assembler code is use in C file.
This last solution should compliant with MISRA 2.1 but not with MISRA 1.1
(inline assembler is not C standard).


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)