Reply by Ale Avila June 28, 20032003-06-28
To answer the original question...

IAR and MSPGCC do interrupt declarations a little differently.  In IAR it
looks like this:

interrupt[TIMERA0_VECTOR] void Timer_A (void)

For MSPGCC, it should look like this:

interrupt (TIMERA0_VECTOR) Timer_A (void)

The "void" that is was referring to was the void in the interrupt
declaration, not main().   I also had to include <signal.h> so it would
know
what _EINT() was, but somehow you didn't get that error...

I used the following command to compile it (calling the source file
blink-int.c):

msp430-gcc -O2 -mmcu=msp430x1101 -Wall -o blink-int blink-int.c

HTH,
Ale

Ah_Chieh  said:
> i got this demo program and compile it on IAR and MSPGCC.
>
> RESULTS :
> IAR  = no error
>
> MSPGCC > fet1101_ta01.c: In fucntion 'main' :
> fet1101_ta01.c:28: warning: return type of 'main' is not
'int'
> fet1101_ta01.c: At top level:
> fet1101_ta01.c: syntax error before "void"
>
> //*******************************************************************
> //  MSP-FET430X110 Demo - Timer_A Toggle P1.0, CCR0 Contmode ISR,  //
> DCO SMCLK
> //  Description; Toggle P1.0 using using software and TA_0 ISR.
> //  Toggle rate is
> //  set at 50000 DCO/SMCLK cycles. Default DCO frequency used for  //
> TACLK.
> //  Durring the TA_0 ISR P0.1 is toggled and 50000 clock cycles are  //
>  added to
> //  CCR0.  TA_0 ISR is triggered exactly 50000 cycles. CPU is
> //  normally off and
> //  used only durring TA_ISR.
> //  ACLK = n/a, MCLK = SMCLK = TACLK = DCO ~ 800k.
> //
> //           MSP430F1121
> //         ---------------
> //     /|\|            XIN|-
> //      | |               |
> //      --|RST        XOUT|-
> //        |               |
> //        |           P1.0|-->LED
> //
> //  M.Buccini
> //  Texas Instruments, Inc
> //  January 2002
> //  Built with IAR Embedded Workbench Version: 1.25A
>
> #include <msp430x11x1.h>
>
> void main(void)
> {
>  WDTCTL = WDTPW + WDTHOLD;             // Stop WDT
>  TACTL = TASSEL1 + TACLR;              // SMCLK, clear TAR
>  CCTL0 = CCIE;                         // CCR0 interrupt enabled
>  CCR0 = 50000;
>  P1DIR |= 0x01;                        // P1.0 output
>  TACTL |= MC1;                         // Start Timer_A in
> continuous mode
>  _EINT();                              // Enable interrupts
>
>  for (;;)
>  {
>    _BIS_SR(CPUOFF);                    // CPU off
>    _NOP();                             // Required only for C-spy
>  }
> }
>
> // Timer A0 interrupt service routine
> interrupt[TIMERA0_VECTOR] void Timer_A (void)
> {
>  P1OUT ^= 0x01;                        // Toggle P1.0
>  CCR0 += 50000;                        // Add Offset to CCR0
> }
>




Beginning Microcontrollers with the MSP430

Reply by Paul Curtis June 28, 20032003-06-28
Richard,

> At 10:02 AM 6/28/2003 +0100, Paul Curtis
wrote:
> >ISO/ANSI C does define two variants of main().  It's either int 
> >main(int argc, char **argv) or void main(void), and others if 
> >documented by the language translator. ...
> 
> Yup, the former for "normal" C compilers, the latter for use by
these 
> annoying little devices w/o an OS, something about in (the) 
> bed system or 
> something

Yeah, freestanding implementation is how the ISO standard phrases it.

-- Paul.

Reply by onestone June 28, 20032003-06-28
Ah the wonders of a STANDARD EASILY PORTABLE LANGUAGE. Funny how no two
compilers seem to work quite the same way.

;@}

Al

