Пример #1
0
void RelocIterator::print() {
  RelocIterator save_this = (*this);
  relocInfo* scan = _current;
  if (!has_current())  scan += 1;  // nothing to scan here!

  bool skip_next = has_current();
  bool got_next;
  while (true) {
    got_next = (skip_next || next());
    skip_next = false;

    tty->print("         @" INTPTR_FORMAT ": ", scan);
    relocInfo* newscan = _current+1;
    if (!has_current())  newscan -= 1;  // nothing to scan here!
    while (scan < newscan) {
      tty->print("%04x", *(short*)scan & 0xFFFF);
      scan++;
    }
    tty->cr();

    if (!got_next)  break;
    print_current();
  }

  (*this) = save_this;
}
Пример #2
0
/// exhausted - returns true if the voltage remains below the low_voltage for 10 seconds or remaining capacity falls below min_capacity_mah
bool AP_BattMonitor::exhausted(uint8_t instance, float low_voltage, float min_capacity_mah)
{
    // exit immediately if no monitors setup
    if (_num_instances == 0 || instance >= AP_BATT_MONITOR_MAX_INSTANCES || drivers[instance] == NULL) {
        return false;
    }

    // get current time
    uint32_t tnow = AP_HAL::millis();

    // check voltage
    if ((state[instance].voltage > 0.0f) && (low_voltage > 0) && (state[instance].voltage < low_voltage)) {
        // this is the first time our voltage has dropped below minimum so start timer
        if (state[instance].low_voltage_start_ms == 0) {
            state[instance].low_voltage_start_ms = tnow;
        }else if (tnow - state[instance].low_voltage_start_ms > AP_BATT_LOW_VOLT_TIMEOUT_MS) {
            return true;
        }
    }else{
        // acceptable voltage so reset timer
        state[instance].low_voltage_start_ms = 0;
    }

    // check capacity if current monitoring is enabled
    if (has_current(instance) && (min_capacity_mah>0) && (_pack_capacity[instance] - state[instance].current_total_mah < min_capacity_mah)) {
        return true;
    }

    // if we've gotten this far battery is ok
    return false;
}
 /// exhausted - returns true if the voltage remains below the low_voltage for 10 seconds or remaining capacity falls below min_capacity_mah
