/* 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 #include "terminalcodes.h" #include "status.h" #ifdef SERIAL_STATUS static int StdioSerial_TxByte0(char DataByte, FILE *Stream); static int StdioSerial_TxByte1(char DataByte, FILE *Stream); FILE ser0stream = FDEV_SETUP_STREAM(StdioSerial_TxByte0,NULL,_FDEV_SETUP_WRITE); FILE ser1stream = FDEV_SETUP_STREAM(StdioSerial_TxByte1,NULL,_FDEV_SETUP_WRITE); void StdioSerial_TxByte(char DataByte, uint8_t Port) { #ifdef COOKED_SERIAL if((DataByte=='\r') || (DataByte=='\n')) { if(Port==1) { Serial_TxByte1('\r'); Serial_TxByte1('\n'); } else { Serial_TxByte0('\r'); Serial_TxByte0('\n'); } } else #endif if(Port==1) Serial_TxByte1(DataByte); else Serial_TxByte0(DataByte); } int StdioSerial_TxByte0(char DataByte, FILE *Stream) { StdioSerial_TxByte(DataByte,0); return 0; } int StdioSerial_TxByte1(char DataByte, FILE *Stream) { StdioSerial_TxByte(DataByte,1); return 0; } void cls(uint8_t Port) { if(Port==1) { log1(ESC_ERASE_DISPLAY); log1(ESC_CURSOR_POS(0,0)); } else { log0(ESC_ERASE_DISPLAY); log0(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 } void USART_Init1(const uint32_t BaudRate) { #ifdef UCSR1A UCSR1A = 0; UCSR1B = ((1 << RXEN1) | (1 << TXEN1)); UCSR1C = ((1 << UCSZ11) | (1 << UCSZ10)); UBRR1 = 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<