| 
									
										
										
										
											2013-05-06 12:50:19 +07:00
										 |  |  | /**************************************************************************/ | 
					
						
							|  |  |  | /*!
 | 
					
						
							|  |  |  |     @file     test_osal_none.c | 
					
						
							|  |  |  |     @author   hathach (tinyusb.org) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @section LICENSE | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Software License Agreement (BSD License) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Copyright (c) 2013, hathach (tinyusb.org) | 
					
						
							|  |  |  |     All rights reserved. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Redistribution and use in source and binary forms, with or without | 
					
						
							|  |  |  |     modification, are permitted provided that the following conditions are met: | 
					
						
							|  |  |  |     1. Redistributions of source code must retain the above copyright | 
					
						
							|  |  |  |     notice, this list of conditions and the following disclaimer. | 
					
						
							|  |  |  |     2. Redistributions in binary form must reproduce the above copyright | 
					
						
							|  |  |  |     notice, this list of conditions and the following disclaimer in the | 
					
						
							|  |  |  |     documentation and/or other materials provided with the distribution. | 
					
						
							|  |  |  |     3. Neither the name of the copyright holders nor the | 
					
						
							|  |  |  |     names of its contributors may be used to endorse or promote products | 
					
						
							|  |  |  |     derived from this software without specific prior written permission. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY | 
					
						
							|  |  |  |     EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 
					
						
							|  |  |  |     WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 
					
						
							|  |  |  |     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY | 
					
						
							|  |  |  |     DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 
					
						
							|  |  |  |     INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 
					
						
							|  |  |  |     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND | 
					
						
							|  |  |  |     ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
					
						
							|  |  |  |     INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS | 
					
						
							|  |  |  |     SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     This file is part of the tinyusb stack. | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | /**************************************************************************/ | 
					
						
							| 
									
										
										
										
											2013-01-26 01:37:15 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-30 11:35:37 +07:00
										 |  |  | #ifdef TUSB_CFG_OS
 | 
					
						
							|  |  |  | #undef TUSB_CFG_OS
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-26 01:37:15 +07:00
										 |  |  | #include "unity.h"
 | 
					
						
							| 
									
										
										
										
											2013-02-06 13:15:12 +07:00
										 |  |  | #include "errors.h"
 | 
					
						
							| 
									
										
										
										
											2013-01-30 12:55:44 +07:00
										 |  |  | #include "osal_none.h"
 | 
					
						
							| 
									
										
										
										
											2013-01-30 23:29:27 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-30 17:53:37 +07:00
										 |  |  | #define QUEUE_DEPTH 10
 | 
					
						
							| 
									
										
										
										
											2013-01-30 23:29:27 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-30 11:35:37 +07:00
										 |  |  | uint32_t statements[10]; | 
					
						
							| 
									
										
										
										
											2013-01-30 17:53:37 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-04 16:07:42 +07:00
										 |  |  | OSAL_SEM_DEF(sem); | 
					
						
							| 
									
										
										
										
											2013-01-30 11:35:37 +07:00
										 |  |  | osal_semaphore_handle_t sem_hdl; | 
					
						
							| 
									
										
										
										
											2013-01-26 01:37:15 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-10 01:13:31 +07:00
										 |  |  | OSAL_QUEUE_DEF(queue, QUEUE_DEPTH, uint32_t); | 
					
						
							| 
									
										
										
										
											2013-01-30 17:53:37 +07:00
										 |  |  | osal_queue_handle_t queue_hdl; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-26 01:37:15 +07:00
										 |  |  | void setUp(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-01-30 11:35:37 +07:00
										 |  |  |   memset(statements, 0, sizeof(statements)); | 
					
						
							| 
									
										
										
										
											2013-02-04 16:07:42 +07:00
										 |  |  |   sem_hdl = osal_semaphore_create(OSAL_SEM_REF(sem)); | 
					
						
							| 
									
										
										
										
											2013-01-30 17:53:37 +07:00
										 |  |  |   queue_hdl = osal_queue_create(&queue); | 
					
						
							| 
									
										
										
										
											2013-01-26 01:37:15 +07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void tearDown(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-30 11:35:37 +07:00
										 |  |  | //--------------------------------------------------------------------+
 | 
					
						
							|  |  |  | // Semaphore
 | 
					
						
							|  |  |  | //--------------------------------------------------------------------+
 | 
					
						
							|  |  |  | void test_semaphore_create(void) | 
					
						
							| 
									
										
										
										
											2013-01-26 01:37:15 +07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-01-30 11:35:37 +07:00
										 |  |  |   TEST_ASSERT_EQUAL_PTR(&sem, sem_hdl); | 
					
						
							|  |  |  |   TEST_ASSERT_EQUAL(0, sem); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void test_semaphore_post(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   osal_semaphore_post(sem_hdl); | 
					
						
							|  |  |  |   TEST_ASSERT_EQUAL(1, sem); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-01-30 17:53:37 +07:00
										 |  |  | // blocking service such as semaphore wait need to be invoked within a task's loop
 | 
					
						
							| 
									
										
										
										
											2013-01-30 11:35:37 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | //--------------------------------------------------------------------+
 | 
					
						
							|  |  |  | // Queue
 | 
					
						
							|  |  |  | //--------------------------------------------------------------------+
 | 
					
						
							|  |  |  | void test_queue_create(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-01-30 17:53:37 +07:00
										 |  |  |   TEST_ASSERT_EQUAL_PTR(&queue, queue_hdl); | 
					
						
							|  |  |  |   TEST_ASSERT_EQUAL(QUEUE_DEPTH, queue_hdl->depth); | 
					
						
							|  |  |  |   TEST_ASSERT_EQUAL_PTR(queue_buffer, queue_hdl->buffer); | 
					
						
							|  |  |  |   TEST_ASSERT_EQUAL(0, queue_hdl->count); | 
					
						
							|  |  |  |   TEST_ASSERT_EQUAL(0, queue_hdl->wr_idx); | 
					
						
							|  |  |  |   TEST_ASSERT_EQUAL(0, queue_hdl->rd_idx); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void test_queue_send(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   uint32_t const item = 0x1234; | 
					
						
							| 
									
										
										
										
											2013-04-10 01:13:31 +07:00
										 |  |  |   osal_queue_send(queue_hdl, &item); | 
					
						
							| 
									
										
										
										
											2013-01-30 17:53:37 +07:00
										 |  |  |   TEST_ASSERT_EQUAL(1, queue_hdl->count); | 
					
						
							| 
									
										
										
										
											2013-04-10 01:13:31 +07:00
										 |  |  |   TEST_ASSERT_EQUAL_MEMORY(&item, queue_hdl->buffer + (queue_hdl->rd_idx * queue_hdl->item_size), 4); | 
					
						
							| 
									
										
										
										
											2013-01-26 01:37:15 +07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-01-30 17:53:37 +07:00
										 |  |  | // blocking service such as semaphore wait need to be invoked within a task's loop
 | 
					
						
							| 
									
										
										
										
											2013-01-26 01:37:15 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-30 11:35:37 +07:00
										 |  |  | //--------------------------------------------------------------------+
 | 
					
						
							| 
									
										
										
										
											2013-02-06 13:15:12 +07:00
										 |  |  | // TASK SEMAPHORE
 | 
					
						
							| 
									
										
										
										
											2013-01-30 11:35:37 +07:00
										 |  |  | //--------------------------------------------------------------------+
 | 
					
						
							| 
									
										
										
										
											2013-03-10 19:28:38 +07:00
										 |  |  | tusb_error_t sample_task_semaphore(void) | 
					
						
							| 
									
										
										
										
											2013-01-30 11:35:37 +07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-02-01 10:33:43 +07:00
										 |  |  |   tusb_error_t error = TUSB_ERROR_NONE; | 
					
						
							| 
									
										
										
										
											2013-01-30 11:35:37 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-02 15:36:20 +07:00
										 |  |  |   OSAL_TASK_LOOP_BEGIN | 
					
						
							| 
									
										
										
										
											2013-01-30 11:35:37 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-02 15:36:20 +07:00
										 |  |  |   statements[0]++; | 
					
						
							| 
									
										
										
										
											2013-01-30 11:35:37 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-02 15:36:20 +07:00
										 |  |  |   osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_WAIT_FOREVER, &error); | 
					
						
							|  |  |  |   statements[1]++; | 
					
						
							| 
									
										
										
										
											2013-01-30 11:35:37 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-02 15:36:20 +07:00
										 |  |  |   osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_WAIT_FOREVER, &error); | 
					
						
							|  |  |  |   statements[2]++; | 
					
						
							| 
									
										
										
										
											2013-01-30 11:35:37 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-02 15:36:20 +07:00
										 |  |  |   osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_WAIT_FOREVER, &error); | 
					
						
							|  |  |  |   statements[3]++; | 
					
						
							| 
									
										
										
										
											2013-02-01 12:00:34 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-02 15:36:20 +07:00
										 |  |  |   osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_NORMAL, &error); | 
					
						
							|  |  |  |   statements[4]++; | 
					
						
							|  |  |  |   TEST_ASSERT_EQUAL(TUSB_ERROR_OSAL_TIMEOUT, error); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   OSAL_TASK_LOOP_END | 
					
						
							| 
									
										
										
										
											2013-01-30 11:35:37 +07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void test_task_with_semaphore(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   // several invoke before sempahore is available
 | 
					
						
							| 
									
										
										
										
											2013-02-01 12:00:34 +07:00
										 |  |  |   for(uint32_t i=0; i<10; i++) | 
					
						
							| 
									
										
										
										
											2013-01-30 11:35:37 +07:00
										 |  |  |     sample_task_semaphore(); | 
					
						
							|  |  |  |   TEST_ASSERT_EQUAL(1, statements[0]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-30 23:29:27 +07:00
										 |  |  |   // invoke after posting semaphore
 | 
					
						
							| 
									
										
										
										
											2013-01-30 11:35:37 +07:00
										 |  |  |   osal_semaphore_post(sem_hdl); | 
					
						
							|  |  |  |   sample_task_semaphore(); | 
					
						
							|  |  |  |   TEST_ASSERT_EQUAL(1, statements[1]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-01 10:33:43 +07:00
										 |  |  |   // post 2 consecutive times
 | 
					
						
							| 
									
										
										
										
											2013-01-30 11:35:37 +07:00
										 |  |  |   osal_semaphore_post(sem_hdl); | 
					
						
							|  |  |  |   osal_semaphore_post(sem_hdl); | 
					
						
							|  |  |  |   sample_task_semaphore(); | 
					
						
							|  |  |  |   TEST_ASSERT_EQUAL(1, statements[2]); | 
					
						
							|  |  |  |   TEST_ASSERT_EQUAL(1, statements[3]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-01 10:33:43 +07:00
										 |  |  |   // timeout
 | 
					
						
							| 
									
										
										
										
											2013-02-01 12:00:34 +07:00
										 |  |  |   for(uint32_t i=0; i<(OSAL_TIMEOUT_NORMAL*TUSB_CFG_OS_TICKS_PER_SECOND)/1000 ; i++) // not enough time
 | 
					
						
							|  |  |  |     osal_tick_tock(); | 
					
						
							|  |  |  |   sample_task_semaphore(); | 
					
						
							|  |  |  |   TEST_ASSERT_EQUAL(0, statements[4]); | 
					
						
							|  |  |  |   osal_tick_tock(); | 
					
						
							|  |  |  |   sample_task_semaphore(); | 
					
						
							| 
									
										
										
										
											2013-02-01 10:33:43 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-30 11:35:37 +07:00
										 |  |  |   // reach end of task loop, back to beginning
 | 
					
						
							|  |  |  |   sample_task_semaphore(); | 
					
						
							|  |  |  |   TEST_ASSERT_EQUAL(2, statements[0]); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-06 13:15:12 +07:00
										 |  |  | //--------------------------------------------------------------------+
 | 
					
						
							| 
									
										
										
										
											2013-04-27 00:24:15 +07:00
										 |  |  | // TASK QUEUE
 | 
					
						
							| 
									
										
										
										
											2013-02-06 13:15:12 +07:00
										 |  |  | //--------------------------------------------------------------------+
 | 
					
						
							| 
									
										
										
										
											2013-03-10 19:28:38 +07:00
										 |  |  | tusb_error_t sample_task_with_queue(void) | 
					
						
							| 
									
										
										
										
											2013-01-30 23:29:27 +07:00
										 |  |  | { | 
					
						
							|  |  |  |   uint32_t data; | 
					
						
							| 
									
										
										
										
											2013-02-01 12:39:39 +07:00
										 |  |  |   tusb_error_t error; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-02 15:36:20 +07:00
										 |  |  |   OSAL_TASK_LOOP_BEGIN | 
					
						
							| 
									
										
										
										
											2013-01-30 23:29:27 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-02 15:36:20 +07:00
										 |  |  |   statements[0]++; | 
					
						
							| 
									
										
										
										
											2013-01-30 23:29:27 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-02 15:36:20 +07:00
										 |  |  |   osal_queue_receive(queue_hdl, &data, OSAL_TIMEOUT_WAIT_FOREVER, &error); | 
					
						
							|  |  |  |   TEST_ASSERT_EQUAL(0x1111, data); | 
					
						
							|  |  |  |   statements[1]++; | 
					
						
							| 
									
										
										
										
											2013-01-30 23:29:27 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-02 15:36:20 +07:00
										 |  |  |   osal_queue_receive(queue_hdl, &data, OSAL_TIMEOUT_WAIT_FOREVER, &error); | 
					
						
							|  |  |  |   TEST_ASSERT_EQUAL(0x2222, data); | 
					
						
							|  |  |  |   statements[2]++; | 
					
						
							| 
									
										
										
										
											2013-01-30 23:29:27 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-02 15:36:20 +07:00
										 |  |  |   osal_queue_receive(queue_hdl, &data, OSAL_TIMEOUT_WAIT_FOREVER, &error); | 
					
						
							|  |  |  |   TEST_ASSERT_EQUAL(0x3333, data); | 
					
						
							|  |  |  |   statements[3]++; | 
					
						
							| 
									
										
										
										
											2013-01-30 23:29:27 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-02 15:36:20 +07:00
										 |  |  |   osal_queue_receive(queue_hdl, &data, OSAL_TIMEOUT_NORMAL, &error); | 
					
						
							|  |  |  |   statements[4]++; | 
					
						
							|  |  |  |   TEST_ASSERT_EQUAL(TUSB_ERROR_OSAL_TIMEOUT, error); | 
					
						
							| 
									
										
										
										
											2013-02-01 12:39:39 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-02 15:36:20 +07:00
										 |  |  |   OSAL_TASK_LOOP_END | 
					
						
							| 
									
										
										
										
											2013-01-30 23:29:27 +07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void test_task_with_queue(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   uint32_t i = 0; | 
					
						
							| 
									
										
										
										
											2013-04-10 01:13:31 +07:00
										 |  |  |   uint32_t item; | 
					
						
							| 
									
										
										
										
											2013-01-30 23:29:27 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   sample_task_with_queue(); | 
					
						
							|  |  |  |   // several invoke before queue is available
 | 
					
						
							|  |  |  |   for(i=0; i<10; i++) | 
					
						
							|  |  |  |     sample_task_with_queue(); | 
					
						
							|  |  |  |   TEST_ASSERT_EQUAL(1, statements[0]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // invoke after posting semaphore
 | 
					
						
							| 
									
										
										
										
											2013-04-10 01:13:31 +07:00
										 |  |  |   item = 0x1111; | 
					
						
							|  |  |  |   osal_queue_send(queue_hdl, &item); | 
					
						
							| 
									
										
										
										
											2013-01-30 23:29:27 +07:00
										 |  |  |   sample_task_with_queue(); | 
					
						
							|  |  |  |   TEST_ASSERT_EQUAL(1, statements[1]); | 
					
						
							|  |  |  |   sample_task_with_queue(); | 
					
						
							|  |  |  |   TEST_ASSERT_EQUAL(1, statements[1]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-10 01:13:31 +07:00
										 |  |  |   item = 0x2222; | 
					
						
							|  |  |  |   osal_queue_send(queue_hdl, &item); | 
					
						
							|  |  |  |   item = 0x3333; | 
					
						
							|  |  |  |   osal_queue_send(queue_hdl, &item); | 
					
						
							| 
									
										
										
										
											2013-01-30 23:29:27 +07:00
										 |  |  |   sample_task_with_queue(); | 
					
						
							|  |  |  |   TEST_ASSERT_EQUAL(1, statements[2]); | 
					
						
							|  |  |  |   TEST_ASSERT_EQUAL(1, statements[3]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-01 12:39:39 +07:00
										 |  |  |   // timeout
 | 
					
						
							|  |  |  |   for(uint32_t i=0; i<(OSAL_TIMEOUT_NORMAL*TUSB_CFG_OS_TICKS_PER_SECOND)/1000 ; i++) // not enough time
 | 
					
						
							|  |  |  |     osal_tick_tock(); | 
					
						
							|  |  |  |   sample_task_with_queue(); | 
					
						
							|  |  |  |   TEST_ASSERT_EQUAL(0, statements[4]); | 
					
						
							|  |  |  |   osal_tick_tock(); | 
					
						
							|  |  |  |   sample_task_with_queue(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // reach end of task loop, back to beginning
 | 
					
						
							|  |  |  |   sample_task_with_queue(); | 
					
						
							|  |  |  |   TEST_ASSERT_EQUAL(2, statements[0]); | 
					
						
							| 
									
										
										
										
											2013-01-30 23:29:27 +07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-01-26 01:37:15 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-27 00:24:15 +07:00
										 |  |  | //--------------------------------------------------------------------+
 | 
					
						
							|  |  |  | // TASK DELAY
 | 
					
						
							|  |  |  | //--------------------------------------------------------------------+
 | 
					
						
							|  |  |  | tusb_error_t sample_task_with_delay(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   tusb_error_t error; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   OSAL_TASK_LOOP_BEGIN | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   osal_task_delay(1000); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   statements[0]++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   OSAL_TASK_LOOP_END | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void test_task_with_delay(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   sample_task_with_delay(); | 
					
						
							|  |  |  |   TEST_ASSERT_EQUAL(0, statements[0]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for(uint32_t i=0; i<TUSB_CFG_OS_TICKS_PER_SECOND*1000; i++) // not enough time
 | 
					
						
							|  |  |  |     osal_tick_tock(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   sample_task_with_delay(); | 
					
						
							|  |  |  |   TEST_ASSERT_EQUAL(1, statements[0]); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-06 13:15:12 +07:00
										 |  |  | //--------------------------------------------------------------------+
 | 
					
						
							|  |  |  | // TASK FLOW CONTROL
 | 
					
						
							|  |  |  | //--------------------------------------------------------------------+
 | 
					
						
							|  |  |  | void flow_control_error_handler(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   statements[5]++; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-24 12:20:56 +07:00
										 |  |  | tusb_error_t sample_flow_control_subtask2(void) | 
					
						
							| 
									
										
										
										
											2013-02-06 13:15:12 +07:00
										 |  |  | { | 
					
						
							|  |  |  |   tusb_error_t error; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-24 12:20:56 +07:00
										 |  |  |   OSAL_SUBTASK_BEGIN | 
					
						
							| 
									
										
										
										
											2013-02-06 13:15:12 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   statements[0]++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_NORMAL, &error); | 
					
						
							| 
									
										
										
										
											2013-04-24 12:20:56 +07:00
										 |  |  |   SUBTASK_ASSERT(TUSB_ERROR_NONE == error); | 
					
						
							| 
									
										
										
										
											2013-02-06 13:15:12 +07:00
										 |  |  |   statements[1]++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_NORMAL, &error); | 
					
						
							| 
									
										
										
										
											2013-04-24 12:20:56 +07:00
										 |  |  |   SUBTASK_ASSERT_STATUS(error); | 
					
						
							| 
									
										
										
										
											2013-02-06 13:15:12 +07:00
										 |  |  |   statements[2]++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_NORMAL, &error); | 
					
						
							| 
									
										
										
										
											2013-04-24 12:20:56 +07:00
										 |  |  |   SUBTASK_ASSERT_STATUS_WITH_HANDLER(error, flow_control_error_handler()); | 
					
						
							| 
									
										
										
										
											2013-02-06 13:15:12 +07:00
										 |  |  |   statements[3]++; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-24 12:20:56 +07:00
										 |  |  |   OSAL_SUBTASK_END | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | tusb_error_t sample_flow_control_subtask(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   OSAL_SUBTASK_BEGIN | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-24 17:53:43 +07:00
										 |  |  |   sample_flow_control_subtask2(); | 
					
						
							| 
									
										
										
										
											2013-04-24 12:20:56 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   OSAL_SUBTASK_END | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | tusb_error_t sample_task_flow_control(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   OSAL_TASK_LOOP_BEGIN | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-24 13:45:42 +07:00
										 |  |  |   sample_flow_control_subtask(); | 
					
						
							| 
									
										
										
										
											2013-04-24 12:20:56 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-06 13:15:12 +07:00
										 |  |  |   OSAL_TASK_LOOP_END | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void test_task_flow_control_assert(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   sample_task_flow_control(); | 
					
						
							|  |  |  |   for(uint32_t i=0; i<(OSAL_TIMEOUT_NORMAL*TUSB_CFG_OS_TICKS_PER_SECOND)/1000 + 1; i++) osal_tick_tock(); | 
					
						
							|  |  |  |   sample_task_flow_control(); | 
					
						
							|  |  |  |   TEST_ASSERT_EQUAL(0, statements[1]); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void test_task_flow_control_assert_status(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   for (uint8_t i=0; i<1; i++) osal_semaphore_post(sem_hdl); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   sample_task_flow_control(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for(uint32_t i=0; i<(OSAL_TIMEOUT_NORMAL*TUSB_CFG_OS_TICKS_PER_SECOND)/1000 + 1; i++) osal_tick_tock(); | 
					
						
							|  |  |  |   sample_task_flow_control(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   TEST_ASSERT_EQUAL(0, statements[2]); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void test_task_flow_control_assert_status_hanlder(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   for (uint8_t i=0; i<2; i++) osal_semaphore_post(sem_hdl); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   sample_task_flow_control(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for(uint32_t i=0; i<(OSAL_TIMEOUT_NORMAL*TUSB_CFG_OS_TICKS_PER_SECOND)/1000 + 1; i++) osal_tick_tock(); | 
					
						
							|  |  |  |   sample_task_flow_control(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   TEST_ASSERT_EQUAL(0, statements[3]); | 
					
						
							|  |  |  |   TEST_ASSERT_EQUAL(1, statements[5]); | 
					
						
							|  |  |  | } |