/* write one character to serial, must not trigger interrupt */ static void rt_hw_console_putc(const char c) { if (c == '\n') while(UARTCharPutNonBlocking(UART0_BASE, '\r') == false); while(UARTCharPutNonBlocking(UART0_BASE, c) == false); }
//***************************************************************************** // // The UART interrupt handler. // //***************************************************************************** void UART0IntHandler(void) { unsigned long ulStatus; tBoolean bRc; // // Get the interrrupt status. // ulStatus = UARTIntStatus(UART0_BASE, true); // // Clear the asserted interrupts. // UARTIntClear(UART0_BASE, ulStatus); // // Check what is the source of the interrupt // //if(ulStatus & UART_INT_OE) //{ //} //else if(ulStatus & UART_INT_BE) //{ //} //else if(ulStatus & UART_INT_PE) //{ //} if(ulStatus & UART_INT_TX) { // TX int // Push next char to transmitter bRc = true; while(m_nTxBuffIn > 0 && bRc == true) { bRc = UARTCharPutNonBlocking(UART0_BASE,m_tTxBuff[m_nTxNextNdx]); if(bRc == true) { m_nTxNextNdx++; m_nTxBuffIn--; } } } else if(ulStatus & UART_INT_RX || ulStatus & UART_INT_RT) { // RX int // Read all RX fifo data while(UARTCharsAvail(UART0_BASE)) { // Read the next character from the UART // (and write it back to the UART) ? #if defined(stabilizition) ContropMessageLoop(UART0_BASE,0); #else MessageLoop(UART0_BASE,0); #endif } } }
//***************************************************************************** // // This function handles the UART interrupt. It will copy data from the // software FIFO to the hardware. // //***************************************************************************** void LogIntHandler(void) { // // Clear the UART interrupt. // UARTIntClear(UART1_BASE, UART_INT_TX); // // Loop while there is more data to be transferred from the software FIFO. // while(g_ulReadPtr != g_ulWritePtr) { // // Transfer the next byte to the UART. Break out of the loop if the // hardware FIFO is full. // if(UARTCharPutNonBlocking(UART1_BASE, g_pcTransmitBuffer[g_ulReadPtr]) == false) { break; } // // This byte has been transferred to the UART, so remove it from the // software FIFO. // g_ulReadPtr = (g_ulReadPtr + 1) & (SOFT_FIFO_SIZE - 1); } }
uint8_t uart_transmit(char* formatted, uint8_t length) { //FOR TESTING PURPOSES ONLY uint8_t uart_counter = 0; while( uart_counter < 8 ) { while( !UARTSpaceAvail(UART0_BASE) ) {} if (uart_counter == 0) { UARTCharPutNonBlocking(UART0_BASE, (char) 0xFF); } else UARTCharPutNonBlocking(UART0_BASE, formatted[uart_counter-1]); uart_counter++; } //Api_rx_all(formatted, vars); return 1; }
static void UART2_RxTxHandler(void) { uint32_t IntStatus, byteCnt, timeout = 1000000; uint8_t c; IntStatus = UARTIntStatus(UART2_BASE, true); UARTIntClear(UART2_BASE, IntStatus); if(IntStatus & UART_INT_TX) { byteCnt = RINGBUF_GetFill(&long_Uart2_TxRingBuf); if (byteCnt) { RINGBUF_Get(&long_Uart2_TxRingBuf, &c); UARTCharPutNonBlocking(UART2_BASE, c); if (byteCnt == 1) { UARTIntDisable(UART2_BASE, UART_INT_TX); } } else { UARTIntDisable(UART2_BASE, UART_INT_TX); } } else if (IntStatus & (UART_INT_RX | UART_INT_RT)) { while(!UARTCharsAvail(UART2_BASE) && (timeout--)); c = UARTCharGet(UART2_BASE); RINGBUF_Put(&long_Uart0_RxRingBuf,c); } else { c = UARTCharGet(UART2_BASE); } }
static size_t uartPut(const uint8_t* data, size_t nData, void* usr) { uint32_t uart_base = (uint32_t) usr; size_t ret = 0; while (ret < nData && UARTCharPutNonBlocking(uart_base, data[ret])) ret++; return ret; }
//***************************************************************************** // // The UART interrupt handler. // //***************************************************************************** void UART0IntHandler(void) { unsigned long ulStatus; // // Get the interrrupt status. // ulStatus = UARTIntStatus(UART0_BASE, true); // // Clear the asserted interrupts. // UARTIntClear(UART0_BASE, ulStatus); // // Loop while there are characters in the receive FIFO. // while(UARTCharsAvail(UART0_BASE)) { // // Read the next character from the UART and write it back to the UART. // UARTCharPutNonBlocking(UART0_BASE, UARTCharGetNonBlocking(UART0_BASE)); } }
/* ** Uart ISR to read the inputs */ static void uartIsr(void) { volatile unsigned char rxByte; ; /* Perform nothing */ rxByte = UARTCharGetNonBlocking(SOC_UART_0_REGS); UARTCharPutNonBlocking(SOC_UART_0_REGS, rxByte); }
bool bluetooth_send(const uint8_t *pui8Buffer, uint32_t ui32Count) { if (txHead == txTail) { UARTCharPutNonBlocking(UART0_BASE, *pui8Buffer++); ui32Count--; } // // Loop while there are more characters to send. // while (ui32Count--) { if (txHead + 1 < MAX_TX_BUF) { if ((txHead + 1) != txTail) { txBuffer[txHead++] = *pui8Buffer++; } else return false; } else { if (0 != txTail) { txBuffer[txHead] = *pui8Buffer++; txHead = 0; } else return false; } // // Write the next character to the UART. // // UARTCharPut(UART0_BASE, *pui8Buffer++); } return true; }
/* * シリアルI/Oポートへの文字送信 */ bool_t sio_snd_chr(SIOPCB *p_siopcb, char c) { if(UARTSpaceAvail(p_siopcb->p_siopinib->base)){ UARTCharPutNonBlocking(p_siopcb->p_siopinib->base, c); return(true); } return(false); }
void SAD_txHSBYTE(DriverRegisters* sadreg) { // clear timer // start timer sadreg->timer.running=true; sadreg->hs_cnt++; UARTCharPutNonBlocking(UART1_BASE, HS_BYTE); }
/* Send a string to the UART. */ static void UARTSend(portCHAR *pucBuffer, unsigned long ulCount) { // Loop while there are more characters to send. while(ulCount--) { // Write the next character to the UART. UARTCharPutNonBlocking(UART0_BASE, *pucBuffer++); } }
/************************************************************************************************* * @fn procTx * * @brief Process Tx bytes. * * @param void * * @return void */ static void procTx(void) { while ((txHead != txTail) && (UARTCharPutNonBlocking(HAL_UART_PORT, txBuf[txHead]))) { if (++txHead >= SB_BUF_SIZE) { txHead = 0; } } }
//***************************************************************************** // // Send a string to the UART. // //***************************************************************************** void UARTSend(const unsigned char *pucBuffer, unsigned long ulCount) { // // Loop while there are more characters to send. // while (ulCount--) { // // Write the next character to the UART. // UARTCharPutNonBlocking(UART0_BASE, *pucBuffer++); } }
/********************************************************************************************************* ** Function name: Uart0Send ** Descriptions: 发送多个字节数据 ** input parameters: Buffer:发送数据存储位置 ** NByte:发送数据个数 ** Output parameters:: 无 ** Returned value: 无 ** Created by: ** Created Date: 2014.10.03 **-------------------------------------------------------------------------------------------------------- ** Modified by: ** Modified date: 2014.10.03 **-------------------------------------------------------------------------------------------------------- *********************************************************************************************************/ void UartSend (u8 *Buffer, u16 NByte) { while (NByte) { if ( UARTSpaceAvail(UART1_BASE) ) { UARTCharPutNonBlocking(UART1_BASE, *Buffer++); NByte--; } } while (UARTBusy(UART1_BASE) ) { ; } }
void UARTINtHandler(void) { uint32_t ui32Status; ui32Status = UARTIntStatus(UART0_BASE, true); // Thuc hien lay trang thai ngat UARTIntClear(UART0_BASE, ui32Status); //Xoa co ngat uart while(UARTCharsAvail(UART0_BASE)) //Thuc hien cho ki tu { UARTCharPutNonBlocking(UART0_BASE, UARTCharGetNonBlocking(UART0_BASE)); //nhan ki tu GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2); //chop tat led SysCtlDelay(SysCtlClockGet()/(1000*3)); //Thuc hien delay khoang 1ms GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0); //Tat LED } }
static void USBUARTPrimeTransmit(unsigned int ulBase) { unsigned int ulRead; unsigned char ucChar; // // If we are currently sending a break condition, don't receive any // more data. We will resume transmission once the break is turned off. // if(g_bSendingBreak) { return; } // // If there is space in the UART FIFO, try to read some characters // from the receive buffer to fill it again. // while(UARTSpaceAvail(ulBase)) { // // Get a character from the buffer. // ulRead = USBBufferRead((tUSBBuffer *)&g_sRxBuffer, &ucChar, 1); // // Did we get a character? // if(ulRead) { // // Place the character in the UART transmit FIFO. // UARTCharPutNonBlocking(ulBase, ucChar); // // Update our count of bytes transmitted via the UART. // g_ulUARTTxCount++; } else { // // We ran out of characters so exit the function. // return; } } }
void Long_Uart2_PutChar(char c) { uint32_t byteCnt; byteCnt = RINGBUF_GetFill(&long_Uart2_TxRingBuf); if (byteCnt) { RINGBUF_Put(&long_Uart2_TxRingBuf, c); } else { UARTCharPutNonBlocking(UART2_BASE, c); UARTIntEnable(UART2_BASE, UART_INT_TX); } }
void UARTSend(const uint8_t *pui8Buffer, uint32_t ui32Count) { // // Loop while there are more characters to send. // while(ui32Count--) { // // Write the next character to the UART. // UARTCharPutNonBlocking(UART4_BASE, *pui8Buffer++); } }
static void Bluetooth_RxTxHandler(void) { uint32_t IntStatus; IntStatus = UARTIntStatus(UART0_BASE, true); UARTIntClear(UART0_BASE, IntStatus); if (IntStatus & UART_INT_TX) { if (txTail < MAX_TX_BUF) { if (txHead != txTail) { UARTCharPutNonBlocking(UART0_BASE, txBuffer[txTail++]); } else { HC05_PutEvtIntoQueue(HC05_TX_DONE_EVENT); } } else { if (0 != txHead) { UARTCharPutNonBlocking(UART0_BASE, txBuffer[0]); txTail = 1; } else { HC05_PutEvtIntoQueue(HC05_TX_DONE_EVENT); } } } while (UARTCharsAvail(UART0_BASE)) { b_is_has_new_data = true; if (rxHead + 1 < MAX_RX_BUF) { if ((rxHead + 1) != rxTail) { rxBuffer[rxHead++] = UARTCharGet(UART0_BASE); ui16_rxSize++; } } else { if (0 != rxTail) { rxBuffer[rxHead] = UARTCharGet(UART0_BASE); ui16_rxSize++; rxHead = 0; } } } }
/************************************************************************************************* * @fn procTx * * @brief Process Tx bytes. * * @param void * * @return void *************************************************************************************************/ static void procTx(void) { uint16 head = uartRecord.tx.bufferHead; uint16 tail = uartRecord.tx.bufferTail; while ((head != tail) && (UARTCharPutNonBlocking(HAL_UART_PORT, uartRecord.tx.pBuffer[head]))) { if (++head >= uartRecord.tx.maxBufSize) { head = 0; } } uartRecord.tx.bufferHead = head; }
/* -- void UARTIntHandler(void) ---------------------------------- * * Description : UART interrupts handler . * Parameters : none * Return : don't care */ void UARTIntHandler(void) { uint32_t ui32Status; ui32Status = UARTIntStatus(UART0_BASE, true); //get interrupt status UARTIntClear(UART0_BASE, ui32Status); //clear the asserted interrupts while(UARTCharsAvail(UART0_BASE)) //loop while there are chars { UARTCharPutNonBlocking(UART0_BASE, UARTCharGetNonBlocking(UART0_BASE)); //echo character GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2); //blink LED SysCtlDelay(SysCtlClockGet() / (1000 * 3)); //delay ~1 msec GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0); //turn off LED } }
//***************************************************************************** // // Puts a UART message on the line to the RNP. // // \param pui8Msg pointer to the data that will be put on the bus. Must be // already formated with SOF, length and checksum by the caller. // // \param ui16Length the number of bytes that are to be put out the UART. // // This function copies the message to the ring buffer and then starts a // transmission process. Application must assure that transmitter is not busy. // //***************************************************************************** void RemoTIUARTPutMsg(uint8_t* pui8Msg, uint_fast16_t ui16Length) { bool bIntState; // // Capture the current state of the master interrupt enable. // bIntState = IntMasterDisable(); // // Store the message in the ringbuffer for transmission. // RingBufWrite(&g_rbRemoTITxRingBuf, pui8Msg, ui16Length); // // If the UART transmit is idle prime the transmitter with first byte and. // enable transmit interrupts. // if(!g_bTxBusy) { // // Enable the TX interrupts and start the transmission of the first // byte. // UARTIntEnable(g_ui32UARTBase, UART_INT_TX); UARTCharPutNonBlocking(g_ui32UARTBase, RingBufReadOne(&g_rbRemoTITxRingBuf)); // // Set the Transmit busy flag. // g_bTxBusy = true; } // // Restore the master interrupt enable to its previous state. // if(!bIntState) { IntMasterEnable(); } // // Finished. // }
void s_printf(const char *fmt, ...) { va_list ap; char buf[512] = {0}; size_t len; size_t index = 0; va_start(ap, fmt); vsprintf(buf, fmt, ap); va_end(ap); len = strlen(buf); while(index < len){ while(UARTCharPutNonBlocking(UART0_BASE, buf[index]) == false); index++; } }
/** * @brief Guarda los datos en el buffer del hardware. * * @return - * * Guardado de los datos del buffer de software en el buffer de * hardware para su posterior envio. */ static int toHwFIFO(int nPort) { unsigned char c; /*Variable temporal donde se guardan los caracteres a enviar*/ int n; /*Numero de huecos en el buffer de hardware*/ int m; /*Valor de retorno*/ n=nElementosOut(nPort); m=0; while((n-->0)&&(UARTSpaceAvail(gs_ul_uarts_bases[nPort]))) { c=gs_cu_uarts[nPort].outBuf[gs_cu_uarts[nPort].outTail]; gs_cu_uarts[nPort].outTail++; if(gs_cu_uarts[nPort].outTail==BUFF_SIZE) gs_cu_uarts[nPort].outTail=0; UARTCharPutNonBlocking(gs_ul_uarts_bases[nPort], c); } return m; }
void UART1IntHandler() { unsigned long ulStatus; // // Get the interrrupt status. // ulStatus = UARTIntStatus(UART1_BASE, true); // // Clear the asserted interrupts. // UARTIntClear(UART1_BASE, ulStatus); if(ulStatus & UART_INT_TX) { // TX int // Push next char to transmitter bRc = true; while((m_nTxBuffIn1 > 0) && (bRc == true) && UARTSpaceAvail(UART1_BASE)) { // // Write the next character into the transmit FIFO. // bRc = UARTCharPutNonBlocking(UART1_BASE,m_tTxBuff1[m_nTxNextNdx1]); if(bRc == true) { m_nTxNextNdx1++; m_nTxBuffIn1--; } } } else if(ulStatus & UART_INT_RX || ulStatus & UART_INT_RT) { // RX int // Read all RX fifo data while(UARTCharsAvail(UART1_BASE)) { // Read the next character from the UART // (and write it back to the UART) ? OmapMessageLoop(UART1_BASE,1); } } }
// Main entry point int main(void) { volatile uint32_t ui32Loop; // Set the clocking to run directly from the crystal. SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); SYSCTL_RCGC2_R = SYSCTL_RCGC2_GPIOF; ui32Loop = SYSCTL_RCGC2_R; GPIO_PORTF_DIR_R = 0x08; GPIO_PORTF_DEN_R = 0x08; ConfigureUART(); for (ui32Loop = 0; ui32Loop < 200000; ui32Loop++) { } //UARTprintf("AT+NAMEGloveKey"); UARTCharPut(UART1_BASE, 'f'); for (ui32Loop = 0; ui32Loop < 2000000; ui32Loop++) { } while(1) { UARTprintf("Hi Clark\r\n"); if (UARTCharsAvail(UART1_BASE)) { unsigned char temp = UARTgetc(); UARTCharPutNonBlocking(UART0_BASE, temp); } GPIO_PORTF_DATA_R |= 0x08; for (ui32Loop = 0; ui32Loop < 200000; ui32Loop++) { } GPIO_PORTF_DATA_R &= ~(0x08); for (ui32Loop = 0; ui32Loop < 200000; ui32Loop++) { } } return 0; }
//***************************************************************************** // // The UART interrupt handler. // //***************************************************************************** void UARTIntHandler(void) { unsigned long ulStatus; // // Get the interrrupt status. // ulStatus = UARTIntStatus(UART0_BASE, true); // // Clear the asserted interrupts. // UARTIntClear(UART0_BASE, ulStatus); // // Loop while there are characters in the receive FIFO. // while (UARTCharsAvail(UART0_BASE)) { // // Read the next character from the UART and write it back to the UART. // unsigned char b; b = UARTCharGetNonBlocking(UART0_BASE); UARTCharPutNonBlocking(UART0_BASE,b); // UARTCharPutNonBlocking(UART0_BASE,'_'); // // Blink the LED to show a character transfer is occuring. // GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2); // // Delay for 1 millisecond. Each SysCtlDelay is about 3 clocks. // SysCtlDelay(SysCtlClockGet() / (1000 * 3)); // // Turn off the LED // GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0); } }
/************************************************************************************//** ** \brief Callback that gets called each time new log information becomes ** available during a firmware update. ** \param info_string Pointer to a character array with the log entry info. ** \return none. ** ****************************************************************************************/ void FileFirmwareUpdateLogHook(blt_char *info_string) { /* write the string to the log file */ if (logfile.canUse == BLT_TRUE) { if (f_puts(info_string, &logfile.handle) < 0) { logfile.canUse = BLT_FALSE; f_close(&logfile.handle); } } /* echo all characters in the string on UART */ while(*info_string != '\0') { /* write character to transmit holding register */ UARTCharPutNonBlocking(UART0_BASE, *info_string); /* wait for tx holding register to be empty */ while(UARTSpaceAvail(UART0_BASE) == false); /* point to the next character in the string */ info_string++; } } /*** end of FileFirmwareUpdateLogHook ***/
void UART1Send(unsigned char *pucBuffer, unsigned ulCount) { tBoolean bRc; static int FCount = 0; static int SCount = 0; // // Loop while there are more characters to send. // if(m_nTxBuffIn1 + ulCount >= TXBUFFSIZE1) { // No place to put new data // To be sure we purge all tx data IntDisable(INT_UART1); #if 0 // Sent all data buffer until empty and put new data in to the buffer for sent // Fill hardware FIFO while(m_nTxBuffIn1 > 0) { bRc = UARTCharPutNonBlocking(UART1_BASE,m_tTxBuff1[m_nTxNextNdx1]); if(bRc == true) { m_nTxNextNdx1++; m_nTxBuffIn1--; } } memcpy(m_tTxBuff1 ,pucBuffer,ulCount); m_nTxNextNdx1 = 0; m_nTxBuffIn1 = ulCount; #else // Throw all data buffer and put new data in to buffer for sent //memcpy(m_tTxBuff1 ,pucBuffer,ulCount); //m_nTxNextNdx1 = 0; //m_nTxBuffIn1 = ulCount; FCount++; // Fill hardware FIFO bRc = true; while(m_nTxBuffIn1 > 0 && bRc == true) { bRc = UARTCharPutNonBlocking(UART1_BASE,m_tTxBuff1[m_nTxNextNdx1]); if(bRc == true) { m_nTxNextNdx1++; m_nTxBuffIn1--; } } #endif IntEnable(INT_UART1); } else if(ulCount > 0) { IntDisable(INT_UART1); if(m_nTxBuffIn1 > 0) { // Move TX data to start if(m_nTxNextNdx1 > 0) { memmove(m_tTxBuff1,&m_tTxBuff1[m_nTxNextNdx1],m_nTxBuffIn1); } m_nTxNextNdx1 = 0; // Add data to TXBuff memcpy(&m_tTxBuff1[m_nTxBuffIn1],pucBuffer,ulCount); m_nTxBuffIn1 += ulCount; } else { memcpy(m_tTxBuff1 ,pucBuffer,ulCount); m_nTxNextNdx1 = 0; m_nTxBuffIn1 = ulCount; } // Fill hardware FIFO bRc = true; while(m_nTxBuffIn1 > 0 && bRc == true) { bRc = UARTCharPutNonBlocking(UART1_BASE,m_tTxBuff1[m_nTxNextNdx1]); if(bRc == true) { m_nTxNextNdx1++; m_nTxBuffIn1--; } } IntEnable(INT_UART1); } }