perf_os_patch_rtx5.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /****************************************************************************
  2. * Copyright 2022 Gorgon Meducer (Email:embedded_zhuoran@hotmail.com) *
  3. * *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); *
  5. * you may not use this file except in compliance with the License. *
  6. * You may obtain a copy of the License at *
  7. * *
  8. * http://www.apache.org/licenses/LICENSE-2.0 *
  9. * *
  10. * Unless required by applicable law or agreed to in writing, software *
  11. * distributed under the License is distributed on an "AS IS" BASIS, *
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
  13. * See the License for the specific language governing permissions and *
  14. * limitations under the License. *
  15. * *
  16. ****************************************************************************/
  17. /*============================ INCLUDES ======================================*/
  18. #include "rtx_os.h"
  19. #include "perf_counter.h"
  20. #include "cmsis_compiler.h"
  21. #include "rtx_evr.h" // RTX Event Recorder definitions
  22. /*============================ MACROS ========================================*/
  23. #undef __WRAP_FUNC
  24. #undef WRAP_FUNC
  25. #if defined(__IS_COMPILER_ARM_COMPILER__) && __IS_COMPILER_ARM_COMPILER__
  26. # define __WRAP_FUNC(__NAME) $Sub$$##__NAME
  27. # define __ORIG_FUNC(__NAME) $Super$$##__NAME
  28. #elif (defined(__IS_COMPILER_LLVM__) && __IS_COMPILER_LLVM__) \
  29. || (defined(__IS_COMPILER_GCC__) && __IS_COMPILER_GCC__)
  30. # define __WRAP_FUNC(__NAME) __wrap_##__NAME
  31. # define __ORIG_FUNC(__NAME) __real_##__NAME
  32. #endif
  33. #define WRAP_FUNC(__NAME) __WRAP_FUNC(__NAME)
  34. #define ORIG_FUNC(__NAME) __ORIG_FUNC(__NAME)
  35. struct __task_cycle_info_t {
  36. task_cycle_info_t tInfo;
  37. int64_t lLastTimeStamp;
  38. task_cycle_info_agent_t tList;
  39. uint32_t wMagicWord;
  40. } ;
  41. /*============================ TYPES =========================================*/
  42. /*============================ GLOBAL VARIABLES ==============================*/
  43. /*============================ LOCAL VARIABLES ===============================*/
  44. /*============================ PROTOTYPES ====================================*/
  45. extern void __on_context_switch_in(uint32_t *pwStack);
  46. extern void __on_context_switch_out(uint32_t *pwStack);
  47. /*============================ IMPLEMENTATION ================================*/
  48. /*! \brief wrapper function for rtos context switching */
  49. void __on_context_switch (osRtxThread_t *thread)
  50. {
  51. if (NULL != osRtxInfo.thread.run.curr) {
  52. __on_context_switch_out(osRtxInfo.thread.run.curr->stack_mem);
  53. }
  54. __on_context_switch_in(thread->stack_mem);
  55. }
  56. __attribute__((used))
  57. void EvrRtxThreadSwitched (osThreadId_t thread_id)
  58. {
  59. __on_context_switch((osRtxThread_t *)thread_id);
  60. #if defined(RTE_Compiler_EventRecorder)
  61. # define EvtRtxThreadSwitched \
  62. EventID(EventLevelOp, EvtRtxThreadNo, 0x19U)
  63. (void)EventRecord2(EvtRtxThreadSwitched, (uint32_t)thread_id, 0U);
  64. #else
  65. (void)thread_id;
  66. #endif
  67. }
  68. task_cycle_info_t * get_rtos_task_cycle_info(void)
  69. {
  70. osRtxThread_t *curr = osRtxInfo.thread.run.curr;
  71. if (NULL == curr) {
  72. return NULL;
  73. }
  74. return &(((struct __task_cycle_info_t *)curr->stack_mem)->tInfo);
  75. }