int _write (int fd, char *ptr, int len) { char *p = ptr; int res = UART_SUCCESS; (void)fd; (void)len; while (*p != '\n') { UART_WriteChar(*p++); if (res != UART_SUCCESS) { break; } /* if(*p == '\t') { break; }*/ } if(*p == '\n') { UART_WriteChar('\r'); UART_WriteChar('\n'); } return res; }
/** @brief Internal printf function with semihosting via UART. @param ptr - data to write. @return UART_SUCCESS or error code. **/ int _write(int fd, char *ptr, int len) { if ((fd == 1) && no_error) { for (auto a = 0; a < len; ++a) { UART_WriteChar(ptr[a], UART_WRITE); } } if (fd == 2) { //stderr no_error = false; NVIC_DisableIRQ(UART_IRQn); for (auto a = 0; a < len; ++a) { while (!COMLSR_TEMT_BBA) ; UART_WriteChar(ptr[a], UART_WRITE_INT); } } return len; }
void UART_WriteStr(tUART* uart, unsigned char* str) { // Write until End of String while(str != 0) UART_WriteChar(uart, *str++); // Also send End of String char UART_WriteChar(uart, 0); }
/** @brief UART test function @return none **/ static void Test_UART(void) { if(UART_PINS == UART_PINS_67) { /* Check if UART is connected to P0.6-P0.7 pins */ UART_WriteChar('V'); /* 0x56 - Write data to UART*/ } else if(UART_PINS == UART_PINS_12) { /* Check if UART is connected to P0.1-P0.2 pins */ UART_WriteChar(0x43); /* Write data to UART */ } }
/***************************************************************************//** * @brief Writes one character string to UART. * * @param data - Character to write. * * @return None. *******************************************************************************/ void UART_WriteString(const char* string) { while(*string) { UART_WriteChar(*string++); } }
void _ttywrch(int ch) { if (no_error) { UART_WriteChar(ch, UART_WRITE); } }
int _write(int file, char *ptr, unsigned int len) { unsigned int i; for(i = 0; i < len; i++){ #ifndef SILENT UART_WriteChar(PRINTF_UART_TX, ptr[i]); #endif } return i; }
/** @brief Writes string to UART. @param string - string to write. @return UART_SUCCESS or error code. **/ int UART_WriteString(char *string) { int result = UART_SUCCESS; while (*string != '\0') { result = UART_WriteChar(*string++, UART_WRITE_NO_INT); if (result != UART_SUCCESS) { break; } } return result; }
void UART_Write(tUART* uart, unsigned char* buff, unsigned long len) { for(; len > 0; len--) UART_WriteChar(uart, *buff++); }
/***************************************************************************//** * @brief Prints formatted data to console. * * @param str - String to be printed. * * @return None. *******************************************************************************/ void CONSOLE_Print(char* str, ...) { char* stringPtr; char firstParam = 0; char secondParam = 0; unsigned long xMask = 0; unsigned long dMask = 0; char chNumber = 0; unsigned long multiplier = 1; char* strArg; long longArg; double doubleArg; va_list argp; va_start(argp, str); for(stringPtr = str; *stringPtr != '\0'; stringPtr++) { if(*stringPtr!='%') { UART_WriteChar(*stringPtr); continue; } stringPtr++; firstParam = 0; while((*stringPtr >= 0x30) & (*stringPtr <= 0x39)) { firstParam *= 10; firstParam += (*stringPtr - 0x30); stringPtr++; } if(*stringPtr == '.') { stringPtr++; secondParam = 0; while((*stringPtr >= 0x30) & (*stringPtr <= 0x39)) { secondParam *= 10; secondParam += (*stringPtr - 0x30); stringPtr++; } } switch(*stringPtr) { case 'c': longArg = va_arg(argp, long); UART_WriteChar((char)longArg); break; case 's': strArg = va_arg(argp, char*); UART_WriteString(strArg); break; case 'd': longArg = va_arg(argp, long); UART_WriteString(intToStr(longArg, 10)); break; case 'x': longArg = va_arg(argp, long); xMask = 268435456; chNumber = 8; while(xMask > longArg) { xMask /= 16; chNumber--; } while(chNumber < firstParam) { UART_WriteChar('0'); chNumber++; } if(longArg != 0) { UART_WriteString(intToStr(longArg, 16)); } break; case 'f': doubleArg = va_arg(argp, double); chNumber = secondParam; while(chNumber > 0) { multiplier *= 10; chNumber--; } doubleArg *= multiplier; if(doubleArg < 0) { doubleArg *= -1; UART_WriteChar('-'); } longArg = (long)doubleArg; UART_WriteString(intToStr((longArg / multiplier), 10)); UART_WriteChar('.'); dMask = 1000000000; chNumber = 10; while(dMask > (long)(longArg % multiplier)) { dMask /= 10; chNumber--; } while(chNumber < secondParam) { UART_WriteChar('0'); chNumber++; } if((longArg % multiplier) != 0) { UART_WriteString(intToStr((longArg % multiplier), 10)); } break; } } va_end(argp); }