Firmware: reworked status to avoid log0

Change-Id: I0d9341d31a5d3d26b8a164ca05a0c459d2505126
This commit is contained in:
David Banks 2019-11-10 16:31:16 +00:00
parent 0437543149
commit cbab81263a
3 changed files with 13 additions and 209 deletions

View File

@ -1547,7 +1547,7 @@ void initialize() {
STATUS_DDR = MUXSEL_MASK;
MUX_DDR = 0;
CTRL_PORT = 0;
Serial_Init(57600,57600);
Serial_Init(57600);
version();
// Update the hardware copy of the breakpoints
uploadBreakpoints();

View File

@ -106,61 +106,32 @@ char *strhex4(char *buffer, uint16_t i) {
#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)
void StdioSerial_TxByte(char DataByte)
{
#ifdef COOKED_SERIAL
if((DataByte=='\r') || (DataByte=='\n'))
{
if(Port==1)
{
Serial_TxByte1('\r');
Serial_TxByte1('\n');
}
else
{
Serial_TxByte0('\r');
Serial_TxByte0('\n');
}
Serial_TxByte0('\r');
Serial_TxByte0('\n');
}
else
#endif
if(Port==1)
Serial_TxByte1(DataByte);
else
Serial_TxByte0(DataByte);
Serial_TxByte0(DataByte);
}
int StdioSerial_TxByte0(char DataByte, FILE *Stream)
{
StdioSerial_TxByte(DataByte,0);
StdioSerial_TxByte(DataByte);
return 0;
}
int StdioSerial_TxByte1(char DataByte, FILE *Stream)
void cls()
{
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));
}
logs(ESC_ERASE_DISPLAY);
logs(ESC_CURSOR_POS(0,0));
}
@ -179,18 +150,6 @@ void USART_Init0(const uint32_t 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
@ -206,15 +165,6 @@ void Serial_TxByte0(const char DataByte)
#endif
}
void Serial_TxByte1(const char DataByte)
{
#ifdef UCSR1A
while ( !( UCSR1A & (1<<UDRE1)) ) ;
UDR1=DataByte;
#endif
}
/** Receives a byte from the USART.
*
* \return Byte received from the USART
@ -230,16 +180,6 @@ char Serial_RxByte0(void)
#endif
}
char Serial_RxByte1(void)
{
#ifdef UCSR1A
while (!(UCSR1A & (1 << RXC1))) ;
return UDR1;
#else
return 0;
#endif
}
uint8_t Serial_ByteRecieved0(void)
{
#ifdef UCSR0A
@ -249,134 +189,14 @@ uint8_t Serial_ByteRecieved0(void)
#endif
}
uint8_t Serial_ByteRecieved1(void)
{
#ifdef UCSR1A
return (UCSR1A & (1 << RXC1));
#else
return 0;
#endif
}
void Serial_Init(const uint32_t BaudRate0,
const uint32_t BaudRate1)
void Serial_Init(const uint32_t BaudRate0)
{
if (BaudRate0<=0)
USART_Init0(DefaultBaudRate);
else
USART_Init0(BaudRate0);
if (BaudRate1<=0)
USART_Init1(DefaultBaudRate);
else
USART_Init1(BaudRate1);
cls(0);
cls(1);
// log0("stdio initialised\n");
// log0("SerialPort0\n");
// log1("SerialPort1\n");
cls();
}
#ifdef USE_HEXDUMP
void HexDump(const uint8_t *Buff,
uint16_t Length,
uint8_t Port)
{
char LineBuff[80];
char *LineBuffPos;
uint16_t LineOffset;
uint16_t CharOffset;
const uint8_t *BuffPtr;
BuffPtr=Buff;
for(LineOffset=0;LineOffset<Length;LineOffset+=16, BuffPtr+=16)
{
LineBuffPos=LineBuff;
LineBuffPos+=sprintf(LineBuffPos,"%4.4X ",LineOffset);
for(CharOffset=0;CharOffset<16;CharOffset++)
{
if((LineOffset+CharOffset)<Length)
LineBuffPos+=sprintf(LineBuffPos,"%2.2X ",BuffPtr[CharOffset]);
else
LineBuffPos+=sprintf(LineBuffPos," ");
}
for(CharOffset=0;CharOffset<16;CharOffset++)
{
if((LineOffset+CharOffset)<Length)
{
if(isprint(BuffPtr[CharOffset]))
LineBuffPos+=sprintf(LineBuffPos,"%c",BuffPtr[CharOffset]);
else
LineBuffPos+=sprintf(LineBuffPos," ");
}
else
LineBuffPos+=sprintf(LineBuffPos,".");
}
switch (Port)
{
case 0 : log0("%s\n",LineBuff); break;
case 1 : log1("%s\n",LineBuff); break;
}
}
}
void HexDumpHead(const uint8_t *Buff,
uint16_t Length,
uint8_t Port)
{
FILE *File;
File=&ser0stream;
switch (Port)
{
case 0 : File=&ser0stream; break;
case 1 : File=&ser1stream; break;
}
fprintf_P(File,PSTR("%d\n"),Buff);
fprintf_P(File,PSTR("Addr 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F ASCII\n"));
fprintf_P(File,PSTR("----------------------------------------------------------\n"));
HexDump(Buff,Length,Port);
};
#else
void HexDump(const uint8_t *Buff,
uint16_t Length,
uint8_t Port) {};
void HexDumpHead(const uint8_t *Buff,
uint16_t Length,
uint8_t Port) {};
#endif
#else
void USART_Init0(const uint32_t BaudRate) {};
void Serial_TxByte0(const char DataByte) {};
char Serial_RxByte0(void) {};
uint8_t Serial_ByteRecieved0(void) {};
void USART_Init1(const uint32_t BaudRate) {};
void Serial_TxByte1(const char DataByte) {};
char Serial_RxByte1(void) {};
uint8_t Serial_ByteRecieved1(void) {};
void Serial_Init(const uint32_t BaudRate0,
const uint32_t BaudRate1) {};
void cls(uint8_t Port) {};
void HexDump(const uint8_t *Buff,
uint16_t Length,
uint8_t Port) {};
void HexDumpHead(const uint8_t *Buff,
uint16_t Length,
uint8_t Port) {};
#endif

View File

@ -45,10 +45,8 @@ char *strhex4(char *buffer, uint16_t i);
#ifdef SERIAL_STATUS
#define log0(format,...) fprintf_P(&ser0stream,PSTR(format),##__VA_ARGS__)
#define log1(format,...) fprintf_P(&ser1stream,PSTR(format),##__VA_ARGS__)
#else
#define log0(format,...)
#define log1(format,...)
#endif
//
@ -56,7 +54,6 @@ char *strhex4(char *buffer, uint16_t i);
//
extern FILE ser0stream;
extern FILE ser1stream;
/* Default baud rate if 0 passed to Serial_Init */
@ -88,21 +85,8 @@ void Serial_TxByte0(const char DataByte);
char Serial_RxByte0(void);
uint8_t Serial_ByteRecieved0(void);
void USART_Init1(const uint32_t BaudRate);
void Serial_TxByte1(const char DataByte);
char Serial_RxByte1(void);
uint8_t Serial_ByteRecieved1(void);
void Serial_Init(const uint32_t BaudRate0);
void Serial_Init(const uint32_t BaudRate0,
const uint32_t BaudRate1);
void cls(uint8_t Port);
void HexDump(const uint8_t *Buff,
uint16_t Length,
uint8_t Port);
void HexDumpHead(const uint8_t *Buff,
uint16_t Length,
uint8_t Port);
void cls();
#endif