EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

How does can you use all functions lpc230x.c

Started by jefspalace April 27, 2008
Paul, et al:

OK, now can we start a discussion on the various misapprehensions of
sequence points in C? :-)

No, but seriously, your insistence on carrying this discussion on for as
long as it has is good from time to time, if for no other reason than to
remind C programmers that there are rules to a language which we must
not dismiss as unimportant simply because they seem arcane in typical
use. These issues should not be construed as merely the basis of some
kind of "trick question" in a college programming course. It is
precisely these kinds of seemingly arcane rules that can lead apparently
well-written code to fail to perform as expected in real applications.
How many times have you found a bug in someone's code wherein there are
two independent instances of the same presumed "global" variable because
someone has confused the rules of scope/storage class? Some days, I
think that about 75% of all C code operational anomalies can be
attributed to either the scope/storage class confusion, the failure to
understand the "volatile" keyword, or the failure to understand sequence
points and the related differences between when values are evaluated vs.
when the results of such evaluations are stored.

Alas, these subjects rarely come up except in the occasional discussion
thread, and the length at which such discussions can go on -- and the
varied nature of the positions that individual posters can make with
conviction in such discussions -- indicates that too little time is
spent on these "arcane" items in the early stages (incl. college
coursework) of the making of software engineers.

Thanks for daring to push the subject in spite of the possibility it
might have initiated the slings and arrows of those who thought they
understood the subject. And congratulations to the group for not
letting this one veer into the kind of nastiness that often attends such
discussions.

-cordeg
Paul Curtis wrote:

> Hi,
>
> > Paul,
> >
> > as I read your emails I start to think I don't know C at all. :-)
>
> It's not uncommon for productive programmers to use a pragmatic
> non-tricksy
> subset of the language to get stuff done. I don't hold with adding
> more and
> ore toppings to a simple language to build a monster nobody understands. I
> don't expect many programmers to know the full set of language rules.
>
> Hands up who can recite the precedence and associativity of each C
> operator?
> I can't and that's why I use parentheses.
>
> (Modula-2, Pascal, and Oberon had the right idea, only two levels
> precedence
> associativity you needed to remember, both in line with mathematical
> notation...)
>
> --
> Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
>
> CrossWorks for ARM, MSP430, AVR, MAXQ, and now Cortex-M3 processors
>
>


An Engineer's Guide to the LPC2100 Series

Hi,

I am trying to generate GPIO interrupt on lpc23xx simulator,
I setup Pin 0.11as a input, I can see signal on P0.11 in KEIL through
Logic Analyzer,

Code snippet is:

PINSEL0 &= 0xFF3FFFFF;
PINMODE0 &= 0xFFBFFFFF;

FIO0DIR1 &= 0xF7; // input direction
IO0_INT_EN_F &=0x800; //falling edge

VICVectAddr17 = (uint32) int_gpio;
VICIntEnable = (1 << 17); // channel 17 shared between GPIO and EINT3
interrupts.

Inside int_gpio, I clear interrupt. I have put breakpoint in int_gpio, it
never come to isr.
And signal are provided through ini file,
I am not sure what exactly I am missing, help is appreciated. Thank you in
advance.

Thank you & Regards,
Chandrashekhar
=====-----=====-----====Notice: The information contained in this e-mail
message and/or attachments to it may contain
confidential or privileged information. If you are
not the intended recipient, any dissemination, use,
review, distribution, printing or copying of the
information contained in this e-mail message
and/or attachments to it are strictly prohibited. If
you have received this communication in error,
please notify us by reply e-mail or telephone and
immediately and permanently delete the message
and any attachments. Thank you


Since you're using fast gpio, make sire fast gpio's are enabled, by default they're not!

~ Paul Claessen

----- Original Message -----
From: Chandrashekhar Kulkarni
To: l...
Sent: Tuesday, April 29, 2008 1:44 AM
Subject: Re: [lpc2000] Re: How does can you use all functions lpc230x.c
Hi,

I am trying to generate GPIO interrupt on lpc23xx simulator,
I setup Pin 0.11as a input, I can see signal on P0.11 in KEIL through
Logic Analyzer,

Code snippet is:

PINSEL0 &= 0xFF3FFFFF;
PINMODE0 &= 0xFFBFFFFF;

FIO0DIR1 &= 0xF7; // input direction
IO0_INT_EN_F &=0x800; //falling edge

VICVectAddr17 = (uint32) int_gpio;
VICIntEnable = (1 << 17); // channel 17 shared between GPIO and EINT3
interrupts.

Inside int_gpio, I clear interrupt. I have put breakpoint in int_gpio, it
never come to isr.
And signal are provided through ini file,
I am not sure what exactly I am missing, help is appreciated. Thank you in
advance.

