Esempio n. 1
0
void testFiberFifoGetW(void)
{
	void *pGetData;   /* pointer to FIFO object get from the queue */
	void *pPutData;   /* pointer to FIFO object to put to the queue */

	TC_PRINT("Test Fiber FIFO Get Wait Interfaces\n\n");
	pGetData = nano_fiber_fifo_get(&nanoFifoObj2, TICKS_UNLIMITED);
	TC_PRINT("FIBER FIFO Get from queue2: %p\n", pGetData);
	/* Verify results */
	if (pGetData != pMyFifoData1) {
		retCode = TC_FAIL;
		TCERR2;
		return;
	}

	pPutData = pMyFifoData2;
	TC_PRINT("FIBER FIFO Put to queue1: %p\n", pPutData);
	nano_fiber_fifo_put(&nanoFifoObj, pPutData);

	pGetData = nano_fiber_fifo_get(&nanoFifoObj2, TICKS_UNLIMITED);
	TC_PRINT("FIBER FIFO Get from queue2: %p\n", pGetData);
	/* Verify results */
	if (pGetData != pMyFifoData3) {
		retCode = TC_FAIL;
		TCERR2;
		return;
	}

	pPutData = pMyFifoData4;
	TC_PRINT("FIBER FIFO Put to queue1: %p\n", pPutData);
	nano_fiber_fifo_put(&nanoFifoObj, pPutData);

	TC_END_RESULT(retCode);

}  /* testFiberFifoGetW */
Esempio n. 2
0
void fiber1(void)
{
	void   *pData;      /* pointer to FIFO object get from the queue */
	int     count = 0;  /* counter */

	/* Wait for fiber1 to be activated. */
	nano_fiber_sem_take_wait(&nanoSemObj1);

	/* Wait for data to be added to <nanoFifoObj> by task */
	pData = nano_fiber_fifo_get_wait(&nanoFifoObj);
	if (pData != pPutList1[0]) {
		TC_ERROR("fiber1 (1) - expected 0x%x, got 0x%x\n",
				 pPutList1[0], pData);
		retCode = TC_FAIL;
		return;
	}

	/* Wait for data to be added to <nanoFifoObj2> by fiber3 */
	pData = nano_fiber_fifo_get_wait(&nanoFifoObj2);
	if (pData != pPutList2[0]) {
		TC_ERROR("fiber1 (2) - expected 0x%x, got 0x%x\n",
				 pPutList2[0], pData);
		retCode = TC_FAIL;
		return;
	}

	nano_fiber_sem_take_wait(&nanoSemObj1);   /* Wait for fiber1 to be reactivated */

	TC_PRINT("Test Fiber FIFO Get\n\n");
	/* Get all FIFOs */
	while ((pData = nano_fiber_fifo_get(&nanoFifoObj)) != NULL) {
		TC_PRINT("FIBER FIFO Get: count = %d, ptr is %p\n", count, pData);
		if ((count >= NUM_FIFO_ELEMENT) || (pData != pPutList1[count])) {
			TCERR1(count);
			retCode = TC_FAIL;
			return;
		}
		count++;
	}

	TC_END_RESULT(retCode);
	PRINT_LINE;

	/*
	 * Entries in the FIFO queue have to be unique.
	 * Put data.
	 */
	TC_PRINT("Test Fiber FIFO Put\n");
	TC_PRINT("\nFIBER FIFO Put Order: ");
	for (int i=0; i<NUM_FIFO_ELEMENT; i++) {
		nano_fiber_fifo_put(&nanoFifoObj, pPutList2[i]);
		TC_PRINT(" %p,", pPutList2[i]);
	}
	TC_PRINT("\n");
	PRINT_LINE;

	/* Give semaphore to allow the main task to run */
	nano_fiber_sem_give(&nanoSemObjTask);

} /* fiber1 */
Esempio n. 3
0
static void test_fiber_ticks_special_values(int packet, int special_value)
{
	struct reply_packet *reply_packet = (void *)packet;

	reply_packet->reply =
		nano_fiber_sem_take_wait_timeout(&sem_timeout[0], special_value);
	nano_fiber_fifo_put(&timeout_order_fifo, reply_packet);
}
Esempio n. 4
0
/* try getting data on lifo with special timeout value, return result in fifo */
static void test_fiber_ticks_special_values(int packet, int special_value)
{
	struct reply_packet *reply_packet = (void *)packet;

	reply_packet->reply =
		!!nano_fiber_lifo_get(&lifo_timeout[0], special_value);

	nano_fiber_fifo_put(&timeout_order_fifo, reply_packet);
}
Esempio n. 5
0
/* a fiber is started with a delay, then it reports that it ran via a fifo */
void delayed_fiber(int num, int unused)
{
	struct timeout_order_data *data = &timeout_order_data[num];

	ARG_UNUSED(unused);

	TC_PRINT(" fiber (q order: %d, t/o: %d) is running\n",
				data->q_order, data->timeout);

	nano_fiber_fifo_put(&timeout_order_fifo, data);
}
Esempio n. 6
0
static void shell(int arg1, int arg2)
{
	char *argv[ARGC_MAX + 1];
	size_t argc;

	while (1) {
		struct uart_console_input *cmd;
		shell_cmd_function_t cb;

		printk("%s", get_prompt());

		cmd = nano_fiber_fifo_get(&cmds_queue, TICKS_UNLIMITED);

		argc = line2argv(cmd->line, argv, ARRAY_SIZE(argv));
		if (!argc) {
			nano_fiber_fifo_put(&avail_queue, cmd);
			continue;
		}

		cb = get_cb(argv[0]);
		if (!cb) {
			if (app_cmd_handler != NULL) {
				cb = app_cmd_handler;
			} else {
				printk("Unrecognized command: %s\n", argv[0]);
				printk("Type 'help' for list of available commands\n");
				nano_fiber_fifo_put(&avail_queue, cmd);
				continue;
			}
		}

		/* Execute callback with arguments */
		if (cb(argc, argv) < 0) {
			show_cmd_help(argc, argv);
		}

		nano_fiber_fifo_put(&avail_queue, cmd);
	}
}
Esempio n. 7
0
static void errno_fiber(int n, int my_errno)
{
	errno = my_errno;

	printk("fiber %d, errno before sleep: %x\n", n, errno);

	fiber_sleep(3 - n);
	if (errno == my_errno) {
		result[n].pass = 1;
	}

	printk("fiber %d, errno after sleep:  %x\n", n, errno);

	nano_fiber_fifo_put(&fifo, &result[n]);
}
Esempio n. 8
0
/* a fiber pends on a semaphore with a timeout and gets the semaphore in time */
static void test_fiber_pend_and_get_sem(int data, int unused)
{
	struct timeout_order_data *the_data = (void *)data;
	int rv;

	ARG_UNUSED(unused);

	rv = nano_fiber_sem_take_wait_timeout(the_data->sem, the_data->timeout);
	if (!rv) {
		TC_PRINT(" *** fiber (q order: %d, t/o: %d, sem: %p) timed out!\n",
						the_data->q_order, the_data->timeout, the_data->sem);
		return;
	}

	nano_fiber_fifo_put(&timeout_order_fifo, the_data);
}
Esempio n. 9
0
/* a fiber pends on a lifo with a timeout and gets the data in time */
static void test_fiber_pend_and_get_data(int data, int unused)
{
	struct timeout_order_data *d = (void *)data;
	void *packet;

	ARG_UNUSED(unused);

	packet = nano_fiber_lifo_get(d->lifo, d->timeout);
	if (!packet) {
		TC_PRINT(" *** fiber (q order: %d, t/o: %d, lifo %p) timed out!\n",
						d->q_order, d->timeout, d->lifo);
		return;
	}

	put_scratch_packet(packet);
	nano_fiber_fifo_put(&timeout_order_fifo, d);
}
Esempio n. 10
0
/**
 *
 * @brief Fifo test fiber
 *
 * @param par1   Ignored parameter.
 * @param par2   Number of test loops.
 *
 * @return N/A
 */
