Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
01/08/08 09:47
Read: times


 
#149123 - Some advice
Responding to: ???'s previous message
1. Depending on the compiler you are using, there might be some differences in how pointers are handled. Keil C51, for example, distinguishes between generic and memory-specific pointers, and you usually want to use the latter if you know beforehand that your pointer is only going to point to one type of memory (i.e. code space, xdata space or idata space). This should be explained in detail in the compiler's manual.

2. You are modifying PtrRx in your interrupt service routine, and you are using PtrRx in comparisons in your main loop. This has a chance of causing atomicity issues, which means that the comparison in your main loop may consist of comparing several bytes (if the pointer is longer than 1 byte) that may be interrupted by the ISR. The result is usually undefined and therefore unwanted behavior.

A small example: Suppose you have a 16 bit variable called a_example, which is incremented in an ISR and compared to some value in the main loop.

unsigned int a_example;

int main(void)
{
   ...
   if(a_example == 0x01FF)
   {
      // this should never happen
   }
   ...
}

void some_isr(void)
{
   a_example++;
   if(a_example > 0x0101)
   {
      a_example = 0;
   }
}


a_example should never become 0x01FF in this code, but there is a chance that the comparison in the main loop wil be true if the code first checks the low byte when it is 0xFF, is interrupted by some_isr which increments a_example to 0x0100, and then compares the high byte to 0x01 (which is true).

You will need to analyze your code for potential atomicity problems and deal with them in some way (the most simple, but also the most disruptive way being disabling the interrupts temporarily when dealing with the variable in the main loop).

List of 26 messages in thread
TopicAuthorDate
Serial Problem            01/01/70 00:00      
   Can you post more information ?            01/01/70 00:00      
      more information            01/01/70 00:00      
         Too much information!            01/01/70 00:00      
         Some advice            01/01/70 00:00      
         while loop            01/01/70 00:00      
            Bad indenting trap!            01/01/70 00:00      
               Andu, Andy, how dare you ..            01/01/70 00:00      
            I don't think that's the problem.            01/01/70 00:00      
               you're right            01/01/70 00:00      
                  So, have you got it working yet?            01/01/70 00:00      
                     can't receive the 16 bytes            01/01/70 00:00      
                        Have you dealt with the atomicity issues ?            01/01/70 00:00      
                        Debugging            01/01/70 00:00      
                           details            01/01/70 00:00      
   Misleading comment            01/01/70 00:00      
      I too dislike the placement, even worse it is WRON            01/01/70 00:00      
   RI and TI are not mutually exclusive            01/01/70 00:00      
      ... but this is not a cause it will not work...            01/01/70 00:00      
         Yes...            01/01/70 00:00      
   Here is a sample code that is working ...            01/01/70 00:00      
      ... and here for the right processor            01/01/70 00:00      
         Wheel reinvention is -            01/01/70 00:00      
         I have a doubt about that KEIL code.            01/01/70 00:00      
            The Question is what do you want to loose?            01/01/70 00:00      
               No - I was just wondering the hardware            01/01/70 00:00      

Back to Subject List