FreeRTOS API Software Timers

Started by tha, January 18, 2022, 05:28:34 PM

Previous topic - Next topic

tha

https://www.freertos.org/FreeRTOS-timers-xTimerIsTimerActive.html

xTimerIsTimerActive
[Timer API]

timers.h

BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer );

สอบถาม a software timer เพื่อดูว่ามัน active หรือ dormant.

A timer จะหยุดเฉยถ้า:

     1. มันถูกสร้างแต่ยังไม่ถูกสตาร์ท, หรือ
     2. มันเป็น an expired one-shot timer ที่ยังไม่ถูกสตาร์ทซ้ำ.

Timers ถูกสร้างใน the dormant state. The xTimerStart(), xTimerReset(), xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and xTimerChangePeriodFromISR() API functions ทั้งหมดสามารถถูกใช้เพื่อเปลี่ยนผ่าน a timer ลงใน the active state.

Parameters:

     xTimer          The timer ที่กำลังถูกสอบถาม.

Returns:

     pdFALSE จะถูกส่งคืนกลับถ้า the timer อยู่เฉย. ค่านอกเหนือจาก pdFALSE จะถูกส่งคืนกลับถ้า the timer ทำงานอยู่.


tha

https://www.freertos.org/FreeRTOS-timers-xTimerStart.html

xTimerStart
[Timer API]

timers.h

BaseType_t xTimerStart( TimerHandle_t xTimer,
                            TickType_t xBlockTime );

Software timer functionality ถูกจัดให้มีโดย a timer service/daemon task. จำนวนมากของ the public FreeRTOS timer API functions ส่งคำสั่งไปยัง the timer service task ผ่านทาง a queue ที่เรียกว่า the timer command queue. The timer command queue เป็นแบบส่วนตัวสำหรับ the RTOS kernel เองและไม่สามารถเข้าถึงได้โดยตรงไปยัง application code. ความยาวของ the timer command queue ถูกเซ็ตโดย the configTIMER_QUEUE_LENGTH configuration constant.

xTimerStart() สตาร์ท a timer ที่ถูกสร้างก่อนหน้าแล้วโดยใช้ the xTimerCreate() API function. ถ้า the timer ถูกสตาร์ทไปแล้วและอยู่ใน the active state แล้ว, ดังนั้น xTimerStart() จะมีฟังก์ชันเทียบเท่ากับ the xTimerReset() API function.

การสตาร์ท a timer ช่วยให้ the timer อยู่ใน the active state. ถ้า the timer ไม่ถูกหยุด, ลบ, หรือรีเซ็ตในกลางเวลา, the callback function ที่เกี่ยวข้องกับ the timer จะถูกเรียกที่ 'n 'ticks หลังจาก xTimerStart() ถูกสตาร์ท, โดยที่ 'n' เป็น the timers defined period.

มันจะใช้ได้ที่เรียก xTimerStart() ก่อน the RTOS scheduler ถูกสตาร์ท, แต่เมื่อสิ่งนี้ถูกทำ the timer จะไม่สตาร์ทจริงๆจนกว่า the RTOS scheduler ถูกสตาร์ท, และ the timers expiry time จะสัมพันธ์กับเมื่อ the RTOS scheduler ถูกสตาร์ท, ไม่สัมพันธ์กับเมื่อ xTimerStart() ถูกเรียก.

The configUSE_TIMERS configuration constant ต้องถูกเซ็ตเป็น 1 สำหรับ xTimerStart() มีให้ใช้เป็นประโยชน์.

tha

Parameters:

     xTimer             The handle of the timer ที่กำลังถูกสตาร์ท/สตาร์ทซ้ำ.

     xBlockTime      ระบุเวลา, เป็น ticks, ที่ the calling task ควรถูกเก็บใน the Blocked state เพื่อรอสำหรับ the start command
                                ถูกส่งไปยัง the timer command queue สำเร็จ, หาก the queue เต็มแล้วเมื่อตอน xTimerStart() ถูกเรียก.
                                xBlockTime จะถูกละเลยถ้า xTimerStart() ถูกเรียกก่อน the RTOS scheduler ถูกสตาร์ท.


tha

Returns:

     pdFAIL จะถูกส่งคืนกลับถ้า the start command ไม่สามารถถูกส่งไปยัง the timer command queue พอดีหลังจาก xBlockTime
     ticks ได้ผ่านไปแล้ว. pdPASS จะถูกส่งคืนกลับถ้า the command ถูกส่งไปยัง the timer command queue สำเร็จ. เมื่อ the
     command ถูกประมวลผลจริงๆจะขึ้นอยู่กับ the priority of the timer service/daemon task ที่เกี่ยวข้องกันกับ tasks อื่นๆใน the
     system, แม้ว่า the timers expiry time จะสัมพันธ์กันกับเมื่อ xTimerStart() ถูกสตาร์ทจริงๆ. The timer service/daemon
     task priority ถูกเซ็ตโดย the configTIMER_TASK_PRIORITY configuration constant.

