Method, device, medium for calibrating bluetooth traffic scheduling time
Patent Information
- Application Number
- CN202610973286.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-01
- Publication Date
- 2026-10-16
AI Technical Summary
也即每次切换会引入1个时钟周期(31.25us)内的时间误差,误差会直接作用至定时器,误差累计会导致后续蓝牙业务定时不准进而产生蓝牙业务在调度过程中出现收发包异常问题
[0007]In summary, the method for calibrating Bluetooth service scheduling time according to the above embodiments of this application is applied to a Bluetooth system. The Bluetooth system has an active mode and a sleep mode. The Bluetooth system includes a high-precision clock source, a low-precision clock source, a low-precision timer, and a high-precision timer. The low-precision clock source and the high-precision clock source are both divided to output a 32kHz clock to drive the low-precision timer. The low-precision timer includes a first comparison unit and a second comparison unit, and the high-precision timer includes a third comparison unit. The method includes: receiving a switching signal from the Bluetooth system switching from active mode to sleep mode; taking the detection of the first falling edge of the high-precision clock source as the target time; stopping the low-precision timer at the target time; and starting the timer from the target time until the detection of the first falling edge of the low-precision clock source to obtain a compensation value; and responding to... In response to the scheduling command corresponding to the Bluetooth service, the target scheduling time is determined based on the compensation value, and the wake-up value of the first comparison unit is determined according to the target scheduling time, the compensation amount, and the preset scheduling advance. In response to the wake-up value, the low-precision clock source is controlled to enter a sleep state and switched to a high-precision clock source to drive the low-precision timer. The low-precision scheduling value corresponding to the second comparison unit is determined according to the target scheduling time and the compensation value, and the high-precision scheduling value corresponding to the third comparison unit is determined according to the target scheduling time, the preset clock period, and the remainder value corresponding to the compensation value. The count value of the low-precision timer is accumulated to the second comparison unit to obtain a low-precision count value. When the low-precision count value is greater than the low-precision scheduling value, the high-precision timer is triggered to start accumulating the count value to the third comparison unit until it is equal to the high-precision scheduling value, triggering the scheduling of the Bluetooth service.This application embodiment first uses the detection of the first falling edge of the high-precision clock source as the target time. At the target time, the Bluetooth timer stops counting and starts counting again from the target time until the detection of the first falling edge of the low-precision clock source, obtaining a compensation value. This allows for accurate timing of the time error during the switching between the high-precision and low-precision clock sources, resulting in a compensation value. In response to the scheduling command corresponding to the Bluetooth service, the target scheduling time is determined based on the compensation value. The wake-up value of the first comparison unit is determined according to the target scheduling time, the compensation amount, and a preset scheduling advance. In response to the wake-up value, the low-precision clock source is controlled to enter a sleep state, and the high-precision clock source drives the low-precision timer. This allows for compensation of the switching between the high-precision and low-precision clock sources using the compensation value, thereby improving the reliability of the time reference. Based on an accurate time reference, according to the target... The scheduling time and compensation value determine the low-precision scheduling value corresponding to the second comparison unit. The target scheduling time can be compensated based on the compensation value, making the reliability of the obtained low-precision scheduling value higher. The high-precision scheduling value corresponding to the third comparison unit is determined based on the target scheduling time, the preset clock period, and the remainder value corresponding to the compensation value. The reliability of the high-precision scheduling value is further improved by compensating the target scheduling time with the remainder value corresponding to the compensation value. The count value of the low-precision timer is accumulated to the second comparison unit to obtain a low-precision count value. When the low-precision count value is greater than the low-precision scheduling value, the high-precision timer is triggered to start accumulating the count value to the third comparison unit until it is equal to the high-precision scheduling value, triggering the scheduling of Bluetooth services. Thus, Bluetooth service scheduling is triggered based on the low-precision scheduling value and the high-precision scheduling value, thereby reducing the probability of packet transmission and reception abnormalities in Bluetooth services during the scheduling process.
Smart Images

