[ECOS] Getting battery status on ipaq

Cristiano Ligieri Pereira cpereira@ics.uci.edu
Wed Oct 3 15:43:00 GMT 2001


Hi folks,

I'm attaching my code to get battery status from amtel controller in the
compaq ipaq. The code seems to work fine when there is no
cyg_thread_delay() called in thread code. When there is a function call to
cyg_thread_delay() it only works once and I don't get any answer from the
controller and the system seems to freeze after that.

The code seems correct to me. Can anyone guess what's the problem if I
call cyg_thread_delay()?

-----------------------------------------------------------------------------

static unsigned char *data;
static volatile cyg_uint8 received = 0;

static void batt_status_ack(atmel_pkt *pkt)
{
  int i;

  data = &pkt->data[1];
  received = 1;
}

cyg_uint8 get_batt_status(batt_device_t *batt_dev)
{
  static int count;
  atmel_register(ATMEL_CMD_BATTERY, batt_status_ack);

  atmel_interrupt_mode(1);
  atmel_send(ATMEL_CMD_BATTERY, NULL, 0);
  count = 0;
  while ( !received && count < 100 ) {
    count++;
    hal_delay_us(10);
  }

  if (received) {
    batt_dev->ac_status = (enum ipaq_battery_ac_status)data[0];
    batt_dev->batt1_chemistry = (enum ipaq_battery_chemistry)data[1];
    batt_dev->batt1_voltage = ((short)((data[3] << 8) | data[2]));
    batt_dev->batt1_status = (enum ipaq_battery_status)data[4];
    batt_dev->batt2_chemistry = 0;
    batt_dev->batt2_voltage = 0;
    batt_dev->batt2_status = 0;
    received = 0;
    return 1;
    return 1;
  }
  else {
    return 0;
  }
}

-----------------------------------------------------------------------------

thanks,
Cristiano.

------------------------------------------------------------
Cristiano Ligieri Pereira - http://www.ics.uci.edu/~cpereira



More information about the Ecos-discuss mailing list