Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rt_Time.c 3.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*----------------------------------------------------------------------------
  2. * RL-ARM - RTX
  3. *----------------------------------------------------------------------------
  4. * Name: RT_TIME.C
  5. * Purpose: Delay and interval wait functions
  6. * Rev.: V4.60
  7. *----------------------------------------------------------------------------
  8. *
  9. * Copyright (c) 1999-2009 KEIL, 2009-2012 ARM Germany GmbH
  10. * All rights reserved.
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. * - Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. * - Neither the name of ARM nor the names of its contributors may be used
  19. * to endorse or promote products derived from this software without
  20. * specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *---------------------------------------------------------------------------*/
  34. #include "rt_TypeDef.h"
  35. #include "RTX_Config.h"
  36. #include "rt_Task.h"
  37. #include "rt_Time.h"
  38. /*----------------------------------------------------------------------------
  39. * Global Variables
  40. *---------------------------------------------------------------------------*/
  41. /* Free running system tick counter */
  42. U32 os_time;
  43. /*----------------------------------------------------------------------------
  44. * Functions
  45. *---------------------------------------------------------------------------*/
  46. /*--------------------------- rt_time_get -----------------------------------*/
  47. U32 rt_time_get (void) {
  48. /* Get system time tick */
  49. return (os_time);
  50. }
  51. /*--------------------------- rt_dly_wait -----------------------------------*/
  52. void rt_dly_wait (U16 delay_time) {
  53. /* Delay task by "delay_time" */
  54. rt_block (delay_time, WAIT_DLY);
  55. }
  56. /*--------------------------- rt_itv_set ------------------------------------*/
  57. void rt_itv_set (U16 interval_time) {
  58. /* Set interval length and define start of first interval */
  59. os_tsk.run->interval_time = interval_time;
  60. os_tsk.run->delta_time = interval_time + (U16)os_time;
  61. }
  62. /*--------------------------- rt_itv_wait -----------------------------------*/
  63. void rt_itv_wait (void) {
  64. /* Wait for interval end and define start of next one */
  65. U16 delta;
  66. delta = os_tsk.run->delta_time - (U16)os_time;
  67. os_tsk.run->delta_time += os_tsk.run->interval_time;
  68. if ((delta & 0x8000) == 0) {
  69. rt_block (delta, WAIT_ITV);
  70. }
  71. }
  72. /*----------------------------------------------------------------------------
  73. * end of file
  74. *---------------------------------------------------------------------------*/