Firmware: move logging to status.c

Change-Id: Id3fada3d5902ca9e81794020b24f1f480870e986
This commit is contained in:
David Banks 2019-11-09 14:18:47 +00:00
parent 877e075b4d
commit a46db8f641
3 changed files with 116 additions and 98 deletions

View File

@ -481,67 +481,6 @@ uint8_t error_flag = 0;
#define MASK_CLOCK_ERROR 1
#define MASK_TIMEOUT_ERROR 2
/********************************************************
* 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++);
}
}
#define logstr(s) logpgmstr(PSTR((s)))
void logpgmstr(const char *s) {
char c;
do {
c = pgm_read_byte(s++);
if (c) {
logc(c);
}
} while (c);
}
void loghex1(uint8_t i) {
i &= 0x0f;
if (i < 10) {
i += '0';
} else {
i += ('A' - 10);
}
logc(i);
}
void loghex2(uint8_t i) {
loghex1(i >> 4);
loghex1(i);
}
void loghex4(uint16_t i) {
loghex2(i >> 8);
loghex2(i);
}
//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));
//}
/********************************************************
* User Command Processor
********************************************************/

View File

@ -14,6 +14,67 @@
#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);
}
void loghex1(uint8_t i) {
i &= 0x0f;
if (i < 10) {
i += '0';
} else {
i += ('A' - 10);
}
logc(i);
}
void loghex2(uint8_t i) {
loghex1(i >> 4);
loghex1(i);
}
void loghex4(uint16_t i) {
loghex2(i >> 8);
loghex2(i);
}
//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);

View File

@ -20,6 +20,24 @@
#ifndef __STATUS_DEFINES__
#define __STATUS_DEFINES__
/********************************************************
* Simple string logger, as log0 is expensive
********************************************************/
#define logstr(s) logpgmstr(PSTR((s)))
void logc(char c);
void logs(const char *s);
void logpgmstr(const char *s);
void loghex1(uint8_t i);
void loghex2(uint8_t i);
void loghex4(uint16_t i);
//void loglong(long i);
//void logint(int i);
#ifdef SERIAL_STATUS
#define log0(format,...) fprintf_P(&ser0stream,PSTR(format),##__VA_ARGS__)
#define log1(format,...) fprintf_P(&ser1stream,PSTR(format),##__VA_ARGS__)