FreeRTOS API Software Timers

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

Previous topic - Next topic

tha

Parameters:

     xTimer                The handle of the timer ที่กำลังมี period ของมันถูกเปลี่ยน.

     xNewPeriod       The new period สำหรับ xTimer. Timer periods ถูกระบุเป็น tick periods, ดังนั้น the constant
                                  portTICK_PERIOD_MS สามารถถูกใช้เพื่อแปลง a time ที่ถูกระบุเป็น milliseconds. ตัวอย่างเช่น, ถ้า the
                                  timer ต้องหมดเวลาลงหลังจาก 100 ticks, ดังนั้น xNewPeriod ควรถูกเซ็ตเป็น 100. อีกทางเลือกหนึ่ง, ถ้า
                                  the timer ต้องหมดเวลาลงหลังจาก 500ms, ดังนั้น xNewPeriod สามารถถูกเซ็ตเป็น                           
                                  ( 500 / portTICK_PERIOD_MS ) ที่จัดให้มี configTICK_RATE_HZ น้อยกว่าหรือเท่ากับ 1000.

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

tha

Returns:

     pdFAIL จะถูกส่งคืนกลับถ้า the change period 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:
(ตัวอย่างโค้ดดูในลิ้งค์เอานะครับ)
https://www.freertos.org/FreeRTOS-timers-xTimerChangePeriod.html

tha

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

xTimerDelete
[Timer API]

timers.h

BaseType_t xTimerDelete( 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.

xTimerDelete() ลบ a timer ที่ถูกสร้างก่อนหน้าโดยใช้ the xTimerCreate() API function. หมายเหตุ, เมื่อลบ a statically allocated timer, static memory ของมันไม่สามารถถูกใช้ซ้ำได้จนกว่า timer นั้นจะถูกแสดงให้เห็นว่าไม่ทำงานโดย xTimerIsTimerActive().

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

Parameters:

     xTimer             The handle of the timer ที่กำลังถูกลบ.

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

Returns:

     pdFAIL จะถูกส่งคืนกลับถ้า the delete 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 xTimerChangePeriod() documentation page.


tha

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

xTimerReset
[Timer API]

timers.h

BaseType_t xTimerReset( 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.

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

tha

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

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

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

tha

Parameters:

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

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

tha

Returns:

     pdFAIL จะถูกส่งคืนกลับถ้า the reset 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 จะสัมพันธ์กันกับเมื่อ xTimerReset() ถูกเรียกจริงๆ. The timer
     service/daemon task priority ถูกเซ็ตโดย the configTIMER_TASK_PRIORITY configuration constant.

Example usage:
(ตัวอย่างโค้ดดูในลิงค์เอานะครับ)

tha

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

xTimerStartFromISR
[Timer API]

timers.h

BaseType_t xTimerStartFromISR
               (
                  TimerHandle_t xTimer,
                  BaseType_t *pxHigherPriorityTaskWoken
               );


A version of xTimerStart() ที่สามารถถูกเรียกจาก an interrupt service routine.

Parameters:

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

pxHigherPriorityTaskWoken     The timer service/daemon task ใช้เวลาส่วนใหญ่ของมันใน the Blocked state, รอสำหรับ
                                                       messages มาถึงบน the timer command queue. การเรียก xTimerStartFromISR()
                                                       เขียน a message ไปยัง the timer command queue, ดังนั้นจึงมีศักยภาพเปลี่ยนผ่าน
                                                       the timer service/daemon task ออกจาก the Blocked state. ถ้าการเรียก
                                                       xTimerStartFromISR() เป็นเหตุให้ the timer service/daemon task ออกจาก the
                                                       Blocked state, และ the timer service/ daemon task มี a priority เท่ากับหรือใหญ่
                                                       กว่า the currently executing task (the task ที่ถูกอินเตอร์รัพท์), ดังนั้น
                                                       *pxHigherPriorityTaskWoken จะได้รับการเซ็ตภายในเป็น pdTRUE ภายใน the
                                                       xTimerStartFromISR() function. ถ้า xTimerStartFromISR() เซ็ตค่านี้เป็น
                                                       pdTRUE, ดังนั้น a context switch ควรถูกดำเนินการก่อน the interrupt จะออก.

Returns:

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

Example usage:
(ตัวอย่างโค้ดดูในลิ้งค์เอานะครับ)