cancel
Showing results for 
Search instead for 
Did you mean: 

how to create interrupt process in main.c

wpj1018
Associate II
Posted on October 09, 2011 at 14:38

Hi:

   STM8S105C6 is used in my project.

   I want to create the interrupt process in main.c, the compiler is cosmic.

   In general, the interrupt function is created in stm8_interrupt_vector.c. So i want move it into the file of main.c.

   Can you tell how to do? thanks!

Best Regards!

Fred

  

#describe-the-goal-not-the-step
4 REPLIES 4
Andrew Neil
Evangelist III
Posted on October 09, 2011 at 20:15

''I want move it into the file of main.c''

Why?

 

 

http://www.catb.org/~esr/faqs/smart-questions.html#goal

wpj1018
Associate II
Posted on October 10, 2011 at 02:51

Hi:

   Aim to put all function into main.c.

Fred

mighel84
Associate II
Posted on October 18, 2011 at 18:48

Warning...

If you need it, it's better using ''extern volatile'' variables in main, accessed by the interrupt.c file.

A much better way is to make a set of ''set_var'' ''get_var'' ''clr_var'' functions in your main and call them from your interrupt.c file.

For example, the timer interrupt will add a second in the RTC.

  • With ''extern volatile'' variable you will have in your interrupt.c:
extern volatile main_time;

void TIMER(void) interrupt

{

main_time++;

}

  • With ''get-set-clr'' functions in main.c file, you will have in your interrupt.c:
#include ''main.h''

void TIMER(void) interrupt

{

u32 time = MAIN_GetTime();

MAIN_SetTime(++time);

}

Use ''inline functions'' if you can.

  • If you need to move that:
  1. Move functions needed from your interrupt.c file to your main.c file,
  2. Add all the #include ''xxx.h'' headers from interrupt.c in main.c
  3. Try it

Andrew Neil
Evangelist III
Posted on October 20, 2011 at 22:26

What constitutes ''better'' depends very much on the particular system requirements & constraints.

Very often, it is important that ISRs are as ''lean and mean'' as possible - so the overhead of calling a function to get the value into a local copy, update the local copy, and then call another function to write it back may be undesirable.

At least consider providing a function to increment the count in a single call...