This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: Strange Problem in cyg_thread_delay( )?
- To: Huang Qiang <jameshq at liverpool dot ac dot uk>
- Subject: Re: [ECOS] Strange Problem in cyg_thread_delay( )?
- From: Andrew Lunn <andrew dot lunn at ascom dot ch>
- Date: Mon, 23 Apr 2001 15:18:17 +0200
- Cc: eCos <ecos-discuss at sources dot redhat dot com>
- References: <KIEBICHBADHFCLGCKOPDCEFACBAA.jameshq@liv.ac.uk>
Hum, your code looks OK. As has already been mentioned on this list,
what do the other bits in the register do?
Have you tried other values of delay? Does it run for longer?
Are you a CS student at Liverpool Uni? I've edited your code a bit to
improve the style. I've moved some variables around, and replaced your
big case statemenet with a one liner. Lookup bitwise shift operations
in your C book. I've not checked this still compiles.
Andrew
/* define the LED PORT address */
#include <cyg/kernel/kapi.h>
#define IOPDATA ((volatile unsigned *)(0x03FF5008))
#define STACKSIZE 4096
void delay(int cnt); /* delay routine */
cyg_thread thread_s;
char stack[STACKSIZE];
cyg_handle_t LED_thread;
cyg_thread_entry_t LED_program;
void cyg_user_start(void)
{
cyg_thread_create(4,LED_program, (cyg_addrword_t) 0, "LED Thread",
(void *) stack,STACKSIZE, &LED_thread, &thread_s);
cyg_thread_resume(LED_thread); /* resume the led thread */
}
void LED_program(cyg_addrword_t data)
{
unsigned dispcnt = 0; /* display counter */
*IOPDATA = 0x00; /* clear display of the LED */
delay(20);
for(;;)
{
/* ensure the display counter not exceed 4-bit. (value 15)
(we got 4 led on the evaluator7T board so 4 bits) */
if (dispcnt>=16)
dispcnt = 0;
*IOPDATA = ( dispcnt << 4);
cyg_thread_delay(200);
dispcnt++;
}
}
/* manual delay routine */
void delay(int cnt)
{
int cnt1, cnt2, cnt3;
for(cnt1=0;cnt1<40000;cnt1++)
{
for(cnt2=0;cnt2<cnt;cnt2++)
cnt3 = 0;
}
}