Exemple #1
0
/*******************************************************************************
* Function Name  : uart_read
* Description    : Read data bytes from the USARTx RxBuffer.
* Input          : - WrPtr: Location where the first byte is to be stored
*                : - Size: Number of bytes to be read
*                : - Uart: Select the USART or the UART peripheral.
* Output         : None
* Return         : Number of bytes read from the UARTx RxBuffer (-1 if the number
*                  of bytes to be read superior to the number of bytes available)
*******************************************************************************/
int uart_read(void *WrPtr, u16 Size, const _Uart_Descriptor *Uart)
{
  u16 i;
  char *ptr;
  int ch;
  int cb;

  //
  if (!(*Uart->Ctrl)) 
    return(-1);
  //
  if((*Uart->Ctrl)->RxCnt>Size)
    cb=Size;
  else
    cb=(*Uart->Ctrl)->RxCnt;
  //
  ptr = (char *)WrPtr;
  //
  for (i = 0 ; i < cb ; i++)
  {
    if ((ch = uart_get_char(Uart)) == -1) 
      break;
    *ptr++ = (char)ch;
  }
  return((int)(i));
}
Exemple #2
0
//----------------------------------------------------------
// process internal logic
void uart0_process(void)
{
  byte i;
  byte sum;
  byte *ptr;

  // pøedává zpravy na odvysílání z paketového do lineárního bufferu
  if (!uart_pac_empty()) {
    // jsou data k odesláni ?
    if ((!uart0_flags.txing) && (!uart0_flags.wait_tx)) {
      // nevysíláme ani neèekáme na odpoveï ?
      // zaèneme vysílat další zprávu
      i = ++uart0_buf_pac_ptr_b;
      ptr = (byte *) &(uart0_buf_pac_tx[uart0_buf_pac_ptr_b]);
      for (i=0; i<9; i++) {
        uart0_buf_tx[i] = *ptr;
        ptr++;
      }
      uart0_buf_tx_ptr = 0;
      uart_send();
    }
  }

  // kontroluje pøijatá data
  if ((!uart0_flags.data_received) && (uart_tx_size() > 8)) {
    // máme alespoò 9 bytù dat a nejsou nezpracovaná data?

    // pøedáme do paketového pøijímacího bufferu
    for(i=0; i<9; i++) {
      uart0_buf_pac_rx.b[i] = uart_get_char();
    }

    // odpovídá kontrolní souèet?
    sum = 0;
    for(i=0; i<8; i++) {
      sum += uart0_buf_pac_rx.b[i];
    }
    if (sum == uart0_buf_pac_rx.b[8]) {
      // souèet v poøádku
      uart0_flags.data_received = TRUE;
      uart0_flags.wait_tx = FALSE; // odpoveï pøišla
     } else {
      uart0_flags.data_receive_error = TRUE;
    }
  }

}
Exemple #3
0
/**
  * @brief  shell 从终端获取一个字节	
  * @param  ch 字节数据的地址				
  * @retval 0 没有数据							
	* 				 1 有数据								
  */
static INT8U shell_get_char(INT8U *ch)
{
	return uart_get_char(ch);
}