Exemple #1
0
void HES::readSensor() {
  int16_t ADC_Low  = 0; // low and high byte of ADC value
  int16_t ADC_High = 0;
  int16_t ADC_Val  = 0; // ADC value reading
  Wire.beginTransmission(SensorAddr);
  Wire.write(hallSensorOutputAddress);
  byte errors = Wire.endTransmission();

  if (errors){
    Serial.print("\tI2C Transmission Error: ");
    Serial.println((int)errors);
  }

  int bytesReceived = Wire.requestFrom(SensorAddr, numBytesPerSensorReading);
  if ((bytesReceived != numBytesPerSensorReading) || (Wire.available() != numBytesPerSensorReading)){
    Serial.print("\tI2C Error: Received ");
    Serial.print(bytesReceived);
    Serial.println(" bytes instead of expected 2");
  }
  if (Wire.available() >= numBytesPerSensorReading) {
    Wire.read();
    Wire.read();
    ADC_High  = Wire.read();
    ADC_Low = Wire.read();
    ADC_Val  = ADC_High << 8;
    ADC_Val |= ADC_Low;
    if (ADC_Val & 0x800){
      ADC_Val |= 0xF800; 
    }
  }
  values[counter] = ADC_Val;
  incr_counter();
  //return ADC_Val;
}
Exemple #2
0
qtperfdata_t* qtperf_iter_next(qtperf_iterator_t** iter){
  qtperfdata_t* data = qtperf_iter_deref(*iter);
  // try to increment the counter. If that fails, try to increment the
  // group. If that also fails, the iterator is finished.
  if(!incr_counter(iter) && !incr_group(iter)){
    (*iter) = qtperf_iter_end();
    return NULL;
  }
  return data;
}
Exemple #3
0
void get_lexeme(char*buf)
{
    int tmplexptr=lexptr;
    int i=0;
    while(tmplexptr!=fwd)
    {
        buf[i]=dbuf[tmplexptr];
        incr_counter(&tmplexptr);
        i++;
    }
    buf[i]='\0';
	lexptr=fwd;
	if(dbuf[lexptr]==EOF)
		incr_lexptr();
}	
Exemple #4
0
void incr_lexptr()
{
	incr_counter(&lexptr);
}
ExpressionVariable *
ExpressionVariable::make_random(CGContext &cg_context, const Type* type, const CVQualifiers* qfer, bool as_param, bool as_return)
{
	DEPTH_GUARD_BY_TYPE_RETURN(dtExpressionVariable, NULL);
	Function *curr_func = cg_context.get_current_func(); 
	FactMgr* fm = get_fact_mgr_for_func(curr_func);
	vector<const Variable*> dummy; 

	// save current effects, in case we need to reset 
	Effect eff_accum = cg_context.get_accum_effect();
	Effect eff_stmt = cg_context.get_effect_stm();
  
	ExpressionVariable *ev = 0;
	do {
		const Variable* var = 0; 
		// try to use one of must_read_vars in CGContext 
		var = VariableSelector::select_must_use_var(Effect::READ, cg_context, type, qfer);  
		if (var == NULL) {
			var = VariableSelector::select(Effect::READ, cg_context, type, qfer, dummy, eFlexible);
		}
		ERROR_GUARD(NULL);
		if (!var) 
			continue;
		if (!type->is_float() && var->type->is_float())
			continue;
		// forbid a parameter to take the address of an argument
		// this is to simplify the path shortcutting delta
		if (as_param && var->is_argument() && var->type->is_dereferenced_from(type)) {
			continue;
		}
		if (!CGOptions::addr_taken_of_locals()
			&& var->type->is_dereferenced_from(type)
			&& (var->is_argument() || var->is_local())) {
			continue;
		}

		// forbid a escaping pointer to take the address of an argument or a local variable
		int indirection = var->type->get_indirect_level() - type->get_indirect_level();
		if (as_return && CGOptions::no_return_dead_ptr() &&
			FactPointTo::is_pointing_to_locals(var, cg_context.get_current_block(), indirection, fm->global_facts)) {
			continue;
		}
		int valid = FactPointTo::opportunistic_validate(var, type, fm->global_facts);
		if (valid) {
			ExpressionVariable tmp(*var, type);
			if (tmp.visit_facts(fm->global_facts, cg_context)) { 
				ev = tmp.get_indirect_level() == 0 ? new ExpressionVariable(*var) : new ExpressionVariable(*var, type); 
				cg_context.curr_blk = cg_context.get_current_block();
				break;
			}  
			else {
				cg_context.reset_effect_accum(eff_accum);
				cg_context.reset_effect_stm(eff_stmt);
			}
		}
		dummy.push_back(var);
	} while (true);

	// statistics
	int deref_level = ev->get_indirect_level();
	if (deref_level > 0) {
		incr_counter(Bookkeeper::read_dereference_cnts, deref_level); 
	}
	if (deref_level < 0) {
		Bookkeeper::record_address_taken(ev->get_var());
	}   
	Bookkeeper::record_volatile_access(ev->get_var(), deref_level, false);
	return ev;
}