port.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. /* Kernel includes. */
  29. #include "FreeRTOS.h"
  30. #include "task.h"
  31. #define portINITIAL_FORMAT_VECTOR ( ( StackType_t ) 0x4000 )
  32. /* Supervisor mode set. */
  33. #define portINITIAL_STATUS_REGISTER ( ( StackType_t ) 0x2000)
  34. /* Used to keep track of the number of nested calls to taskENTER_CRITICAL(). This
  35. will be set to 0 prior to the first task being started. */
  36. static uint32_t ulCriticalNesting = 0x9999UL;
  37. /*-----------------------------------------------------------*/
  38. StackType_t *pxPortInitialiseStack( StackType_t * pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
  39. {
  40. *pxTopOfStack = ( StackType_t ) pvParameters;
  41. pxTopOfStack--;
  42. *pxTopOfStack = (StackType_t) 0xDEADBEEF;
  43. pxTopOfStack--;
  44. /* Exception stack frame starts with the return address. */
  45. *pxTopOfStack = ( StackType_t ) pxCode;
  46. pxTopOfStack--;
  47. *pxTopOfStack = ( portINITIAL_FORMAT_VECTOR << 16UL ) | ( portINITIAL_STATUS_REGISTER );
  48. pxTopOfStack--;
  49. *pxTopOfStack = ( StackType_t ) 0x0; /*FP*/
  50. pxTopOfStack -= 14; /* A5 to D0. */
  51. return pxTopOfStack;
  52. }
  53. /*-----------------------------------------------------------*/
  54. BaseType_t xPortStartScheduler( void )
  55. {
  56. extern void vPortStartFirstTask( void );
  57. ulCriticalNesting = 0UL;
  58. /* Configure the interrupts used by this port. */
  59. vApplicationSetupInterrupts();
  60. /* Start the first task executing. */
  61. vPortStartFirstTask();
  62. return pdFALSE;
  63. }
  64. /*-----------------------------------------------------------*/
  65. void vPortEndScheduler( void )
  66. {
  67. /* Not implemented as there is nothing to return to. */
  68. }
  69. /*-----------------------------------------------------------*/
  70. void vPortEnterCritical( void )
  71. {
  72. if( ulCriticalNesting == 0UL )
  73. {
  74. /* Guard against context switches being pended simultaneously with a
  75. critical section being entered. */
  76. do
  77. {
  78. portDISABLE_INTERRUPTS();
  79. if( MCF_INTC0_INTFRCL == 0UL )
  80. {
  81. break;
  82. }
  83. portENABLE_INTERRUPTS();
  84. } while( 1 );
  85. }
  86. ulCriticalNesting++;
  87. }
  88. /*-----------------------------------------------------------*/
  89. void vPortExitCritical( void )
  90. {
  91. ulCriticalNesting--;
  92. if( ulCriticalNesting == 0 )
  93. {
  94. portENABLE_INTERRUPTS();
  95. }
  96. }
  97. /*-----------------------------------------------------------*/
  98. void vPortYieldHandler( void )
  99. {
  100. uint32_t ulSavedInterruptMask;
  101. ulSavedInterruptMask = portSET_INTERRUPT_MASK_FROM_ISR();
  102. /* Note this will clear all forced interrupts - this is done for speed. */
  103. MCF_INTC0_INTFRCL = 0;
  104. vTaskSwitchContext();
  105. portCLEAR_INTERRUPT_MASK_FROM_ISR( ulSavedInterruptMask );
  106. }