Software Interrupt/Exception

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

Anyone have example code of generating a software interrupt/exception.

Thanks

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

I have lots of example code for doing that, but not for the chip that you haven't told us you are using. :)

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

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

UC3 EVK1104. If you have a good example could you pm me with it. Thanks from Ireland.

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

Sorry, I did say that I don't have code for AVR 32. I was hoping that you would benefit by posting the chip you are using and getting help from others.

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

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

Okay then, is there away for me to cause this interrupt to occur by setting a register flag (what register).

__attribute__((naked))void compare_irq_handler(void)
{
	Set_sys_compare(NB_CLOCK_CYCLE_DELAY_LONG);
	}	
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Perhaps telling us what it is exactly that you are trying to accomplish/do with this will get you more responses. I'm just a messenger, I do not have experience with AVR32.

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

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

I have the compare interrupt and I want to be able to fire the interrupt from software...

I'm sure there is a register somewhere that I can set a bit causing the interrupt to occur but I'm new to the UC3...

Any help is more than welcome.

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

Hi, if you are using AVR studio6 (or 5 i thing) you can easily use one of the exemple for the device you want to use.

File -> new -> Exemple project from ASF

then you can chose the exemple for your board and UC3A chip.

So to use the interrupt, you need 2 things.

1) You need to register a interrupt handler to the interrupt register with the function :

INTC_register_interrupt("adress of function" , "interrupt vector" , "interrup priority")

Exemple for twi:

//Function to handle twi interrupt
extern void global_twi_interrupt_handler();

void init_twi()
{
 //...

INTC_register_interrupt(&global_twi_interrupt_handler, AVR32_TWIM0_IRQ, AVR32_INTC_INT2);
 
 //..
}

2) You need to set the corresponding bit in the Interrupt Enable Register of your device. You can use the already coded MASK

Once again an exemple for twi :

AVR_TWI.ier = 
AVR32_TWI_IER_NACK_MASK   | //
AVR32_TWI_IER_OVRE_MASK   | // 
AVR32_TWI_IER_ARBLST_MASK | //			      AVR32_TWI_IER_TXRDY_MASK; 

Guillaume Charland

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

I have the interrupt set up and working, what I need to do is find away to trigger that interrupt from within the software.

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

Did you try:
#define Set_sys_count(x ) ( Set_system_register(AVR32_COUNT, (x)) )
?
check out:
cycle_counter.h and cycle_counter_example.c for details

-sb

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

Thanks, I'll try it in the morning.

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

Tried that, it does not work. I think your missing my point, I've setup the interupt and it works perfectly. What I want to is find away of manually causing the interrupt from within my code..

I'm preety sure all that is required is a system register bit needs set.

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

What does the datasheet say?

I know that on the regular AVR some interrupt sources can be triggered by software, but this is more by mere accident than by actual design.

You could call the ISR directly, and simulate what's pushed onto the stack when an actual hardware interrupt occurs and execution is transferred to the ISR by pushing that register on the stack before the call.

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

jayjay, your quite correct, but when I optimise at level 3 I have no way of knowing the PC address to return to. If I can cause an interupt at level 3 naked then it pushes the PC for me

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

You should call the ISR, not jump into it. A call instruction also pushes the PC. The only difference usually between a normal function and an ISR is that the latter ends with a special return instruction, like the AVR8 RETI instruction instead of the regular RET instruction. Though on the AVR8 the only difference is the latter reenables interrupts.

I don't know how this works on the AVR32, it might automatically store the status register for example when it vectors to an ISR, something a regular CALL would not do.

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

jayjay, I'll give it a blast..

thanks for your time and effort

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

nah, never worked. When I used the AVR 128 I could simply set a bit in the interrupt register and cause a hardware interupt. I believe it is the same with the AVR32 however I have no idea where the register is. I'll go looking for the documents.

Thanks for the suggestions jayjay.

I might offer a AP7002 dev. board for the person who finds this register....

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

Fianawarrior wrote:
When I used the AVR 128 I could simply set a bit in the interrupt register and cause a hardware interupt. I believe it is the same with the AVR32 however I have no idea where the register is. I'll go looking for the documents.
Interrupt autovectors (one for each group) are set into the IPRX (IPR0, IPR1, IPR2 etc.) registers within the Interrupt controller module (INTC). These offsets are related to EVBA (exception vector base address), which is one of the system registers (find "system registers" table from your datasheet). To enable the interrupts you have to set GM bit in the status register. Again one of the system registers.

AVR32 headers defines these registers as AVR32_EVBA and AVR32_SR, respectively. In C you can access these registers with __builtin_mtsr/mfsr() functions.

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

I think he wants to create some kind of software-triggered interrupt.

Have you considered using a TC that just counts to 1 at high speed? It can be started via a software trigger, counts to 1 and then runs your interrupt handler?

If you’re still trying to create OS tasks in interrupt context, I still think you’re doing it wrong.

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

catweax wrote:
I think he wants to create some kind of software-triggered interrupt.
The thread started with the software-triggered interrupts, but the latest post was about hardware-triggered interrupts. I don't know which one he's after. It might be a good idea to clarify it at this point ;)

catweax wrote:
Have you considered using a TC that just counts to 1 at high speed? It can be started via a software trigger, counts to 1 and then runs your interrupt handler?
Most likely I'm missing something here. How TC knows about this handler? :roll:

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

Still no joy with this. been looking now for 3 days. Might kill myself.

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

Okay, let me clarify, I have a working timer compare interrupt thats great and it works. However, I also need to trigger the interrupt from software. I cannot call it from software has the stack epilogue is different.

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

kblomqvist wrote:
catweax wrote:
Have you considered using a TC that just counts to 1 at high speed? It can be started via a software trigger, counts to 1 and then runs your interrupt handler?
Most likely I'm missing something here. How TC knows about this handler? :roll:
Use the ASF INTC functions to register your handler for the TC interrupt. That way the handler will be called when the TC raises its interrupt line.
Fianawarrior wrote:
Okay, let me clarify, I have a working timer compare interrupt thats great and it works. However, I also need to trigger the interrupt from software. I cannot call it from software has the stack epilogue is different.
Use the Timer/Counter module instead of the systimer. The systimer always runs and you can only reset it to 0, I think. If you use a Timer/Counter, you can use its software trigger by writing a one to the SWTRG bit in the CCRn register and then it’ll start counting.

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

Let the ISR call a separate function where the real work is done. Want a 'software interrupt', just call that separate function.

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

What I was trying to do was use the epilogue of the ISR call has part of a context switch. The reason being is that across all priority levels it remained the same. I think I've found away around it, however I'll need more testig before I can consider it working before moving on with my project.

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

you might have a look into asf/thirdparty/freertos/source/portable/gcc/avr32_uc3/portmacro.h

but take care about the license, they are not happy if somebody uses their code
to invent a new os, maybe for academic usage it's ok, I assume you wan't to publish your work anyway ...

-sb

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

Yes, I do intend to publish my work, basically it it a 3 phase modulation unit.

It has hard and soft timing characteristics and I need to be able to do a lot of FFT processing between gathering data from the power grid...

Maybe if I have the CPU resourses I'll implement a embedded tcp/ip comms