void USART_WriteStr(char* str) { while(*str) { USART_Write(*str); str++; } }
void printHex8(unsigned char a) { char lookup[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; USART_Write(lookup[a >> 4]); USART_Write(lookup[a & 0xF]); }
void __section("SectionForFlashOperations") Native_Profiler_Dump() { lcd_printf("Buffer is full. Dumping...\r\n"); UINT64 time1, time2; time1 = Native_Profiler_TimeInMicroseconds(); USART_Initialize( ConvertCOM_ComPort(USART_DEFAULT_PORT), HalSystemConfig.USART_DefaultBaudRate, USART_PARITY_NONE, 8, USART_STOP_BITS_ONE, USART_FLOW_NONE ); // clear_watchdog // if we do not disable the watchdog, it can be called while we dump data Watchdog_GetSetEnabled( FALSE, TRUE ); // flush existing characters USART_Flush( ConvertCOM_ComPort(USART_DEFAULT_PORT) ); // write string char *offset = (char *)&ProfilerBufferBegin; UINT32 size = (char *)s_native_profiler.position - (char *)&ProfilerBufferBegin; do { UINT32 bytes_written = USART_Write(ConvertCOM_ComPort(USART_DEFAULT_PORT), offset, size); offset += bytes_written; size -= bytes_written; } while(size); // flush new characters USART_Flush( ConvertCOM_ComPort(USART_DEFAULT_PORT) ); Watchdog_GetSetEnabled( TRUE, TRUE ); time2 = Native_Profiler_TimeInMicroseconds(); s_native_profiler.initTime += (time2 - time1); s_native_profiler.position = &ProfilerBufferBegin; *s_native_profiler.position++ = NATIVE_PROFILER_START_TAG; *s_native_profiler.position++ = s_native_profiler.engineTimeOffset; s_native_profiler.writtenData = FALSE; }
void __section("SectionForFlashOperations") Native_Profiler_WriteToCOM(void *buffer, UINT32 size) { UINT64 time1, time2; time1 = Native_Profiler_TimeInMicroseconds(); USART_Initialize( ConvertCOM_ComPort(USART_DEFAULT_PORT), HalSystemConfig.USART_DefaultBaudRate, USART_PARITY_NONE, 8, USART_STOP_BITS_ONE, USART_FLOW_NONE ); // disable watchdog Watchdog_GetSetEnabled( FALSE, TRUE ); // flush existing characters USART_Flush( ConvertCOM_ComPort(USART_DEFAULT_PORT) ); // write string char *offset = (char *) buffer; do { UINT32 bytes_written = USART_Write(ConvertCOM_ComPort(USART_DEFAULT_PORT), offset, size); offset += bytes_written; size -= bytes_written; } while(size); // flush new characters USART_Flush( ConvertCOM_ComPort(USART_DEFAULT_PORT) ); Watchdog_GetSetEnabled( TRUE, TRUE ); time2 = Native_Profiler_TimeInMicroseconds(); s_native_profiler.initTime += (time2 - time1); }
void USART_WriteUnsignedChar(unsigned char number) { unsigned char write_data = FALSE; // This number is at most 255 (3 digits) unsigned char ones = number % 10; number /= 10; unsigned char tens = number % 10; number /= 10; unsigned char hundreds = number % 10; if (hundreds > 0) write_data = TRUE; if (write_data) USART_Write('0' + hundreds); if (tens > 0) write_data = TRUE; if (write_data) USART_Write('0' + tens); USART_Write('0' + ones); }
void vDebugTask (void *pvParameters) { int Res; char strMsgDebug[64]; #ifdef DEBUG_OUTPUT_USART InitUSART(UART_DBG, DBG_BAUDRATE); InitDMA(UART_DBG); #endif while(1) { LED_TOGGLE; Res = HandlerCompass(strMsgDebug); strcat(strMsgDebug, "\r\n"); if(!(Res)) { #ifdef DEBUG_OUTPUT_USART USART_Write(UART_DBG, strMsgDebug, strlen(strMsgDebug)); #endif #ifdef DEBUG_OUTPUT_USB if(bDeviceState == CONFIGURED) { CDC_Send_DATA ((unsigned char *)strMsgDebug, strlen(strMsgDebug)); NVIC_EnableIRQ(USB_LP_CAN1_RX0_IRQn); } #endif } _delay_ms(1000); } }
void printHex(int i){ char hex[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; USART_Write(hex[(i&0xF000) >> 12]); USART_Write(hex[(i&0xF00) >> 8]); USART_Write(hex[(i&0xF0) >> 4]); USART_Write(hex[i&0xF]); }
/******************************************************************************* 函 数 名: USART_Send 功能说明: 串口数据发送 参 数: *data: 要发送的数内容 len : 数据长度 返 回 值: 发送结果 TRUE/FALSE *******************************************************************************/ BF_INT08U USART_Send(BF_INT08U *data, BF_INT08U len, BF_INT08U level) { while (len--) { if (!USART_Write(*data++)) { return FALSE;; } } return TRUE; }
void USART_WriteString(char *string) { // Write characters out until we reach a NULL character while (*string != 0) { // Write the current character USART_Write((unsigned char)*string); // Next character string++; } }
//------------------------------------------------------------------------------ /// Implementation of fputc using USART0 as the standard output. Required /// for printf(). /// Returns the character written if successful, or -1 if the output stream is /// not stdout or stderr. /// \param c Character to write. /// \param pStream Output stream. //------------------------------------------------------------------------------ signed int fputc(signed int c, FILE *pStream) { if ((pStream == stdout) || (pStream == stderr)) { USART_Write(BOARD_USART_BASE, c, 0); return c; } else { return EOF; } }
void USART_WriteSignedInt(int number) { // This number is at most +32768 and at least -32767 (5 digits + sign)s // Print the sign if applicable if (number < 0) { USART_Write('-'); // Convert the number into an unsigned int number *= -1; } // Print out the positive number result USART_WriteUnsignedInt((unsigned int)number); }
void USART_WriteUnsignedInt(unsigned int number) { unsigned char write_data = FALSE; // This number is at most 65535 (5 digits) unsigned char digit1 = number % 10; number /= 10; unsigned char digit2 = number % 10; number /= 10; unsigned char digit3 = number % 10; number /= 10; unsigned char digit4 = number % 10; number /= 10; unsigned char digit5 = number % 10; if (digit5 > 0) write_data = TRUE; if (write_data) USART_Write('0' + digit5); if (digit4 > 0) write_data = TRUE; if (write_data) USART_Write('0' + digit4); if (digit3 > 0) write_data = TRUE; if (write_data) USART_Write('0' + digit3); if (digit2 > 0) write_data = TRUE; if (write_data) USART_Write('0' + digit2); USART_Write('0' + digit1); }
int DebuggerPort_Write( COM_HANDLE ComPortNum, const char* Data, size_t size ) { NATIVE_PROFILE_PAL_COM(); UINT32 transport = ExtractTransport(ComPortNum); const char* dataTmp = Data; INT32 totWrite = 0; int retries = 100; while(size > 0 && retries--) { int ret = 0; switch(transport) { case USART_TRANSPORT: ret = USART_Write( ConvertCOM_ComPort( ComPortNum ), dataTmp, size ); break; case USB_TRANSPORT: ret = USB_Write( ConvertCOM_UsbStream( ComPortNum ), dataTmp, size ); break; case SOCKET_TRANSPORT: ret = SOCKETS_Write( ConvertCOM_SockPort(ComPortNum), dataTmp, size ); break; } if(ret < 0) { break; } else if(ret == 0) { // if interrupts are off and our buffer is full then there is nothing we can do if(!INTERRUPTS_ENABLED_STATE()) break; Events_WaitForEvents(0, 1); } else { retries = 50; // reset retries size -= ret; dataTmp += ret; totWrite += ret; } } return totWrite; }
void USART_WriteByte(USART * serial, unsigned char dat) { if (serial->isSerialProtocol) { /*unsigned char tempCTRLA = serial->port.usart_port->CTRLA; tempCTRLA = (tempCTRLA & ~USART_DREINTLVL_gm) | USART_DREINTLVL_LO_gc; serial->port.usart_port->CTRLA = tempCTRLA; serial->port.usart_port->CTRLA = ((serial->port.usart_port)->CTRLA & ~USART_DREINTLVL_gm) | USART_DREINTLVL_LO_gc; */ /*if (serial->port.usart_port->CTRLA & USART_DREINTLVL_LO_gc) PORTE.OUTSET = PIN0_bm; else PORTE.OUTCLR = PIN0_bm; */ serial->port.usart_port->DATA = dat; // _delay_us(500); } else { USART_Write(serial,&dat,1); } }
void monitor_debug_printf( const char* format, ... ) { char buffer[256]; va_list arg_ptr; va_start( arg_ptr, format ); int len = hal_vsnprintf( buffer, sizeof(buffer)-1, format, arg_ptr ); // flush existing characters USART_Flush( ConvertCOM_ComPort(USART_DEFAULT_PORT) ); // write string USART_Write( ConvertCOM_ComPort(USART_DEFAULT_PORT), buffer, len ); // flush new characters USART_Flush( ConvertCOM_ComPort(USART_DEFAULT_PORT) ); va_end( arg_ptr ); }
int UartInit() { //CDCDSerialDriver_Initialize(); PIO_Configure(g_UartPins, PIO_LISTSIZE(g_UartPins)); PMC_EnablePeripheral(AT91C_ID_US0); USART_Configure(AT91C_BASE_US0, USART_MODE_ASYNCHRONOUS, 115200, MCK); USART_SetReceiverEnabled(AT91C_BASE_US0, 1); USART_SetTransmitterEnabled(AT91C_BASE_US0, 1); //DMA_Init(&g_Uart1DMA, AT91C_BASE_PDC_US0); //SetPitCallback(UartRefresh, 2); UartRefresh(); while(1){ USART_Write(AT91C_BASE_US0,'a',0); } return 1; }
static void uart_send( int fd, char c ) { fd = fd; USART_Write( AT91C_BASE_US0, c, 0 ); }
void USART_WriteCRLF(void) { USART_Write(CR); USART_Write(LF); }
void platform_s_uart_send( unsigned id, u8 data ) { AT91S_USART* base = id == 0 ? AT91C_BASE_US0 : AT91C_BASE_US1; USART_Write( base, data, 0 ); }
/** * \brief usart_spi Application entry point. * * \return Unused (ANSI-C compatibility). */ extern int main(void) { uint8_t ucKey, i; /* Disable watchdog */ WDT_Disable(WDT); SCB_EnableICache(); SCB_EnableDCache(); /* Configure systick for 1 ms. */ TimeTick_Configure(); /* Output example information */ printf("-- USART SPI Example %s --\n\r", SOFTPACK_VERSION); printf("-- %s\n\r", BOARD_NAME); printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__, COMPILER_NAME); /* Display menu */ _DisplayMainmenu(); while (1) { ucKey = DBG_GetChar(); switch (ucKey) { /*usart as spi master*/ case 'm': case 'M': /* Configure pins*/ PIO_Configure(pins1, PIO_LISTSIZE(pins1)); /* Configure USART as SPI master */ _ConfigureUsartAsSpiMaster(); /* Configure SPi slave */ _ConfigureSpiSlave(); printf("-I- Configure USART as spi master ...\n\r"); SPI_EnableIt(SPI, SPI_IER_RDRF); SPI_Enable(SPI); USART_EnableIt(USART, UART_IER_RXRDY); for (i = 0; (pTxBuffer1[i]!='\0' && pTxBuffer2[i]!='\0'); i++) { while ((SPI->SPI_SR & SPI_SR_TXEMPTY) == 0); SPI->SPI_TDR = ((uint16_t)pTxBuffer2[i]) | SPI_PCS( 0 ); USART_Write( USART, pTxBuffer1[i], 0); } break; /*usart as spi slave*/ case 's': case 'S': printf("-I- Configure USART as spi slave...\n\r"); /* Configure pins*/ PIO_Configure(pins2, PIO_LISTSIZE(pins2)); /* Configure USART as SPI slave */ _ConfigureUsartAsSpiSlave(); /* Configure SPI master */ _ConfigureSpiMaster(); USART_EnableIt(USART, UART_IER_RXRDY); SPI_EnableIt(SPI, SPI_IER_RDRF); SPI_Enable(SPI); for (i = 0; (pTxBuffer1[i]!='\0' && pTxBuffer2[i]!='\0'); i++) { USART_Write(USART, (uint16_t)pTxBuffer2[i], 0); SPI_Write( SPI, 1, (uint16_t)pTxBuffer1[i]); } break; case 'h': case 'H': _DisplayMainmenu(); break; } } }
void USART_WriteByte(USART * serial, unsigned char dat) { USART_Write(serial,&dat,1); }
void DBGU_PutChar(unsigned char ch) { USART_Write(BOARD_USART_BASE, ch, 0); }
int COM2_write( char* buffer, size_t size ) { return USART_Write( ConvertCOM_ComPort( COM2 ), buffer, size ); }