rtx_delay.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright (c) 2013-2021 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. * 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. /// Wait for Timeout (Time Delay).
  28. /// \note API identical to osDelay
  29. static osStatus_t svcRtxDelay (uint32_t ticks) {
  30. osStatus_t status;
  31. if (ticks == 0U) {
  32. EvrRtxDelayError((int32_t)osErrorParameter);
  33. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  34. return osErrorParameter;
  35. }
  36. if (osRtxThreadWaitEnter(osRtxThreadWaitingDelay, ticks)) {
  37. EvrRtxDelayStarted(ticks);
  38. status = osOK;
  39. } else {
  40. EvrRtxDelayError((int32_t)osError);
  41. status = osError;
  42. }
  43. return status;
  44. }
  45. /// Wait until specified time.
  46. /// \note API identical to osDelayUntil
  47. static osStatus_t svcRtxDelayUntil (uint32_t ticks) {
  48. osStatus_t status;
  49. ticks -= osRtxInfo.kernel.tick;
  50. if ((ticks == 0U) || (ticks > 0x7FFFFFFFU)) {
  51. EvrRtxDelayError((int32_t)osErrorParameter);
  52. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  53. return osErrorParameter;
  54. }
  55. if (osRtxThreadWaitEnter(osRtxThreadWaitingDelay, ticks)) {
  56. EvrRtxDelayUntilStarted(ticks);
  57. status = osOK;
  58. } else {
  59. EvrRtxDelayError((int32_t)osError);
  60. status = osError;
  61. }
  62. return status;
  63. }
  64. // Service Calls definitions
  65. //lint ++flb "Library Begin" [MISRA Note 11]
  66. SVC0_1(Delay, osStatus_t, uint32_t)
  67. SVC0_1(DelayUntil, osStatus_t, uint32_t)
  68. //lint --flb "Library End"
  69. // ==== Public API ====
  70. /// Wait for Timeout (Time Delay).
  71. osStatus_t osDelay (uint32_t ticks) {
  72. osStatus_t status;
  73. EvrRtxDelay(ticks);
  74. if (IsException() || IsIrqMasked()) {
  75. EvrRtxDelayError((int32_t)osErrorISR);
  76. status = osErrorISR;
  77. } else {
  78. status = __svcDelay(ticks);
  79. }
  80. return status;
  81. }
  82. /// Wait until specified time.
  83. osStatus_t osDelayUntil (uint32_t ticks) {
  84. osStatus_t status;
  85. EvrRtxDelayUntil(ticks);
  86. if (IsException() || IsIrqMasked()) {
  87. EvrRtxDelayError((int32_t)osErrorISR);
  88. status = osErrorISR;
  89. } else {
  90. status = __svcDelayUntil(ticks);
  91. }
  92. return status;
  93. }