portASM.s 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. ;/*
  2. ; FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
  3. ; All rights reserved
  4. ;
  5. ;
  6. ; ***************************************************************************
  7. ; * *
  8. ; * FreeRTOS tutorial books are available in pdf and paperback. *
  9. ; * Complete, revised, and edited pdf reference manuals are also *
  10. ; * available. *
  11. ; * *
  12. ; * Purchasing FreeRTOS documentation will not only help you, by *
  13. ; * ensuring you get running as quickly as possible and with an *
  14. ; * in-depth knowledge of how to use FreeRTOS, it will also help *
  15. ; * the FreeRTOS project to continue with its mission of providing *
  16. ; * professional grade, cross platform, de facto standard solutions *
  17. ; * for microcontrollers - completely free of charge! *
  18. ; * *
  19. ; * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
  20. ; * *
  21. ; * Thank you for using FreeRTOS, and thank you for your support! *
  22. ; * *
  23. ; ***************************************************************************
  24. ;
  25. ;
  26. ; This file is part of the FreeRTOS distribution.
  27. ;
  28. ; FreeRTOS is free software; you can redistribute it and/or modify it under
  29. ; the terms of the GNU General Public License (version 2) as published by the
  30. ; Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
  31. ; >>>NOTE<<< The modification to the GPL is included to allow you to
  32. ; distribute a combined work that includes FreeRTOS without being obliged to
  33. ; provide the source code for proprietary components outside of the FreeRTOS
  34. ; kernel. FreeRTOS is distributed in the hope that it will be useful, but
  35. ; WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  36. ; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  37. ; more details. You should have received a copy of the GNU General Public
  38. ; License and the FreeRTOS license exception along with FreeRTOS; if not it
  39. ; can be viewed here: http://www.freertos.org/a00114.html and also obtained
  40. ; by writing to Richard Barry, contact details for whom are available on the
  41. ; FreeRTOS WEB site.
  42. ;
  43. ; 1 tab == 4 spaces!
  44. ;
  45. ; http://www.FreeRTOS.org - Documentation, latest information, license and
  46. ; contact details.
  47. ;
  48. ; http://www.SafeRTOS.com - A version that is certified for use in safety
  49. ; critical systems.
  50. ;
  51. ; http://www.OpenRTOS.com - Commercial support, development, porting,
  52. ; licensing and training services.
  53. ;*/
  54. INCLUDE portmacro.inc
  55. IMPORT vTaskSwitchContext
  56. IMPORT xTaskIncrementTick
  57. EXPORT vPortYieldProcessor
  58. EXPORT vPortStartFirstTask
  59. EXPORT vPreemptiveTick
  60. EXPORT vPortYield
  61. VICVECTADDR EQU 0xFFFFF030
  62. T0IR EQU 0xE0004000
  63. T0MATCHBIT EQU 0x00000001
  64. ARM
  65. AREA PORT_ASM, CODE, READONLY
  66. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  67. ; Starting the first task is done by just restoring the context
  68. ; setup by pxPortInitialiseStack
  69. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  70. vPortStartFirstTask
  71. PRESERVE8
  72. portRESTORE_CONTEXT
  73. vPortYield
  74. PRESERVE8
  75. SVC 0
  76. bx lr
  77. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  78. ; Interrupt service routine for the SWI interrupt. The vector table is
  79. ; configured in the startup.s file.
  80. ;
  81. ; vPortYieldProcessor() is used to manually force a context switch. The
  82. ; SWI interrupt is generated by a call to taskYIELD() or portYIELD().
  83. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  84. vPortYieldProcessor
  85. PRESERVE8
  86. ; Within an IRQ ISR the link register has an offset from the true return
  87. ; address, but an SWI ISR does not. Add the offset manually so the same
  88. ; ISR return code can be used in both cases.
  89. ADD LR, LR, #4
  90. ; Perform the context switch.
  91. portSAVE_CONTEXT ; Save current task context
  92. LDR R0, =vTaskSwitchContext ; Get the address of the context switch function
  93. MOV LR, PC ; Store the return address
  94. BX R0 ; Call the contedxt switch function
  95. portRESTORE_CONTEXT ; restore the context of the selected task
  96. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  97. ; Interrupt service routine for preemptive scheduler tick timer
  98. ; Only used if portUSE_PREEMPTION is set to 1 in portmacro.h
  99. ;
  100. ; Uses timer 0 of LPC21XX Family
  101. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  102. vPreemptiveTick
  103. PRESERVE8
  104. portSAVE_CONTEXT ; Save the context of the current task.
  105. LDR R0, =xTaskIncrementTick ; Increment the tick count.
  106. MOV LR, PC ; This may make a delayed task ready
  107. BX R0 ; to run.
  108. CMP R0, #0
  109. BEQ SkipContextSwitch
  110. LDR R0, =vTaskSwitchContext ; Find the highest priority task that
  111. MOV LR, PC ; is ready to run.
  112. BX R0
  113. SkipContextSwitch
  114. MOV R0, #T0MATCHBIT ; Clear the timer event
  115. LDR R1, =T0IR
  116. STR R0, [R1]
  117. LDR R0, =VICVECTADDR ; Acknowledge the interrupt
  118. STR R0,[R0]
  119. portRESTORE_CONTEXT ; Restore the context of the highest
  120. ; priority task that is ready to run.
  121. END