int uart_rx_char(pyb_uart_obj_t *self) { if (self->read_buf_tail != self->read_buf_head) { // buffering via IRQ int data = self->read_buf[self->read_buf_tail]; self->read_buf_tail = (self->read_buf_tail + 1) % self->read_buf_len; return data; } else { // no buffering return MAP_UARTCharGetNonBlocking(self->reg); } }
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); } } }
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 ); } }
//-------------------------------- 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; } } }
int platform_s_uart_recv( unsigned id, timer_data_type timeout ) { u32 base = uart_base[ id ]; #ifdef BUILD_USB_CDC if( id == CDC_UART_ID ) return cdc_uart_recv( timeout ); #endif if( timeout == 0 ) return MAP_UARTCharGetNonBlocking( base ); return MAP_UARTCharGet( base ); }
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); } }
//***************************************************************************** // //! 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; }
//------------------------------------------------------------------------------ //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(); } }