Callback from residential portion to ThreadX module

HugPeter-9392 246 Reputation points
2023-02-28T13:55:13.9366667+00:00

Hello

Background

We get a communication stack/library. This communication stack should be part of the residential portion of the solution. This library happens to expose a series of callbacks that we need to serve in time.

Different products are planned. Each of them implemented within a different ThreadX module. Each module/product provides different data exposed on the communication bus.

Question

Which are the options to delegate a communication stack callback from residential portion to a module. Such callbacks should complete fast as the stack expects a synchronous completion. The stack has the requirement to run periodically each approx 5ms. Within this 5ms a series (assume 10) of callbacks might need to be processed.

The simplest approach I can imagine is that the module initializes the communication stack by use of a module application request. This initialization request could include function pointers that implement the product specific callbacks. This would result into the situation that the residential portion would execute code from the module without context switch. Is this possible/advisable? Are there limitations? Are there other options?

Currently, we plan to use Cortex-M4 and Cortex-M33 cores. No MPU. Module and residential portion are not planned to run within Trustzone secure area.

Thanks for support.

Peter

Azure RTOS
Azure RTOS
An Azure embedded development suite including a small but powerful operating system for resource-constrained devices.
331 questions
0 comments No comments
{count} votes

Accepted answer
  1. Scott Azure RTOS 4,051 Reputation points
    2023-03-01T03:27:39.4333333+00:00

    Hi Peter,

    Because you are not using MPU, I assume you are not concerned about security/module isolation.

    I'm not sure if your approach will work because typically the resident application is built using absolute positioning and modules are built with position independence. The registers may not be set up correctly (for relative offsets using R9) when the resident application is executing module functions.

    Are you able to architect a solution where the module can use any of the existing ThreadX APIs that provide callback functionality? The module could, for example, create an event flags group and a notification function using tx_event_flags_set_notify. The module could then share the handle of the event flags group with the resident application, which would set a flag. The callback would be executed in the context of the module (every module has two hidden threads - the start/stop thread and the callback thread).

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. QuantumCache 20,266 Reputation points
    2023-03-01T23:24:50.09+00:00

    Hello @Hug Peter,

    Thought of sharing below document if that may be helpful!

    Did you try inter-thread communication and synchronization, such as message queues, event flags, and semaphores.

    Use message queues for inter-thread communication in Azure RTOS ThreadX

    User's image

    Using Message Queues: You can create a message queue in the residential portion of the application and pass a message to the module whenever a callback is triggered. The module can then process the message and execute the corresponding function pointer.

    Use an event flags group to sync threads in ThreadX

    Using Event Flags: You can create an event flag in the residential portion of the application and set a flag whenever a callback is triggered. The module can then check the flag and execute the corresponding function pointer.

    User's image

    I am not an experienced person on this particular topic,but wanted to help with some available documents, meanwhile the Community SME's on this topic or our team will review your scenario and circle back at the possible earliest time. 

    If you have any further questions or comments, please submit in the below comment section.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.