USART_RXCIF doesn't turn on upon pressing a key IF you're ALREADY in the USART_RXC interrupt

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is a problem.

Because my program goes like this.

1. Main program is running

2. Someone presses a key and it goes into a buffer. If enter is pressed, an action is executed.

3. If "break" is typed, the break function is called where MCU waits for the user to enter a key

4. Infinite loop happens because the USART_RXCIF flag doesn't turn on!

 

How can I make my main program pause when I say "break", but at the same time listen to USART as I type "dump", "cpu", "insert" and "continue" so when I say "continue" that everything continues?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If a valid character has been received then the USART_RXCIF will be set. If you are inside an interrupt then the main interrupt bit is clear and will not be set until you exit the interrupt.

 

In other words whenever a character has been received you go into an ISR (I hope), stuff the character into the buffer and exit the ISR.

If CR is received you signal the main program about that to take action. Whatever you do DO NOT stay inside an ISR.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you are using RXC interrupts the handler should only really be doing one thing - stuffing them into a FIFO. Let non-interrupt mainline code worry about the actual consumption and processing f the characters in the FIFO.

 

Only in extreme circumstances have the ISR actually "process" the received characters in any way. (sometimes you might want to treat '\r' or '\n' as a "command delimiter" and when seen the ISR may want to alert some foreground process that a "whole sentence" has now been received\accumulated and is read to be processed. (but not in the context of the ISR).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When I exit the ISR, I want to switch context and get into a special infinite loop called MP_deadlock where I have to type "continue" in order to get back to the main context.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are you talking about pre-emptively switching context? (I guess you are if it's in an ISR) so are you creating a full TCB for the interrupted task? If not how else can you restore the context to return to it later (as if nothing ever happened)? This is the basis of what a pre-emptive RTOS is doing except that it only switches context in a timer interrupt. But there'd be a lot to be learned by looking at the implementation notes for FreeRTOS. As you'll see there this is not something that can be achieve in C alone. You need to use Asm to snapshot the entire TCB.