/** * * @brief Lifo test fiber * * @param par1 Ignored parameter. * @param par2 Number of test loops. * * @return N/A */ void lifo_fiber1(int par1, int par2) { int i; int element_a[2]; int element_b[2]; int *pelement; ARG_UNUSED(par1); for (i = 0; i < par2 / 2; i++) { pelement = (int *)nano_fiber_lifo_get(&nanoLifo1, TICKS_UNLIMITED); if (pelement[1] != 2 * i) { break; } element_a[1] = 2 * i; nano_fiber_lifo_put(&nanoLifo2, element_a); pelement = (int *)nano_fiber_lifo_get(&nanoLifo1, TICKS_UNLIMITED); if (pelement[1] != 2 * i + 1) { break; } element_b[1] = 2 * i + 1; nano_fiber_lifo_put(&nanoLifo2, element_b); } /* wait till it is safe to end: */ nano_fiber_fifo_get(&nanoFifo_sync, TICKS_UNLIMITED); }
int fiberLifoWaitTest(void) { void *data; /* ptr to data retrieved from LIFO */ /* * The LIFO is empty; wait for an item to be added to the LIFO * from the task. */ TC_PRINT("Fiber waiting on an empty LIFO\n"); nano_fiber_sem_give(&taskWaitSem); data = nano_fiber_lifo_get(&test_lifo, TICKS_UNLIMITED); if (data != &lifoItem[0]) { fiberDetectedFailure = 1; return -1; } nano_fiber_sem_take(&fiberWaitSem, TICKS_UNLIMITED); data = nano_fiber_lifo_get(&test_lifo, TICKS_UNLIMITED); if (data != &lifoItem[2]) { fiberDetectedFailure = 1; return -1; } /* * Give the task some time to check the results. Ideally, this would * be waiting for a semaphore instead of a using a delay, but if the * main task wakes the fiber before it blocks on the LIFO, the fiber * will add the item to the LIFO too soon. Obviously, a semaphore could * not be given if the task is blocked on the LIFO; hence the delay. */ nano_fiber_timer_start(&timer, SECONDS(2)); nano_fiber_timer_test(&timer, TICKS_UNLIMITED); /* The task is waiting on an empty LIFO. Wake it up. */ nano_fiber_lifo_put(&test_lifo, &lifoItem[3]); nano_fiber_lifo_put(&test_lifo, &lifoItem[1]); /* * Wait for the task to check the results. If the results pass, then the * the task will wake the fiber. If the results do not pass, then the * fiber will wait forever. */ nano_fiber_sem_take(&fiberWaitSem, TICKS_UNLIMITED); return 0; }
/** * * @brief Lifo test fiber * * @param par1 Address of the counter. * @param par2 Number of test cycles. * * @return N/A */ void lifo_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_lifo_put(&nanoLifo1, element); pelement = (int *)nano_fiber_lifo_get(&nanoLifo2, TICKS_UNLIMITED); if (pelement[1] != i) { break; } (*pcounter)++; } /* wait till it is safe to end: */ nano_fiber_fifo_get(&nanoFifo_sync, TICKS_UNLIMITED); }
/* a fiber sleeps then puts data on the lifo */ static void test_fiber_put_timeout(int lifo, int timeout) { fiber_sleep((int32_t)timeout); nano_fiber_lifo_put((struct nano_lifo *)lifo, get_scratch_packet()); }
int fiberLifoNonWaitTest(void) { void *data; /* pointer to data retrieved from LIFO */ /* The LIFO has two items in it; retrieve them both */ data = nano_fiber_lifo_get(&test_lifo, TICKS_NONE); if (data != (void *) &lifoItem[3]) { goto errorReturn; } data = nano_fiber_lifo_get(&test_lifo, TICKS_NONE); if (data != (void *) &lifoItem[2]) { goto errorReturn; } /* LIFO should be empty--verify. */ data = nano_fiber_lifo_get(&test_lifo, TICKS_NONE); if (data != NULL) { goto errorReturn; } /* * The LIFO is now empty. Add two items to the LIFO and then wait * for the semaphore so that the task can retrieve them. */ TC_PRINT("Task to get LIFO items without waiting\n"); nano_fiber_lifo_put(&test_lifo, &lifoItem[0]); nano_fiber_lifo_put(&test_lifo, &lifoItem[1]); nano_fiber_sem_give(&taskWaitSem); /* Wake the task (if blocked) */ /* * Wait for the task to get the items and then trigger an ISR to populate * the LIFO. */ nano_fiber_sem_take(&fiberWaitSem, TICKS_UNLIMITED); /* * The task retrieved the two items from the LIFO and then triggered * two interrupts to add two other items to the LIFO. The fiber will * now trigger two interrupts to read the two items. */ _trigger_nano_isr_lifo_get(); if (isrLifoInfo.data != &lifoItem[1]) { goto errorReturn; } _trigger_nano_isr_lifo_get(); if (isrLifoInfo.data != &lifoItem[3]) { goto errorReturn; } /* The LIFO should now be empty--verify */ _trigger_nano_isr_lifo_get(); if (isrLifoInfo.data != NULL) { goto errorReturn; } return 0; errorReturn: fiberDetectedFailure = 1; return -1; }