simualtor I/O refactoring - better names and removing duplication
This commit is contained in:
parent
f4b26c071c
commit
fcbf67c7d7
|
@ -27,11 +27,11 @@ static thread_t *cdtp;
|
|||
|
||||
#define cputs(msg) chMsgSend(cdtp, (msg_t)msg)
|
||||
|
||||
void printToWin32Console(char *p) {
|
||||
void printToConsole(char *p) {
|
||||
cputs(p);
|
||||
}
|
||||
|
||||
TestStream testStream;
|
||||
SerialAdapter_t serialAdapterInstance;
|
||||
|
||||
/*
|
||||
* 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) {
|
||||
|
||||
initTestStream(&testStream);
|
||||
initTestStream(&serialAdapterInstance);
|
||||
|
||||
/*
|
||||
* System initializations.
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
/**
|
||||
* 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);
|
||||
#define getSlowAdcCounter() 0
|
||||
|
|
|
@ -27,7 +27,7 @@ efitimesec_t getTimeNowSeconds(void) {
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ static char putMessageBuffer[2];
|
|||
static msg_t wt_put(void *ip, uint8_t b) {
|
||||
putMessageBuffer[0] = b;
|
||||
putMessageBuffer[1] = 0;
|
||||
printToWin32Console((char*)putMessageBuffer);
|
||||
printToConsole((char*)putMessageBuffer);
|
||||
// cputs("wt_put");
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ extern "C"
|
|||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
void initTestStream(TestStream *ts);
|
||||
void initTestStream(SerialAdapter_t *ts);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -56,24 +56,20 @@
|
|||
#define UTILITY_THREAD_STACK_SIZE 1384
|
||||
|
||||
/**
|
||||
* @brief @p Win32TestStream virtual methods table.
|
||||
*
|
||||
*/
|
||||
struct Win32TestStreamVMT {
|
||||
_base_channel_methods
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
const struct Win32TestStreamVMT *vmt;
|
||||
} TestStream;
|
||||
const struct BaseChannelVMT *vmt;
|
||||
} SerialAdapter_t;
|
||||
|
||||
extern TestStream testStream;
|
||||
extern SerialAdapter_t serialAdapterInstance;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
void printToWin32Console(char *p);
|
||||
void printToConsole(char *p);
|
||||
|
||||
int getRemainingStack(thread_t *otp);
|
||||
|
||||
|
|
|
@ -56,15 +56,15 @@ static void assertString(const char*actual, const char *expected) {
|
|||
}
|
||||
|
||||
static void runChprintfTest() {
|
||||
static MemoryStream testStream;
|
||||
static MemoryStream ts;
|
||||
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
|
||||
testStream.eos = 0; // reset
|
||||
chprintf((BaseSequentialStream*)&testStream, "%.2f/%.4f/%.4f", 0.239f, 239.932, 0.1234);
|
||||
testStream.buffer[testStream.eos] = 0;
|
||||
ts.eos = 0; // reset
|
||||
chprintf((BaseSequentialStream*)&ts, "%.2f/%.4f/%.4f", 0.239f, 239.932, 0.1234);
|
||||
ts.buffer[ts.eos] = 0;
|
||||
|
||||
assertString(testBuffer, "0.23/239.9320/0.1234");
|
||||
|
||||
|
@ -91,10 +91,10 @@ static void runChprintfTest() {
|
|||
}
|
||||
|
||||
void rusEfiFunctionalTest(void) {
|
||||
printToWin32Console("Running rusEfi simulator version:");
|
||||
printToConsole("Running rusEfi simulator version:");
|
||||
static char versionBuffer[20];
|
||||
itoa10(versionBuffer, (int)getRusEfiVersion());
|
||||
printToWin32Console(versionBuffer);
|
||||
printToConsole(versionBuffer);
|
||||
|
||||
initIntermediateLoggingBuffer();
|
||||
initErrorHandling();
|
||||
|
|
Loading…
Reference in New Issue