mirror of
https://github.com/hathach/tinyusb.git
synced 2025-02-14 18:40:37 +00:00
change osal_timeout_t to uint32_t
implement osal_tick_get & osal_tick_tock for osal_none implement timeout for osal_semaphore_wait
This commit is contained in:
parent
9e3785e7e1
commit
aab92b40d2
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
|
@ -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
|
||||
//--------------------------------------------------------------------+
|
||||
|
Loading…
x
Reference in New Issue
Block a user