rt_Time.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*----------------------------------------------------------------------------
  2. * CMSIS-RTOS - RTX
  3. *----------------------------------------------------------------------------
  4. * Name: RT_TIME.C
  5. * Purpose: Delay and interval wait functions
  6. * Rev.: V4.79
  7. *----------------------------------------------------------------------------
  8. *
  9. * Copyright (c) 1999-2009 KEIL, 2009-2017 ARM Germany GmbH. All rights reserved.
  10. *
  11. * SPDX-License-Identifier: Apache-2.0
  12. *
  13. * Licensed under the Apache License, Version 2.0 (the License); you may
  14. * not use this file except in compliance with the License.
  15. * You may obtain a copy of the License at
  16. *
  17. * www.apache.org/licenses/LICENSE-2.0
  18. *
  19. * Unless required by applicable law or agreed to in writing, software
  20. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  21. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the License for the specific language governing permissions and
  23. * limitations under the License.
  24. *---------------------------------------------------------------------------*/
  25. #include "rt_TypeDef.h"
  26. #include "RTX_Config.h"
  27. #include "rt_Task.h"
  28. #include "rt_Time.h"
  29. /*----------------------------------------------------------------------------
  30. * Global Variables
  31. *---------------------------------------------------------------------------*/
  32. /* Free running system tick counter */
  33. U32 os_time;
  34. /*----------------------------------------------------------------------------
  35. * Functions
  36. *---------------------------------------------------------------------------*/
  37. /*--------------------------- rt_time_get -----------------------------------*/
  38. U32 rt_time_get (void) {
  39. /* Get system time tick */
  40. return (os_time);
  41. }
  42. /*--------------------------- rt_dly_wait -----------------------------------*/
  43. void rt_dly_wait (U16 delay_time) {
  44. /* Delay task by "delay_time" */
  45. rt_block (delay_time, WAIT_DLY);
  46. }
  47. /*--------------------------- rt_itv_set ------------------------------------*/
  48. void rt_itv_set (U16 interval_time) {
  49. /* Set interval length and define start of first interval */
  50. os_tsk.run->interval_time = interval_time;
  51. os_tsk.run->delta_time = interval_time + (U16)os_time;
  52. }
  53. /*--------------------------- rt_itv_wait -----------------------------------*/
  54. void rt_itv_wait (void) {
  55. /* Wait for interval end and define start of next one */
  56. U16 delta;
  57. delta = os_tsk.run->delta_time - (U16)os_time;
  58. os_tsk.run->delta_time += os_tsk.run->interval_time;
  59. if ((delta & 0x8000U) == 0U) {
  60. rt_block (delta, WAIT_ITV);
  61. }
  62. }
  63. /*----------------------------------------------------------------------------
  64. * end of file
  65. *---------------------------------------------------------------------------*/