__attribute__((weak)) void board_thread(void* arg) { for(;;) { caribou_thread_yield(); } }
/** ************************************************************************** ** @brief Fetch last message from the queue. ** @param queue The queue to operate on. ** @return Return the message pointer or NULL. *****************************************************************************/ caribou_queue_msg_t* caribou_queue_take_last(caribou_queue_t* queue, caribou_tick_t timeout) { caribou_queue_msg_t* rc; caribou_tick_t start = caribou_timer_ticks(); while ( (rc=caribou_queue_try_take_last(queue)) == NULL && !caribou_timer_ticks_timeout(start,timeout) ) caribou_thread_yield(); return rc; }
/** ************************************************************************** ** @brief Post a message to the queue and block while there is no space in ** the queue. ** @param queue The queue to operate on. ** @param msg A pointer to the message to insert. ** @return If the message was posted return true. *****************************************************************************/ bool caribou_queue_post(caribou_queue_t* queue, caribou_queue_msg_t* msg, caribou_tick_t timeout) { caribou_tick_t start = caribou_timer_ticks(); while( !caribou_queue_try_post(queue,msg) ) { if ( caribou_timer_ticks_timeout(start,timeout) ) return false; caribou_thread_yield(); } return true; }
/** ************************************************************************** ** @brief This operation atomically decreases the semaphore counter. ** @param semaphore The semaphore to operate on. ** @return true of the semaphore was released. *****************************************************************************/ bool caribou_semaphore_wait(caribou_semaphore_t* semaphore, caribou_tick_t timeout) { bool rc=true; caribou_tick_t start = caribou_timer_ticks(); while ( !(rc=caribou_semaphore_try_wait(semaphore)) ) { if ( caribou_timer_ticks_timeout(start,timeout) ) { rc = false; break; } caribou_thread_yield(); } return rc; }
/** Wait for a semaphore for the specified timeout * @param sem the semaphore to wait for * @param timeout timeout in milliseconds to wait (0 = wait forever) * @return time (in milliseconds) waited for the semaphore * or SYS_ARCH_TIMEOUT on timeout */ u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout) { uint64_t start_time = caribou_timer_ticks(); uint64_t now = start_time; while ( !caribou_semaphore_down_trylock(*sem) && (timeout==0 || to_ms(((now=caribou_timer_ticks())-start_time)) <= timeout ) ) { if ( timeout && (now - start_time >= timeout) ) { return SYS_ARCH_TIMEOUT; } caribou_thread_yield(); } return to_ms(caribou_timer_ticks() - start_time); }
/** 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) { uint64_t start_time = caribou_timer_ticks(); uint64_t now = start_time; while ( !caribou_queue_try_fetch(*mbox,msg) && ( timeout==0 || to_ms(((now=caribou_timer_ticks())-start_time)) <= timeout ) ) { if ( timeout && ( (now-start_time) >= timeout) ) { return SYS_ARCH_TIMEOUT; } caribou_thread_yield(); } return to_ms(caribou_timer_ticks() - start_time); }