public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
From: "Øyvind Harboe" <oyvind.harboe@zylin.com>
To: ecos-discuss@sources.redhat.com
Subject: [ECOS] HAL_DELAY_US() default implementation
Date: Wed, 22 Jun 2005 07:26:00 -0000	[thread overview]
Message-ID: <1119425206.20805.21.camel@localhost.localdomain> (raw)

Ref

http://ecos.sourceware.org/ml/ecos-patches/2005-06/msg00033.html

Looks good.

Thoughts on a default implementation:

- Add calibration by default on startup. There are so many things
  affecting the performance: type of ram/flash, caches, off-frequency
  crystals(e.g. 64MHz instead of 66 MHz crystal), etc. 
  I'm not entirely convinced that the calibration number can
  be put in the source and committed to CVS. E.g. for the AT91
  there are 5 HALs X 3 types of code memory(internal, external
  & flash) =  15 calibration numbers. The number of combinations
  for all the eCos HAL's could easy reach thousands.
- Calibration can be disabled by specifying the number in 
  a CDL option. This number is extracted by running the app in 
  the debugger and setting a breakpoint at the end of the calibration 
  loop.
- The calibration algorithm must have some sort of way to estimating
  the accuracy to determine when the calibration should terminate.
  Integer math.


Some code:

/* this fn takes at least 0.000001342194658704 seconds 
 * to execute one iteration (EB40a running out of flash).
 * 
 * A number of factors affect this number:
 * 
 * - Is the code in ram/rom, wait states
 * - Iterrupts/task switches can slow it down
 */
 

static void busy(int j)
{
	__asm volatile (
	
	".L1: nop\n" 
	"sub %0,%0,#1\n" 
	"cmp %0,#0\n"
	"bne .L1\n"
	
	: "+r" (j));
}

/* times the busy() function */
void timeIt() 
{
	for (int j=1000; j<10000000; j=((j*110)/100))
	{
		// time it.
		cyg_tick_count_t lastTime=cyg_current_time();
		busy(j);
		cyg_tick_count_t current=cyg_current_time();
		diag_printf("%d %d\n", j, (int)(current-lastTime));
	}
}


/* Waits at least this many us.
 * 
 * Does not require kernel to be running.
 */
void waitus(int us)
{
	float oneIteration=0.000001342194658704;
	int iterations;
	iterations=(int)(us*1000000*oneIteration);
	busy(iterations);
}

Example run:

loops   ticks   time/seconds
1395411	187	0,000001340106964901
1534952	206	0,000001342061510718
1688447	227	0,000001344430710588
1857291	249	0,000001340662287170
2043020	274	0,000001341151824260
2247322	301	0,000001339371928010
2472054	331	0,000001338967514464
2719259	365	0,000001342277436610
2991184	401	0,000001340606261601
3290302	441	0,000001340302501108
3619332	486	0,000001342789221879
3981265	535	0,000001343793995125
4379391	588	0,000001342652437291
4817330	647	0,000001343067632900
5299063	711	0,000001341746644643
5828969	782	0,000001341575156773
6411865	861	0,000001342823031988
7053051	947	0,000001342681344570
7758356	1042	0,000001343068041735
8534191	1145	0,000001341662027485
9387610	1260	0,000001342194658704


-- 
Øyvind Harboe
http://www.zylin.com


--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

             reply	other threads:[~2005-06-22  7:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-22  7:26 Øyvind Harboe [this message]
2005-06-26 14:26 ` Bart Veer
2005-06-26 17:11   ` Øyvind Harboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1119425206.20805.21.camel@localhost.localdomain \
    --to=oyvind.harboe@zylin.com \
    --cc=ecos-discuss@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).