portext.asm 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. ;/*
  2. ; * FreeRTOS Kernel V10.4.6
  3. ; * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. ; *
  5. ; * SPDX-License-Identifier: MIT
  6. ; *
  7. ; * Permission is hereby granted, free of charge, to any person obtaining a copy of
  8. ; * this software and associated documentation files (the "Software"), to deal in
  9. ; * the Software without restriction, including without limitation the rights to
  10. ; * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  11. ; * the Software, and to permit persons to whom the Software is furnished to do so,
  12. ; * subject to the following conditions:
  13. ; *
  14. ; * The above copyright notice and this permission notice shall be included in all
  15. ; * copies or substantial portions of the Software.
  16. ; *
  17. ; * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. ; * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  19. ; * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  20. ; * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  21. ; * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. ; * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. ; *
  24. ; * https://www.FreeRTOS.org
  25. ; * https://github.com/FreeRTOS
  26. ; *
  27. ; */
  28. ; * The definition of the "register test" tasks, as described at the top of
  29. ; * main.c
  30. .include data_model.h
  31. .global xTaskIncrementTick
  32. .global vTaskSwitchContext
  33. .global vPortSetupTimerInterrupt
  34. .global pxCurrentTCB
  35. .global usCriticalNesting
  36. .def vPortPreemptiveTickISR
  37. .def vPortCooperativeTickISR
  38. .def vPortYield
  39. .def xPortStartScheduler
  40. ;-----------------------------------------------------------
  41. portSAVE_CONTEXT .macro
  42. ;Save the remaining registers.
  43. pushm_x #12, r15
  44. mov.w &usCriticalNesting, r14
  45. push_x r14
  46. mov_x &pxCurrentTCB, r12
  47. mov_x sp, 0( r12 )
  48. .endm
  49. ;-----------------------------------------------------------
  50. portRESTORE_CONTEXT .macro
  51. mov_x &pxCurrentTCB, r12
  52. mov_x @r12, sp
  53. pop_x r15
  54. mov.w r15, &usCriticalNesting
  55. popm_x #12, r15
  56. nop
  57. pop.w sr
  58. nop
  59. ret_x
  60. .endm
  61. ;-----------------------------------------------------------
  62. ;*
  63. ;* The RTOS tick ISR.
  64. ;*
  65. ;* If the cooperative scheduler is in use this simply increments the tick
  66. ;* count.
  67. ;*
  68. ;* If the preemptive scheduler is in use a context switch can also occur.
  69. ;*/
  70. .text
  71. .align 2
  72. vPortPreemptiveTickISR: .asmfunc
  73. ; The sr is not saved in portSAVE_CONTEXT() because vPortYield() needs
  74. ;to save it manually before it gets modified (interrupts get disabled).
  75. push.w sr
  76. portSAVE_CONTEXT
  77. call_x #xTaskIncrementTick
  78. call_x #vTaskSwitchContext
  79. portRESTORE_CONTEXT
  80. .endasmfunc
  81. ;-----------------------------------------------------------
  82. .align 2
  83. vPortCooperativeTickISR: .asmfunc
  84. ; The sr is not saved in portSAVE_CONTEXT() because vPortYield() needs
  85. ;to save it manually before it gets modified (interrupts get disabled).
  86. push.w sr
  87. portSAVE_CONTEXT
  88. call_x #xTaskIncrementTick
  89. portRESTORE_CONTEXT
  90. .endasmfunc
  91. ;-----------------------------------------------------------
  92. ;
  93. ; Manual context switch called by the portYIELD() macro.
  94. ;
  95. .align 2
  96. vPortYield: .asmfunc
  97. ; The sr needs saving before it is modified.
  98. push.w sr
  99. ; Now the SR is stacked we can disable interrupts.
  100. dint
  101. nop
  102. ; Save the context of the current task.
  103. portSAVE_CONTEXT
  104. ; Select the next task to run.
  105. call_x #vTaskSwitchContext
  106. ; Restore the context of the new task.
  107. portRESTORE_CONTEXT
  108. .endasmfunc
  109. ;-----------------------------------------------------------
  110. ;
  111. ; Start off the scheduler by initialising the RTOS tick timer, then restoring
  112. ; the context of the first task.
  113. ;
  114. .align 2
  115. xPortStartScheduler: .asmfunc
  116. ; Setup the hardware to generate the tick. Interrupts are disabled
  117. ; when this function is called.
  118. call_x #vPortSetupTimerInterrupt
  119. ; Restore the context of the first task that is going to run.
  120. portRESTORE_CONTEXT
  121. .endasmfunc
  122. ;-----------------------------------------------------------
  123. .end