VxWorks timing mechanisms

Source: Internet
Author: User
Tags posix

In the programming process, timing and latency are more or less required. There are several Timing/latency mechanisms in VxWorks. Based on the relevant documents of VxWorks, based on the learning and hands-on experiments, I would like to summarize their usage and problems and hope to help you. If it is incorrect, please correct it. A 1 taskdelay-K ~ Taskdelay () provides a simple task sleep mechanism, which is also commonly used in applications that require a timing/latency mechanism. The format is status taskdelay (INT ticks/* Number of ticks to delay task */), we can see that the unit for implementing latency using this function is tick (generally, one tick in the system is MS-level ). In VxWorks, The taskdelay () function can be used as follows: taskdelay (sysclkrateget () * 1 ). The sysclkrateget () function returns the clock rate of the system, measured in tick count/second (the system clock rate can be changed using the sysclkrateset () function ). In POSIX, there is a function corresponding to taskdelay ()-nanosleep () (described below ). The two functions only have different delay units, and the effect is the same. & AM
With taskdelay (), you can move the called task to the end of the ready queue with the same priority. In particular, you can call taskdelay (0) to deliver the CPU to other tasks with the same priority in the system. A call with a delay of 0 can only be used in taskdelay (). nanosleep () considers this call as incorrect. 8 taskdelay () will cause the called task to discard the CPU during the specified delay period (counted by ticks) and put the task in the delay state (therefore, it cannot be used to interrupt the service program ). It is usually affected by task scheduling, but it is useful when waiting for some external conditions that are not associated with the interruption. If the called task receives a signal indicating that it is not blocked or ignored, taskdelay () Returns Error and sets errno to eintr after the signal processing program runs. Wepim
2 watchdog. epupo VxWorks provides a watchdog timer mechanism. With the provided functions, any task can create a watchdog timer. After a specified delay, to run the specified program in the context of the system clock ISR. In VxWorks, the watchdog timer is maintained as part of the system clock interruption service program. Therefore, the function associated with the watchdog timer runs at the system clock interruption level. When the watchdog timer is used to implement Timing/latency, the application interruption takes priority over the system clock interruption at the specified time. However, if the kernel cannot immediately execute this interrupt service program, this task is queued to texctask.
In the work queue, the priority of tasks in the texctask work queue is texctask (usually 0 ). For interrupt service programs that use the watchdog timer, the general ISR rules must be followed. Pu creates a watchdog timer through wdcreate. Call wdstart () to start the timer. The delay parameter is in the unit of tick. You must also specify the program to be called after the timer is completed. If your application requires multiple watchdog functions, use wdcreate () to generate an independent watchdog ID for each requirement. Because only the nearest wdstart () is valid for the given watchdog ID. You can call wdcancel () to cancel a watchdog timer before the specified tick count reaches. X
Each time wdstart () is called, the watchdog timer is executed only once. For applications that require periodic execution. To achieve this effect, the timer function must call wdstart () recursively to restart the timer. C _/P uses the watchdog timer, and the called task is not blocked because wdstart () is returned immediately. This method is used to implement latency. The associated functions are too limited, so many system calls are unavailable and depressing... Hakir 3 timer (POSIX) 9ca 3.1 timer ~ KN and VxWorks provide the ieee posix 1003.1b standard timer interface. With this timer mechanism, after a specified time interval, the task sends a signal to itself. The timer is built on the clock and signal. N
You can create, set, and delete a timer. When the timer expires, the default signal (sigalrm) will be sent to the task ). <General process for using Timer: XR;, 0n/* Create timer */[] 9, * If (timer_create (clock_realtime, 0, & mytimer) = Error) = s return (error);)/* connect the user program to the timer */{K if (timer_connect (mytimer, (voidfuncptr) my_handler, 0) = Error) w ^ BW 'Return (error); B
/* Set the timer value */kh_kr9 if (timer_settime (mytimer, 0, & Value, 0) = Error) g return (error ); DU/* a delay */| KF ...... & UF5/* Delete timer */H v-If (timer_delete (mytimer) = Error) Zul return (error); H @ <when using a timer, it is easy to ignore the process of sending signals to the task after the scheduled end. That is, after the timer ends, the timer program will not be able to run if the task that creates the timer does not exist. The error "interrupt:
Timerwdhandler: Kill failed (timer = ******, tid = *******, errno = 0x16) "(there is) A few questions about the function!" Post, which mentions this issue ). When I was on the machine, I set a timer for a long time, and used the same latency operation (taskdelay () and nanosleep () in the task of creating a timer ), at this time, the program runs normally. After the timer ends, the program associated with the timer is correctly executed. After the timer ends, I delete the task of creating the timer under shell, the preceding error occurs after the scheduled task is completed. Therefore, when using the POSIX timer, be sure not to let the task of creating the timer end before triggering the Timer Program, otherwise... Prepare reset BBQ
3.2 nanosleep () K3] The function nanosleep () is similar to taskdelay () provided by VxWorks. nanosleep () allows you to specify the scheduled/delayed time in seconds and in seconds, taskdelay () uses tick as the Scheduled/delayed time. The two are only different delay units, rather than different precision, which are determined by the system clock frequency. Like taskdelay (), tasks that use nanosleep () for timing and latency are also affected by scheduling. Pay attention to this in actual operations. When * K * B uses nanosleep (), the timing parameter uses it_value IN THE itimerspe structure. You can specify the second and the second in it_value as the Scheduled/delayed time. Functions are easy to use. Ud0f
4 other Ri * Y uses msgqreceive () and semtask () with a timeout value of timeout to implement latency (is this method used for latency? No? Yes? No? Yes? No ?...). % This method will block the task and cause it to wait for timeout. The latency function semtask (..., Timeout), msgqreceive (...,...,..., Timeout ). Call tasks are put into the blocking queue. (Note that the value of time cannot be no_wait when semtask and msgqreceive are used. If no_wait is specified, the system will return immediately, in this case, the latency is not achieved. ^_^ ). If you want to keep the task from being blocked, you can continue to execute the task. Sorry, this method is not feasible. Use the dog. T' FQ
When the blocked task meets the conditions for continued execution, it will be placed in the ready queue. It is important to note that the task is put into the ready queue, which does not mean that the task is executed immediately. Think about it. If a task with a higher priority is occupying resources or waiting for resources, then... Latency will be uncertain

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.