Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom implementation of osal_task_delay for OS_NONE #1987

Open
1 task done
SelvinPL opened this issue Mar 28, 2023 · 2 comments
Open
1 task done

Custom implementation of osal_task_delay for OS_NONE #1987

SelvinPL opened this issue Mar 28, 2023 · 2 comments

Comments

@SelvinPL
Copy link

SelvinPL commented Mar 28, 2023

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

  • I confirm I have checked existing issues, dicussion and documentation.
@hathach
Copy link
Owner

hathach commented Mar 28, 2023

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

@abakosh
Copy link

abakosh commented Jun 27, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants