diff --git a/os/hal/platforms/Linux/console.c b/os/hal/platforms/Linux/console.c index c7b71823a..0c47ff491 100644 --- a/os/hal/platforms/Linux/console.c +++ b/os/hal/platforms/Linux/console.c @@ -45,6 +45,19 @@ BaseChannel CD1; /* Driver local functions. */ /*===========================================================================*/ + +static size_t writes(void *ip, const uint8_t *bp, size_t n) { + + (void)ip; + return fwrite(bp, 1, n, stdout); +} + +static size_t reads(void *ip, uint8_t *bp, size_t n) { + + (void)ip; + return fread(bp, 1, n, stdin); +} + static bool_t putwouldblock(void *ip) { (void)ip; @@ -57,24 +70,39 @@ static bool_t getwouldblock(void *ip) { return TRUE; } -static msg_t put(void *ip, uint8_t b, systime_t timeout) { +static msg_t putt(void *ip, uint8_t b, systime_t time) { (void)ip; - (void)timeout; + (void)time; fputc(b, stdout); fflush(stdout); return RDY_OK; } -static msg_t get(void *ip, systime_t timeout) { +static msg_t gett(void *ip, systime_t time) { (void)ip; - (void)timeout; + (void)time; return fgetc(stdin); } +static size_t writet(void *ip, const uint8_t *bp, size_t n, systime_t time) { + + (void)ip; + (void)time; + return fwrite(bp, 1, n, stdout); +} + +static size_t readt(void *ip, uint8_t *bp, size_t n, systime_t time) { + + (void)ip; + (void)time; + return fread(bp, 1, n, stdin); +} + static const struct BaseChannelVMT vmt = { - {putwouldblock, getwouldblock, put, get} + {writes, reads}, + {putwouldblock, getwouldblock, putt, gett, writet, readt} }; /*===========================================================================*/ diff --git a/os/hal/platforms/Win32/console.c b/os/hal/platforms/Win32/console.c index c7b71823a..0c47ff491 100644 --- a/os/hal/platforms/Win32/console.c +++ b/os/hal/platforms/Win32/console.c @@ -45,6 +45,19 @@ BaseChannel CD1; /* Driver local functions. */ /*===========================================================================*/ + +static size_t writes(void *ip, const uint8_t *bp, size_t n) { + + (void)ip; + return fwrite(bp, 1, n, stdout); +} + +static size_t reads(void *ip, uint8_t *bp, size_t n) { + + (void)ip; + return fread(bp, 1, n, stdin); +} + static bool_t putwouldblock(void *ip) { (void)ip; @@ -57,24 +70,39 @@ static bool_t getwouldblock(void *ip) { return TRUE; } -static msg_t put(void *ip, uint8_t b, systime_t timeout) { +static msg_t putt(void *ip, uint8_t b, systime_t time) { (void)ip; - (void)timeout; + (void)time; fputc(b, stdout); fflush(stdout); return RDY_OK; } -static msg_t get(void *ip, systime_t timeout) { +static msg_t gett(void *ip, systime_t time) { (void)ip; - (void)timeout; + (void)time; return fgetc(stdin); } +static size_t writet(void *ip, const uint8_t *bp, size_t n, systime_t time) { + + (void)ip; + (void)time; + return fwrite(bp, 1, n, stdout); +} + +static size_t readt(void *ip, uint8_t *bp, size_t n, systime_t time) { + + (void)ip; + (void)time; + return fread(bp, 1, n, stdin); +} + static const struct BaseChannelVMT vmt = { - {putwouldblock, getwouldblock, put, get} + {writes, reads}, + {putwouldblock, getwouldblock, putt, gett, writet, readt} }; /*===========================================================================*/ diff --git a/test/testqueues.c b/test/testqueues.c index c07e8aee3..6c16cce63 100644 --- a/test/testqueues.c +++ b/test/testqueues.c @@ -112,13 +112,24 @@ static void queues1_execute(void) { test_assert(6, n == TEST_QUEUES_SIZE, "wrong returned size"); test_assert(7, chIQIsEmpty(&iq), "still full"); + /* Queue filling again */ + for (i = 0; i < TEST_QUEUES_SIZE; i++) + chIQPutI(&iq, 'A' + i); + + /* Partial reads */ + n = chIQReadTimeout(&iq, wa[1], TEST_QUEUES_SIZE / 2, TIME_IMMEDIATE); + test_assert(8, n == TEST_QUEUES_SIZE / 2, "wrong returned size"); + n = chIQReadTimeout(&iq, wa[1], TEST_QUEUES_SIZE / 2, TIME_IMMEDIATE); + test_assert(9, n == TEST_QUEUES_SIZE / 2, "wrong returned size"); + test_assert(10, chIQIsEmpty(&iq), "still full"); + /* Testing reset */ chIQPutI(&iq, 0); chIQResetI(&iq); - test_assert(8, chIQIsEmpty(&iq), "still full"); + test_assert(11, chIQIsEmpty(&iq), "still full"); /* Timeout */ - test_assert(9, chIQGetTimeout(&iq, 10) == Q_TIMEOUT, "wrong timeout return"); + test_assert(12, chIQGetTimeout(&iq, 10) == Q_TIMEOUT, "wrong timeout return"); } const struct testcase testqueues1 = { @@ -167,18 +178,22 @@ static void queues2_execute(void) { /* Writing the whole thing */ n = chOQWriteTimeout(&oq, wa[1], TEST_QUEUES_SIZE * 2, TIME_IMMEDIATE); - test_assert(6, n == TEST_QUEUES_SIZE,"wrong returned size"); + test_assert(6, n == TEST_QUEUES_SIZE, "wrong returned size"); test_assert(7, chOQIsFull(&oq), "not full"); /* Testing reset */ chOQResetI(&oq); test_assert(8, chOQIsEmpty(&oq), "still full"); + /* Partial writes */ + n = chOQWriteTimeout(&oq, wa[1], TEST_QUEUES_SIZE / 2, TIME_IMMEDIATE); + test_assert(9, n == TEST_QUEUES_SIZE / 2, "wrong returned size"); + n = chOQWriteTimeout(&oq, wa[1], TEST_QUEUES_SIZE / 2, TIME_IMMEDIATE); + test_assert(10, n == TEST_QUEUES_SIZE / 2, "wrong returned size"); + test_assert(11, chOQIsFull(&oq), "not full"); + /* Timeout */ - for (i = 0; i < TEST_QUEUES_SIZE; i++) - chOQPut(&oq, 'A' + i); - test_assert(9, chOQIsFull(&oq), "still has space"); - test_assert(10, chOQPutTimeout(&oq, 0, 10) == Q_TIMEOUT, "wrong timeout return"); + test_assert(12, chOQPutTimeout(&oq, 0, 10) == Q_TIMEOUT, "wrong timeout return"); } const struct testcase testqueues2 = {