Example usage:

ดูตัวอย่างบน the xTimerCreate() documentation page.

tha

https://www.freertos.org/FreeRTOS-timers-xTimerStop.html

xTimerStop
[Timer API]

timers.h

BaseType_t xTimerStop( TimerHandle_t xTimer,
                           TickType_t xBlockTime );


Software timer functionality ถูกจัดให้มีโดย a timer service/daemon task. จำนวนมากของ the public FreeRTOS timer API functions ส่งคำสั่งไปยัง the timer service task ผ่านทาง a queue ที่เรียกว่า the timer command queue. The timer command queue เป็นแบบส่วนตัวสำหรับ the RTOS kernel เองและไม่สามารถเข้าถึงได้โดยตรงไปยัง application code. ความยาวของ the timer command queue ถูกเซ็ตโดย the configTIMER_QUEUE_LENGTH configuration constant.

xTimerStop() จะหยุด a timer ที่ถูกสตาร์ทก่อนหน้าแล้วโดยใช้อย่างใดอย่างหนึ่งของ the xTimerStart(), xTimerReset(), xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and xTimerChangePeriodFromISR() API functions.

การหยุด a timer ทำให้แน่ใจว่า the timer ไม่อยู่ใน the active state.

The configUSE_TIMERS configuration constant ต้องถูกเซ็ตเป็น 1 สำหรับ xTimerStop() มีให้ใช้เป็นประโยชน์.

tha

Parameters:

     xTimer             The handle of the timer ที่กำลังถูกหยุด

     xBlockTime      ระบุเวลา, เป็น ticks, ที่ the calling task ควรถูกเก็บใน the Blocked state เพื่อรอสำหรับ the stop command
                                ถูกส่งไปยัง the timer command queue สำเร็จ, หาก the queue เต็มแล้วเมื่อตอน xTimerStop() ถูกเรียก.
                                xBlockTime จะถูกละเลยถ้า xTimerStop() ถูกเรียกก่อน the RTOS scheduler ถูกสตาร์ท.

tha

Returns:

     pdFAIL จะถูกส่งคืนกลับถ้า the stop command ไม่สามารถถูกส่งไปยัง the timer command queue พอดีหลังจาก xBlockTime
     ticks ได้ผ่านไปแล้ว. pdPASS จะถูกส่งคืนกลับถ้า the command ถูกส่งไปยัง the timer command queue สำเร็จ. เมื่อ the
     command ถูกประมวลผลจริงๆจะขึ้นอยู่กับ the priority of the timer service/daemon task ที่เกี่ยวข้องกันกับ tasks อื่นๆใน the
     system. The timer service/daemon task priority ถูกเซ็ตโดย the configTIMER_TASK_PRIORITY configuration
     constant.

Example usage:

ดูตัวอย่างบน the xTimerCreate() documentation page.

tha

https://www.freertos.org/FreeRTOS-timers-xTimerChangePeriod.html

xTimerChangePeriod
[Timer API]

timers.h

BaseType_t xTimerChangePeriod( TimerHandle_t xTimer,
                                   TickType_t xNewPeriod,
                                   TickType_t xBlockTime );


Software timer functionality ถูกจัดให้มีโดย a timer service/daemon task. จำนวนมากของ the public FreeRTOS timer API functions ส่งคำสั่งไปยัง the timer service task ผ่านทาง a queue ที่เรียกว่า the timer command queue. The timer command queue เป็นแบบส่วนตัวสำหรับ the RTOS kernel เองและไม่สามารถเข้าถึงได้โดยตรงไปยัง application code. ความยาวของ the timer command queue ถูกเซ็ตโดย the configTIMER_QUEUE_LENGTH configuration constant.

xTimerChangePeriod() เปลี่ยน the period of a timer ที่ถูกสร้างก่อนหน้าแล้วโดยใช้ the xTimerCreate() API function.

xTimerChangePeriod() สามารถถูกเรียกเพื่อเปลี่ยน the period ของ an active or dormant state timer. การเปลี่ยน the period of a dormant timers จะสตาร์ท the timer ด้วย.

The configUSE_TIMERS configuration constant ต้องถูกเซ็ตเป็น 1 สำหรับ xTimerChangePeriod() มีให้ใช้เป็นประโยชน์.