Thank you & Regards,
Chandrashekhar
=====-----=====-----====Notice: The information contained in this e-mail
message and/or attachments to it may contain
confidential or privileged information. If you are
not the intended recipient, any dissemination, use,
review, distribution, printing or copying of the
information contained in this e-mail message
and/or attachments to it are strictly prohibited. If
you have received this communication in error,
please notify us by reply e-mail or telephone and
immediately and permanently delete the message
and any attachments. Thank you




Hi Paul,

Thank you for your reply, I forgot to mention that I already enable fast
gpio:

SCS |= 1;

With this I do not get interrupt.
Is there anything to do with simulator?

Thank you & Regards,
Chandrashekhar

"Paul Claessen"
Sent by: l...
04/29/2008 05:21 PM
Please respond to
l...
To

cc

Subject
Re: [lpc2000] Re: How does can you use all functions lpc230x.c

Since you're using fast gpio, make sire fast gpio's are enabled, by
default they're not!

~ Paul Claessen

----- Original Message -----
From: Chandrashekhar Kulkarni
To: l...
Sent: Tuesday, April 29, 2008 1:44 AM
Subject: Re: [lpc2000] Re: How does can you use all functions lpc230x.c

Hi,

I am trying to generate GPIO interrupt on lpc23xx simulator,
I setup Pin 0.11as a input, I can see signal on P0.11 in KEIL through
Logic Analyzer,

Code snippet is:

PINSEL0 &= 0xFF3FFFFF;
PINMODE0 &= 0xFFBFFFFF;

FIO0DIR1 &= 0xF7; // input direction
IO0_INT_EN_F &=0x800; //falling edge

VICVectAddr17 = (uint32) int_gpio;
VICIntEnable = (1 << 17); // channel 17 shared between GPIO and EINT3
interrupts.

Inside int_gpio, I clear interrupt. I have put breakpoint in int_gpio, it
never come to isr.
And signal are provided through ini file,
I am not sure what exactly I am missing, help is appreciated. Thank you in

advance.

Thank you & Regards,
Chandrashekhar
=====-----=====-----====Notice: The information contained in this e-mail
message and/or attachments to it may contain
confidential or privileged information. If you are
not the intended recipient, any dissemination, use,
review, distribution, printing or copying of the
information contained in this e-mail message
and/or attachments to it are strictly prohibited. If
you have received this communication in error,
please notify us by reply e-mail or telephone and
immediately and permanently delete the message
and any attachments. Thank you





ForwardSourceID:NT000020D2
=====-----=====-----====Notice: The information contained in this e-mail
message and/or attachments to it may contain
confidential or privileged information. If you are
not the intended recipient, any dissemination, use,
review, distribution, printing or copying of the
information contained in this e-mail message
and/or attachments to it are strictly prohibited. If
you have received this communication in error,
please notify us by reply e-mail or telephone and
immediately and permanently delete the message
and any attachments. Thank you


Interrupts enabled in startup?

Albert

Hi,

I am trying to generate GPIO interrupt on lpc23xx simulator,
I setup Pin 0.11as a input, I can see signal on P0.11 in KEIL through
Logic Analyzer,

Code snippet is:

PINSEL0 &= 0xFF3FFFFF;
PINMODE0 &= 0xFFBFFFFF;

FIO0DIR1 &= 0xF7; // input direction
IO0_INT_EN_F &=0x800; //falling edge

VICVectAddr17 = (uint32) int_gpio;
VICIntEnable = (1 << 17); // channel 17 shared between GPIO and EINT3
interrupts.

Inside int_gpio, I clear interrupt. I have put breakpoint in int_gpio,
it
never come to isr.
And signal are provided through ini file,
I am not sure what exactly I am missing, help is appreciated. Thank you
in
advance.


Hi Albert,

Yes, interrupts are enabled in startup. I am able to catch timer and EINT3
interrupt.

Thank you & Regards,
Chandrashekhar.

a...@vp.pl
Sent by: l...
04/29/2008 06:19 PM
Please respond to
l...
To
l...
cc

Subject
Re: Re: [lpc2000] Re: How does can you use all functions lpc230x.c

Interrupts enabled in startup?

Albert

Hi,

I am trying to generate GPIO interrupt on lpc23xx simulator,
I setup Pin 0.11as a input, I can see signal on P0.11 in KEIL through
Logic Analyzer,

Code snippet is:

PINSEL0 &= 0xFF3FFFFF;
PINMODE0 &= 0xFFBFFFFF;

