Looking for explaination of code.

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This bit of code came from "largedemo.c" from the latest WinAVR install. Can someone explain what the two lines after the first void handle_mcucsr(void) do? Or better yet, can someone tell me where to find the information?

/*
 * Read out and reset MCUCSR early during startup.
 */
void handle_mcucsr(void)
  __attribute__((section(".init3")))
  __attribute__((naked));
void handle_mcucsr(void)
{
  mcucsr = MCUCSR;
  MCUCSR = 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Those are GCC attributes - function modifiers which GCC uses to alter the way in which the code is compiled. You can use attributes to specify that a routine is an interrupt (this instructs the compiler to add the ISR prologue/epilogue and other ISR-specific data) as well as specify the memory locaton at which it will be stored and other function details.

The attributes "signal" and "interrupt" are used the most in AVR-GCC - the former specifies an ISR function in which interrupts are disabled, while the latter specifies an ISR in which global interrupts are re-enabled at the beginning of the ISR code.

A list of all the GCC attributes can be found here.

In your code, the first attrbute tells the compiler to locate the routine inside the ".init3" section (run before the main(void) program function) while the "naked" attrbute specifies that the routine should have no prologue or epilogue code (ie no register setup or saving).

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks,

Exactly what I was looking for. I'll be readin' them manuals tonight.

Do you know if there is a no_bugs attribute I can add to the start of my code?

:wink:

S.G.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Do you know if there is a no_bugs attribute I can add to the start of my code?

Sorry, that would conflict with the bugs_exist flag (which is set to 1 and read-only). :D

Regards,
Steve A.

The Board helps those that help themselves.