Design of asynchronous general timer under VxWorks

Design of asynchronous general timer under VxWorks

1 Overview VxWorks is a high-performance real-time embedded operating system kernel developed by WindRiver. Timers are often used in the development of application software. There are 2 ways to realize the timing function under VxWorks: one, with the help of the taskDelay function; second, use the watchdog provided by VxWorks. The disadvantage of using the taskDelay function to implement a timer is that it is task-based, and the task priority will result in inaccurate timing. The watchdog is based on the system clock interrupt, and the timing accuracy is much better than the former, but there are many restrictions on the user's callback function (such as semTake, printf and other functions that need to wait for a certain resource to be used, otherwise it will cause a crash). In addition, the watchdog triggers the callback function only once. If the user needs the period timer, the watchdog needs to be restarted.
This article designs an asynchronous general-purpose timer based on the watchdog mechanism, and designs two types of timers, periodic timing and one-time timing, according to actual needs. Asynchronous means that the timer runs in the task without any restrictions on the user. The asynchronous universal timer provides an operation interface similar to the timer under Windows, which is simple and convenient.


2 Watchdog under VxWorks VxWorks provides a watchdog mechanism that allows user functions that wish to be executed after a certain time delay to be connected to the watchdog, and is automatically executed by the watchdog when the timing time arrives. The watchdog mechanism is maintained by the operating system in the system clock interrupt, and the function connected to the watchdog also runs in the system clock interrupt service program. If the operating system stores functions that cannot be executed immediately in the queue of the tExcTask task due to various reasons (such as an interrupt before the system clock is interrupted or the state of the kernel), the functions in the queue will run at the priority of the tExc-Task task ( Usually 0). The operating system's various restrictions on the interrupt service routine also apply to user functions connected to the watchdog, such as printf, semTake, etc. cannot be used.
There are 4 operation functions for watchdog: create watchdog function, WDOGID wdCreate (void); start watchdog function, STATUS wdStart (WDOG_ID wdId, int delay, FUNCPTR pRouTIne, intparameter); delete watchdog function, STATUS WdDelete (WDOG_ID wdld); cancel watchdog timer function, STATUS wdCancel (WDOG_ID wdld).
The simple use of watchdog is as follows:


First create a watchdog, then connect the user function and set the delay time when starting the watchdog. The interval in the above program is the delay time, and the unit is the TIck number of the system clock. By default, the TIck of the system clock per second is 60. When interval is 1, that is, execute usrFunc after 1/60 s delay. The TIck number of the system clock can be set by the sysClkRateSet function.


3 Design of asynchronous general timer
3.1 Design Idea Although the timing mechanism provided by the watchdog is relatively simple and easy to use, there are still many limitations: â‘  The unit of the timing time is the tick number, not the commonly used s or ms. â‘¡ The user function runs in the system clock interrupt service routine, not in the context of the task. This brings many restrictions to user functions (for example, user functions cannot use memory allocation, get semaphores, printf printouts, etc.), and some functions may not be realized under these restrictions. â‘¢ The trigger of the watchdog is one-time, and usually requires a periodic timer. â‘£ Compared with the timer interface under Windows, the watchdog interface is not simple enough. The design of the asynchronous universal timer is based on the watchdog, and on this basis, further encapsulation is provided to provide a similar use method to Windows. The tick number of the system clock per second can be set by the sysClkRateSet function, which is generally set to 1 000, that is, each tick represents 1 ms. In this way, a timer with a resolution of ms can be provided, which can meet the requirements for most applications. Each timer corresponds to a watchdog and a task at the same time, so that the user function runs in the task rather than in the interrupt, which can avoid various restrictions on the interrupt processing function of the operating system. The specific method is: when generating the timer, start the watchdog to start timing, and at the same time create a task to wait for a counting semaphore (the semaphore is initially empty, the task is in the PEND state); when the timing time arrives, the watchdog is released This signal activates the task and calls the user function in the task. The advantage of this is that it improves efficiency, reduces the load, and reduces the operations in the interrupt (just release the semaphore); although an additional task is created, the task is still in the PEND state when the timer is not triggered, which is Takes up very little.

3.2 Interface design Provide interface functions similar to Windows, the only index of the timer is the id number, and the operation timer is completed by id. There are two types of timers: periodic timers and one-time timers. The periodic timer can be triggered periodically. The one-time timer is only triggered once, similar to the countdown timer, the watchdog is automatically deleted after the trigger, and the corresponding task is automatically exited. After the user initializes the timer module, the user can call the interface provided by the timer anywhere in the program.



3.3 Specific implementation
3.3.1 Encapsulation of the watchdog Based on program design considerations, the management and control of the timer and the specific operation of the watchdog are separated, and the watchdog is encapsulated. The CClkGenerator class encapsulates all operations of the watchdog , Including creation, deletion, cancellation and start of watchdog, save timer id, type, timing period, etc. It is worth noting that the callback function of the watchdog is not the callback function of the user, but a unified callback function provided in the watchdog management control. The parameter in the callback function is the index number of the timer. The package code is as follows:


As can be seen from the class definition, users cannot directly use CClkGen-erator. In other words, this class is invisible to the user, which blocks direct operation of the watchdog, and only the timer management control module can operate it.
3.3.2 Timer management and control The timer management and control module is responsible for module initialization, storage management of multiple timer-related parameters, safe exit of timer tasks, and implementation of the user interface.
The main data structure of the timer: timer control structure and storage structure.

