portmacro.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * FreeRTOS Kernel <DEVELOPMENT BRANCH>
  3. * Copyright 2020 Cambridge Consultants Ltd.
  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. #ifndef PORTMACRO_H
  29. #define PORTMACRO_H
  30. /* *INDENT-OFF* */
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. /* *INDENT-ON* */
  35. #include <limits.h>
  36. #include <stdint.h>
  37. /*-----------------------------------------------------------
  38. * Port specific definitions.
  39. *
  40. * The settings in this file configure FreeRTOS correctly for the
  41. * given hardware and compiler.
  42. *
  43. * These settings should not be altered.
  44. *-----------------------------------------------------------
  45. */
  46. /* Type definitions. */
  47. #define portCHAR char
  48. #define portFLOAT float
  49. #define portDOUBLE double
  50. #define portLONG long
  51. #define portSHORT short
  52. #define portSTACK_TYPE unsigned long
  53. #define portBASE_TYPE long
  54. #define portPOINTER_SIZE_TYPE intptr_t
  55. typedef portSTACK_TYPE StackType_t;
  56. typedef long BaseType_t;
  57. typedef unsigned long UBaseType_t;
  58. typedef unsigned long TickType_t;
  59. #define portMAX_DELAY ( ( TickType_t ) ULONG_MAX )
  60. #define portTICK_TYPE_IS_ATOMIC 1
  61. /*-----------------------------------------------------------*/
  62. /* Architecture specifics. */
  63. #define portSTACK_GROWTH ( -1 )
  64. #define portHAS_STACK_OVERFLOW_CHECKING ( 1 )
  65. #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
  66. #define portTICK_RATE_MICROSECONDS ( ( TickType_t ) 1000000 / configTICK_RATE_HZ )
  67. #define portBYTE_ALIGNMENT 8
  68. /*-----------------------------------------------------------*/
  69. /* Scheduler utilities. */
  70. extern void vPortYield( void );
  71. #define portYIELD() vPortYield()
  72. #define portEND_SWITCHING_ISR( xSwitchRequired ) \
  73. do \
  74. { \
  75. if( xSwitchRequired != pdFALSE ) \
  76. { \
  77. traceISR_EXIT_TO_SCHEDULER(); \
  78. vPortYield(); \
  79. } \
  80. else \
  81. { \
  82. traceISR_EXIT(); \
  83. } \
  84. } while( 0 )
  85. #define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x )
  86. /*-----------------------------------------------------------*/
  87. /* Critical section management. */
  88. extern void vPortDisableInterrupts( void );
  89. extern void vPortEnableInterrupts( void );
  90. #define portSET_INTERRUPT_MASK() ( vPortDisableInterrupts() )
  91. #define portCLEAR_INTERRUPT_MASK() ( vPortEnableInterrupts() )
  92. extern UBaseType_t xPortSetInterruptMask( void );
  93. extern void vPortClearInterruptMask( UBaseType_t xMask );
  94. extern void vPortEnterCritical( void );
  95. extern void vPortExitCritical( void );
  96. #define portSET_INTERRUPT_MASK_FROM_ISR() xPortSetInterruptMask()
  97. #define portCLEAR_INTERRUPT_MASK_FROM_ISR( x ) vPortClearInterruptMask( x )
  98. #define portDISABLE_INTERRUPTS() portSET_INTERRUPT_MASK()
  99. #define portENABLE_INTERRUPTS() portCLEAR_INTERRUPT_MASK()
  100. #define portENTER_CRITICAL() vPortEnterCritical()
  101. #define portEXIT_CRITICAL() vPortExitCritical()
  102. /*-----------------------------------------------------------*/
  103. extern void vPortThreadDying( void * pxTaskToDelete,
  104. volatile BaseType_t * pxPendYield );
  105. extern void vPortCancelThread( void * pxTaskToDelete );
  106. #define portPRE_TASK_DELETE_HOOK( pvTaskToDelete, pxPendYield ) vPortThreadDying( ( pvTaskToDelete ), ( pxPendYield ) )
  107. #define portCLEAN_UP_TCB( pxTCB ) vPortCancelThread( pxTCB )
  108. /*-----------------------------------------------------------*/
  109. #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void * pvParameters ) __attribute__( ( noreturn ) )
  110. #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void * pvParameters )
  111. /*-----------------------------------------------------------*/
  112. /*
  113. * Tasks run in their own pthreads and context switches between them
  114. * are always a full memory barrier. ISRs are emulated as signals
  115. * which also imply a full memory barrier.
  116. *
  117. * Thus, only a compiler barrier is needed to prevent the compiler
  118. * reordering.
  119. */
  120. #define portMEMORY_BARRIER() __asm volatile ( "" ::: "memory" )
  121. extern uint32_t ulPortGetRunTime( void );
  122. #define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() /* no-op */
  123. #define portGET_RUN_TIME_COUNTER_VALUE() ulPortGetRunTime()
  124. /* *INDENT-OFF* */
  125. #ifdef __cplusplus
  126. }
  127. #endif
  128. /* *INDENT-ON* */
  129. #endif /* PORTMACRO_H */