void fifo_fiber1(int par1, int par2)
{
	int i;
	int element[2];
	int * pelement;

	ARG_UNUSED(par1);
	for (i = 0; i < par2; i++) {
		pelement = (int *) nano_fiber_fifo_get(&nanoFifo1, TICKS_UNLIMITED);
		if (pelement[1] != i) {
			break;
		}
		element[1] = i;
		nano_fiber_fifo_put(&nanoFifo2, element);
	}
	/* wait till it is safe to end: */
	nano_fiber_fifo_get(&nanoFifo_sync, TICKS_UNLIMITED);
}
Esempio n. 11
0
/**
 *
 * @brief Fifo test fiber
 *
 * @param par1   Address of the counter.
 * @param par2   Number of test cycles.
 *
 * @return N/A
 */
void fifo_fiber2(int par1, int par2)
{
	int i;
	int element[2];
	int * pelement;
	int * pcounter = (int *) par1;

	for (i = 0; i < par2; i++) {
		element[1] = i;
		nano_fiber_fifo_put(&nanoFifo1, element);
		pelement = (int *) nano_fiber_fifo_get(&nanoFifo2, TICKS_UNLIMITED);
		if (pelement[1] != i) {
			break;
		}
		(*pcounter)++;
	}
	/* wait till it is safe to end: */
	nano_fiber_fifo_get(&nanoFifo_sync, TICKS_UNLIMITED);
}
Esempio n. 12
0
/* a fiber pends on a lifo then times out */
static void test_fiber_pend_and_timeout(int data, int unused)
{
	struct timeout_order_data *d = (void *)data;
	int32_t orig_ticks = sys_tick_get();
	void *packet;

	ARG_UNUSED(unused);

	packet = nano_fiber_lifo_get(d->lifo, d->timeout);
	if (packet) {
		TC_ERROR(" *** timeout of %d did not time out.\n",
					d->timeout);
		return;
	}
	if (!is_timeout_in_range(orig_ticks, d->timeout)) {
		return;
	}

	nano_fiber_fifo_put(&timeout_order_fifo, d);
}
Esempio n. 13
0
/* a fiber pends on a semaphore then times out */
static void test_fiber_pend_and_timeout(int data, int unused)
{
	struct timeout_order_data *the_data = (void *)data;
	int32_t orig_ticks = nano_tick_get();
	int rv;

	ARG_UNUSED(unused);

	rv = nano_fiber_sem_take_wait_timeout(the_data->sem, the_data->timeout);
	if (rv) {
		TC_ERROR(" *** timeout of %d did not time out.\n",
					the_data->timeout);
		return;
	}
	if (!is_timeout_in_range(orig_ticks, the_data->timeout)) {
		return;
	}

	nano_fiber_fifo_put(&timeout_order_fifo, the_data);
}
Esempio n. 14
0
File: bttester.c Progetto: gemtara/z
static void cmd_handler(int arg1, int arg2)
{
	while (1) {
		struct btp_hdr *cmd;
		uint16_t len;

		cmd = nano_fiber_fifo_get(&cmds_queue, TICKS_UNLIMITED);

		len = sys_le16_to_cpu(cmd->len);

		/* TODO
		 * verify if service is registered before calling handler
		 */

		switch (cmd->service) {
		case BTP_SERVICE_ID_CORE:
			handle_core(cmd->opcode, cmd->index, cmd->data, len);
			break;
		case BTP_SERVICE_ID_GAP:
			tester_handle_gap(cmd->opcode, cmd->index, cmd->data,
					  len);
			break;
		case BTP_SERVICE_ID_GATT:
			tester_handle_gatt(cmd->opcode, cmd->index, cmd->data,
					    len);
			break;
		case BTP_SERVICE_ID_L2CAP:
			tester_handle_l2cap(cmd->opcode, cmd->index, cmd->data,
					    len);
			break;
		default:
			tester_rsp(cmd->service, cmd->opcode, cmd->index,
				   BTP_STATUS_FAILED);
			break;
		}

		nano_fiber_fifo_put(&avail_queue, cmd);
	}
}
Esempio n. 15
0
/**
 *
 * @brief Fifo test fiber
 *
 * @param par1   Address of the counter.
 * @param par2   Number of test cycles.
 *
 * @return N/A
 */
