예제 #1
0
파일: uart_config.c 프로젝트: oter/BSPTools
	//*****************************************************************************
	//
	//! GETChar
	//!
	//!  \param  ucBuffer to which Command will be populated
	//!
	//!  \return Success or Failure
	//!
	//!  \brief   Get the char string from UART
	//
	//*****************************************************************************
	unsigned int GETChar(unsigned char *ucBuffer)
	{

		int i = 0;
		char c;
		uiUartline = 0;

			    //
			    // Wait to receive a character over UART
			    //
		while (MAP_UARTCharsAvail(CONSOLE) == false)
		{
			osi_Sleep(1);
		}
		c = MAP_UARTCharGetNonBlocking(CONSOLE);

		MAP_UARTCharPut(CONSOLE, c);
		ilength = 0;
		//
		// Checking the end of line
		//
		while (c != '\r' && c != '\n')
		{
			uiUartline = 1;
			//
			// Copying Data from UART into a buffer
			//
			if (c != '\b')
			{
				ilength++;
				*(ucBuffer + i) = c;
				i++;
			}
			//
			// Deleting last character when you hit backspace
			//
			if (c == '\b')
			{
				i--;
				ilength--;
			}
			while (MAP_UARTCharsAvail(CONSOLE) == false)
			{
				osi_Sleep(1);
			}
			c = MAP_UARTCharGetNonBlocking(CONSOLE);
			MAP_UARTCharPut(CONSOLE, c);
		}

		strncpy((char*)g_ucUARTBuffer, (char *)ucBuffer, ilength);
		memset(g_ucUARTRecvBuffer, 0, sizeof(g_ucUARTRecvBuffer));

		return uiUartline;
	}