"J.C. Wren" wrote:
> 
>         The actual C language specification does not define main(), as far
as I know.
> This is left up to the compiler designer.  In a C programming running under
> an actual O/S, when it exits, the result can be returned to the operating
> system.  (exit() is not required, although it's standard.  The reality
is
> that you can just return (somevalue), and everyone is happy).
> 
>         In an embedded system, the return result is pointless.  Main()
*should* never
> return, since the main *is* the application.  Most C startup code handles
the
> error of main() returning by jumping into an endless loop.  Whatever the
> case, the return code from main() is pointless.
> 
>         Declaring main() to return an int or a void doesn't matter. 
Just do whatever
> makes the compiler happy.  99.9% of the time, this is the right thing to
do.
> The exception *might* be a multi-tasking OS, where the tasker actually
checks
> what main() returns.  This is very unlikely.
> 
>         Incidently, a little Google research, and a basic reading of the
K&R and GCC
> manual would have told you this.
> 
>         --John
> 
> On Saturday 28 June 2003 01:06 am, Ah_Chieh wrote:
> >  i got this demo program and compile it on IAR and MSPGCC.
> >
> >  RESULTS :
> >  IAR  = no error
> >
> >  MSPGCC > >  fet1101_ta01.c: In fucntion 'main' :
> >  fet1101_ta01.c:28: warning: return type of 'main' is not
'int'
> >  fet1101_ta01.c: At top level:
> >  fet1101_ta01.c: syntax error before "void"
> >
> >  //*******************************************************************
> >  //  MSP-FET430X110 Demo - Timer_A Toggle P1.0, CCR0 Contmode ISR,
> >  //  DCO SMCLK
> >  //  Description; Toggle P1.0 using using software and TA_0 ISR.
> >  //  Toggle rate is
> >  //  set at 50000 DCO/SMCLK cycles. Default DCO frequency used for
> >  //  TACLK.
> >  //  Durring the TA_0 ISR P0.1 is toggled and 50000 clock cycles are
> >  //  added to
> >  //  CCR0.  TA_0 ISR is triggered exactly 50000 cycles. CPU is
> >  //  normally off and
> >  //  used only durring TA_ISR.
> >  //  ACLK = n/a, MCLK = SMCLK = TACLK = DCO ~ 800k.
> >  //
> >  //           MSP430F1121
> >  //         ---------------
> >  //     /|\|            XIN|-
> >  //      | |               |
> >  //      --|RST        XOUT|-
> >  //        |               |
> >  //        |           P1.0|-->LED
> >  //
> >  //  M.Buccini
> >  //  Texas Instruments, Inc
> >  //  January 2002
> >  //  Built with IAR Embedded Workbench Version: 1.25A
> >
> >  #include <msp430x11x1.h>
> >
> >  void main(void)
> >  {
> >    WDTCTL = WDTPW + WDTHOLD;             // Stop WDT
> >    TACTL = TASSEL1 + TACLR;              // SMCLK, clear TAR
> >    CCTL0 = CCIE;                         // CCR0 interrupt enabled
> >    CCR0 = 50000;
> >    P1DIR |= 0x01;                        // P1.0 output
> >    TACTL |= MC1;                         // Start Timer_A in
> >  continuous mode
> >    _EINT();                              // Enable interrupts
> >
> >    for (;;)
> >    {
> >      _BIS_SR(CPUOFF);                    // CPU off
> >      _NOP();                             // Required only for C-spy
> >    }
> >  }
> >
> >  // Timer A0 interrupt service routine
> >  interrupt[TIMERA0_VECTOR] void Timer_A (void)
> >  {
> >    P1OUT ^= 0x01;                        // Toggle P1.0
> >    CCR0 += 50000;                        // Add Offset to CCR0
> >  }
> >
> >
> >
> >
> >
> > Yahoo! Groups Sponsor
> >
> >
> >
> >
> >
> >
> >  .
> >
> >
> >
> >  ">http://docs.yahoo.com/info/terms/

Reply by Richard F. Man June 28, 20032003-06-28
At 10:02 AM 6/28/2003 +0100, Paul Curtis wrote:
>ISO/ANSI C does define two variants of main(). 
It's either int main(int
>argc, char **argv) or void main(void), and others if documented by the
>language translator.
>...

Yup, the former for "normal" C compilers, the latter for use by these 
annoying little devices w/o an OS, something about in (the) bed system or 
something

:-)


// richard <http://www.imagecraft.com> 
<http://www.dragonsgate.net/mailman/listinfo> 


