This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

#pragma ASM/ENDASM inside a #define (???)

Hello,

I'm having trouble using #pragma ASM/ENDASM inside a #define statement. This is what I want to do inside the #define:

- push ACC (assembly)
- push IE (assembly)
- EA = 0 (C)

This is the code I'm *trying* to use:

#define portENTER_CRITICAL() \ 
{ \ 
#pragma ASM \ 
push  ACC \ 
push  IE  \ 
#pragma ENDASM \ 
EA = 0; \ 
}

But I always get an error, no matter what I change... also, it seems that #pragma ASM/ENDASM can't be used inside header files (who knows why...), is there any workaround for that, without repeating the same #defines inside all .c files that uses it?

Best regards,
Carlos.

PS: any one answering this thread, nevermind the "that's a bad practice! use separate asm and c source files! blah blah!..." comments... I really need this, so don't bother with those kind of comments...

Parents
  • Hello,

    What I'm trying to do is port FreeRTOS (http://www.FreeRTOS.org) to the philips 51MX architecture (P89C669)...

    The way freertos is made, to add support to other processors/microcontrolers one needs to make some architecture specific functions and some macros (#defines) . Those defines are used mainly for context switching, so they need to be done in assembly, to make use of push's and pop's. If anyone saw the freertos sources, you know what I'm talking about...

    Regards,
    Carlos.

Reply
  • Hello,

    What I'm trying to do is port FreeRTOS (http://www.FreeRTOS.org) to the philips 51MX architecture (P89C669)...

    The way freertos is made, to add support to other processors/microcontrolers one needs to make some architecture specific functions and some macros (#defines) . Those defines are used mainly for context switching, so they need to be done in assembly, to make use of push's and pop's. If anyone saw the freertos sources, you know what I'm talking about...

    Regards,
    Carlos.

Children
  • "Those defines are used mainly for context switching, so they need to be done in assembly"

    Yes that is the kind of thing that should be done in assembly!

    It really shouldn't be anywhere near a 'C' file!

    "If anyone saw the freertos sources, you know what I'm talking about..."

    I haven't, so I'll take your word for it...

    If you're stuck with having to do it this way because of 3rd-party constraints, then I s'pose you'll have to go that way - even if it really is a "bad practice" blah, blah, etc...

    :-(

    So, although the source is "free", the work to port it is going to cost something - that's always the tradeoff: is it worth it, rather than buy something "ready-to-go"...?
    That's a call only you can make!

  • It says a port already exists to the SiLabs 8051-derivatives:
    www.freertos.org/main.html

    could you get any tips from the way they did it?

  • Hello :)

    Yep, I took Cygnal port as a base... The problem is the compiler... I'm using Keil and they use SDCC. SDCC suports assembly in #define statements, but doesn't support 51MX family, I think only keil cx51 supports 51MX...

    I already "expanded" all #defines with the code that was supposed to be inside them (basically I've made the pre-processor work by hand :), but now I have linker errors saying that it can't find some libraries (I think it has to do with floating point operations)...

    Regards and thanks for the replies :)
    Carlos.

  • "(I think it has to do with floating point operations)"

    Why would an RTOS be doing floating-point operations...?!

  • Hi,

    It's only on the demo software, to test the RTOS. The logic behind that is the greater probability of a task being interrupted by a context switch between a float operation (sum, multiplication, etc...) than with a single byte operation...

    regards,
    Carlos.

  • ANSI C does not allow preprocessor directives to be generated by #define.

    There's one ugly way to do this just with the C preprocessor:

    header.h
    --
    ...
    #include "mypragma.pragma"
    ...

    mypragma.pragma
    --
    #pragma mypragma
    --

    But I can't really recommend it.