OpenBIC
OpenSource Bridge-IC
plat_fsc.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef PLAT_FSC_H
18#define PLAT_FSC_H
19#include "stdio.h"
20#include "stdint.h"
21#include "stdbool.h"
22
23#define FSC_TEMP_INVALID 0x8000
24#define FSC_RPM_INVALID 0xFFFF
25
26#define FSC_ENABLE 1
27#define FSC_DISABLE 0
28
29#define SENSOR_STEPWISE_STEPS_MAX 16
30
32 FSC_ERROR_NONE = 0, // OK status
39};
40
47};
48
51 FSC_MODE_AUTO_MODE, // include auto tune
54};
55
56/* stepwise */
57typedef struct {
58 uint8_t temp;
59 uint8_t duty;
61
62typedef struct {
63 uint8_t sensor_num;
65 uint8_t pos_hyst; // positive_hysteresis
66 uint8_t neg_hyst; // negative_hysteresis
67
68 // calculate use
69 int16_t last_temp;
71
72/* pid */
73typedef struct {
74 uint8_t sensor_num;
76 /*uint8_t setpoint_type;*/
77 float kp;
78 float ki;
79 float kd;
80 int16_t i_limit_min; // RPM
81 int16_t i_limit_max; // RPM
82 uint8_t pos_hyst; // positive_hysteresis
83 uint8_t neg_hyst; // negative_hysteresis
84
85 // calculate use
86 float integral;
87 int last_error; //for kd
88 int16_t last_temp;
89} pid_cfg;
90
91/* zone control */
92typedef struct {
93 uint8_t sensor_num;
94 uint8_t type; // stepwise or pid
96
97typedef struct {
99 uint8_t sw_tbl_num;
100
102 uint8_t pid_tbl_num;
103
104 uint8_t out_limit_min; // Duty
105 uint8_t out_limit_max; // Duty
106 uint16_t slew_neg; // RPM
107 uint16_t slew_pos; // RPM
108 uint8_t interval; // sec
109
110 uint8_t (*set_duty)(uint8_t, uint8_t); // set duty function
111 uint8_t set_duty_arg; // set_duty arg
112
113 // calculate use
115 uint8_t last_duty;
116 uint8_t is_init;
117} zone_cfg;
118
119uint8_t get_fsc_enable_flag(void);
120void set_fsc_enable_flag(uint8_t flag);
121void set_fsc_tbl_enable(uint8_t flag);
122void fsc_init(void);
123void controlFSC(uint8_t action);
124uint8_t fsc_debug_set(uint8_t enable);
125uint8_t fsc_debug_get(void);
126uint8_t get_fsc_setpoint(uint8_t idx);
127void set_fsc_setpoint(uint8_t idx, uint8_t val);
128void change_lpm_setpoint(uint8_t onoff);
129void change_temp_setpoint(uint8_t onoff);
130
131#endif
uint8_t idx
Definition: plat_util.c:39
uint32_t val
Definition: plat_util.c:40
void change_temp_setpoint(uint8_t onoff)
Definition: plat_fsc.c:289
void fsc_init(void)
Definition: plat_fsc.c:389
FSC_ERROR
Definition: plat_fsc.h:31
@ FSC_ERROR_NOT_FOUND_PID_TABLE
Definition: plat_fsc.h:37
@ FSC_ERROR_NOT_FOUND_STEPWISE_TABLE
Definition: plat_fsc.h:36
@ FSC_ERROR_UNKNOW
Definition: plat_fsc.h:33
@ FSC_ERROR_NOT_FOUND_ZONE_TABLE
Definition: plat_fsc.h:35
@ FSC_ERROR_NONE
Definition: plat_fsc.h:32
@ FSC_ERROR_OUT_OF_RANGE
Definition: plat_fsc.h:34
@ FSC_ERROR_NULL_ARG
Definition: plat_fsc.h:38
void set_fsc_setpoint(uint8_t idx, uint8_t val)
Definition: plat_fsc.c:69
uint8_t get_fsc_enable_flag(void)
Definition: plat_fsc.c:43
FSC_TYPE
Definition: plat_fsc.h:41
@ FSC_TYPE_STEPWISE
Definition: plat_fsc.h:43
@ FSC_TYPE_DEFAULT
Definition: plat_fsc.h:46
@ FSC_TYPE_BOTH
Definition: plat_fsc.h:45
@ FSC_TYPE_DISABLE
Definition: plat_fsc.h:42
@ FSC_TYPE_PID
Definition: plat_fsc.h:44
uint8_t get_fsc_setpoint(uint8_t idx)
Definition: plat_fsc.c:62
void set_fsc_enable_flag(uint8_t flag)
Definition: plat_fsc.c:48
void change_lpm_setpoint(uint8_t onoff)
Definition: plat_fsc.c:272
void controlFSC(uint8_t action)
Function to control the FSC thread.
Definition: plat_fsc.c:302
uint8_t fsc_debug_get(void)
Definition: plat_fsc.c:38
FSC_MODE_E
Definition: plat_fsc.h:49
@ FSC_MODE_MANUAL_MODE
Definition: plat_fsc.h:52
@ FSC_MODE_AUTO_MODE
Definition: plat_fsc.h:51
@ FSC_MODE_UNKNOW
Definition: plat_fsc.h:50
@ FSC_MODE_SEMI_MODE
Definition: plat_fsc.h:53
void set_fsc_tbl_enable(uint8_t flag)
Definition: plat_fsc.c:57
uint8_t fsc_debug_set(uint8_t enable)
Definition: plat_fsc.c:32
#define SENSOR_STEPWISE_STEPS_MAX
Definition: plat_fsc.h:29
Definition: plat_fsc.h:92
uint8_t sensor_num
Definition: plat_fsc.h:93
uint8_t type
Definition: plat_fsc.h:94
Definition: plat_fsc.h:73
float ki
Definition: plat_fsc.h:78
int16_t i_limit_min
Definition: plat_fsc.h:80
float kp
Definition: plat_fsc.h:77
float integral
Definition: plat_fsc.h:86
uint8_t neg_hyst
Definition: plat_fsc.h:83
int setpoint
Definition: plat_fsc.h:75
float kd
Definition: plat_fsc.h:79
int last_error
Definition: plat_fsc.h:87
uint8_t pos_hyst
Definition: plat_fsc.h:82
int16_t i_limit_max
Definition: plat_fsc.h:81
int16_t last_temp
Definition: plat_fsc.h:88
uint8_t sensor_num
Definition: plat_fsc.h:74
Definition: plat_fsc.h:62
int16_t last_temp
Definition: plat_fsc.h:69
uint8_t pos_hyst
Definition: plat_fsc.h:65
uint8_t neg_hyst
Definition: plat_fsc.h:66
uint8_t sensor_num
Definition: plat_fsc.h:63
Definition: plat_fsc.h:57
uint8_t temp
Definition: plat_fsc.h:58
uint8_t duty
Definition: plat_fsc.h:59
Definition: plat_fsc.h:97
uint8_t last_duty
Definition: plat_fsc.h:115
uint8_t set_duty_arg
Definition: plat_fsc.h:111
uint16_t slew_pos
Definition: plat_fsc.h:107
uint8_t pid_tbl_num
Definition: plat_fsc.h:102
uint8_t out_limit_max
Definition: plat_fsc.h:105
uint8_t out_limit_min
Definition: plat_fsc.h:104
uint16_t fsc_poll_count
Definition: plat_fsc.h:114
uint16_t slew_neg
Definition: plat_fsc.h:106
uint8_t sw_tbl_num
Definition: plat_fsc.h:99
stepwise_cfg * sw_tbl
Definition: plat_fsc.h:98
uint8_t interval
Definition: plat_fsc.h:108
uint8_t is_init
Definition: plat_fsc.h:116
pid_cfg * pid_tbl
Definition: plat_fsc.h:101