void fifo_fiber3(int par1, int par2)
{
	int i;
	int element[2];
	int * pelement;
	int * pcounter = (int *) par1;

	for (i = 0; i < par2; i++) {
		element[1] = i;
		nano_fiber_fifo_put(&nanoFifo1, element);
		while ((pelement = nano_fiber_fifo_get(&nanoFifo2,
							TICKS_NONE)) == NULL) {
			fiber_yield();
		}
		if (pelement[1] != i) {
			break;
		}
		(*pcounter)++;
	}
	/* wait till it is safe to end: */
	nano_fiber_fifo_get(&nanoFifo_sync, TICKS_UNLIMITED);
}
Esempio n. 16
0
void fiber3(void)
{
	void *pData;

	/* Wait for fiber3 to be activated */
	nano_fiber_sem_take(&nanoSemObj3, TICKS_UNLIMITED);

	/* Put two items onto <nanoFifoObj2> to unblock fibers #1 and #2. */
	nano_fiber_fifo_put(&nanoFifoObj2, pPutList2[0]);    /* Wake fiber1 */
	nano_fiber_fifo_put(&nanoFifoObj2, pPutList2[1]);    /* Wake fiber2 */

	/* Wait for fiber3 to be re-activated */
	nano_fiber_sem_take(&nanoSemObj3, TICKS_UNLIMITED);

	/* Immediately get the data from <nanoFifoObj2>. */
	pData = nano_fiber_fifo_get(&nanoFifoObj2, TICKS_UNLIMITED);
	if (pData != pPutList2[0]) {
		retCode = TC_FAIL;
		TC_ERROR("fiber3 (1) - got 0x%x from <nanoFifoObj2>, expected 0x%x\n",
				 pData, pPutList2[0]);
	}

	/* Put three items onto the FIFO for the task to get */
	nano_fiber_fifo_put(&nanoFifoObj2, pPutList2[0]);
	nano_fiber_fifo_put(&nanoFifoObj2, pPutList2[1]);
	nano_fiber_fifo_put(&nanoFifoObj2, pPutList2[2]);

	/* Sleep for 2 seconds */
	nano_fiber_timer_start(&timer, SECONDS(2));
	nano_fiber_timer_test(&timer, TICKS_UNLIMITED);

	/* Put final item onto the FIFO for the task to get */
	nano_fiber_fifo_put(&nanoFifoObj2, pPutList2[3]);

	/* Wait for fiber3 to be re-activated (not expected to occur) */
	nano_fiber_sem_take(&nanoSemObj3, TICKS_UNLIMITED);
}