portext.s43 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. #include "msp430.h"
  29. #include "FreeRTOSConfig.h"
  30. #include "data_model.h"
  31. IMPORT xTaskIncrementTick
  32. IMPORT vTaskSwitchContext
  33. IMPORT vPortSetupTimerInterrupt
  34. IMPORT pxCurrentTCB
  35. IMPORT usCriticalNesting
  36. EXPORT vPortTickISR
  37. EXPORT vPortYield
  38. EXPORT xPortStartScheduler
  39. portSAVE_CONTEXT macro
  40. /* Save the remaining registers. */
  41. pushm_x #12, r15
  42. mov.w &usCriticalNesting, r14
  43. push_x r14
  44. mov_x &pxCurrentTCB, r12
  45. mov_x sp, 0( r12 )
  46. endm
  47. /*-----------------------------------------------------------*/
  48. portRESTORE_CONTEXT macro
  49. mov_x &pxCurrentTCB, r12
  50. mov_x @r12, sp
  51. pop_x r15
  52. mov.w r15, &usCriticalNesting
  53. popm_x #12, r15
  54. nop
  55. pop.w sr
  56. nop
  57. reta
  58. endm
  59. /*-----------------------------------------------------------*/
  60. /*
  61. * The RTOS tick ISR.
  62. *
  63. * If the cooperative scheduler is in use this simply increments the tick
  64. * count.
  65. *
  66. * If the preemptive scheduler is in use a context switch can also occur.
  67. */
  68. RSEG CODE
  69. EVEN
  70. vPortTickISR:
  71. /* The sr is not saved in portSAVE_CONTEXT() because vPortYield() needs
  72. to save it manually before it gets modified (interrupts get disabled).
  73. Entering through this interrupt means the SR is already on the stack, but
  74. this keeps the stack frames identical. */
  75. push.w sr
  76. portSAVE_CONTEXT
  77. calla #xTaskIncrementTick
  78. cmp.w #0x0, R12
  79. jeq SkipContextSwitch
  80. calla #vTaskSwitchContext
  81. SkipContextSwitch:
  82. portRESTORE_CONTEXT
  83. /*-----------------------------------------------------------*/
  84. /*
  85. * Manual context switch called by the portYIELD() macro.
  86. */
  87. EVEN
  88. vPortYield:
  89. /* The sr needs saving before it is modified. */
  90. push.w sr
  91. /* Now the SR is stacked interrupts can be disabled. */
  92. dint
  93. nop
  94. /* Save the context of the current task. */
  95. portSAVE_CONTEXT
  96. /* Select the next task to run. */
  97. calla #vTaskSwitchContext
  98. /* Restore the context of the new task. */
  99. portRESTORE_CONTEXT
  100. /*-----------------------------------------------------------*/
  101. /*
  102. * Start off the scheduler by initialising the RTOS tick timer, then restoring
  103. * the context of the first task.
  104. */
  105. EVEN
  106. xPortStartScheduler:
  107. /* Setup the hardware to generate the tick. Interrupts are disabled
  108. when this function is called. */
  109. calla #vPortSetupTimerInterrupt
  110. /* Restore the context of the first task that is going to run. */
  111. portRESTORE_CONTEXT
  112. /*-----------------------------------------------------------*/
  113. END