mirror of
https://github.com/hathach/tinyusb.git
synced 2025-02-15 21:40:18 +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
|
.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);
|
TEST_ASSERT_EQUAL_PTR(enumeration_queue_hdl, queue_hdl);
|
||||||
memcpy(p_data, &enum_connect, 4);
|
memcpy(p_data, &enum_connect, 4);
|
||||||
|
@ -88,7 +88,7 @@
|
|||||||
#define TUSB_CFG_DEBUG 3
|
#define TUSB_CFG_DEBUG 3
|
||||||
|
|
||||||
#define TUSB_CFG_OS TUSB_OS_NONE
|
#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
|
#ifdef __CODE_RED // make use of code red's support for ram region macros
|
||||||
#if (MCU == MCU_LPC11UXX) || (MCU == MCU_LPC13UXX)
|
#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);
|
osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_WAIT_FOREVER, &error);
|
||||||
statements[3]++;
|
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
|
OSAL_TASK_LOOP_END
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_task_with_semaphore(void)
|
void test_task_with_semaphore(void)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
|
||||||
// several invoke before sempahore is available
|
// several invoke before sempahore is available
|
||||||
for(i=0; i<10; i++)
|
for(uint32_t i=0; i<10; i++)
|
||||||
sample_task_semaphore();
|
sample_task_semaphore();
|
||||||
TEST_ASSERT_EQUAL(1, statements[0]);
|
TEST_ASSERT_EQUAL(1, statements[0]);
|
||||||
|
|
||||||
@ -148,7 +151,12 @@ void test_task_with_semaphore(void)
|
|||||||
TEST_ASSERT_EQUAL(1, statements[3]);
|
TEST_ASSERT_EQUAL(1, statements[3]);
|
||||||
|
|
||||||
// timeout
|
// 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
|
// reach end of task loop, back to beginning
|
||||||
sample_task_semaphore();
|
sample_task_semaphore();
|
||||||
|
@ -74,8 +74,6 @@
|
|||||||
|
|
||||||
#include "osal_common.h"
|
#include "osal_common.h"
|
||||||
|
|
||||||
typedef uint32_t osal_timeout_t;
|
|
||||||
|
|
||||||
//------------- Tick -------------//
|
//------------- Tick -------------//
|
||||||
uint32_t osal_tick_get(void);
|
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 uint32_t osal_semaphore_t;
|
||||||
typedef void* osal_semaphore_handle_t;
|
typedef void* osal_semaphore_handle_t;
|
||||||
osal_semaphore_handle_t osal_semaphore_create(osal_semaphore_t * const sem);
|
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);
|
tusb_error_t osal_semaphore_post(osal_semaphore_handle_t const sem_hdl);
|
||||||
|
|
||||||
//------------- Queue -------------//
|
//------------- Queue -------------//
|
||||||
@ -105,7 +103,7 @@ typedef void* osal_queue_handle_t;
|
|||||||
osal_queue_t name
|
osal_queue_t name
|
||||||
|
|
||||||
osal_queue_handle_t osal_queue_create (osal_queue_t *p_queue);
|
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);
|
tusb_error_t osal_queue_send (osal_queue_handle_t const queue_hdl, uint32_t data);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -56,13 +56,13 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "common/common.h"
|
#include "common/common.h"
|
||||||
|
|
||||||
//typedef void (*pfTask)( void * );
|
//typedef void (*pfTask)( void * );
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
OSAL_TIMEOUT_NOTIMEOUT = 0, // for use within ISR, return immediately
|
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 {
|
typedef enum {
|
||||||
@ -71,6 +71,12 @@ typedef enum {
|
|||||||
OSAL_PRIO_HIGH
|
OSAL_PRIO_HIGH
|
||||||
}osal_prio_t;
|
}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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -35,10 +35,33 @@
|
|||||||
* This file is part of the tiny usb stack.
|
* This file is part of the tiny usb stack.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "osal_none.h"
|
#include "tusb_option.h"
|
||||||
|
|
||||||
#if TUSB_CFG_OS == TUSB_OS_NONE
|
#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
|
#endif
|
||||||
|
@ -57,7 +57,11 @@
|
|||||||
|
|
||||||
#include "osal_common.h"
|
#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
|
// 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_create(code, name, stack_depth, parameters, prio)
|
||||||
|
|
||||||
#define OSAL_TASK_LOOP \
|
#define OSAL_TASK_LOOP \
|
||||||
|
static uint32_t timeout = 0;\
|
||||||
static uint16_t state = 0;\
|
static uint16_t state = 0;\
|
||||||
switch(state)\
|
switch(state)\
|
||||||
|
|
||||||
@ -85,6 +90,7 @@ typedef uint32_t osal_timeout_t;
|
|||||||
#define OSAL_TASK_LOOP_END \
|
#define OSAL_TASK_LOOP_END \
|
||||||
default:\
|
default:\
|
||||||
state = 0;
|
state = 0;
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// Semaphore API
|
// 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) \
|
#define osal_semaphore_wait(sem_hdl, msec, p_error) \
|
||||||
do {\
|
do {\
|
||||||
|
timeout = osal_tick_get();\
|
||||||
state = __LINE__; case __LINE__:\
|
state = __LINE__; case __LINE__:\
|
||||||
if( (*sem_hdl) == 0 ) \
|
if( *(sem_hdl) == 0 ) {\
|
||||||
return;\
|
if ( timeout + osal_tick_from_msec(msec) < osal_tick_get() ) /* time out */ \
|
||||||
else\
|
*(p_error) = TUSB_ERROR_OSAL_TIMEOUT;\
|
||||||
(*sem_hdl)--; /*TODO mutex hal_interrupt_disable consideration*/\
|
else\
|
||||||
|
return;\
|
||||||
|
} else\
|
||||||
|
(*(sem_hdl))--; /*TODO mutex hal_interrupt_disable consideration*/\
|
||||||
}while(0)
|
}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
|
#error TUSB_CFG_ATTR_USBRAM is not defined, please help me know how to place data in accessible RAM for usb controller
|
||||||
#endif
|
#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
|
// HOST OPTIONS
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
@ -103,21 +114,10 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif // end TUSB_CFG_HOST_HID_KEYBOARD
|
#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_CLASS_HID ( (defined TUSB_CFG_HOST_HID_KEYBOARD) )
|
||||||
#define HOST_EHCI
|
#define HOST_EHCI
|
||||||
#endif // end TUSB_CFG_HOST
|
#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
|
// DEVICE OPTIONS
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
Loading…
x
Reference in New Issue
Block a user