This is the mail archive of the
ecos-discuss@sourceware.org
mailing list for the eCos project.
Re: how to get minimum resolution
- From: Andrew Lunn <andrew at lunn dot ch>
- To: sandip <sandip at masibus dot com>
- Cc: ecos-discuss at ecos dot sourceware dot org
- Date: Sat, 11 Aug 2007 10:05:57 +0200
- Subject: Re: [ECOS] how to get minimum resolution
- References: <1186804964921.23.postmaster@masibus.com>
On Sat, Aug 11, 2007 at 09:32:33AM +0530, sandip wrote:
> dear friend ,
>
> here i send my code, using alarm i am going to drive seven segment display.
> cyg_alarm_initialize(test_alarmH, cyg_current_time()+1, 1);
> using this i provide minimum delay and function call in short time.but i
> didn't get small delay.
Try this version. You should see output like:
ticks: 1000, alarms: 1000, alarms/second: 100
ticks: 2000, alarms: 2000, alarms/second: 100
ticks: 3000, alarms: 3000, alarms/second: 100
ticks: 4000, alarms: 4000, alarms/second: 100
ticks: 5000, alarms: 5000, alarms/second: 100
ticks: 6000, alarms: 6000, alarms/second: 100
ticks: 7000, alarms: 7000, alarms/second: 100
ticks: 8000, alarms: 8000, alarms/second: 100
I've not tried it on the sam7x, but i expect it to pretty similar.
Andrew
#include <cyg/kernel/kapi.h>
#include <cyg/infra/diag.h>
#define HZ 100
/* test_alarm_func() is invoked as an alarm handler. so
Increments the data that is passed to it. */
void
test_alarm_func(cyg_handle_t alarmH, cyg_addrword_t data)
{
++*((unsigned *) data);
}
/* Entry point. Setup and alarm, and then print how often it gets
called per second */
int
main(const int argc, const char * argv[])
{
cyg_handle_t test_counterH, test_alarmH;
cyg_alarm test_alarm;
cyg_uint32 alarm_count = 0;
/* Get the counter associated to the real time clock. */
cyg_clock_to_counter(cyg_real_time_clock(), &test_counterH);
/* Create an alarm */
cyg_alarm_create(test_counterH, test_alarm_func,
(cyg_addrword_t) &alarm_count,
&test_alarmH, &test_alarm);
/* Initialize the alarm to trigger once per system tick,
recurring. */
cyg_alarm_initialize(test_alarmH, cyg_current_time()+1, 1);
/* Every so often, print out how many alarms per second we are
achieving. */
for (;;) {
cyg_uint32 alarms;
cyg_uint32 ticks;
cyg_thread_delay(10 * HZ);
cyg_scheduler_lock();
alarms = alarm_count;
ticks = cyg_current_time();
cyg_scheduler_unlock();
diag_printf("ticks: %5d, alarms: %5d, alarms/second: %3d\n",
ticks, alarms, alarms/(ticks/HZ));
}
}
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss