Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Attach rx callback for HardwareSerial #2708

Open
Labels
enhancementNew feature or request
@marshfolx

Description

@marshfolx

I'm using freertos, and I have a task listening serial messages. When the rx buffer is empty, I want the task to be blocked, or "sleep", and a rx callback will return the task to running state after several bytes have arrived. Otherwise the listening task will constantly occupies CPU time, leaves no process opportunity for other tasks, unless the priority of the task is low enough.

The callback function would be like:

voidrx_callback(HardwareSerial*serial_instance) {if(serial_instance->available()>5) {if(the_task_is_blocked_waiting_message ) {wake_up_the_task();        }    }}

It would be more convenient to define the rx_callback function as:

voidrx_callback(HardwareSerial*serial_instance,void*ptr_to_callback_object) {if(serial_instance->available()>5) {if(the_task_is_blocked_waiting_message ) {            auto*ptr=reinterpret_cast<CallbackObjectType*>(ptr_to_callback_obejct)ptr->wake_up_the_task();        }    }}

The value ofptr_to_callback_object is stored in a member of HardwareSerial. This way, the callback function can directly get the handle to the task. And the code of callback function can be reused in different projects without modification.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp