usb_osal_rtthread.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * @file usb_osal_rtthread.c
  3. * @brief
  4. *
  5. * Copyright (c) 2022 sakumisu
  6. *
  7. * Licensed to the Apache Software Foundation (ASF) under one or more
  8. * contributor license agreements. See the NOTICE file distributed with
  9. * this work for additional information regarding copyright ownership. The
  10. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  11. * "License"); you may not use this file except in compliance with the
  12. * License. You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  18. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  19. * License for the specific language governing permissions and limitations
  20. * under the License.
  21. *
  22. */
  23. #include "usb_osal.h"
  24. #include <rtthread.h>
  25. usb_osal_thread_t usb_osal_thread_create(const char *name, uint32_t stack_size, uint32_t prio, usb_thread_entry_t entry, void *args)
  26. {
  27. rt_thread_t htask;
  28. htask = rt_thread_create(name, entry, args, stack_size, prio, 10);
  29. rt_thread_startup(htask);
  30. return (usb_osal_thread_t)htask;
  31. }
  32. usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count)
  33. {
  34. return (usb_osal_sem_t)rt_sem_create("usbh_sem", initial_count, RT_IPC_FLAG_FIFO);
  35. }
  36. int usb_osal_sem_take(usb_osal_sem_t sem)
  37. {
  38. return (int)rt_sem_take(sem, RT_WAITING_FOREVER);
  39. }
  40. int usb_osal_sem_give(usb_osal_sem_t sem)
  41. {
  42. return (int)rt_sem_release(sem);
  43. }
  44. usb_osal_mutex_t usb_osal_mutex_create(void)
  45. {
  46. return (usb_osal_mutex_t)rt_mutex_create("usbh_mutex", RT_IPC_FLAG_FIFO);
  47. }
  48. int usb_osal_mutex_take(usb_osal_mutex_t mutex)
  49. {
  50. return (int)rt_mutex_take(mutex, RT_WAITING_FOREVER);
  51. }
  52. int usb_osal_mutex_give(usb_osal_mutex_t mutex)
  53. {
  54. return (int)rt_mutex_release(mutex);
  55. }
  56. uint32_t usb_osal_enter_critical_section(void)
  57. {
  58. rt_enter_critical();
  59. return 1;
  60. }
  61. void usb_osal_leave_critical_section(uint32_t flag)
  62. {
  63. rt_exit_critical();
  64. }
  65. void usb_osal_msleep(uint32_t delay)
  66. {
  67. rt_thread_mdelay(delay);
  68. }