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_Robin.c 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*----------------------------------------------------------------------------
  2. * RL-ARM - RTX
  3. *----------------------------------------------------------------------------
  4. * Name: RT_ROBIN.C
  5. * Purpose: Round Robin Task switching
  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_Conf.h"
  36. #include "rt_List.h"
  37. #include "rt_Task.h"
  38. #include "rt_Time.h"
  39. #include "rt_Robin.h"
  40. #include "rt_HAL_CM.h"
  41. /*----------------------------------------------------------------------------
  42. * Global Variables
  43. *---------------------------------------------------------------------------*/
  44. struct OS_ROBIN os_robin;
  45. /*----------------------------------------------------------------------------
  46. * Global Functions
  47. *---------------------------------------------------------------------------*/
  48. /*--------------------------- rt_init_robin ---------------------------------*/
  49. __weak void rt_init_robin (void) {
  50. /* Initialize Round Robin variables. */
  51. os_robin.task = NULL;
  52. os_robin.tout = (U16)os_rrobin;
  53. }
  54. /*--------------------------- rt_chk_robin ----------------------------------*/
  55. __weak void rt_chk_robin (void) {
  56. /* Check if Round Robin timeout expired and switch to the next ready task.*/
  57. P_TCB p_new;
  58. if (os_robin.task != os_rdy.p_lnk) {
  59. /* New task was suspended, reset Round Robin timeout. */
  60. os_robin.task = os_rdy.p_lnk;
  61. os_robin.time = (U16)os_time + os_robin.tout - 1;
  62. }
  63. if (os_robin.time == (U16)os_time) {
  64. /* Round Robin timeout has expired, swap Robin tasks. */
  65. os_robin.task = NULL;
  66. p_new = rt_get_first (&os_rdy);
  67. rt_put_prio ((P_XCB)&os_rdy, p_new);
  68. }
  69. }
  70. /*----------------------------------------------------------------------------
  71. * end of file
  72. *---------------------------------------------------------------------------*/