simualtor I/O refactoring - better names and removing duplication

This commit is contained in:
rusefi 2019-02-03 20:31:42 -05:00
parent f4b26c071c
commit fcbf67c7d7
6 changed files with 21 additions and 25 deletions

View File

@ -27,11 +27,11 @@ static thread_t *cdtp;
#define cputs(msg) chMsgSend(cdtp, (msg_t)msg) #define cputs(msg) chMsgSend(cdtp, (msg_t)msg)
void printToWin32Console(char *p) { void printToConsole(char *p) {
cputs(p); cputs(p);
} }
TestStream testStream; SerialAdapter_t serialAdapterInstance;
/* /*
* Console print server done using synchronous messages. This makes the access * Console print server done using synchronous messages. This makes the access
@ -135,7 +135,7 @@ static evhandler_t fhandlers[] = { termination_handler, sd1_handler, sd2_handler
*------------------------------------------------------------------------*/ *------------------------------------------------------------------------*/
int main(void) { int main(void) {
initTestStream(&testStream); initTestStream(&serialAdapterInstance);
/* /*
* System initializations. * System initializations.

View File

@ -17,7 +17,7 @@
/** /**
* This implementation writes to both windows console and console port * This implementation writes to both windows console and console port
*/ */
#define EFI_CONSOLE_UART_DEVICE (&testStream) #define EFI_CONSOLE_UART_DEVICE (&serialAdapterInstance)
int getAdcValue(const char *msg, int channel); int getAdcValue(const char *msg, int channel);
#define getSlowAdcCounter() 0 #define getSlowAdcCounter() 0

View File

@ -27,7 +27,7 @@ efitimesec_t getTimeNowSeconds(void) {
} }
static size_t wt_writes(void *ip, const uint8_t *bp, size_t n) { static size_t wt_writes(void *ip, const uint8_t *bp, size_t n) {
printToWin32Console((char*)bp); printToConsole((char*)bp);
return CONSOLE_PORT->vmt->write(CONSOLE_PORT, bp, n); return CONSOLE_PORT->vmt->write(CONSOLE_PORT, bp, n);
} }
@ -57,7 +57,7 @@ static char putMessageBuffer[2];
static msg_t wt_put(void *ip, uint8_t b) { static msg_t wt_put(void *ip, uint8_t b) {
putMessageBuffer[0] = b; putMessageBuffer[0] = b;
putMessageBuffer[1] = 0; putMessageBuffer[1] = 0;
printToWin32Console((char*)putMessageBuffer); printToConsole((char*)putMessageBuffer);
// cputs("wt_put"); // cputs("wt_put");
return CONSOLE_PORT->vmt->put(CONSOLE_PORT, b); return CONSOLE_PORT->vmt->put(CONSOLE_PORT, b);
} }
@ -68,8 +68,8 @@ static msg_t wt_get(void *ip) {
return CONSOLE_PORT->vmt->get(CONSOLE_PORT); return CONSOLE_PORT->vmt->get(CONSOLE_PORT);
} }
static const struct Win32TestStreamVMT vmt = { wt_writes, wt_reads, wt_put, wt_get, wt_putt, wt_gett, wt_writet, wt_readt }; static const struct BaseChannelVMT vmt = { wt_writes, wt_reads, wt_put, wt_get, wt_putt, wt_gett, wt_writet, wt_readt };
void initTestStream(TestStream *ts) { void initTestStream(SerialAdapter_t *ts) {
ts->vmt = &vmt; ts->vmt = &vmt;
} }

View File

@ -12,7 +12,7 @@ extern "C"
{ {
#endif /* __cplusplus */ #endif /* __cplusplus */
void initTestStream(TestStream *ts); void initTestStream(SerialAdapter_t *ts);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -56,24 +56,20 @@
#define UTILITY_THREAD_STACK_SIZE 1384 #define UTILITY_THREAD_STACK_SIZE 1384
/** /**
* @brief @p Win32TestStream virtual methods table. *
*/ */
struct Win32TestStreamVMT {
_base_channel_methods
};
typedef struct { typedef struct {
const struct Win32TestStreamVMT *vmt; const struct BaseChannelVMT *vmt;
} TestStream; } SerialAdapter_t;
extern TestStream testStream; extern SerialAdapter_t serialAdapterInstance;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
{ {
#endif /* __cplusplus */ #endif /* __cplusplus */
void printToWin32Console(char *p); void printToConsole(char *p);
int getRemainingStack(thread_t *otp); int getRemainingStack(thread_t *otp);

View File

@ -56,15 +56,15 @@ static void assertString(const char*actual, const char *expected) {
} }
static void runChprintfTest() { static void runChprintfTest() {
static MemoryStream testStream; static MemoryStream ts;
static char testBuffer[200]; static char testBuffer[200];
msObjectInit(&testStream, (uint8_t *) testBuffer, sizeof(testBuffer), 0); msObjectInit(&ts, (uint8_t *) testBuffer, sizeof(testBuffer), 0);
// it's a very, very long and mostly forgotten story how this became our %.2f precision format // it's a very, very long and mostly forgotten story how this became our %.2f precision format
testStream.eos = 0; // reset ts.eos = 0; // reset
chprintf((BaseSequentialStream*)&testStream, "%.2f/%.4f/%.4f", 0.239f, 239.932, 0.1234); chprintf((BaseSequentialStream*)&ts, "%.2f/%.4f/%.4f", 0.239f, 239.932, 0.1234);
testStream.buffer[testStream.eos] = 0; ts.buffer[ts.eos] = 0;
assertString(testBuffer, "0.23/239.9320/0.1234"); assertString(testBuffer, "0.23/239.9320/0.1234");
@ -91,10 +91,10 @@ static void runChprintfTest() {
} }
void rusEfiFunctionalTest(void) { void rusEfiFunctionalTest(void) {
printToWin32Console("Running rusEfi simulator version:"); printToConsole("Running rusEfi simulator version:");
static char versionBuffer[20]; static char versionBuffer[20];
itoa10(versionBuffer, (int)getRusEfiVersion()); itoa10(versionBuffer, (int)getRusEfiVersion());
printToWin32Console(versionBuffer); printToConsole(versionBuffer);
initIntermediateLoggingBuffer(); initIntermediateLoggingBuffer();
initErrorHandling(); initErrorHandling();