Firmware: cleaned up status.c

Change-Id: I59a54b89cf3eb701a10953f4a4450ee0c64b862c
This commit is contained in:
David Banks 2019-11-10 17:42:55 +00:00
parent f841079548
commit b28e49dbd9
3 changed files with 103 additions and 112 deletions

View File

@ -8,118 +8,23 @@
*/
#include <avr/interrupt.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include "terminalcodes.h"
#include "status.h"
/********************************************************
* Simple string logger, as log0 is expensive
********************************************************/
void logc(char c) {
Serial_TxByte0(c);
if (c == '\n') {
Serial_TxByte0('\r');
}
}
void logs(const char *s) {
while (*s) {
logc(*s++);
}
}
void logpgmstr(const char *s) {
char c;
do {
c = pgm_read_byte(s++);
if (c) {
logc(c);
}
} while (c);
}
char hex1(uint8_t i) {
i &= 0x0f;
if (i < 10) {
i += '0';
} else {
i += ('A' - 10);
}
return i;
}
void loghex1(uint8_t i) {
logc(hex1(i));
}
void loghex2(uint8_t i) {
loghex1(i >> 4);
loghex1(i);
}
void loghex4(uint16_t i) {
loghex2(i >> 8);
loghex2(i);
}
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;
}
//void loglong(long i) {
// char buffer[16];
// // ltoa adds 176 bytes
// logs(ltoa(i, buffer, 10));
//}
//
//void logint(int i) {
// char buffer[16];
// // itoa adds 176 bytes
// logs(itoa(i, buffer, 10));
//}
#ifdef SERIAL_STATUS
static int StdioSerial_TxByte0(char DataByte, FILE *Stream);
FILE ser0stream = FDEV_SETUP_STREAM(StdioSerial_TxByte0,NULL,_FDEV_SETUP_WRITE);
void StdioSerial_TxByte(char DataByte)
{
#ifdef COOKED_SERIAL
if((DataByte=='\r') || (DataByte=='\n'))
{
Serial_TxByte0('\r');
Serial_TxByte0('\n');
}
else
#endif
Serial_TxByte0(DataByte);
if((DataByte=='\r') || (DataByte=='\n')) {
Serial_TxByte0('\r');
Serial_TxByte0('\n');
} else {
Serial_TxByte0(DataByte);
}
}
int StdioSerial_TxByte0(char DataByte, FILE *Stream)
@ -199,4 +104,94 @@ void Serial_Init(const uint32_t BaudRate0)
cls();
}
#endif
/********************************************************
* Simple string logger, as log0 is expensive
********************************************************/
void logc(char c) {
StdioSerial_TxByte(c);
}
void logs(const char *s) {
while (*s) {
logc(*s++);
}
}
void logpgmstr(const char *s) {
char c;
do {
c = pgm_read_byte(s++);
if (c) {
logc(c);
}
} while (c);
}
char hex1(uint8_t i) {
i &= 0x0f;
if (i < 10) {
i += '0';
} else {
i += ('A' - 10);
}
return i;
}
void loghex1(uint8_t i) {
logc(hex1(i));
}
void loghex2(uint8_t i) {
loghex1(i >> 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);
}

View File

@ -34,20 +34,16 @@ void logpgmstr(const char *s);
void loghex1(uint8_t i);
void loghex2(uint8_t i);
void loghex4(uint16_t i);
void logint(int i);
void loglong(long i);
char *strfill(char *buffer, char c, uint8_t i);
char *strhex1(char *buffer, uint8_t i);
char *strhex2(char *buffer, uint8_t i);
char *strhex4(char *buffer, uint16_t i);
char *strint(char *buffer, int i);
char *strlong(char *buffer, long i);
//void loglong(long i);
//void logint(int i);
#ifdef SERIAL_STATUS
#define log0(format,...) fprintf_P(&ser0stream,PSTR(format),##__VA_ARGS__)
#else
#define log0(format,...)
#endif
//
// For stdio

View File

@ -18,7 +18,7 @@ OBJCOPY=avr-objcopy
PROG = avr_progmem
CFLAGS=$(CPU_CFLAGS) -DF_CPU=${F_CPU}UL -DSERIAL_STATUS -DCOOKED_SERIAL -DNOUSART1 -mmcu=$(MCU) -Wall -Os -mcall-prologues
CFLAGS=$(CPU_CFLAGS) -DF_CPU=${F_CPU}UL -mmcu=$(MCU) -Wall -Os -mcall-prologues
OBJECTS=AtomBusMon.o status.o $(CPU_OBJECTS)