Thread: how to put a check on an extern variable set as flag

  1. #16
    Registered User
    Join Date
    Mar 2009
    Posts
    9
    Hello,

    @matsp, sorry i didnt understand your last post. Beside that i have one confusion or a question and i hope you can answer that. My main concern is that if i ll try to run my routines in main code, without any infinte loop they never work.

    Code:
    /* main file */
    extern USIGN8 RX_TEST;
    extern USIGN8 RX_Receive_Test;
    
    VOID main (VOID)
    
    if(RX_TEST==1) // flag set in sync pin ISR if the receive packet bytes are      corrupted
    {
      perform function a();
      flush RX_Fifo();
      set SYNC pin low();
      blink LED1();
      RX_Test=0;  // set the global variable again to 0;
      
    
    }
    else if (RX_Receive_Test ==1)// flag set in SYNC pin ISR if the packet is complete
    {
      perform function b();
      dispatch_frame_into_another_buffer();
      flush RX_Fifo();
      blink LED2();
      RX_Receive_Test=0;
    }
    But if i ll put this whole code into a while(1), infinte loop i ll see my system working and LED 1 or 2 blinking, further i can stop debugging and verify the contents of the packet. could anyone please guide, do we need some kind of loops to run the system into an interrupt.

    Code:
    extern USIGN8 RX_TEST;
    extern USIGN8 RX_Receive_Test;
    
    VOID main (VOID)
    while(1)
    {
    if(RX_TEST==1) // flag set in sync pin ISR if the receive packet bytes are      corrupted
    {
      perform function a();
      flush RX_Fifo();
      set SYNC pin low();
      blink LED1();
      RX_Test=0;  // set the global variable again to 0;
      
    
    }
    else if (RX_Receive_Test ==1)// flag set in SYNC pin ISR if the packet is complete
    {
      perform function b();
      dispatch_frame_into_another_buffer();
      flush RX_Fifo();
      blink LED2();
      RX_Receive_Test=0;}

  2. #17
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So, my first comment was that you are accessing outside the valid range of your array.

    My second comment was to say that when you (probably) should not just check to see if the counts suggested in my previous post for difference, but actually do a while-loop that goes on until the two values are the same. The key here is to "catch up" if the interrupt function gets ahead of the main process. And of course, for each item received you will need to actually process it, so the processing should go inside the while-loop.

    And as you have discovered, main must have a loop, or call a function that loops. That's normal for this type of program. '

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #18
    Registered User
    Join Date
    Mar 2009
    Posts
    9
    @ mats, could you provide some dummy code example, that how this operation could be acheived in a multi-source file enviorment.

    Best Regards
    RebelSoul

  4. #19
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Well, what you have already looks pretty good - it's just a case of putting the different bits from what you have together with what I have described:
    1. Don't just "set" and "reset" flags - count up in the interrupt code, and count up in the code dealing with the interrupt.
    2. Use a while-loop to make sure that if you run out of phase (two interrupts complete in whilst dealing with one).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. using extern to have a global variable
    By steve1_rm in forum C Programming
    Replies: 3
    Last Post: 01-29-2009, 06:44 AM
  2. recursion error
    By cchallenged in forum C Programming
    Replies: 2
    Last Post: 12-18-2006, 09:15 AM
  3. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  4. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 10:14 PM
  5. My graphics library
    By stupid_mutt in forum C Programming
    Replies: 3
    Last Post: 11-26-2001, 06:05 PM

Tags for this Thread