static void queues1_execute(void) { unsigned i; size_t n; /* Initial empty state */ test_assert_lock(1, chIQIsEmptyI(&iq), "not empty"); /* Queue filling */ chSysLock(); for (i = 0; i < TEST_QUEUES_SIZE; i++) chIQPutI(&iq, 'A' + i); chSysUnlock(); test_assert_lock(2, chIQIsFullI(&iq), "still has space"); test_assert_lock(3, chIQPutI(&iq, 0) == Q_FULL, "failed to report Q_FULL"); /* Queue emptying */ for (i = 0; i < TEST_QUEUES_SIZE; i++) test_emit_token(chIQGet(&iq)); test_assert_lock(4, chIQIsEmptyI(&iq), "still full"); test_assert_sequence(5, "ABCD"); /* Queue filling again */ chSysLock(); for (i = 0; i < TEST_QUEUES_SIZE; i++) chIQPutI(&iq, 'A' + i); chSysUnlock(); /* Reading the whole thing */ n = chIQReadTimeout(&iq, wa[1], TEST_QUEUES_SIZE * 2, TIME_IMMEDIATE); test_assert(6, n == TEST_QUEUES_SIZE, "wrong returned size"); test_assert_lock(7, chIQIsEmptyI(&iq), "still full"); /* Queue filling again */ chSysLock(); for (i = 0; i < TEST_QUEUES_SIZE; i++) chIQPutI(&iq, 'A' + i); chSysUnlock(); /* 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_lock(10, chIQIsEmptyI(&iq), "still full"); /* Testing reset */ chSysLock(); chIQPutI(&iq, 0); chIQResetI(&iq); chSysUnlock(); test_assert_lock(11, chIQGetFullI(&iq) == 0, "still full"); threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriorityX()+1, thread1, NULL); test_assert_lock(12, chIQGetFullI(&iq) == 0, "not empty"); test_wait_threads(); /* Timeout */ test_assert(13, chIQGetTimeout(&iq, 10) == Q_TIMEOUT, "wrong timeout return"); }
static void writeOscQueue( InputQueue * q ) { msg_t msg; uint8_t noData; size_t cnt, i; chSysLock(); cnt = (chQSpaceI( q ) / 2) * 2; chSysUnlock(); // And just limit send data size to ensure USB chip will not overfull. cnt = ( cnt <= USB_FIFO_SZ ) ? cnt : USB_FIFO_SZ; for ( i=0; i<cnt; i++ ) { msg = chIQGetTimeout( q, TIME_IMMEDIATE ); noData = ( ( msg == Q_TIMEOUT ) || ( msg == Q_RESET ) ) ? 1 : 0; uint8_t v; v = ( noData ) ? 0 : (uint8_t)msg; writeResult( v ); } writeEom(); }
static msg_t gett(void *ip, systime_t timeout) { return chIQGetTimeout(&((BulkUSBDriver *)ip)->iqueue, timeout); }
static msg_t get(void *ip) { return chIQGetTimeout(&((BulkUSBDriver *)ip)->iqueue, TIME_INFINITE); }
static msg_t thread1(void *p) { (void)p; chIQGetTimeout(&iq, MS2ST(200)); return 0; }
msg_t InQueue::getTimeout(systime_t time) { return chIQGetTimeout(&iq, time); }