/* Status.c Functions for logging program status to the serial port, to be used for debugging pruposes etc. 2008-03-21, P.Harvey-Smith. */ #include #include #include "terminalcodes.h" #include "status.h" static int StdioSerial_TxByte0(char DataByte, FILE *Stream); FILE ser0stream = FDEV_SETUP_STREAM(StdioSerial_TxByte0,NULL,_FDEV_SETUP_WRITE); void StdioSerial_TxByte(char DataByte) { if((DataByte=='\r') || (DataByte=='\n')) { Serial_TxByte0('\r'); Serial_TxByte0('\n'); } else { Serial_TxByte0(DataByte); } } int StdioSerial_TxByte0(char DataByte, FILE *Stream) { StdioSerial_TxByte(DataByte); return 0; } void cls() { logs(ESC_ERASE_DISPLAY); logs(ESC_CURSOR_POS(0,0)); } void USART_Init0(const uint32_t BaudRate) { #ifdef UCSR0A UCSR0A = 0; UCSR0B = ((1 << RXEN0) | (1 << TXEN0)); UCSR0C = ((1 << UCSZ01) | (1 << UCSZ00)); UBRR0 = SERIAL_UBBRVAL(BaudRate); #else UCR = ((1 << RXEN) | (1 << TXEN)); UBRR = SERIAL_UBBRVAL(BaudRate); #endif } /** Transmits a given byte through the USART. * * \param DataByte Byte to transmit through the USART */ void Serial_TxByte0(const char DataByte) { #ifdef UCSR0A while ( !( UCSR0A & (1<> 4); loghex1(i); } void loghex4(uint16_t i) { loghex2(i >> 8); loghex2(i); } void logint(int i) { char buffer[16]; strint(buffer, i); logs(buffer); } void loglong(long i) { char buffer[16]; strlong(buffer, i); logs(buffer); } char *strfill(char *buffer, char c, uint8_t i) { while (i-- > 0) { *buffer++ = c; } return buffer; } char *strhex1(char *buffer, uint8_t i) { *buffer++ = hex1(i); return buffer; } char *strhex2(char *buffer, uint8_t i) { buffer = strhex1(buffer, i >> 4); buffer = strhex1(buffer, i); return buffer; } char *strhex4(char *buffer, uint16_t i) { buffer = strhex2(buffer, i >> 8); buffer = strhex2(buffer, i); return buffer; } char *strint(char *buffer, int i) { return itoa(i, buffer, 10); } char *strlong(char *buffer, long i) { return ltoa(i, buffer, 10); } char *strinsert(char *buffer, const char *s) { while (*s) { *buffer++ = *s++; } return buffer; }