lpcware

interrupt handling in freertos

Discussion created by lpcware Employee on Jun 15, 2016
Content originally posted in LPCWare by lukkezeh on Thu Apr 01 10:24:30 MST 2010
Hello all,

I have got a problem with my usart interrupt. I think my usart interrupt is being stopped by the systick. Could someone look to my code and telling me what i am doing wrong?


The task:


[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2][B]vUserTask3[/B]([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] *pvParameters) {[/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]while[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (1) {[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ( UARTCount != 0 )[/SIZE][/LEFT]
[SIZE=2]{[/SIZE]
[LEFT][SIZE=2]LPC_UART->[/LEFT]
[/LEFT]
[/SIZE][LEFT][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]IER[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = IER_THRE | IER_RLS; [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]/* Disable RBR */[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f5f]
[/COLOR][/SIZE][SIZE=2]UARTSend( ([/SIZE][SIZE=2][COLOR=#005032][SIZE=2][COLOR=#005032]uint8_t[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] *)UARTBuffer, UARTCount );[/SIZE]
[LEFT][SIZE=2][SIZE=2]}[/SIZE]
[SIZE=2]LPC_UART->[/LEFT]
[/LEFT]
[/SIZE][LEFT][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]IER[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = IER_THRE | IER_RLS | IER_RBR; [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]/* Re-enable RBR */[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f5f]
[LEFT][/COLOR][/SIZE][SIZE=2]}[/SIZE]
[SIZE=2]}[/SIZE][/LEFT]
[SIZE=2]}[/SIZE]
[/SIZE]



[LEFT]usart.h[/LEFT]

[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] [B]UART_IRQHandler[/B]([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]) [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]__attribute__[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]((interrupt(IRQ)));[/SIZE][/LEFT]


[LEFT]usart.c[/LEFT]


[LEFT][SIZE=2][COLOR=#7f0055][B][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/B][/LEFT]


[/COLOR][/SIZE][LEFT][SIZE=2][B]UART_IRQHandler[/B]([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2])[/SIZE][/LEFT]




[SIZE=2][LEFT]{[/SIZE][/LEFT]


[LEFT][SIZE=2][COLOR=#005032][SIZE=2][COLOR=#005032]uint8_t[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] IIRValue, LSRValue;[/SIZE][/LEFT]




[LEFT][SIZE=2][COLOR=#005032][SIZE=2][COLOR=#005032]uint8_t[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Dummy = Dummy;[/SIZE][/LEFT]





[SIZE=2][LEFT]IIRValue = LPC_UART->[/SIZE]


[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]IIR[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE][/LEFT]





[SIZE=2][LEFT]IIRValue >>= 1; [/SIZE]


[SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]/* skip pending bit in IIR */[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]




[SIZE=2][LEFT]IIRValue &= 0x07; [/SIZE]


[SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]/* check bit 1~3, interrupt identification */[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]




[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (IIRValue == IIR_RLS) [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]/* Receive Line Status */[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]




[SIZE=2][LEFT]{[/SIZE][/LEFT]




[SIZE=2][LEFT]LSRValue = LPC_UART->[/SIZE]


[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LSR[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE][/LEFT]




[LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]/* Receive Line Status */[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]




[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (LSRValue & (LSR_OE | LSR_PE | LSR_FE | LSR_RXFE | LSR_BI))[/SIZE][/LEFT]




[SIZE=2][LEFT]{[/SIZE][/LEFT]




[LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]/* There are errors or break interrupt */[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]




[LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]/* Read LSR will clear the interrupt */[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]




[SIZE=2][LEFT]UARTStatus = LSRValue;[/SIZE][/LEFT]




[SIZE=2][LEFT]Dummy = LPC_UART->[/SIZE]


[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]RBR[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]; [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]/* Dummy read on RX to clear [/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]




[SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f][LEFT]interrupt, then bail out */[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]
[SIZE=2][COLOR=#3f7f5f]



[/COLOR][/SIZE][LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]return[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2];[/SIZE][/LEFT]




[SIZE=2][LEFT]}[/SIZE][/LEFT]




[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (LSRValue & LSR_RDR) [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]/* Receive Data Ready */[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]




[SIZE=2][LEFT]{[/SIZE][/LEFT]




[LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]/* If no error on RLS, normal ready, save into the data buffer. */[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]




[LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]/* Note: read RBR will clear the interrupt */[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]




[SIZE=2][LEFT]UARTBuffer[UARTCount++] = LPC_UART->[/SIZE]


[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]RBR[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE][/LEFT]




[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (UARTCount == BUFSIZE)[/SIZE][/LEFT]




[SIZE=2][LEFT]{[/SIZE][/LEFT]




[SIZE=2][LEFT]UARTCount = 0; [/SIZE]


[SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]/* buffer overflow */[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]




[SIZE=2][LEFT]} [/SIZE][/LEFT]




[SIZE=2][LEFT]}[/SIZE][/LEFT]




[SIZE=2][LEFT]}[/SIZE][/LEFT]




[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]else[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (IIRValue == IIR_RDA) [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]/* Receive Data Available */[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]




[SIZE=2][LEFT]{[/SIZE][/LEFT]




[LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]/* Receive Data Available */[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]




[SIZE=2][LEFT]UARTBuffer[UARTCount++] = LPC_UART->[/SIZE]


[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]RBR[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE][/LEFT]




[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (UARTCount == BUFSIZE)[/SIZE][/LEFT]




[SIZE=2][LEFT]{[/SIZE][/LEFT]




[SIZE=2][LEFT]UARTCount = 0; [/SIZE]


[SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]/* buffer overflow */[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]




[SIZE=2][LEFT]}[/SIZE][/LEFT]




[SIZE=2][LEFT]}[/SIZE][/LEFT]




[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]else[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (IIRValue == IIR_CTI) [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]/* Character timeout indicator */[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]




[SIZE=2][LEFT]{[/SIZE][/LEFT]




[LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]/* Character Time-out indicator */[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]




[SIZE=2][LEFT]UARTStatus |= 0x100; [/SIZE]


[SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]/* Bit 9 as the CTI error */[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]




[SIZE=2][LEFT]}[/SIZE][/LEFT]




[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]else[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (IIRValue == IIR_THRE) [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]/* THRE, transmit holding register empty */[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]




[SIZE=2][LEFT]{[/SIZE][/LEFT]




[LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]/* THRE interrupt */[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]




[SIZE=2][LEFT]LSRValue = LPC_UART->[/SIZE]


[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LSR[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]; [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]/* Check status in the LSR to see if[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]




[SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f][LEFT]valid data in U0THR or not */[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]
[SIZE=2][COLOR=#3f7f5f]



[/COLOR][/SIZE][LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (LSRValue & LSR_THRE)[/SIZE][/LEFT]




[SIZE=2][LEFT]{[/SIZE][/LEFT]




[SIZE=2][LEFT]UARTTxEmpty = 1;[/SIZE][/LEFT]




[SIZE=2][LEFT]}[/SIZE][/LEFT]




[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]else[/COLOR][/SIZE][/COLOR][/SIZE][/B][/LEFT]




[SIZE=2][LEFT]{[/SIZE][/LEFT]




[SIZE=2][LEFT]UARTTxEmpty = 0;[/SIZE][/LEFT]




[SIZE=2][LEFT]}[/SIZE][/LEFT]




[SIZE=2][LEFT]}[/SIZE] [/LEFT]


[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]return[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2];[/SIZE][/LEFT]



[LEFT][SIZE=2]}[/SIZE][/LEFT]




[/LEFT]

Outcomes