usb_osal_rtthread.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. void usb_osal_thread_suspend(usb_osal_thread_t thread)
  33. {
  34. rt_thread_suspend(thread);
  35. }
  36. void usb_osal_thread_resume(usb_osal_thread_t thread)
  37. {
  38. rt_thread_resume(thread);
  39. }
  40. usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count)
  41. {
  42. return (usb_osal_sem_t)rt_sem_create("usbh_sem", initial_count, RT_IPC_FLAG_FIFO);
  43. }
  44. void usb_osal_sem_delete(usb_osal_sem_t sem)
  45. {
  46. rt_sem_delete((rt_sem_t)sem);
  47. }
  48. int usb_osal_sem_take(usb_osal_sem_t sem, uint32_t timeout)
  49. {
  50. return (int)rt_sem_take((rt_sem_t)sem, rt_tick_from_millisecond(timeout));
  51. }
  52. int usb_osal_sem_give(usb_osal_sem_t sem)
  53. {
  54. return (int)rt_sem_release((rt_sem_t)sem);
  55. }
  56. usb_osal_mutex_t usb_osal_mutex_create(void)
  57. {
  58. return (usb_osal_mutex_t)rt_mutex_create("usbh_mutex", RT_IPC_FLAG_FIFO);
  59. }
  60. void usb_osal_mutex_delete(usb_osal_mutex_t mutex)
  61. {
  62. rt_mutex_delete((rt_mutex_t)mutex);
  63. }
  64. int usb_osal_mutex_take(usb_osal_mutex_t mutex)
  65. {
  66. return (int)rt_mutex_take((rt_mutex_t)mutex, RT_WAITING_FOREVER);
  67. }
  68. int usb_osal_mutex_give(usb_osal_mutex_t mutex)
  69. {
  70. return (int)rt_mutex_release((rt_mutex_t)mutex);
  71. }
  72. usb_osal_event_t usb_osal_event_create(void)
  73. {
  74. return (usb_osal_event_t)rt_event_create("psc_event", RT_IPC_FLAG_FIFO);
  75. }
  76. void usb_osal_event_delete(usb_osal_event_t event)
  77. {
  78. rt_event_delete((rt_event_t)event);
  79. }
  80. int usb_osal_event_recv(usb_osal_event_t event, uint32_t set, uint32_t *recved)
  81. {
  82. rt_event_recv((rt_event_t)event, set, RT_EVENT_FLAG_OR, RT_WAITING_FOREVER, recved);
  83. }
  84. int usb_osal_event_send(usb_osal_event_t event, uint32_t set)
  85. {
  86. rt_event_send((rt_event_t)event, set);
  87. }
  88. uint32_t usb_osal_enter_critical_section(void)
  89. {
  90. return rt_hw_interrupt_disable();
  91. }
  92. void usb_osal_leave_critical_section(uint32_t flag)
  93. {
  94. rt_hw_interrupt_enable(flag);
  95. }
  96. void usb_osal_msleep(uint32_t delay)
  97. {
  98. rt_thread_mdelay(rt_tick_from_millisecond(delay));
  99. }