FIO0DIR1 &= 0xF7; // input direction
IO0_INT_EN_F &=0x800; //falling edge

VICVectAddr17 = (uint32) int_gpio;
VICIntEnable = (1 << 17); // channel 17 shared between GPIO and EINT3
interrupts.

Inside int_gpio, I clear interrupt. I have put breakpoint in int_gpio,
it
never come to isr.
And signal are provided through ini file,
I am not sure what exactly I am missing, help is appreciated. Thank you
in
advance.



ForwardSourceID:NT000020DE
=====-----=====-----====Notice: The information contained in this e-mail
message and/or attachments to it may contain
confidential or privileged information. If you are
not the intended recipient, any dissemination, use,
review, distribution, printing or copying of the
information contained in this e-mail message
and/or attachments to it are strictly prohibited. If
you have received this communication in error,
please notify us by reply e-mail or telephone and
immediately and permanently delete the message
and any attachments. Thank you


IO0_INT_EN_F &=0x800; //falling edge ?????????????

Should be |= not &=



(Sudden feeling of dvu .. havent we seen this code snippet before?)



~ Paul Claessen



From: l... [mailto:l...] On Behalf Of
Chandrashekhar Kulkarni
Sent: Tuesday, April 29, 2008 8:18 AM
To: l...
Cc: l...
Subject: Re: [lpc2000] Re: How does can you use all functions lpc230x.c



Hi Paul,

Thank you for your reply, I forgot to mention that I already enable fast
gpio:

SCS |= 1;

With this I do not get interrupt.
Is there anything to do with simulator?

Thank you & Regards,
Chandrashekhar

"Paul Claessen" >
Sent by: l...
04/29/2008 05:21 PM
Please respond to
l...

To
>
cc

Subject
Re: [lpc2000] Re: How does can you use all functions lpc230x.c

Since you're using fast gpio, make sire fast gpio's are enabled, by
default they're not!

~ Paul Claessen

----- Original Message -----
From: Chandrashekhar Kulkarni
To: l...
Sent: Tuesday, April 29, 2008 1:44 AM
Subject: Re: [lpc2000] Re: How does can you use all functions lpc230x.c

Hi,

I am trying to generate GPIO interrupt on lpc23xx simulator,
I setup Pin 0.11as a input, I can see signal on P0.11 in KEIL through
Logic Analyzer,

Code snippet is:

PINSEL0 &= 0xFF3FFFFF;
PINMODE0 &= 0xFFBFFFFF;

FIO0DIR1 &= 0xF7; // input direction
IO0_INT_EN_F &=0x800; //falling edge

VICVectAddr17 = (uint32) int_gpio;
VICIntEnable = (1 << 17); // channel 17 shared between GPIO and EINT3
interrupts.

Inside int_gpio, I clear interrupt. I have put breakpoint in int_gpio, it
never come to isr.
And signal are provided through ini file,
I am not sure what exactly I am missing, help is appreciated. Thank you in

advance.

Thank you & Regards,
Chandrashekhar
=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain
confidential or privileged information. If you are
not the intended recipient, any dissemination, use,
review, distribution, printing or copying of the
information contained in this e-mail message
and/or attachments to it are strictly prohibited. If
you have received this communication in error,
please notify us by reply e-mail or telephone and
immediately and permanently delete the message
and any attachments. Thank you





ForwardSourceID:NT000020D2
=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain
confidential or privileged information. If you are
not the intended recipient, any dissemination, use,
review, distribution, printing or copying of the
information contained in this e-mail message
and/or attachments to it are strictly prohibited. If
you have received this communication in error,
please notify us by reply e-mail or telephone and
immediately and permanently delete the message
and any attachments. Thank you






Paul Curtis wrote:

"At top-level, and without contrary declarations, "int x" declares an
integer with file scope and extern storage class."

According to my beloved K&R 2nd edition of "The C language".

The above seems to contradict appendix A8.1:

"At most one storage class specifier may be given in a declaration. If none
is given, these rules are used: [.]; objects and functions declared outside
a function are taken to be STATIC with external linkage."

In fact both Paul and K&R are right, even though this is confusing.

I think the confusion is caused by the 'overloading' of the storage class
specifiers: they do more than just specify storage class.

Maybe this helps to clarify things:

There are only TWO storage classes: 'automatic', meaning storage will be
discarded once the block it is declared in is left, and 'static', simply
meaning storage will never be discarded during the lifetime of the program.

(See appendix A4.1)

Storage class INDENTIFIERS, can, in addition to storage class also specify
linkage!

The keywords 'auto' and 'register' both specify 'automatic' storage class.

The keywords 'static' and 'extern' BOTH specify 'static' (as opposed to
'auto') storage class. In either case, storage will not be discarded.

