We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi! For a few months i started programming with ARM7(CPU:LPC 2138).I have this interrupt driven UART I/O:
void sio_irq (void) __irq { volatile char dummy; volatile char IIR; struct buf_st *p; /*------------------------------------------------ Repeat while there is at least one interrupt source. ------------------------------------------------*/ while (((IIR = U1IIR) & 0x01) == 0) { switch (IIR & 0x0E) { case 0x06: /* Receive Line Status */ dummy = U1LSR; /* Just clear the interrupt source */ break; case 0x04: /* Receive Data Available */ case 0x0C: /* Character Time-Out */ p = &rbuf; if (((p->in - p->out) & ~(RBUF_SIZE-1)) == 0) { p->buf [p->in & (RBUF_SIZE-1)] = U1RBR; p->in++; } break; case 0x02: /* THRE Interrupt */ p = &tbuf; if (p->in != p->out) { U1THR = p->buf [p->out & (TBUF_SIZE-1)]; p->out++; tx_restart = 0; } else { tx_restart = 1; } break; case 0x00: /* Modem Interrupt */ dummy = U1MSR; /* Just clear the interrupt source */ break; default: break; } } VICVectAddr = 0; /* Acknowledge Interrupt */ }
....
int __swi(8) com_putchar (int c); int __SWI_8 (int c) { struct buf_st *p = &tbuf; /*------------------------------------------------ If the buffer is full, return an error value. ------------------------------------------------*/ if (SIO_TBUFLEN >= TBUF_SIZE) return (-1); /*------------------------------------------------ Add the data to the transmit buffer. If the transmit interrupt is disabled, then enable it. ------------------------------------------------*/ if (tx_restart) { tx_restart = 0; U1THR = c; } else { p->buf [p->in & (TBUF_SIZE - 1)] = c; p->in++; } return (0); }
/*------------------------------------------------------------------------------ ------------------------------------------------------------------------------*/
int __swi(9) com_getchar (void); int __SWI_9 (int c) { struct buf_st *p = &rbuf; if (SIO_RBUFLEN == 0) return (-1); return (p->buf [(p->out++) & (RBUF_SIZE - 1)]); }
How can i modify this so that only when a specific character(for example:'#') is given then the interrupt flag is setting? Thank you in advance for any help.
You can't filter what characters the serial port receives. The interrupt will always be taken. Then, you can decide if you want to insert the received character into the receive buffer or not.
If using a RTOS, you don't have to wake up the consumer thread unless the rx interrupt processed a trigger character.
Thanks for the answer.
But i have a question:What is a RTOS?how can i use it? How can i practically make a decision if i want to insert the received character into the received buffer or not? I give some explanation:When a special character(for example '#')has been given,it is the sign that the next characters build an instruction.A the end of this instruction the interrupt flag will be clear. I hope that you understand what i mean.
Best reguards.
It seems that you are misplacing some concepts here. You are talking about 'interrupt' but describe a high-level process.
Interrupts are very low-level. In other words, your UART ISR handler will get executed (i.e., an interrupt will be fired) *EVERY* time a character is received by the UART.
You describe some 'sequence' of characters that your code must respond to. That's OK, but you have to handle the sequence at a higher level.
For example: If you let your UART handler just do the work of receiving the chars and placing them in a circular buffer (or FIFO), and then signaling to the rest of the system that chars are available, then the UART handler is kept simple, generic and small. The signal can be a bit set in a global variable, for example.
Then your main program can check if the signal is set, and analyse the FIFO for the magic chars you want, and get the following chars in the sequence as you wish. Please not that the signal flag has nothing to do with the interrupt flag.
Please look up on the net: FIFO, circular buffer, signal flags, interrupt handler.
Hi! very thanks for answer me. But still have question(please excuse my inexperience)
The signal can be a bit set in a global variable, for example.
How and where can i set this bit?
Please look up on the net: FIFO, circular buffer, signal flags, interrupt handler
i have looked for all that but i didn't find something good for signal flag and circular buffer. plaese when you have some links for me i would be thanksfull to have it.
Best regard
www.google.com/search
Well, as I've just been doing some searching on this, I have these 2 references to hand:
c2.com/.../wiki
www.embedded.com/.../printableArticle.jhtml
but you really need to learn how to use internet search engines effectively!
Thanks for trying to help me.I have found the solution of mein problem.
may God blessed you.