void initNanoObjects(void) { nano_fifo_init(&nanoFifoObj); nano_fifo_init(&nanoFifoObj2); nano_sem_init(&nanoSemObj1); nano_sem_init(&nanoSemObj2); nano_sem_init(&nanoSemObj3); nano_sem_init(&nanoSemObjTask); nano_timer_init(&timer, timerData); } /* initNanoObjects */
static void init_tx_queue(void) { nano_fifo_init(&netdev.tx_queue); fiber_start(tx_fiber_stack, sizeof(tx_fiber_stack), (nano_fiber_entry_t) net_tx_fiber, 0, 0, 7, 0); }
void zephyr_getline_init(void) { int i; nano_fifo_init(&used_queue); nano_fifo_init(&free_queue); for (i = 0; i < sizeof(line_bufs) / sizeof(*line_bufs); i++) { nano_fifo_put(&free_queue, &line_bufs[i]); } /* Zephyr UART handler takes an empty buffer from free_queue, stores UART input in it until EOL, and then puts it into used_queue. */ uart_register_input(&free_queue, &used_queue, NULL); }
void shell_init(const char *str, const struct shell_cmd *cmds) { nano_fifo_init(&cmds_queue); nano_fifo_init(&avail_queue); commands = cmds; line_queue_init(); prompt = str ? str : ""; task_fiber_start(stack, STACKSIZE, shell, 0, 0, 7, 0); /* Register serial console handler */ uart_register_input(&avail_queue, &cmds_queue, completion); }
void tester_init(void) { int i; nano_fifo_init(&cmds_queue); nano_fifo_init(&avail_queue); for (i = 0; i < CMD_QUEUED; i++) { nano_fifo_put(&avail_queue, &cmd_buf[i * BTP_MTU]); } task_fiber_start(stack, STACKSIZE, cmd_handler, 0, 0, 7, 0); uart_pipe_register(nano_fifo_get(&avail_queue, TICKS_NONE), BTP_MTU, recv_cb); printk("BT tester initialized\n"); }
int sol_mainloop_impl_platform_init(void) { int i; sol_mainloop_zephyr_common_init(); nano_fifo_init(&_sol_mainloop_pending_events); nano_fifo_init(&_sol_mainloop_free_events); for (i = 0; i < SOL_UTIL_ARRAY_SIZE(_events); i++) { struct me_fifo_entry *mfe; mfe = &_events[i]; nano_fifo_put(&_sol_mainloop_free_events, mfe); } return 0; }
int sol_mainloop_impl_platform_init(void) { int i; main_thread_id = sys_thread_self_get(); nano_sem_init(&_sol_mainloop_lock); nano_sem_give(&_sol_mainloop_lock); nano_fifo_init(&_sol_mainloop_pending_events); nano_fifo_init(&_sol_mainloop_free_events); for (i = 0; i < sol_util_array_size(_events); i++) { struct me_fifo_entry *mfe; mfe = &_events[i]; nano_fifo_put(&_sol_mainloop_free_events, mfe); } return 0; }
void initNanoObjects(void) { struct isrInitInfo i = { {isr_fifo_put, isr_fifo_get}, {&isrFifoInfo, &isrFifoInfo}, }; (void)initIRQ(&i); nano_fifo_init(&nanoFifoObj); nano_fifo_init(&nanoFifoObj2); nano_sem_init(&nanoSemObj1); nano_sem_init(&nanoSemObj2); nano_sem_init(&nanoSemObj3); nano_sem_init(&nanoSemObjTask); nano_timer_init(&timer, timerData); } /* initNanoObjects */
int initNanoObjects(void) { nano_sem_init(&wakeFiber); nano_timer_init(&timer, timerData); nano_fifo_init(&timeout_order_fifo); /* no nanoCpuExcConnect on Cortex-M3/M4 */ #if !defined(CONFIG_CPU_CORTEX_M3_M4) nanoCpuExcConnect(IV_DIVIDE_ERROR, exc_divide_error_handler); #endif return TC_PASS; }
static void h5_init(void) { BT_DBG(""); h5.link_state = UNINIT; h5.rx_state = START; h5.tx_win = 4; /* TX fiber */ nano_fifo_init(&h5.tx_queue); fiber_start(tx_stack, sizeof(tx_stack), (nano_fiber_entry_t)tx_fiber, 0, 0, 7, 0); /* RX fiber */ net_buf_pool_init(signal_pool); nano_fifo_init(&h5.rx_queue); fiber_start(rx_stack, sizeof(rx_stack), (nano_fiber_entry_t)rx_fiber, 0, 0, 7, 0); /* Unack queue */ nano_fifo_init(&h5.unack_queue); }
void net_context_init(void) { int i; nano_sem_init(&contexts_lock); memset(contexts, 0, sizeof(contexts)); for (i = 0; i < NET_MAX_CONTEXT; i++) { nano_fifo_init(&contexts[i].rx_queue); } context_sem_give(&contexts_lock); }
/* Delayed fiber taking care about retransmitting packets */ static void retx_fiber(int arg1, int arg2) { ARG_UNUSED(arg1); ARG_UNUSED(arg2); BT_DBG("unack_queue_len %u", unack_queue_len); h5.retx_to = NULL; if (unack_queue_len) { struct nano_fifo tmp_queue; struct net_buf *buf; nano_fifo_init(&tmp_queue); /* Queue to temperary queue */ while ((buf = nano_fifo_get(&h5.tx_queue, TICKS_NONE))) { nano_fifo_put(&tmp_queue, buf); } /* Queue unack packets to the beginning of the queue */ while ((buf = nano_fifo_get(&h5.unack_queue, TICKS_NONE))) { /* include also packet type */ net_buf_push(buf, sizeof(uint8_t)); nano_fifo_put(&h5.tx_queue, buf); h5.tx_seq = (h5.tx_seq - 1) & 0x07; unack_queue_len--; } /* Queue saved packets from temp queue */ while ((buf = nano_fifo_get(&tmp_queue, TICKS_NONE))) { nano_fifo_put(&h5.tx_queue, buf); } /* Analyze stack */ stack_analyze("retx_stack", retx_stack, sizeof(retx_stack)); } }
void main(void) { int rv = TC_PASS; nano_fifo_init(&fifo); errno = errno_values[N_FIBERS]; printk("task, errno before starting fibers: %x\n", errno); for (int ii = 0; ii < N_FIBERS; ii++) { result[ii].pass = TC_FAIL; } for (int ii = 0; ii < N_FIBERS; ii++) { task_fiber_start(stacks[ii], STACK_SIZE, errno_fiber, ii, errno_values[ii], ii + 5, 0); } for (int ii = 0; ii < N_FIBERS; ii++) { struct result *p = nano_task_fifo_get(&fifo, 10); if (!p || !p->pass) { rv = TC_FAIL; } } printk("task, errno after running fibers: %x\n", errno); if (errno != errno_values[N_FIBERS]) { rv = TC_FAIL; } TC_END_RESULT(rv); TC_END_REPORT(rv); }
/* the timeout test entry point */ static int test_timeout(void) { int64_t orig_ticks; int32_t timeout; int rv; void *packet, *scratch_packet; int test_data_size; int ii; struct reply_packet reply_packet; nano_lifo_init(&lifo_timeout[0]); nano_lifo_init(&lifo_timeout[1]); nano_fifo_init(&timeout_order_fifo); nano_fifo_init(&scratch_q_packets_fifo); for (ii = 0; ii < NUM_SCRATCH_Q_PACKETS; ii++) { scratch_q_packets[ii].data_if_needed = (void *)ii; nano_task_fifo_put(&scratch_q_packets_fifo, &scratch_q_packets[ii]); } /* test nano_task_lifo_get() with timeout */ timeout = 10; orig_ticks = sys_tick_get(); packet = nano_task_lifo_get(&lifo_timeout[0], timeout); if (packet) { TC_ERROR(" *** timeout of %d did not time out.\n", timeout); return TC_FAIL; } if ((sys_tick_get() - orig_ticks) < timeout) { TC_ERROR(" *** task did not wait long enough on timeout of %d.\n", timeout); return TC_FAIL; } /* test nano_task_lifo_get() with timeout of 0 */ packet = nano_task_lifo_get(&lifo_timeout[0], 0); if (packet) { TC_ERROR(" *** timeout of 0 did not time out.\n"); return TC_FAIL; } /* test nano_task_lifo_get() with timeout > 0 */ TC_PRINT("test nano_task_lifo_get() with timeout > 0\n"); timeout = 3; orig_ticks = sys_tick_get(); packet = nano_task_lifo_get(&lifo_timeout[0], timeout); if (packet) { TC_ERROR(" *** timeout of %d did not time out.\n", timeout); return TC_FAIL; } if (!is_timeout_in_range(orig_ticks, timeout)) { return TC_FAIL; } TC_PRINT("nano_task_lifo_get() timed out as expected\n"); /* * test nano_task_lifo_get() with a timeout and fiber that puts * data on the lifo on time */ timeout = 5; orig_ticks = sys_tick_get(); task_fiber_start(timeout_stacks[0], FIBER_STACKSIZE, test_fiber_put_timeout, (int)&lifo_timeout[0], timeout, FIBER_PRIORITY, 0); packet = nano_task_lifo_get(&lifo_timeout[0], (int)(timeout + 5)); if (!packet) { TC_ERROR(" *** data put in time did not return valid pointer.\n"); return TC_FAIL; } put_scratch_packet(packet); if (!is_timeout_in_range(orig_ticks, timeout)) { return TC_FAIL; } TC_PRINT("nano_task_lifo_get() got lifo in time, as expected\n"); /* * test nano_task_lifo_get() with TICKS_NONE and no data * unavailable. */ if (nano_task_lifo_get(&lifo_timeout[0], TICKS_NONE)) { TC_ERROR("task with TICKS_NONE got data, but shouldn't have\n"); return TC_FAIL; } TC_PRINT("task with TICKS_NONE did not get data, as expected\n"); /* * test nano_task_lifo_get() with TICKS_NONE and some data * available. */ scratch_packet = get_scratch_packet(); nano_task_lifo_put(&lifo_timeout[0], scratch_packet); if (!nano_task_lifo_get(&lifo_timeout[0], TICKS_NONE)) { TC_ERROR("task with TICKS_NONE did not get available data\n"); return TC_FAIL; } put_scratch_packet(scratch_packet); TC_PRINT("task with TICKS_NONE got available data, as expected\n"); /* * test nano_task_lifo_get() with TICKS_UNLIMITED and the * data available. */ TC_PRINT("Trying to take available data with TICKS_UNLIMITED:\n" " will hang the test if it fails.\n"); scratch_packet = get_scratch_packet(); nano_task_lifo_put(&lifo_timeout[0], scratch_packet); if (!nano_task_lifo_get(&lifo_timeout[0], TICKS_UNLIMITED)) { TC_ERROR(" *** This will never be hit!!! .\n"); return TC_FAIL; } put_scratch_packet(scratch_packet); TC_PRINT("task with TICKS_UNLIMITED got available data, as expected\n"); /* test fiber with timeout of TICKS_NONE not getting data on empty lifo */ task_fiber_start(timeout_stacks[0], FIBER_STACKSIZE, test_fiber_ticks_special_values, (int)&reply_packet, TICKS_NONE, FIBER_PRIORITY, 0); if (!nano_task_fifo_get(&timeout_order_fifo, TICKS_NONE)) { TC_ERROR(" *** fiber should have run and filled the fifo.\n"); return TC_FAIL; } if (reply_packet.reply != 0) { TC_ERROR(" *** fiber should not have obtained the data.\n"); return TC_FAIL; } TC_PRINT("fiber with TICKS_NONE did not get data, as expected\n"); /* test fiber with timeout of TICKS_NONE getting data when available */ scratch_packet = get_scratch_packet(); nano_task_lifo_put(&lifo_timeout[0], scratch_packet); task_fiber_start(timeout_stacks[0], FIBER_STACKSIZE, test_fiber_ticks_special_values, (int)&reply_packet, TICKS_NONE, FIBER_PRIORITY, 0); put_scratch_packet(scratch_packet); if (!nano_task_fifo_get(&timeout_order_fifo, TICKS_NONE)) { TC_ERROR(" *** fiber should have run and filled the fifo.\n"); return TC_FAIL; } if (reply_packet.reply != 1) { TC_ERROR(" *** fiber should have obtained the data.\n"); return TC_FAIL; } TC_PRINT("fiber with TICKS_NONE got available data, as expected\n"); /* test fiber with TICKS_UNLIMITED timeout getting data when availalble */ scratch_packet = get_scratch_packet(); nano_task_lifo_put(&lifo_timeout[0], scratch_packet); task_fiber_start(timeout_stacks[0], FIBER_STACKSIZE, test_fiber_ticks_special_values, (int)&reply_packet, TICKS_UNLIMITED, FIBER_PRIORITY, 0); put_scratch_packet(scratch_packet); if (!nano_task_fifo_get(&timeout_order_fifo, TICKS_NONE)) { TC_ERROR(" *** fiber should have run and filled the fifo.\n"); return TC_FAIL; } if (reply_packet.reply != 1) { TC_ERROR(" *** fiber should have obtained the data.\n"); return TC_FAIL; } TC_PRINT("fiber with TICKS_UNLIMITED got available data, as expected\n"); /* test multiple fibers pending on the same lifo with different timeouts */ test_data_size = ARRAY_SIZE(timeout_order_data); TC_PRINT("testing timeouts of %d fibers on same lifo\n", test_data_size); rv = test_multiple_fibers_pending(timeout_order_data, test_data_size); if (rv != TC_PASS) { TC_ERROR(" *** fibers did not time out in the right order\n"); return TC_FAIL; } /* test mult. fibers pending on different lifos with different timeouts */ test_data_size = ARRAY_SIZE(timeout_order_data_mult_lifo); TC_PRINT("testing timeouts of %d fibers on different lifos\n", test_data_size); rv = test_multiple_fibers_pending(timeout_order_data_mult_lifo, test_data_size); if (rv != TC_PASS) { TC_ERROR(" *** fibers did not time out in the right order\n"); return TC_FAIL; } /* * test multiple fibers pending on same lifo with different timeouts, but * getting the data in time, except the last one. */ test_data_size = ARRAY_SIZE(timeout_order_data); TC_PRINT("testing %d fibers timing out, but obtaining the data in time\n" "(except the last one, which times out)\n", test_data_size); rv = test_multiple_fibers_get_data(timeout_order_data, test_data_size); if (rv != TC_PASS) { TC_ERROR(" *** fibers did not get the data in the right order\n"); return TC_FAIL; } return TC_PASS; }
/** * * @brief The main test entry * * @return 1 if success and 0 on failure */ int lifo_test(void) { uint32_t t; int i = 0; int return_value = 0; int element[2]; int j; nano_fifo_init(&nanoFifo_sync); /* test get wait & put fiber functions */ fprintf(output_file, sz_test_case_fmt, "LIFO #1"); fprintf(output_file, sz_description, "\n\tnano_lifo_init" "\n\tnano_fiber_lifo_get(TICKS_UNLIMITED)" "\n\tnano_fiber_lifo_put"); printf(sz_test_start_fmt); lifo_test_init(); t = BENCH_START(); task_fiber_start(fiber_stack1, STACK_SIZE, lifo_fiber1, 0, NUMBER_OF_LOOPS, 3, 0); task_fiber_start(fiber_stack2, STACK_SIZE, lifo_fiber2, (int) &i, NUMBER_OF_LOOPS, 3, 0); t = TIME_STAMP_DELTA_GET(t); return_value += check_result(i, t); /* fibers have done their job, they can stop now safely: */ for (j = 0; j < 2; j++) { nano_task_fifo_put(&nanoFifo_sync, (void *) element); } /* test get/yield & put fiber functions */ fprintf(output_file, sz_test_case_fmt, "LIFO #2"); fprintf(output_file, sz_description, "\n\tnano_lifo_init" "\n\tnano_fiber_lifo_get(TICKS_UNLIMITED)" "\n\tnano_fiber_lifo_get(TICKS_NONE)" "\n\tnano_fiber_lifo_put" "\n\tfiber_yield"); printf(sz_test_start_fmt); lifo_test_init(); t = BENCH_START(); i = 0; task_fiber_start(fiber_stack1, STACK_SIZE, lifo_fiber1, 0, NUMBER_OF_LOOPS, 3, 0); task_fiber_start(fiber_stack2, STACK_SIZE, lifo_fiber3, (int) &i, NUMBER_OF_LOOPS, 3, 0); t = TIME_STAMP_DELTA_GET(t); return_value += check_result(i, t); /* fibers have done their job, they can stop now safely: */ for (j = 0; j < 2; j++) { nano_task_fifo_put(&nanoFifo_sync, (void *) element); } /* test get wait & put fiber/task functions */ fprintf(output_file, sz_test_case_fmt, "LIFO #3"); fprintf(output_file, sz_description, "\n\tnano_lifo_init" "\n\tnano_fiber_lifo_get(TICKS_UNLIMITED)" "\n\tnano_fiber_lifo_put" "\n\tnano_task_lifo_get(TICKS_UNLIMITED)" "\n\tnano_task_lifo_put"); printf(sz_test_start_fmt); lifo_test_init(); t = BENCH_START(); task_fiber_start(fiber_stack1, STACK_SIZE, lifo_fiber1, 0, NUMBER_OF_LOOPS, 3, 0); for (i = 0; i < NUMBER_OF_LOOPS / 2; i++) { int element[2]; int *pelement; element[1] = 2 * i; nano_task_lifo_put(&nanoLifo1, element); element[1] = 2 * i + 1; nano_task_lifo_put(&nanoLifo1, element); pelement = (int *)nano_task_lifo_get(&nanoLifo2, TICKS_UNLIMITED); if (pelement[1] != 2 * i + 1) { break; } pelement = (int *)nano_task_lifo_get(&nanoLifo2, TICKS_UNLIMITED); if (pelement[1] != 2 * i) { break; } } t = TIME_STAMP_DELTA_GET(t); return_value += check_result(i * 2, t); /* fibers have done their job, they can stop now safely: */ for (j = 0; j < 2; j++) { nano_task_fifo_put(&nanoFifo_sync, (void *) element); } return return_value; }
void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state) { bt_conn_state_t old_state; BT_DBG("%s -> %s", state2str(conn->state), state2str(state)); if (conn->state == state) { BT_WARN("no transition"); return; } old_state = conn->state; conn->state = state; /* Actions needed for exiting the old state */ switch (old_state) { case BT_CONN_DISCONNECTED: /* Take a reference for the first state transition after * bt_conn_add_le() and keep it until reaching DISCONNECTED * again. */ bt_conn_ref(conn); break; case BT_CONN_CONNECT: if (conn->timeout) { fiber_delayed_start_cancel(conn->timeout); conn->timeout = NULL; /* Drop the reference taken by timeout fiber */ bt_conn_unref(conn); } break; default: break; } /* Actions needed for entering the new state */ switch (conn->state) { case BT_CONN_CONNECTED: nano_fifo_init(&conn->tx_queue); fiber_start(conn->stack, sizeof(conn->stack), conn_tx_fiber, (int)bt_conn_ref(conn), 0, 7, 0); bt_l2cap_connected(conn); notify_connected(conn); break; case BT_CONN_DISCONNECTED: /* Notify disconnection and queue a dummy buffer to wake * up and stop the tx fiber for states where it was * running. */ if (old_state == BT_CONN_CONNECTED || old_state == BT_CONN_DISCONNECT) { bt_l2cap_disconnected(conn); notify_disconnected(conn); nano_fifo_put(&conn->tx_queue, net_buf_get(&dummy, 0)); } else if (old_state == BT_CONN_CONNECT) { /* conn->err will be set in this case */ notify_connected(conn); } else if (old_state == BT_CONN_CONNECT_SCAN && conn->err) { /* this indicate LE Create Connection failed */ notify_connected(conn); } /* Release the reference we took for the very first * state transition. */ bt_conn_unref(conn); break; case BT_CONN_CONNECT_SCAN: break; case BT_CONN_CONNECT: /* * Timer is needed only for LE. For other link types controller * will handle connection timeout. */ if (conn->type != BT_CONN_TYPE_LE) { break; } /* Add LE Create Connection timeout */ conn->timeout = fiber_delayed_start(conn->stack, sizeof(conn->stack), timeout_fiber, (int)bt_conn_ref(conn), 0, 7, 0, CONN_TIMEOUT); break; case BT_CONN_DISCONNECT: break; default: BT_WARN("no valid (%u) state was set", state); break; } }
/* the timeout test entry point */ static int test_timeout(void) { int64_t orig_ticks; int32_t timeout; int rv; int test_data_size; struct reply_packet reply_packet; nano_sem_init(&sem_timeout[0]); nano_sem_init(&sem_timeout[1]); nano_fifo_init(&timeout_order_fifo); /* test nano_task_sem_take_wait_timeout() with timeout */ timeout = 10; orig_ticks = nano_tick_get(); rv = nano_task_sem_take_wait_timeout(&sem_timeout[0], timeout); if (rv) { TC_ERROR(" *** timeout of %d did not time out.\n", timeout); return TC_FAIL; } if ((nano_tick_get() - orig_ticks) < timeout) { TC_ERROR(" *** task did not wait long enough on timeout of %d.\n", timeout); return TC_FAIL; } /* test nano_task_sem_take_wait_timeout with timeout of 0 */ rv = nano_task_sem_take_wait_timeout(&sem_timeout[0], 0); if (rv) { TC_ERROR(" *** timeout of 0 did not time out.\n"); return TC_FAIL; } /* test nano_task_sem_take_wait_timeout with timeout > 0 */ TC_PRINT("test nano_task_sem_take_wait_timeout with timeout > 0\n"); timeout = 3; orig_ticks = nano_tick_get(); rv = nano_task_sem_take_wait_timeout(&sem_timeout[0], timeout); if (rv) { TC_ERROR(" *** timeout of %d did not time out.\n", timeout); return TC_FAIL; } if (!is_timeout_in_range(orig_ticks, timeout)) { return TC_FAIL; } TC_PRINT("nano_task_sem_take_wait_timeout timed out as expected\n"); /* * test nano_task_sem_take_wait_timeout with a timeout and fiber that gives * the semaphore on time */ timeout = 5; orig_ticks = nano_tick_get(); task_fiber_start(timeout_stacks[0], FIBER_STACKSIZE, test_fiber_give_timeout, (int)&sem_timeout[0], timeout, FIBER_PRIORITY, 0); rv = nano_task_sem_take_wait_timeout(&sem_timeout[0], (int)(timeout + 5)); if (!rv) { TC_ERROR(" *** timed out even if semaphore was given in time.\n"); return TC_FAIL; } if (!is_timeout_in_range(orig_ticks, timeout)) { return TC_FAIL; } TC_PRINT("nano_task_sem_take_wait_timeout got sem in time, as expected\n"); /* * test nano_task_sem_take_wait_timeout with TICKS_NONE and the * semaphore unavailable. */ if (nano_task_sem_take_wait_timeout(&sem_timeout[0], TICKS_NONE)) { TC_ERROR("task with TICKS_NONE got sem, but shouldn't have\n"); return TC_FAIL; } TC_PRINT("task with TICKS_NONE did not get sem, as expected\n"); /* * test nano_task_sem_take_wait_timeout with TICKS_NONE and the * semaphore available. */ nano_task_sem_give(&sem_timeout[0]); if (!nano_task_sem_take_wait_timeout(&sem_timeout[0], TICKS_NONE)) { TC_ERROR("task with TICKS_NONE did not get available sem\n"); return TC_FAIL; } TC_PRINT("task with TICKS_NONE got available sem, as expected\n"); /* * test nano_task_sem_take_wait_timeout with TICKS_UNLIMITED and the * semaphore available. */ TC_PRINT("Trying to take available sem with TICKS_UNLIMITED:\n" " will hang the test if it fails.\n"); nano_task_sem_give(&sem_timeout[0]); if (!nano_task_sem_take_wait_timeout(&sem_timeout[0], TICKS_UNLIMITED)) { TC_ERROR(" *** This will never be hit!!! .\n"); return TC_FAIL; } TC_PRINT("task with TICKS_UNLIMITED got available sem, as expected\n"); /* test fiber with timeout of TICKS_NONE not getting empty semaphore */ task_fiber_start(timeout_stacks[0], FIBER_STACKSIZE, test_fiber_ticks_special_values, (int)&reply_packet, TICKS_NONE, FIBER_PRIORITY, 0); if (!nano_task_fifo_get(&timeout_order_fifo)) { TC_ERROR(" *** fiber should have run and filled the fifo.\n"); return TC_FAIL; } if (reply_packet.reply != 0) { TC_ERROR(" *** fiber should not have obtained the semaphore.\n"); return TC_FAIL; } TC_PRINT("fiber with TICKS_NONE did not get sem, as expected\n"); /* test fiber with timeout of TICKS_NONE getting full semaphore */ nano_task_sem_give(&sem_timeout[0]); task_fiber_start(timeout_stacks[0], FIBER_STACKSIZE, test_fiber_ticks_special_values, (int)&reply_packet, TICKS_NONE, FIBER_PRIORITY, 0); if (!nano_task_fifo_get(&timeout_order_fifo)) { TC_ERROR(" *** fiber should have run and filled the fifo.\n"); return TC_FAIL; } if (reply_packet.reply != 1) { TC_ERROR(" *** fiber should have obtained the semaphore.\n"); return TC_FAIL; } TC_PRINT("fiber with TICKS_NONE got available sem, as expected\n"); /* test fiber with timeout of TICKS_UNLIMITED getting full semaphore */ nano_task_sem_give(&sem_timeout[0]); task_fiber_start(timeout_stacks[0], FIBER_STACKSIZE, test_fiber_ticks_special_values, (int)&reply_packet, TICKS_UNLIMITED, FIBER_PRIORITY, 0); if (!nano_task_fifo_get(&timeout_order_fifo)) { TC_ERROR(" *** fiber should have run and filled the fifo.\n"); return TC_FAIL; } if (reply_packet.reply != 1) { TC_ERROR(" *** fiber should have obtained the semaphore.\n"); return TC_FAIL; } TC_PRINT("fiber with TICKS_UNLIMITED got available sem, as expected\n"); /* test multiple fibers pending on the same sem with different timeouts */ test_data_size = ARRAY_SIZE(timeout_order_data); TC_PRINT("testing timeouts of %d fibers on same sem\n", test_data_size); rv = test_multiple_fibers_pending(timeout_order_data, test_data_size); if (rv != TC_PASS) { TC_ERROR(" *** fibers did not time out in the right order\n"); return TC_FAIL; } /* test multiple fibers pending on different sems with different timeouts */ test_data_size = ARRAY_SIZE(timeout_order_data_mult_sem); TC_PRINT("testing timeouts of %d fibers on different sems\n", test_data_size); rv = test_multiple_fibers_pending(timeout_order_data_mult_sem, test_data_size); if (rv != TC_PASS) { TC_ERROR(" *** fibers did not time out in the right order\n"); return TC_FAIL; } /* * test multiple fibers pending on same sem with different timeouts, but * getting the semaphore in time, except the last one. */ test_data_size = ARRAY_SIZE(timeout_order_data); TC_PRINT("testing %d fibers timing out, but obtaining the sem in time\n" "(except the last one, which times out)\n", test_data_size); rv = test_multiple_fibers_get_sem(timeout_order_data, test_data_size); if (rv != TC_PASS) { TC_ERROR(" *** fibers did not get the sem in the right order\n"); return TC_FAIL; } return TC_PASS; }
/** * * @brief Initialize FIFOs for the test * * @return N/A */ void fifo_test_init(void) { nano_fifo_init(&nanoFifo1); nano_fifo_init(&nanoFifo2); }