[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [avr-gcc-list] Is this a Stack problem?
From: |
Brian Cuthie |
Subject: |
RE: [avr-gcc-list] Is this a Stack problem? |
Date: |
Tue, 20 Jan 2004 10:18:30 -0500 |
Basically, you need to read the Atmel data sheet very carefully. But your
interrupt handler will look something like this (in pseudo code):
// transmitter interrupt
// BTW, we're not interested in the TXC interrupt.
UDRE_Interrupt() {
IntProlog(); // you really need this
if (xmitbuffer count > 0) {
UDR = *(xmitbuffer pointer) // this clears the interrupt
increment xmitbuffer pointer
decrement xmitbuffer count
}
else {
disable interrupt by writing UDRIE to 0
notify outer (non-interrupt) task that send is complete
}
Epilog();
}
// receiver interrupt
RXC_Interrupt() {
IntProlog(); // don't ever forget this!
if (recvbuffer size > 0) {
*(recvbuffer pointer) = UDR
increment recvbuffer pointer
decrement recvbuffer size
}
if (recvbuffer <= 0) {
disable receiver interrupt by writing 0 to RXCIE
notify outer (non-interrupt) task that receive is complete
}
Epilog();
}
I typically use AvrXIntSetSemaphore to notify the task that started the I/O
that it's compelete.
I doubt the interrupt is getting enabled inside his interrupt handler. But I
suspsect that he's not clearing the interrupt in some cases.
-brian
> -----Original Message-----
> From: address@hidden
> [mailto:address@hidden On Behalf Of Lorne Gutz
> Sent: Tuesday, January 20, 2004 9:42 AM
> To: Eric Fu; address@hidden
> Subject: Re: [avr-gcc-list] Is this a Stack problem?
>
> If you check you will find that there are 2 interrupts
> involved with the UART transmitt.
> Basicly you must use one to enable the other when the UART is
> ready to except another character.
> From what you have stated below I believe that your code has
> rammed 11 characters into the UART before anything
> ever gets sent. You could easly have a stack overflow if
> your code is reenterand, and interrupt gets enabled inside your ISR.
>
> cheers
> Lorne
>
>
>
> On Monday 19 January 2004 16:41, Eric Fu wrote:
> > Hi All,
> >
> > I'm writing a test code to implement a SW half duplex
> interrupt UART
> > with
> > ATmega16 / STK500. The code passes the compiler (modified from a
> > successful HW UART code). However, it doesn't work. It couldn't
> > transmit anything, nothing happens at the transmit pin. The
> degugging
> > I did shows the
> > following: a.. The timer interrupt routine has been entered
> 22 times
> > before it stops. And it is repeatable. Note: the timer period is
> > defined same as bit rate. It supposed to transmit 11 ASCII code,
> > equivalent to 220 timer interrupt entries. b.. If I run the
> Simulator
> > in AVR Studio 4.08 in step mode, it could transmit the all the 11
> > characters, at least this is what I saw in the Simulator, and the
> > transmit pin behaves as expected (in the
> > Simulator) c.. If I run in continuos mode with a breakpoint set
> > immediately after the 11 characters, it took 28 Secs to complete,
> > however, it seems it does it connectedly. As I don't have a
> emulator
> > at the moment, it is hard for me to find the fault.
> >
> > Could it be Stack problem? If it is, how to fix it?
> > The compile message for code size is
> >
> > Size after:
> > RF001.elf :
> > section size addr
> > .text 1622 0
> > .data 12 8388704
> > .bss 137 8388716
> > .noinit 0 8388853
> > .eeprom 0 8454144
> > .stab 7212 0
> > .stabstr 3158 0
> > Total 12141
> >
> > I'm not sure what stab and stabstr are. Are they supposed
> to be like that?
> >
> > Thanks
> >
> > Eric Fu
> >
> > _______________________________________________
> > avr-gcc-list mailing list
> > address@hidden
> > http://www.avr1.org/mailman/listinfo/avr-gcc-list
>
>
> _______________________________________________
> avr-gcc-list mailing list
> address@hidden
> http://www.avr1.org/mailman/listinfo/avr-gcc-list
>