portmacro.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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. #ifndef PORTMACRO_H
  29. #define PORTMACRO_H
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. /* BSP includes. */
  34. #include <mb_interface.h>
  35. #include <xparameters.h>
  36. /*-----------------------------------------------------------
  37. * Port specific definitions.
  38. *
  39. * The settings in this file configure FreeRTOS correctly for the
  40. * given hardware and compiler.
  41. *
  42. * These settings should not be altered.
  43. *-----------------------------------------------------------
  44. */
  45. /* Type definitions. */
  46. #define portCHAR char
  47. #define portFLOAT float
  48. #define portDOUBLE double
  49. #define portLONG long
  50. #define portSHORT short
  51. #define portSTACK_TYPE uint32_t
  52. #define portBASE_TYPE long
  53. typedef portSTACK_TYPE StackType_t;
  54. typedef long BaseType_t;
  55. typedef unsigned long UBaseType_t;
  56. #if( configUSE_16_BIT_TICKS == 1 )
  57. typedef uint16_t TickType_t;
  58. #define portMAX_DELAY ( TickType_t ) 0xffff
  59. #else
  60. typedef uint32_t TickType_t;
  61. #define portMAX_DELAY ( TickType_t ) 0xffffffffUL
  62. /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do
  63. not need to be guarded with a critical section. */
  64. #define portTICK_TYPE_IS_ATOMIC 1
  65. #endif
  66. /*-----------------------------------------------------------*/
  67. /* Interrupt control macros and functions. */
  68. void microblaze_disable_interrupts( void );
  69. void microblaze_enable_interrupts( void );
  70. #define portDISABLE_INTERRUPTS() microblaze_disable_interrupts()
  71. #define portENABLE_INTERRUPTS() microblaze_enable_interrupts()
  72. /*-----------------------------------------------------------*/
  73. /* Critical section macros. */
  74. void vPortEnterCritical( void );
  75. void vPortExitCritical( void );
  76. #define portENTER_CRITICAL() { \
  77. extern volatile UBaseType_t uxCriticalNesting; \
  78. microblaze_disable_interrupts(); \
  79. uxCriticalNesting++; \
  80. }
  81. #define portEXIT_CRITICAL() { \
  82. extern volatile UBaseType_t uxCriticalNesting; \
  83. /* Interrupts are disabled, so we can */ \
  84. /* access the variable directly. */ \
  85. uxCriticalNesting--; \
  86. if( uxCriticalNesting == 0 ) \
  87. { \
  88. /* The nesting has unwound and we \
  89. can enable interrupts again. */ \
  90. portENABLE_INTERRUPTS(); \
  91. } \
  92. }
  93. /*-----------------------------------------------------------*/
  94. /* The yield macro maps directly to the vPortYield() function. */
  95. void vPortYield( void );
  96. #define portYIELD() vPortYield()
  97. /* portYIELD_FROM_ISR() does not directly call vTaskSwitchContext(), but instead
  98. sets a flag to say that a yield has been requested. The interrupt exit code
  99. then checks this flag, and calls vTaskSwitchContext() before restoring a task
  100. context, if the flag is not false. This is done to prevent multiple calls to
  101. vTaskSwitchContext() being made from a single interrupt, as a single interrupt
  102. can result in multiple peripherals being serviced. */
  103. extern volatile uint32_t ulTaskSwitchRequested;
  104. #define portYIELD_FROM_ISR( x ) do { if( ( x ) != pdFALSE ) ulTaskSwitchRequested = 1; } while( 0 )
  105. #if( configUSE_PORT_OPTIMISED_TASK_SELECTION == 1 )
  106. /* Generic helper function. */
  107. __attribute__( ( always_inline ) ) static inline uint8_t ucPortCountLeadingZeros( uint32_t ulBitmap )
  108. {
  109. uint8_t ucReturn;
  110. __asm volatile ( "clz %0, %1" : "=r" ( ucReturn ) : "r" ( ulBitmap ) );
  111. return ucReturn;
  112. }
  113. /* Check the configuration. */
  114. #if( configMAX_PRIORITIES > 32 )
  115. #error configUSE_PORT_OPTIMISED_TASK_SELECTION can only be set to 1 when configMAX_PRIORITIES is less than or equal to 32. It is very rare that a system requires more than 10 to 15 difference priorities as tasks that share a priority will time slice.
  116. #endif
  117. /* Store/clear the ready priorities in a bit map. */
  118. #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )
  119. #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )
  120. /*-----------------------------------------------------------*/
  121. #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31UL - ( uint32_t ) ucPortCountLeadingZeros( ( uxReadyPriorities ) ) )
  122. #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
  123. /*-----------------------------------------------------------*/
  124. /* Hardware specifics. */
  125. #define portBYTE_ALIGNMENT 4
  126. #define portSTACK_GROWTH ( -1 )
  127. #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
  128. #define portNOP() asm volatile ( "NOP" )
  129. /*-----------------------------------------------------------*/
  130. /* Task function macros as described on the FreeRTOS.org WEB site. */
  131. #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )
  132. #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )
  133. /*-----------------------------------------------------------*/
  134. /* The following structure is used by the FreeRTOS exception handler. It is
  135. filled with the MicroBlaze context as it was at the time the exception occurred.
  136. This is done as an aid to debugging exception occurrences. */
  137. typedef struct PORT_REGISTER_DUMP
  138. {
  139. /* The following structure members hold the values of the MicroBlaze
  140. registers at the time the exception was raised. */
  141. uint32_t ulR1_SP;
  142. uint32_t ulR2_small_data_area;
  143. uint32_t ulR3;
  144. uint32_t ulR4;
  145. uint32_t ulR5;
  146. uint32_t ulR6;
  147. uint32_t ulR7;
  148. uint32_t ulR8;
  149. uint32_t ulR9;
  150. uint32_t ulR10;
  151. uint32_t ulR11;
  152. uint32_t ulR12;
  153. uint32_t ulR13_read_write_small_data_area;
  154. uint32_t ulR14_return_address_from_interrupt;
  155. uint32_t ulR15_return_address_from_subroutine;
  156. uint32_t ulR16_return_address_from_trap;
  157. uint32_t ulR17_return_address_from_exceptions; /* The exception entry code will copy the BTR into R17 if the exception occurred in the delay slot of a branch instruction. */
  158. uint32_t ulR18;
  159. uint32_t ulR19;
  160. uint32_t ulR20;
  161. uint32_t ulR21;
  162. uint32_t ulR22;
  163. uint32_t ulR23;
  164. uint32_t ulR24;
  165. uint32_t ulR25;
  166. uint32_t ulR26;
  167. uint32_t ulR27;
  168. uint32_t ulR28;
  169. uint32_t ulR29;
  170. uint32_t ulR30;
  171. uint32_t ulR31;
  172. uint32_t ulPC;
  173. uint32_t ulESR;
  174. uint32_t ulMSR;
  175. uint32_t ulEAR;
  176. uint32_t ulFSR;
  177. uint32_t ulEDR;
  178. /* A human readable description of the exception cause. The strings used
  179. are the same as the #define constant names found in the
  180. microblaze_exceptions_i.h header file */
  181. int8_t *pcExceptionCause;
  182. /* The human readable name of the task that was running at the time the
  183. exception occurred. This is the name that was given to the task when the
  184. task was created using the FreeRTOS xTaskCreate() API function. */
  185. char *pcCurrentTaskName;
  186. /* The handle of the task that was running a the time the exception
  187. occurred. */
  188. void * xCurrentTaskHandle;
  189. } xPortRegisterDump;
  190. /*
  191. * Installs pxHandler as the interrupt handler for the peripheral specified by
  192. * the ucInterruptID parameter.
  193. *
  194. * ucInterruptID:
  195. *
  196. * The ID of the peripheral that will have pxHandler assigned as its interrupt
  197. * handler. Peripheral IDs are defined in the xparameters.h header file, which
  198. * is itself part of the BSP project. For example, in the official demo
  199. * application for this port, xparameters.h defines the following IDs for the
  200. * four possible interrupt sources:
  201. *
  202. * XPAR_INTC_0_UARTLITE_1_VEC_ID - for the UARTlite peripheral.
  203. * XPAR_INTC_0_TMRCTR_0_VEC_ID - for the AXI Timer 0 peripheral.
  204. * XPAR_INTC_0_EMACLITE_0_VEC_ID - for the Ethernet lite peripheral.
  205. * XPAR_INTC_0_GPIO_1_VEC_ID - for the button inputs.
  206. *
  207. *
  208. * pxHandler:
  209. *
  210. * A pointer to the interrupt handler function itself. This must be a void
  211. * function that takes a (void *) parameter.
  212. *
  213. *
  214. * pvCallBackRef:
  215. *
  216. * The parameter passed into the handler function. In many cases this will not
  217. * be used and can be NULL. Some times it is used to pass in a reference to
  218. * the peripheral instance variable, so it can be accessed from inside the
  219. * handler function.
  220. *
  221. *
  222. * pdPASS is returned if the function executes successfully. Any other value
  223. * being returned indicates that the function did not execute correctly.
  224. */
  225. BaseType_t xPortInstallInterruptHandler( uint8_t ucInterruptID, XInterruptHandler pxHandler, void *pvCallBackRef );
  226. /*
  227. * Enables the interrupt, within the interrupt controller, for the peripheral
  228. * specified by the ucInterruptID parameter.
  229. *
  230. * ucInterruptID:
  231. *
  232. * The ID of the peripheral that will have its interrupt enabled in the
  233. * interrupt controller. Peripheral IDs are defined in the xparameters.h header
  234. * file, which is itself part of the BSP project. For example, in the official
  235. * demo application for this port, xparameters.h defines the following IDs for
  236. * the four possible interrupt sources:
  237. *
  238. * XPAR_INTC_0_UARTLITE_1_VEC_ID - for the UARTlite peripheral.
  239. * XPAR_INTC_0_TMRCTR_0_VEC_ID - for the AXI Timer 0 peripheral.
  240. * XPAR_INTC_0_EMACLITE_0_VEC_ID - for the Ethernet lite peripheral.
  241. * XPAR_INTC_0_GPIO_1_VEC_ID - for the button inputs.
  242. *
  243. */
  244. void vPortEnableInterrupt( uint8_t ucInterruptID );
  245. /*
  246. * Disables the interrupt, within the interrupt controller, for the peripheral
  247. * specified by the ucInterruptID parameter.
  248. *
  249. * ucInterruptID:
  250. *
  251. * The ID of the peripheral that will have its interrupt disabled in the
  252. * interrupt controller. Peripheral IDs are defined in the xparameters.h header
  253. * file, which is itself part of the BSP project. For example, in the official
  254. * demo application for this port, xparameters.h defines the following IDs for
  255. * the four possible interrupt sources:
  256. *
  257. * XPAR_INTC_0_UARTLITE_1_VEC_ID - for the UARTlite peripheral.
  258. * XPAR_INTC_0_TMRCTR_0_VEC_ID - for the AXI Timer 0 peripheral.
  259. * XPAR_INTC_0_EMACLITE_0_VEC_ID - for the Ethernet lite peripheral.
  260. * XPAR_INTC_0_GPIO_1_VEC_ID - for the button inputs.
  261. *
  262. */
  263. void vPortDisableInterrupt( uint8_t ucInterruptID );
  264. /*
  265. * This is an application defined callback function used to install the tick
  266. * interrupt handler. It is provided as an application callback because the
  267. * kernel will run on lots of different MicroBlaze and FPGA configurations - not
  268. * all of which will have the same timer peripherals defined or available. This
  269. * example uses the AXI Timer 0. If that is available on your hardware platform
  270. * then this example callback implementation should not require modification.
  271. * The name of the interrupt handler that should be installed is vPortTickISR(),
  272. * which the function below declares as an extern.
  273. */
  274. void vApplicationSetupTimerInterrupt( void );
  275. /*
  276. * This is an application defined callback function used to clear whichever
  277. * interrupt was installed by the the vApplicationSetupTimerInterrupt() callback
  278. * function - in this case the interrupt generated by the AXI timer. It is
  279. * provided as an application callback because the kernel will run on lots of
  280. * different MicroBlaze and FPGA configurations - not all of which will have the
  281. * same timer peripherals defined or available. This example uses the AXI Timer 0.
  282. * If that is available on your hardware platform then this example callback
  283. * implementation should not require modification provided the example definition
  284. * of vApplicationSetupTimerInterrupt() is also not modified.
  285. */
  286. void vApplicationClearTimerInterrupt( void );
  287. /*
  288. * vPortExceptionsInstallHandlers() is only available when the MicroBlaze
  289. * is configured to include exception functionality, and
  290. * configINSTALL_EXCEPTION_HANDLERS is set to 1 in FreeRTOSConfig.h.
  291. *
  292. * vPortExceptionsInstallHandlers() installs the FreeRTOS exception handler
  293. * for every possible exception cause.
  294. *
  295. * vPortExceptionsInstallHandlers() can be called explicitly from application
  296. * code. After that is done, the default FreeRTOS exception handler that will
  297. * have been installed can be replaced for any specific exception cause by using
  298. * the standard Xilinx library function microblaze_register_exception_handler().
  299. *
  300. * If vPortExceptionsInstallHandlers() is not called explicitly by the
  301. * application, it will be called automatically by the kernel the first time
  302. * xPortInstallInterruptHandler() is called. At that time, any exception
  303. * handlers that may have already been installed will be replaced.
  304. *
  305. * See the description of vApplicationExceptionRegisterDump() for information
  306. * on the processing performed by the FreeRTOS exception handler.
  307. */
  308. void vPortExceptionsInstallHandlers( void );
  309. /*
  310. * The FreeRTOS exception handler fills an xPortRegisterDump structure (defined
  311. * in portmacro.h) with the MicroBlaze context, as it was at the time the
  312. * exception occurred. The exception handler then calls
  313. * vApplicationExceptionRegisterDump(), passing in the completed
  314. * xPortRegisterDump structure as its parameter.
  315. *
  316. * The FreeRTOS kernel provides its own implementation of
  317. * vApplicationExceptionRegisterDump(), but the kernel provided implementation
  318. * is declared as being 'weak'. The weak definition allows the application
  319. * writer to provide their own implementation, should they wish to use the
  320. * register dump information. For example, an implementation could be provided
  321. * that wrote the register dump data to a display, or a UART port.
  322. */
  323. void vApplicationExceptionRegisterDump( xPortRegisterDump *xRegisterDump );
  324. #ifdef __cplusplus
  325. }
  326. #endif
  327. #endif /* PORTMACRO_H */