예제 #2
0
static int cc32xx_uart_rx_bytes(uint32_t base, struct cs_rbuf *rxb) {
  int num_recd = 0;
  while (rxb->avail > 0 && MAP_UARTCharsAvail(base)) {
    uint32_t chf = HWREG(base + UART_O_DR);
    /* Note: There are error flags here, we may be interested in those. */
    cs_rbuf_append_one(rxb, (uint8_t) chf);
    num_recd++;
  }
  return num_recd;
}
예제 #3
0
파일: serial.c 프로젝트: comrid1987/jb3500
void rt_hw_uart_isr(struct rt_lm3s_serial* serial)
{
    rt_device_t device;
    rt_uint32_t status;

    device = (struct rt_device*)serial;
    status = MAP_UARTIntStatus(serial->hw_base, true);

    /* clear interrupt status */
    MAP_UARTIntClear(serial->hw_base, status);

    if (device->flag & RT_DEVICE_FLAG_INT_RX)
    {
        char ch;
		rt_base_t level;

        while (MAP_UARTCharsAvail(serial->hw_base))
        {
            ch = MAP_UARTCharGetNonBlocking(serial->hw_base);

            /* disable interrupt */
			level = rt_hw_interrupt_disable();

			/* read character */
			serial->rx_buffer[serial->save_index] = ch;
			serial->save_index ++;
			if (serial->save_index >= RT_UART_RX_BUFFER_SIZE)
				serial->save_index = 0;

			/* if the next position is read index, discard this 'read char' */
			if (serial->save_index == serial->read_index)
			{
				serial->read_index ++;
				if (serial->read_index >= RT_UART_RX_BUFFER_SIZE)
					serial->read_index = 0;
			}

			/* enable interrupt */
			rt_hw_interrupt_enable(level);
        }

		/* invoke callback */
		if(device->rx_indicate != RT_NULL)
		{
		    rt_int32_t length;

		    length = serial->save_index - serial->read_index;
		    if (length < 0) length += RT_UART_RX_BUFFER_SIZE;
            device->rx_indicate(device, length);
		}
    }
}
예제 #4
0
void UARTIntHandler()
{
  u32 temp;
  int c;

  temp = MAP_UARTIntStatus(uart_base[ CON_UART_ID ], true);
  MAP_UARTIntClear(uart_base[ CON_UART_ID ], temp);
  while( MAP_UARTCharsAvail( uart_base[ CON_UART_ID ] ) )
  {
    c = MAP_UARTCharGetNonBlocking( uart_base[ CON_UART_ID ] );
    buf_write( BUF_ID_UART, CON_UART_ID, ( t_buf_data* )&c );
  }
}
예제 #5
0
파일: esp8266.cpp 프로젝트: anol/justscale
//--------------------------------
void esp8266::OnReceive() {
	while (MAP_UARTCharsAvail(UART_BASE)) {
		// Read a character
		char cSymb = (0xFF & MAP_UARTCharGetNonBlocking(UART_BASE));
		if ('\n' == cSymb) {
			m_nRxEndOfLine++;
		}
		if (m_nRxHead != ((m_nRxFill + 1) % InputBufferSize)) {
			// Store the new character in the receive buffer
			m_nRxFill = ((m_nRxFill + 1) % InputBufferSize);
			m_cInput[m_nRxFill] = cSymb;
		}
	}
}
예제 #6
0
void HardwareSerial::UARTIntHandler(void)
{
	unsigned long ulInts;
	long lChar;

	/* Get and clear the current interrupt source(s) */
	ulInts = MAP_UARTIntStatus(UART_BASE, true);
	MAP_UARTIntClear(UART_BASE, ulInts);

	/* Are we being interrupted because the TX FIFO has space available? */
	if(ulInts & UART_INT_TX) {
		/* Move as many bytes as we can into the transmit FIFO. */
		primeTransmit(UART_BASE);

		/* If the output buffer is empty, turn off the transmit interrupt. */
		if(TX_BUFFER_EMPTY) {
			MAP_UARTIntDisable(UART_BASE, UART_INT_TX);
		}
	}

	if(ulInts & (UART_INT_RT | UART_INT_TX)) {
		while(MAP_UARTCharsAvail(UART_BASE)) {
			/* Read a character */
			lChar = MAP_UARTCharGetNonBlocking(UART_BASE);

			/* If there is space in the receive buffer, put the character
			 * there, otherwise throw it away. */
			uint8_t volatile full = RX_BUFFER_FULL;
			if(full) break;

			rxBuffer[rxWriteIndex] = (unsigned char)(lChar & 0xFF);
			rxWriteIndex = ((rxWriteIndex) + 1) % rxBufferSize;

			/* If we wrote anything to the transmit buffer, make sure it actually
			 * gets transmitted. */
		}

		primeTransmit(UART_BASE);
		MAP_UARTIntEnable(UART_BASE, UART_INT_TX);
	}
}
예제 #7
0
void mgos_uart_hal_dispatch_rx_top(struct mgos_uart_state *us) {
  bool recd;
  struct cc32xx_uart_state *ds = (struct cc32xx_uart_state *) us->dev_data;
  cs_rbuf_t *irxb = &ds->isr_rx_buf;
  MAP_UARTIntDisable(ds->base, UART_RX_INTS);
recv_more:
  recd = false;
  cc32xx_uart_rx_bytes(ds->base, irxb);
  while (irxb->used > 0 && mgos_uart_rxb_free(us) > 0) {
    int num_recd = 0;
    do {
      uint8_t *data;
      int num_to_get = MIN(mgos_uart_rxb_free(us), irxb->used);
      num_recd = cs_rbuf_get(irxb, num_to_get, &data);
      mbuf_append(&us->rx_buf, data, num_recd);
      cs_rbuf_consume(irxb, num_recd);
      us->stats.rx_bytes += num_recd;
      if (num_recd > 0) recd = true;
      cc32xx_uart_rx_bytes(ds->base, irxb);
    } while (num_recd > 0);
  }
  /* If we received something during this cycle and there is buffer space
   * available, "linger" for some more, maybe there's more to come. */
  if (recd && mgos_uart_rxb_free(us) > 0 && us->cfg.rx_linger_micros > 0) {
    /* Magic constants below are tweaked so that the loop takes at most the
     * configured number of microseconds. */
    int ctr = us->cfg.rx_linger_micros * 31 / 12;
    // HWREG(GPIOA1_BASE + GPIO_O_GPIO_DATA + 8) = 0xFF; /* Pin 64 */
    while (ctr-- > 0) {
      if (MAP_UARTCharsAvail(ds->base)) {
        us->stats.rx_linger_conts++;
        goto recv_more;
      }
    }
    // HWREG(GPIOA1_BASE + GPIO_O_GPIO_DATA + 8) = 0; /* Pin 64 */
  }
  MAP_UARTIntClear(ds->base, UART_RX_INTS);
}
static void uart_common_rx_handler( int resnum )
{
  MAP_UARTIntClear( uart_base[ resnum ], uart_int_mask );
  while( MAP_UARTCharsAvail( uart_base[ resnum ] ) )  
    cmn_int_handler( INT_UART_RX, resnum );  
}
예제 #9
0
bool uart_rx_any(pyb_uart_obj_t *self) {
    return (self->read_buf_tail != self->read_buf_head || MAP_UARTCharsAvail(self->reg));
}
예제 #10
0
파일: uart_if.c 프로젝트: greatlevi/TI3200
//*****************************************************************************
//
//! Get the Command string from UART
//!
//! \param  pucBuffer is the command store to which command will be populated
//! \param  ucBufLen is the length of buffer store available
//!
//! \return Length of the bytes received. -1 if buffer length exceeded.
//! 
//*****************************************************************************
int
GetCmd(char *pcBuffer, unsigned int uiBufLen)
{
    char cChar;
    int iLen = 0;
    
    //
    // Wait to receive a character over UART
    //
    while(MAP_UARTCharsAvail(CONSOLE) == false)
    {
#if defined(USE_FREERTOS) || defined(USE_TI_RTOS)
    	osi_Sleep(1);
#endif
    }
    cChar = MAP_UARTCharGetNonBlocking(CONSOLE);
    
    //
    // Echo the received character
    //
    MAP_UARTCharPut(CONSOLE, cChar);
    iLen = 0;
    
    //
    // Checking the end of Command
    //
    while((cChar != '\r') && (cChar !='\n') )
    {
        //
        // Handling overflow of buffer
        //
        if(iLen >= uiBufLen)
        {
            return -1;
        }
        
        //
        // Copying Data from UART into a buffer
        //
        if(cChar != '\b')
        { 
            *(pcBuffer + iLen) = cChar;
            iLen++;
        }
        else
        {
            //
            // Deleting last character when you hit backspace 
            //
            if(iLen)
            {
                iLen--;
            }
        }
        //
        // Wait to receive a character over UART
        //
        while(MAP_UARTCharsAvail(CONSOLE) == false)
        {
#if defined(USE_FREERTOS) || defined(USE_TI_RTOS)
        	osi_Sleep(1);
#endif
        }
        cChar = MAP_UARTCharGetNonBlocking(CONSOLE);
        //
        // Echo the received character
        //
        MAP_UARTCharPut(CONSOLE, cChar);
    }

    *(pcBuffer + iLen) = '\0';

    Report("\n\r");

    return iLen;
}
예제 #11
0
파일: gps.c 프로젝트: tuzhikov/SURD
//------------------------------------------------------------------------------
//new
void uart0_int_handler()
{
    unsigned long const ist = MAP_UARTIntStatus(UART_BASE, TRUE);

    if (ist & (UART_INT_RX | UART_INT_RT))
    {
        MAP_UARTIntClear(UART_BASE, UART_INT_RX|UART_INT_RT);
        long  b;
      while(MAP_UARTCharsAvail(UART_BASE))
      {
        b = MAP_UARTCharGetNonBlocking(UART_BASE);
        if (b == -1 || (char)b == '$' || g_rx_buf_len >= UART_BUF_SZ)
        {
            g_rx_buf_len = 0;
            g_rx_buf[g_rx_buf_len++] = b;
        }else
        {
            if (b == 0x0D && g_rx_buf[0] == '$' && g_rx_buf[g_rx_buf_len-3] == '*')  // +ёыш ъюэхЎ яръхЄр
            {
                if ( g_rx_buf_len > 10)
                {

                    unsigned char crc;
                    if (g_rx_buf[--g_rx_buf_len] > '9')
                        crc = 0x0A + g_rx_buf[g_rx_buf_len]-'A';
                    else
                        crc = (g_rx_buf[g_rx_buf_len]-'0');

                    if (g_rx_buf[--g_rx_buf_len] > '9')
                        crc |= (0x0A + g_rx_buf[g_rx_buf_len]-'A')<< 4;
                    else
                        crc |= (g_rx_buf[g_rx_buf_len]-'0')<< 4;

                    g_rx_buf_len-=2;

                    do{
                        crc ^= g_rx_buf[g_rx_buf_len];
                    }while( --g_rx_buf_len );

                    if (!crc) // CRC
                    {
                        health_count = 0;
                        gps_info.pack_found++;

                       /* Parse packet */
                        if( !strncmp((char*)g_rx_buf, "$GPGGA", 6) )
	                {
		            ProcessGPGGA(&g_rx_buf[7]);
                            st[1] =hw_time();
                        }
	                else if( !strncmp((char*)g_rx_buf, "$GPRMC", 6))
	                {
	                    ProcessGPRMC(&g_rx_buf[7]);
                            //
                            gps_pps_counter=0;
                            //
                            //
                            st[0] =hw_time();

                        }
                    }else
                    {
                        gps_info.crc_error++;
                    }
                }

                g_rx_buf_len = 0;
            }else
            if (b != 0x0A)
                g_rx_buf[g_rx_buf_len++] = b;
          }

       }//while
    }
    /////
    if (ist & UART_INT_TX)
    {
        MAP_UARTIntClear(UART_BASE, UART_INT_TX);
        tx_pkt_snd_one();
    }

}