473,396 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Explain Macro from avr-libc

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
Nov 14 '05 #1
6 3134
Affan Syed <as***@usc.edu> 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 (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"We're women. We've got double standards to live up to."
- Ally McBeal
Nov 14 '05 #2
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.
Nov 14 '05 #3
Joona I Palaste wrote:

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


Negative, group degrading response.

--
Thomas.
Nov 14 '05 #4
In article <d0**********@gist.usc.edu>, as***@usc.edu 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
Nov 14 '05 #5

On Tue, 8 Mar 2005, Joona I Palaste wrote:

Affan Syed <as***@usc.edu> 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?
Nov 14 '05 #6
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
mf*****@sbcglobal.net

Nov 14 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Dead RAM | last post by:
Hey people, i'll try to keep this short ;) Here is what I want to type (or at least close too)... #define VER_BUILD 1 #define STR_VER_BUILD "VER_BUILD" But what happends is...
2
by: RadGar | last post by:
Hi, I'm reposting my question in this group from comp.arch.embedded - as it was suggested to me that it might be better to do so. In advance to all reading: this is meant mostly for people who...
11
by: kartheeknagasuri | last post by:
my friend gave this code to me..... it is working fine....how come? please explain me if u can understand..... #include <stdio.h> #include <conio.h> #define _(__,___)\ ___##__
3
by: Lars | last post by:
Hi I'm programming C to an AVR-Board and would like to activate a register on the board with an C# application. Instead of pressing the button (PINA.4 or address 0x19 bit 4) , i would like to...
3
by: lorenzvvv | last post by:
Hello! I need to compile a program where wctomb and mbtowc functions are in. These functions are useful for conversions from wide characters to multi-byte and vice versa. Avr-gcc lacks wctype.h...
2
by: hechergo | last post by:
Hello, here my problem: I am using AVR GCC compiler for programming Atmega168 microcontroller. I am using an I2C communication, my problem is when I receive a command I run a function and the...
4
by: Ravi | last post by:
#define JOIN(s1,s2) printf("%s = %s %s = %s",#s1,s1,#s2,s2)
2
by: TYF | last post by:
hi, can any one explain me what this little macro is doing? #define pos_of(h, f) ((short int) &((h *) 0)->f) h is a struct f is a member of it i have no clue, i only know it has...
4
by: 3mwn8tbfrd19ph0 | last post by:
I am writing codes in windows and Unicode. The windows header file defines CreateFont into CreateFontW. I am using a class which has a function CreateFile. So when compiling, I got error that the...
3
by: phoenix1990 | last post by:
so i started learning avr-c programming a few weeks ago and i'm a little confused about using the eeprom so save values. i've been working a snake game for my project, and i need to save everything...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.