Explain Macro from avr-libc

Discussion in 'C Programming' started by Affan Syed, Mar 8, 2005.

  1. Affan Syed

    Affan Syed Guest

    I am not able to figure out exactly what this macro is doing. Can one of the
    gurus around here decipher this?

    #define sei() __asm__ __volatile__ ("sei" ::)

    PS: It is from the avr-libc interrupt.h and it should set a partilcular
    interrrupt.

    Thanks.

    Affan
     
    Affan Syed, Mar 8, 2005
    #1
    1. Advertising

  2. Affan Syed <> scribbled the following:
    > I am not able to figure out exactly what this macro is doing. Can one of the
    > gurus around here decipher this?


    > #define sei() __asm__ __volatile__ ("sei" ::)


    > PS: It is from the avr-libc interrupt.h and it should set a partilcular
    > interrrupt.


    > Thanks.


    It's a syntax error. :: is an invalid token in C.

    --
    /-- Joona Palaste () ------------- Finland --------\
    \-------------------------------------------------------- rules! --------/
    "We're women. We've got double standards to live up to."
    - Ally McBeal
     
    Joona I Palaste, Mar 8, 2005
    #2
    1. Advertising

  3. Affan Syed

    jacob navia Guest

    Affan Syed wrote:
    > I am not able to figure out exactly what this macro is doing. Can one of the
    > gurus around here decipher this?
    >
    > #define sei() __asm__ __volatile__ ("sei" ::)
    >
    > PS: It is from the avr-libc interrupt.h and it should set a partilcular
    > interrrupt.
    >
    > Thanks.
    >
    > Affan
    >
    >


    This is GNU C. The macro expands to an __asm__ construct, that
    emits an assembler instruction. I do not know anything more, and
    since I do not use gcc I can't tell you more. Just google around
    for the gcc documentation, and you will find the explanation.
     
    jacob navia, Mar 8, 2005
    #3
  4. Joona I Palaste wrote:
    >
    > It's a syntax error. :: is an invalid token in C.
    >


    Negative, group degrading response.

    --
    Thomas.
     
    Thomas Stegen, Mar 8, 2005
    #4
  5. Affan Syed

    Randy Howard Guest

    In article <d0jcnb$bea$>, says...
    > I am not able to figure out exactly what this macro is doing. Can one of the
    > gurus around here decipher this?
    >
    > #define sei() __asm__ __volatile__ ("sei" ::)
    >
    > PS: It is from the avr-libc interrupt.h and it should set a partilcular
    > interrrupt.
    >


    Without looking at the documentation for that particular compiler, it
    is pretty hard to guess what that is doing. Apparently you have not
    bothered to RTFM yet, because it is covered.

    AVR Libc has a website at http://www.nongnu.org/avr-libc/

    Looking at the online documentation on that site, they cover the sei
    and cli macros under "Interrupts and Signals", which apparently
    enable or disable the I bit of the status register. so the "::"
    syntax is probably some flag to the compiler to make that happen.
    The manual says it is a single instruction when compiled, so it is
    low overhead.

    It does not, as you imply above, set a particular interrupt. It
    enables/disables interrupts entirely. If you want to work with
    particular interrupts, again I refer you to the documentation under
    "Interrupts and Signals" which cover this.

    You would probably be a lot better off asking in a forum dedicated
    to the AVR, or one of an embedded newsgroup instead if that is
    insufficient.

    --
    Randy Howard (2reply remove FOOBAR)
    "Making it hard to do stupid things often makes it hard
    to do smart ones too." -- Andrew Koenig
     
    Randy Howard, Mar 8, 2005
    #5
  6. On Tue, 8 Mar 2005, Joona I Palaste wrote:
    >
    > Affan Syed <> scribbled the following:
    >> I am not able to figure out exactly what this macro is doing. Can one
    >> of the gurus around here decipher this?

    >
    >> #define sei() __asm__ __volatile__ ("sei" ::)

    >
    > It's a syntax error. :: is an invalid token in C.


    Actually, :: /isn't/ a token in C. Therefore, what we really have
    here is one : token, immediately followed by another : token. This
    would indeed be a syntax error if it weren't "hidden" by the #define.

    #define sei() a bunch of nonsense tokens :: ^%! asd6 **(!%

    is perfectly valid C code on its own; it only contributes to a syntax
    error once you use 'sei()' in an expression seen by the parser.[1]

    Potentially more useful to the OP: The line of code you posted is
    from a platform-specific implementation library. We don't discuss
    individual platforms here; there are other Usenet newsgroups devoted
    to them. Rest assured that you will never need to know what "__asm__
    __volatile__ ("sei" ::)" means... or if you can't do that, ask the
    question again in a group dedicated to your particular computer
    architecture, where someone will probably know what "sei" means to
    your computer.

    -Arthur

    [1] - The parser that parses "real" C code, not the parser that's
    part of the preprocessor, that is. How does one accurately and
    precisely refer to that concept, without resorting to Standardese
    like "the seventh phase of translation," or whatever it is?
     
    Arthur J. O'Dwyer, Mar 8, 2005
    #6
  7. [OT] Re: Explain Macro from avr-libc

    Affan Syed wrote:
    > I am not able to figure out exactly what this macro is doing. Can one

    of the
    > gurus around here decipher this?
    >
    > #define sei() __asm__ __volatile__ ("sei" ::)
    >
    > PS: It is from the avr-libc interrupt.h and it should set a

    partilcular
    > interrrupt.
    >


    For the most part, off topic, but I think we can scrounge at least some
    topicality. The C standard states:

    7.1.3 Reserved identifiers

    [...]

    All identifiers that begin with an underscore and either
    an uppercase letter or another underscore are always
    reserved for any use.


    So __asm__ and __volatile__ are implementation-defined identifiers, or
    in other words, specific to your compiler.

    [OT]

    If you're using gcc, __asm__ is a construct for using assembly code
    from within C code. The presence of __volatile__ tells the compiler
    not to reorder or optimize away the instruction. "sei" is an assembly
    instruction that enables interrupt processing on the processor. The
    double colons delimit input and output operands, of which there are
    none here. As always, see your compiler documentation for definitive
    information.

    When you're mucking around with enabling and disabling interrupts,
    there's usually hard and strict requirements about exactly what is
    executed with interrupts enabled/disabled. The last thing you want
    there is the compiler rearranging or eliminating instructions like this
    behind your back, hence the usage of __volatile__ in this case.


    Mark F. Haigh
     
    Mark F. Haigh, Mar 9, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. avishay

    AVR core and patents

    avishay, Jun 9, 2005, in forum: VHDL
    Replies:
    0
    Views:
    739
    avishay
    Jun 9, 2005
  2. Replies:
    0
    Views:
    598
  3. RadGar

    CCITT in C++ for AVR

    RadGar, Nov 27, 2005, in forum: C++
    Replies:
    2
    Views:
    534
    RadGar
    Nov 27, 2005
  4. lorenzvvv

    wctomb function for AVR

    lorenzvvv, Apr 4, 2007, in forum: C Programming
    Replies:
    3
    Views:
    369
    Keith Thompson
    Apr 5, 2007
  5. Ivan Shmakov

    Re: Getting started with AVR and C

    Ivan Shmakov, Nov 24, 2012, in forum: C Programming
    Replies:
    60
    Views:
    971
    Ben Bacarisse
    Dec 17, 2012
Loading...

Share This Page