AnsweredAssumed Answered

Troubles at receive more than one character (RTOS-RL-ARM)

Question asked by siqueira.erisson on Mar 2, 2012
Latest reply on Mar 8, 2012 by siqueira.erisson

How to send and receive data using RTOS (RL-ARM) with tasks?
(Without generating an interruption?)
Using this functions below:

TO SEND
/*----------------------------------------------------------------------------
  Write character to Serial Port
 *----------------------------------------------------------------------------*/
int sendchar (int c) {

  if (c == '\n')  {
    while (!(USARTx->SR & USART_FLAG_TXE));
    USARTx->DR = 0x0D;
  }
  while (!(USARTx->SR & USART_FLAG_TXE));
  USARTx->DR = (c & 0x1FF);

  return (c);
}

TO RECEIVE
/*----------------------------------------------------------------------------
 *      Line Editor
 *---------------------------------------------------------------------------*/
void getline (char *line, int n) {
  int  cnt = 0;
  char c;

  do {
    if ((c = getkey ()) == CR)  c = LF;    /* read character                 */
    if (c == BACKSPACE  ||  c == DEL) {    /* process backspace              */
      if (cnt != 0)  {           
        cnt--;                             /* decrement count                */
        line--;                            /* and line pointer               */
        putchar (BACKSPACE);               /* echo backspace                 */
        putchar (' ');
        putchar (BACKSPACE);
      }
    }
    else if (c != CNTLQ && c != CNTLS) {   /* ignore Control S/Q             */
      putchar (*line = c);                 /* echo and store character       */
      line++;                              /* increment line pointer         */
      cnt++;                               /* and count                      */
    }
  } while (cnt < n - 1  &&  c != LF);      /* check limit and line feed      */
  *(line - 1) = 0;                         /* mark end of string             */
}

Outcomes