int main(void) { signed int fridgeTemp; signed int freezeTemp; signed int defrostTemp; signed int fridgePro; network_control(ENABLE); iomod_backlight(ON); /* Initialize servo and temperature sensor ports */ DDRB = 0x0F; PORTB = 0x00; set_bit(DDRD, 2); clear_bit(PORTD, 2); /* Set up .01 sec timer */ TCCR0A = (2 << WGM00); TCCR0B = (5 << CS00); TIMSK0 = (1 << OCIE0A); OCR0A = 195; sei(); //fridgeTemp = -5; //freezeTemp = -18; while(1) { /* Check tempreture in fridge and freezer */ fridgeTemp = temp_sensor_read(FRIDGE_SENSE, TEMPERATURE); freezeTemp = temp_sensor_read(FREEZE_SENSE, TEMPERATURE); // defrostTemp = temp_sensor_read(DEFROST_SENSE, TEMPERATURE); /* Control freezer */ if (freezeTemp > (freezerSet + FREEZE_RANGE)) compressor(ON); else if (freezeTemp < (freezerSet - FREEZE_RANGE)) compressor(OFF); /* Control refridgerator */ fridgePro = ((fridgeTemp - fridgeSet) * 100) / FRIDGE_RANGE; if (fridgePro > 100) fridgePro = 100; if (fridgePro < -100) fridgePro = -100; damper_control(1200 + (fridgePro * 4)); /* Display information on LCD */ iomod_text(FIRST_LINE, "FD:"); iomod_signed(FIRST_LINE+3, fridgeTemp, 2); iomod_text(SECOND_LINE, "FZ:"); iomod_signed(SECOND_LINE+3, freezeTemp, 2); // iomod_text(SECOND_LINE+6, "FZ:"); // iomod_signed(SECOND_LINE+9, defrostTemp, 2); } }
int main(void) { uint16_t send_temp_counter = 0; init(); // system initialization while (1) { can_handler(); do_ani(); if (tickscounter > 10) { tickscounter = 0; switch_handler(); #ifndef NO_NETVAR netvar_handle_events(); #endif send_temp_counter++; if (send_temp_counter > 1000) { temp_sensor_read(); send_temp_counter = 0; } //motion_tick(); } wdt_reset(); } }
static void thermal_control(void) { int i, j, t, rv, f; int count_over[EC_TEMP_THRESH_COUNT]; int count_under[EC_TEMP_THRESH_COUNT]; int num_valid_limits[EC_TEMP_THRESH_COUNT]; int num_sensors_read; int fmax; int dptf_tripped; int temp_fan_configured; /* Get ready to count things */ memset(count_over, 0, sizeof(count_over)); memset(count_under, 0, sizeof(count_under)); memset(num_valid_limits, 0, sizeof(num_valid_limits)); num_sensors_read = 0; fmax = 0; dptf_tripped = 0; temp_fan_configured = 0; /* go through all the sensors */ for (i = 0; i < TEMP_SENSOR_COUNT; ++i) { /* read one */ rv = temp_sensor_read(i, &t); if (rv != EC_SUCCESS) continue; else num_sensors_read++; /* check all the limits */ for (j = 0; j < EC_TEMP_THRESH_COUNT; j++) { int limit = thermal_params[i].temp_host[j]; if (limit) { num_valid_limits[j]++; if (t > limit) count_over[j]++; else if (t < limit) count_under[j]++; } } /* figure out the max fan needed, too */ if (thermal_params[i].temp_fan_off && thermal_params[i].temp_fan_max) { f = thermal_fan_percent(thermal_params[i].temp_fan_off, thermal_params[i].temp_fan_max, t); if (f > fmax) fmax = f; temp_fan_configured = 1; } /* and check the dptf thresholds */ dptf_tripped |= dpft_check_temp_threshold(i, t); } if (!num_sensors_read) { /* * Trigger a SMI event if we can't read any sensors. * * In theory we could do something more elaborate like forcing * the system to shut down if no sensors are available after * several retries. This is a very unlikely scenario - * particularly on LM4-based boards, since the LM4 has its own * internal temp sensor. It's most likely to occur during * bringup of a new board, where we haven't debugged the I2C * bus to the sensors; forcing a shutdown in that case would * merely hamper board bringup. */ smi_sensor_failure_warning(); return; } /* See what the aggregated limits are. Any temp over the limit * means it's hot, but all temps have to be under the limit to * be cool again. */ for (j = 0; j < EC_TEMP_THRESH_COUNT; j++) { if (count_over[j]) cond_set_true(&cond_hot[j]); else if (count_under[j] == num_valid_limits[j]) cond_set_false(&cond_hot[j]); } /* What do we do about it? (note hard-coded logic). */ if (cond_went_true(&cond_hot[EC_TEMP_THRESH_HALT])) { CPRINTS("thermal SHUTDOWN"); chipset_force_shutdown(); } else if (cond_went_false(&cond_hot[EC_TEMP_THRESH_HALT])) { /* We don't reboot automatically - the user has to push * the power button. It's likely that we can't even * detect this sensor transition until then, but we * do have to check in order to clear the cond_t. */ CPRINTS("thermal no longer shutdown"); } if (cond_went_true(&cond_hot[EC_TEMP_THRESH_HIGH])) { CPRINTS("thermal HIGH"); throttle_ap(THROTTLE_ON, THROTTLE_HARD, THROTTLE_SRC_THERMAL); } else if (cond_went_false(&cond_hot[EC_TEMP_THRESH_HIGH])) { CPRINTS("thermal no longer high"); throttle_ap(THROTTLE_OFF, THROTTLE_HARD, THROTTLE_SRC_THERMAL); } if (cond_went_true(&cond_hot[EC_TEMP_THRESH_WARN])) { CPRINTS("thermal WARN"); throttle_ap(THROTTLE_ON, THROTTLE_SOFT, THROTTLE_SRC_THERMAL); } else if (cond_went_false(&cond_hot[EC_TEMP_THRESH_WARN])) { CPRINTS("thermal no longer warn"); throttle_ap(THROTTLE_OFF, THROTTLE_SOFT, THROTTLE_SRC_THERMAL); } if (temp_fan_configured) { #ifdef CONFIG_FANS /* TODO(crosbug.com/p/23797): For now, we just treat all fans the * same. It would be better if we could assign different thermal * profiles to each fan - in case one fan cools the CPU while another * cools the radios or battery. */ for (i = 0; i < CONFIG_FANS; i++) fan_set_percent_needed(i, fmax); #endif } /* Don't forget to signal any DPTF thresholds */ if (dptf_tripped) host_set_single_event(EC_HOST_EVENT_THERMAL_THRESHOLD); }