Reply by Paul Curtis June 28, 20032003-06-28
John,

> 	The actual C language specification does not
define 
> main(), as far as I know.  

ISO/ANSI C does define two variants of main().  It's either int main(int
argc, char **argv) or void main(void), and others if documented by the
language translator.

-- Paul.

Reply by J.C. Wren June 28, 20032003-06-28
	The actual C language specification does not define main(), as far as I
know.  
This is left up to the compiler designer.  In a C programming running under 
an actual O/S, when it exits, the result can be returned to the operating 
system.  (exit() is not required, although it's standard.  The reality is 
that you can just return (somevalue), and everyone is happy).

	In an embedded system, the return result is pointless.  Main() *should* never 
return, since the main *is* the application.  Most C startup code handles the 
error of main() returning by jumping into an endless loop.  Whatever the 
case, the return code from main() is pointless.

	Declaring main() to return an int or a void doesn't matter.  Just do
whatever 
makes the compiler happy.  99.9% of the time, this is the right thing to do.  
The exception *might* be a multi-tasking OS, where the tasker actually checks 
what main() returns.  This is very unlikely.

	Incidently, a little Google research, and a basic reading of the K&R and
GCC 
manual would have told you this.

	--John

On Saturday 28 June 2003 01:06 am, Ah_Chieh wrote:
>  i got this demo program and compile it on IAR and MSPGCC.
>
>  RESULTS :
>  IAR  = no error
>
>  MSPGCC >  fet1101_ta01.c: In fucntion 'main' :
>  fet1101_ta01.c:28: warning: return type of 'main' is not
'int'
>  fet1101_ta01.c: At top level:
>  fet1101_ta01.c: syntax error before "void"
>
>  //*******************************************************************
>  //  MSP-FET430X110 Demo - Timer_A Toggle P1.0, CCR0 Contmode ISR,
>  //  DCO SMCLK
>  //  Description; Toggle P1.0 using using software and TA_0 ISR.
>  //  Toggle rate is
>  //  set at 50000 DCO/SMCLK cycles. Default DCO frequency used for
>  //  TACLK.
>  //  Durring the TA_0 ISR P0.1 is toggled and 50000 clock cycles are
>  //  added to
>  //  CCR0.  TA_0 ISR is triggered exactly 50000 cycles. CPU is
>  //  normally off and
>  //  used only durring TA_ISR. 
>  //  ACLK = n/a, MCLK = SMCLK = TACLK = DCO ~ 800k.
>  //
>  //           MSP430F1121
>  //         ---------------
>  //     /|\|            XIN|- 
>  //      | |               |
>  //      --|RST        XOUT|-
>  //        |               |
>  //        |           P1.0|-->LED
>  //
>  //  M.Buccini
>  //  Texas Instruments, Inc
>  //  January 2002
>  //  Built with IAR Embedded Workbench Version: 1.25A
>
>  #include <msp430x11x1.h>
>
>  void main(void)
>  {
>    WDTCTL = WDTPW + WDTHOLD;             // Stop WDT
>    TACTL = TASSEL1 + TACLR;              // SMCLK, clear TAR
>    CCTL0 = CCIE;                         // CCR0 interrupt enabled
>    CCR0 = 50000;
>    P1DIR |= 0x01;                        // P1.0 output
>    TACTL |= MC1;                         // Start Timer_A in
>  continuous mode
>    _EINT();                              // Enable interrupts
>
>    for (;;)                            
>    {
>      _BIS_SR(CPUOFF);                    // CPU off
>      _NOP();                             // Required only for C-spy
>    }
>  }
>
>  // Timer A0 interrupt service routine
>  interrupt[TIMERA0_VECTOR] void Timer_A (void)
>  {
>    P1OUT ^= 0x01;                        // Toggle P1.0
>    CCR0 += 50000;                        // Add Offset to CCR0
>  }
>
>
>
>
>
> Yahoo! Groups Sponsor
>
>
>
>
>
>
>  .
>
>
>
>  


Reply by Robert Reid June 28, 20032003-06-28
Ah_Chieh wrote:

