Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

Application timer

Altera_Forum
Honored Contributor II
1,089 Views

Hi, 

 

I'm trying to write an application that polls at regular intervals my hardware via serial port. 

 

What I need is an event that calls a function at regular times without charge the CPU usage. 

 

What can I do? 

 

I tried different solutions without succes. 

 

I read something about kernel timers, but I don't need to wirte a driver for the kernel. 

 

Can somebody give me an input? 

 

thanks 

 

stepa
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
390 Views

Hi stepa, 

 

> What I need is an event that calls a function at regular times 

 

I'm assuming you want to access the hardware directly? ... Without 

using the serial driver? If so, you can use the select() system call to wakeup 

periodically. E.g.:<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

while (1) { 

 

    /* Wait for 100 ms */ 

    tv.tv_sec = 0; 

    tv.tv_usec = 100 * 1000; 

    result = select (0, NULL, NULL, NULL, &tv); /* Sleep */ 

 

    /* Do the periodic check */ 

}[/b] 

--- Quote End ---  

 

 

See the manpage for details on select() -- it&#39;s a pretty complete manpage :-) 

 

Regards, 

--Scott
0 Kudos
Altera_Forum
Honored Contributor II
390 Views

Hi Scott, 

 

sorry for the delay of my answer, but I spent some days at home. 

 

Thank you for your answer.  

 

 

<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

I&#39;m assuming you want to access the hardware directly? ... Without 

using the serial driver? [/b] 

--- Quote End ---  

 

 

I&#39;ve a device connected to the Nios via rs232. 

My application has to poll the device periodically to read his status and if somthing changes it sends SNMP traps. 

 

I tried the select example code this morning and it seems to work. 

 

I&#39;m pretty new in uClinux and so I have some questions: 

- is my solution good or is it better to write a kernel driver, and to use kernel timers or task queues or something else? 

 

thanks, 

StePa
0 Kudos
Altera_Forum
Honored Contributor II
390 Views

Hello, 

 

I was looking for some help on using the select() system call and I&#39;ve found this topic. 

My problem is about a multi-threaded application getting stuck (all pthreads generated by this application) when it enters a select which should sleep on a tty. Both the tty driver and the peripheral are custom made. Both worked on an older kernel version: the problem raised this year when we tried to port the system to v 2.6.28 and still persists on v 2.6.30 

The thing which upsets me is that the application could hang for an indefinite time until I make some collateral traffic, e.g. : opening another shell via telnet and launching a top, pressing some buttons (another custom couple of IP and driver). 

 

In case someone would like to help me, what do you need? Which info? (code snippets, sources, info about kernel compilation options... just tell me) 

 

Thanks in advance, 

gabrigob
0 Kudos
Altera_Forum
Honored Contributor II
390 Views

Hello, fyi (if someone found interesting this topic) 

we made some other tests and the driver and the uart seem to work correctly together. We have some troubles with the scheduling in the application. We had to lower the system timer frequency... Does any experienced programmer knows if the scheduler has grown in complexity enough?
0 Kudos
Reply