Bas
Bas

Reputation: 467

scheduling tasks in linux

Can we schedule a program to execute every 5 ms or 10 ms etc? I need to generate a pulse through the serial port for 1 khz and 15 khz. But the program should only toggle the pins in the serial port , so the frequency has to be produced by a scheduler. is this possible in linux with a rt patch?

Upvotes: 4

Views: 1161

Answers (4)

Bas
Bas

Reputation: 467

I have finally found a way to get it done. The best way to do it is to first create a timer with the required amount of time. and then to call the task( which is the pulse generating program) every time the timer overflows. The program for the timer can be run in the background. the timer can be created and set using the timer_create() and timer_settime() respectively. A different program can be called from one program using fork() and execl(). The program can be run in the background using the daemon(). By using all these things we can create our own scheduler.

Upvotes: 0

user2485710
user2485710

Reputation: 9801

There is the PPS project that is now part ( at least a portion of it for the 2.6 branch, but in the latest 3.x kernel branch it looks like there is a full integration ) of the mainline linux kernel.

There is also an explicit reference to using this PPS implementation with a serial port in the linked txt file

A PPS source can be connected to a serial port (usually to the Data Carrier Detect pin) or to a parallel port (ACK-pin) or to a special CPU's GPIOs (this is the common case in embedded systems) but in each case when a new pulse arrives the system must apply to it a timestamp and record it for userland.

Apparently good examples / tutorials / guides, are not even that hard to find , I'm sure that you'll find a lot of good resources while just using search engine.

The header for the APIs is usually under /usr/include/linux/pps.h .

Upvotes: 1

Jeyaram
Jeyaram

Reputation: 9474

is this possible in linux with a rt patch?

I suggest to go for RT patch, if timing is critical.

Xenomai is a RT patch which I used on 2.6 kernel some days back.

Here is an example which runs every 1 second. http://www.xenomai.org/documentation/trunk/html/api/trivial-periodic_8c-example.html

Upvotes: 1

Lee Duhem
Lee Duhem

Reputation: 15121

I believe a better solution is to put your "generate a pulse" function in a loop, for example:

for (;;) {
    generate_pulse(); /* generate a pulse */
    sleep(5ms);       /* or 10ms */
}

Upvotes: 1

Related Questions