void fiber1(void) { uint32_t data; /* data used to put and get from the stack queue */ int count = 0; /* counter */ TC_PRINT("Test Fiber STACK Pop\n\n"); /* Get all data */ while (nano_fiber_stack_pop(&nanoStackObj, &data, TICKS_NONE) != 0) { TC_PRINT("FIBER STACK Pop: count = %d, data is %d\n", count, data); if ((count >= NUM_STACK_ELEMENT) || (data != myData[NUM_STACK_ELEMENT - 1 - count])) { TCERR1(count); retCode = TC_FAIL; return; } count++; } TC_END_RESULT(retCode); PRINT_LINE; /* Put data */ TC_PRINT("Test Fiber STACK Push\n"); TC_PRINT("\nFIBER STACK Put Order: "); for (int i=NUM_STACK_ELEMENT; i>0; i--) { nano_fiber_stack_push(&nanoStackObj, myData[i-1]); TC_PRINT(" %d,", myData[i-1]); } TC_PRINT("\n"); PRINT_LINE; /* Give semaphore to allow the main task to run */ nano_fiber_sem_give(&nanoSemObj); } /* fiber1 */
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 */
void testIsrFifoFromTask(void) { void *pGetData; /* pointer to FIFO object get from the queue */ void *pPutData; /* pointer to FIFO object put to queue */ int count = 0; /* counter */ TC_PRINT("Test ISR FIFO (invoked from Task)\n\n"); /* This is data pushed by function testIsrFifoFromFiber * Get all FIFOs */ _trigger_nano_isr_fifo_get(); pGetData = isrFifoInfo.data; while (pGetData != NULL) { TC_PRINT("Get from queue1: count = %d, ptr is %p\n", count, pGetData); if ((count >= NUM_FIFO_ELEMENT) || (pGetData != pPutList1[count])) { TCERR1(count); retCode = TC_FAIL; return; } /* Get the next element */ _trigger_nano_isr_fifo_get(); pGetData = isrFifoInfo.data; count++; } /* while */ /* Put data into queue and get it again */ pPutData = pPutList2[3]; isrFifoInfo.data = pPutData; _trigger_nano_isr_fifo_put(); isrFifoInfo.data = NULL; /* force data to a new value */ /* Get data from queue */ _trigger_nano_isr_fifo_get(); pGetData = isrFifoInfo.data; /* Verify data */ if (pGetData != pPutData) { retCode = TC_FAIL; TCERR2; return; } else { TC_PRINT("\nTest ISR FIFO (invoked from Task) - put %p and get back %p\n", pPutData, pGetData); } TC_END_RESULT(retCode); } /* testIsrFifoFromTask */
void testIsrStackFromTask(void) { uint32_t result = INVALID_DATA; /* data used to put and get from the stack queue */ int count = 0; TC_PRINT("Test ISR STACK (invoked from Task)\n\n"); /* Get all data */ _trigger_nano_isr_stack_pop(); result = isrStackInfo.data; while (result != INVALID_DATA) { TC_PRINT(" Pop from queue1: count = %d, data is %d\n", count, result); if ((count >= NUM_STACK_ELEMENT) || (result != myIsrData[NUM_STACK_ELEMENT - count - 1])) { TCERR1(count); retCode = TC_FAIL; return; } /* if */ /* Get the next element */ _trigger_nano_isr_stack_pop(); result = isrStackInfo.data; count++; } /* while */ /* Put data into stack and get it again */ isrStackInfo.data = myIsrData[3]; _trigger_nano_isr_stack_push(); isrStackInfo.data = INVALID_DATA; /* force variable to a new value */ /* Get data from stack */ _trigger_nano_isr_stack_pop(); result = isrStackInfo.data; /* Verify data */ if (result != myIsrData[3]) { TCERR2; retCode = TC_FAIL; return; } else { TC_PRINT("\nTest ISR STACK (invoked from Task) - push %d and pop back %d\n", myIsrData[3], result); } TC_END_RESULT(retCode); }
void main(void) { int count = 0; /* counter */ uint32_t data; /* data used to put and get from the stack queue */ int rc; /* return code */ TC_START("Test Nanokernel STACK"); /* Initialize data */ initData(); /* Initialize the queues and semaphore */ initNanoObjects(); /* Start fiber3 */ task_fiber_start(&fiberStack3[0], STACKSIZE, (nano_fiber_entry_t) fiber3, 0, 0, 7, 0); /* * While fiber3 blocks (for one second), wait for an item to be pushed * onto the stack so that it can be popped. This will put the nanokernel * into an idle state. */ rc = nano_task_stack_pop(&nanoStackObj, &data, TICKS_UNLIMITED); if ((rc == 0) || (data != myData[0])) { TC_ERROR("nano_task_stack_pop(TICKS_UNLIMITED) expected 0x%x, but got 0x%x\n", myData[0], data); retCode = TC_FAIL; goto exit; } /* Put data */ TC_PRINT("Test Task STACK Push\n"); TC_PRINT("\nTASK STACK Put Order: "); for (int i=0; i<NUM_STACK_ELEMENT; i++) { nano_task_stack_push(&nanoStackObj, myData[i]); TC_PRINT(" %d,", myData[i]); } TC_PRINT("\n"); PRINT_LINE; /* Start fiber */ task_fiber_start(&fiberStack1[0], STACKSIZE, (nano_fiber_entry_t) fiber1, 0, 0, 7, 0); if (retCode == TC_FAIL) { goto exit; } /* * Wait for fiber1 to complete execution. (Using a semaphore gives * the fiber the freedom to do blocking-type operations if it wants to.) * */ nano_task_sem_take(&nanoSemObj, TICKS_UNLIMITED); TC_PRINT("Test Task STACK Pop\n"); /* Get all data */ while (nano_task_stack_pop(&nanoStackObj, &data, TICKS_NONE) != 0) { TC_PRINT("TASK STACK Pop: count = %d, data is %d\n", count, data); if ((count >= NUM_STACK_ELEMENT) || (data != myData[count])) { TCERR1(count); retCode = TC_FAIL; goto exit; } count++; } /* Test Task Stack Pop Wait interfaces*/ testTaskStackPopW(); if (retCode == TC_FAIL) { goto exit; } PRINT_LINE; /* Test ISR interfaces */ testIsrStackFromTask(); PRINT_LINE; exit: TC_END_RESULT(retCode); TC_END_REPORT(retCode); }
void main(void) { void *pData; /* pointer to FIFO object get from the queue */ int count = 0; /* counter */ TC_START("Test Nanokernel FIFO"); /* Initialize the FIFO queues and semaphore */ initNanoObjects(); /* Create and start the three (3) fibers. */ task_fiber_start(&fiberStack1[0], FIBER_STACKSIZE, (nano_fiber_entry_t) fiber1, 0, 0, 7, 0); task_fiber_start(&fiberStack2[0], FIBER_STACKSIZE, (nano_fiber_entry_t) fiber2, 0, 0, 7, 0); task_fiber_start(&fiberStack3[0], FIBER_STACKSIZE, (nano_fiber_entry_t) fiber3, 0, 0, 7, 0); /* * The three fibers have each blocked on a different semaphore. Giving * the semaphore nanoSemObjX will unblock fiberX (where X = {1, 2, 3}). * * Activate fibers #1 and #2. They will each block on nanoFifoObj. */ nano_task_sem_give(&nanoSemObj1); nano_task_sem_give(&nanoSemObj2); /* Put two items into <nanoFifoObj> to unblock fibers #1 and #2. */ nano_task_fifo_put(&nanoFifoObj, pPutList1[0]); /* Wake fiber1 */ nano_task_fifo_put(&nanoFifoObj, pPutList1[1]); /* Wake fiber2 */ /* Activate fiber #3 */ nano_task_sem_give(&nanoSemObj3); /* * All three fibers should be blocked on their semaphores. Put data into * <nanoFifoObj2>. Fiber #3 will read it after it is reactivated. */ nano_task_fifo_put(&nanoFifoObj2, pPutList2[0]); nano_task_sem_give(&nanoSemObj3); /* Reactivate fiber #3 */ for (int i = 0; i < 4; i++) { pData = nano_task_fifo_get(&nanoFifoObj2, TICKS_UNLIMITED); if (pData != pPutList2[i]) { TC_ERROR("nano_task_fifo_get() expected 0x%x, got 0x%x\n", pPutList2[i], pData); goto exit; } } /* Add items to <nanoFifoObj> for fiber #2 */ for (int i = 0; i < 4; i++) { nano_task_fifo_put(&nanoFifoObj, pPutList1[i]); } nano_task_sem_give(&nanoSemObj2); /* Activate fiber #2 */ /* Wait for fibers to finish */ nano_task_sem_take(&nanoSemObjTask, TICKS_UNLIMITED); if (retCode == TC_FAIL) { goto exit; } /* * Entries in the FIFO queue have to be unique. * Put data to queue. */ TC_PRINT("Test Task FIFO Put\n"); TC_PRINT("\nTASK FIFO Put Order: "); for (int i = 0; i < NUM_FIFO_ELEMENT; i++) { nano_task_fifo_put(&nanoFifoObj, pPutList1[i]); TC_PRINT(" %p,", pPutList1[i]); } TC_PRINT("\n"); PRINT_LINE; nano_task_sem_give(&nanoSemObj1); /* Activate fiber1 */ if (retCode == TC_FAIL) { goto exit; } /* * Wait for fiber1 to complete execution. (Using a semaphore gives * the fiber the freedom to do blocking-type operations if it wants to.) */ nano_task_sem_take(&nanoSemObjTask, TICKS_UNLIMITED); TC_PRINT("Test Task FIFO Get\n"); /* Get all FIFOs */ while ((pData = nano_task_fifo_get(&nanoFifoObj, TICKS_NONE)) != NULL) { TC_PRINT("TASK FIFO Get: count = %d, ptr is %p\n", count, pData); if ((count >= NUM_FIFO_ELEMENT) || (pData != pPutList2[count])) { TCERR1(count); retCode = TC_FAIL; goto exit; } count++; } /* Test FIFO Get Wait interfaces*/ testTaskFifoGetW(); PRINT_LINE; testIsrFifoFromTask(); PRINT_LINE; /* test timeouts */ if (test_fifo_timeout() != TC_PASS) { retCode = TC_FAIL; goto exit; } PRINT_LINE; exit: TC_END_RESULT(retCode); TC_END_REPORT(retCode); }