rt_Robin.c 2.6 KB

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