首页 > 其他分享 >温度控制

温度控制

时间:2023-08-11 18:35:57浏览次数:36  
标签:info 温度控制 temp ctrl fan cpld ptr

void fan_speed_control(void)
{
    temp_range_t *temp_range_ptr = board_device_temp_info_get();
    fan_cpld_t *fan_cpld_ptr = board_fan_cpld_info_get();
    if (temp_range_ptr == NULL || fan_cpld_ptr == NULL)
    {
        return;
    }

    fan_temp_get();
#if 0
    if (fan_overt_temp_recovery())
    {
        return;
    }
#endif

    for (uint8_t i = 0; i < TEMP_MAX; i++)
    {
        if (fan_ctrl_info[i].temp == 0)
        {
            continue;
        }
        // temp >= overt
        if ((fan_ctrl_info[i].temp >= temp_range_ptr[i].overt) && (i != TEMP_OPT))
        {
            // power off, keep max level
            cpld_assert_set(ASSERT);
            fan_cpld_ptr->level = FAN_LEVEL_MAX;
            fan_level_write(fan_cpld_ptr->level);
            if (CAT_NUM_BIT(temp_overt_flag, i) == 0)
            {
                log_write(LOG_WARRING, "%s(%d)overt,pwroff",
                          fan_ctrl_info[i].name, fan_ctrl_info[i].temp);
                DBG("%s(%d) overt,poweroff",
                    fan_ctrl_info[i].name, fan_ctrl_info[i].temp);
                fan_ctrl_info[i].overt_f++;
            }

            if (fan_ctrl_info[i].overt_f > 3)
            {

                SET_NUM_BIT(temp_overt_flag, i); // set flag, sys_led red on
                led_stat_msg_update(SYS_TEMP_OVERT, true);
                // clear uart receive temp
                OPTTemp(0);
            }
            continue;
        }

        fan_ctrl_info[i].overt_f = 0;

        // temp >= alert
        if (fan_ctrl_info[i].temp >= temp_range_ptr[i].alert)
        {
            if (fan_auto_ctrl_read())
            {
                fan_cpld_ptr->level = FAN_LEVEL_MAX;
                fan_level_write(fan_cpld_ptr->level);
            }

            if (CAT_NUM_BIT(temp_alert_flag, i) == 0)
            {
                log_write(LOG_WARRING, "%s(%d)alert",
                          fan_ctrl_info[i].name, fan_ctrl_info[i].temp);
                DBG("%s(%d) alert",
                    fan_ctrl_info[i].name, fan_ctrl_info[i].temp);
            }

            RESET_NUM_BIT(temp_overt_flag, i);
            SET_NUM_BIT(temp_alert_flag, i);

            // set alert flag, keep sys_led blink
            if (temp_overt_flag == 0)
            {
                led_stat_msg_update(SYS_TEMP_OVERT, false);
            }
            led_stat_msg_update(SYS_TEMP_ALERT, true);

            continue;
        }

        // clear flag
        RESET_NUM_BIT(temp_alert_flag, i);
        if (temp_alert_flag == 0)
        {
            led_stat_msg_update(SYS_TEMP_ALERT, false);
        }

        // close fan auto control
        if (fan_auto_ctrl_read() == false)
        {
            continue;
        }

        // temp >= upper
        if (fan_ctrl_info[i].temp >= temp_range_ptr[i].upper)
        {
            fan_ctrl_info[i].count_h++;
            if (fan_ctrl_info[i].count_h > FAN_TEMP_KEEP_TIME)
            {
                fan_ctrl_info[i].count_h = 0;
                fan_cpld_ptr->level += FAN_CTRL_LEVEL_NUM;
                fan_level_write(fan_cpld_ptr->level);
            }
            continue;
        }

        // temp <= lower
        if (fan_ctrl_info[i].temp < temp_range_ptr[i].lower)
        {
            fan_ctrl_info[i].count_l++;
            if (fan_ctrl_info[i].count_l > FAN_TEMP_KEEP_TIME)
            {
                fan_ctrl_info[i].count_l = 0;
                fan_cpld_ptr->level -= FAN_CTRL_LEVEL_NUM;
                fan_level_write(fan_cpld_ptr->level);
            }
            continue;
        }

        // clear count
        fan_ctrl_info[i].count_l = 0;
        fan_ctrl_info[i].count_h = 0;
    }
}



标签:info,温度控制,temp,ctrl,fan,cpld,ptr
From: https://www.cnblogs.com/YTZt/p/17623695.html

相关文章