rtx_delay.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (c) 2013-2018 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. if (ticks != 0U) {
  31. if (!osRtxThreadWaitEnter(osRtxThreadWaitingDelay, ticks)) {
  32. EvrRtxThreadDelayCompleted();
  33. }
  34. }
  35. return osOK;
  36. }
  37. /// Wait until specified time.
  38. /// \note API identical to osDelayUntil
  39. static osStatus_t svcRtxDelayUntil (uint32_t ticks) {
  40. ticks -= osRtxInfo.kernel.tick;
  41. if ((ticks == 0U) || (ticks > 0x7FFFFFFFU)) {
  42. EvrRtxThreadError(NULL, (int32_t)osErrorParameter);
  43. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  44. return osErrorParameter;
  45. }
  46. if (!osRtxThreadWaitEnter(osRtxThreadWaitingDelay, ticks)) {
  47. EvrRtxThreadDelayCompleted();
  48. }
  49. return osOK;
  50. }
  51. // Service Calls definitions
  52. //lint ++flb "Library Begin" [MISRA Note 11]
  53. SVC0_1(Delay, osStatus_t, uint32_t)
  54. SVC0_1(DelayUntil, osStatus_t, uint32_t)
  55. //lint --flb "Library End"
  56. // ==== Public API ====
  57. /// Wait for Timeout (Time Delay).
  58. osStatus_t osDelay (uint32_t ticks) {
  59. osStatus_t status;
  60. EvrRtxThreadDelay(ticks);
  61. if (IsIrqMode() || IsIrqMasked()) {
  62. EvrRtxThreadError(NULL, (int32_t)osErrorISR);
  63. status = osErrorISR;
  64. } else {
  65. status = __svcDelay(ticks);
  66. }
  67. return status;
  68. }
  69. /// Wait until specified time.
  70. osStatus_t osDelayUntil (uint32_t ticks) {
  71. osStatus_t status;
  72. EvrRtxThreadDelayUntil(ticks);
  73. if (IsIrqMode() || IsIrqMasked()) {
  74. EvrRtxThreadError(NULL, (int32_t)osErrorISR);
  75. status = osErrorISR;
  76. } else {
  77. status = __svcDelayUntil(ticks);
  78. }
  79. return status;
  80. }