bool AP_BattMonitor::exhausted(uint8_t instance, float low_voltage, float min_capacity_mah)
{
    // exit immediately if no monitors setup
    if (_num_instances == 0 || instance >= _num_instances) {
        return false;
    }

    // check voltage
    if ((state[instance].voltage > 0) && (low_voltage > 0) && (state[instance].voltage < low_voltage)) {
        // this is the first time our voltage has dropped below minimum so start timer
        if (state[instance].low_voltage_start_ms == 0) {
            state[instance].low_voltage_start_ms = AP_HAL::millis();
        } else if (_volt_timeout > 0 && AP_HAL::millis() - state[instance].low_voltage_start_ms > uint32_t(_volt_timeout.get())*1000U) {
            return true;
        }
    } else {
        // acceptable voltage so reset timer
        state[instance].low_voltage_start_ms = 0;
    }

    // check capacity if current monitoring is enabled
    if (has_current(instance) && (min_capacity_mah > 0) && (_pack_capacity[instance] - state[instance].current_total_mah < min_capacity_mah)) {
        return true;
    }

    // if we've gotten this far then battery is ok
    return false;
}
Пример #4
0
// read - read the voltage and current
void
AP_BattMonitor_Analog::read()
{
    // this copes with changing the pin at runtime
    _volt_pin_analog_source->set_pin(_params._volt_pin);

    // get voltage
    _state.voltage = _volt_pin_analog_source->voltage_average() * _params._volt_multiplier;

    // read current
    if (has_current()) {
        // calculate time since last current read
        uint32_t tnow = AP_HAL::micros();
        float dt = tnow - _state.last_time_micros;

        // this copes with changing the pin at runtime
        _curr_pin_analog_source->set_pin(_params._curr_pin);

        // read current
        _state.current_amps = (_curr_pin_analog_source->voltage_average()-_params._curr_amp_offset)*_params._curr_amp_per_volt;

        // update total current drawn since startup
        if (_state.last_time_micros != 0 && dt < 2000000.0f) {
            // .0002778 is 1/3600 (conversion to hours)
            float mah = _state.current_amps * dt * 0.0000002778f;
            _state.consumed_mah += mah;
            _state.consumed_wh  += 0.001f * mah * _state.voltage;
        }

        // record time
        _state.last_time_micros = tnow;
    }
}
Пример #5
0
void RelocIterator::initialize(intptr_t delta, CodeBlob* cb, address begin, address limit) {
#ifndef CORE  
  if (cb == NULL && delta == 0 && begin != NULL) {
    // allow CodeBlob to be deduced from beginning address
    cb = CodeCache::find_blob(begin);
  }
  assert(cb != NULL, "must be able to deduce nmethod from other arguments");

  _code    = cb;
  _current = cb->relocation_begin()-1;
  _end     = cb->relocation_end();
  _addr    = (address) cb->instructions_begin();

  assert(!has_current(), "just checking");  
  address code_end = cb->instructions_end();

  assert(begin == NULL || begin >= delta + cb->instructions_begin(), "in bounds");
 // FIX THIS  assert(limit == NULL || limit <= delta + code_end,                 "in bounds");
  if (begin != NULL)  begin -= delta;
  if (limit != NULL)  limit -= delta;
  set_limits(begin, limit);

  // after limits have been set and indexes consulted, then apply the delta
  if (delta == 0) {
    _is_copy = false;
  } else {
    _is_copy = true;
    _addr  += delta;		// we are operating on a copy of the code
    _limit += delta;
  }
#endif // !CORE
}
Пример #6
0
RelocIterator::RelocIterator(CodeBuffer* cb, address begin, address limit) {
#ifndef CORE
  _current = cb->locs_start()-1;
  _end     = cb->locs_end();
  _addr    = (address) cb->code_begin();
  _code    = cb->get_blob();

  assert(!has_current(), "just checking");

  assert(begin == NULL || begin >= cb->code_begin(), "in bounds");
  assert(limit == NULL || limit <= cb->code_end(),   "in bounds");
  set_limits(begin, limit);
#endif // !CORE
}
Пример #7
0
void RelocIterator::print_current() {
  if (!has_current()) {
    tty->print_cr("(no relocs)");
    return;
  }
  tty->print("relocInfo@" INTPTR_FORMAT " [type=%d(%s) addr=" INTPTR_FORMAT,
	     _current, type(), reloc_type_string((relocInfo::relocType) type()), _addr);
  if (current()->format() != 0)
    tty->print(" format=%d", current()->format());
  if (datalen() == 1) {
    tty->print(" data=%d", data()[0]);
  } else if (datalen() > 0) {
    tty->print(" data={");
    for (int i = 0; i < datalen(); i++) {
      tty->print("%04x", data()[i] & 0xFFFF);
    }
    tty->print("}");
  }
  tty->print("]");
  switch (type()) {
  case relocInfo::oop_type:
    {
      oop_Relocation* r = oop_reloc();
      oop* oop_addr  = NULL;
      oop  raw_oop   = NULL;
      oop  oop_value = NULL;
      if (code() != NULL || r->oop_index() == 0) {
	oop_addr  = r->oop_addr();
	raw_oop   = *oop_addr;
	oop_value = r->oop_value();
      }
      tty->print_cr(" | [oop_addr=" INTPTR_FORMAT " *=" INTPTR_FORMAT " offset=%d]",
		    oop_addr, raw_oop, r->offset());
      // Do not print the oop by default--we want this routine to
      // work even during GC or other inconvenient times.
      if (WizardMode && oop_value != NULL) {
	tty->print("oop_value=" INTPTR_FORMAT ": ", oop_value);
	oop_value->print_value_on(tty);
      }
      break;
    }
  case relocInfo::external_word_type:
  case relocInfo::internal_word_type:
    {
      DataRelocation* r = (DataRelocation*) reloc();
      tty->print(" | [target=" INTPTR_FORMAT "]", r->value()); //value==target
      break;
    }
  case relocInfo::static_call_type:
  case relocInfo::runtime_call_type:
  case relocInfo::jsr_type:
    {
      CallRelocation* r = (CallRelocation*) reloc();
      tty->print(" | [destination=" INTPTR_FORMAT "]", r->destination());
      break;
    }
  case relocInfo::virtual_call_type:
    {
      virtual_call_Relocation* r = (virtual_call_Relocation*) reloc();
      tty->print(" | [destination=" INTPTR_FORMAT " first_oop=" INTPTR_FORMAT " oop_limit=" INTPTR_FORMAT "]",
		 r->destination(), r->first_oop(), r->oop_limit());
      break;
    }
  case relocInfo::static_stub_type:
    {
      static_stub_Relocation* r = (static_stub_Relocation*) reloc();
      tty->print(" | [static_call=" INTPTR_FORMAT "]", r->static_call());
      break;
    }
  }
  tty->cr();
}