// simple line entry only handles backspace void Serial_GetLine(char *buffer, size_t length) { size_t cursor = 0; buffer[cursor] = '\0'; for (;;) { char c = Serial_GetChar(); if ('\010' == c || 127 == c) { if (cursor > 0) { buffer[--cursor] = '\0'; Serial_print("\010 \010"); } else { Serial_print("\007"); } } else if (c >= ' ' && c < 127) { if (cursor < length - 1) { // remember space for the '\0' buffer[cursor++] = c; buffer[cursor] = '\0'; Serial_PutChar(c); } else { Serial_print("\007"); } } else if ('\r' == c || '\n' == c) { return; } } }
static void printchar(char **str, int c) { if (str) { **str = c; ++(*str); } else Serial_PutChar(c); }
void Serial_HexDump(const void *buffer, size_t size) { uint32_t start = (uint32_t)buffer & 0x0f; uint32_t address = (uint32_t)buffer & ~0x0f; const uint8_t *bytes = (const uint8_t *)address; size_t offset; for (offset = 0; offset < start + size; offset += 16) { Serial_printf("%08lx: ", address + offset); int i; for (i = 0; i < 16; ++i) { if (8 == i) { Serial_PutChar(' '); } if (offset + i < start || offset + i >= start + size) { Serial_print(" --"); } else { Serial_printf(" %02x", bytes[offset + i]); } } Serial_print(" |"); for (i = 0; i < 16; i++) { if (8 == i) { Serial_PutChar(' '); } if (offset + i < start || offset + i >= start + size) { Serial_PutChar(' '); } else if (isprint(bytes[offset + i])) { Serial_PutChar(bytes[offset + i]); } else { Serial_PutChar('.'); } } Serial_print("|\n"); } }
int Serial_PutChar(int c) { c = (unsigned char)(c); if ('\n' == c) { Serial_PutChar('\r'); } while (!Serial_PutReady()) { } Watchdog_KeepAlive(WATCHDOG_KEY); REG_EFSIF0_TXD = c; return c; }
void Log_Error(FARROM *string) { char t=0; char c=0; if(STDERR > -1) { do { c = string[t]; Serial_PutChar(STDERR,c); t++; } while(c!=0); Serial_Send_Full_TX_Buffer(STDERR); } }
void Serial_print(const char *message) { while ('\0' != *message) { Serial_PutChar(*message++); } }