This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Using alarm
- To: "Ecos-Discuss (E-mail)" <ecos-discuss at sources dot redhat dot com>
- Subject: [ECOS] Using alarm
- From: Ho Shui Choy Stanley NCS <scho at ncs dot com dot sg>
- Date: Fri, 3 Aug 2001 11:20:41 +0800
Hi
I have written a test program using alarm. Following is the code:
static void my_alarm_func (cyg_handle_t alarm, cyg_addrword_t data)
{
cyg_uint8 buf[100];
cyg_uint32 len;
cyg_uint16 index;
bool found;
len = 100;
cyg_io_read(serial0, buf, &len); //clear buffer
len = strlen(at_cmd);
cyg_io_write(serial0, at_cmd, &len);
if (green_led_status == false) {
PIO->PIO_CODR = GREEN_LED;
green_led_status = true;
}
else {
PIO->PIO_SODR = GREEN_LED;
green_led_status = false;
}
found =false;
//// program hangs here
while (found == false) {
len = 100;
cyg_io_read(serial0, buf, &len);
if (len != 0) {
for (index = 0; index < len; index++) {
if (buf[index] == 0x3E) {
found = true;
break;
}
}
}
}
if (found == true) {
len = strlen(string);
cyg_io_write(serial0, string, &len);
}
}
static void blink_led(CYG_ADDRESS data)
{
bool found = false;
while (1) {
if (found == false) {
PIO->PIO_CODR = YELLOW_LED;
found = true;
}
else {
PIO->PIO_SODR = YELLOW_LED;
found = false;
}
cyg_thread_delay(100);
}
}
void cyg_user_start(void)
{
cyg_uint32 data = 0;
cyg_uint32 data_len = sizeof(data);
cyg_tick_count_t new_alarm_trig = 200;
cyg_tick_count_t new_alarm_intv = 3000;
cyg_io_lookup( "/dev/ser0", &serial0 );
#ifdef CYGOPT_IO_SERIAL_SUPPORT_NONBLOCKING
// serial port 0
cyg_io_set_config(serial0, CYG_IO_SET_CONFIG_READ_BLOCKING, &data ,
&data_len);
#endif
cyg_clock_to_counter(cyg_real_time_clock(), &rtc_handle);
cyg_alarm_create(rtc_handle, &my_alarm_func, 1, &my_alarm_handle,
&my_alarm);
cyg_alarm_initialize(my_alarm_handle, new_alarm_trig, new_alarm_intv);
cyg_alarm_enable(my_alarm_handle);
cyg_thread_create(4, blink_led, (cyg_addrword_t) 0, "serial1",
(void *)stack[0], STACKSIZE, &thread[0],
&thread_obj[0]);
cyg_thread_resume(thread[0]);
}
The program hangs when the alarm triggers for the first time and stops in
the alarm function at the while loop.
Can anyone please advice on what is the cause?
Thanks
Stanley
> ____________________________
> This email (including all attachments) contains confidential information
> which may be privileged. It is intended solely for the identified
> recipient(s) to whom it is addressed. If you are not an intended
> recipient, please reply to us immediately and delete this message from
> your system. You may not copy or use it for any purpose, or otherwise
> disclose its contents to any person.
>