Figure CN122934231A_ABST
Abstract
Description
Technical Field
[0001] This application relates to, but is not limited to, the technical field, and in particular to a method, device, and medium for calibrating Bluetooth service scheduling time. Background Technology
[0002] The Bluetooth protocol is divided into two modes: Classic Bluetooth and Low Energy (BLE). The Bluetooth SIG defines the BLE clock accuracy requirement as 50 ppm during normal operation and wake-up, and 500 ppm during sleep. In Bluetooth systems, to meet the requirements of high accuracy and low power consumption, two clock sources work together: an external high-precision crystal oscillator and a low-precision RC oscillator. Specifically, the high-precision clock source operates during Bluetooth chip wake-up, and the low-precision clock source operates during Bluetooth chip sleep. Both clock sources are divided to output a 32 kHz frequency to drive a timer (the timer is mainly used for timing Bluetooth services that will process packets). However, when the Bluetooth chip switches between wake-up and sleep modes, the high-precision clock source is not immediately put into sleep mode. Instead, a synchronization operation is performed: the next edge of the high-precision clock source (time T0) is detected and recorded as a precise time reference point. Starting from time T0, the timer waits for the first edge of the low-precision clock source. Between time T0 and the next edge of the low-precision clock, there exists a random time error (i.e., phase difference). The maximum value of this time error is one complete clock cycle of the low-precision clock source. In other words, each switch introduces a time error of one clock cycle (31.25µs). This error directly affects the timer, and the accumulation of errors can lead to inaccurate timing of subsequent Bluetooth services, resulting in packet transmission and reception anomalies during Bluetooth service scheduling. Summary of the Invention
[0003] This application provides a method, device, and medium for calibrating Bluetooth service scheduling time, which can reduce the probability of packet transmission and reception abnormalities during Bluetooth service scheduling.
[0004] In a first aspect, embodiments of this application provide a method for calibrating Bluetooth service scheduling time, applied to a Bluetooth system. The Bluetooth system includes an active mode and a sleep mode. The Bluetooth system comprises a high-precision clock source, a low-precision clock source, a low-precision timer, and a high-precision timer. The low-precision clock source and the high-precision clock source are both divided to output a 32kHz clock to drive the low-precision timer. The low-precision timer includes a first comparison unit and a second comparison unit. The high-precision timer includes a third comparison unit, comprising: Upon receiving the switching signal from active mode to sleep mode from the Bluetooth system, the first falling edge of the high-precision clock source is detected as the target time; At the target time, the low-precision timer is stopped, and the timer starts counting from the target time until the first falling edge of the low-precision clock source is detected, to obtain the compensation value; In response to the scheduling instruction corresponding to the Bluetooth service, a target scheduling time is determined based on the compensation value, and a wake-up value for the first comparison unit is determined based on the target scheduling time, the compensation amount, and a preset scheduling advance amount. In response to the wake-up value, the low-precision clock source is controlled to enter a sleep state, and the high-precision clock source is switched to drive the low-precision timer; The low-precision scheduling value corresponding to the second comparison unit is determined based on the target scheduling time and the compensation value, and the high-precision scheduling value corresponding to the third comparison unit is determined based on the target scheduling time, the preset clock period and the remainder value corresponding to the compensation value. The count value of the low-precision timer is accumulated into the second comparison unit to obtain a low-precision count value. When the low-precision count value is greater than the low-precision scheduling value, the high-precision timer is triggered to start accumulating the count value into the third comparison unit until it is equal to the high-precision scheduling value, triggering the scheduling of the Bluetooth service.
[0005] Secondly, an electronic device provided according to an embodiment of this application includes: At least one processor; At least one memory for storing at least one program; When at least one of the programs is executed by at least one of the processors, the method for calibrating Bluetooth service scheduling time as described in any of the first aspects is implemented.
[0006] Thirdly, according to the embodiments of the application, a computer-readable storage medium is provided, storing computer-executable instructions, which are used to execute the method for calibrating Bluetooth service scheduling time as described in any of the first aspects.
[0007] In summary, the method for calibrating Bluetooth service scheduling time according to the above embodiments of this application is applied to a Bluetooth system. The Bluetooth system has an active mode and a sleep mode. The Bluetooth system includes a high-precision clock source, a low-precision clock source, a low-precision timer, and a high-precision timer. The low-precision clock source and the high-precision clock source are both divided to output a 32kHz clock to drive the low-precision timer. The low-precision timer includes a first comparison unit and a second comparison unit, and the high-precision timer includes a third comparison unit. The method includes: receiving a switching signal from the Bluetooth system switching from active mode to sleep mode; taking the detection of the first falling edge of the high-precision clock source as the target time; stopping the low-precision timer at the target time; and starting the timer from the target time until the detection of the first falling edge of the low-precision clock source to obtain a compensation value; and responding to... In response to the scheduling command corresponding to the Bluetooth service, the target scheduling time is determined based on the compensation value, and the wake-up value of the first comparison unit is determined according to the target scheduling time, the compensation amount, and the preset scheduling advance. In response to the wake-up value, the low-precision clock source is controlled to enter a sleep state and switched to a high-precision clock source to drive the low-precision timer. The low-precision scheduling value corresponding to the second comparison unit is determined according to the target scheduling time and the compensation value, and the high-precision scheduling value corresponding to the third comparison unit is determined according to the target scheduling time, the preset clock period, and the remainder value corresponding to the compensation value. The count value of the low-precision timer is accumulated to the second comparison unit to obtain a low-precision count value. When the low-precision count value is greater than the low-precision scheduling value, the high-precision timer is triggered to start accumulating the count value to the third comparison unit until it is equal to the high-precision scheduling value, triggering the scheduling of the Bluetooth service.This application embodiment first uses the detection of the first falling edge of the high-precision clock source as the target time. At the target time, the Bluetooth timer stops counting and starts counting again from the target time until the detection of the first falling edge of the low-precision clock source, obtaining a compensation value. This allows for accurate timing of the time error during the switching between the high-precision and low-precision clock sources, resulting in a compensation value. In response to the scheduling command corresponding to the Bluetooth service, the target scheduling time is determined based on the compensation value. The wake-up value of the first comparison unit is determined according to the target scheduling time, the compensation amount, and a preset scheduling advance. In response to the wake-up value, the low-precision clock source is controlled to enter a sleep state, and the high-precision clock source drives the low-precision timer. This allows for compensation of the switching between the high-precision and low-precision clock sources using the compensation value, thereby improving the reliability of the time reference. Based on an accurate time reference, according to the target... The scheduling time and compensation value determine the low-precision scheduling value corresponding to the second comparison unit. The target scheduling time can be compensated based on the compensation value, making the reliability of the obtained low-precision scheduling value higher. The high-precision scheduling value corresponding to the third comparison unit is determined based on the target scheduling time, the preset clock period, and the remainder value corresponding to the compensation value. The reliability of the high-precision scheduling value is further improved by compensating the target scheduling time with the remainder value corresponding to the compensation value. The count value of the low-precision timer is accumulated to the second comparison unit to obtain a low-precision count value. When the low-precision count value is greater than the low-precision scheduling value, the high-precision timer is triggered to start accumulating the count value to the third comparison unit until it is equal to the high-precision scheduling value, triggering the scheduling of Bluetooth services. Thus, Bluetooth service scheduling is triggered based on the low-precision scheduling value and the high-precision scheduling value, thereby reducing the probability of packet transmission and reception abnormalities in Bluetooth services during the scheduling process. Attached Figure Description
[0008] Figure 1 This is a flowchart illustrating the steps of a method for calibrating Bluetooth service scheduling time according to an embodiment of this application; Figure 2 This is a schematic diagram illustrating the principle of compensation value provided in one embodiment of this application; Figure 3 This application provides a flowchart of the existing Bluetooth protocol stack service scheduling process as one embodiment. Figure 4 This application provides a flowchart of the Bluetooth service scheduling process in one embodiment; Figure 5 This is a hardware schematic diagram of an electronic device provided in one embodiment of this application. Detailed Implementation
[0009] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0010] It is understandable that although functional modules are divided in the device schematic diagram and a logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first," "second," etc., in the specification, claims, or the aforementioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence.
[0011] The Bluetooth protocol is divided into two modes: Classic Bluetooth and Low Energy (BLE). The Bluetooth SIG defines the BLE clock accuracy requirement as 50 ppm during normal operation and wake-up, and 500 ppm during sleep. In Bluetooth systems, to meet the requirements of high accuracy and low power consumption, two clock sources work together: an external high-precision crystal oscillator and a low-precision RC oscillator. Specifically, the high-precision clock source operates during Bluetooth chip wake-up, and the low-precision clock source operates during Bluetooth chip sleep. Both clock sources are divided to output a 32 kHz frequency to drive a timer (the timer is mainly used for timing Bluetooth services that will process packets). However, when the Bluetooth chip switches between wake-up and sleep modes, the high-precision clock source is not immediately put into sleep mode. Instead, a synchronization operation is performed: the next edge of the high-precision clock source (time T0) is detected and recorded as a precise time reference point. Starting from time T0, the timer waits for the first edge of the low-precision clock source. Between time T0 and the next edge of the low-precision clock, there exists a random time error (i.e., phase difference). The maximum value of this time error is one complete clock cycle of the low-precision clock source. In other words, each switch introduces a time error of one clock cycle (31.25µs). This error directly affects the timer, and the accumulation of errors can lead to inaccurate timing of subsequent Bluetooth services, resulting in packet transmission and reception anomalies during Bluetooth service scheduling.
[0012] This application provides a method, device, and medium for calibrating Bluetooth service scheduling time, which can reduce the probability of packet transmission and reception abnormalities during Bluetooth service scheduling.
[0013] For example, the first falling edge of the high-precision clock source is detected as the target time. At the target time, the Bluetooth timer stops counting and starts counting again until the first falling edge of the low-precision clock source is detected, obtaining a compensation value. This allows for accurate timing of the time error during the switching between the high-precision and low-precision clock sources. In response to the scheduling command corresponding to the Bluetooth service, the target scheduling time is determined based on the compensation value. The wake-up value of the first comparison unit is determined according to the target scheduling time, the compensation amount, and a preset scheduling advance. In response to the wake-up value, the low-precision clock source is controlled to enter a sleep state, and the high-precision clock source drives the low-precision timer. This allows for compensation of the switching between the high-precision and low-precision clock sources using the compensation value, thereby improving the reliability of the time reference. Based on an accurate time reference, the target scheduling... The low-precision scheduling value corresponding to the second comparison unit is determined by the time and compensation value. The target scheduling time can be compensated according to the compensation value, making the reliability of the obtained low-precision scheduling value higher. The high-precision scheduling value corresponding to the third comparison unit is determined according to the target scheduling time, the preset clock period, and the remainder value corresponding to the compensation value. The reliability of the high-precision scheduling value is further improved by compensating the target scheduling time with the remainder value corresponding to the compensation value. The count value of the low-precision timer is accumulated to the second comparison unit to obtain the low-precision count value. When the low-precision count value is greater than the low-precision scheduling value, the high-precision timer is triggered to start accumulating the count value to the third comparison unit until it is equal to the high-precision scheduling value, triggering the scheduling of Bluetooth services. Thus, Bluetooth service scheduling is triggered based on the low-precision scheduling value and the high-precision scheduling value, thereby reducing the probability of packet transmission and reception abnormalities in Bluetooth services during the scheduling process.
[0014] For example, the Bluetooth system is configured with an active mode and a sleep mode. The Bluetooth system includes a high-precision clock source, a low-precision clock source, a low-precision timer, and a high-precision timer. The low-precision clock source and the high-precision clock source are both divided to output a 32KHz clock to drive the low-precision timer. The low-precision timer includes a first comparison unit and a second comparison unit, and the high-precision timer includes a third comparison unit.
[0015] For example, the Bluetooth system includes a PCB board, a Bluetooth chip, a high-precision clock source, a low-precision clock source, a low-precision timer, a high-precision timer, and other peripheral circuit devices. The Bluetooth chip, high-precision clock source, low-precision clock source, low-precision timer, high-precision timer, and other peripheral circuit devices are all mounted on the PCB board. The high-precision clock source, low-precision clock source, low-precision timer, and high-precision timer are integrated inside the Bluetooth chip. The high-precision clock source and low-precision clock source are connected to the low-precision timer and high-precision timer, respectively. The high-precision clock source is a crystal oscillator located outside the Bluetooth chip, used to provide a high-precision clock signal. The low-precision clock source is an RC oscillator located outside or integrated inside the Bluetooth chip, used to provide a clock signal in a low-power state where a high-precision clock is not required. The low-precision timer and high-precision timer are used for time synchronization during Bluetooth system communication, as well as for wake-up calls during clock source switching and service scheduling.
[0016] Specifically, the high-precision clock source can be a temperature-controlled crystal oscillator or a rubidium atomic clock, outputting a clock signal with a stable frequency. The low-precision clock source can be an internal RC oscillator, a basic mode crystal oscillator, or a ceramic resonator, capable of outputting a clock signal with a stable frequency at low cost and low power consumption. The accuracy of the high-precision clock source is higher than that of the low-precision clock source. This application does not limit the specific devices used for the high-precision and low-precision clock sources; they can be configured according to actual needs. The following embodiments of this application use an example where both the high-precision and low-precision clock sources output clock signals at 32kHz, with a corresponding clock period of 31.25µs.
[0017] For example, refer to Figure 1 As shown, the method for calibrating Bluetooth service scheduling time includes, but is not limited to, the following steps: In step S100, a switching signal from active mode to sleep mode is received from the Bluetooth system, and the first falling edge of the detected high-precision clock source is taken as the target time.
[0018] Step S110: Stop the low-precision timer at the target time and start timing from the target time until the first falling edge of the low-precision clock source is detected to obtain the compensation value.
[0019] It is understood that this application uses the falling edge as an example, but similarly, the rising edge can also be used as the trigger time. This application does not limit the specific trend of the clock source; while ensuring consistency in the trend, a specific trend can be set according to actual needs.
[0020] For example, taking the switching from a low-precision clock source to a high-precision clock source as an example, refer to... Figure 2As shown, before the switching trigger, the clock signal output to the timer is completely consistent with the waveform of the low-precision clock source. The timer increments by one for each waveform period, and after the switching is complete, it becomes consistent with the waveform of the high-precision clock source. Thus, firstly, at the target time, the Bluetooth timer is pulled low to stop counting. Then, a separate high-frequency clock source starts counting from the target time until the first falling edge of the low-precision clock source is detected. The compensation value obtained from this timing is the phase difference between the low-precision and high-precision clock sources, representing the time error that occurs during the switching. Finally, the compensation value is stored in the corresponding register of the Bluetooth system. In this way, the time error during the switching from the low-precision to the high-precision clock source is accurately calculated using existing hardware within the Bluetooth system.
[0021] Specifically, the high-frequency clock source can be an external crystal oscillator, thus avoiding the impact of switching from a high-precision clock source to a low-precision clock source, and the frequency of the high-frequency clock source can reach 40MHz or 24MHz to improve the accuracy of timing.
[0022] It is understood that the specific implementation method for switching from a high-precision clock source to a low-precision clock source is the same as the above-described implementation method for switching from a low-precision clock source to a high-precision clock source, and will not be repeated here.
[0023] Step S120: In response to the scheduling instruction corresponding to the Bluetooth service, determine the target scheduling time based on the compensation value, and determine the wake-up value of the first comparison unit according to the target scheduling time, the compensation amount and the preset scheduling advance amount.
[0024] In some embodiments, determining the target scheduling time based on the compensation value includes: determining a first time based on the compensation value, the scheduling delay corresponding to the Bluetooth service, and the scheduling time in units of 1µs before n service cycles; and accumulating the service cycles of all Bluetooth services before the target time to the first time to obtain the target scheduling time.
[0025] In some embodiments, the target scheduling time is represented by the following formula: ; in, The target scheduling time is in units of 1µs. For scheduling time, The number of n Bluetooth service cycles that have passed before the target time. The unit of a single service cycle for Bluetooth services is 1µs. The compensation value is in units of 31.25 µs. The scheduling latency corresponding to Bluetooth services. The preset clock cycle is 31.25µs.
[0026] Understandably, the initial scheduling time is first determined based on the scheduling delay corresponding to the Bluetooth service and the scheduling time in units of 1µs before n service cycles. Then, considering the random time error that occurs when the Bluetooth chip switches between wake-up and sleep scenarios, the compensation value calculated in the above steps is used to compensate for the time error, thereby improving the accuracy of the first time. Furthermore, the service cycles of all Bluetooth services that exist before the target time are accumulated to the first time to obtain the target scheduling time based on the accurate time.
[0027] In some embodiments, determining the wake-up value of the first comparison unit based on the target scheduling time, the compensation amount, and the preset scheduling advance includes: compensating the target scheduling time with the compensation value to obtain an intermediate value; and adjusting the intermediate value in conjunction with the preset scheduling advance to obtain the wake-up value.
[0028] In some embodiments, the wake-up value satisfies the following expression: ; in, The wake-up value is expressed in units of 31.25µs. The target scheduling time is in units of 1µs. To pre-set the scheduling lead time, The compensation value is in units of 31.25 µs. The preset clock cycle is 31.25µs.
[0029] It is understandable that the subsequent steps of switching between the low-precision clock source and the high-precision clock source twice will introduce a delay. Since the specific value of this delay cannot be predicted when configuring the wake-up value, the theoretical maximum delay value corresponding to the clock switching is obtained, and the two theoretical maximum delay values are used as preset scheduling advances to avoid being unable to schedule the configuration due to delay.
[0030] In step S130, in response to the wake-up value, the low-precision clock source is controlled to enter a sleep state and switched to a high-precision clock source to drive the low-precision timer.
[0031] For example, if the time interval between two adjacent Bluetooth service packet transmissions is large (e.g., 1 second), the software-initiated sleep callback function of the Bluetooth system controls the digital circuitry in the Bluetooth product to switch from a low-precision clock source to a high-precision clock source.
[0032] Step S140: Determine the low-precision scheduling value corresponding to the second comparison unit based on the target scheduling time and the compensation value, and determine the high-precision scheduling value corresponding to the third comparison unit based on the target scheduling time, the preset clock period, and the remainder value corresponding to the compensation value.
[0033] In some embodiments, determining the low-precision scheduling value corresponding to the second comparison unit based on the target scheduling time and the compensation value, and determining the high-precision scheduling value corresponding to the third comparison unit based on the target scheduling time, the preset clock period, and the remainder value corresponding to the compensation value, includes: dividing the target scheduling time by the preset clock period and then subtracting it from the compensation value in a weighted manner to obtain the low-precision scheduling value; and taking the remainder value after taking the remainder value from the target scheduling time and the preset clock period to obtain the high-precision scheduling value.
[0034] Understandably, based on an accurate time base, the target scheduling time can be compensated according to the compensation value, thereby improving the reliability of low-precision scheduling values. Since the remainder of the compensation value is the remainder part of the compensation value, the remainder represents a finer time segment that cannot be divided evenly by the preset clock period. That is, the remainder represents the time error within one preset clock period. By compensating the target scheduling time with the remainder, the reliability of high-precision scheduling values is further improved.
[0035] In some embodiments, the low-precision scheduling value satisfies the following expression: ; in, The target scheduling time is in units of 1µs. The preset clock cycle is 31.25µs. The scheduling value is a low-precision value in units of 31.25µs. This is the compensation value.
[0036] In some embodiments, the high-precision scheduling value satisfies the following expression: ; in, High-precision scheduling values in units of 1µs. The preset clock cycle is 31.25µs. The remainder value, The target scheduling time is expressed in units of 1µs.
[0037] In step S150, the count value of the low-precision timer is accumulated to the second comparison unit to obtain a low-precision count value. When the low-precision count value is greater than the low-precision scheduling value, the high-precision timer is triggered to start accumulating the count value to the third comparison unit until it is equal to the high-precision scheduling value to trigger the scheduling of Bluetooth services.
[0038] It is understandable that reliable low-precision count values and high-precision scheduling values are used to trigger the scheduling of Bluetooth services, thereby reducing the probability of packet transmission and reception anomalies during the scheduling process.
[0039] Specifically, in the embodiments of this application, Tbase in all formulas refers to the integer value of the current accumulated compensation value divided by 31.25us, and Tfine is the remainder value (in us) of the remainder of the current accumulated compensation value divided by 31.25us. By default, one clock cycle of a 32KHz high-precision clock source or a low-precision clock source is 31.25us.
[0040] For example, refer to Figure 3 As shown, the existing Bluetooth protocol stack service scheduling process (excluding clock switching scenarios) is as follows: First, when a periodic Bluetooth service is created, the initial scheduling time is determined based on the value of the current low-precision timer. Then, after each service cycle is completed, the scheduling time of the next Bluetooth service is incremented by the Bluetooth service cycle time. Next, the low-precision timer is started to perform packet transmission and reception configuration processing in advance before the scheduling time of the next cycle arrives. Specifically, the wake-up value of the first comparison unit of the low-precision timer is obtained by subtracting the preset scheduling advance amount from the service scheduling time. Then, the system enters a sleep state and enters a wake-up state just before the service scheduling. During this process, the clock source of the timer does not switch. Finally, the first comparison unit times out (the current low-precision timer accumulates to the wake-up value, triggering the low-precision timer timeout), triggering the Bluetooth protocol stack to perform the second and third comparison unit configurations to ensure that the Bluetooth service transmits and receives packets at the accurate scheduling time.
[0041] However, when there are two or more clock sources in a Bluetooth system, taking a low-precision clock source and a high-precision clock source as an example, there is a scenario where the low-precision clock source and the high-precision clock source switch between each other. Each sleep and wake-up operation between the low-precision clock source and the high-precision clock source introduces an additional 0~31.25us time error to the current timer. The existing Bluetooth protocol stack service scheduling process uses the current timer count value as a reference when configuring the timer. After multiple sleep and wake-up operations, the error of the current timer will accumulate, eventually causing the timeout trigger time to be later than expected, thus causing abnormal packet transmission and reception issues in the Bluetooth service scheduling process.
[0042] Therefore, refer to Figure 4 As shown, this embodiment adds the current cumulative compensation value to the scheduling time in units of 1µs from n service cycles ago, while also considering the impact of scheduling delays during Bluetooth service scheduling. This ensures that the Bluetooth service avoids the impact of clock switching delays when obtaining timestamps, thereby obtaining an accurate target scheduling time.
[0043] Thus, for each Bluetooth service cycle completed, the target scheduling time accumulates a compensation value. Assuming a total of 10 service cycles have passed, corresponding to 10 sleep and wake-up cycles, or 20 clock switches, each switch is calculated based on the maximum error, i.e., one clock cycle. At this point, the current accumulated compensation value is 20 * 31.25us. Since the target scheduling time is calculated during clock switching, a preset scheduling advance is used when setting the wake-up value of the first comparison unit to ensure that the actual Bluetooth service scheduling time is not missed. After 20 clock switchings, the cumulative delay error of the timer is 20*31.25us, so the preset scheduling advance is set to 13*31.25us.
[0044] If the cumulative delay error exceeds the preset scheduling lead time, the preset scheduling lead time for the wake-up value will not take effect, and the actual business scheduling time will be later than the target scheduling time. Therefore, the current cumulative delay needs to be compensated when setting the wake-up value, that is, the wake-up value is subtracted from the compensation value.
[0045] Understandably, since the two clock switches corresponding to sleep and wake-up introduce two delays, and these delays cannot be predicted when configuring the timer, the preset scheduling lead is also increased by an additional 2 * 31.25us to reserve two units (one unit is 31.25us) of the theoretical maximum delay value in advance, thereby avoiding the inability to schedule configuration due to delays. Furthermore, low-precision and high-precision scheduling values are calculated to account for the two delays introduced by the two clock switches corresponding to sleep and wake-up.
[0046] This application also provides an electronic device, which includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the above-described method for calibrating Bluetooth service scheduling time. This electronic device can be any smart terminal, including tablet computers, in-vehicle computers, etc.
[0047] Please see Figure 5 , Figure 5 The hardware structure of an electronic device according to another embodiment is illustrated. The electronic device includes: The processor 501 can be implemented using a general-purpose CPU (Central Processing Unit), microprocessor, application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this application. The memory 502 can be implemented as a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 502 can store the operating system and other applications. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 502 and is called by the processor 501 to execute the method for calibrating Bluetooth service scheduling time according to the embodiments of this application. The input / output interface 503 is used to implement information input and output; The communication interface 504 is used to enable communication and interaction between this device and other devices. Communication can be achieved through wired means (such as USB, network cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.). Bus 505 transmits information between various components of the device (e.g., processor 501, memory 502, input / output interface 503, and communication interface 504); The processor 501, memory 502, input / output interface 503, and communication interface 504 are connected to each other within the device via bus 505.
[0048] In some embodiments, this application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described method for calibrating Bluetooth service scheduling time.
[0049] Memory, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer-executable programs. Furthermore, memory may include high-speed random access memory, and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, memory may optionally include memory remotely located relative to the processor, and these remote memories can be connected to the processor via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
[0050] The embodiments described in this application are for the purpose of more clearly illustrating the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions provided by the embodiments of this application. As those skilled in the art will know, with the evolution of technology and the emergence of new application scenarios, the technical solutions provided by the embodiments of this application are also applicable to similar technical problems.
[0051] Those skilled in the art will understand that the technical solutions shown in the figures do not constitute a limitation on the embodiments of this application, and may include more or fewer steps than shown, or combine certain steps, or different steps.
[0052] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.
[0053] Those skilled in the art will understand that all or some of the steps in the methods disclosed above, as well as the functional modules / units in the systems and devices, can be implemented as software, firmware, hardware, or suitable combinations thereof.
[0054] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0055] It should be understood that in this application, "at least one (item)" means one or more, and "more than" means two or more. "And / or" is used to describe the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one (item) of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one (item) of a, b, or c can represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.
[0056] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of the units described above is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
[0057] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0058] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0059] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes multiple instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing programs, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
Claims
1. A method for calibrating Bluetooth service scheduling time, characterized in that, The method is applied to a Bluetooth system, which includes an active mode and a sleep mode. The Bluetooth system comprises a high-precision clock source, a low-precision clock source, a low-precision timer, and a high-precision timer. The low-precision clock source and the high-precision clock source are both divided to output a 32kHz clock to drive the low-precision timer. The low-precision timer includes a first comparison unit and a second comparison unit. The high-precision timer includes a third comparison unit. The method includes: Upon receiving the switching signal from active mode to sleep mode from the Bluetooth system, the first falling edge of the high-precision clock source is detected as the target time; At the target time, the low-precision timer is stopped, and the timer starts counting from the target time until the first falling edge of the low-precision clock source is detected, to obtain the compensation value; In response to the scheduling instruction corresponding to the Bluetooth service, a target scheduling time is determined based on the compensation value, and a wake-up value for the first comparison unit is determined based on the target scheduling time, the compensation amount, and a preset scheduling advance amount. In response to the wake-up value, the low-precision clock source is controlled to enter a sleep state, and the high-precision clock source is switched to drive the low-precision timer; The low-precision scheduling value corresponding to the second comparison unit is determined based on the target scheduling time and the compensation value, and the high-precision scheduling value corresponding to the third comparison unit is determined based on the target scheduling time, the preset clock period and the remainder value corresponding to the compensation value. The count value of the low-precision timer is accumulated into the second comparison unit to obtain a low-precision count value. When the low-precision count value is greater than the low-precision scheduling value, the high-precision timer is triggered to start accumulating the count value into the third comparison unit until it is equal to the high-precision scheduling value, triggering the scheduling of the Bluetooth service.
2. The method for calibrating Bluetooth service scheduling time according to claim 1, characterized in that, Determining the target scheduling time based on the compensation value includes: The first time is determined based on the compensation value, the scheduling delay corresponding to the Bluetooth service, and the scheduling time in units of 1µs before n service cycles. The target scheduling time is obtained by summing the service cycles of all Bluetooth services prior to the target time to the first time.
3. The method for calibrating Bluetooth service scheduling time according to claim 2, characterized in that, The target scheduling time is expressed by the following formula: ; in, The target scheduling time is expressed in units of 1µs. The scheduling time, The number of n Bluetooth service cycles that have passed before the target time. The period time of a single service cycle of the Bluetooth service is measured in 1µs. The compensation value is expressed in units of 31.25 μs. The scheduling delay corresponding to the Bluetooth service. The preset clock cycle is defined as 31.25µs.
4. The method for calibrating Bluetooth service scheduling time according to claim 1, characterized in that, The step of determining the wake-up value of the first comparison unit based on the target scheduling time, the compensation amount, and the preset scheduling advance amount includes: The target scheduling time is compensated using the compensation value to obtain an intermediate value; The intermediate value is adjusted by combining the preset scheduling advance amount to obtain the wake-up value.
5. The method for calibrating Bluetooth service scheduling time according to claim 4, characterized in that, The wake-up value satisfies the following expression: ; in, The wake-up value is expressed in units of 31.25 µs. The target scheduling time is expressed in units of 1µs. The preset scheduling lead time, The compensation value is expressed in units of 31.25 μs. The preset clock cycle is defined as 31.25µs.
6. The method for calibrating Bluetooth service scheduling time according to claim 1, characterized in that, The step of determining the low-precision scheduling value corresponding to the second comparison unit based on the target scheduling time and the compensation value, and determining the high-precision scheduling value corresponding to the third comparison unit based on the target scheduling time, the preset clock period, and the remainder value corresponding to the compensation value, includes: The low-precision scheduling value is obtained by dividing the target scheduling time by the preset clock period and then subtracting it from the compensation value. The high-precision scheduling value is obtained by taking the remainder of the target scheduling time and the preset clock period and then subtracting the remainder value.
7. The method for calibrating Bluetooth service scheduling time according to claim 6, characterized in that, The low-precision scheduling value satisfies the following expression: ; in, The target scheduling time is in units of 1µs. The preset clock period is 31.25µs. The low-precision scheduling value is expressed in units of 31.25 µs. The compensation value is [value].
8. The method for calibrating Bluetooth service scheduling time according to claim 6, characterized in that, The high-precision scheduling value satisfies the following expression: ; in, The high-precision scheduling value is expressed in units of 1µs. The preset clock period is 31.25µs. The remainder value is the value mentioned above. The target scheduling time is measured in units of 1µs.
9. An electronic device, characterized in that, include: At least one processor; At least one memory for storing at least one program; When at least one of the programs is executed by at least one of the processors, the method for calibrating Bluetooth service scheduling time as described in any one of claims 1 to 8 is implemented.
10. A computer-readable storage medium storing computer-executable instructions, characterized in that, The computer-executable instructions are used to perform the method for calibrating Bluetooth service scheduling time as described in any one of claims 1 to 8.