The keyword 'static' ALSO implies local linkage, and the keyword 'extern'
ALSO implies external linkage.

In this light, Paul's statement above would have been more correct (but not
necessarily more clear) if stated as:

"At top-level, and without contrary declarations, "int x" declares an
integer with file scope, static storage class and external linkage"

So, one has to make a clear distinction between static storage class and the
'static' and 'extern' storage class (and linkage) SPECIFIERS!

Considering all this I think I can still make a case for my earlier remark
(and K&R's) that storage class affects scope, when by 'storage class' we
actually mean, like Paul does in his statement above, 'storage class
specifier', and also considering that 'scope' includes the notion of
linkage, in addition to lexical scope.

See appendix A11:

"Therefore there are two kinds of scope to consider: first lexical scope of
an identifier, [.]; second, the scope associated with objects and functions
with external linkage, which determines the connection between identifiers
in separately compiled translation units."

So. by changing an object's storage class (specifier), say, from 'extern' to
'static' you WILL affect its scope (linkage).

Somehow I think I was too fast in admitting I was wrong. ;-)

~ Paul Claessen

From: l... [mailto:l...] On Behalf Of
Paul Curtis
Sent: Monday, April 28, 2008 12:47 PM
To: l...
Subject: RE: [lpc2000] Re: How does can you use all functions lpc230x.c

Hi Jan at al,

The following code demonstrates scope:

void foo(void)
{
while (1) // don't confuse the unwary, wrap a block in a construct
{
extern int x;
x = 1;
}
x = 2;
}

Here, x in foo is addressing something called "x" that is allocated storage
over the lifetime of the application. The scope of the declaration of "x"
in "foo" is only for the inner block. The line x=2 will generate an error
even though something called "x" exists in the universe and is seen by the
linker, it's just that the compiler can't see it at that point.

C is a language that separates scope from storage class. In other
algorithmic languages, most notably the Pascal and Modula languages, scope
and storage class are combined into one and can never be separated: "global"
variables are declared at the outermost level and all variables in functions
or procedures get "auto" storage class and local scope. (For those that
know Modula-2, please don't interject and chime on about import, export, and
local modules, those were severely brain-dead constructs.)

Note that storage class is inferred, if it is not specified, and depends
where the variable is declared.

At top-level, and without contrary declarations, "int x" declares an integer
with file scope and extern storage class. In a function block, "int x"
declares an integer with block scope and auto storage class.

--
Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
CrossWorks for ARM, MSP430, AVR, MAXQ, and now Cortex-M3 processors

> -----Original Message-----
> From: l...
[mailto:l... ] On
> Behalf Of Jan Vanek
> Sent: 28 April 2008 17:14
> To: l...
> Subject: Re: [lpc2000] Re: How does can you use all functions lpc230x.c
>
> Hi,
>
> I think Paul Curtis is 100% right, but at the same time I think Paul
> Claessen's formulation "that functions have universal scope" nicely
> illustrates what he is trying to say, especially given he is trying to
> answer relative-c-newbie question. The scope he means is not the scope
> of a declaration, but can be very well seen as a scope of a symbol for
> the linker. Which of course is a linkage class, and here this word game
> starts again :-)
>
> Regards,
> Jan
>
> ----- Original Message -----
> From: Paul Curtis
> To: l...
> Sent: Monday, April 28, 2008 5:37 PM
> Subject: RE: [lpc2000] Re: How does can you use all functions
> lpc230x.c
>
> Mark,
>
> > I don't think that is correct.
>
> Oh, by jove, is is correct.
>
> > By declaring it as "extern" you are
> > explicitly telling the compiler that storage is allocated
> elsewhere.
>
> Actually, no. You're telling it that it has external linkage.
>
> > What you wrote does not declare a local variable.
>
> Oh, it's not an "auto" variable for sure. However, the declaration of
> x has
> LOCAL SCOPE. You cannot assign to "x" outside the function unless you
> have
> another declaration or a definition.
>
> > If x is not declared elsewhere, the linker will generate an error.
>
> Correct. That's linkage and storage class. It has ZERO, NOTHING, NADA
> to
> do with the scope of a declaration.
>
> --
> Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
> CrossWorks for ARM, MSP430, AVR, MAXQ, and now Cortex-M3 processors
>
> #ygrp-mkp { BORDER-RIGHT: #d8d8d8 1px solid; PADDING-RIGHT:
14px;
> BORDER-TOP: #d8d8d8 1px solid; PADDING-LEFT: 14px; PADDING-BOTTOM: 0px;
> MARGIN: 14px 0px; BORDER-LEFT: #d8d8d8 1px solid; PADDING-TOP: 0px;
> BORDER-BOTTOM: #d8d8d8 1px solid; FONT-FAMILY: Arial}#ygrp-mkp HR {
> BORDER-RIGHT: #d8d8d8 1px solid; BORDER-TOP: #d8d8d8 1px solid;
> BORDER-LEFT: #d8d8d8 1px solid; BORDER-BOTTOM: #d8d8d8 1px solid}#ygrp-
> mkp #hd { FONT-WEIGHT: bold; FONT-SIZE: 85%; MARGIN: 10px 0px; COLOR:
> #628c2a; LINE-HEIGHT: 122%}#ygrp-mkp #ads { MARGIN-BOTTOM:
> 10px}#ygrp-mkp .ad { PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-
> BOTTOM: 0px; PADDING-TOP: 0px}#ygrp-mkp .ad A { COLOR: #0000ff;
TEXT-
> DECORATION: none}
>
> ---------------------------------
> Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try
> it now.
>
>
>
Hi Paul,

