예제 #1
0
/** Wait for a new message to arrive in the mbox
 * @param mbox mbox to get a message from
 * @param msg pointer where the message is stored
 * @param timeout maximum time (in milliseconds) to wait for a message
 * @return time (in milliseconds) waited for a message, may be 0 if not waited
 *         or SYS_ARCH_TIMEOUT on timeout
 *         The returned time has to be accurate to prevent timer jitter! */
u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout)
{
	u32_t rc = SYS_ARCH_TIMEOUT;
	caribou_tick_t start = caribou_timer_ticks();
	if ( caribou_queue_take_first(*mbox,msg,timeout) )
	{
		return to_ms(caribou_timer_ticks()) - start;
	}
	return rc;
}
예제 #2
0
static bool dequeue_test()
{
    bool passed = true;
    
    static char message_b[MESSAGE_SZ];
    memset(message_b,'A',MESSAGE_SZ);

    for( int n=0; passed && n < QUEUE_DEPTH; n++ )
    {
		char* message_a;
		passed = caribou_queue_take_first(&test.queue_a,&message_a,from_ms(QUEUE_TIMEOUT_MS));
        if ( passed )
        {
            passed = (message_a != NULL);
            if ( passed )
            {
                passed = (memcmp(message_a,message_b,MESSAGE_SZ) == 0);
                free(message_a);
            }
        }
	}
    return passed;
}