summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2013-02-01 12:00:34 +0700
committerhathach <[email protected]>2013-02-01 12:25:02 +0700
commitaab92b40d2e904e8ad85386e4a4f3b59e84eb844 (patch)
treef8099f4075a1e7612b6522d1c8902d56aa13b3f7
parent9e3785e7e1bd5bac3c8e24477edbde12cc09dd4b (diff)
change osal_timeout_t to uint32_t
implement osal_tick_get & osal_tick_tock for osal_none implement timeout for osal_semaphore_wait
-rw-r--r--tests/test/host/test_usbd_host.c2
-rw-r--r--tests/test/support/tusb_config.h2
-rw-r--r--tests/test/test_osal_none.c14
-rw-r--r--tinyusb/osal/osal.h6
-rw-r--r--tinyusb/osal/osal_common.h10
-rw-r--r--tinyusb/osal/osal_none.c25
-rw-r--r--tinyusb/osal/osal_none.h20
-rw-r--r--tinyusb/tusb_option.h22
8 files changed, 73 insertions, 28 deletions
diff --git a/tests/test/host/test_usbd_host.c b/tests/test/host/test_usbd_host.c
index 7dceff7db..654178dc5 100644
--- a/tests/test/host/test_usbd_host.c
+++ b/tests/test/host/test_usbd_host.c
@@ -126,7 +126,7 @@ usbh_enumerate_t enum_connect =
.connect_status = 1
};
-void queue_recv_stub (osal_queue_handle_t const queue_hdl, uint32_t *p_data, osal_timeout_t msec, tusb_error_t *p_error, int num_call)
+void queue_recv_stub (osal_queue_handle_t const queue_hdl, uint32_t *p_data, uint32_t msec, tusb_error_t *p_error, int num_call)
{
TEST_ASSERT_EQUAL_PTR(enumeration_queue_hdl, queue_hdl);
memcpy(p_data, &enum_connect, 4);
diff --git a/tests/test/support/tusb_config.h b/tests/test/support/tusb_config.h
index 87b09a9dd..aee1e3996 100644
--- a/tests/test/support/tusb_config.h
+++ b/tests/test/support/tusb_config.h
@@ -88,7 +88,7 @@
#define TUSB_CFG_DEBUG 3
#define TUSB_CFG_OS TUSB_OS_NONE
-#define TUSB_CFG_OS_TICK_PER_SECOND 1000 // 1 ms tick
+#define TUSB_CFG_OS_TICKS_PER_SECOND 1000 // 1 ms tick
#ifdef __CODE_RED // make use of code red's support for ram region macros
#if (MCU == MCU_LPC11UXX) || (MCU == MCU_LPC13UXX)
diff --git a/tests/test/test_osal_none.c b/tests/test/test_osal_none.c
index 122dc48e2..231edbef1 100644
--- a/tests/test/test_osal_none.c
+++ b/tests/test/test_osal_none.c
@@ -123,15 +123,18 @@ void sample_task_semaphore(void)
osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_WAIT_FOREVER, &error);
statements[3]++;
+ osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_NORMAL, &error);
+ statements[4]++;
+ TEST_ASSERT_EQUAL(TUSB_ERROR_OSAL_TIMEOUT, error);
+
OSAL_TASK_LOOP_END
}
}
void test_task_with_semaphore(void)
{
- uint32_t i;
// several invoke before sempahore is available
- for(i=0; i<10; i++)
+ for(uint32_t i=0; i<10; i++)
sample_task_semaphore();
TEST_ASSERT_EQUAL(1, statements[0]);
@@ -148,7 +151,12 @@ void test_task_with_semaphore(void)
TEST_ASSERT_EQUAL(1, statements[3]);
// 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_semaphore();
+ TEST_ASSERT_EQUAL(0, statements[4]);
+ osal_tick_tock();
+ sample_task_semaphore();
// reach end of task loop, back to beginning
sample_task_semaphore();
diff --git a/tinyusb/osal/osal.h b/tinyusb/osal/osal.h
index 0c99e497f..298a54f3e 100644
--- a/tinyusb/osal/osal.h
+++ b/tinyusb/osal/osal.h
@@ -74,8 +74,6 @@
#include "osal_common.h"
-typedef uint32_t osal_timeout_t;
-
//------------- Tick -------------//
uint32_t osal_tick_get(void);
@@ -94,7 +92,7 @@ tusb_error_t osal_task_create(osal_task_t *task);
typedef uint32_t osal_semaphore_t;
typedef void* osal_semaphore_handle_t;
osal_semaphore_handle_t osal_semaphore_create(osal_semaphore_t * const sem);
-void osal_semaphore_wait(osal_semaphore_handle_t const sem_hdl, osal_timeout_t msec, tusb_error_t *p_error);
+void osal_semaphore_wait(osal_semaphore_handle_t const sem_hdl, uint32_t msec, tusb_error_t *p_error);
tusb_error_t osal_semaphore_post(osal_semaphore_handle_t const sem_hdl);
//------------- Queue -------------//
@@ -105,7 +103,7 @@ typedef void* osal_queue_handle_t;
osal_queue_t name
osal_queue_handle_t osal_queue_create (osal_queue_t *p_queue);
-void osal_queue_receive (osal_queue_handle_t const queue_hdl, uint32_t *p_data, osal_timeout_t msec, tusb_error_t *p_error);
+void osal_queue_receive (osal_queue_handle_t const queue_hdl, uint32_t *p_data, uint32_t msec, tusb_error_t *p_error);
tusb_error_t osal_queue_send (osal_queue_handle_t const queue_hdl, uint32_t data);
#endif
diff --git a/tinyusb/osal/osal_common.h b/tinyusb/osal/osal_common.h
index 62a21ae74..24428e614 100644
--- a/tinyusb/osal/osal_common.h
+++ b/tinyusb/osal/osal_common.h
@@ -56,13 +56,13 @@
#endif
#include "common/common.h"
-
//typedef void (*pfTask)( void * );
enum
{
OSAL_TIMEOUT_NOTIMEOUT = 0, // for use within ISR, return immediately
- OSAL_TIMEOUT_WAIT_FOREVER = 1
+ OSAL_TIMEOUT_WAIT_FOREVER = 1,
+ OSAL_TIMEOUT_NORMAL = 10 // default is 10 msec
};
typedef enum {
@@ -71,6 +71,12 @@ typedef enum {
OSAL_PRIO_HIGH
}osal_prio_t;
+static inline uint32_t osal_tick_from_msec(uint32_t msec) ATTR_CONST ATTR_ALWAYS_INLINE;
+static inline uint32_t osal_tick_from_msec(uint32_t msec)
+{
+ return (msec * TUSB_CFG_OS_TICKS_PER_SECOND)/1000;
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/tinyusb/osal/osal_none.c b/tinyusb/osal/osal_none.c
index d32b00225..4a66f0dc3 100644
--- a/tinyusb/osal/osal_none.c
+++ b/tinyusb/osal/osal_none.c
@@ -35,10 +35,33 @@
* This file is part of the tiny usb stack.
*/
-#include "osal_none.h"
+#include "tusb_option.h"
#if TUSB_CFG_OS == TUSB_OS_NONE
+#define _TINY_USB_SOURCE_FILE_
+
+//--------------------------------------------------------------------+
+// INCLUDE
+//--------------------------------------------------------------------+
+#include "osal_none.h"
+
+//--------------------------------------------------------------------+
+// INTERNAL OBJECT & FUNCTION DECLARATION
+//--------------------------------------------------------------------+
+static volatile uint32_t osal_tick_current = 0;
+
+//--------------------------------------------------------------------+
+// IMPLEMENTATION
+//--------------------------------------------------------------------+
+volatile uint32_t osal_tick_get(void)
+{
+ return osal_tick_current;
+}
+void osal_tick_tock(void)
+{
+ osal_tick_current++;
+}
#endif
diff --git a/tinyusb/osal/osal_none.h b/tinyusb/osal/osal_none.h
index 84373b6de..6aab4e594 100644
--- a/tinyusb/osal/osal_none.h
+++ b/tinyusb/osal/osal_none.h
@@ -57,7 +57,11 @@
#include "osal_common.h"
-typedef uint32_t osal_timeout_t;
+//--------------------------------------------------------------------+
+// TICK API
+//--------------------------------------------------------------------+
+void osal_tick_tock(void);
+uint32_t osal_tick_get(void);
//--------------------------------------------------------------------+
// TASK API
@@ -76,6 +80,7 @@ typedef uint32_t osal_timeout_t;
//#define osal_task_create(code, name, stack_depth, parameters, prio)
#define OSAL_TASK_LOOP \
+ static uint32_t timeout = 0;\
static uint16_t state = 0;\
switch(state)\
@@ -85,6 +90,7 @@ typedef uint32_t osal_timeout_t;
#define OSAL_TASK_LOOP_END \
default:\
state = 0;
+
//--------------------------------------------------------------------+
// Semaphore API
//--------------------------------------------------------------------+
@@ -108,11 +114,15 @@ static inline tusb_error_t osal_semaphore_post(osal_semaphore_handle_t const se
#define osal_semaphore_wait(sem_hdl, msec, p_error) \
do {\
+ timeout = osal_tick_get();\
state = __LINE__; case __LINE__:\
- if( (*sem_hdl) == 0 ) \
- return;\
- else\
- (*sem_hdl)--; /*TODO mutex hal_interrupt_disable consideration*/\
+ if( *(sem_hdl) == 0 ) {\
+ if ( timeout + osal_tick_from_msec(msec) < osal_tick_get() ) /* time out */ \
+ *(p_error) = TUSB_ERROR_OSAL_TIMEOUT;\
+ else\
+ return;\
+ } else\
+ (*(sem_hdl))--; /*TODO mutex hal_interrupt_disable consideration*/\
}while(0)
//--------------------------------------------------------------------+
diff --git a/tinyusb/tusb_option.h b/tinyusb/tusb_option.h
index 79c957051..cc12cc8eb 100644
--- a/tinyusb/tusb_option.h
+++ b/tinyusb/tusb_option.h
@@ -78,6 +78,17 @@
#error TUSB_CFG_ATTR_USBRAM is not defined, please help me know how to place data in accessible RAM for usb controller
#endif
+#if TUSB_CFG_OS == TUSB_OS_NONE
+ #ifndef TUSB_CFG_OS_TICKS_PER_SECOND
+ #error TUSB_CFG_OS_TICKS_PER_SECOND is required to use with OS_NONE
+ #endif
+#endif
+
+#ifndef TUSB_CFG_CONFIGURATION_MAX
+ #define TUSB_CFG_CONFIGURATION_MAX 1
+ #warning TUSB_CFG_CONFIGURATION_MAX is not defined, default value is 1
+#endif
+
//--------------------------------------------------------------------+
// HOST OPTIONS
//--------------------------------------------------------------------+
@@ -103,21 +114,10 @@
#endif
#endif // end TUSB_CFG_HOST_HID_KEYBOARD
- #if TUSB_CFG_OS == TUSB_OS_NONE
- #ifndef TUSB_CFG_OS_TICK_PER_SECOND
- #error TUSB_CFG_OS_TICK_PER_SECOND is required to use with OS_NONE
- #endif
- #endif
-
#define HOST_CLASS_HID ( (defined TUSB_CFG_HOST_HID_KEYBOARD) )
#define HOST_EHCI
#endif // end TUSB_CFG_HOST
-#ifndef TUSB_CFG_CONFIGURATION_MAX
- #define TUSB_CFG_CONFIGURATION_MAX 1
- #warning TUSB_CFG_CONFIGURATION_MAX is not defined, default value is 1
-#endif
-
//--------------------------------------------------------------------+
// DEVICE OPTIONS
//--------------------------------------------------------------------+