• Skip to primary navigation
  • Skip to main content
FDI: Future Designs, Inc.

FDI

Future Designs, Inc.

  • Products
    • μEZ GUI
    • ELI
    • ΣyG
    • Modular Development Kits – DK
    • Other Products
    • End of Life
    • All Products (By part number)
  • Engineering Design
  • Production
  • Support
    • Forums
  • About FDI
    • News
    • Management
    • Partners
    • Distributors
    • Practices
    • Careers
    • New Customer Referral
  • Contact Us
  • Show Search
Hide Search

Potential error in function UEZTaskGetCurrent

Homepage › Forums › μEZ › Software › Potential error in function UEZTaskGetCurrent

  • This topic has 0 replies, 1 voice, and was last updated 4 months, 2 weeks ago by Logan Moon.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • February 6, 2025 at 9:29 pm #16768
    Logan Moon
    Keymaster

      (This message was transferred over from our old forum)
      Posted August 19, 2015
      By Todd DeBoer
      [hr]
      On 03/04/2010 wella asked, “I think, there is an error in the function UEZTaskGetCurrent.

      T_uezTask UEZTaskGetCurrent(void)
      {
      T_uezTask h;
      TUInt32 index = 0;
      T_uezError found;
      xTaskHandle currentTask;
      xTaskHandle task;

      // TBD: This is slow!

      // Get the FreeRTOS handle
      currentTask = xTaskGetCurrentTaskHandle();
      do {
      found = uEZHandleFindOfType(UEZ_HANDLE_TASK, &h, &index);

      // Didn’t find task? Return 0
      if (found != UEZ_ERROR_NONE)
      return 0;

      uEZHandleGet(h, 0, 0, 0, (TUInt32 *)&task);
      if (task == currentTask)
      return h;
      error:——————– } while (found);————

      return 0;
      }

      If some UEZ_HANDLE_TASK is found, the found is UEZ_ERROR_NONE, 0 numerically. So that if the task is not first created(registered) it always return 0. I am suggesting the patch below, just only do it in the infinite loop.

      Martin

      ————solution—————————–
      T_uezTask UEZTaskGetCurrent(void)
      {
      T_uezTask h;
      TUInt32 index = 0;
      T_uezError found;
      xTaskHandle currentTask;
      xTaskHandle task;

      // TBD: This is slow!

      // Get the FreeRTOS handle
      currentTask = xTaskGetCurrentTaskHandle();
      do {
      found = uEZHandleFindOfType(UEZ_HANDLE_TASK, &h, &index);

      // Didn’t find task? Return 0
      if (found != UEZ_ERROR_NONE)
      return 0;

      uEZHandleGet(h, 0, 0, 0, (TUInt32 *)&task);
      if (task == currentTask)
      return h;
      } while (ETrue);

      return 0;
      }”
      [hr]
      (Follow up post)

      Answered:

      I found this one myself and fixed it this way (I should have posted this sooner):

      T_uezTask UEZTaskGetCurrent(void)
      {
      T_uezTask h;
      TUInt32 index = 0;
      T_uezError found;
      xTaskHandle currentTask;
      xTaskHandle task;

      // TBD: This is slow!

      // Get the FreeRTOS handle
      currentTask = xTaskGetCurrentTaskHandle();
      do {
      found = uEZHandleFindOfType(UEZ_HANDLE_TASK, &h, &index);

      // Didn’t find task? Return 0
      if (found != UEZ_ERROR_NONE)
      return 0;

      uEZHandleGet(h, 0, 0, 0, (TUInt32 *)&task);
      if (task == currentTask) {
      UEZAssert(uEZHandleGetType(h) == UEZ_HANDLE_TASK);
      return h;
      }
      } while (!found);

      return 0;
      }

      — Effectively the same as ETrue in the while.

      I’m going to change that to ETrue to save a few bytes.

    • Author
      Posts
    Viewing 1 post (of 1 total)
    • You must be logged in to reply to this topic.
    Log In

    Partners

    NXP
    Renesas

    ARM
    SEGGER

    STMicroelectronics
    SAFERTOS

    FreeRTOS

    Copyright © 2025 Future Designs, Inc. | μEZ GUI | ELI | Engineering Design | Production | Privacy Policy | Log in