Use the map in the C ++ standard template library to store the timer. The first parameter is the index number of the timer, and the second parameter is the timer control structure. Use map to easily implement storage management and search for index numbers based on timer index numbers. The schematic diagram of timer storage using map is shown in Figure 1.


When calling the SetTimer function, the user creates a count semaphore timerArrv whose initial state is empty, and generates a task timerTask to wait for the semaphore. At this time, the task state is PEND; instantiates a CClk-Generator object to create a watchdog start timing Device. When the timer expires, the timerArrv semaphore is released, the task blocked on timerArrv is released, and the user function is called back to complete a complete timing process. The typical running process of the timer is shown in Figure 2.

The bottom dotted line in Figure 2 points to the interrupt processing flow after starting the watchdog. The middle part shows the running process of the timer task. It can be seen that the user callback function is running in the task space. The dotted line from "callback function release semaphore" to timer task semTake "indicates that releasing the semaphore unlocks the task.


4 Application of timer The timer management and control module is the only interface for users, and uses Single-ton mode. Just call CTimerCtrl :: GetTimerCtrl () to complete the initialization of the asynchronous universal timer. In addition to the timer related operations, it also includes setting the system clock ticks per second to 1000 through the sysClkRateSet function. The following example contains 2 timers: one is a 1 sN periodic timer; the other is a one-time timer with a period of 5 s.

Conclusion From the application examples, it can be seen that the use method of the asynchronous universal timer is not much different from the timer under Windows, and the interface is simple and clear. Asynchronous general-purpose timers can be used in most applications with a timing accuracy of ms. It is more appropriate to use hardware-assisted clock interrupts for timings with accuracy requirements higher than ms, but pay attention to the limitations of the operating system on interrupt handling functions.

Micro LED Copper Light

Micro LED is a new kind of light source which has developed rapidly in recent years. LED light has been widely used for its advantages of small size, low power consumption, long service life, high brightness, low heat and environmental protection.

With the development of LED technology, more and more LED lights, and LED products LED copper wire in the lamp string not only applied to various festivals such as Christmas holiday decoration, and applied to a family to decorate and designs city-lighting project and all kinds of entertainment places.LED twinkle light has incomparable advantages with the traditional incandescent lamp series: colour is gorgeous, can realize a variety of color changes, and effectively reduce the energy consumption, composed of 7 colour color LED twinkle light can not only play the role of lighting, its adornment effect is to let different programs and different occasions add to the festive atmosphere.

The LED copper wire lamp is about 0.38-0.5mm without soldering point, and it has high softness, flexible bending, arbitrary shape and not easy to be broken down.                                                                                                        

 [1]LED copper wire lamps are mainly used in the use of value: low power consumption, high efficiency, long life cold light source, long time lighting, rich color.

[ 2] LED copper wire light product use performance: easy installation, low maintenance rate, non-friable, high brightness, flexible, high temperature resistance, water proofing property is good, green environmental protection, low temperature, energy saving, high safety, light weight, small volume.
[3]LED copper wire light application range: all kinds of strange new utility can be DIY products, such as clothes, bags, shoes, gloves, jewelry (necklaces, lei), bicycles, motorcycles and all kinds of car shine.Product classification editor
Classification by wire material.
A. Copper wire lamp string.
B. String of silver wires.
C. flexible string
D. copper enameled wire (available in any color, black, white, blue, green, etc.)
Sort by drive.
A. The battery box class LED lamp is equipped with 10-100pcs lamp beads, and the optimal configuration is below 50 beads.
1. 2*AA battery box.
2. 3*AAA battery box.
3. Waterproof 3*AAA battery box.
4. 2*CR2032 battery box.
5. 3*AG13 battery box.
6. Time switch battery box.
7. Multi-functional battery box.
Drive the classification chart.
Drive classification scheme (8 sheets)
B. There is no limit on the configuration of power transformer LED lamps, and the input voltage and LED quantity have a certain relationship as follows:
3 V(10-50 lamps);
4.5V(50 ~ 70 lamps);
6 V(100 ~ 300 lights);
12 V(above 300 lights);
24V(above 1000 lamps);
36 V(above 2000 lamps);
C. Solar energy: use the solar power to charge, put the lamp string controller in the sunny place, and hit the switch to (ON 1) or (ON 2).
D.USB power source:
E. Remote power source: the color change, speed change and brightness change of LED copper wire lamp are realized through the remote control device.
Classification by lamp beads.
A. ordinary rice grains.
B. Shape: such as heart, star, diamond, snowflake, petal, star, Christmas tree, Santa Claus, Christmas boots, etc.
Classification by appearance.
A.lamp string.
B.PVC tube light.
C. watefall lights
D. Cluster Lights
E.Cascade Lights  F.icicle&curtain lights  G.Tangle Free Item  H. Figure Lights   I.3D Acrylic                                              
Use method editing
1- battery pack: install the battery, press the pull switch to install the product to any place you can install.
2- power transformer: the installation is simple and easy to use, just plug in the plug or switch on the battery box switch to power the power.Put the lamp around the place you want and set the shape you want.The humanized design of the product lets you eliminate the trouble of installation and use.
Specification editor
Common length, lamp distance, number of lights.
1M 20 lights (spacing 5CM)
5M 50 lights (spacing 10CM)
10m-100 light (spacing 10CM)                                                                                                                                                  

Micro Led Copper Light

Micro LED Copper Light,Silver Copper String Lights,Copper Wire String Lights,Micro String Light

Heshan Jianhao Lighting Industrial Co., Ltd. , https://www.sunclubtw.com

This entry was posted in on