Thank you for input, I have changed to

IO0_INT_EN_F |= 0x800;

Still I am not able to get ineterrupt.
And I can see value of IO0_INT_EN_F is 0x800 in memory window.

Thank you & Regards,
Chandrashekhar

"Paul Claessen"
Sent by: l...
04/29/2008 07:08 PM
Please respond to
l...
To

cc

Subject
RE: [lpc2000] Re: How does can you use all functions lpc230x.c

IO0_INT_EN_F &=0x800; //falling edge ?????????????

Should be |= not &=

(Sudden feeling of dvu .. haven?t we seen this code snippet before?)

~ Paul Claessen

From: l... [mailto:l...] On Behalf
Of
Chandrashekhar Kulkarni
Sent: Tuesday, April 29, 2008 8:18 AM
To: l...
Cc: l...
Subject: Re: [lpc2000] Re: How does can you use all functions lpc230x.c

Hi Paul,

Thank you for your reply, I forgot to mention that I already enable fast
gpio:

SCS |= 1;

With this I do not get interrupt.
Is there anything to do with simulator?

Thank you & Regards,
Chandrashekhar

"Paul Claessen" >
Sent by: l...
04/29/2008 05:21 PM
Please respond to
l...

To
>
cc

Subject
Re: [lpc2000] Re: How does can you use all functions lpc230x.c

Since you're using fast gpio, make sire fast gpio's are enabled, by
default they're not!

~ Paul Claessen

----- Original Message -----
From: Chandrashekhar Kulkarni
To: l...
Sent: Tuesday, April 29, 2008 1:44 AM
Subject: Re: [lpc2000] Re: How does can you use all functions lpc230x.c

Hi,

I am trying to generate GPIO interrupt on lpc23xx simulator,
I setup Pin 0.11as a input, I can see signal on P0.11 in KEIL through
Logic Analyzer,

Code snippet is:

PINSEL0 &= 0xFF3FFFFF;
PINMODE0 &= 0xFFBFFFFF;

FIO0DIR1 &= 0xF7; // input direction
IO0_INT_EN_F &=0x800; //falling edge

VICVectAddr17 = (uint32) int_gpio;
VICIntEnable = (1 << 17); // channel 17 shared between GPIO and EINT3
interrupts.

Inside int_gpio, I clear interrupt. I have put breakpoint in int_gpio, it
never come to isr.
And signal are provided through ini file,
I am not sure what exactly I am missing, help is appreciated. Thank you in
advance.

Thank you & Regards,
Chandrashekhar
=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain
confidential or privileged information. If you are
not the intended recipient, any dissemination, use,
review, distribution, printing or copying of the
information contained in this e-mail message
and/or attachments to it are strictly prohibited. If
you have received this communication in error,
please notify us by reply e-mail or telephone and
immediately and permanently delete the message
and any attachments. Thank you





ForwardSourceID:NT000020D2
=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain
confidential or privileged information. If you are
not the intended recipient, any dissemination, use,
review, distribution, printing or copying of the
information contained in this e-mail message
and/or attachments to it are strictly prohibited. If
you have received this communication in error,
please notify us by reply e-mail or telephone and
immediately and permanently delete the message
and any attachments. Thank you






ForwardSourceID:NT0000210E
=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain
confidential or privileged information. If you are
not the intended recipient, any dissemination, use,
review, distribution, printing or copying of the
information contained in this e-mail message
and/or attachments to it are strictly prohibited. If
you have received this communication in error,
please notify us by reply e-mail or telephone and
immediately and permanently delete the message
and any attachments. Thank you



The 2024 Embedded Online Conference