port.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. /*-----------------------------------------------------------
  29. * Implementation of functions defined in portable.h for the SH2A port.
  30. *----------------------------------------------------------*/
  31. /* Scheduler includes. */
  32. #include "FreeRTOS.h"
  33. #include "task.h"
  34. /* Library includes. */
  35. #include "string.h"
  36. /* Hardware specifics. */
  37. #include <iorx62n.h>
  38. /*-----------------------------------------------------------*/
  39. /* Tasks should start with interrupts enabled and in Supervisor mode, therefore
  40. PSW is set with U and I set, and PM and IPL clear. */
  41. #define portINITIAL_PSW ( ( StackType_t ) 0x00030000 )
  42. #define portINITIAL_FPSW ( ( StackType_t ) 0x00000100 )
  43. /*-----------------------------------------------------------*/
  44. /*
  45. * Function to start the first task executing - written in asm code as direct
  46. * access to registers is required.
  47. */
  48. extern void prvStartFirstTask( void );
  49. /*
  50. * The tick ISR handler. The peripheral used is configured by the application
  51. * via a hook/callback function.
  52. */
  53. __interrupt void vTickISR( void );
  54. /*-----------------------------------------------------------*/
  55. extern void *pxCurrentTCB;
  56. /*-----------------------------------------------------------*/
  57. /*
  58. * See header file for description.
  59. */
  60. StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
  61. {
  62. /* R0 is not included as it is the stack pointer. */
  63. *pxTopOfStack = 0x00;
  64. pxTopOfStack--;
  65. *pxTopOfStack = portINITIAL_PSW;
  66. pxTopOfStack--;
  67. *pxTopOfStack = ( StackType_t ) pxCode;
  68. /* When debugging it can be useful if every register is set to a known
  69. value. Otherwise code space can be saved by just setting the registers
  70. that need to be set. */
  71. #ifdef USE_FULL_REGISTER_INITIALISATION
  72. {
  73. pxTopOfStack--;
  74. *pxTopOfStack = 0xffffffff; /* r15. */
  75. pxTopOfStack--;
  76. *pxTopOfStack = 0xeeeeeeee;
  77. pxTopOfStack--;
  78. *pxTopOfStack = 0xdddddddd;
  79. pxTopOfStack--;
  80. *pxTopOfStack = 0xcccccccc;
  81. pxTopOfStack--;
  82. *pxTopOfStack = 0xbbbbbbbb;
  83. pxTopOfStack--;
  84. *pxTopOfStack = 0xaaaaaaaa;
  85. pxTopOfStack--;
  86. *pxTopOfStack = 0x99999999;
  87. pxTopOfStack--;
  88. *pxTopOfStack = 0x88888888;
  89. pxTopOfStack--;
  90. *pxTopOfStack = 0x77777777;
  91. pxTopOfStack--;
  92. *pxTopOfStack = 0x66666666;
  93. pxTopOfStack--;
  94. *pxTopOfStack = 0x55555555;
  95. pxTopOfStack--;
  96. *pxTopOfStack = 0x44444444;
  97. pxTopOfStack--;
  98. *pxTopOfStack = 0x33333333;
  99. pxTopOfStack--;
  100. *pxTopOfStack = 0x22222222;
  101. pxTopOfStack--;
  102. }
  103. #else
  104. {
  105. pxTopOfStack -= 15;
  106. }
  107. #endif
  108. *pxTopOfStack = ( StackType_t ) pvParameters; /* R1 */
  109. pxTopOfStack--;
  110. *pxTopOfStack = portINITIAL_FPSW;
  111. pxTopOfStack--;
  112. *pxTopOfStack = 0x12345678; /* Accumulator. */
  113. pxTopOfStack--;
  114. *pxTopOfStack = 0x87654321; /* Accumulator. */
  115. return pxTopOfStack;
  116. }
  117. /*-----------------------------------------------------------*/
  118. BaseType_t xPortStartScheduler( void )
  119. {
  120. extern void vApplicationSetupTimerInterrupt( void );
  121. /* Use pxCurrentTCB just so it does not get optimised away. */
  122. if( pxCurrentTCB != NULL )
  123. {
  124. /* Call an application function to set up the timer that will generate the
  125. tick interrupt. This way the application can decide which peripheral to
  126. use. A demo application is provided to show a suitable example. */
  127. vApplicationSetupTimerInterrupt();
  128. /* Enable the software interrupt. */
  129. _IEN( _ICU_SWINT ) = 1;
  130. /* Ensure the software interrupt is clear. */
  131. _IR( _ICU_SWINT ) = 0;
  132. /* Ensure the software interrupt is set to the kernel priority. */
  133. _IPR( _ICU_SWINT ) = configKERNEL_INTERRUPT_PRIORITY;
  134. /* Start the first task. */
  135. prvStartFirstTask();
  136. }
  137. /* Should not get here. */
  138. return pdFAIL;
  139. }
  140. /*-----------------------------------------------------------*/
  141. #pragma vector = configTICK_VECTOR
  142. __interrupt void vTickISR( void )
  143. {
  144. /* Re-enable interrupts. */
  145. __enable_interrupt();
  146. /* Increment the tick, and perform any processing the new tick value
  147. necessitates. */
  148. __set_interrupt_level( configMAX_SYSCALL_INTERRUPT_PRIORITY );
  149. {
  150. if( xTaskIncrementTick() != pdFALSE )
  151. {
  152. taskYIELD();
  153. }
  154. }
  155. __set_interrupt_level( configKERNEL_INTERRUPT_PRIORITY );
  156. }
  157. /*-----------------------------------------------------------*/
  158. void vPortEndScheduler( void )
  159. {
  160. /* Not implemented in ports where there is nothing to return to.
  161. Artificially force an assert. */
  162. configASSERT( pxCurrentTCB == NULL );
  163. }
  164. /*-----------------------------------------------------------*/