| View previous topic :: View next topic |
| Author |
Message |
Guest
|
|
Posted: Thu Oct 16, 2008 8:05 am |
|
|
Ah ok. Sorry I forgot to post the rest...
| Code: |
void main(void)
{
struct timref_t mainTimRef;
setTimer(10000, &mainTimRef);
// some code
while(1)
{
if(getTimeout(&mainTimRef))
{
setTimer(10000, &mainTimRef);
// some code
}
// some code
}
}
|
The interrupt routine which causes the problem is used for receiving data on the UART and contains the following code:
| Code: |
#INT_RDA
void rda_handler(void)
{
unsetTimer(&rs232TimerRef);
inDataBuffer[BufPtr] = RCREG; // Get received character from receive buffer
BufPtr++;
rs232receiving = 1; // driver is receiving data
setTimer(RS232_TIMEOUT, &rs232TimerRef);
}
|
The Timer in the UART receiving Interrupt is used to detect gaps in the received data stream. As one can see the Interrupt uses an other timer reference (rs232TimerRef) which is declared globally (in order to make it accessible to the interrupt handler and to other functions in the UART module). |
|
 |
Guest
|
|
Posted: Thu Oct 16, 2008 8:08 am |
|
|
| Oh sorry I didn't read your second post Wayne_. I do not deallocate the memory because I don't use dynamic memory. Therefore the mainTimRef should always be valid. |
|
 |
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Thu Oct 16, 2008 8:11 am |
|
|
| And the definition for rs232TimerRef ? |
|
 |
Guest
|
|
Posted: Thu Oct 16, 2008 8:17 am |
|
|
This one is declared globally in the file for the RS232 driver (in the same file the RDA interrupt is implemented).
| Code: |
struct timref_t rs232TimerRef;
|
The pointers in the timers[] array are only used in the interrupt in order to know which timref_t's I have to increment and check for a Timeout. However the timref_t's itself (which actually allocate the memory) remain valid throughout the runtime of the program because they are either declared globally or static (if only used in a function) or in main. |
|
 |
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Thu Oct 16, 2008 8:30 am |
|
|
How big is your inDataBuffer[BufPtr] buffer ?
Is it possible that you recieve too many characters before resetiing it therfore overwriting something else ? |
|
 |
Guest
|
|
Posted: Thu Oct 16, 2008 8:36 am |
|
|
Huh ok this one I forgot to check But it is not the solution to my problem. I quickly fixed it (BufPtr will be reset if bigger than the buffer size) and checked it with my hardware. Still the same behavior... |
|
 |
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Thu Oct 16, 2008 8:40 am |
|
|
This may just be a case of you trying to debug it !
Is your breakpoint in the if statement ? |
|
 |
Guest
|
|
Posted: Thu Oct 16, 2008 8:47 am |
|
|
No I set the breakpoint after the decision on the first statement in the if path. I tried to run the progam without debugging (program the chip and let it run) -> same behavior (checked it with some stupid LED's).
But to come back to the memory locations which are commonly used by the compiler. If the function getTimeout works correct (what is the case in 99% of the calls) the two memory location 8c7 and 8c8 hold the address to mainTimRef. When it fails locations 8c7 and 8c8 hold either the address of rs232TimerRef or a mix between the address of mainTimRef and rs232TimerRef... |
|
 |
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Thu Oct 16, 2008 8:55 am |
|
|
There is a potential problem with setTimer.
It is possible that during setTimer in main the rs232 interrupt occurs and calls setTimer.
Depending on where in the setTimer routine the main call is the rs232 call could use the same timer index as the mainTimRef causing corruption.
I would sort this and see if it fixes your problem. I can see where you may see what you are with this problem.
The only way to stop this I can see is by disabling interrupts during the allocation of the timerindex in the setTimer routine. |
|
 |
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Thu Oct 16, 2008 9:01 am |
|
|
Just a question to anyone who can answer.
If this is true shouldn't the compiler issues a "Disabled interrupts due to re-entrency" warning ? |
|
 |
Guest
|
|
Posted: Thu Oct 16, 2008 9:03 am |
|
|
Well I think this is also not the problem because the compiler states that it disables interrupts during call of setTimer and unsetTimer to prevent reentrancy (sorry I forgot to post that one ). Do you know if there is a directive for the compiler to disable interrupts during the execution of a particular function (i.e. the same thing it does to setTimer and unsetTimer)? |
|
 |
Guest
|
|
Posted: Thu Oct 16, 2008 12:05 pm |
|
|
| Again, Wayne_ thanks for your support. I now passed the problem also to CCS. I will post the answer I get here too. Meanwhile any other suggestions are greatly appreciated. |
|
 |
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Fri Oct 17, 2008 1:50 am |
|
|
| Yes, please let us know the outcome. |
|
 |
Ttelmah Guest
|
|
Posted: Fri Oct 17, 2008 2:15 am |
|
|
I'd say the most likely problem source here, is accessing multi byte values both inside and outside the interrupt.
The compiler automatically disables interrupts around _functions_, that might result in re-entrancy (function calling itself), but does not disable interrupts around multi-byte I/O operations to access values both from inside and outside the interrupt. So (for instance), when I want to access a counter, that is being updated inside an interrupt, I'd use:
| Code: |
int32 mirror_counter;
disable_interrupts(global);
mirror_conter=counter;
enable_interrupts(global);
|
and then use this 'mirror' value for my operations.
Best Wishes |
|
 |
Guest
|
|
Posted: Fri Oct 17, 2008 3:10 am |
|
|
Hi Ttelmah
Thanks for your input. However I think my problem is slightly another one because the passing parameter of the function gets corrupted during the function call and not the variable itself. I will try to use a local variable in my getTimeout to save the passing parameter there but I think that this will not prevent the data corruption... |
|
 |
|