473,796 Members | 2,586 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3155
Affan Syed <as***@usc.ed u> 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.hel sinki.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**********@g ist.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.ed u> 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*****@sbcglob al.net

Nov 14 '05 #7

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

Similar topics

20
2837
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 the preprocessor see the quots in STR_VER_BUILD and replaces that text with "VER_BUILD"... I need it to see the VER_BUILD and replace it with 1, and only after doing
2
4770
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 code in C++ for microcontrollers such as AVR. So here it goes: I am making a school project for PocketPC which is to send some data
11
1906
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
5017
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 press a button i C# instead. I got a serial connection to the board and experimented a bit, but i'm quite lost. I know howto send text... SerialPort port = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
3
1789
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 (that contains them). Does exist a library to include in my sources or should I write those two functions on my own? Thanks, in advance.
2
3695
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 result of this function should be store in a global variable and remain with this value till next time I need to run this function. OK, this should be possible using an static variable declared in the global part. static unsigned int value=8; //...
4
1715
by: Ravi | last post by:
#define JOIN(s1,s2) printf("%s = %s %s = %s",#s1,s1,#s2,s2)
2
1300
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 something to do with the position.
4
3710
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 CreateFontW is not a member of the class. What should I do? Thanks for your help!
3
4084
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 at any point to the eeprom so that the user can load it from that spot again. but first i've been receiving warnings in regard to the way i've been trying to save the the highscore #include <avr/eeprom.h> eeprom_write_word(1, hiscore);...
0
9685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9535
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10242
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9061
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7558
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5453
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4127
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2931
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.