trcRunnable.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Percepio Trace Recorder for Tracealyzer v4.9.2
  3. * Copyright 2023 Percepio AB
  4. * www.percepio.com
  5. *
  6. * SPDX-License-Identifier: Apache-2.0
  7. *
  8. * The implementation for strings.
  9. */
  10. #include <trcRecorder.h>
  11. #if (TRC_USE_TRACEALYZER_RECORDER == 1) && (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
  12. #define TRC_RUNNABLE_STATE_INDEX_OWNER_TASK 0UL
  13. /*cstat !MISRAC2004-6.3 !MISRAC2012-Dir-4.6_a Suppress basic char type usage*/
  14. traceResult xTraceRunnableRegister(const char* szName, TraceRunnableRegisterMethod_t uxRegisterMethod, TraceRunnableHandle_t *pxRunnableHandle)
  15. {
  16. TraceEntryHandle_t xEntryHandle;
  17. int32_t i;
  18. uint32_t uiLength = 0u;
  19. /* This should never fail */
  20. TRC_ASSERT(szName != (void*)0);
  21. /* This should never fail */
  22. TRC_ASSERT(pxRunnableHandle != (void*)0);
  23. for (i = 0; (szName[i] != (char)0) && (i < (int32_t)(TRC_ENTRY_TABLE_SLOT_SYMBOL_SIZE)); i++) {} /*cstat !MISRAC2004-6.3 !MISRAC2012-Dir-4.6_a Suppress basic char type usage*/ /*cstat !MISRAC2004-17.4_b We need to access every character in the string*/
  24. uiLength = (uint32_t)i;
  25. if (uxRegisterMethod == TRC_RUNNABLE_REGISTER_METHOD_USE_ENTRY_TABLE)
  26. {
  27. /* Check if we have already created an entry previously */
  28. if (*pxRunnableHandle == (void*)0)
  29. {
  30. /* We need to check this */
  31. if (xTraceEntryCreate(&xEntryHandle) == TRC_FAIL)
  32. {
  33. return TRC_FAIL;
  34. }
  35. TRC_ASSERT_ALWAYS_EVALUATE(xTraceEntrySetOptions(xEntryHandle, TRC_ENTRY_OPTION_RUNNABLE) == TRC_SUCCESS);
  36. TRC_ASSERT_ALWAYS_EVALUATE(xTraceEntrySetState(xEntryHandle, TRC_RUNNABLE_STATE_INDEX_OWNER_TASK, (TraceUnsignedBaseType_t)xTraceTaskGetCurrentReturn()) == TRC_SUCCESS); /*cstat !MISRAC2004-11.3 !MISRAC2012-Rule-11.4 !MISRAC2012-Rule-11.6 We need the address of the task*/
  37. /* The address to the available symbol table slot is the address we use */
  38. /* This should never fail */
  39. TRC_ASSERT_ALWAYS_EVALUATE(xTraceEntrySetSymbol(xEntryHandle, szName, uiLength) == TRC_SUCCESS);
  40. *pxRunnableHandle = (TraceRunnableHandle_t)xEntryHandle;
  41. }
  42. }
  43. else if (uxRegisterMethod == TRC_RUNNABLE_REGISTER_METHOD_USE_STRING_ADDRESS)
  44. {
  45. *pxRunnableHandle = (TraceRunnableHandle_t)szName; /*cstat !MISRAC2004-11.5 !MISRAC2012-Rule-11.8 We need the address of the string*/
  46. }
  47. else if (uxRegisterMethod == TRC_RUNNABLE_REGISTER_METHOD_USE_HANDLE_ADDRESS)
  48. {
  49. /* The handle address should be a unique value that we can use as handle */
  50. *pxRunnableHandle = (TraceRunnableHandle_t)pxRunnableHandle;
  51. }
  52. else
  53. {
  54. return TRC_FAIL;
  55. }
  56. return xTraceEventCreateData1(PSF_EVENT_RUNNABLE_REGISTER, (TraceUnsignedBaseType_t)*pxRunnableHandle, (TraceUnsignedBaseType_t*)szName, uiLength + 1);
  57. }
  58. #endif