naked function

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

Okay, I have a interrupt routine that I wish to prevent a prologue/epilogue return.

I've tried using the following:

void compare_irq_handler(void)__attribute__( (naked) );

With the function then:

void compare_irq_handler(void)
{
        Set_sys_compare(NB_CLOCK_CYCLE_DELAY_LONG);
	OSTCBHighRdy = OSTCBHighRdy->tcb_next;
	os_context_sw();
}	

Any suggestions are welcome. Thank you.

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

So… where’s your problem? It doesn’t work? If so, in what way? Are function prologue/epilogue still emitted?

Also I believe you must add the “naked” attribute to the function definition, not to the declaration.

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

tried adding it to the function definition, still no luck. the eilogue is still overwriting my data

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

The epilogue should only restore the registers that were saved and used inside the interrupt routine, then return via reti. If that’s overwriting your data, you’re doing something very wrong.

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

I recall a problem I had a couple years ago using the naked attribute. IIRC, the issue seemed to be that the compiler ignored naked when compiling for debug (-O0). Compiling with higher optimization levels produced the expected results. If you're interested, I can pull that project up when I get back to the office (2 days from now) and post more info after I've refreshed my memory on the details.

Letting the smoke out since 1978

 

 

 

 

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

What does the disassembly say? Does it push/pop and ret? Or does it do as expected, but you have a user error in between? Remember that you must add ret/rete/reti to the end of your function when you go naked ;)

Hans-Christian

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

yes, I do have the RETE (Return from Interrupt) I could write some assembly code to correct it but thats a dirty solution.

digitalDan, I'll have a look at optimisation levels later when I recover from a killer hangover ;)

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

From the Architecture Manual:

Quote:
When a request is accepted, the Status Register and Program Counter of the current context is stored to the system stack. If the event is an INT0, INT1, INT2 or INT3, registers R8 to R12 and LR are also automatically stored to stack. Storing the Status Register ensures that the core is returned to the previous execution mode when the current event handling is completed.

The rete instruction signals the end of the event. When encountered, the Return Status Register and Return Address Register are popped from the system stack and restored to the Status Register and Program Counter. If the rete instruction returns from INT0, INT1, INT2 or INT3, registers R8 to R12 and LR are also popped from the system stack. The restored Status Register contains information allowing the core to resume operation in the previous execution mode.

[Somewhat different for AP7.] If you are using the framework, it handles the rete for you. See exception.s in intc driver.

If you are trying to save the current context, and return to a different one, I'd guess you will need to drop into assembly. There used to be an example of this in the FreeTOS demo files, but I can't seem to find it today.

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

After looking into this I can report the following:
At -O0 and without the naked attribute the prologue consists of saving the SP, modifying the SP to reserve space for the function paramters, and copying the function parameters (from registers) onto the stack (presumably to support debugging).
At -O0 and with the naked attribute, all SP manipulation disappears from the prologue yet the instructions to copy the function parameters (from registers) onto the stack remain. Since space hasn't been reserved on the stack, bad things happen.
At -O1 and higher with the naked attribute, all traces of the prologue disappear and life is good again.

Letting the smoke out since 1978

 

 

 

 

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

Thank you for your time. It's very much appreciated.

Wm.

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

Still having trouble. Here is the code listing, maybe someone could see where I'm going wrong. Thanks for the Help.

I've attached the file. It will be easier for you to look at.

Attachment(s): 

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

MRetzer your quite correct... Any suggestions on how to proceed?

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

There is a lot of good information here: http://support.atmel.no/knowledgebase/avr32studiohelp/AT32UC3B_Software_Framework/SERVICES/FREERTOS/Demo/AVR32_UC3/DOC/html/files.html

[It's up to you to read all the license stuff.]

BTW Thank you, digitalDan. You answered my question.

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

Found the answer, I decided to create a context switch around the ISR for the rest of the system. Then came up with the idea of checking the FreeRTOS and MicroC/OS. Both do the same thing. Nice one, now I can get on with designing the system.

Thanks for the help freaks!