tinyusb
tinyusb copied to clipboard
Custom implementation of osal_task_delay for OS_NONE
Related area
Host, osal_task_delay
Hardware specification
Any
Is your feature request related to a problem?
I'm using non supported here MCU/Board and I wan use OS_NONE but provide custom osal_task_delay
Describe the solution you'd like
in osal_none.h
#if CFG_TUH_ENABLED
// currently only needed/available in host mode
#ifdef SOME_CONFIG_FLAG
#include "tusb_os_none.h" //provided by platform implemetation of osal_task_delay
#else
void osal_task_delay(uint32_t msec);
#endif
#endif
in usbh.c
#if CFG_TUSB_OS == OPT_OS_NONE && ! defined(SOME_CONFIG_FLAG)
// TODO rework time-related function later
void osal_task_delay(uint32_t msec)
{
const uint32_t start = hcd_frame_number(_usbh_controller);
while ( ( hcd_frame_number(_usbh_controller) - start ) < msec ) {}
}
#endif
example tusb_os_none.h
#include "tusb_common.h"
#include "BOARD_SPECIFIC.h"
TU_ATTR_ALWAYS_INLINE static inline void osal_task_delay(uint32_t msec)
{
BoardSpecificDelaymS((cast_if_needed)msec);
}
//or
//#define osal_task_delay(msec) BoardSpecificDelaymS((cast_if_needed)msec)
By default SOME_CONFIG_FLAG
would not be defined so it would not affect existing platforms
I have checked existing issues, dicussion and documentation
- [X] I confirm I have checked existing issues, dicussion and documentation.
I see some bsp/sdk provide an better delay than using hcd frame number, which only exist if there is an device attached to bus. I think we can have an optinal callback to get timestamp instead of having an custom OS. There is other place that need this callback as well. Let me think which name we should use
I think the best way is to declare it as a weak function that can be implemented by user, or keep the current implementation . See #2093