Timer Driver

Hardware timers typically operates in two modes: timer mode and counter mode. Regardless of the mode, they rely on an internal counter module that counts pulse signals. Below are key concepts related to timers. The application accesses the hardware timer device via the I/O device management interface provided by RT-Thread. The relevant functions are listed as follows:

Table 1. Timer-related Functions
Function Description
rt_device_find() Looks up the timer device.
rt_device_open() Opens the timer device in read-write mode.
rt_device_set_rx_indicate() Sets the timeout callback function.
rt_device_control() Controls the timer behavior, including setting timing modes (single time/cycle), adjusting counting frequency, and stopping the timer.
rt_device_write() Sets the timer's timeout value and starts the timer automatically.
rt_device_read() Retrieves the current count value of the timer.
rt_device_close() Closes the timer device.

The RTOS includes a timer driver and a test program that is located at rtthread/bsp/starfive/jh7110/applications/timer_test.c.

Figure 1. Timer Test Case

Test result: Set the timer's timeout value to 1s and 10 μs, and then start the timer. It will enter the timer callback function every 1 second and 10 microsecond respectively.