How does Quanzhi XR806 chip use timer command line command?

1. Problem background
How to use timer on XR809/XR871/XR808/XR872

2. Problem description
Timer module is only a small module in the chip. There is no special document to explain in the release document, only the code use case. Some customers will be confused about some parameters in timer after reading the code

3. Solutions
The following will help customers understand and test the timer module from several aspects.

3.1 how to add the command line command for testing timer in firmware:

(1). project/XXX/command. Add the timer command to the C file as follows:

--- a/platforms/xr806/xr806-os/project/tuya/command.c
+++ b/platforms/xr806/xr806-os/project/tuya/command.c
@@ -181,6 +181,7 @@ static const struct cmd_data g_main_cmds[] = {
+       { "timer",  cmd_timer_exec },
        { "sysinfo",cmd_sysinfo_exec, CMD_DESC("system information command") },
        { "help",   cmd_main_help_exec, CMD_DESC(CMD_HELP_DESC) },

(2). After adding, compile and burn the firmware. Enter the help command on the command line to see that the timer command is compiled into the firmware:

[*] net      : network command
[*] rf       : radio frequency command
[*] drv      : driver command
[*] echo     : echo command
[*] mem      : memory command
[*] heap     : heap use information command
[*] thread   : thread information command
[*] upgrade  : upgrade command
[*] reboot   : reboot command
[*] ota      : over the airtechnology upgrade commands
[*] etf      : etf command
[*] pm       : power management command
[*] efpg     : efpg command
[*] flash    : flash control command
[*] lmac     : low mac command
[*] timer
[*] sysinfo  : system information command
[*] ble
[*] help     : print this message and quit

(3) The source code of timer command is in project/common/cmd/cmd_timer.c. Users can modify and test the source code, or refer to the timer interface of the file for application development.

3.2 how to use the timer command

(1) The timer command line supports the following subcommands:

timer config i=X m=X s=X d=X p=X   -->  to configure timer Parameters of,Parameters are described later
timer deconfig i=X                 -->  Cancel current timer Configuration parameters for
timer start i=X                    -->  Start the corresponding timer(Support 2 timer 0/1)
timer stop i=X                     -->  Stop corresponding timer
timer pause i=X                    -->  Pause corresponding timer
timer continue i=X                 -->  Continue with the corresponding timer
Timer value i=X                    -->  Get corresponding timer Value of(This value is the remaining timing time, which needs to be calculated)

(2) Parameter description of timer command line:

parameter i: 0/1  -->  Which is controlled timer,806 Support 2 timer,0/1
 parameter m: repeat/once  -->  Timing mode, repeat: Cycle timing mode, once: Primary timing mode
 parameter s: LF/HF  -->  Clock source, LF: Low frequency 32 k Crystal oscillator, HF: High frequency crystal oscillator, which is an externally connected crystal oscillator,For example, if the connection is 40 M,HF It's 40 M,It's 26 M,HF It's 26 M
 parameter d: 1/2/4/8/16/32/64/128  -->  division factor 
parameter p:                     -->  timing period Value, which needs to be calculated by the user according to the clock source, frequency division coefficient and timing time:
                                The calculation formula to be used is as follows:
                                interval = period / ( clk-src / clk-div )
                                period = interval * ( clk-src / clk-div )

(3) Description of formula parameters:

parameter interval: Value requiring timing(Example 5 s,0.5s)
parameter clk-src: Clock source(For example 40 M,26M)
parameter clk-div: division factor (The choice of frequency division coefficient affects the accuracy and timing time range)
parameter period: The value calculated according to the timing value, clock source and frequency division coefficient, which will be written to timer Register, timer modular
            Timing is based on this value.
Example: for example, timing 5 is required s,The external clock source of the board is 26 M,If the frequency division coefficient is 4, it can be calculated according to the formula period The value of should be filled in 32,500,000

4. Practical operation description of timer command

timer config i=1 m=once s=HF d=4 p=32500000    -- 1
<ACK> 200 OK
timer start i=2                                -- 2
<ACK> 200 OK
timer value i=1                                -- 3
<ACK> 200 value=19462685
timer value i=1                                -- 4
<ACK> 200 value=4617179
timer value i=1                                -- 5
<ACK> 200 value=0
(1).to configure timer 1,Mode setting once Mode, clock source selection HF(26M),Select 4 for frequency division because you want to time 5 s,So calculate p The value needs to be filled in 32500000
(2).Start timer 1
(3).First acquisition period Value 19462685, according to formula interval = period / ( clk-src / clk-div )
    You can calculate the remaining time interval = 19462685 / (26000000 / 4) = 2.994s
(4).The second remaining time can be calculated as above interval = 4617179 / (26000000/4) = 0.71s
(5).When getting the value for the third time, it has exceeded 5 s,So the obtained value is 0

If you want to set other frequency division and time, you can calculate the period value according to the formula and the frequency division time to be set, and fill it in the corresponding function interface.

Other commands are relatively simple, so the actual operation display is no longer carried out

be careful:
If the timer test timing time is inconsistent with the actual situation, you can check from the following directions:
(1). Calculate the crystal oscillator and the actual crystal oscillator (for example, 26M is used for calculation, but 40m is used for actual board connection)
(2). Repeat the calculation of the period value. The incorrect filling of the period value will also lead to inaccurate timing time

Attachment timer_pparam.xlsx: timer_param.xlsx
The attachment is the reference table of time, frequency division and period value of 26M parameters. Crystal oscillators of other frequencies can also refer to this table to calculate the period value.

Original link:
Quanzhi online developer exchange Penguin Group (24-hour online answer of customer service robot): 498263967
Resource acquisition and problem discussion can be conducted in Quanzhi online developer community:
Official account and developer's latest developments can be concerned about WeChat online.

Keywords: Embedded system

Added by on Fri, 04 Mar 2022 03:59:51 +0200