>i got this demo program and compile it on IAR and
MSPGCC.
>
>RESULTS :
>IAR  = no error
>
>MSPGCC >fet1101_ta01.c: In fucntion 'main' :
>fet1101_ta01.c:28: warning: return type of 'main' is not
'int'
>fet1101_ta01.c: At top level:
>fet1101_ta01.c: syntax error before "void" 
>  
>
The first is only a warning, in PC land you would have main returning 0 
for success normlly, doesn't really matter for an embedded processor.  
There may be an option to ignore this warning, or otherwise "int 
main(void)" and then after the infinite for loop "return 0;"

Before the void is #include, so it could be coming from the include 
file?  Is there any difference between the msp430x11x1.h files between 
the two compilers (I've only ever used mspgcc)?

Rob

>//*******************************************************************
>//  MSP-FET430X110 Demo - Timer_A Toggle P1.0, CCR0 Contmode ISR, 
>//  DCO SMCLK
>//  Description; Toggle P1.0 using using software and TA_0 ISR. 
>//  Toggle rate is 
>//  set at 50000 DCO/SMCLK cycles. Default DCO frequency used for 
>//  TACLK. 
>//  Durring the TA_0 ISR P0.1 is toggled and 50000 clock cycles are 
>//  added to 
>//  CCR0.  TA_0 ISR is triggered exactly 50000 cycles. CPU is 
>//  normally off and
>//  used only durring TA_ISR.  
>//  ACLK = n/a, MCLK = SMCLK = TACLK = DCO ~ 800k. 
>//
>//           MSP430F1121
>//         ---------------
>//     /|\|            XIN|-  
>//      | |               |
>//      --|RST        XOUT|-
>//        |               |
>//        |           P1.0|-->LED
>//
>//  M.Buccini
>//  Texas Instruments, Inc
>//  January 2002
>//  Built with IAR Embedded Workbench Version: 1.25A
>
>#include <msp430x11x1.h>
>
>void main(void)
>{ 
>  WDTCTL = WDTPW + WDTHOLD;             // Stop WDT
>  TACTL = TASSEL1 + TACLR;              // SMCLK, clear TAR
>  CCTL0 = CCIE;                         // CCR0 interrupt enabled
>  CCR0 = 50000;
>  P1DIR |= 0x01;                        // P1.0 output
>  TACTL |= MC1;                         // Start Timer_A in 
>continuous mode
>  _EINT();                              // Enable interrupts
> 
>  for (;;)                             
>  {
>    _BIS_SR(CPUOFF);                    // CPU off
>    _NOP();                             // Required only for C-spy
>  }
>}
>
>// Timer A0 interrupt service routine
>interrupt[TIMERA0_VECTOR] void Timer_A (void)
>{
>  P1OUT ^= 0x01;                        // Toggle P1.0
>  CCR0 += 50000;                        // Add Offset to CCR0
>}
>
>
>
>
>.
>
> 
>
>">http://docs.yahoo.com/info/terms/ 
>
>
>  
>



Reply by ale...@... June 28, 20032003-06-28
Hello,

> Is the GCC set to accept C++ style comments ?
> Maybe that's the syntax error before void ?

Yes, GCC accepts // as comments, but what may be happening is the first line
looks like this:

//*******

It may think that /* is the important combination there, so there's a
lonely
'/' at the beginning of the line.  If you put a space between the
second '/'
and the first '*' that may fix the problem:

// *******

> The non-return of a (int) from main warning of
course relates to PCs.
> Which reminds of some review I read on Amazon about Herbert Schildt's
> book "C The complete reference".
>
> Someone there really bagged Herbert Schildt because his main() doesn't
> return an in.
> So ?
> What's the big deal - it's embedded - No OS is presumed to have
called
> main() ?

It does seem pretty silly, but that's how GCC likes it, so I've just
become
accustomed to:

int main()
{
[...]
return 0;
}

But that's just a warning after all.  It wouldn't affect compilation
or
execution of that code.

Other than the comment syntax, I can't see anything else that might be
wrong
with the code.  Unfortunately, I don't have access to my MSPGCC install at
the moment...

HTH,
Ale


> ----- Original Message -----
> From: "Ah_Chieh " <chokobo_k@chok...>
> To: <msp430@msp4...>
> Sent: Saturday, June 28, 2003 3:06 PM
> Subject: [msp430] Re: MSPGCC vs IAR?
>
>
>> i got this demo program and compile it on IAR and MSPGCC.
>>
>> RESULTS :
>> IAR  = no error
>>
>> MSPGCC >> fet1101_ta01.c: In fucntion 'main' :
>> fet1101_ta01.c:28: warning: return type of 'main' is not
'int'
>> fet1101_ta01.c: At top level:
>> fet1101_ta01.c: syntax error before "void"
>
>
> ------------------------ Yahoo! Groups Sponsor
> ---------------------~--> Looking for the latest Free IT White Papers?
> Visit SearchNetworking.com to access over 500 white papers.
> Get instant access at SearchNetworking.com Today
> http://us.click.yahoo.com/maEeOB/OLNGAA/titMAA/CFFolB/TM
> ---------------------------------~->
>
> .
>
>
>
> ">http://docs.yahoo.com/info/terms/




Reply by microbit June 28, 20032003-06-28
Hi,

Is the GCC set to accept C++ style comments ?
Maybe that's the syntax error before void ?

The non-return of a (int) from main warning of course relates to PCs.
Which reminds of some review I read on Amazon about Herbert Schildt's book
"C The complete reference".

Someone there really bagged Herbert Schildt because his main() doesn't
return an in.
So ?
What's the big deal - it's embedded - No OS is presumed to have called
main() ?

Well, every dog has its day I guess.

----- Original Message -----
From: "Ah_Chieh " <chokobo_k@chok...>
To: <msp430@msp4...>
Sent: Saturday, June 28, 2003 3:06 PM
Subject: [msp430] Re: MSPGCC vs IAR?


> i got this demo program and compile it on IAR and
MSPGCC.
>
> RESULTS :
> IAR  = no error
>
> MSPGCC > fet1101_ta01.c: In fucntion 'main' :
> fet1101_ta01.c:28: warning: return type of 'main' is not
'int'
> fet1101_ta01.c: At top level:
> fet1101_ta01.c: syntax error before "void"


Reply by Ah_Chieh June 28, 20032003-06-28
i got this demo program and compile it on IAR and MSPGCC.

RESULTS :
IAR  = no error

MSPGCC fet1101_ta01.c: In fucntion 'main' :
fet1101_ta01.c:28: warning: return type of 'main' is not
'int'
fet1101_ta01.c: At top level:
fet1101_ta01.c: syntax error before "void" 

//*******************************************************************
//  MSP-FET430X110 Demo - Timer_A Toggle P1.0, CCR0 Contmode ISR, 
//  DCO SMCLK
//  Description; Toggle P1.0 using using software and TA_0 ISR. 
//  Toggle rate is 
//  set at 50000 DCO/SMCLK cycles. Default DCO frequency used for 
//  TACLK. 
//  Durring the TA_0 ISR P0.1 is toggled and 50000 clock cycles are 
//  added to 
//  CCR0.  TA_0 ISR is triggered exactly 50000 cycles. CPU is 
//  normally off and
//  used only durring TA_ISR.  
//  ACLK = n/a, MCLK = SMCLK = TACLK = DCO ~ 800k. 
//
//           MSP430F1121
//         ---------------
//     /|\|            XIN|-  
//      | |               |
//      --|RST        XOUT|-
//        |               |
//        |           P1.0|-->LED
//
//  M.Buccini
//  Texas Instruments, Inc
//  January 2002
//  Built with IAR Embedded Workbench Version: 1.25A

#include <msp430x11x1.h>

void main(void)
{ 
  WDTCTL = WDTPW + WDTHOLD;             // Stop WDT
  TACTL = TASSEL1 + TACLR;              // SMCLK, clear TAR
  CCTL0 = CCIE;                         // CCR0 interrupt enabled
  CCR0 = 50000;
  P1DIR |= 0x01;                        // P1.0 output
  TACTL |= MC1;                         // Start Timer_A in 
continuous mode
  _EINT();                              // Enable interrupts
 
  for (;;)                             
  {
    _BIS_SR(CPUOFF);                    // CPU off
    _NOP();                             // Required only for C-spy
  }
}

// Timer A0 interrupt service routine
interrupt[TIMERA0_VECTOR] void Timer_A (void)
{
  P1OUT ^= 0x01;                        // Toggle P1.0
  CCR0 += 50000;                        // Add Offset to CCR0
}