Hello,
This week I accomplished something; I managed to hook up a HD47780 style LCD to
the Fox Board. I did however notice that the program rssreader was using up all
of the CPU because of its brutal 'delay' routines, so I went looking for a fix
for this.
I needed a function that would put the process to sleep for at least a given
period of time and give up the CPU to play nice with other processes. I doesn't
matter if that time is too long, the whole communication is synchronous anyway.
I found some documentation on sleep(), nanosleep() and finally settled on using
the select() function as the documentation that I found stated that it was the
most portable way of doing it.
I replaced the functions msDelay() and usDelay() with the following:
void msDelay(int ms)
{
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = ms * 1000;
select(0, NULL, NULL, NULL, &tv);
}
void usDelay(int us)
{
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = us;
select(0, NULL, NULL, NULL, &tv);
}
I compiled and ran it for a while and found out system load dropped from >1 to
0.03. Perhaps this snippet of code is worthy of inclusion in the next version
of the Fox SDK?
Sincerely,
Dave Van den Eynde