Skip to main content
wpj1018
Associate
Oct 9, 2011 12:38 PM UTC
Question

how to create interrupt process in main.c

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
    This topic has been closed for replies.

    4 replies

    Andrew Neil
    Super User
    Oct 9, 2011 6:15 PM UTC
    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

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    wpj1018
    wpj1018Author
    Associate
    Oct 10, 2011 12:51 AM UTC
    Posted on October 10, 2011 at 02:51

    Hi:

       Aim to put all function into main.c.

    Fred

    mighel84
    Associate
    Oct 18, 2011 4:48 PM UTC
    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
    Super User
    Oct 20, 2011 8:26 PM UTC
    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...

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.