introduction
In VxWorks, the implementation of the timer mechanism is based on the clock. Different timing mechanisms can be selected according to different requirements, such as taskDelay(), WatchDog, and auxiliary clock . The first two timings are based on the system clock.
taskDelay() is the simplest delay method. Its unit is tick, so its delay accuracy is not high, but it is sufficient for systems with delays of more than 10 ms. Using taskDelay(), the called task can be transferred from the ready state to the sleep state, but it cannot be used in interrupt service routines. In addition, by calling taskDelay(0), the CPU can be handed over to other tasks of the same priority in the system.
The watchdog timer is maintained as part of the system clock interrupt service routine. Therefore, the functions associated with the watchdog timer run at the system clock interrupt level, and the delay unit is tick. If the application requires multiple watchdog functions, wdCreate() can be used to generate independent watchdog IDs for each requirement, because for a given watchdog ID, only the most recent wdStart() is valid. With the watchdog timer, the calling task will not be blocked because the wdStart() call returns immediately. But it is generally only suitable for systems with a delay of more than 10ms.
If a higher precision timing (such as 1 ms) is required in practice, then the use of auxiliary clock is a very desirable method. Generally, auxiliary clock is not configured in the BSP of VxWorks system. This article introduces the configuration and use of auxiliary clock in detail so that it can be used flexibly in practice.
1 AT91RM9200 Industrial Platform Clock and Timer
The research in this paper is based on the AT91RM9200 industrial platform, so it is necessary to first introduce the clock and timer under this platform.
AT91RM9200 provides two 3-channel 16-bit timer/counters (TC). Although the three channels are independent, they operate in the same way. Each channel is user-configurable, including three external clock inputs (XC0, XCl or XC2), five internal clock inputs (TIMER_CLOCK1, TIMER_CLOCK2, TIMER CLOCK3, TIMER_CL0CK4, TIMER_CLOCK5), and two multi-function input/output signals that can be configured by the user. In addition, each channel can work in two different modes, namely capture mode and waveform mode. Among them, the capture mode provides signal measurement, and the waveform mode is used to generate waveforms, which can be programmed by the WAVE bit of the TC channel mode register. The block diagram of the timer/counter is shown in Figure 1.
Among them, if the channel signal is selected, XCO, XCl, and XC2 represent three external clock inputs; TIOA and TIOB represent two multi-function input/output signals acting on each channel; INT represents interrupt signal output; and SYNC represents synchronous input signal. If the block signal is selected, TCLKO, TCLKl, and TCLK2 represent three external clock inputs; TIOAO~TIOA2 represent the TIOA signals of channels 0 to 2, and TIOB0~TIOB2 represent the TI0B signals of channels 0 to 2.
Among them, the five internal clock inputs are related to the main clock (MCK), the slow clock (SLCK) and the clock after the main clock is divided, as listed in Table 1.
2 Configuration of auxiliary clocks in VxWorks
If you want to use the auxiliary clock in the VxWorks operating system, you must go through certain configurations before you can use it. First, you need to define it in the VxWorks component or config.h:
#define INCLUDE_AUX_CLK
If it is not defined, the auxiliary clock cannot be used. In addition, the auxiliary clock needs to be initialized in the sysHwlnit2 function of sysLib.C, that is, the interrupt connection configuration:
(void)intConnect(AUX_TIMER_INT_VEC, sysAuxClkInt, O)
The difference between the auxiliary clock and the system clock is that the auxiliary clock must be provided by the user in the ISR, but calling tickAnnounce() in the ISR is not allowed, otherwise it will disrupt the system clock mechanism.
The configuration of the auxiliary clock can be modified according to the function template in installDir/target/drv/timer/templateTimer. C. The driver used in this article is At91Rm9200timer. c, and the header file is At91Rm9200timer. h. The modifications made in this file need to be made according to the specific chip it depends on, that is, it is necessary to refer to the AT91RM9200 chip data sheet.
The functions related to the auxiliary clock are: sysAuxClkInt(), sysAux-ClkConnect(), sysAuxClkDisable(), sysAuxClkEnable(), sysAuxClkRateGet() and sysAuxClkRateSet(). Among them, sysAuxClkRateGet() can be regarded as a group with sysAuxClkRateSet(). sysAuxClkRateGet() reads the clock frequency set by the sysAuxClkRateSet() function, and the clock frequency setting in the sysAuxClkRateSet() function is limited by AUX_CLK_RATE_MIN and AUX_CLK_RATE_MAX. This maximum and minimum value needs to be defined, and the definition location may be different. Some are placed in eonfig.h, and some are placed in bsp.h. The maximum and minimum values in this article are defined in Inte-grator.h. The next two functions that need to be discussed are sysAux-ClkInt() and sysAuxClkEnable().
The sysAuxClkInt() function calls the user-defined interrupt processing function, and the interrupt processing function called by the user is connected by the sysAuxClkConnect() function. Before calling the interrupt processing function, you must first clear the interrupt operation, such as:
AMBA_TIMER_READ(AMBA_TIMER_T2SR(AMBA_TIMER_BASE), temp);
Otherwise, the CPU will be stuck in interruption and cannot do anything else.
[page]
A lot of other work is done in the sysAuxClkEnble() function. According to the specific situation of AT91RM9200, select one of the five internal clocks, here select TIMER_CLOCK2; according to the channel concept mentioned above, select the second channel. It must be distinguished from the system clock. You cannot select an internal clock and the same channel at the same time.
First, you need to determine whether the auxiliary clock is configured in the power management . You can check the relevant files. If it is not configured, you need to configure it as follows:
AT9l_SYS→PMC_PCER=l<
Secondly, the AIC must be programmed first, and then the TC is configured.
Then, it is necessary to control the specific registers. First, the internal clock needs to be selected, as shown in Figure 2.
Control the channel mode register:
AMBA_TIMER_WRITE(AMBA_TIMER_T2MR(AMBA_TIMER_BASE), TIMER_CLOCK2| TC_CPCTRG);
The second internal clock is selected through the TCCLKS bit, and the RC comparison trigger is enabled according to the timer value written into the RC register. At the same time, the TC channel control register needs to be controlled to write the counter clock enable command and software trigger command, such as:
AMBA_TIMER_WRITE(AMBA_TIMER_T2CR(AMBA_TIMER_BASE), TC_CLKEN);
AMBA_TIMER_WRITE(AMBA_TIMER_T2CR(AMBA_TIMER_BASE), TC_SWTRG);
In addition, since the RC register is used to trigger the enable, it is also necessary to control the TC interrupt enable register and write the RC comparison interrupt enable signal, such as:
AMBA_TIMER_WRITE(AMBA_TIMER_T2IER(AMBA_TIMER_BASE), TC_CPCS);
Finally, the interrupt enable operation needs to be performed, such as:
AMBA_TIMER_INT_ENABLE(AUX_TIMER_INT_LVL);
After everything is configured, recompile bootroFll and VxWorks image, start VxWorks image; then write a test program to test and verify whether the auxiliary clock is configured successfully. In addition, the auxiliary clock interrupt can be checked through a logic analyzer. After the auxiliary clock is driven, the sysAuxClkRateSet() function can be used in the application to dynamically set the number of interrupts per second of the system auxiliary clock; the sysAuxClkConnect() function specifies the ISR for the system auxiliary clock interrupt, and the sysAuxClkEnable() function enables the clock interrupt to call the specified ISR.
Conclusion
The main purpose of VxWorks providing the system auxiliary clock mechanism is to allow users to choose an additional timing resource besides the system clock and provide management means. In addition, some auxiliary debugging tools of VxWorks may also require the use of the system auxiliary clock.
The use of auxiliary clock is achieved by increasing the beat rate, and increasing the beat rate means that clock interrupts are generated more frequently, so the interrupt handler will be executed more frequently. This will bring the following benefits to the entire system:
①Higher clock interrupt resolution can improve the resolution of time-driven events;
② Improved the accuracy of time-driven events.
Previous article:Multi-channel USB2.0 data acquisition system based on AT91SAM7X
Next article:Characteristic Analysis and Application of Synchronous Serial Port SSC of AT91RM9200 Processor
Recommended ReadingLatest update time:2024-11-16 21:38
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- UnitedSiC (now part of Qorvo) announces industry-leading, high-performance 1200 V Gen 4 SiC FETs
- BK3432 DC-DC peripheral reference schematic diagram BK3432 DC-DC peripheral reference schematic diagram
- MSP430 clock system problem
- SD cards all have 4GB/s!
- quartus18.1
- Why are there always connection points when drawing the wiring of the schematic in KICAD? And the lines are always misplaced. Why is this the case?
- Components Science Popularization: Working Principle Analysis of Thermal Protector
- Who knows the principle of voltage doubling circuit? No transformer or inductor is used, just a few diodes and capacitors...
- EEWORLD University Hall----Application of GaN power devices in 1.4KV multi-level system
- 6. DMA implementation of USART1 sending and receiving