rtx_delay.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (c) 2013-2016 ARM Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the License); you may
  7. * not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  14. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * -----------------------------------------------------------------------------
  19. *
  20. * Project: CMSIS-RTOS RTX
  21. * Title: Delay functions
  22. *
  23. * -----------------------------------------------------------------------------
  24. */
  25. #include "rtx_lib.h"
  26. // ==== Service Calls ====
  27. // Service Calls definitions
  28. SVC0_1(Delay, osStatus_t, uint32_t)
  29. SVC0_1(DelayUntil, osStatus_t, uint64_t)
  30. /// Wait for Timeout (Time Delay).
  31. /// \note API identical to osDelay
  32. osStatus_t os_svcDelay (uint32_t millisec) {
  33. if (millisec == 0U) {
  34. return osOK;
  35. }
  36. os_ThreadWaitEnter(os_ThreadWaitingDelay, millisec);
  37. return osOK;
  38. }
  39. /// Wait until specified time.
  40. /// \note API identical to osDelayUntil
  41. osStatus_t os_svcDelayUntil (uint64_t millisec) {
  42. millisec -= os_Info.kernel.time;
  43. if (millisec >= 0xFFFFFFFFU) {
  44. return osError;
  45. }
  46. os_ThreadWaitEnter(os_ThreadWaitingDelay, (uint32_t)millisec);
  47. return osOK;
  48. }
  49. // ==== Public API ====
  50. /// Wait for Timeout (Time Delay).
  51. osStatus_t osDelay (uint32_t millisec) {
  52. if (__get_IPSR() != 0U) {
  53. return osErrorISR; // Not allowed in ISR
  54. }
  55. return __svcDelay(millisec);
  56. }
  57. /// Wait until specified time.
  58. osStatus_t osDelayUntil (uint64_t millisec) {
  59. if (__get_IPSR() != 0U) {
  60. return osErrorISR; // Not allowed in ISR
  61. }
  62. return __svcDelayUntil(millisec);
  63. }