diff --git a/docs/uDCCD_Controller_R9V1_Schematic.PDF b/docs/uDCCD_Controller_R9V1_Schematic.PDF new file mode 100644 index 0000000..3d8c63f Binary files /dev/null and b/docs/uDCCD_Controller_R9V1_Schematic.PDF differ diff --git a/firmware/src/bsp/ain.cpp b/firmware/src/bsp/ain.cpp new file mode 100644 index 0000000..bfaac3b --- /dev/null +++ b/firmware/src/bsp/ain.cpp @@ -0,0 +1,45 @@ +/**** Includes ****/ +#include "../utils/utils.h" +#include "mcu/mcu_hal.h" +#include "ain.h" + +using namespace bsp; + +/**** Private definitions ****/ +/**** Private constants ****/ +/**** Private variables ****/ +/**** Private function declarations ****/ +/**** Public function definitions ****/ +bsp::AnalogIn::AnalogIn(void) +{ + return; +} + +bsp::AnalogIn::~AnalogIn(void) +{ + return; +} + +void bsp::AnalogIn::init(uint8_t adc_ch) +{ + this->adc_ch = adc_ch; + this->mul = DEF_AIN_MUL; + this->div = DEF_AIN_DIV; + this->offset = DEF_AIN_OFFSET; + this->last_read = 0; +} + + +uint16_t bsp::AnalogIn::read(void) +{ + //Read ADC + uint16_t raw = mcu::adc_read(this->adc_ch); + + //Convert to mV + this->last_read = util::convert_muldivoff(raw, this->mul, this->div, this->offset); + + return this->last_read; +} + +/**** Private function definitions ****/ + diff --git a/firmware/src/bsp/ain.h b/firmware/src/bsp/ain.h new file mode 100644 index 0000000..75e8eb0 --- /dev/null +++ b/firmware/src/bsp/ain.h @@ -0,0 +1,42 @@ +#ifndef ANALOG_IN_H_ +#define ANALOG_IN_H_ + +/**** Includes ****/ +#include + +namespace bsp { + +/**** Public definitions ****/ +static const uint8_t DEF_AIN_MUL = 215; +static const uint8_t DEF_AIN_DIV = 44; +static const int16_t DEF_AIN_OFFSET = 0; + +class AnalogIn +{ + public: + AnalogIn(void); + ~AnalogIn(void); + + void init(uint8_t adc_ch); + + uint8_t mul; + uint8_t div; + int16_t offset; + uint16_t last_read; + + uint16_t read(void); + + #ifndef TESTING + protected: + #endif + uint8_t adc_ch; +}; + +/**** Public function declarations ****/ + +#ifdef TESTING +#endif + +} //namespace + +#endif /* ANALOG_IN_H_ */ \ No newline at end of file diff --git a/firmware/src/bsp/ain_lpf.cpp b/firmware/src/bsp/ain_lpf.cpp new file mode 100644 index 0000000..a24f491 --- /dev/null +++ b/firmware/src/bsp/ain_lpf.cpp @@ -0,0 +1,52 @@ +/**** Includes ****/ +#include "../utils/utils.h" +#include "mcu/mcu_hal.h" +#include "ain_lpf.h" + +using namespace bsp; + +/**** Private definitions ****/ +/**** Private constants ****/ +/**** Private variables ****/ +/**** Private function declarations ****/ +/**** Public function definitions ****/ +bsp::AnalogInLfp::AnalogInLfp(void) +{ + return; +} + +bsp::AnalogInLfp::~AnalogInLfp(void) +{ + return; +} + +void bsp::AnalogInLfp::init(uint8_t adc_ch) +{ + this->adc_ch = adc_ch; + this->mul = DEF_AIN_MUL; + this->div = DEF_AIN_DIV; + this->offset = DEF_AIN_OFFSET; + this->strength = 0; + this->last_read = 0; + this->last_read_direct = 0; +} + +uint16_t bsp::AnalogInLfp::read(void) +{ + //Read ADC + uint16_t raw = mcu::adc_read(this->adc_ch); + + //Convert to mV + this->last_read_direct = util::convert_muldivoff(raw, this->mul, this->div, this->offset); + + // Do filtering + uint32_t td0 = ((uint32_t)(255 - this->strength) * this->last_read_direct); + uint32_t td1 = ((uint32_t)(this->strength) * this->last_read); + uint32_t out = (td0 + td1)/255; + + this->last_read = util::sat_cast(out); + + return this->last_read; +} + +/**** Private function definitions ****/ diff --git a/firmware/src/bsp/ain_lpf.h b/firmware/src/bsp/ain_lpf.h new file mode 100644 index 0000000..6a6609f --- /dev/null +++ b/firmware/src/bsp/ain_lpf.h @@ -0,0 +1,36 @@ +#ifndef ANALOG_IN_LPF_H_ +#define ANALOG_IN_LPF_H_ + +/**** Includes ****/ +#include +#include "ain.h" + +namespace bsp { + +/**** Public definitions ****/ +class AnalogInLfp : public AnalogIn +{ + public: + // New stuff + AnalogInLfp(void); + ~AnalogInLfp(void); + + void init(uint8_t adc_ch); + uint16_t read(void); + + uint8_t strength; + uint16_t last_read_direct; + + #ifndef TESTING + protected: + #endif +}; + +/**** Public function declarations ****/ + +#ifdef TESTING +#endif + +} //namespace + +#endif /* ANALOG_IN_LPF_H_ */ \ No newline at end of file diff --git a/firmware/src/bsp/board.cpp b/firmware/src/bsp/board.cpp new file mode 100644 index 0000000..7440429 --- /dev/null +++ b/firmware/src/bsp/board.cpp @@ -0,0 +1,108 @@ +/**** Includes ****/ +#include "../utils/utils.h" +#include "mcu/mcu_hal.h" +#include "board.h" + +using namespace bsp; + +/**** Private definitions ****/ +/**** Private constants ****/ +/**** Private variables ****/ +/**** Private function declarations ****/ +/**** Public function definitions ****/ +bsp::Board::Board(void) +{ + return; +} + +bsp::Board::~Board(void) +{ + return; +} + +void bsp::Board::init(boardCfg_t* cfg) +{ + // Calculate settings + + // Controller setup + mcu::startupCfg_t mcu_cfg; + + mcu_cfg.adc_clk = mcu::ADC_DIV64; // 8MHz/64=125kHz + mcu_cfg.pwm_clk = mcu::TIM_DIV1; // 8MHz/1 = 8MHz + mcu_cfg.pwm_top = 4000/(uint16_t)cfg->pwm_f_khz; + mcu_cfg.od_common_is_pwm = cfg->od_common_is_pwm; + + mcu::startup(&mcu_cfg); + + // Analog inputs + this->out_voltage.init(mcu::ADC_VOUT); + this->out_voltage.mul = 20; + this->out_voltage.div = 1; + this->out_voltage.offset = 0; + + this->out_current.init(mcu::ADC_IOUT); + this->out_current.mul = 215; + this->out_current.div = 22; + this->out_current.offset = 0; + + this->battery_voltage.init(mcu::ADC_VBAT); + this->battery_voltage.mul = 20; + this->battery_voltage.div = 1; + this->battery_voltage.offset = 0; + + this->battery_current.init(mcu::ADC_IBAT); + this->battery_current.mul = 235; + this->battery_current.div = 6; + this->battery_current.offset = 0; + + this->ain1.init(mcu::ADC_AIN1); + this->ain2.init(mcu::ADC_AIN2); + + // Digital inputs + this->din1.init(mcu::GPIO_DIN1, 0); + this->din2.init(mcu::GPIO_DIN2, 0); + this->din3.init(mcu::GPIO_DIN3, 0); + this->din4.init(mcu::GPIO_DIN4, 0); + this->hvdin1.init(mcu::GPIO_HVDIN1, 1); + this->hvdin2.init(mcu::GPIO_HVDIN2, 1); + this->hvdin3.init(mcu::GPIO_HVDIN3, 1); + + this->hvdin3_pull.init(mcu::GPIO_HVDIN3_PULL, 0); + this->freq_pull.init(mcu::GPIO_FREQ_PULL, 0); + + // Open-drain outputs + this->od1.init(mcu::GPIO_OD1, 1); + this->od2.init(mcu::GPIO_OD2, 1); + this->od3.init(mcu::GPIO_OD3, 1); + this->od4.init(mcu::GPIO_OD4, 1); + this->od5.init(mcu::GPIO_OD5, 1); + this->od6.init(mcu::GPIO_OD6, 1); + this->od_pwm.init(mcu::PWM_OD, 100); + + // PWM driver output + this->out_pwm.init(mcu::PWM_OUT, 95); + this->out_low.init(mcu::GPIO_OUT_LOW, 0); +} + +void bsp::Board::read(void) +{ + // Update all analog inputs + this->out_voltage.read(); + this->out_current.read(); + this->battery_voltage.read(); + this->battery_current.read(); + this->ain1.read(); + this->ain2.read(); + + // Update all digital inputs + this->din1.read(); + this->din2.read(); + this->din3.read(); + this->din4.read(); + this->hvdin1.read(); + this->hvdin2.read(); + this->hvdin3.read(); +} + +/**** Private function definitions ****/ + diff --git a/firmware/src/bsp/board.h b/firmware/src/bsp/board.h new file mode 100644 index 0000000..97a5d9d --- /dev/null +++ b/firmware/src/bsp/board.h @@ -0,0 +1,75 @@ +#ifndef UDCCD_BOARD_H_ +#define UDCCD_BOARD_H_ + +/**** Includes ****/ +#include + +#include "ain.h" +#include "ain_lpf.h" +#include "din.h" +#include "dout.h" +#include "pwm_out.h" +#include "memory.h" + +namespace bsp { + +/**** Public definitions ****/ +class Board +{ + public: + typedef struct { + uint8_t pwm_f_khz; + uint8_t od_common_is_pwm; + } boardCfg_t; + + Board(void); + ~Board(void); + + void init(boardCfg_t* cfg); + + AnalogIn out_voltage; + AnalogIn out_current; + AnalogIn battery_voltage; + AnalogIn battery_current; + AnalogIn ain1; + AnalogIn ain2; + + DigitalIn din1; + DigitalIn din2; + DigitalIn din3; + DigitalIn din4; + DigitalIn hvdin1; + DigitalIn hvdin2; + DigitalIn hvdin3; + + DigitalOut hvdin3_pull; + DigitalOut freq_pull; + + DigitalOut od1; + DigitalOut od2; + DigitalOut od3; + DigitalOut od4; + DigitalOut od5; + DigitalOut od6; + PwmOut od_pwm; + + PwmOut out_pwm; + DigitalOut out_low; + + Memory nvmem; + + void read(void); + + #ifndef TESTING + protected: + #endif +}; + +/**** Public function declarations ****/ + +#ifdef TESTING +#endif + +} //namespace + +#endif /* UDCCD_BOARD_H_ */ \ No newline at end of file diff --git a/firmware/src/bsp/din.cpp b/firmware/src/bsp/din.cpp new file mode 100644 index 0000000..dd9b953 --- /dev/null +++ b/firmware/src/bsp/din.cpp @@ -0,0 +1,48 @@ +/**** Includes ****/ +#include "../utils/utils.h" +#include "mcu/mcu_hal.h" +#include "din.h" + +using namespace bsp; + +/**** Private definitions ****/ +/**** Private constants ****/ +/**** Private variables ****/ +/**** Private function declarations ****/ +/**** Public function definitions ****/ +bsp::DigitalIn::DigitalIn(void) +{ + return; +} + +bsp::DigitalIn::~DigitalIn(void) +{ + return; +} + +void bsp::DigitalIn::init(uint8_t gpio_ch, uint8_t inverted) +{ + this->gpio_ch = gpio_ch; + if(inverted == 0) this->is_inverted = 0; + else this->is_inverted = 1; + this->last_read = 0; +} + + +uint8_t bsp::DigitalIn::read(void) +{ + // Read ADC + this->last_read = mcu::gpio_read(this->gpio_ch); + + // Invert if necessary + if(this->is_inverted) + { + if(this->last_read==0) this->last_read = 1; + else this->last_read = 0; + }; + + return this->last_read; +} + +/**** Private function definitions ****/ + diff --git a/firmware/src/bsp/din.h b/firmware/src/bsp/din.h new file mode 100644 index 0000000..af0080d --- /dev/null +++ b/firmware/src/bsp/din.h @@ -0,0 +1,36 @@ +#ifndef DIGITAL_IN_H_ +#define DIGITAL_IN_H_ + +/**** Includes ****/ +#include + +namespace bsp { + +/**** Public definitions ****/ +class DigitalIn +{ + public: + DigitalIn(void); + ~DigitalIn(void); + + void init(uint8_t gpio_ch, uint8_t inverted); + + uint8_t last_read; + + uint8_t read(void); + + #ifndef TESTING + protected: + #endif + uint8_t gpio_ch; + uint8_t is_inverted; +}; + +/**** Public function declarations ****/ + +#ifdef TESTING +#endif + +} //namespace + +#endif /* DIGITAL_IN_H_ */ \ No newline at end of file diff --git a/firmware/src/bsp/dout.cpp b/firmware/src/bsp/dout.cpp new file mode 100644 index 0000000..cdb7f07 --- /dev/null +++ b/firmware/src/bsp/dout.cpp @@ -0,0 +1,37 @@ +/**** Includes ****/ +#include "../utils/utils.h" +#include "mcu/mcu_hal.h" +#include "dout.h" + +using namespace bsp; + +/**** Private definitions ****/ +/**** Private constants ****/ +/**** Private variables ****/ +/**** Private function declarations ****/ +/**** Public function definitions ****/ +bsp::DigitalOut::DigitalOut(void) +{ + return; +} + +bsp::DigitalOut::~DigitalOut(void) +{ + return; +} + +void bsp::DigitalOut::write(int8_t level) +{ + if(this->is_inverted) + { + if(level==0) level = 1; + else if (level > 0) level = 0; + }; + + mcu::gpio_write(this->gpio_ch, level); + + this->last_writen = level; +} + +/**** Private function definitions ****/ + diff --git a/firmware/src/bsp/dout.h b/firmware/src/bsp/dout.h new file mode 100644 index 0000000..36e8d98 --- /dev/null +++ b/firmware/src/bsp/dout.h @@ -0,0 +1,34 @@ +#ifndef DIGITAL_OUT_H_ +#define DIGITAL_OUT_H_ + +/**** Includes ****/ +#include +#include "din.h" + +namespace bsp { + +/**** Public definitions ****/ +class DigitalOut : public DigitalIn +{ + public: + // New or redefined stuff + DigitalOut(void); + ~DigitalOut(void); + + int8_t last_writen; + + void write(int8_t level); + + #ifndef TESTING + protected: + #endif +}; + +/**** Public function declarations ****/ + +#ifdef TESTING +#endif + +} //namespace + +#endif /* DIGITAL_OUT_H_ */ \ No newline at end of file diff --git a/firmware/src/bsp/mcu/mcu_hal.h b/firmware/src/bsp/mcu/mcu_hal.h new file mode 100644 index 0000000..187d17d --- /dev/null +++ b/firmware/src/bsp/mcu/mcu_hal.h @@ -0,0 +1,114 @@ +#ifndef MCU_HAL_H_ +#define MCU_HAL_H_ + +/**** Includes ****/ +#include + +namespace mcu { + +/**** Public definitions ****/ +/* +*/ +const uint8_t LEVEL_LOW = 0; +const uint8_t LEVEL_HIGH = 1; +const int8_t LEVEL_HIZ = -1; + +const uint8_t GPIO_DIN1 = 0; +const uint8_t GPIO_DIN2 = 1; +const uint8_t GPIO_DIN3 = 2; +const uint8_t GPIO_DIN4 = 3; +const uint8_t GPIO_HVDIN1 = 4; +const uint8_t GPIO_HVDIN2 = 5; +const uint8_t GPIO_HVDIN3 = 6; +const uint8_t GPIO_HVDIN3_PULL = 7; +const uint8_t GPIO_OD1 = 8; +const uint8_t GPIO_OD2 = 9; +const uint8_t GPIO_OD3 = 10; +const uint8_t GPIO_OD4 = 11; +const uint8_t GPIO_OD5 = 12; +const uint8_t GPIO_OD6 = 13; +const uint8_t GPIO_OUT_LOW = 14; +const uint8_t GPIO_OUT_HIGH = 15; +const uint8_t GPIO_OD_PWM = 16; +const uint8_t GPIO_FREQ1 = 17; +const uint8_t GPIO_FREQ2 = 18; +const uint8_t GPIO_FREQ_PULL = 19; +const uint8_t GPIO_TX = 20; +const uint8_t GPIO_RX = 21; + +const uint8_t ADC_IOUT = 0; //Output current +const uint8_t ADC_VOUT = 1; //Output voltage +const uint8_t ADC_VBAT = 2; //Battery voltage +const uint8_t ADC_IBAT = 3; //Battery current +const uint8_t ADC_AIN2 = 4; //Potentiometer +const uint8_t ADC_AIN1 = 5; //Mode +const uint8_t ADC_TEMP = 8; //MCU temperature +const uint8_t ADC_IVREF = 14; //MCU internal reference +const uint8_t ADC_GND = 15; //MCU ground + +const uint8_t PWM_OUT = 0; //DCCD +const uint8_t PWM_OD = 1; //LED + +//ADC definitions +typedef enum { + ADC_DIV2 = 0x01, + ADC_DIV4 = 0x02, + ADC_DIV8 = 0x03, + ADC_DIV16 = 0x04, + ADC_DIV32 = 0x05, + ADC_DIV64 = 0x06, + ADC_DIV128 = 0x07 +} adcClkDiv_t; + +//Timer definitions +typedef enum { + TIM_DIV1 = 0x01, + TIM_DIV8 = 0x02, + TIM_DIV64 = 0x03, + TIM_DIV256 = 0x04, + TIM_DIV1024 = 0x05 +} timerClkDiv_t; + +typedef struct { + adcClkDiv_t adc_clk; + timerClkDiv_t pwm_clk; + uint16_t pwm_top; + uint8_t od_common_is_pwm; +} startupCfg_t; + +/**** Public function declarations ****/ +void startup(startupCfg_t* hwCfg); + +void rtc_set_calibration(uint16_t coef); + +uint8_t gpio_read(uint8_t ch); +void gpio_write(uint8_t ch, int8_t lvl); +void gpio_write_pull(uint8_t ch, int8_t lvl); + +void adc_start(uint8_t ch); +uint8_t adc_is_running(void); +uint8_t adc_is_new(void); +uint16_t adc_read(void); +uint16_t adc_read(uint8_t ch); + +void pwm_write(uint8_t ch, uint16_t dc); +uint16_t pwm_read(uint8_t ch); + +void timer_reset(uint8_t ch); +uint16_t timer_read(uint8_t ch); +uint16_t timer_read_top(uint8_t ch); + +uint32_t timer_convert_us(uint8_t ch, uint16_t raw); +uint32_t timer_convert_ms(uint8_t ch, uint16_t raw); + +uint8_t eeprom_read8b(uint16_t address); +uint16_t eeprom_read16b(uint16_t address); +uint32_t eeprom_read32b(uint16_t address); + +void eeprom_write8b(uint16_t address, uint8_t value); +void eeprom_write16b(uint16_t address, uint16_t value); +void eeprom_write32b(uint16_t address, uint32_t value); + +} //namespace + +#endif /* MCU_HAL_H_ */ diff --git a/firmware/src/hw/board/mcu/mcu_hal_r8.c b/firmware/src/bsp/mcu/mcu_hal_r8.cpp similarity index 53% rename from firmware/src/hw/board/mcu/mcu_hal_r8.c rename to firmware/src/bsp/mcu/mcu_hal_r8.cpp index bd1bcfe..2056d15 100644 --- a/firmware/src/hw/board/mcu/mcu_hal_r8.c +++ b/firmware/src/bsp/mcu/mcu_hal_r8.cpp @@ -3,16 +3,20 @@ #include #include "mcu_hal.h" +using namespace mcu; + /**** Private definitions ****/ /**** Private constants ****/ /**** Private variables ****/ +static volatile uint16_t rtc_ms = 1000; + /**** Private function declarations ****/ -static uint8_t gpio_read(uint8_t pin_reg, uint8_t mask); +static uint8_t gpio_read_level(uint8_t pin_reg, uint8_t mask); static void pwm_write_ocx(uint8_t ch, uint16_t value); static uint16_t pwm_read_ocx(uint8_t ch); /**** Public function definitions ****/ -void mcu_startup(startupCfg_t* hwCfg) +void mcu::startup(startupCfg_t* hwCfg) { // Fail-safe GPIO init PORTB = 0xF8; // Set PORTB pull-ups @@ -32,9 +36,9 @@ void mcu_startup(startupCfg_t* hwCfg) DDRB |= 0x03; //Set as output // Common OD PWM pin - if(hwCfg->pwm_chb_en) PORTB &= ~0x04; //Set low - else PORTB |= 0x04; //Set high - DDRB |= 0x04; //Set as output + if(hwCfg->od_common_is_pwm) PORTB &= ~0x04; //Set low + else PORTB |= 0x04; //Set high + DDRB |= 0x04; //Set as output // OD control pins PORTD &= ~0x3F; //Set low (off) @@ -64,6 +68,10 @@ void mcu_startup(startupCfg_t* hwCfg) PORTC &= ~0x30; //Pull-up off DDRC &= ~0x30; //Set as inputs + // Freq-pull control pins + PORTD &= ~0x40; //Set low + DDRD |= 0x40; //Set as output + //ADC configuration PRR0 &= ~0x01; //Enable ADC power DIDR0 |= 0x0F; //Disable digital inputs, ADC0-ADC3 @@ -78,7 +86,7 @@ void mcu_startup(startupCfg_t* hwCfg) //DCCD and LED PWM configuration PRR0 &= ~0x80; //Enable Timer1 power TCCR1A = 0xC2; //Connect OC1A, inverted mode - if(hwCfg->pwm_chb_en) TCCR1A |= 0x30; //Connect OC1B, inverted mode + if(hwCfg->od_common_is_pwm) TCCR1A |= 0x30; //Connect OC1B, inverted mode TCCR1B = 0x18; //PWM, Phase & Frequency Correct ICR1 top, no clock, WGM:0xE TCCR1C = 0x00; TCNT1 = 0x0000; @@ -92,128 +100,92 @@ void mcu_startup(startupCfg_t* hwCfg) TCCR1B |= tim1_prescaler; //Enable timer } -// ADC Interface functions -uint16_t mcu_adc_read(uint8_t ch) +void mcu::rtc_set_calibration(uint16_t coef) { - //check if ADC is enabled - if(!(ADCSRA&0x80)) return 0xFFFF; - - //Safe guard mux - if(ch > 15) return 0xFFFF; - // Not available channels - if((ch > 8) && (ch<14)) return 0xFFFF; - - ADMUX &= ~0x0F; - ADMUX |= ch; - ADCSRA |= 0x40; - while(ADCSRA&0x40); //wait to finish - return ADC; + rtc_ms = coef; } -// PWM Timer Interface functions -void mcu_pwm_write(uint8_t ch, uint16_t dc) -{ - dc = 0xFFFF - dc; - - // Calculate value as % of TOP - uint32_t top = (uint32_t)ICR1; - uint32_t temp = (uint32_t)dc * top; - temp = temp/0x0000FFFF; - - //Limit temp - if(temp>0x0000FFFF) temp = 0x0000FFFF; - uint16_t ocrx = (uint16_t)temp; - - // Write register - pwm_write_ocx(ch, ocrx); -} - -uint16_t mcu_pwm_read(uint8_t ch) -{ - uint16_t ocrx = pwm_read_ocx(ch); - - // Check easy answers - if(ocrx == 0) return 0; - if(ocrx >= ICR1) return 0xFFFF; - - // Calculate - uint32_t top = (uint32_t)ICR1; - uint32_t temp = (uint32_t)ocrx * 0xFFFF; - temp = temp/top; - - //Limit temp - if(temp>0x0000FFFF) return 0xFFFF; - return (uint16_t)temp; -} - -uint8_t mcu_gpio_read(uint8_t ch) +// GPIO interface functions +uint8_t mcu::gpio_read(uint8_t ch) { switch(ch) { - case MCU_GPIO0: // Mode DIN1 - return gpio_read(PINC,0x20); + case GPIO_DIN1: // Mode DIN1 + return gpio_read_level(PINC,0x20); - case MCU_GPIO1: // Pot DIN2 - return gpio_read(PINC,0x10); + case GPIO_DIN2: // Pot DIN2 + return gpio_read_level(PINC,0x10); - case MCU_GPIO2: // Down DIN3 - return gpio_read(PINE,0x02); + case GPIO_DIN3: // Down DIN3 + return gpio_read_level(PINE,0x02); - case MCU_GPIO3: // Up DIN4 - return gpio_read(PINE,0x08); + case GPIO_DIN4: // Up DIN4 + return gpio_read_level(PINE,0x08); - case MCU_GPIO4: // Dimm DIN5 - return gpio_read(PIND,0x80); + case GPIO_HVDIN1: // Dimm DIN5 + return gpio_read_level(PIND,0x80); - case MCU_GPIO5: // Brakes DIN6 - return gpio_read(PINB,0x80); + case GPIO_HVDIN2: // Brakes DIN6 + return gpio_read_level(PINB,0x80); - case MCU_GPIO6: // Handbrake DIN7 - return gpio_read(PINB,0x40); + case GPIO_HVDIN3: // Handbrake DIN7 + return gpio_read_level(PINB,0x40); - case MCU_GPIO7: // Handbrake pull DIN8 - return gpio_read(PINB,0x20); + case GPIO_HVDIN3_PULL: // Handbrake pull DIN8 + return gpio_read_level(PINB,0x20); - case MCU_GPIO8: // Speed-pull - return gpio_read(PIND,0x40); + case GPIO_OD1: // LED 0 + return gpio_read_level(PIND,0x01); - case MCU_GPIO9: // LED 0 - return gpio_read(PIND,0x01); + case GPIO_OD2: // LED 1 + return gpio_read_level(PIND,0x02); - case MCU_GPIO10: // LED 1 - return gpio_read(PIND,0x02); + case GPIO_OD3: // LED 2 + return gpio_read_level(PIND,0x04); - case MCU_GPIO11: // LED 2 - return gpio_read(PIND,0x04); + case GPIO_OD4: // LED 3 + return gpio_read_level(PIND,0x08); - case MCU_GPIO12: // LED 3 - return gpio_read(PIND,0x08); + case GPIO_OD5: // LED 4 + return gpio_read_level(PIND,0x10); - case MCU_GPIO13: // LED 4 - return gpio_read(PIND,0x10); + case GPIO_OD6: // LED 5 + return gpio_read_level(PIND,0x20); - case MCU_GPIO14: // LED 5 - return gpio_read(PIND,0x20); + case GPIO_OUT_LOW: // DCCD Enable + return gpio_read_level(PINB,0x01); - case MCU_GPIO15: // DCCD Enable - return gpio_read(PINB,0x01); + case GPIO_OUT_HIGH: // DCCD PWM + return gpio_read_level(PINB,0x02); - case MCU_GPIO16: // DCCD PWM - return gpio_read(PINB,0x02); + case GPIO_OD_PWM: // LED PWM + return gpio_read_level(PINB,0x04); - case MCU_GPIO17: // LED PWM - return gpio_read(PINB,0x04); + case GPIO_FREQ1: // Speed 1 + return gpio_read_level(PINE,0x04); + + case GPIO_FREQ2: // Speed 2 + return gpio_read_level(PINE,0x01); + + case GPIO_FREQ_PULL: // Speed-pull + return gpio_read_level(PIND,0x40); + + case GPIO_TX: // + return gpio_read_level(PINB,0x08); + + case GPIO_RX: // + return gpio_read_level(PINB,0x10); default: return 0; } } -void mcu_gpio_write(uint8_t ch, int8_t lvl) +void mcu::gpio_write(uint8_t ch, int8_t lvl) { switch(ch) { - case MCU_GPIO0: // Mode DIN1 + case GPIO_DIN1: // Mode DIN1 if(lvl>0) { PORTC |= 0x20; @@ -231,7 +203,7 @@ void mcu_gpio_write(uint8_t ch, int8_t lvl) } return; - case MCU_GPIO1: // Pot DIN2 + case GPIO_DIN2: // Pot DIN2 if(lvl>0) { PORTC |= 0x10; @@ -249,7 +221,7 @@ void mcu_gpio_write(uint8_t ch, int8_t lvl) } return; - case MCU_GPIO2: // Down DIN3 + case GPIO_DIN3: // Down DIN3 if(lvl>0) { PORTE |= 0x02; @@ -267,7 +239,7 @@ void mcu_gpio_write(uint8_t ch, int8_t lvl) } return; - case MCU_GPIO3: // Up DIN4 + case GPIO_DIN4: // Up DIN4 if(lvl>0) { PORTE |= 0x08; @@ -285,7 +257,7 @@ void mcu_gpio_write(uint8_t ch, int8_t lvl) } return; - case MCU_GPIO7: // Handbrake pull DIN + case GPIO_HVDIN3_PULL: // Handbrake pull DIN if(lvl>0) { PORTB |= 0x20; @@ -303,97 +275,234 @@ void mcu_gpio_write(uint8_t ch, int8_t lvl) } return; - case MCU_GPIO8: // Speed-pull - if(lvl>0) PORTD |= 0x40; - else PORTD &= ~0x40; - return; - - case MCU_GPIO9: // LED 0 + case GPIO_OD1: // LED 0 if(lvl>0) PORTD |= 0x01; else PORTD &= ~0x01; return; - case MCU_GPIO10: // LED 1 + case GPIO_OD2: // LED 1 if(lvl>0) PORTD |= 0x02; else PORTD &= ~0x02; return; - case MCU_GPIO11: // LED 2 + case GPIO_OD3: // LED 2 if(lvl>0) PORTD |= 0x04; else PORTD &= ~0x04; return; - case MCU_GPIO12: // LED 3 + case GPIO_OD4: // LED 3 if(lvl>0) PORTD |= 0x08; else PORTD &= ~0x08; return; - case MCU_GPIO13: // LED 4 + case GPIO_OD5: // LED 4 if(lvl>0) PORTD |= 0x10; else PORTD &= ~0x10; return; - case MCU_GPIO14: // LED 5 + case GPIO_OD6: // LED 5 if(lvl>0) PORTD |= 0x20; else PORTD &= ~0x20; return; - case MCU_GPIO15: // DCCD Enable + case GPIO_OUT_LOW: // DCCD Enable if(lvl>0) PORTB |= 0x01; else PORTB &= ~0x01; return; + case GPIO_FREQ_PULL: // Speed-pull + if(lvl>0) PORTD |= 0x40; + else PORTD &= ~0x40; + return; + default: return; } } -uint8_t mcu_ee_read8b(uint16_t address) +void mcu::gpio_write_pull(uint8_t ch, int8_t lvl) +{ + switch(ch) + { + case GPIO_DIN1: // Mode DIN1 + if(lvl>0) PORTC |= 0x20; + else PORTC &= ~0x20; + return; + + case GPIO_DIN2: // Pot DIN2 + if(lvl>0) PORTC |= 0x10; + else PORTC &= ~0x10; + return; + + case GPIO_DIN3: // Down DIN3 + if(lvl>0) PORTE |= 0x02; + else PORTE &= ~0x02; + return; + + case GPIO_DIN4: // Up DIN4 + if(lvl>0) PORTE |= 0x08; + else PORTE &= ~0x08; + return; + + case GPIO_HVDIN1: // Dimm + if(lvl>0) PORTD |= 0x80; + else PORTD &= ~0x80; + return; + + case GPIO_HVDIN2: // Brakes + if(lvl>0) PORTB |= 0x80; + else PORTB &= ~0x80; + return; + + case GPIO_HVDIN3: // Handbrake + if(lvl>0) PORTB |= 0x40; + else PORTB &= ~0x40; + return; + + default: + return; + } +} + +// ADC interface functions +void mcu::adc_start(uint8_t ch) +{ + // check if already running + if(ADCSRA&0x40) return; + + //check if ADC is enabled + if(!(ADCSRA&0x80)) return; + + //Safe guard mux + if(ch > 15) return; + // Not available channels + if((ch > 8) && (ch<14)) return; + + ADMUX &= ~0x0F; + ADMUX |= ch; + ADCSRA |= 0x10; // Reset int. flag + ADCSRA |= 0x40; +} + + +uint8_t mcu::adc_is_running(void) +{ + if(ADCSRA&0x40) return 1; + else return 0; +} + +uint8_t mcu::adc_is_new(void) +{ + if(ADCSRA&0x10) return 1; + else return 0; +} + +uint16_t mcu::adc_read(void) +{ + ADCSRA |= 0x10; // Reset int. flag + return ADC; +} + +uint16_t mcu::adc_read(uint8_t ch) +{ + //check if ADC is enabled + if(!(ADCSRA&0x80)) return 0xFFFF; + + //Safe guard mux + if(ch > 15) return 0xFFFF; + // Not available channels + if((ch > 8) && (ch<14)) return 0xFFFF; + + ADMUX &= ~0x0F; + ADMUX |= ch; + ADCSRA |= 0x40; + while(ADCSRA&0x40); //wait to finish + return ADC; +} + +// PWM interface functions +void mcu::pwm_write(uint8_t ch, uint16_t dc) +{ + dc = 0xFFFF - dc; + + // Calculate value as % of TOP + uint32_t top = (uint32_t)ICR1; + uint32_t temp = (uint32_t)dc * top; + temp = temp/0x0000FFFF; + + //Limit temp + if(temp>0x0000FFFF) temp = 0x0000FFFF; + uint16_t ocrx = (uint16_t)temp; + + // Write register + pwm_write_ocx(ch, ocrx); +} + +uint16_t mcu::pwm_read(uint8_t ch) +{ + uint16_t ocrx = pwm_read_ocx(ch); + + // Check easy answers + if(ocrx == 0) return 0; + if(ocrx >= ICR1) return 0xFFFF; + + // Calculate + uint32_t top = (uint32_t)ICR1; + uint32_t temp = (uint32_t)ocrx * 0xFFFF; + temp = temp/top; + + //Limit temp + if(temp>0x0000FFFF) return 0xFFFF; + return (uint16_t)temp; +} + +// EEPROM interface functions +uint8_t mcu::eeprom_read8b(uint16_t address) { return eeprom_read_byte((uint8_t*)address); } -uint16_t mcu_ee_read16b(uint16_t address) +uint16_t mcu::eeprom_read16b(uint16_t address) { return eeprom_read_word((uint16_t*)address); } -uint32_t mcu_ee_read32b(uint16_t address) +uint32_t mcu::eeprom_read32b(uint16_t address) { return eeprom_read_dword((uint32_t*)address); } -void mcu_ee_write8b(uint16_t address, uint8_t value) +void mcu::eeprom_write8b(uint16_t address, uint8_t value) { eeprom_write_byte((uint8_t*)address, value); } -void mcu_ee_write16b(uint16_t address, uint16_t value) +void mcu::eeprom_write16b(uint16_t address, uint16_t value) { eeprom_write_word((uint16_t*)address, value); } -void mcu_ee_write32b(uint16_t address, uint32_t value) +void mcu::eeprom_write32b(uint16_t address, uint32_t value) { eeprom_write_dword((uint32_t*)address, value); } /**** Private function definitions ****/ -static uint8_t gpio_read(uint8_t pin_reg, uint8_t mask) +static uint8_t gpio_read_level(uint8_t pin_reg, uint8_t mask) { - if(pin_reg&mask) return MCU_GPIO_HIGH; - else return MCU_GPIO_LOW; + if(pin_reg&mask) return LEVEL_HIGH; + else return LEVEL_LOW; } static void pwm_write_ocx(uint8_t ch, uint16_t value) { switch(ch) { - case MCU_PWM0: + case PWM_OUT: OCR1A = value; return; - case MCU_PWM1: + case PWM_OD: OCR1B = value; return; @@ -406,13 +515,13 @@ static uint16_t pwm_read_ocx(uint8_t ch) { switch(ch) { - case MCU_PWM0: + case PWM_OUT: return OCR1A; - case MCU_PWM1: + case PWM_OD: return OCR1B ; default: return 0x0000; } -} \ No newline at end of file +} diff --git a/firmware/src/bsp/memory.cpp b/firmware/src/bsp/memory.cpp new file mode 100644 index 0000000..a186eae --- /dev/null +++ b/firmware/src/bsp/memory.cpp @@ -0,0 +1,55 @@ +/**** Includes ****/ +#include "mcu/mcu_hal.h" +#include "memory.h" + +using namespace bsp; + +/**** Private definitions ****/ +/**** Private constants ****/ +/**** Private variables ****/ +/**** Private function declarations ****/ +/**** Public function definitions ****/ +bsp::Memory::Memory(void) +{ + return; +} + +bsp::Memory::~Memory(void) +{ + return; +} + +uint8_t bsp::Memory::read_8b(uint16_t address) +{ + return mcu::eeprom_read8b(address); +} + + +uint16_t bsp::Memory::read_16b(uint16_t address) +{ + return mcu::eeprom_read16b(address); +} + +uint32_t bsp::Memory::read_32b(uint16_t address) +{ + return mcu::eeprom_read32b(address); +} + +void bsp::Memory::write_8b(uint16_t address, uint8_t value) +{ + mcu::eeprom_write8b(address, value); +} + + +void bsp::Memory::write_16b(uint16_t address, uint16_t value) +{ + mcu::eeprom_write16b(address, value); +} + +void bsp::Memory::write_32b(uint16_t address, uint32_t value) +{ + mcu::eeprom_write32b(address, value); +} + +/**** Private function definitions ****/ + diff --git a/firmware/src/bsp/memory.h b/firmware/src/bsp/memory.h new file mode 100644 index 0000000..b66c293 --- /dev/null +++ b/firmware/src/bsp/memory.h @@ -0,0 +1,36 @@ +#ifndef MEMORY_IN_H_ +#define MEMORY_IN_H_ + +/**** Includes ****/ +#include + +namespace bsp { + +/**** Public definitions ****/ +class Memory +{ + public: + Memory(void); + ~Memory(void); + + uint8_t read_8b(uint16_t address); + uint16_t read_16b(uint16_t address); + uint32_t read_32b(uint16_t address); + + void write_8b(uint16_t address, uint8_t value); + void write_16b(uint16_t address, uint16_t value); + void write_32b(uint16_t address, uint32_t value); + + #ifndef TESTING + protected: + #endif +}; + +/**** Public function declarations ****/ + +#ifdef TESTING +#endif + +} //namespace + +#endif /* MEMORY_IN_H_ */ \ No newline at end of file diff --git a/firmware/src/bsp/pwm_out.cpp b/firmware/src/bsp/pwm_out.cpp new file mode 100644 index 0000000..72c34ab --- /dev/null +++ b/firmware/src/bsp/pwm_out.cpp @@ -0,0 +1,56 @@ +/**** Includes ****/ +#include "../utils/utils.h" +#include "mcu/mcu_hal.h" +#include "pwm_out.h" + +using namespace bsp; + +/**** Private definitions ****/ +/**** Private constants ****/ +/**** Private variables ****/ +/**** Private function declarations ****/ + +/**** Public function definitions ****/ +bsp::PwmOut::PwmOut(void) +{ + return; +} + +bsp::PwmOut::~PwmOut(void) +{ + this->last_duty = 0; +} + +void bsp::PwmOut::init(uint8_t pwm_ch, uint8_t max_dc) +{ + this->pwm_ch = pwm_ch; + + this->last_duty = 0; + + if(max_dc>100) max_dc = 100; + + this->max_dc = util::percent_to_16b(max_dc); +} + +void bsp::PwmOut::write(uint16_t numerator) +{ + // Update target + if(numerator > this->max_dc) numerator = this->max_dc; + this->last_duty = numerator; + + // Set PWM + mcu::pwm_write(this->pwm_ch, numerator); +} + +void bsp::PwmOut::write(uint8_t percent) +{ + // Convert to numerator/0xFFFF + this->write(util::percent_to_16b(percent)); +} + +uint16_t bsp::PwmOut::get_set_duty(void) +{ + return this->last_duty; +} + +/**** Private function definitions ****/ diff --git a/firmware/src/bsp/pwm_out.h b/firmware/src/bsp/pwm_out.h new file mode 100644 index 0000000..cdcfec1 --- /dev/null +++ b/firmware/src/bsp/pwm_out.h @@ -0,0 +1,37 @@ +#ifndef PWM_OUT_H_ +#define PWM_OUT_H_ + +/**** Includes ****/ +#include + +namespace bsp { + +/**** Public definitions ****/ +class PwmOut +{ + public: + PwmOut(void); + ~PwmOut(void); + + void init(uint8_t pwm_ch, uint8_t max_dc); + + void write(uint16_t numerator); + void write(uint8_t percent); + uint16_t get_set_duty(void); + + #ifndef TESTING + protected: + #endif + uint8_t pwm_ch; + uint16_t last_duty; + uint16_t max_dc; +}; + +/**** Public function declarations ****/ + +#ifdef TESTING +#endif + +} //namespace + +#endif /* PWM_OUT_H_ */ \ No newline at end of file diff --git a/firmware/src/dccd/dccd.cpp b/firmware/src/dccd/dccd.cpp new file mode 100644 index 0000000..88e7bc2 --- /dev/null +++ b/firmware/src/dccd/dccd.cpp @@ -0,0 +1,432 @@ +/**** Includes ****/ +#include "../utils/utils.h" +#include "dccd.h" + +using namespace dccd; + +/**** Private definitions ****/ +/**** Private constants ****/ +static const uint16_t def_lock_current = 4500; +static const uint16_t def_max_hbrake_time = 0; +static const uint16_t def_btn_force_repeat_time = 300; +static const uint16_t def_btn_mode_repeat_time = 700; +static const uint8_t def_button_inputs = 1; + +static const uint8_t def_display_brigth = 100; +static const uint8_t def_display_dimm = 50; + +static const uint16_t cv_ref_resistance = 1500; +static const uint16_t cc_ref_resistance = 2000; +static const uint16_t cc_min_resistance = 1000; + +static const uint8_t bmode_image_open = 0x07; +static const uint8_t bmode_image_user = 0x1E; +static const uint8_t bmode_image_lock = 0x38; + +static const uint16_t display_keep_bmode = 2000; +static const uint16_t display_keep_userf = 1000; + +static const uint8_t user_force_step = 10; + +static const uint8_t def_btn_force = 0; +static const uint8_t def_brake_mode = 0; + +static const uint16_t def_chasis_inp_debounce = 100; +static const uint16_t def_user_inp_debounce = 20; + +static const uint16_t mem_addr_inp_mode = 0; +static const uint16_t mem_addr_force = 1; +static const uint16_t mem_addr_bmode = 2; +static const uint16_t mem_addr_dsp_brigth = 3; +static const uint16_t mem_addr_dsp_dimm = 4; +static const uint16_t mem_addr_lock_current = 5; +static const uint16_t mem_addr_hbrake_time = 7; + +/**** Private variables ****/ +/**** Private function declarations ****/ +static uint8_t img_gen_dot10(uint8_t percent); +static uint8_t img_gen_dot20(uint8_t percent); +static uint8_t img_gen_bar(uint8_t percent); + +/**** Public function definitions ****/ +dccd::DccdApp::DccdApp(void) +{ + return; +} + +dccd::DccdApp::~DccdApp(void) +{ + return; +} + +void dccd::DccdApp::init(DccdHw* dccd_hw) +{ + this->hardware = dccd_hw; + + #define OVERRIDEDEDBNC + #ifdef OVERRIDEDEDBNC + this->hardware->btn_mode.dbnc_lim = def_user_inp_debounce; + this->hardware->btn_up.dbnc_lim = def_user_inp_debounce; + this->hardware->btn_down.dbnc_lim = def_user_inp_debounce; + this->hardware->handbrake.dbnc_lim = def_chasis_inp_debounce; + this->hardware->brakes.dbnc_lim = def_chasis_inp_debounce; + this->hardware->dimm.dbnc_lim = def_chasis_inp_debounce; + #endif + + // Load saved config from memory + this->loadMemCfg(); + + this->btn_force_repeat_time = def_btn_force_repeat_time; + this->btn_mode_repeat_time = def_btn_mode_repeat_time; + this->pot_force = 0; + + this->hardware->read(); + this->hardware->dimm.force_read(); + + this->hardware->outreg.write_voltage(0); + this->hardware->outreg.write_current(0); + this->hardware->outreg.write_on(1); + + this->hardware->display.write(0x01); + if(this->hardware->dimm.state) this->hardware->display.write_backlight(this->display_dimm); + else this->hardware->display.write_backlight(this->display_brigth); + + this->hardware->write(); +} + +void dccd::DccdApp::process(void) +{ + // Update all inputs + this->hardware->read(); + + uint8_t is_new_mode = 0; + uint8_t is_new_btn_force = 0; + + // Process mode button + if((this->hardware->btn_mode.state==1)&&((this->hardware->btn_mode.is_new)||(this->hardware->btn_mode.time_read() >= this->btn_mode_repeat_time))) + { + this->hardware->btn_mode.time_reset(); + this->hardware->btn_mode.is_new = 0; + // Change mode + switch(this->brake_mode) + { + case 0: + this->brake_mode = 1; + break; + + case 1: + this->brake_mode = 2; + break; + + default: + this->brake_mode = 0; + break; + } + is_new_mode = 1; + this->hardware->board_hw.nvmem.write_8b(mem_addr_bmode, this->brake_mode); + }; + + // Process user force inputs + if((this->hardware->btn_up.state==1)&&((this->hardware->btn_up.is_new)||(this->hardware->btn_up.time_read() >= this->btn_force_repeat_time))) + { + this->hardware->btn_up.time_reset(); + this->hardware->btn_up.is_new = 0; + // Increase user force + this->btn_force += user_force_step; + if(this->btn_force > 100) this->btn_force = 100; + is_new_btn_force = 1; + }; + + if((this->hardware->btn_down.state==1)&&((this->hardware->btn_down.is_new)||(this->hardware->btn_down.time_read() >= this->btn_force_repeat_time))) + { + this->hardware->btn_down.time_reset(); + this->hardware->btn_down.is_new = 0; + // Decrease user force + this->btn_force -= user_force_step; + if(this->btn_force > 100) this->btn_force = 0; + is_new_btn_force = 1; + }; + + if(is_new_btn_force) + { + this->hardware->board_hw.nvmem.write_8b(mem_addr_force, this->btn_force); + }; + + this->pot_force = this->hardware->pot.last_percent; + + // Determine user force + int8_t user_force; + if(this->button_inputs) user_force = (int8_t)this->btn_force; + else user_force = (int8_t)this->pot_force; + + // Determine next settable force + int8_t next_force; + + uint8_t hbrake_timeout = 0; + if((this->max_hbrake_time!=0)&&(this->hardware->handbrake.time_read() >= this->max_hbrake_time)) + { + hbrake_timeout = 1; + }; + + if((this->hardware->handbrake.state == 1)&&(hbrake_timeout==0)) + { + // Handbrake override + next_force = -1; + } + else if(this->hardware->brakes.state == 1) + { + // Brakes override + switch(this->brake_mode) + { + case 0: + next_force = -1; + break; + + case 1: + next_force = user_force; + break; + + case 2: + next_force = 100; + break; + + default: + next_force = -1; + this->brake_mode = 0; + break; + } + } + else + { + // User force + next_force = user_force; + } + + // Apply next force + if(next_force < 0) + { + // HiZ + this->hardware->outreg.write_voltage(0); + this->hardware->outreg.write_current(0); + this->hardware->outreg.write_on(0); + // For display + next_force = 0; + } + else if(next_force == 0) + { + // Open + this->hardware->outreg.write_voltage(0); + this->hardware->outreg.write_current(0); + this->hardware->outreg.write_on(1); + } + else + { + // Calculate current and voltage settings + this->hardware->outreg.write_current(util::percent_of((uint8_t)next_force, this->lock_current)); + uint16_t ref_resistance = cv_ref_resistance; + if(this->hardware->outreg.cc_mode_en) ref_resistance = cc_ref_resistance; + this->hardware->outreg.write_voltage(util::sat_mul_kilo(this->hardware->outreg.read_current(), ref_resistance)); + this->hardware->outreg.write_on(1); + } + + // Display image + if(is_new_mode) + { + uint8_t bmode_image; + switch(this->brake_mode) + { + case 0: + bmode_image = bmode_image_open; + break; + + case 1: + bmode_image = bmode_image_user; + break; + + case 2: + bmode_image = bmode_image_lock; + break; + + default: + bmode_image = bmode_image_open; + this->brake_mode = 0; + break; + } + this->hardware->display.write(bmode_image, display_keep_bmode, display_keep_bmode, 1); + is_new_mode = 0; + } + else if((is_new_btn_force)&&(this->button_inputs)) + { + this->hardware->display.write(img_gen_dot10(this->btn_force), display_keep_userf, display_keep_userf, 1); + is_new_btn_force = 0; + } + else if(this->hardware->display.is_cycle_end()) + { + this->hardware->display.write(img_gen_dot10((uint8_t)next_force)); + }; + + // Display backlight + if(this->hardware->dimm.is_new) + { + this->hardware->dimm.is_new = 0; + if(this->hardware->dimm.state) this->hardware->display.write_backlight(this->display_dimm); + else this->hardware->display.write_backlight(this->display_brigth); + }; + + // Execute outputs + this->hardware->write(); +} + +uint8_t dccd::DccdApp::loadMemCfg(void) +{ + // Load saved config from memory + uint8_t t1; + uint16_t t2; + uint8_t def_applied = 0; + + t1 = this->hardware->board_hw.nvmem.read_8b(mem_addr_inp_mode); + if(t1 > 1){this->button_inputs = def_button_inputs; def_applied=1; } + else this->button_inputs = t1; + + t1 = this->hardware->board_hw.nvmem.read_8b(mem_addr_force); + if(t1 > 100){this->btn_force = def_btn_force; def_applied=1; } + else this->btn_force = t1; + + t1 = this->hardware->board_hw.nvmem.read_8b(mem_addr_bmode); + if(t1 > 2){this->brake_mode = def_brake_mode; def_applied=1; } + else this->brake_mode = t1; + + t1 = this->hardware->board_hw.nvmem.read_8b(mem_addr_dsp_brigth); + if((t1 > 100)||(t1 == 0)){this->display_brigth = def_brake_mode; def_applied=1; } + else this->display_brigth = t1; + + t1 = this->hardware->board_hw.nvmem.read_8b(mem_addr_dsp_dimm); + if((t1 > 100)||(t1 == 0)){this->display_dimm = def_brake_mode; def_applied=1; } + else this->display_dimm = t1; + + t2 = this->hardware->board_hw.nvmem.read_16b(mem_addr_lock_current); + if((t2 > 5000)||(t2 < 1000)){this->lock_current = def_lock_current; def_applied=1; } + else this->lock_current = t2; + + t2 = this->hardware->board_hw.nvmem.read_16b(mem_addr_hbrake_time); + if((t2 > 30000)||(t2 == 0)){this->max_hbrake_time = def_max_hbrake_time; def_applied=1; } + else this->max_hbrake_time = t2; + + return def_applied; +} + +void dccd::DccdApp::saveMemCfg(void) +{ + // Save config to memory + + this->hardware->board_hw.nvmem.write_8b(mem_addr_inp_mode, this->button_inputs); + + this->hardware->board_hw.nvmem.write_8b(mem_addr_force, this->btn_force); + + this->hardware->board_hw.nvmem.write_8b(mem_addr_bmode, this->brake_mode); + + this->hardware->board_hw.nvmem.write_8b(mem_addr_dsp_brigth, this->display_brigth); + + this->hardware->board_hw.nvmem.write_8b(mem_addr_dsp_dimm, this->display_dimm); + + this->hardware->board_hw.nvmem.write_16b(mem_addr_lock_current, this->lock_current); + + this->hardware->board_hw.nvmem.write_16b(mem_addr_hbrake_time, this->max_hbrake_time); +} + +/**** Private function definitions ***/ +static uint8_t img_gen_dot10(uint8_t percent) +{ + switch(percent) + { + case 0 ... 5: + return 0x01; + + case 6 ... 15: + return 0x03; + + case 16 ... 25: + return 0x02; + + case 26 ... 35: + return 0x06; + + case 36 ... 45: + return 0x04; + + case 46 ... 55: + return 0x0C; + + case 56 ... 65: + return 0x08; + + case 66 ... 75: + return 0x18; + + case 76 ... 85: + return 0x10; + + case 86 ... 95: + return 0x30; + + case 96 ... 100: + return 0x20; + + default: + return 0x20; + } +} + +static uint8_t img_gen_dot20(uint8_t percent) +{ + switch(percent) + { + case 0 ... 10: + return 0x01; + + case 11 ... 30: + return 0x02; + + case 31 ... 50: + return 0x04; + + case 51 ... 70: + return 0x08; + + case 71 ... 90: + return 0x10; + + case 91 ... 100: + return 0x20; + + default: + return 0x20; + } +} + +static uint8_t img_gen_bar(uint8_t percent) +{ + switch(percent) + { + case 0 ... 10: + return 0x01; + + case 11 ... 30: + return 0x03; + + case 31 ... 50: + return 0x07; + + case 51 ... 70: + return 0x0F; + + case 71 ... 90: + return 0x1F; + + case 91 ... 100: + return 0x3F; + + default: + return 0x3F; + } +} diff --git a/firmware/src/dccd/dccd.h b/firmware/src/dccd/dccd.h new file mode 100644 index 0000000..bacd4db --- /dev/null +++ b/firmware/src/dccd/dccd.h @@ -0,0 +1,48 @@ +#ifndef DCCD_APP_H_ +#define DCCD_APP_H_ + +/**** Includes ****/ +#include +#include "dccd_hw.h" + +namespace dccd { + +/**** Public definitions ****/ +class DccdApp +{ + public: + DccdApp(void); + ~DccdApp(void); + + void init(DccdHw* dccd_hw); + void process(void); + + uint16_t lock_current; + uint16_t max_hbrake_time; + uint16_t btn_force_repeat_time; + uint16_t btn_mode_repeat_time; + uint8_t button_inputs; + uint8_t display_brigth; + uint8_t display_dimm; + + uint8_t btn_force; + uint8_t pot_force; + uint8_t brake_mode; + + uint8_t loadMemCfg(void); + void saveMemCfg(void); + + #ifdef TESTING + protected: + #endif + DccdHw* hardware; +}; + +/**** Public function declarations ****/ + +#ifdef TESTING +#endif + +} //namespace + +#endif /* DCCD_APP_H_ */ \ No newline at end of file diff --git a/firmware/src/dccd/dccd_hw.cpp b/firmware/src/dccd/dccd_hw.cpp new file mode 100644 index 0000000..4270771 --- /dev/null +++ b/firmware/src/dccd/dccd_hw.cpp @@ -0,0 +1,190 @@ +/**** Includes ****/ +#include "../utils/utils.h" +#include "dccd_hw.h" + +using namespace dccd; + +/**** Private definitions ****/ +/**** Private constants ****/ +static const uint8_t def_dbnc_time = 10; + +static const uint16_t def_pot_dead_bot = 500; +static const uint16_t def_pot_dead_top = 4500; + +static const uint8_t def_cc_mode_en = 1; + +static const uint16_t def_cnter_us = 900; + +static const uint16_t def_out_voltage_under_treshold = 0; +static const uint16_t def_out_voltage_over_treshold = 9000; +static const uint16_t def_out_voltage_hold_time = 1000; +static const uint16_t def_out_voltage_cooldown_time = 0; + +static const uint16_t def_out_current_under_treshold = 0; +static const uint16_t def_out_current_over_treshold = 6000; +static const uint16_t def_out_current_hold_time = 200; +static const uint16_t def_out_current_cooldown_time = 1000; + +static const uint16_t def_battery_voltage_under_treshold = 9000; +static const uint16_t def_battery_voltage_over_treshold = 18000; +static const uint16_t def_battery_voltage_hold_time = 1000; +static const uint16_t def_battery_voltage_cooldown_time = 0; + +static const uint16_t def_battery_current_under_treshold = 0; +static const uint16_t def_battery_current_over_treshold = 8000; +static const uint16_t def_battery_current_hold_time = 200; +static const uint16_t def_battery_current_cooldown_time = 1000; + +static const uint16_t def_inital_bat_voltage = 12000; + +/**** Private variables ****/ +/**** Private function declarations ****/ +/**** Public function definitions ****/ +dccd::DccdHw::DccdHw(void) +{ + return; +} + +dccd::DccdHw::~DccdHw(void) +{ + return; +} + +void dccd::DccdHw::init(dccdHwCfg_t* cfg) +{ + // Apply config + bsp::Board::boardCfg_t board_cfg; + board_cfg.pwm_f_khz = cfg->pwm_f_khz; + board_cfg.od_common_is_pwm = 1; + this->board_hw.init(&board_cfg); + + this->counter.init(0xFFFF, cfg->counter_step_us); + this->counter.disabled = 0; + + this->out_voltage.init(&(this->board_hw.out_voltage), &(this->counter)); + this->out_voltage.under_treshold = def_out_voltage_under_treshold; + this->out_voltage.over_treshold = def_out_voltage_over_treshold; + this->out_voltage.hold_time = def_out_voltage_hold_time; + this->out_voltage.cooldown_time = def_out_voltage_cooldown_time; + this->out_voltage.update_ain = 0; + this->out_voltage.auto_reset = 1; + + this->out_current.init(&(this->board_hw.out_current), &(this->counter)); + this->out_current.under_treshold = def_out_current_under_treshold; + this->out_current.over_treshold = def_out_current_over_treshold; + this->out_current.hold_time = def_out_current_hold_time; + this->out_current.cooldown_time = def_out_current_cooldown_time; + this->out_current.update_ain = 0; + this->out_current.auto_reset = 1; + + this->battery_voltage.init(&(this->board_hw.battery_voltage), &(this->counter)); + this->battery_voltage.under_treshold = def_battery_voltage_under_treshold; + this->battery_voltage.over_treshold = def_battery_voltage_over_treshold; + this->battery_voltage.hold_time = def_battery_voltage_hold_time; + this->battery_voltage.cooldown_time = def_battery_voltage_cooldown_time; + this->battery_voltage.update_ain = 0; + this->battery_voltage.auto_reset = 1; + this->battery_voltage.last_read = def_inital_bat_voltage; + + this->battery_current.init(&(this->board_hw.battery_current), &(this->counter)); + this->battery_current.under_treshold = def_battery_current_under_treshold; + this->battery_current.over_treshold = def_battery_current_over_treshold; + this->battery_current.hold_time = def_battery_current_hold_time; + this->battery_current.cooldown_time = def_battery_current_cooldown_time; + this->battery_current.update_ain = 0; + this->battery_current.auto_reset = 1; + + this->btn_up.init(&(this->board_hw.din4), 0, &(this->counter), def_dbnc_time); + this->btn_up.update_din = 0; + + this->btn_down.init(&(this->board_hw.din3), 0, &(this->counter), def_dbnc_time); + this->btn_down.update_din = 0; + + this->btn_mode.init(&(this->board_hw.din1), 0, &(this->counter), def_dbnc_time); + this->btn_mode.update_din = 0; + + this->handbrake.init(&(this->board_hw.hvdin3), 0, &(this->counter), def_dbnc_time); + this->handbrake.update_din = 0; + + this->brakes.init(&(this->board_hw.hvdin2), 1, &(this->counter), def_dbnc_time); + this->brakes.update_din = 0; + + this->dimm.init(&(this->board_hw.hvdin1), 1, &(this->counter), def_dbnc_time); + this->dimm.update_din = 0; + + this->pot.init(&(this->board_hw.ain2), def_pot_dead_bot, def_pot_dead_top); + this->pot.update_ain = 0; + + hw::OutReg::outRegCfg_t outreg_cfg; + outreg_cfg.pwm_high = &this->board_hw.out_pwm; + outreg_cfg.dout_low = &this->board_hw.out_low; + outreg_cfg.ubat = &this->board_hw.battery_voltage; + outreg_cfg.uout = &this->board_hw.out_voltage; + outreg_cfg.iout = &this->board_hw.out_current; + this->outreg.init(&outreg_cfg); + this->outreg.cc_mode_en = def_cc_mode_en; + this->outreg.update_ain = 0; + + hw::LedDisplay::doutCfg_t dsp_cfg; + dsp_cfg.led0_dout_ch = &(this->board_hw.od1); + dsp_cfg.led1_dout_ch = &(this->board_hw.od2); + dsp_cfg.led2_dout_ch = &(this->board_hw.od3); + dsp_cfg.led3_dout_ch = &(this->board_hw.od4); + dsp_cfg.led4_dout_ch = &(this->board_hw.od5); + dsp_cfg.led5_dout_ch = &(this->board_hw.od6); + + this->display.init(&dsp_cfg, 0, &(this->counter), &(this->board_hw.od_pwm)); + + // Apply configuration + if(cfg->handbrake_pull_up) + { + this->board_hw.hvdin3_pull.write(1); + } + else this->board_hw.hvdin3_pull.write(0); + + if(cfg->speed_hall) + { + this->board_hw.freq_pull.write(1); + } + else this->board_hw.freq_pull.write(0); + + // Set initial output states + this->outreg.write_voltage(0); + this->outreg.write_current(0); + this->outreg.write_on(0); + this->outreg.write_lock(0); + this->outreg.process(); + + this->display.write_backlight(100); + this->display.write(0x00); +} + +void dccd::DccdHw::read(void) +{ + // Update low level inputs + this->board_hw.read(); + + this->counter.increment(); + + this->out_voltage.process(); + this->out_current.process(); + this->battery_voltage.process(); + this->battery_current.process(); + + this->btn_up.process(); + this->btn_down.process(); + this->btn_mode.process(); + this->handbrake.process(); + this->brakes.process(); + this->dimm.process(); + + this->pot.read(); +} + +void dccd::DccdHw::write(void) +{ + this->display.process(); + this->outreg.process(); +} + +/**** Private function definitions ***/ diff --git a/firmware/src/dccd/dccd_hw.h b/firmware/src/dccd/dccd_hw.h new file mode 100644 index 0000000..3ccdd0c --- /dev/null +++ b/firmware/src/dccd/dccd_hw.h @@ -0,0 +1,69 @@ +#ifndef DCCD_HW_H_ +#define DCCD_HW_H_ + +/**** Includes ****/ +#include +#include "../bsp/board.h" +#include "../utils/vcounter.h" +#include "../hw/button.h" +#include "../hw/led_display.h" +#include "../hw/potentiometer.h" +#include "../hw/out_driver.h" +#include "../hw/safe_ain.h" +#include "../hw/out_reg.h" + +namespace dccd { + +/**** Public definitions ****/ +class DccdHw +{ + public: + typedef struct { + uint8_t pwm_f_khz; + uint8_t handbrake_pull_up; + uint8_t speed_hall; + uint16_t counter_step_us; + } dccdHwCfg_t; + + DccdHw(void); + ~DccdHw(void); + + void init(dccdHwCfg_t* cfg); + + // Inputs + hw::SafeAin out_voltage; + hw::SafeAin out_current; + hw::SafeAin battery_voltage; + hw::SafeAin battery_current; + + hw::Button btn_up; + hw::Button btn_down; + hw::Button btn_mode; + hw::Button handbrake; + hw::Button brakes; + hw::Button dimm; + + hw::Potentiometer pot; + + // Outputs + hw::LedDisplay display; + hw::OutReg outreg; + + void read(void); + void write(void); + + #ifdef TESTING + protected: + #endif + bsp::Board board_hw; + util::VCounter counter; +}; + +/**** Public function declarations ****/ + +#ifdef TESTING +#endif + +} //namespace + +#endif /* DCCD_HW_H_ */ \ No newline at end of file diff --git a/firmware/src/hw/analog.c b/firmware/src/hw/analog.c deleted file mode 100644 index 8f8a291..0000000 --- a/firmware/src/hw/analog.c +++ /dev/null @@ -1,45 +0,0 @@ -/**** Includes ****/ -#include "board/utils/utils.h" -#include "board/ain.h" -#include "analog.h" - -/**** Private definitions ****/ -/**** Private constants ****/ -/**** Private variables ****/ -/**** Private function declarations ****/ -static uint8_t ain_mapping(uint8_t analog_ch, uint8_t* ain_ch); - -/**** Public function definitions ****/ -uint16_t analog_ch_get(uint8_t analog_ch) -{ - uint8_t ain_ch; - // Get channel config - if(ain_mapping(analog_ch, &ain_ch)) return 0; - - // Read input as mV - uint16_t ch_mv = bsp_ain_read(ain_ch); - - // Return result - return ch_mv; -} - -/**** Private function definitions ****/ -static uint8_t ain_mapping(uint8_t analog_ch, uint8_t* ain_ch) -{ - switch(analog_ch) - { - case ANALOG_1: // Pot - *ain_ch = BSP_AIN2; - return 0; - - case ANALOG_2: // Mode - *ain_ch = BSP_AIN1; - return 0; - - default: //Invalid channel - *ain_ch = BSP_AIN5; - return 1; - } - - return 1; -} diff --git a/firmware/src/hw/analog.h b/firmware/src/hw/analog.h deleted file mode 100644 index c09021b..0000000 --- a/firmware/src/hw/analog.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef ANALOG_H_ -#define ANALOG_H_ - -/* -*/ - -/**** Includes ****/ -#include - -/**** Public definitions ****/ -#define ANALOG_1 1 //Potentiometer -#define ANALOG_2 2 //Mode - -/**** Public function declarations ****/ -uint16_t analog_ch_get(uint8_t analog_ch); - -#ifdef TESTING -#endif - -#endif /* ANALOG_H_ */ \ No newline at end of file diff --git a/firmware/src/hw/board/ain.c b/firmware/src/hw/board/ain.c deleted file mode 100644 index a7c6230..0000000 --- a/firmware/src/hw/board/ain.c +++ /dev/null @@ -1,77 +0,0 @@ -/**** Includes ****/ -#include "utils/utils.h" -#include "mcu/mcu_hal.h" -#include "ain.h" - -/**** Private definitions ****/ -typedef struct { - uint8_t adc_ch; - uint8_t mul; - uint8_t div; - int16_t offset; -} ainchcfg_t; - -/**** Private constants ****/ -static const uint8_t MV_MUL = BSP_AIN_DEF_MV_MUL; -static const uint8_t MV_DIV = BSP_AIN_DEF_MV_DIV; -static const int16_t MV_OFFSET = BSP_AIN_DEF_MV_OFFSET; - -/**** Private variables ****/ - -/**** Private function declarations ****/ -static uint8_t ain_mapping(uint8_t ain_ch, ainchcfg_t* ain_ch_cfg); - -/**** Public function definitions ****/ -uint16_t bsp_ain_read(uint8_t ch) -{ - ainchcfg_t cfg; - // Get analog input config, and check validity - if(ain_mapping(ch, &cfg)) return 0; - - //Read ADC - uint16_t raw = mcu_adc_read(cfg.adc_ch); - - //Convert to mV - raw = util_convert_muldivoff(raw, cfg.mul, cfg.div, cfg.offset); - - // Return result - return raw; -} - -/**** Private function definitions ****/ -static uint8_t ain_mapping(uint8_t ain_ch, ainchcfg_t* ain_ch_cfg) -{ - // Default 10bit ADC with 5V reference to mV conversion - ain_ch_cfg->mul = MV_MUL; - ain_ch_cfg->div = MV_DIV; - ain_ch_cfg->offset = MV_OFFSET; - - switch(ain_ch) - { - case BSP_AIN1: // Mode - ain_ch_cfg->adc_ch = MCU_ADC5; - return 0; - - case BSP_AIN2: // Pot - ain_ch_cfg->adc_ch = MCU_ADC4; - return 0;; - - case BSP_AIN3: // MCU Temp - ain_ch_cfg->adc_ch = MCU_ADC8; - return 0; - - case BSP_AIN4: // MCU Internal reference - ain_ch_cfg->adc_ch = MCU_ADC14; - return 0; - - case BSP_AIN5: // MCU Ground - ain_ch_cfg->adc_ch = MCU_ADC15; - return 0; - - default: // Invalid channel - ain_ch_cfg->adc_ch = MCU_ADC15; - return 1; - } - - return 1; -} diff --git a/firmware/src/hw/board/ain.h b/firmware/src/hw/board/ain.h deleted file mode 100644 index a973f8c..0000000 --- a/firmware/src/hw/board/ain.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef AIN_H_ -#define AIN_H_ - -/* -AIN1 MODE -AIN2 POT -*/ - -/**** Includes ****/ -#include -#include "config.h" - -/**** Public definitions ****/ -#define BSP_AIN1 1 // Mode -#define BSP_AIN2 2 // Pot -#define BSP_AIN3 3 // MCU Temp -#define BSP_AIN4 4 // MCU Internal reference -#define BSP_AIN5 5 // MCU Ground - -/**** Public function declarations ****/ -uint16_t bsp_ain_read(uint8_t ch); - -#ifdef TESTING -#endif - -#endif /* AIN_H_ */ \ No newline at end of file diff --git a/firmware/src/hw/board/config.h b/firmware/src/hw/board/config.h deleted file mode 100644 index 851b087..0000000 --- a/firmware/src/hw/board/config.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef BSP_CONFIG_H_ -#define BSP_CONFIG_H_ - -/**** Includes ****/ -#include - -/**** Public definitions ****/ -#define BSP_AIN_DEF_MV_MUL 215 -#define BSP_AIN_DEF_MV_DIV 44 -#define BSP_AIN_DEF_MV_OFFSET 0 - -#define BSP_HB_MV_MUL BSP_AIN_DEF_MV_MUL -#define BSP_HB_MV_DIV BSP_AIN_DEF_MV_DIV -#define BSP_HB_MV_OFFSET BSP_AIN_DEF_MV_OFFSET - -#define BSP_HB_UDIV_MUL 20 -#define BSP_HB_UDIV_DIV 1 -#define BSP_HB_UDIV_OFFSET 0 - -#define BSP_HB_ISUP_MUL 235 -#define BSP_HB_ISUP_DIV 6 -#define BSP_HB_ISUP_OFFSET 0 - -#define BSP_HB_IOUT_MUL 215 -#define BSP_HB_IOUT_DIV 22 -#define BSP_HB_IOUT_OFFSET 0 - -/**** Public function declarations ****/ -#ifdef TESTING -#endif - -#endif /* BSP_CONFIG_H_ */ \ No newline at end of file diff --git a/firmware/src/hw/board/din.c b/firmware/src/hw/board/din.c deleted file mode 100644 index 3476e11..0000000 --- a/firmware/src/hw/board/din.c +++ /dev/null @@ -1,83 +0,0 @@ -/**** Includes ****/ -#include "utils/utils.h" -#include "mcu/mcu_hal.h" -#include "din.h" - -/**** Private definitions ****/ -typedef struct { - uint8_t gpio_ch; - uint8_t invert; -} dinchcfg_t; - -/**** Private constants ****/ -/**** Private variables ****/ -/**** Private function declarations ****/ -static uint8_t din_mapping(uint8_t din_ch, dinchcfg_t* din_ch_cfg); - -/**** Public function definitions ****/ -uint8_t bsp_din_read(uint8_t ch) -{ - dinchcfg_t cfg; - // Get digital input config, and check validity - if(din_mapping(ch, &cfg)) return BSP_DIN_LOW; - - //Read GPIO - uint8_t raw = mcu_gpio_read(cfg.gpio_ch); - - // Check config and invert - if(cfg.invert) raw = util_invert_8b(raw); - - // Return result - return raw; -} - -/**** Private function definitions ***/ -static uint8_t din_mapping(uint8_t din_ch, dinchcfg_t* din_ch_cfg) -{ - // By default ch is not inverted - din_ch_cfg->invert = 0; - - switch(din_ch) - { - case BSP_DIN1: //Mode - din_ch_cfg->gpio_ch = MCU_GPIO0; - return 0; - - case BSP_DIN2: //Pot - din_ch_cfg->gpio_ch = MCU_GPIO1; - return 0; - - case BSP_DIN3: //Down - din_ch_cfg->gpio_ch = MCU_GPIO2; - return 0; - - case BSP_DIN4: //Up - din_ch_cfg->gpio_ch = MCU_GPIO3; - return 0; - - case BSP_DIN5: //Dimm - din_ch_cfg->gpio_ch = MCU_GPIO4; - din_ch_cfg->invert = 1; - return 0; - - case BSP_DIN6: //Brakes - din_ch_cfg->gpio_ch = MCU_GPIO5; - din_ch_cfg->invert = 1; - return 0; - - case BSP_DIN7: //Handbrake - din_ch_cfg->gpio_ch = MCU_GPIO6; - din_ch_cfg->invert = 1; - return 0; - - case BSP_DIN7N: //Handbrake pull - din_ch_cfg->gpio_ch = MCU_GPIO7; - return 0; - - default: //Invalid channel - din_ch_cfg->gpio_ch = 0; - return 1; - } - - return 1; -} diff --git a/firmware/src/hw/board/din.h b/firmware/src/hw/board/din.h deleted file mode 100644 index 6a74fe2..0000000 --- a/firmware/src/hw/board/din.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef DIN_H_ -#define DIN_H_ - -/* -DIN1 MODE -DIN2 POT -DIN3 DOWN -DIN4 UP -DIN5 HV DIM -DIN6 HV BRAKES -DIN7 HV HANDBRAKE -DIN8 HBRAKE PULL -*/ - -/**** Includes ****/ -#include - -/**** Public definitions ****/ -#define BSP_DIN1 1 -#define BSP_DIN2 2 -#define BSP_DIN3 3 -#define BSP_DIN4 4 -#define BSP_DIN5 5 -#define BSP_DIN6 6 -#define BSP_DIN7 7 -#define BSP_DIN7N 8 - -#define BSP_DIN_LOW 0 -#define BSP_DIN_HIGH 1 - -/**** Public function declarations ****/ -uint8_t bsp_din_read(uint8_t ch); - -#ifdef TESTING -#endif - -#endif /* DIN_H_ */ \ No newline at end of file diff --git a/firmware/src/hw/board/dout.c b/firmware/src/hw/board/dout.c deleted file mode 100644 index 9a5214c..0000000 --- a/firmware/src/hw/board/dout.c +++ /dev/null @@ -1,58 +0,0 @@ -/**** Includes ****/ -#include "utils/utils.h" -#include "mcu/mcu_hal.h" -#include "dout.h" - -/**** Private definitions ****/ -/**** Private constants ****/ -/**** Private variables ****/ -/**** Private function declarations ****/ -static uint8_t dout_mapping(uint8_t dout_ch, uint8_t* gpio_ch); - -/**** Public function definitions ****/ -void bsp_dout_write(uint8_t ch, int8_t lvl) -{ - uint8_t gpio_ch; - // Get digital input config, and check validity - if(dout_mapping(ch, &gpio_ch)) return; - - // Write GPIO - mcu_gpio_write(gpio_ch, lvl); -} - -/**** Private function definitions ***/ -static uint8_t dout_mapping(uint8_t dout_ch, uint8_t* gpio_ch) -{ - switch(dout_ch) - { - case BSP_DOUT1: //Mode - *gpio_ch = MCU_GPIO0; - return 0; - - case BSP_DOUT2: //Pot - *gpio_ch = MCU_GPIO1; - return 0; - - case BSP_DOUT3: //Down - *gpio_ch = MCU_GPIO2; - return 0; - - case BSP_DOUT4: //Up - *gpio_ch = MCU_GPIO3; - return 0; - - case BSP_DOUT5: //Handbrake pull - *gpio_ch = MCU_GPIO7; - return 0; - - case BSP_DOUT6: //Speed pull - *gpio_ch = MCU_GPIO8; - return 0; - - default: //Invalid channel - *gpio_ch = 0; - return 1; - } - - return 1; -} diff --git a/firmware/src/hw/board/dout.h b/firmware/src/hw/board/dout.h deleted file mode 100644 index adbbef8..0000000 --- a/firmware/src/hw/board/dout.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef DOUT_H_ -#define DOUT_H_ - -/* -DOUT1 MODE -DOUT2 POT -DOUT3 DOWN -DOUT4 UP -DOUT5 HBRAKE PULL -DOUT6 SPEED PULL -*/ - -/**** Includes ****/ -#include - -/**** Public definitions ****/ -#define BSP_DOUT1 1 -#define BSP_DOUT2 2 -#define BSP_DOUT3 3 -#define BSP_DOUT4 4 -#define BSP_DOUT5 5 -#define BSP_DOUT6 6 - -#define BSP_DOUT_LOW 0 -#define BSP_DOUT_HIGH 1 -#define BSP_DOUT_HIZ -1 - -/**** Public function declarations ****/ -void bsp_dout_write(uint8_t ch, int8_t lvl); - -#ifdef TESTING -#endif - -#endif /* DOUT_H_ */ \ No newline at end of file diff --git a/firmware/src/hw/board/halfbridge.c b/firmware/src/hw/board/halfbridge.c deleted file mode 100644 index 3789d03..0000000 --- a/firmware/src/hw/board/halfbridge.c +++ /dev/null @@ -1,179 +0,0 @@ -/**** Includes ****/ -#include "utils/utils.h" -#include "mcu/mcu_hal.h" -#include "halfbridge.h" - -/**** Private definitions ****/ -typedef struct { - uint8_t adc_ch; - uint8_t mul; - uint8_t div; - int16_t offset; -} ainchcfg_t; - -typedef enum { - AIN_OUT_VOLTAGE, - AIN_OUT_CURRENT, - AIN_SUP_VOLTAGE, - AIN_SUP_CURRENT -} hb_ainch_t; - -/**** Private constants ****/ -// Analog channels conversion coefficients -static const uint8_t MV_MUL = BSP_HB_MV_MUL; -static const uint8_t MV_DIV = BSP_HB_MV_DIV; -static const int16_t MV_OFFSET = BSP_HB_MV_OFFSET; - -static const uint8_t UDIV_MUL = BSP_HB_UDIV_MUL; -static const uint8_t UDIV_DIV = BSP_HB_UDIV_DIV; -static const int16_t UDIV_OFFSET = BSP_HB_UDIV_OFFSET; - -static const uint8_t ISUP_MUL = BSP_HB_ISUP_MUL; -static const uint8_t ISUP_DIV = BSP_HB_ISUP_DIV; -static const int16_t ISUP_OFFSET = BSP_HB_ISUP_OFFSET; - -static const uint8_t IOUT_MUL = BSP_HB_IOUT_MUL; -static const uint8_t IOUT_DIV = BSP_HB_IOUT_DIV; -static const int16_t IOUT_OFFSET = BSP_HB_IOUT_OFFSET; - -/**** Private variables ****/ - -/**** Mapping function declarations ****/ -static uint8_t hb_pwm_mapping(uint8_t* pwm_ch); -static uint8_t hb_low_side_mapping(uint8_t* gpio_ch); -static uint8_t hb_ain_mapping(hb_ainch_t ain_ch, ainchcfg_t* ain_ch_cfg); - -/**** Private function declarations ****/ -static uint16_t limit_pwm(uint16_t pwm_in); -static uint16_t read_ain(hb_ainch_t ch); - -/**** Public function definitions ****/ -void bsp_hb_write_low(uint8_t state) -{ - uint8_t gpio_ch; - // Get GPIO channel, and check validity - if(hb_low_side_mapping(&gpio_ch)) return; - - // Set low side on or off - if(state) mcu_gpio_write(gpio_ch, MCU_GPIO_HIGH); - else mcu_gpio_write(gpio_ch, MCU_GPIO_LOW); -} - -void bsp_hb_write_pwm(uint16_t pwm) -{ - uint8_t pwm_ch; - // Get PWM channel, and check validity - if(hb_pwm_mapping(&pwm_ch)) return; - - // Limit PWM, because of charge pump - pwm = limit_pwm(pwm); - - // Set pwm - mcu_pwm_write(pwm_ch, pwm); -} - -void bsp_hb_read_meas(hb_meas_t* measurements) -{ - // Read analog inputs - measurements->out_voltage = read_ain(AIN_OUT_VOLTAGE); - measurements->out_current = read_ain(AIN_OUT_CURRENT); - measurements->sup_voltage = read_ain(AIN_SUP_VOLTAGE); - measurements->sup_current = read_ain(AIN_SUP_CURRENT); - - // Calculate secondary measurements - measurements->out_power = util_sat_mul_kilo(measurements->out_voltage, measurements->out_current); - measurements->sup_power = util_sat_mul_kilo(measurements->sup_voltage, measurements->sup_current); - - measurements->out_impedance = util_sat_div_kilo(measurements->out_voltage, measurements->out_current); - - uint8_t ch; - //Read low side control GPIO level - if(hb_low_side_mapping(&ch)) measurements->low_side_ctrl = 0; - else measurements->low_side_ctrl = mcu_gpio_read(ch); - - //Read PWM duty cycle in 16b format - if(hb_pwm_mapping(&ch)) measurements->pwm = 0; - else measurements->pwm = mcu_pwm_read(ch); -} - -/**** Private function declarations ****/ -static uint16_t read_ain(hb_ainch_t ch) -{ - ainchcfg_t cfg; - // Get analog input config, and check validity - if(hb_ain_mapping(ch, &cfg)) return 0; - - //Read ADC - uint16_t raw = mcu_adc_read(cfg.adc_ch); - - //Convert to target units - raw = util_convert_muldivoff(raw, cfg.mul, cfg.div, cfg.offset); - - // Return result - return raw; -} - -static uint16_t limit_pwm(uint16_t pwm_in) -{ - // Limit to ~95% - if (pwm_in > 0xFC00) return 0xFC00; - else return pwm_in; -} - -/**** Mapping function definitions ****/ -static uint8_t hb_pwm_mapping(uint8_t* pwm_ch) -{ - *pwm_ch = MCU_PWM0; - return 0; -} - -static uint8_t hb_low_side_mapping(uint8_t* gpio_ch) -{ - *gpio_ch = MCU_GPIO15; - return 0; -} - -static uint8_t hb_ain_mapping(hb_ainch_t ain_ch, ainchcfg_t* ain_ch_cfg) -{ - switch(ain_ch) - { - case AIN_OUT_VOLTAGE: - ain_ch_cfg->adc_ch = MCU_ADC1; - ain_ch_cfg->mul = UDIV_MUL; - ain_ch_cfg->div = UDIV_DIV; - ain_ch_cfg->offset = UDIV_OFFSET; - return 0; - - case AIN_OUT_CURRENT: - ain_ch_cfg->adc_ch = MCU_ADC0; - ain_ch_cfg->mul = IOUT_MUL; - ain_ch_cfg->div = IOUT_DIV; - ain_ch_cfg->offset = IOUT_OFFSET; - return 0; - - case AIN_SUP_VOLTAGE: - ain_ch_cfg->adc_ch = MCU_ADC2; - ain_ch_cfg->mul = UDIV_MUL; - ain_ch_cfg->div = UDIV_DIV; - ain_ch_cfg->offset = UDIV_OFFSET; - return 0; - - case AIN_SUP_CURRENT: - ain_ch_cfg->adc_ch = MCU_ADC3; - ain_ch_cfg->mul = ISUP_MUL; - ain_ch_cfg->div = ISUP_DIV; - ain_ch_cfg->offset = ISUP_OFFSET; - return 0; - - default: //Invalid channel - ain_ch_cfg->adc_ch = MCU_ADC15; - // Default 10bit ADC with 5V reference to mV conversion - ain_ch_cfg->mul = MV_MUL; - ain_ch_cfg->div = MV_DIV; - ain_ch_cfg->offset = MV_OFFSET; - return 1; - } - - return 1; -} - diff --git a/firmware/src/hw/board/halfbridge.h b/firmware/src/hw/board/halfbridge.h deleted file mode 100644 index bf5e1a7..0000000 --- a/firmware/src/hw/board/halfbridge.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef HALFBRIDGE_H_ -#define HALFBRIDGE_H_ - -/* -*/ - -/**** Includes ****/ -#include -#include "config.h" - -/**** Public definitions ****/ -typedef struct { - uint16_t out_voltage; - uint16_t out_current; - uint16_t sup_voltage; - uint16_t sup_current; - uint16_t out_power; - uint16_t sup_power; - uint16_t out_impedance; - uint8_t low_side_ctrl; - uint16_t pwm; -} hb_meas_t; - -/**** Public function declarations ****/ -void bsp_hb_write_low(uint8_t state); -void bsp_hb_write_pwm(uint16_t pwm); - -// Feedback functions -void bsp_hb_read_meas(hb_meas_t* measurements); - -#ifdef TESTING -#endif - -#endif /* HALFBRIDGE_H_ */ diff --git a/firmware/src/hw/board/mcu/mcu_hal.h b/firmware/src/hw/board/mcu/mcu_hal.h deleted file mode 100644 index 010fad2..0000000 --- a/firmware/src/hw/board/mcu/mcu_hal.h +++ /dev/null @@ -1,120 +0,0 @@ -#ifndef MCU_HAL_H_ -#define MCU_HAL_H_ - -/**** Includes ****/ -#include - -/**** Public definitions ****/ -/* -GPIO0 Down -GPIO1 Up -GPIO2 Mode -GPIO3 Handbrake -GPIO4 Brakes -GPIO5 Dimm -GPIO6 LED0 -GPIO7 LED1 -GPIO8 LED2 -GPIO9 LED3 -GPIO10 LED4 -GPIO11 LED5 -GPIO12 DCCD Enable -GPIO13 Handbrake pull -GPIO14 Speed pull -GPIO15 DCCD PWM -GPIO16 LED PWM - -ADC0 Output current -ADC1 Output voltage -ADC2 Battery current -ADC3 Battery voltage -ADC4 Potentiometer -ADC5 Mode -ADC8 MCU temperature -ADC14 MCU internal reference -ADC15 MCU ground -*/ - -#define MCU_GPIO0 0 //Mode -#define MCU_GPIO1 1 //Pot -#define MCU_GPIO2 2 //Down -#define MCU_GPIO3 3 //Up -#define MCU_GPIO4 4 //Dimm -#define MCU_GPIO5 5 //Brakes -#define MCU_GPIO6 6 //Handbrake -#define MCU_GPIO7 7 //Handbrake pull -#define MCU_GPIO8 8 //Speed pull -#define MCU_GPIO9 9 //LED0 -#define MCU_GPIO10 10 //LED1 -#define MCU_GPIO11 11 //LED2 -#define MCU_GPIO12 12 //LED3 -#define MCU_GPIO13 13 //LED4 -#define MCU_GPIO14 14 //LED5 -#define MCU_GPIO15 15 //DCCD Enable -#define MCU_GPIO16 16 //DCCD PWM -#define MCU_GPIO17 17 //LED PWM - -#define MCU_GPIO_LOW 0 -#define MCU_GPIO_HIGH 1 -#define MCU_GPIO_HIZ -1 - -#define MCU_ADC0 0 //Output current -#define MCU_ADC1 1 //Output voltage -#define MCU_ADC2 2 //Battery voltage -#define MCU_ADC3 3 //Battery current -#define MCU_ADC4 4 //Potentiometer -#define MCU_ADC5 5 //Mode -#define MCU_ADC8 8 //MCU temperature -#define MCU_ADC14 14 //MCU internal reference -#define MCU_ADC15 15 //MCU ground - -#define MCU_PWM0 0 //DCCD -#define MCU_PWM1 1 //LED - -//ADC definitions -typedef enum { - MCU_ADC_DIV2 = 0x01, - MCU_ADC_DIV4 = 0x02, - MCU_ADC_DIV8 = 0x03, - MCU_ADC_DIV16 = 0x04, - MCU_ADC_DIV32 = 0x05, - MCU_ADC_DIV64 = 0x06, - MCU_ADC_DIV128 = 0x07 -} adcClkDiv_t; - -//Timer definitions -typedef enum { - MCU_TIM_DIV1 = 0x01, - MCU_TIM_DIV8 = 0x02, - MCU_TIM_DIV64 = 0x03, - MCU_TIM_DIV256 = 0x04, - MCU_TIM_DIV1024 = 0x05 -} timerClkDiv_t; - -typedef struct { - adcClkDiv_t adc_clk; - timerClkDiv_t pwm_clk; - uint16_t pwm_top; - uint8_t pwm_chb_en; -} startupCfg_t; - -/**** Public function declarations ****/ -void mcu_startup(startupCfg_t* hwCfg); - -uint8_t mcu_gpio_read(uint8_t ch); -void mcu_gpio_write(uint8_t ch, int8_t lvl); - -uint16_t mcu_adc_read(uint8_t ch); - -void mcu_pwm_write(uint8_t ch, uint16_t dc); -uint16_t mcu_pwm_read(uint8_t ch); - -uint8_t mcu_ee_read8b(uint16_t address); -uint16_t mcu_ee_read16b(uint16_t address); -uint32_t mcu_ee_read32b(uint16_t address); - -void mcu_ee_write8b(uint16_t address, uint8_t value); -void mcu_ee_write16b(uint16_t address, uint16_t value); -void mcu_ee_write32b(uint16_t address, uint32_t value); - -#endif /* MCU_HAL_H_ */ diff --git a/firmware/src/hw/board/odout.c b/firmware/src/hw/board/odout.c deleted file mode 100644 index f5fda12..0000000 --- a/firmware/src/hw/board/odout.c +++ /dev/null @@ -1,80 +0,0 @@ -/**** Includes ****/ -#include "utils/utils.h" -#include "mcu/mcu_hal.h" -#include "odout.h" - -/**** Private definitions ****/ -/**** Private constants ****/ -/**** Private variables ****/ -/**** Private function declarations ****/ -static uint8_t odout_pwm_mapping(uint8_t* pwm_ch); -static uint8_t odout_mapping(uint8_t od_ch, uint8_t* gpio_ch); - - -/**** Public function definitions ****/ -void bsp_odout_write(uint8_t ch, int8_t lvl) -{ - uint8_t gpio_ch; - // Get GPIO channel config, and check validity - if(odout_mapping(ch, &gpio_ch)) return; - - // Set output level - if(lvl==0) mcu_gpio_write(gpio_ch, 1); // Output active - else mcu_gpio_write(gpio_ch, 0); // Output off -} - -void bsp_odout_write_common(uint8_t percent) -{ - uint8_t pwm_ch; - // Get PWM channel config, and check validity - if(odout_pwm_mapping(&pwm_ch)) return; - - // Convert percent to 16b duty cycle - uint16_t dc = util_percent_to_16b(percent); - - // Set PWM - mcu_pwm_write(pwm_ch, dc); -} - -/**** Private function definitions ****/ -static uint8_t odout_pwm_mapping(uint8_t* pwm_ch) -{ - *pwm_ch = MCU_PWM1; - return 0; -} - -static uint8_t odout_mapping(uint8_t od_ch, uint8_t* gpio_ch) -{ - switch(od_ch) - { - case BSP_OD1: // LED0 - *gpio_ch = MCU_GPIO9; - return 0; - - case BSP_OD2: // LED1 - *gpio_ch = MCU_GPIO10; - return 0; - - case BSP_OD3: // LED2 - *gpio_ch = MCU_GPIO11; - return 0; - - case BSP_OD4: // LED3 - *gpio_ch = MCU_GPIO12; - return 0; - - case BSP_OD5: // LED4 - *gpio_ch = MCU_GPIO13; - return 0; - - case BSP_OD6: // LED5 - *gpio_ch = MCU_GPIO14; - return 0; - - default: //Invalid channel - *gpio_ch = 0; - return 1; - } - - return 1; -} diff --git a/firmware/src/hw/board/odout.h b/firmware/src/hw/board/odout.h deleted file mode 100644 index 0d7ad5e..0000000 --- a/firmware/src/hw/board/odout.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef ODOUT_H_ -#define ODOUT_H_ - -/* -OD1 LED 0 -OD2 LED 1 -OD3 LED 2 -OD4 LED 3 -OD5 LED 4 -OD6 LED 5 - -COMMON LED PWM -*/ - -/**** Includes ****/ -#include - -/**** Public definitions ****/ -#define BSP_OD1 1 -#define BSP_OD2 2 -#define BSP_OD3 3 -#define BSP_OD4 4 -#define BSP_OD5 5 -#define BSP_OD6 6 - -#define BSP_ODOUT_LOW 0 -#define BSP_ODOUT_HIGH 1 -#define BSP_ODOUT_HIZ -1 - -/**** Public function declarations ****/ -void bsp_odout_write(uint8_t ch, int8_t lvl); -void bsp_odout_write_common(uint8_t percent); - -#ifdef TESTING -#endif - -#endif /* ODOUT_H_ */ \ No newline at end of file diff --git a/firmware/src/hw/board/setup.c b/firmware/src/hw/board/setup.c deleted file mode 100644 index 5f13cc4..0000000 --- a/firmware/src/hw/board/setup.c +++ /dev/null @@ -1,23 +0,0 @@ -/**** Includes ****/ -#include "utils/utils.h" -#include "mcu/mcu_hal.h" -#include "setup.h" - -/**** Private definitions ****/ -/**** Private constants ****/ -/**** Private variables ****/ -/**** Private function declarations ****/ -/**** Public function definitions ****/ - -/**** Private function definitions ****/ -void bsp_startup(void) -{ - startupCfg_t mcu_cfg; - - mcu_cfg.adc_clk = MCU_ADC_DIV2; - mcu_cfg.pwm_clk = MCU_TIM_DIV1; - mcu_cfg.pwm_top = 511; - mcu_cfg.pwm_chb_en = 1; - - mcu_startup(&mcu_cfg); -} \ No newline at end of file diff --git a/firmware/src/hw/board/setup.h b/firmware/src/hw/board/setup.h deleted file mode 100644 index c9e5bf8..0000000 --- a/firmware/src/hw/board/setup.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef BSP_SETUP_H_ -#define BSP_SETUP_H_ - -/**** Includes ****/ -#include - -/**** Public definitions ****/ -/**** Public function declarations ****/ -void bsp_startup(void); - -#ifdef TESTING -#endif - -#endif /* BSP_SETUP_H_ */ \ No newline at end of file diff --git a/firmware/src/hw/board/utils/faults.c b/firmware/src/hw/board/utils/faults.c deleted file mode 100644 index 02a04e5..0000000 --- a/firmware/src/hw/board/utils/faults.c +++ /dev/null @@ -1,67 +0,0 @@ -/**** Includes ****/ -#include "faults.h" -#include "utils.h" - -/**** Private definitions ****/ -/**** Private constants ****/ -/**** Private variables ****/ -/**** Mapping function declarations ****/ -/**** Private function declarations ****/ -/**** Public function definitions ****/ -#ifdef TESTING -#endif - -uint8_t fault_process(fault_t* fault, uint8_t w_trig, uint8_t f_trig, fault_cfg_t* cfg) -{ - // Override warning trigger in case of fault trigger - if(f_trig) w_trig = 1; - - // Increase warning time, if reoccurring - if((w_trig)&&(fault->severity != FAULT_LVL_OK)) fault->w_time = util_sat_add_16b(fault->w_time, 1); - else fault->w_time = 0; - - // Check if waring can be considered fault - if((cfg->wtof > 0)&&(fault->w_time > cfg->wtof)) f_trig = 1; - - // Increase fault time, if reoccurring - if((f_trig)&&(fault->severity != FAULT_LVL_OK)) fault->f_time = util_sat_add_16b(fault->f_time, 1); - else fault->f_time = 0; - - // Modify fault trigger - if((cfg->delay)&&(fault->f_time < cfg->delay)) f_trig = 0; - - // Process fault level - if(f_trig) - { - fault->severity = FAULT_LVL_FAULT; - return 1; - } - else - { - if(w_trig) fault->severity = FAULT_LVL_WARNING; - else fault->severity = FAULT_LVL_OK; - } - - return 0; -} - -uint8_t fault_is_active(fault_t* fault) -{ - if(fault->severity == FAULT_LVL_FAULT) return 1; - else return 0; -} - -uint8_t fault_is_warning(fault_t* fault) -{ - if(fault->severity != FAULT_LVL_OK) return 1; - else return 0; -} - -void fault_reset(fault_t* fault) -{ - fault->severity = FAULT_LVL_OK; - fault->w_time = 0; - fault->f_time = 0; -} - -/**** Private function definitions ****/ diff --git a/firmware/src/hw/board/utils/faults.h b/firmware/src/hw/board/utils/faults.h deleted file mode 100644 index 2a89077..0000000 --- a/firmware/src/hw/board/utils/faults.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef FAULTS_H_ -#define FAULTS_H_ - -/* -*/ - -/**** Includes ****/ -#include - -/**** Public definitions ****/ -typedef enum { - FAULT_LVL_OK, - FAULT_LVL_WARNING, - FAULT_LVL_FAULT -} fault_lvl_t; - -typedef struct { - fault_lvl_t severity; - uint16_t w_time; - uint16_t f_time; -} fault_t; - -typedef struct { - uint16_t delay; - uint16_t wtof; -} fault_cfg_t; - -/**** Public function declarations ****/ -uint8_t fault_process(fault_t* fault, uint8_t w_trig, uint8_t f_trig, fault_cfg_t* cfg); -uint8_t fault_is_active(fault_t* fault); -uint8_t fault_is_warning(fault_t* fault); -void fault_reset(fault_t* fault); - -#ifdef TESTING -#endif - -#endif /* FAULTS_H_ */ \ No newline at end of file diff --git a/firmware/src/hw/board/utils/fuses.c b/firmware/src/hw/board/utils/fuses.c deleted file mode 100644 index 997f586..0000000 --- a/firmware/src/hw/board/utils/fuses.c +++ /dev/null @@ -1,81 +0,0 @@ -/**** Includes ****/ -#include "fuses.h" -#include "utils.h" - -/**** Private definitions ****/ -/**** Private constants ****/ -/**** Private variables ****/ -/**** Mapping function declarations ****/ -/**** Private function declarations ****/ -/**** Public function definitions ****/ -#ifdef TESTING -#endif - -void fuse_reset(fuse_t* fuse) -{ - fuse->state = FUSE_OFF; - fuse->timer = 0; - fuse->count = 0; -} - -uint8_t fuse_process(fuse_t* fuse, uint8_t fault, fuse_cfg_t* cfg) -{ - // Active fault condition - if(fault) - { - // Note fuse time count - if((fuse->state == FUSE_OFF)||(fuse->state == FUSE_RETRY)) fuse->count++; - - // Go to fused state in any case - fuse->state = FUSE_ACTIVE; - fuse->timer = 0; - return 1; - }; - - // No active fault condition - if(fuse->state==FUSE_ACTIVE) - { - // Go to cooldown - fuse->state = FUSE_COOLDOWN; - fuse->timer = cfg->cooldown_time; - }; - - // Wait for timeout - if(fuse->timer) - { - fuse->timer--; - if(fuse->state == FUSE_RETRY) return 0; - else return 1; - }; - - // Timeout end, transition logic - switch(fuse->state) - { - case FUSE_COOLDOWN: - // Cooldown end - if(cfg->retry_time) - { - fuse->state = FUSE_RETRY; - fuse->timer = cfg->retry_time; - } - else - { - fuse->state = FUSE_OFF; - fuse->timer = 0; - } - break; - - case FUSE_RETRY: - // Go back to normal - fuse->state = FUSE_OFF; - break; - - default: - // Nothing to do - break; - } - - return 0; -} - -/**** Private function definitions ****/ diff --git a/firmware/src/hw/board/utils/fuses.h b/firmware/src/hw/board/utils/fuses.h deleted file mode 100644 index 49f3ce8..0000000 --- a/firmware/src/hw/board/utils/fuses.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef FUSES_H_ -#define FUSES_H_ - -/* -*/ - -/**** Includes ****/ -#include - -/**** Public definitions ****/ -typedef enum { - FUSE_OFF, - FUSE_ACTIVE, - FUSE_COOLDOWN, - FUSE_RETRY -} fuse_state_t; - -typedef struct { - fuse_state_t state; - uint8_t count; - uint16_t timer; -} fuse_t; - -typedef struct { - uint16_t cooldown_time; - uint16_t retry_time; -} fuse_cfg_t; - -/**** Public function declarations ****/ -void fuse_reset(fuse_t* fuse); -uint8_t fuse_process(fuse_t* fuse, uint8_t fault, fuse_cfg_t* cfg); - -#ifdef TESTING -#endif - -#endif /* FUSES_H_ */ \ No newline at end of file diff --git a/firmware/src/hw/board/utils/utils.c b/firmware/src/hw/board/utils/utils.c deleted file mode 100644 index e1f673d..0000000 --- a/firmware/src/hw/board/utils/utils.c +++ /dev/null @@ -1,272 +0,0 @@ -/**** Includes ****/ -#include "utils.h" - -/**** Private definitions ****/ -/**** Private constants ****/ -/**** Private variables ****/ -/**** Private function declarations ****/ -#ifndef TESTING -static uint8_t find_interval_end_index(uint16_t val, uint16_t* axis_values, uint8_t len_axis); -static uint16_t interpolate_u16b(uint16_t x, uint16_t x0, uint16_t x1, uint16_t y0, uint16_t y1); -static uint16_t index2d_to_index1d(uint8_t ix, uint8_t iy, uint8_t len_x); -#endif - -/**** Public function definitions ****/ -uint8_t util_invert_8b(uint8_t x) -{ - if(x!=0) return 0; - else return 1; -} - -uint8_t util_sat_add_8b(uint8_t x, uint8_t y) -{ - uint8_t z = x + y; - // Check for overflow - if((z < x)||(z < y)) return 0xFF; - else return z; -} - -uint8_t util_sat_subtract_8b(uint8_t x, uint8_t y) -{ - uint8_t z = x - y; - // Check for underflow - if(z > x) return 0; - else return z; -} - -uint16_t util_sat_add_16b(uint16_t x, uint16_t y) -{ - uint16_t z = x + y; - // Check for overflow - if((z < x)||(z < y)) return 0xFFFF; - else return z; -} - -uint16_t util_sat_subtract_16b(uint16_t x, uint16_t y) -{ - uint16_t z = x - y; - // Check for underflow - if(z > x) return 0; - else return z; -} - -uint16_t util_limit_u32b_to_u16b(uint32_t in) -{ - if(in == 0) return 0; - else if(in >= 0x0000FFFF) return 0xFFFF; - else return (uint16_t)in; -} - -uint16_t util_limit_s32b_to_u16b(int32_t in) -{ - if(in <= 0) return 0; - else if(in >= 0x0000FFFF) return 0xFFFF; - else return (uint16_t)in; -} - -uint16_t util_convert_muldivoff(uint16_t raw, uint8_t mul, uint8_t div, int16_t offset) -{ - int32_t temp = (int32_t)raw; - - temp = temp * mul; - if(div>1) temp /= div; - temp += offset; - - return util_limit_s32b_to_u16b(temp); -} - -uint16_t util_sat_mul_kilo(uint16_t xk, uint16_t yk) -{ - uint32_t temp = (uint32_t)xk * (uint32_t)yk; - temp /= 1000; - - return util_limit_u32b_to_u16b(temp); -} - -uint16_t util_sat_div_kilo(uint16_t top, uint16_t bot) -{ - //Sanity check bot - if(bot==0) return 0xFFFF; //aka infinity - - uint32_t temp = (uint32_t)top * 1000; - temp /= (uint32_t)bot; - - return util_limit_u32b_to_u16b(temp); -} - -uint16_t util_sat_ratio_16b(uint16_t top, uint16_t bot) -{ - //Sanity check bot - if(bot==0) return 0xFFFF; //aka infinity - - //Easy option - if(top>=bot) return 0xFFFF; - - uint32_t temp = (uint32_t)top * 0x0000FFFF; - temp /= (uint32_t)bot; - - return util_limit_u32b_to_u16b(temp); -} - -uint16_t util_percent_to_16b(uint8_t percent) -{ - uint32_t temp = (uint32_t)percent * 0x0000FFFF; - temp /= 100; - - // Limit to 16 bits - uint16_t pwm = util_limit_u32b_to_u16b(temp); - - return pwm; -} - -uint16_t util_interpolate_1d_u16b(uint16_t x, uint16_t* x_axis, uint16_t* y_values, uint8_t len_axis) -{ - // validate axis length - if(len_axis==0) return 0; // Empty data set - if(len_axis==1) return y_values[0]; // Only one data point - - uint16_t y; - - uint8_t i = find_interval_end_index(x, x_axis, len_axis); - if(i==0) - { - //Less then start - y = y_values[0]; - } - else if(i==len_axis) - { - //More than end - y = y_values[len_axis-1]; - } - else - { - // Do interpolate - y = interpolate_u16b(x, x_axis[i-1], x_axis[i], y_values[i-1], y_values[i]); - } - - return y; -} - -uint16_t util_interpolate_2d_u16b(uint16_t x, uint16_t y, uint16_t* x_axis, uint8_t len_x_axis, uint16_t* y_axis, uint8_t len_y_axis, uint16_t* z_values) -{ - // validate axis length - if((len_x_axis==0)&&(len_y_axis==0)) return 0; // Empty data set - if((len_x_axis==1)&&(len_y_axis==1)) return z_values[0]; // Only one data point - - uint8_t ix = find_interval_end_index(x, x_axis, len_x_axis); - uint8_t iy = find_interval_end_index(y, y_axis, len_y_axis); - - // Check corners - easy answers - if((ix==0)&&(iy==0)) - { - return z_values[0]; //[0][0] [Y][X] - } - else if((ix==len_x_axis)&&(iy==0)) - { - return z_values[len_x_axis-1]; //[0][end] - } - else if((ix==0)&&(iy==len_y_axis)) - { - uint16_t i = index2d_to_index1d(0, len_y_axis-1, len_x_axis); - return z_values[i]; //[end][0] - } - else if((ix==len_x_axis)&&(iy==len_y_axis)) - { - uint16_t i = index2d_to_index1d(len_x_axis-1, len_y_axis-1, len_x_axis); - return z_values[i]; //[end][end] - }; - - // Check boundaries - 1D interpolation - if(ix==0) - { - // On ix=0 line - uint16_t i = 0; - uint16_t z0 = z_values[i]; - i = index2d_to_index1d(0, len_y_axis-1, len_x_axis); - uint16_t z1 = z_values[i]; - return interpolate_u16b(y, y_axis[0], y_axis[len_y_axis-1], z0, z1); - } - else if(ix==len_x_axis) - { - // On ix=END line - uint16_t i = len_x_axis-1; - uint16_t z0 = z_values[i]; - i = index2d_to_index1d(len_x_axis-1, len_y_axis-1, len_x_axis); - uint16_t z1 = z_values[i]; - return interpolate_u16b(y, y_axis[0], y_axis[len_y_axis-1], z0, z1); - } - else if(iy==0) - { - // On iy=0 line - uint16_t i = 0; - uint16_t z0 = z_values[i]; - i = len_x_axis-1; - uint16_t z1 = z_values[i]; - return interpolate_u16b(x, x_axis[0], x_axis[len_x_axis-1], z0, z1); - } - else if(iy==len_y_axis) - { - // On iy=END line - uint16_t i = index2d_to_index1d(0, len_y_axis-1, len_x_axis); - uint16_t z0 = z_values[i]; - i = index2d_to_index1d(len_x_axis-1, len_y_axis-1, len_x_axis); - uint16_t z1 = z_values[i]; - return interpolate_u16b(x, x_axis[0], x_axis[len_x_axis-1], z0, z1); - } - - // Do interpolation - // Get axis values - uint16_t x0 = x_axis[ix-1]; - uint16_t x1 = x_axis[ix]; - uint16_t y0 = y_axis[iy-1]; - uint16_t y1 = y_axis[iy]; - - // Do y0 line calculation - // Get z values at x0 and x1 points on y0 line - uint16_t i = index2d_to_index1d(ix-1, iy-1, len_x_axis); - uint16_t z0 = z_values[i]; - uint16_t z1 = z_values[i+1]; - // Interpolate z value on y0 line - uint16_t zy0 = interpolate_u16b(x, x0, x1, z0, z1); - - // Do y1 line calculation - // Get z values at x0 and x1 points on y1 line - i = index2d_to_index1d(ix-1, iy, len_x_axis); - z0 = z_values[i]; - z1 = z_values[i+1]; - // Interpolate z value on y0 line - uint16_t zy1 = interpolate_u16b(x, x0, x1, z0, z1); - - // Do calculation in y axis on xz line - return interpolate_u16b(y, y0, y1, zy0, zy1); -} - -/**** Private function definitions ****/ -static uint16_t interpolate_u16b(uint16_t x, uint16_t x0, uint16_t x1, uint16_t y0, uint16_t y1) -{ - int32_t dy = (int32_t)y1 - (int32_t)y0; - int32_t dx = (int32_t)x1 - (int32_t)x0; - int32_t d = (int32_t)x - (int32_t)x0; - - int32_t y = dy * d; - y /= dx; - y += y0; - - return util_limit_s32b_to_u16b(y); -} - -static uint8_t find_interval_end_index(uint16_t val, uint16_t* axis_values, uint8_t len_axis) -{ - for(uint8_t i=0; i - -/**** Public definitions ****/ - -/**** Public function declarations ****/ -uint8_t util_invert_8b(uint8_t x); - -uint16_t util_limit_u32b_to_u16b(uint32_t in); -uint16_t util_limit_s32b_to_u16b(int32_t in); - -uint16_t util_convert_muldivoff(uint16_t raw, uint8_t mul, uint8_t div, int16_t offset); -uint16_t util_sat_mul_kilo(uint16_t xk, uint16_t yk); -uint16_t util_sat_div_kilo(uint16_t top, uint16_t bot); -uint16_t util_sat_ratio_16b(uint16_t top, uint16_t bot); -uint16_t util_percent_to_16b(uint8_t percent); - -uint8_t util_sat_add_8b(uint8_t x, uint8_t y); -uint8_t util_sat_subtract_8b(uint8_t x, uint8_t y); - -uint16_t util_sat_add_16b(uint16_t x, uint16_t y); -uint16_t util_sat_subtract_16b(uint16_t x, uint16_t y); - -uint16_t util_interpolate_1d_u16b(uint16_t x, uint16_t* x_axis, uint16_t* y_values, uint8_t len_axis); -uint16_t util_interpolate_2d_u16b(uint16_t x, uint16_t y, uint16_t* x_axis, uint8_t len_x_axis, uint16_t* y_axis, uint8_t len_y_axis, uint16_t* z_values); - -#ifdef TESTING -// Access to private functions for unit testing -static uint8_t find_interval_end_index(uint16_t val, uint16_t* axis_values, uint8_t len_axis); -static uint16_t interpolate_u16b(uint16_t x, uint16_t x0, uint16_t x1, uint16_t y0, uint16_t y1); -static uint16_t index2d_to_index1d(uint8_t ix, uint8_t iy, uint8_t len_x); -#endif - -#endif /* UTILS_H_ */ \ No newline at end of file diff --git a/firmware/src/hw/button.cpp b/firmware/src/hw/button.cpp new file mode 100644 index 0000000..f847af7 --- /dev/null +++ b/firmware/src/hw/button.cpp @@ -0,0 +1,116 @@ +/**** Includes ****/ +#include "../utils/utils.h" +#include "button.h" + +using namespace hw; + +/**** Private definitions ****/ +/**** Private constants ****/ +/**** Private variables ****/ +/**** Private function declarations ****/ +/**** Public function definitions ****/ +hw::Button::Button(void) +{ + return; +} + +hw::Button::~Button(void) +{ + return; +} + +void hw::Button::init(bsp::DigitalIn* din_ch, uint8_t act_lvl, util::VCounter* timer, uint16_t dbnc_lim) +{ + this->din_ch = din_ch; + this->timer = timer; + + if(act_lvl) this->act_lvl = 1; + else this->act_lvl = 0; + + this->state_start_ts = 0; + this->dbnc_ts = 0; + this->dbnc_lim = dbnc_lim; + + this->state = BUTTON_OFF; + this->is_new = 0; +} + +uint8_t hw::Button::process(void) +{ + // Read din + if(this->update_din) this->din_ch->read(); + + // Get last read level + uint8_t lvl = this->din_ch->last_read; + + // Determine next state + uint8_t next_state = BUTTON_OFF; + if(lvl==this->act_lvl) next_state = BUTTON_ON; + + // Advance debounce sample counter + uint16_t ts_now = this->timer->read(); + + if(next_state != this->state) + { + if(this->dbnc_ts == 0) this->dbnc_ts = ts_now; + uint16_t td = util::time_delta(this->dbnc_ts, ts_now); + uint32_t td_ms = this->timer->convert_ms(td); + // Check for debounce end + if(td_ms >= this->dbnc_lim) + { + // Debounce end. Apply new state. + this->dbnc_ts = 0; + this->state = next_state; + this->state_start_ts = ts_now; + this->is_new = 1; + }; + } + else this->dbnc_ts = 0; + + return this->state; +} + +uint8_t hw::Button::force_read(void) +{ + // Read din + if(this->update_din) this->din_ch->read(); + + // Get last read level + uint8_t lvl = this->din_ch->last_read; + + // Cancels active debounce + this->dbnc_ts = 0; + + // Determine next state + uint8_t next_state = BUTTON_OFF; + if(lvl==this->act_lvl) next_state = BUTTON_ON; + + if(next_state != this->state) + { + this->state_start_ts = this->timer->read(); + this->state = next_state; + this->is_new = 1; + }; + + return this->state; +} + +uint32_t hw::Button::time_read(void) +{ + uint16_t ts_now = this->timer->read(); + uint16_t td = util::time_delta(this->state_start_ts, ts_now); + return this->timer->convert_ms(td); +} + +void hw::Button::time_reset(void) +{ + this->state_start_ts = this->timer->read(); +} + +uint32_t hw::Button::time_read_max(void) +{ + uint16_t ts_max = this->timer->read_top(); + return this->timer->convert_ms(ts_max); +} + +/**** Private function definitions ****/ diff --git a/firmware/src/hw/button.h b/firmware/src/hw/button.h new file mode 100644 index 0000000..3be0c0a --- /dev/null +++ b/firmware/src/hw/button.h @@ -0,0 +1,49 @@ +#ifndef BUTTONS_H_ +#define BUTTONS_H_ + +/**** Includes ****/ +#include +#include "../utils/vcounter.h" +#include "../bsp/board.h" + +namespace hw { + +/**** Public definitions ****/ +const uint8_t BUTTON_OFF = 0; +const uint8_t BUTTON_ON = 1; + +class Button +{ + public: + Button(void); + ~Button(void); + + uint8_t state; + uint16_t dbnc_lim; + uint8_t is_new; + uint8_t update_din; + + void init(bsp::DigitalIn* din_ch, uint8_t act_lvl, util::VCounter* timer, uint16_t dbnc_lim); + uint8_t process(void); + uint8_t force_read(void); + uint32_t time_read(void); + void time_reset(void); + uint32_t time_read_max(void); + + #ifndef TESTING + protected: + #endif + bsp::DigitalIn* din_ch; + util::VCounter* timer; + uint8_t act_lvl; + uint16_t state_start_ts; + uint16_t dbnc_ts; +}; + +/**** Public function declarations ****/ +#ifdef TESTING +#endif + +} //namespace + +#endif /* BUTTONS_H_ */ \ No newline at end of file diff --git a/firmware/src/hw/buttons.c b/firmware/src/hw/buttons.c deleted file mode 100644 index b8c60d5..0000000 --- a/firmware/src/hw/buttons.c +++ /dev/null @@ -1,173 +0,0 @@ -/**** Includes ****/ -#include "board/utils/utils.h" -#include "board/din.h" -#include "board/dout.h" -#include "buttons.h" - -/**** Private definitions ****/ -/**** Private constants ****/ -static const uint8_t DEF_DBNC_LIM = HW_BTN_DEF_DBNC_LIM; -static const uint16_t DEF_REPEAT_TIME = HW_BTN_DEF_REPEAT_TIME; - -/**** Private variables ****/ -/**** Private function declarations ****/ -static uint8_t buttons_mapping(uint8_t btn_ch, uint8_t* din_ch, btn_cfg_t* cfg); -static uint8_t buttons_pull_mapping(uint8_t btn_ch, uint8_t* dout_ch); - -/**** Public function definitions ****/ -void btn_reset(btn_t* btn) -{ - btn->state = BTN_INACTIVE; - btn->new_state = 0; - btn->state_time = 0; - btn->transition_cntr = 0; - btn->dbnc_active = 1; -} - -uint8_t btn_ch_process(uint8_t btn_ch, btn_t* btn) -{ - // Get channel config - uint8_t din_ch; - btn_cfg_t cfg; - if(buttons_mapping(btn_ch, &din_ch, &cfg)) return BTN_INACTIVE; - - // Read din level - uint8_t lvl = bsp_din_read(din_ch); - - // Process button logic - uint8_t btn_act = btn_process(lvl, btn, &cfg); - return btn_act; -} - -uint8_t btn_process(uint8_t lvl, btn_t* btn, btn_cfg_t* cfg) -{ - // Increase state time - btn->state_time = util_sat_add_16b(btn->state_time, 1); - - // Check repeated new flag - if((cfg->repeat_time)&&(btn->state_time < 0xFFFF)) - { - if((btn->state_time)%(cfg->repeat_time) == 0) btn->new_state = 1; - }; - - // Calculate saved level from state and active level cfg - uint8_t prev_lvl = 0; - if(((btn->dbnc_active)&&(btn->state))||((!btn->dbnc_active)&&(!btn->state))) prev_lvl = util_invert_8b(cfg->act_lvl); - else prev_lvl = cfg->act_lvl; - - // Check if level changed - uint8_t lvl_chnaged = 0; - if(lvl!=prev_lvl) lvl_chnaged = 1; - - //Process debounce logic - if(lvl_chnaged) - { - // Changed debounce state - if(!btn->dbnc_active) btn->dbnc_active = 1; // Start debounce - else btn->dbnc_active = 0; // Stop debounce - // Reset debounce counter - btn->transition_cntr = 0; - } - else - { - // Continue debounce - if(btn->dbnc_active) btn->transition_cntr += 1; - } - - // Check for debounce end - if((btn->dbnc_active)&&(btn->transition_cntr >= cfg->dbnc_lim)) - { - // Reset debounce - btn->dbnc_active = 0; //End debounce - btn->transition_cntr = 0; - // Set new state - if(lvl==cfg->act_lvl) btn->state = BTN_ACTIVE; - else btn->state = BTN_INACTIVE; - btn->state_time = 0; //Reset timer - btn->new_state = 1; //Set new flag - }; - - return btn->state; -} - -void btn_ch_set_pull(uint8_t btn_ch, int8_t lvl) -{ - // Get channel config - uint8_t dout_ch; - if(buttons_pull_mapping(btn_ch, &dout_ch)) return; - - // Set button pull - bsp_dout_write(dout_ch, lvl); -} - -/**** Private function definitions ****/ -static uint8_t buttons_mapping(uint8_t btn_ch, uint8_t* din_ch, btn_cfg_t* cfg) -{ - // Default, most common config - cfg->act_lvl = BSP_DIN_LOW; - cfg->dbnc_lim = DEF_DBNC_LIM; - cfg->repeat_time = DEF_REPEAT_TIME; - - switch(btn_ch) - { - case BTN_1: // Mode - *din_ch = BSP_DIN1; - return 0; - - case BTN_2: // Down - *din_ch = BSP_DIN3; - return 0; - - case BTN_3: // Up - *din_ch = BSP_DIN4; - return 0; - - case BTN_4: // Dimm - *din_ch = BSP_DIN5; - cfg->act_lvl = BSP_DIN_HIGH; - cfg->repeat_time = 0; - return 0; - - case BTN_5: // Brakes - *din_ch = BSP_DIN6; - cfg->act_lvl = BSP_DIN_HIGH; - cfg->repeat_time = 0; - return 0; - - case BTN_6: // Handbrake - *din_ch = BSP_DIN7; - cfg->repeat_time = 0; - return 0; - - case BTN_6N: // Handbrake inverted - *din_ch = BSP_DIN7N; - cfg->repeat_time = 0; - return 0; - - default: //Invalid channel - *din_ch = 0; - return 1; - } - - return 1; -} - -static uint8_t buttons_pull_mapping(uint8_t btn_ch, uint8_t* dout_ch) -{ - switch(btn_ch) - { - case BTN_6: // Handbrake - *dout_ch = BSP_DOUT5; - return 0; - - case BTN_6N: // Handbrake inverted - *dout_ch = BSP_DOUT5; - return 0; - - default: //Invalid channel - *dout_ch = 0; - return 1; - } - - return 1; -} diff --git a/firmware/src/hw/buttons.h b/firmware/src/hw/buttons.h deleted file mode 100644 index 323406e..0000000 --- a/firmware/src/hw/buttons.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef BUTTONS_H_ -#define BUTTONS_H_ - -/* -*/ - -/**** Includes ****/ -#include -#include "config.h" - -/**** Public definitions ****/ -typedef struct { - uint8_t act_lvl; - uint8_t dbnc_lim; - uint16_t repeat_time; -} btn_cfg_t; - -typedef struct { - uint8_t state; - uint8_t new_state; - uint16_t state_time; - uint8_t transition_cntr; - uint8_t dbnc_active; -} btn_t; - -#define BTN_1 1 //DIN1 Mode -#define BTN_2 2 //DIN3 Down -#define BTN_3 3 //DIN4 Up -#define BTN_4 4 //DIN5 Dimm -#define BTN_5 5 //DIN6 Brakes -#define BTN_6 6 //DIN7 Handbrake -#define BTN_6N 7 //DIN7N Direct handbrake - -#define BTN_INACTIVE 0 -#define BTN_ACTIVE 1 - -#define BTN_PULL_LOW 0 -#define BTN_PULL_HIGH 1 -#define BTN_PULL_NONE -1 - -/**** Public function declarations ****/ -void btn_reset(btn_t* btn); - -// Using internal map -uint8_t btn_ch_process(uint8_t btn_ch, btn_t* btn); -void btn_ch_set_pull(uint8_t btn_ch, int8_t lvl); - -// Manual process -uint8_t btn_process(uint8_t lvl, btn_t* btn, btn_cfg_t* cfg); - -#ifdef TESTING -#endif - -#endif /* BUTTONS_H_ */ \ No newline at end of file diff --git a/firmware/src/hw/config.h b/firmware/src/hw/config.h deleted file mode 100644 index ac63781..0000000 --- a/firmware/src/hw/config.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef HW_CONFIG_H_ -#define HW_CONFIG_H_ - -/**** Includes ****/ -#include - -/**** Public definitions ****/ -#define HW_BTN_DEF_DBNC_LIM 10 -#define HW_BTN_DEF_REPEAT_TIME 1000 - -#define HW_HB_SUPPLY_VOLT_MIN_W 10000 -#define HW_HB_SUPPLY_VOLT_MIN_F 8000 - -#define HW_HB_SUPPLY_VOLT_MAX_W 16000 -#define HW_HB_SUPPLY_VOLT_MAX_F 19500 - -#define HW_HB_SUPPLY_CURRENT_MAX_W 6000 -#define HW_HB_SUPPLY_CURRENT_MAX_F 8000 - -#define HW_HB_SUPPLY_POWER_MAX_W 30000 -#define HW_HB_SUPPLY_POWER_MAX_F 45000 - -#define HW_HB_OUT_CURRENT_MAX_W 6000 -#define HW_HB_OUT_CURRENT_MAX_F 8000 - -#define HW_HB_OUT_VOLTAGE_MAX_W 8000 -#define HW_HB_OUT_VOLTAGE_MAX_F 10000 - -#define HW_HB_OUT_POWER_MAX_W 30000 -#define HW_HB_OUT_POWER_MAX_F 40000 - -#define HW_HB_OUT_RESISTANCE_MIN_W 750 -#define HW_HB_OUT_RESISTANCE_MIN_F 500 - -#define HW_HB_OUT_RESISTANCE_MAX_W 5000 -#define HW_HB_OUT_RESISTANCE_MAX_F 10000 - -#define HW_HB_FAULT_DELAY 500 -#define HW_HB_WTOF_DELAY 0 - -/**** Public function declarations ****/ -#ifdef TESTING -#endif - -#endif /* HW_CONFIG_H_ */ diff --git a/firmware/src/hw/hb_control.c b/firmware/src/hw/hb_control.c deleted file mode 100644 index 3ab05d6..0000000 --- a/firmware/src/hw/hb_control.c +++ /dev/null @@ -1,399 +0,0 @@ -/**** Includes ****/ -#include "board/utils/utils.h" -#include "board/halfbridge.h" -#include "hb_control.h" - -/**** Private definitions ****/ -/**** Private constants ****/ -// Fault condition thresholds -static const uint16_t SUPPLY_VOLT_MIN_W = HW_HB_SUPPLY_VOLT_MIN_W; -static const uint16_t SUPPLY_VOLT_MIN_F = HW_HB_SUPPLY_VOLT_MIN_F; - -static const uint16_t SUPPLY_VOLT_MAX_W = HW_HB_SUPPLY_VOLT_MAX_W; -static const uint16_t SUPPLY_VOLT_MAX_F = HW_HB_SUPPLY_VOLT_MAX_F; - -static const uint16_t SUPPLY_CURRENT_MAX_W = HW_HB_SUPPLY_CURRENT_MAX_W; -static const uint16_t SUPPLY_CURRENT_MAX_F = HW_HB_SUPPLY_CURRENT_MAX_F; - -static const uint16_t SUPPLY_POWER_MAX_W = HW_HB_SUPPLY_POWER_MAX_W; -static const uint16_t SUPPLY_POWER_MAX_F = HW_HB_SUPPLY_POWER_MAX_F; - -static const uint16_t OUT_CURRENT_MAX_W = HW_HB_OUT_CURRENT_MAX_W; -static const uint16_t OUT_CURRENT_MAX_F = HW_HB_OUT_CURRENT_MAX_F; - -static const uint16_t OUT_VOLTAGE_MAX_W = HW_HB_OUT_VOLTAGE_MAX_W; -static const uint16_t OUT_VOLTAGE_MAX_F = HW_HB_OUT_VOLTAGE_MAX_F; - -static const uint16_t OUT_POWER_MAX_W = HW_HB_OUT_POWER_MAX_W; -static const uint16_t OUT_POWER_MAX_F = HW_HB_OUT_POWER_MAX_F; - -static const uint16_t OUT_RESISTANCE_MIN_W = HW_HB_OUT_RESISTANCE_MIN_W; -static const uint16_t OUT_RESISTANCE_MIN_F = HW_HB_OUT_RESISTANCE_MIN_F; - -static const uint16_t OUT_RESISTANCE_MAX_W = HW_HB_OUT_RESISTANCE_MAX_W; -static const uint16_t OUT_RESISTANCE_MAX_F = HW_HB_OUT_RESISTANCE_MAX_F; - -static const uint16_t FAULT_DELAY = HW_HB_FAULT_DELAY; -static const uint16_t WTOF_DELAY = HW_HB_WTOF_DELAY; - -/**** Private variables ****/ - -/**** Private function declarations ****/ -// Protection functions -static void faults_chs_reset(hb_fault_chs_t* ch_list); -static void faults_init(hb_faults_t* faults, hb_fault_chs_t* en_list); -static void faults_logic(hb_meas_t* measurements, hb_faults_t* faults); - -static uint8_t faults_check(hb_faults_t* faults, hb_fault_chs_t* en_list, hb_fault_chs_t* fb_list, fault_lvl_t check); -static uint8_t warnings_feedback(hb_faults_t* faults, hb_fault_chs_t* en_list, hb_fault_chs_t* fb_list); -static uint8_t faults_feedback(hb_faults_t* faults, hb_fault_chs_t* en_list, hb_fault_chs_t* fb_list); -static uint8_t faults_is_any(hb_fault_chs_t* fb_list); - -static uint8_t is_outside(uint16_t meas, uint16_t min, uint16_t max); - -static uint8_t fuse_subprocess(hb_feedback_t* hb_fb, hb_control_t* hb_ctrl); -static void target_to_control(int16_t target, uint16_t ref_voltage, uint16_t* pwm_out, uint8_t* low_out, hb_fault_chs_t* fault_ch_en); - -/**** Public function definitions ****/ -void hb_init(hb_feedback_t* hb_fb, hb_control_t* hb_ctrl) -{ - // Initialize control - hb_ctrl->enabled = 0; - - // Initialize protection structures - faults_init(&hb_ctrl->out_faults, &hb_ctrl->out_faults_en); - - fuse_reset(&hb_ctrl->out_fuse); - hb_ctrl->out_fuse_cfg.cooldown_time = 1000; - hb_ctrl->out_fuse_cfg.retry_time = 1000; - - // Initialize feedback structure - bsp_hb_read_meas(&hb_fb->analog); - faults_chs_reset(&hb_fb->faults); - faults_chs_reset(&hb_fb->warnings); - - hb_fb->enabled = 0; - hb_fb->warning_act = 0; - hb_fb->fault_act = 0; - hb_fb->fused = 0; - - bsp_hb_write_pwm(0); - bsp_hb_write_low(0); -} - -void hb_enable(hb_control_t* hb_ctrl) -{ - bsp_hb_write_pwm(0); - bsp_hb_write_low(1); - hb_ctrl->enabled = 1; -} - -void hb_disable(hb_control_t* hb_ctrl) -{ - hb_ctrl->enabled = 0; - bsp_hb_write_pwm(0); - bsp_hb_write_low(0); -} - - -void hb_process(int16_t target, hb_feedback_t* hb_fb, hb_control_t* hb_ctrl) -{ - uint16_t out_pwm = 0; - uint8_t low_on = 0; - - // Read feedback - bsp_hb_read_meas(&hb_fb->analog); - - // Process fuse - uint8_t fuse_act = fuse_subprocess(hb_fb, hb_ctrl); - - // Act on fuse state - if((fuse_act)||(!hb_ctrl->enabled)) - { - // Turn off output - bsp_hb_write_pwm(0); - bsp_hb_write_low(0); - return; - }; - - // Process new target - target_to_control(target, hb_fb->analog.sup_voltage, &out_pwm, &low_on, &hb_ctrl->out_faults_en); - - // Apply new controls - bsp_hb_write_low(low_on); - bsp_hb_write_pwm(out_pwm); -} - -/**** Private function definitions ****/ -static void target_to_control(int16_t target, uint16_t ref_voltage, uint16_t* pwm_out, uint8_t* low_out, hb_fault_chs_t* fault_ch_en) -{ - if(target < 0) - { - // Fast decay - *pwm_out = 0; - *low_out = 0; - // Set appropriate fault channels - fault_ch_en->out_short = 0; - fault_ch_en->out_ovp = 0; - } - else if(target == 0) - { - // Slow decay - *pwm_out = 0; - *low_out = 1; - // Set appropriate fault channels - fault_ch_en->out_short = 0; - fault_ch_en->out_ovp = 1; - } - else - { - // Calculate target PWM - *pwm_out = util_sat_ratio_16b((uint16_t)target, ref_voltage); - *low_out = 1; - fault_ch_en->out_short = 1; - fault_ch_en->out_ovp = 1; - } -} - -static uint8_t fuse_subprocess(hb_feedback_t* hb_fb, hb_control_t* hb_ctrl) -{ - // Process faults - faults_logic(&hb_fb->analog, &hb_ctrl->out_faults); - - // Check if any enabled fault is active - uint8_t warn_act = warnings_feedback(&hb_ctrl->out_faults, &hb_ctrl->out_faults_en, &hb_fb->warnings); - uint8_t fault_act = faults_feedback(&hb_ctrl->out_faults, &hb_ctrl->out_faults_en, &hb_fb->faults); - - // Process fuse state - uint8_t fuse_act = fuse_process(&hb_ctrl->out_fuse, fault_act, &hb_ctrl->out_fuse_cfg); - - // Copy feedback data - hb_fb->enabled = hb_ctrl->enabled; - hb_fb->warning_act = warn_act; - hb_fb->fault_act = fault_act; - hb_fb->fused = fuse_act; - - return fuse_act; -} - -// Fault logic functions -static void faults_chs_reset(hb_fault_chs_t* ch_list) -{ - // Zero all channels - ch_list->sup_uvp = 0; - ch_list->sup_ovp = 0; - ch_list->sup_ocp = 0; - ch_list->sup_opp = 0; - ch_list->out_ovp = 0; - ch_list->out_ocp = 0; - ch_list->out_opp = 0; - ch_list->out_short = 0; - ch_list->out_open = 0; -} - -static void faults_init(hb_faults_t* faults, hb_fault_chs_t* en_list) -{ - // Init state - fault_reset(&faults->sup_uvp); - fault_reset(&faults->sup_ovp); - fault_reset(&faults->sup_ocp); - fault_reset(&faults->sup_opp); - fault_reset(&faults->out_ovp); - fault_reset(&faults->out_ocp); - fault_reset(&faults->out_opp); - fault_reset(&faults->out_short); - fault_reset(&faults->out_open); - - // Init enabled channels - faults_chs_reset(en_list); - en_list->sup_ocp = 1; - en_list->out_ocp = 1; - en_list->out_short = 1; -} - -static void faults_logic(hb_meas_t* measurements, hb_faults_t* faults) -{ - uint8_t w_trig = 0; - uint8_t f_trig = 0; - - fault_cfg_t fault_cfg; - fault_cfg.delay = FAULT_DELAY; - fault_cfg.wtof = WTOF_DELAY; - - // Check supply voltage - w_trig = is_outside(measurements->sup_voltage, SUPPLY_VOLT_MIN_W, 0); - f_trig = is_outside(measurements->sup_voltage, SUPPLY_VOLT_MIN_F, 0); - fault_process(&faults->sup_uvp, w_trig, f_trig, &fault_cfg); - - w_trig = is_outside(measurements->sup_voltage, 0, SUPPLY_VOLT_MAX_W); - f_trig = is_outside(measurements->sup_voltage, 0, SUPPLY_VOLT_MAX_F); - fault_process(&faults->sup_ovp, w_trig, f_trig, &fault_cfg); - - // Check supply current - w_trig = is_outside(measurements->sup_current, 0, SUPPLY_CURRENT_MAX_W); - f_trig = is_outside(measurements->sup_current, 0, SUPPLY_CURRENT_MAX_F); - fault_process(&faults->sup_ocp, w_trig, f_trig, &fault_cfg); - - // Check supply power - w_trig = is_outside(measurements->sup_power, 0, SUPPLY_POWER_MAX_W); - f_trig = is_outside(measurements->sup_power, 0, SUPPLY_POWER_MAX_F); - fault_process(&faults->sup_opp, w_trig, f_trig, &fault_cfg); - - // Check output voltage - w_trig = is_outside(measurements->out_voltage, 0, OUT_VOLTAGE_MAX_W); - f_trig = is_outside(measurements->out_voltage, 0, OUT_VOLTAGE_MAX_F); - fault_process(&faults->out_ovp, w_trig, f_trig, &fault_cfg); - - // Check output current - w_trig = is_outside(measurements->out_current, 0, OUT_CURRENT_MAX_W); - f_trig = is_outside(measurements->out_current, 0, OUT_CURRENT_MAX_F); - fault_process(&faults->out_ocp, w_trig, f_trig, &fault_cfg); - - // Check output power - w_trig = is_outside(measurements->out_power, 0, OUT_POWER_MAX_W); - f_trig = is_outside(measurements->out_power, 0, OUT_POWER_MAX_F); - fault_process(&faults->out_opp, w_trig, f_trig, &fault_cfg); - - // Check output resistance - w_trig = is_outside(measurements->out_impedance, OUT_RESISTANCE_MIN_W, 0); - f_trig = is_outside(measurements->out_impedance, OUT_RESISTANCE_MIN_F, 0); - fault_process(&faults->out_short, w_trig, f_trig, &fault_cfg); - - w_trig = is_outside(measurements->out_impedance, 0, OUT_RESISTANCE_MAX_W); - f_trig = is_outside(measurements->out_impedance, 0, OUT_RESISTANCE_MAX_F); - fault_process(&faults->out_open, w_trig, f_trig, &fault_cfg); -} - -static uint8_t warnings_feedback(hb_faults_t* faults, hb_fault_chs_t* en_list, hb_fault_chs_t* fb_list) -{ - return faults_check(faults, en_list, fb_list, FAULT_LVL_WARNING); -} - -static uint8_t faults_feedback(hb_faults_t* faults, hb_fault_chs_t* en_list, hb_fault_chs_t* fb_list) -{ - return faults_check(faults, en_list, fb_list, FAULT_LVL_FAULT); -} - -// Utilities -static uint8_t is_outside(uint16_t meas, uint16_t min, uint16_t max) -{ - if((meas < min)||((max!=0)&&(meas > max))) return 1; - else return 0; -} - -static uint8_t faults_check(hb_faults_t* faults, hb_fault_chs_t* en_list, hb_fault_chs_t* fb_list, fault_lvl_t check) -{ - if((en_list->sup_uvp)&&(faults->sup_uvp.severity == check)) fb_list->sup_uvp = 1; - if((en_list->sup_ovp)&&(faults->sup_ovp.severity == check)) fb_list->sup_ovp = 1; - if((en_list->sup_ocp)&&(faults->sup_ocp.severity == check)) fb_list->sup_ocp = 1; - if((en_list->sup_opp)&&(faults->sup_opp.severity == check)) fb_list->sup_opp = 1; - if((en_list->out_ovp)&&(faults->out_ovp.severity == check)) fb_list->out_ovp = 1; - if((en_list->out_ocp)&&(faults->out_ocp.severity == check)) fb_list->out_ocp = 1; - if((en_list->out_opp)&&(faults->out_opp.severity == check)) fb_list->out_opp = 1; - if((en_list->out_short)&&(faults->out_short.severity == check)) fb_list->out_short = 1; - if((en_list->out_open)&&(faults->out_open.severity == check)) fb_list->out_open = 1; - - return faults_is_any(fb_list); -} - -static uint8_t faults_is_any(hb_fault_chs_t* fb_list) -{ - if(fb_list->sup_uvp) return 1; - if(fb_list->sup_ovp) return 1; - if(fb_list->sup_ocp) return 1; - if(fb_list->sup_opp) return 1; - if(fb_list->out_ovp) return 1; - if(fb_list->out_ocp) return 1; - if(fb_list->out_opp) return 1; - if(fb_list->out_short) return 1; - if(fb_list->out_open) return 1; - - return 0; -} - -#ifdef TESTING -uint8_t hb_is_equal_fb_struct(hb_feedback_t* f1, hb_feedback_t* f2) -{ - if(f1->analog.out_voltage != f2->analog.out_voltage ) return 0; - if(f1->analog.out_current != f2->analog.out_current ) return 0; - if(f1->analog.sup_voltage != f2->analog.sup_voltage ) return 0; - if(f1->analog.sup_current != f2->analog.sup_current ) return 0; - if(f1->analog.out_power != f2->analog.out_power ) return 0; - if(f1->analog.sup_power != f2->analog.sup_power ) return 0; - if(f1->analog.out_impedance != f2->analog.out_impedance ) return 0; - if(f1->analog.low_side_ctrl != f2->analog.low_side_ctrl ) return 0; - if(f1->analog.pwm != f2->analog.pwm ) return 0; - if(f1->enabled != f2->enabled ) return 0; - if(f1->warning_act != f2->warning_act ) return 0; - if(f1->fault_act != f2->fault_act ) return 0; - if(f1->fused != f2->fused ) return 0; - if(f1->warnings.sup_uvp != f2->warnings.sup_uvp ) return 0; - if(f1->warnings.sup_ovp != f2->warnings.sup_ovp ) return 0; - if(f1->warnings.sup_ocp != f2->warnings.sup_ocp ) return 0; - if(f1->warnings.sup_opp != f2->warnings.sup_opp ) return 0; - if(f1->warnings.out_ovp != f2->warnings.out_ovp ) return 0; - if(f1->warnings.out_ocp != f2->warnings.out_ocp ) return 0; - if(f1->warnings.out_opp != f2->warnings.out_opp ) return 0; - if(f1->warnings.out_short != f2->warnings.out_short ) return 0; - if(f1->warnings.out_open != f2->warnings.out_open ) return 0; - if(f1->faults.sup_uvp != f2->faults.sup_uvp ) return 0; - if(f1->faults.sup_ovp != f2->faults.sup_ovp ) return 0; - if(f1->faults.sup_ocp != f2->faults.sup_ocp ) return 0; - if(f1->faults.sup_opp != f2->faults.sup_opp ) return 0; - if(f1->faults.out_ovp != f2->faults.out_ovp ) return 0; - if(f1->faults.out_ocp != f2->faults.out_ocp ) return 0; - if(f1->faults.out_opp != f2->faults.out_opp ) return 0; - if(f1->faults.out_short != f2->faults.out_short ) return 0; - if(f1->faults.out_open != f2->faults.out_open ) return 0; - - return 1; -} - -uint8_t hb_is_equal_ctrl_struct(hb_control_t* c1, hb_control_t* c2) -{ - if(c1->enabled != c2->enabled ) return 0; - if(c1->out_faults.sup_uvp.severity != c2->out_faults.sup_uvp.severity ) return 0; - if(c1->out_faults.sup_uvp.w_time != c2->out_faults.sup_uvp.w_time ) return 0; - if(c1->out_faults.sup_uvp.f_time != c2->out_faults.sup_uvp.f_time ) return 0; - if(c1->out_faults.sup_ovp.severity != c2->out_faults.sup_ovp.severity ) return 0; - if(c1->out_faults.sup_ovp.w_time != c2->out_faults.sup_ovp.w_time ) return 0; - if(c1->out_faults.sup_ovp.f_time != c2->out_faults.sup_ovp.f_time ) return 0; - if(c1->out_faults.sup_ocp.severity != c2->out_faults.sup_ocp.severity ) return 0; - if(c1->out_faults.sup_ocp.w_time != c2->out_faults.sup_ocp.w_time ) return 0; - if(c1->out_faults.sup_ocp.f_time != c2->out_faults.sup_ocp.f_time ) return 0; - if(c1->out_faults.sup_opp.severity != c2->out_faults.sup_opp.severity ) return 0; - if(c1->out_faults.sup_opp.w_time != c2->out_faults.sup_opp.w_time ) return 0; - if(c1->out_faults.sup_opp.f_time != c2->out_faults.sup_opp.f_time ) return 0; - if(c1->out_faults.out_ovp.severity != c2->out_faults.out_ovp.severity ) return 0; - if(c1->out_faults.out_ovp.w_time != c2->out_faults.out_ovp.w_time ) return 0; - if(c1->out_faults.out_ovp.f_time != c2->out_faults.out_ovp.f_time ) return 0; - if(c1->out_faults.out_ocp.severity != c2->out_faults.out_ocp.severity ) return 0; - if(c1->out_faults.out_ocp.w_time != c2->out_faults.out_ocp.w_time ) return 0; - if(c1->out_faults.out_ocp.f_time != c2->out_faults.out_ocp.f_time ) return 0; - if(c1->out_faults.out_opp.severity != c2->out_faults.out_opp.severity ) return 0; - if(c1->out_faults.out_opp.w_time != c2->out_faults.out_opp.w_time ) return 0; - if(c1->out_faults.out_opp.f_time != c2->out_faults.out_opp.f_time ) return 0; - if(c1->out_faults.out_short.severity != c2->out_faults.out_short.severity ) return 0; - if(c1->out_faults.out_short.w_time != c2->out_faults.out_short.w_time ) return 0; - if(c1->out_faults.out_short.f_time != c2->out_faults.out_short.f_time ) return 0; - if(c1->out_faults.out_open.severity != c2->out_faults.out_open.severity ) return 0; - if(c1->out_faults.out_open.w_time != c2->out_faults.out_open.w_time ) return 0; - if(c1->out_faults.out_open.f_time != c2->out_faults.out_open.f_time ) return 0; - if(c1->out_faults_en.sup_uvp != c2->out_faults_en.sup_uvp ) return 0; - if(c1->out_faults_en.sup_ovp != c2->out_faults_en.sup_ovp ) return 0; - if(c1->out_faults_en.sup_ocp != c2->out_faults_en.sup_ocp ) return 0; - if(c1->out_faults_en.sup_opp != c2->out_faults_en.sup_opp ) return 0; - if(c1->out_faults_en.out_ovp != c2->out_faults_en.out_ovp ) return 0; - if(c1->out_faults_en.out_ocp != c2->out_faults_en.out_ocp ) return 0; - if(c1->out_faults_en.out_opp != c2->out_faults_en.out_opp ) return 0; - if(c1->out_faults_en.out_short != c2->out_faults_en.out_short ) return 0; - if(c1->out_faults_en.out_open != c2->out_faults_en.out_open ) return 0; - if(c1->out_fuse.state != c2->out_fuse.state ) return 0; - if(c1->out_fuse.count != c2->out_fuse.count ) return 0; - if(c1->out_fuse.timer != c2->out_fuse.timer ) return 0; - if(c1->out_fuse_cfg.cooldown_time != c2->out_fuse_cfg.cooldown_time ) return 0; - if(c1->out_fuse_cfg.retry_time != c2->out_fuse_cfg.retry_time ) return 0; - - return 1; -} -#endif diff --git a/firmware/src/hw/hb_control.h b/firmware/src/hw/hb_control.h deleted file mode 100644 index aae6afe..0000000 --- a/firmware/src/hw/hb_control.h +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef HB_CONTROL_H_ -#define HB_CONTROL_H_ - -/**** Includes ****/ -#include -#include "board/utils/faults.h" -#include "board/utils/fuses.h" -#include "board/halfbridge.h" -#include "config.h" - -/**** Public definitions ****/ -typedef struct { - fault_t sup_uvp; - fault_t sup_ovp; - fault_t sup_ocp; - fault_t sup_opp; - fault_t out_ovp; - fault_t out_ocp; - fault_t out_opp; - fault_t out_short; - fault_t out_open; -} hb_faults_t; - -typedef struct { - uint8_t sup_uvp; - uint8_t sup_ovp; - uint8_t sup_ocp; - uint8_t sup_opp; - uint8_t out_ovp; - uint8_t out_ocp; - uint8_t out_opp; - uint8_t out_short; - uint8_t out_open; -} hb_fault_chs_t; - -typedef struct { - hb_meas_t analog; - uint8_t enabled; - uint8_t warning_act; - uint8_t fault_act; - uint8_t fused; - hb_fault_chs_t warnings; - hb_fault_chs_t faults; -} hb_feedback_t; - -typedef struct { - uint8_t enabled; - hb_faults_t out_faults; - hb_fault_chs_t out_faults_en; - fuse_t out_fuse; - fuse_cfg_t out_fuse_cfg; -} hb_control_t; - -/**** Public function declarations ****/ -void hb_init(hb_feedback_t* hb_fb, hb_control_t* hb_ctrl); - -void hb_enable(hb_control_t* hb_ctrl); -void hb_disable(hb_control_t* hb_ctrl); - -void hb_process(int16_t target, hb_feedback_t* hb_fb, hb_control_t* hb_ctrl); - -#ifdef TESTING -uint8_t hb_is_equal_fb_struct(hb_feedback_t* f1, hb_feedback_t* f2); -uint8_t hb_is_equal_ctrl_struct(hb_control_t* c1, hb_control_t* c2); -#endif - -#endif /* HB_CONTROL_H_ */ \ No newline at end of file diff --git a/firmware/src/hw/led_display.c b/firmware/src/hw/led_display.c deleted file mode 100644 index d3ebc89..0000000 --- a/firmware/src/hw/led_display.c +++ /dev/null @@ -1,38 +0,0 @@ -/**** Includes ****/ -#include "board/odout.h" -#include "led_display.h" - -/**** Private definitions ****/ -/**** Private constants ****/ -/**** Private variables ****/ -/**** Private function declarations ****/ - -/**** Public function definitions ****/ -void led_dsp_set_image(uint8_t image) -{ - if(image&0x01) bsp_odout_write(BSP_OD1, BSP_ODOUT_LOW); - else bsp_odout_write(BSP_OD1, BSP_ODOUT_HIZ); - - if(image&0x02) bsp_odout_write(BSP_OD2, BSP_ODOUT_LOW); - else bsp_odout_write(BSP_OD2, BSP_ODOUT_HIZ); - - if(image&0x04) bsp_odout_write(BSP_OD3, BSP_ODOUT_LOW); - else bsp_odout_write(BSP_OD3, BSP_ODOUT_HIZ); - - if(image&0x08) bsp_odout_write(BSP_OD4, BSP_ODOUT_LOW); - else bsp_odout_write(BSP_OD4, BSP_ODOUT_HIZ); - - if(image&0x10) bsp_odout_write(BSP_OD5, BSP_ODOUT_LOW); - else bsp_odout_write(BSP_OD5, BSP_ODOUT_HIZ); - - if(image&0x20) bsp_odout_write(BSP_OD6, BSP_ODOUT_LOW); - else bsp_odout_write(BSP_OD6, BSP_ODOUT_HIZ); -} - -void led_dsp_backligth_set(uint8_t percent) -{ - bsp_odout_write_common(percent); -} - -/**** Private function definitions ****/ - diff --git a/firmware/src/hw/led_display.cpp b/firmware/src/hw/led_display.cpp new file mode 100644 index 0000000..ac525f4 --- /dev/null +++ b/firmware/src/hw/led_display.cpp @@ -0,0 +1,160 @@ +/**** Includes ****/ +#include "../utils/utils.h" +#include "led_display.h" + +using namespace hw; + +/**** Private definitions ****/ +/**** Private constants ****/ +/**** Private variables ****/ +/**** Private function declarations ****/ +/**** Public function definitions ****/ +hw::LedDisplay::LedDisplay(void) +{ + return; +} + +hw::LedDisplay::~LedDisplay(void) +{ + this->force(0x00); + this->write_backlight(0); +} + +void hw::LedDisplay::init(doutCfg_t* dout_chs, uint8_t act_lvl, util::VCounter* timer, bsp::PwmOut* pwm_ch) +{ + this->led0_dout_ch = dout_chs->led0_dout_ch; + this->led1_dout_ch = dout_chs->led1_dout_ch; + this->led2_dout_ch = dout_chs->led2_dout_ch; + this->led3_dout_ch = dout_chs->led3_dout_ch; + this->led4_dout_ch = dout_chs->led4_dout_ch; + this->led5_dout_ch = dout_chs->led5_dout_ch; + + if(act_lvl) this->act_lvl = 1; + else this->act_lvl = 0; + + this->timer = timer; + + this->pwm_ch = pwm_ch; + + this->on_time = 0; + this->period = 0; + this->cycle_cnt = 0; + this->cycle_limit = 0; + this->timestamp_start = 0; + this->image = 0x00; + + this->force(0x00); + this->write_backlight(0); +} + +void hw::LedDisplay::force(uint8_t image) +{ + uint8_t led_state; + + if(image&0x01) led_state = 1; + else led_state = 0; + this->set_single_led(led_state, this->led0_dout_ch); + + if(image&0x02) led_state = 1; + else led_state = 0; + this->set_single_led(led_state, this->led1_dout_ch); + + if(image&0x04) led_state = 1; + else led_state = 0; + this->set_single_led(led_state, this->led2_dout_ch); + + if(image&0x08) led_state = 1; + else led_state = 0; + this->set_single_led(led_state, this->led3_dout_ch); + + if(image&0x10) led_state = 1; + else led_state = 0; + this->set_single_led(led_state, this->led4_dout_ch); + + if(image&0x20) led_state = 1; + else led_state = 0; + this->set_single_led(led_state, this->led5_dout_ch); +} + +void hw::LedDisplay::write(uint8_t image) +{ + // Static mode + this->on_time = 1; + this->period = 0; + this->cycle_cnt = 0; + this->cycle_limit = 0; + this->timestamp_start = 0; + this->image = image; + + // Set initial state + this->force(this->image); +} + +void hw::LedDisplay::write(uint8_t image, uint16_t on_time, uint16_t period, uint8_t cycle_limit) +{ + // "PWM" mode + this->on_time = on_time; + this->period = period; + this->cycle_cnt = 0; + this->cycle_limit = cycle_limit; + this->image = image; + + // Set initial state + if(this->on_time > 0) this->force(this->image); + else this->force(0x00); + + // Cycle start time + this->timestamp_start = this->timer->read(); +} + +void hw::LedDisplay::process(void) +{ + if(this->period == 0) return; // Nothing to do + + // Update cycle timing + uint16_t ts_now = this->timer->read(); + uint16_t td = util::time_delta(this->timestamp_start, ts_now); + uint32_t td_ms = this->timer->convert_ms(td); + + if(td_ms >= this->period) + { + this->timestamp_start = ts_now; + this->cycle_cnt++; + }; + + // Check cycle limit + if((this->cycle_cnt >= this->cycle_limit)&&(this->cycle_limit)) + { + this->on_time = 0; + this->period = 0; + this->timestamp_start = 0; + this->force(0x00); + return; + }; + + // Do output compare + if(td_ms < this->on_time) this->force(this->image); + else this->force(0x00); +} + +uint8_t hw::LedDisplay::is_cycle_end(void) +{ + if(this->cycle_cnt >= this->cycle_limit) return 1; + else return 0; +} + +void hw::LedDisplay::write_backlight(uint8_t percent) +{ + this->pwm_ch->write(percent); +} + +void hw::LedDisplay::set_single_led(uint8_t state, bsp::DigitalOut* led_ch) +{ + uint8_t lvl = 0; + + if(((state==0)&&(this->act_lvl==0))||((state!=0)&&(this->act_lvl==1))) lvl = 1; + + led_ch->write(lvl); +} + +/**** Private function definitions ***/ diff --git a/firmware/src/hw/led_display.h b/firmware/src/hw/led_display.h index ac61a08..564d163 100644 --- a/firmware/src/hw/led_display.h +++ b/firmware/src/hw/led_display.h @@ -1,19 +1,66 @@ #ifndef LED_DISPLAY_H_ #define LED_DISPLAY_H_ -/* -*/ - /**** Includes ****/ #include +#include "../utils/vcounter.h" +#include "../bsp/board.h" + +namespace hw { /**** Public definitions ****/ +class LedDisplay +{ + public: + typedef struct { + bsp::DigitalOut* led0_dout_ch; + bsp::DigitalOut* led1_dout_ch; + bsp::DigitalOut* led2_dout_ch; + bsp::DigitalOut* led3_dout_ch; + bsp::DigitalOut* led4_dout_ch; + bsp::DigitalOut* led5_dout_ch; + } doutCfg_t; + + LedDisplay(void); + ~LedDisplay(void); + + uint16_t on_time; + uint16_t period; + uint8_t cycle_cnt; + uint8_t cycle_limit; + + void init(doutCfg_t* dout_chs, uint8_t act_lvl, util::VCounter* timer, bsp::PwmOut* pwm_ch); + void write(uint8_t image); + void write(uint8_t image, uint16_t on_time, uint16_t period, uint8_t cycle_limit); + void process(void); + uint8_t is_cycle_end(void); + void force(uint8_t image); + + void write_backlight(uint8_t percent); + + #ifdef TESTING + protected: + #endif + bsp::DigitalOut* led0_dout_ch; + bsp::DigitalOut* led1_dout_ch; + bsp::DigitalOut* led2_dout_ch; + bsp::DigitalOut* led3_dout_ch; + bsp::DigitalOut* led4_dout_ch; + bsp::DigitalOut* led5_dout_ch; + uint8_t act_lvl; + util::VCounter* timer; + bsp::PwmOut* pwm_ch; + uint16_t timestamp_start; + uint8_t image; + + void set_single_led(uint8_t state, bsp::DigitalOut* led_ch); +}; /**** Public function declarations ****/ -void led_dsp_set_image(uint8_t image); -void led_dsp_backligth_set(uint8_t percent); #ifdef TESTING #endif -#endif /* LED_DISPLAY_H_ */ +} //namespace + +#endif /* LED_DISPLAY_H_ */ \ No newline at end of file diff --git a/firmware/src/hw/out_driver.cpp b/firmware/src/hw/out_driver.cpp new file mode 100644 index 0000000..6701ce6 --- /dev/null +++ b/firmware/src/hw/out_driver.cpp @@ -0,0 +1,105 @@ +/**** Includes ****/ +#include "../utils/utils.h" +#include "out_driver.h" + +using namespace hw; + +/**** Private definitions ****/ +/**** Private constants ****/ +/**** Private variables ****/ +/**** Private function declarations ****/ + +/**** Public function definitions ****/ +hw::OutDriver::OutDriver(void) +{ + return; +} + +hw::OutDriver::~OutDriver(void) +{ + return; +} + +void hw::OutDriver::init(bsp::PwmOut* pwm_high, bsp::DigitalOut* dout_low) +{ + this->pwm_high = pwm_high; + this->dout_low = dout_low; + + this->target_duty = 0; + this->target_low = 0; + this->disabled = 1; +} + +void hw::OutDriver::write(uint16_t numerator) +{ + this->target_duty = numerator; + this->target_low = 1; + + // Check if enabled + if(this->disabled) + { + return; + }; + + // Set low side + if(this->dout_low->last_writen == 0) + { + this->dout_low->write(this->target_low); + }; + + // Set PWM + this->pwm_high->write(this->target_duty); +} + +void hw::OutDriver::write(uint8_t percent) +{ + // Convert to numerator/0xFFFF + this->write(util::percent_to_16b(percent)); +} + +void hw::OutDriver::write_hiz(void) +{ + this->target_duty = 0; + this->target_low = 0; + + // Check if enabled + if(this->disabled) + { + return; + }; + + // Set PWM + this->pwm_high->write((uint16_t)0); + + // Set low side + this->dout_low->write(0); +} + +void hw::OutDriver::enable(void) +{ + if(this->disabled==0) return; + this->disabled = 0; + + if(this->target_low==0) this->write_hiz(); + else this->write(this->target_duty); +} + +void hw::OutDriver::disable(void) +{ + if(this->disabled!=0) return; + + // Set PWM + this->pwm_high->write((uint16_t)0); + + // Set low side + this->dout_low->write(0); + + this->disabled = 1; +} + +uint8_t hw::OutDriver::is_disabled(void) +{ + return this->disabled; +} + +/**** Private function definitions ****/ diff --git a/firmware/src/hw/out_driver.h b/firmware/src/hw/out_driver.h new file mode 100644 index 0000000..b6418e9 --- /dev/null +++ b/firmware/src/hw/out_driver.h @@ -0,0 +1,45 @@ +#ifndef OUT_DRIVER_H_ +#define OUT_DRIVER_H_ + +/**** Includes ****/ +#include +#include "../bsp/board.h" + +namespace hw { + +/**** Public definitions ****/ + +class OutDriver +{ + public: + OutDriver(void); + ~OutDriver(void); + + void init(bsp::PwmOut* pwm_high, bsp::DigitalOut* dout_low); + + uint16_t target_duty; + uint8_t target_low; + + void write(uint16_t numerator); + void write(uint8_t percent); + void write_hiz(void); + void enable(void); + void disable(void); + uint8_t is_disabled(void); + + #ifndef TESTING + protected: + #endif + bsp::PwmOut* pwm_high; + bsp::DigitalOut* dout_low; + uint8_t disabled; +}; + +/**** Public function declarations ****/ + +#ifdef TESTING +#endif + +} //namespace + +#endif /* OUT_DRIVER_H_ */ \ No newline at end of file diff --git a/firmware/src/hw/out_reg.cpp b/firmware/src/hw/out_reg.cpp new file mode 100644 index 0000000..da62478 --- /dev/null +++ b/firmware/src/hw/out_reg.cpp @@ -0,0 +1,139 @@ +/**** Includes ****/ +#include "../utils/utils.h" +#include "out_reg.h" + +using namespace bsp; + +/**** Private definitions ****/ +/**** Private constants ****/ +/**** Private variables ****/ +/**** Private function declarations ****/ + +/**** Public function definitions ****/ +hw::OutReg::OutReg(void) +{ + return; +} + +hw::OutReg::~OutReg(void) +{ + return; +} + +void hw::OutReg::init(outRegCfg_t* cfg) +{ + this->pwm_high = cfg->pwm_high; + this->dout_low = cfg->dout_low; + this->ubat = cfg->ubat; + this->uout = cfg->uout; + this->iout = cfg->iout; + + this->voltage = 0; + this->current = 0; + this->out_on = 0; + this->lock = 0; + + this->cc_mode_en = 0; + this->update_ain = 0; + this->cc_tolerance = 75; +} + +void hw::OutReg::write_voltage(uint16_t voltage) +{ + this->voltage = voltage; +} + +void hw::OutReg::write_current(uint16_t current) +{ + this->current = current; + this->current_bot = util::sat_subtract(current, this->cc_tolerance); + this->current_top = util::sat_add(current, this->cc_tolerance); +} + +void hw::OutReg::write_on(uint8_t state) +{ + this->out_on = state; +} + +void hw::OutReg::write_lock(uint8_t state) +{ + this->lock = state; +} + +uint16_t hw::OutReg::read_voltage(void) +{ + return this->voltage; +} + +uint16_t hw::OutReg::read_current(void) +{ + return this->current; +} + +void hw::OutReg::process(void) +{ + // Update analog input + if(this->update_ain) + { + this->ubat->read(); + this->uout->read(); + this->iout->read(); + }; + + // Check if turned off + if((out_on == 0)||(this->lock != 0)) + { + + this->pwm_high->write((uint16_t)0); + this->dout_low->write(0); + return; + } + else if(this->dout_low->last_writen == 0) + { + this->dout_low->write(1); + }; + + // Calculate next duty cycle setting + uint16_t next_duty = this->pwm_high->get_set_duty(); + + if((this->voltage==0)||(this->current==0)) + { + // Off but not HiZ + next_duty = 0; + } + else if((this->cc_mode_en)&&(this->iout->last_read > this->current_bot)) + { + // Constant current mode - Change voltage to be within current limit + if(util::is_in_range(this->iout->last_read, this->current_bot, this->current_top)==0) + { + // Current outside of tolerance. Recalculate duty cycle. + uint32_t temp = (uint32_t)this->pwm_high->get_set_duty() * (uint32_t)this->current; + temp /= this->iout->last_read; + next_duty = util::sat_cast(temp); + }; + } + else + { + // Constant voltage mode + next_duty = util::sat_ratio(this->voltage, this->ubat->last_read); + } + + this->pwm_high->write(next_duty); + + return; +} + +void hw::OutReg::force_off(void) +{ + // Turn off output - HiZ + this->pwm_high->write((uint16_t)0); + this->dout_low->write(0); + + // Update targets + this->voltage = 0; + this->current = 0; + this->out_on = 0; + this->lock = 1; +} + +/**** Private function definitions ****/ diff --git a/firmware/src/hw/out_reg.h b/firmware/src/hw/out_reg.h new file mode 100644 index 0000000..54ca57a --- /dev/null +++ b/firmware/src/hw/out_reg.h @@ -0,0 +1,66 @@ +#ifndef OUTPUT_REGULATOR_H_ +#define OUTPUT_REGULATOR_H_ + +/**** Includes ****/ +#include +#include "../bsp/board.h" + +namespace hw { + +/**** Public definitions ****/ + +class OutReg +{ + public: + typedef struct { + bsp::PwmOut* pwm_high; + bsp::DigitalOut* dout_low; + bsp::AnalogIn* ubat; + bsp::AnalogIn* uout; + bsp::AnalogIn* iout; + } outRegCfg_t; + + OutReg(void); + ~OutReg(void); + + void init(outRegCfg_t* cfg); + + uint8_t cc_mode_en; + uint8_t update_ain; + uint16_t cc_tolerance; + + void write_voltage(uint16_t voltage); + void write_current(uint16_t current); + void write_on(uint8_t state); + void write_lock(uint8_t state); + + uint16_t read_voltage(void); + uint16_t read_current(void); + + void process(void); + void force_off(void); + + #ifndef TESTING + protected: + #endif + bsp::PwmOut* pwm_high; + bsp::DigitalOut* dout_low; + bsp::AnalogIn* ubat; + bsp::AnalogIn* uout; + bsp::AnalogIn* iout; + uint16_t voltage; + uint16_t current; + uint16_t current_top; + uint16_t current_bot; + uint8_t out_on; + uint8_t lock; +}; + +/**** Public function declarations ****/ + +#ifdef TESTING +#endif + +} //namespace + +#endif /* OUTPUT_REGULATOR_H_ */ \ No newline at end of file diff --git a/firmware/src/hw/potentiometer.cpp b/firmware/src/hw/potentiometer.cpp new file mode 100644 index 0000000..2ddbc11 --- /dev/null +++ b/firmware/src/hw/potentiometer.cpp @@ -0,0 +1,46 @@ +/**** Includes ****/ +#include "../utils/utils.h" +#include "../utils/interpolate.h" +#include "potentiometer.h" + +using namespace hw; + +/**** Private definitions ****/ +/**** Private constants ****/ +/**** Private variables ****/ +/**** Private function declarations ****/ + +/**** Public function definitions ****/ +hw::Potentiometer::Potentiometer(void) +{ + return; +} + +hw::Potentiometer::~Potentiometer(void) +{ + return; +} + +void hw::Potentiometer::init(bsp::AnalogIn* ain_ch, uint16_t low_deadzone, uint16_t high_deadzone) +{ + this->ain_ch = ain_ch; + this->low_deadzone = low_deadzone; + this->high_deadzone = high_deadzone; + this->last_percent = 0; + this->update_ain = 1; +} + +uint8_t hw::Potentiometer::read(void) +{ + // Update analog input + if(this->update_ain) this->ain_ch->read(); + + // Calculate percent + if(this->ain_ch->last_read <= this->low_deadzone) this->last_percent = 0; + else if(this->ain_ch->last_read >= this->high_deadzone ) this->last_percent = 100; + else this->last_percent = util::interpolate(this->ain_ch->last_read, this->low_deadzone, this->high_deadzone, 0, 100); + + return this->last_percent; +} + +/**** Private function definitions ****/ diff --git a/firmware/src/hw/potentiometer.h b/firmware/src/hw/potentiometer.h new file mode 100644 index 0000000..be65f4d --- /dev/null +++ b/firmware/src/hw/potentiometer.h @@ -0,0 +1,40 @@ +#ifndef POTENTIOMETER_H_ +#define POTENTIOMETER_H_ + +/**** Includes ****/ +#include +#include "../bsp/board.h" + +namespace hw { + +/**** Public definitions ****/ + +class Potentiometer +{ + public: + Potentiometer(void); + ~Potentiometer(void); + + void init(bsp::AnalogIn* ain_ch, uint16_t low_deadzone, uint16_t high_deadzone); + + uint16_t low_deadzone; + uint16_t high_deadzone; + uint8_t last_percent; + uint8_t update_ain; + + uint8_t read(void); + + #ifndef TESTING + protected: + #endif + bsp::AnalogIn* ain_ch; +}; + +/**** Public function declarations ****/ + +#ifdef TESTING +#endif + +} //namespace + +#endif /* POTENTIOMETER_H_ */ \ No newline at end of file diff --git a/firmware/src/hw/safe_ain.cpp b/firmware/src/hw/safe_ain.cpp new file mode 100644 index 0000000..5cbc54e --- /dev/null +++ b/firmware/src/hw/safe_ain.cpp @@ -0,0 +1,87 @@ +/**** Includes ****/ +#include "../utils/utils.h" +#include "safe_ain.h" + +using namespace hw; + +/**** Private definitions ****/ +/**** Private constants ****/ +/**** Private variables ****/ +/**** Private function declarations ****/ + +/**** Public function definitions ****/ +hw::SafeAin::SafeAin(void) +{ + return; +} + +hw::SafeAin::~SafeAin(void) +{ + return; +} + +void hw::SafeAin::init(bsp::AnalogIn* ain_ch, util::VCounter* timer) +{ + this->ain_ch = ain_ch; + this->timer = timer; + + this->under_treshold = 0; + this->over_treshold = 0xFFFF; + this->hold_time = 0; + this->cooldown_time = 0; + + this->update_ain = 0; + this->auto_reset = 0; + + this->warning = 0; + this->fault = 0; + + this->last_read = 0; + + this->ts_state_chnage = 0; +} + +void hw::SafeAin::process(void) +{ + // Update analog input + if(this->update_ain) this->ain_ch->read(); + + this->last_read = this->ain_ch->last_read; + + // Get current time + uint16_t ts_now = this->timer->read(); + + // Update over current and warning condition + uint8_t is_outside = 0; + if(this->last_read < this->under_treshold) is_outside = 1; + if(this->last_read > this->over_treshold) is_outside = 1; + + // Note start time if new OC condition + if(is_outside != this->warning) this->ts_state_chnage = ts_now; + + // Update warning + this->warning = is_outside; + + // Calculate warning condition time + uint16_t td = util::time_delta(this->ts_state_chnage, ts_now); + uint32_t time_ms = this->timer->convert_ms(td); + + // Check for fault set + if((this->fault==0)&&(time_ms > (uint32_t)this->hold_time)) + { + this->fault = 1; + return; + }; + + // Check if allowed auto reset + if(this->auto_reset==0) return; + + // Check for fault reset + if((this->fault!=0)&&(time_ms > (uint32_t)this->cooldown_time)) + { + this->fault = 0; + return; + }; +} + +/**** Private function definitions ****/ diff --git a/firmware/src/hw/safe_ain.h b/firmware/src/hw/safe_ain.h new file mode 100644 index 0000000..a48969a --- /dev/null +++ b/firmware/src/hw/safe_ain.h @@ -0,0 +1,50 @@ +#ifndef SAFE_AIN_H_ +#define SAFE_AIN_H_ + +/**** Includes ****/ +#include +#include "../utils/vcounter.h" +#include "../bsp/board.h" + +namespace hw { + +/**** Public definitions ****/ + +class SafeAin +{ + public: + SafeAin(void); + ~SafeAin(void); + + void init(bsp::AnalogIn* ain_ch, util::VCounter* timer); + + uint8_t warning; + uint8_t fault; + uint16_t last_read; + + uint16_t under_treshold; + uint16_t over_treshold; + uint16_t hold_time; + uint16_t cooldown_time; + + uint8_t update_ain; + uint8_t auto_reset; + + void process(void); + + #ifndef TESTING + protected: + #endif + bsp::AnalogIn* ain_ch; + util::VCounter* timer; + uint16_t ts_state_chnage; +}; + +/**** Public function declarations ****/ + +#ifdef TESTING +#endif + +} //namespace + +#endif /* SAFE_AIN_H_ */ \ No newline at end of file diff --git a/firmware/src/hw/startup.c b/firmware/src/hw/startup.c deleted file mode 100644 index 7d37254..0000000 --- a/firmware/src/hw/startup.c +++ /dev/null @@ -1,16 +0,0 @@ -/**** Includes ****/ -#include "board/utils/utils.h" -#include "board/setup.h" -#include "startup.h" - -/**** Private definitions ****/ -/**** Private constants ****/ -/**** Private variables ****/ -/**** Private function declarations ****/ -/**** Public function definitions ****/ -void hw_startup(void) -{ - bsp_startup(); -} - -/**** Private function definitions ****/ diff --git a/firmware/src/hw/startup.h b/firmware/src/hw/startup.h deleted file mode 100644 index 8d8b511..0000000 --- a/firmware/src/hw/startup.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef HW_STARTUP_H_ -#define HW_STARTUP_H_ - -/**** Includes ****/ -#include - -/**** Public definitions ****/ -/**** Public function declarations ****/ -void hw_startup(void); - -#ifdef TESTING -#endif - -#endif /* HW_STARTUP_H_ */ \ No newline at end of file diff --git a/firmware/src/logic/coil.c b/firmware/src/logic/coil.c deleted file mode 100644 index 7b32da2..0000000 --- a/firmware/src/logic/coil.c +++ /dev/null @@ -1,41 +0,0 @@ -/**** Includes ****/ -#include "coil.h" - -/**** Private definitions ****/ -/**** Private constants ****/ -static const int16_t TARGET_HANDBRAKE = COIL_TARGET_HANDBRAKE; -static const int16_t LOCK_VOLTAGE = COIL_LOCK_VOLTAGE; - -/**** Private variables ****/ -/**** Private function declarations ****/ - -/**** Public function definitions ****/ -int16_t coil_target(uint8_t force, uint8_t hbrake_act) -{ - if(hbrake_act) - { - return TARGET_HANDBRAKE; - } - else if(force==0) - { - return 0; - } - else if(force >= 100) - { - return LOCK_VOLTAGE; - } - else - { - // Calculate target - uint32_t t = (uint32_t)force * LOCK_VOLTAGE; - t /= 100; - if(t > LOCK_VOLTAGE) return LOCK_VOLTAGE; - else if(t < 0) return 0; - else return (int16_t)t; - } - - return 0; -} - -/**** Private function definitions ****/ - diff --git a/firmware/src/logic/coil.h b/firmware/src/logic/coil.h deleted file mode 100644 index 6a14495..0000000 --- a/firmware/src/logic/coil.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef COIL_H_ -#define COIL_H_ - -/**** Includes ****/ -#include - -/**** Public definitions ****/ -#define COIL_TARGET_HANDBRAKE -1 -#define COIL_LOCK_VOLTAGE 6500 - -/**** Public function declarations ****/ -int16_t coil_target(uint8_t force, uint8_t hbrake_act); - -#ifdef TESTING -#endif - -#endif /* COIL_H_ */ \ No newline at end of file diff --git a/firmware/src/logic/display.c b/firmware/src/logic/display.c deleted file mode 100644 index d46e8e8..0000000 --- a/firmware/src/logic/display.c +++ /dev/null @@ -1,108 +0,0 @@ -/**** Includes ****/ -#include "display.h" - -/**** Private definitions ****/ -/**** Private constants ****/ -static const uint8_t BACKLIGHT_DIMM = DSP_BACKLIGHT_DIMM_PERCENT; -static const uint8_t BACKLIGHT_BRIGTH = DSP_BACKLIGHT_BRIGTH_PERCENT; - -/**** Private variables ****/ -/**** Private function declarations ****/ -static uint8_t img_gen_dot10(uint8_t percent); -static uint8_t img_gen_dot20(uint8_t percent); -static uint8_t img_gen_bar(uint8_t percent); - -/**** Public function definitions ****/ -void dsp_init_ctrl(dsp_ctrl_t* ctrl) -{ - ctrl->img_lock = 0; - ctrl->act_img = 0x00; -} - -void dsp_set_lock(dsp_ctrl_t* ctrl) -{ - ctrl->img_lock = 1; -} - -void dsp_reset_lock(dsp_ctrl_t* ctrl) -{ - ctrl->img_lock = 0; -} - -uint8_t dsp_img_percent(uint8_t value, dsp_style_t style, dsp_ctrl_t* ctrl) -{ - if(ctrl->img_lock) return ctrl->act_img; - - switch(style) - { - case LED_DSP_BAR: - ctrl->act_img = img_gen_bar(value); - break; - - case LED_DSP_DOT10: - ctrl->act_img = img_gen_dot10(value); - break; - - default: - ctrl->act_img = img_gen_dot20(value); - break; - } - - return ctrl->act_img; -} - -uint8_t dsp_img_raw(uint8_t image, dsp_ctrl_t* ctrl) -{ - if(ctrl->img_lock) return ctrl->act_img; - - ctrl->act_img = image & 0x3F; - - return ctrl->act_img; -} - -uint8_t dsp_get_act_img(dsp_ctrl_t* ctrl) -{ - return ctrl->act_img; -} - -uint8_t dsp_backlight(uint8_t dimm_act) -{ - if(dimm_act) return BACKLIGHT_DIMM; - else return BACKLIGHT_BRIGTH; -} - -/**** Private function definitions ****/ -static uint8_t img_gen_dot10(uint8_t percent) -{ - if(percent<6) return 0x01; - else if(percent<16) return 0x03; - else if(percent<26) return 0x02; - else if(percent<36) return 0x06; - else if(percent<46) return 0x04; - else if(percent<56) return 0x0C; - else if(percent<66) return 0x08; - else if(percent<76) return 0x18; - else if(percent<86) return 0x10; - else if(percent<96) return 0x30; - else return 0x20; -} - -static uint8_t img_gen_dot20(uint8_t percent) -{ - if(percent<11) return 0x01; - else if(percent<31) return 0x02; - else if(percent<51) return 0x04; - else if(percent<71) return 0x08; - else if(percent<91) return 0x10; - else return 0x20; -} - -static uint8_t img_gen_bar(uint8_t percent) -{ - if(percent<11) return 0x01; - else if(percent<31) return 0x03; - else if(percent<51) return 0x07; - else if(percent<71) return 0x0F; - else if(percent<91) return 0x1F; - else return 0x3F; -} diff --git a/firmware/src/logic/display.h b/firmware/src/logic/display.h deleted file mode 100644 index 588bd79..0000000 --- a/firmware/src/logic/display.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef LOGIC_DISPLAY_H_ -#define LOGIC_DISPLAY_H_ - -/**** Includes ****/ -#include - -/**** Public definitions ****/ -#define DSP_BACKLIGHT_DIMM_PERCENT 50 -#define DSP_BACKLIGHT_BRIGTH_PERCENT 100 - -typedef enum { - LED_DSP_DOT20, - LED_DSP_DOT10, - LED_DSP_BAR -} dsp_style_t; - -typedef struct { - uint8_t img_lock; - uint8_t act_img; -} dsp_ctrl_t; - -/**** Public function declarations ****/ -void dsp_init_ctrl(dsp_ctrl_t* ctrl); - -void dsp_set_lock(dsp_ctrl_t* ctrl); -void dsp_reset_lock(dsp_ctrl_t* ctrl); - -uint8_t dsp_img_percent(uint8_t value, dsp_style_t style, dsp_ctrl_t* ctrl); -uint8_t dsp_img_raw(uint8_t image, dsp_ctrl_t* ctrl); -uint8_t dsp_get_act_img(dsp_ctrl_t* ctrl); - -uint8_t dsp_backlight(uint8_t dimm_act); - -#ifdef TESTING -#endif - -#endif /* LOGIC_DISPLAY_H_ */ diff --git a/firmware/src/logic/force.c b/firmware/src/logic/force.c deleted file mode 100644 index adee492..0000000 --- a/firmware/src/logic/force.c +++ /dev/null @@ -1,63 +0,0 @@ -/**** Includes ****/ -#include "force.h" - -/**** Private definitions ****/ -/**** Private constants ****/ -static const uint16_t MAX_HBRAKE_HOLD_TIME = FORCE_MAX_HBRAKE_HOLD_TIME; - -/**** Private variables ****/ -/**** Private function declarations ****/ - -/**** Public function definitions ****/ -#ifdef TESTING -#endif - -uint8_t force_next(uint8_t handbrake, uint8_t brakes, fbrake_mode_t bmode, uint8_t user_force, uint16_t hbarke_act_time) -{ - // Do force logic - if((handbrake)&&(hbarke_act_time < MAX_HBRAKE_HOLD_TIME)) - { - return 0; - } - else if(brakes) - { - switch(bmode) - { - case FORCE_BMODE_KEEP: - return user_force; - break; - - case FORCE_BMODE_LOCK: - return 100; - break; - - default: //FORCE_BMODE_OPEN - return 0; - break; - } - } - else - { - return user_force; - } - - return 0; -} - -fbrake_mode_t force_cycle_bmode(fbrake_mode_t bmode) -{ - switch(bmode) - { - case FORCE_BMODE_OPEN: - return FORCE_BMODE_KEEP; - - case FORCE_BMODE_KEEP: - return FORCE_BMODE_LOCK; - - default: - return FORCE_BMODE_OPEN; - } -} - -/**** Private function definitions ****/ - diff --git a/firmware/src/logic/force.h b/firmware/src/logic/force.h deleted file mode 100644 index 4655b45..0000000 --- a/firmware/src/logic/force.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef FORCE_H_ -#define FORCE_H_ - -/**** Includes ****/ -#include - -/**** Public definitions ****/ -#define FORCE_MAX_HBRAKE_HOLD_TIME 1000 - -typedef enum { - FORCE_BMODE_OPEN, - FORCE_BMODE_KEEP, - FORCE_BMODE_LOCK -} fbrake_mode_t; - -/**** Public function declarations ****/ -uint8_t force_next(uint8_t handbrake, uint8_t brakes, fbrake_mode_t bmode, uint8_t user_force, uint16_t hbarke_act_time); -fbrake_mode_t force_cycle_bmode(fbrake_mode_t bmode); - -#ifdef TESTING -#endif - -#endif /* FORCE_H_ */ \ No newline at end of file diff --git a/firmware/src/logic/pot.c b/firmware/src/logic/pot.c deleted file mode 100644 index 932639c..0000000 --- a/firmware/src/logic/pot.c +++ /dev/null @@ -1,42 +0,0 @@ -/**** Includes ****/ -#include "pot.h" - -/**** Private definitions ****/ -/**** Private constants ****/ -/**** Private variables ****/ -/**** Private function declarations ****/ -/**** Public function definitions ****/ -#ifdef TESTING -#endif - -uint8_t pot_mv_to_percent(uint16_t value, pot_cfg_t* cfg) -{ - // Setup limits - uint16_t bottom = 0; - uint16_t top = cfg->reference; - - // Adjust for top and bottom deadband - if(bottom < cfg->deadband) bottom = cfg->deadband; - if(top > cfg->deadband) top -= cfg->deadband; - - // Calculate percent - if(value <= bottom) return 0; - else if(value >= top) return 100; - else - { - // Adjust values for offset - if(bottom) - { - value = value - bottom; - top = top - bottom; - }; - - uint32_t y = (uint32_t)value * 100; - y = y/(uint32_t)top; - - return (uint16_t)y; - } -} - -/**** Private function definitions ****/ - diff --git a/firmware/src/logic/pot.h b/firmware/src/logic/pot.h deleted file mode 100644 index d77c46b..0000000 --- a/firmware/src/logic/pot.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef POTENTIOMETER_H_ -#define POTENTIOMETER_H_ - -/**** Includes ****/ -#include - -/**** Public definitions ****/ -typedef struct { - uint16_t reference; - uint16_t deadband; -} pot_cfg_t; - -/**** Public function declarations ****/ -uint8_t pot_mv_to_percent(uint16_t value, pot_cfg_t* cfg); - -#ifdef TESTING -#endif - -#endif /* POTENTIOMETER_H_ */ \ No newline at end of file diff --git a/firmware/src/logic/user_force.c b/firmware/src/logic/user_force.c deleted file mode 100644 index 5f856cd..0000000 --- a/firmware/src/logic/user_force.c +++ /dev/null @@ -1,52 +0,0 @@ -/**** Includes ****/ -#include "user_force.h" - -/**** Private definitions ****/ -/**** Private constants ****/ -static const uint8_t MAX_PERCENT = USER_FORCE_MAX_PERCENT; -static const uint8_t MIN_PERCENT = USER_FORCE_MIN_PERCENT; - -/**** Private variables ****/ -/**** Private function declarations ****/ -/**** Public function definitions ****/ -#ifdef TESTING -#endif - -uint8_t user_force_btn(uint8_t prev_force, uint8_t up_act, uint8_t down_act, uint8_t delta) -{ - uint8_t new_froce = prev_force; - - if(up_act) - { - new_froce = prev_force + delta; - // Limit overflow and top value - if(new_froce < prev_force) new_froce = 100; - else if(new_froce < MIN_PERCENT) new_froce = MIN_PERCENT; - }; - - if(down_act) - { - new_froce = prev_force - delta; - // Limit overflow and top value - if(new_froce > prev_force) new_froce = 0; - else if(new_froce > MAX_PERCENT) new_froce = MAX_PERCENT; - }; - - // Do deadband - if(new_froce < MIN_PERCENT) new_froce = 0; - else if(new_froce > MAX_PERCENT) new_froce = 100; - - return new_froce; -} - -uint8_t user_force_pot(uint8_t prev_force, uint8_t pot, uint8_t hyst) -{ - uint8_t new_froce = pot; - - if(new_froce < MIN_PERCENT) new_froce = 0; - else if(new_froce > MAX_PERCENT) new_froce = 100; - - return new_froce; -} - -/**** Private function definitions ****/ diff --git a/firmware/src/logic/user_force.h b/firmware/src/logic/user_force.h deleted file mode 100644 index a7b5aa4..0000000 --- a/firmware/src/logic/user_force.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef USER_FORCE_H_ -#define USER_FORCE_H_ - -/**** Includes ****/ -#include - -/**** Public definitions ****/ -#define USER_FORCE_MAX_PERCENT 90 -#define USER_FORCE_MIN_PERCENT 10 - -/**** Public function declarations ****/ -uint8_t user_force_btn(uint8_t prev_force, uint8_t up_act, uint8_t down_act, uint8_t delta); -uint8_t user_force_pot(uint8_t prev_force, uint8_t pot, uint8_t hyst); - -#ifdef TESTING -#endif - -#endif /* USER_FORCE_H_ */ \ No newline at end of file diff --git a/firmware/src/main.c b/firmware/src/main.c deleted file mode 100644 index b1d9d5b..0000000 --- a/firmware/src/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/**** Includes ****/ -#include - -// Hardware IO -#include "hw/startup.h" -#include "hw/analog.h" -#include "hw/buttons.h" -#include "hw/hb_control.h" -#include "hw/led_display.h" - -// Logic blocks -#include "logic/coil.h" -#include "logic/display.h" -#include "logic/force.h" -#include "logic/pot.h" -#include "logic/user_force.h" - -/**** Private definitions ****/ -/**** Private constants ****/ -/**** Private variables ****/ -static volatile uint8_t user_force = 0; -static volatile uint8_t user_force_step = 10; - -static volatile fbrake_mode_t bmode = FORCE_BMODE_OPEN; - -static volatile uint8_t next_force = 0; -static volatile int16_t next_target = 0; - -static volatile hb_feedback_t hb_feedback; -static volatile hb_control_t hb_ctrl; - -static volatile uint8_t backlight = 0; -static volatile dsp_ctrl_t dsp_logic_ctrl; - -/**** Private function declarations ****/ - -/**** Public function definitions ****/ -int main(void) -{ - hw_startup(); - - // Create objects for all buttons - btn_t btn_mode; - btn_t btn_down; - btn_t btn_up; - btn_t btn_dimm; - btn_t btn_brakes; - btn_t btn_handbrake; - btn_t btn_handbrake_dir; - - // Set button pulls - //btn_ch_set_pull(BTN_1, BTN_PULL_HIGH); - //btn_ch_set_pull(BTN_2, BTN_PULL_HIGH); - //btn_ch_set_pull(BTN_3, BTN_PULL_HIGH); - btn_ch_set_pull(BTN_6, BTN_PULL_HIGH); - - // Create object for half-bridge control - - // Initialize half-bridge - hb_init(&hb_feedback, &hb_ctrl); - hb_enable(&hb_ctrl); - - // Init display backlight - dsp_init_ctrl(&dsp_logic_ctrl); - backlight = dsp_backlight(1); - led_dsp_backligth_set(backlight); - - while(1) - { - // Read buttons - btn_ch_process(BTN_1, &btn_mode); - btn_ch_process(BTN_2, &btn_down); - btn_ch_process(BTN_3, &btn_up); - btn_ch_process(BTN_4, &btn_dimm); - btn_ch_process(BTN_5, &btn_brakes); - btn_ch_process(BTN_6, &btn_handbrake); - btn_ch_process(BTN_6N, &btn_handbrake_dir); - - // Process user force changes - if((btn_up.new_state)||(btn_down.new_state)) - { - uint8_t up_act = btn_up.new_state & btn_up.state; - uint8_t down_act = btn_down.new_state & btn_down.state; - - user_force = user_force_btn(user_force, up_act, down_act, user_force_step); - btn_up.new_state = 0; - btn_down.new_state = 0; - }; - - // Process brake mode changes - if(btn_mode.new_state) - { - if(btn_mode.state) bmode = force_cycle_bmode(bmode); - btn_mode.new_state = 0; - }; - - // Calculate next force - next_force = force_next(btn_handbrake.state, btn_brakes.state, bmode, user_force, btn_handbrake.state_time); - - // Calculate next coil target - next_target = coil_target(next_force, btn_handbrake.state); - - // Read Half-bridge status and apply next target - hb_process(next_target, &hb_feedback, &hb_ctrl); - - // Generate image of current force - uint8_t img = 0x00; - - if(hb_feedback.fused) img = 0xAA; - else img = dsp_img_percent(next_force, LED_DSP_DOT10); - - // Apply image - led_dsp_set_image(img); - - // Process display backlight - if(btn_dimm.new_state) - { - backlight = dsp_backlight(btn_dimm.state); - led_dsp_backligth_set(backlight); - btn_dimm.new_state = 0; - }; - } - - return 0; -} - -/**** Private function definitions ****/ diff --git a/firmware/src/main.cpp b/firmware/src/main.cpp new file mode 100644 index 0000000..f1f6d4c --- /dev/null +++ b/firmware/src/main.cpp @@ -0,0 +1,60 @@ +/**** Includes ****/ +#include "utils/utils.h" + +#include "dccd/dccd_hw.h" +#include "dccd/dccd.h" + +/**** Private definitions ****/ +/**** Private constants ****/ +/**** Private variables ****/ +static dccd::DccdHw dccd_hw; +static dccd::DccdApp app; + +/**** Private function declarations ****/ +/**** Public function definitions ****/ +int main(void) +{ + // Setup + dccd::DccdHw::dccdHwCfg_t cfg; + cfg.handbrake_pull_up = 1; + cfg.pwm_f_khz = 16; + cfg.speed_hall = 0; + cfg.counter_step_us = 2000; + dccd_hw.init(&cfg); + + app.init(&dccd_hw); + + //#define OVERRIDECFG + #ifdef OVERRIDECFG + // Configuration + app.lock_current = 4500; + app.max_hbrake_time = 2000; + app.button_inputs = 1; + app.display_brigth = 100; + app.display_dimm = 25; + + // Initial values + app.btn_force = 0; + app.brake_mode = 0; + #endif + + // Save config to memory + //#define SAVECFG + #ifdef SAVECFG + app.saveMemCfg(); + #endif + + // Super loop + while(1) + { + // Do stuff + app.process(); + // End of super loop + continue; + } + + // Escape the matrix + return 0; +} + +/**** Private function definitions ***/ \ No newline at end of file diff --git a/firmware/src/uDCCD_Controller.atsln b/firmware/src/uDCCD.atsln similarity index 85% rename from firmware/src/uDCCD_Controller.atsln rename to firmware/src/uDCCD.atsln index c9942df..b3332d3 100644 --- a/firmware/src/uDCCD_Controller.atsln +++ b/firmware/src/uDCCD.atsln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Atmel Studio Solution File, Format Version 11.00 VisualStudioVersion = 14.0.23107.0 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "uDCCD_Controller", "uDCCD_Controller.cproj", "{DCE6C7E3-EE26-4D79-826B-08594B9AD897}" +Project("{E66E83B9-2572-4076-B26E-6BE79FF3018A}") = "uDCCD", "uDCCD.cppproj", "{DCE6C7E3-EE26-4D79-826B-08594B9AD897}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/firmware/src/uDCCD_Controller.componentinfo.xml b/firmware/src/uDCCD.componentinfo.xml similarity index 96% rename from firmware/src/uDCCD_Controller.componentinfo.xml rename to firmware/src/uDCCD.componentinfo.xml index 49393d5..03bd101 100644 --- a/firmware/src/uDCCD_Controller.componentinfo.xml +++ b/firmware/src/uDCCD.componentinfo.xml @@ -41,7 +41,7 @@ template source C Exe - YLr2MkKo6ZooP7MhARWYNA== + KjvOcFWd++tbnsEMfVPd/w== templates/main.c Main file (.c) @@ -52,7 +52,7 @@ template source C Exe - mkKaE95TOoATsuBGv6jmxg== + w5aB/d0+DbxGZ7yY0aMMjw== templates/main.cpp Main file (.cpp) diff --git a/firmware/src/uDCCD_Controller.cproj b/firmware/src/uDCCD.cppproj similarity index 60% rename from firmware/src/uDCCD_Controller.cproj rename to firmware/src/uDCCD.cppproj index fd9019a..983558e 100644 --- a/firmware/src/uDCCD_Controller.cproj +++ b/firmware/src/uDCCD.cppproj @@ -3,18 +3,18 @@ 2.0 7.0 - com.Atmel.AVRGCC8.C + com.Atmel.AVRGCC8.CPP dce6c7e3-ee26-4d79-826b-08594b9ad897 ATmega328PB none Executable - C + CPP $(MSBuildProjectName) .elf $(MSBuildProjectDirectory)\$(Configuration) - uDCCD_Controller - uDCCD_Controller - uDCCD_Controller + uDCCD + uDCCD + uDCCD Native true false @@ -26,17 +26,17 @@ exception_table 2 0 - 1 + 0 - + - + @@ -46,20 +46,20 @@ - 125000 + 249992 - debugWIRE + ISP com.atmel.avrdbg.tool.atmelice J42700001490 Atmel-ICE - debugWIRE - 125000 + ISP + 249992 - + -mmcu=atmega328pb -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.7.374\gcc\dev\atmega328pb" True True @@ -82,22 +82,38 @@ True True True - + True + True + - libm + NDEBUG - - + + %24(PackRepoDir)\atmel\ATmega_DFP\1.7.374\include\ - - + + Optimize for size (-Os) + True + True + True + + + libm + + + + + %24(PackRepoDir)\atmel\ATmega_DFP\1.7.374\include\ + + + - + -mmcu=atmega328pb -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.7.374\gcc\dev\atmega328pb" True True @@ -116,161 +132,167 @@ %24(PackRepoDir)\atmel\ATmega_DFP\1.7.374\include\ + Optimize debugging experience (-Og) True True Default (-g2) True - + True + True + - libm + DEBUG - - + + %24(PackRepoDir)\atmel\ATmega_DFP\1.7.374\include\ - - Default (-Wa,-g) - + + Optimize debugging experience (-Og) + True + True + Default (-g2) + True + + + libm + + + + + %24(PackRepoDir)\atmel\ATmega_DFP\1.7.374\include\ + + + Default (-Wa,-g) + - + compile - + compile - + compile - + compile - + compile - + compile - + compile - + compile - + compile - + compile - + compile - + compile - + compile - + compile - + compile - + compile - + compile - + compile - + compile - + compile - + compile - + compile - - compile - - - compile - - - compile - - - compile - - - compile - - - compile - - + compile compile - + compile - + compile - + compile - + compile - + compile - + compile - + compile - + compile - + compile - + compile - + compile - + compile - + + compile + + + compile + + compile + + - - - - + + \ No newline at end of file diff --git a/firmware/src/utils/interpolate.cpp b/firmware/src/utils/interpolate.cpp new file mode 100644 index 0000000..a9af4c7 --- /dev/null +++ b/firmware/src/utils/interpolate.cpp @@ -0,0 +1,163 @@ +/**** Includes ****/ +#include "utils.h" +#include "interpolate.h" + +using namespace util; + +/**** Private definitions ****/ +/**** Private constants ****/ +/**** Private variables ****/ +/**** Private function declarations ****/ +/**** Public function definitions ****/ +uint16_t util::interpolate_1d(uint16_t x, uint16_t* x_axis, uint16_t* y_values, uint8_t len_axis) +{ + // validate axis length + if(len_axis==0) return 0; // Empty data set + if(len_axis==1) return y_values[0]; // Only one data point + + uint16_t y; + + uint8_t i = find_interval_end_index(x, x_axis, len_axis); + if(i==0) + { + //Less then start + y = y_values[0]; + } + else if(i==len_axis) + { + //More than end + y = y_values[len_axis-1]; + } + else + { + // Do interpolate + y = interpolate(x, x_axis[i-1], x_axis[i], y_values[i-1], y_values[i]); + } + + return y; +} + +uint16_t util::interpolate_2d(uint16_t x, uint16_t y, uint16_t* x_axis, uint8_t len_x_axis, uint16_t* y_axis, uint8_t len_y_axis, uint16_t* z_values) +{ + // validate axis length + if((len_x_axis==0)&&(len_y_axis==0)) return 0; // Empty data set + if((len_x_axis==1)&&(len_y_axis==1)) return z_values[0]; // Only one data point + + uint8_t ix = find_interval_end_index(x, x_axis, len_x_axis); + uint8_t iy = find_interval_end_index(y, y_axis, len_y_axis); + + // Check corners - easy answers + if((ix==0)&&(iy==0)) + { + return z_values[0]; //[0][0] [Y][X] + } + else if((ix==len_x_axis)&&(iy==0)) + { + return z_values[len_x_axis-1]; //[0][end] + } + else if((ix==0)&&(iy==len_y_axis)) + { + uint16_t i = index2d_to_index1d(0, len_y_axis-1, len_x_axis); + return z_values[i]; //[end][0] + } + else if((ix==len_x_axis)&&(iy==len_y_axis)) + { + uint16_t i = index2d_to_index1d(len_x_axis-1, len_y_axis-1, len_x_axis); + return z_values[i]; //[end][end] + }; + + // Check boundaries - 1D interpolation + if(ix==0) + { + // On ix=0 line + uint16_t i = 0; + uint16_t z0 = z_values[i]; + i = index2d_to_index1d(0, len_y_axis-1, len_x_axis); + uint16_t z1 = z_values[i]; + return interpolate(y, y_axis[0], y_axis[len_y_axis-1], z0, z1); + } + else if(ix==len_x_axis) + { + // On ix=END line + uint16_t i = len_x_axis-1; + uint16_t z0 = z_values[i]; + i = index2d_to_index1d(len_x_axis-1, len_y_axis-1, len_x_axis); + uint16_t z1 = z_values[i]; + return interpolate(y, y_axis[0], y_axis[len_y_axis-1], z0, z1); + } + else if(iy==0) + { + // On iy=0 line + uint16_t i = 0; + uint16_t z0 = z_values[i]; + i = len_x_axis-1; + uint16_t z1 = z_values[i]; + return interpolate(x, x_axis[0], x_axis[len_x_axis-1], z0, z1); + } + else if(iy==len_y_axis) + { + // On iy=END line + uint16_t i = index2d_to_index1d(0, len_y_axis-1, len_x_axis); + uint16_t z0 = z_values[i]; + i = index2d_to_index1d(len_x_axis-1, len_y_axis-1, len_x_axis); + uint16_t z1 = z_values[i]; + return interpolate(x, x_axis[0], x_axis[len_x_axis-1], z0, z1); + } + + // Do interpolation + // Get axis values + uint16_t x0 = x_axis[ix-1]; + uint16_t x1 = x_axis[ix]; + uint16_t y0 = y_axis[iy-1]; + uint16_t y1 = y_axis[iy]; + + // Do y0 line calculation + // Get z values at x0 and x1 points on y0 line + uint16_t i = index2d_to_index1d(ix-1, iy-1, len_x_axis); + uint16_t z0 = z_values[i]; + uint16_t z1 = z_values[i+1]; + // Interpolate z value on y0 line + uint16_t zy0 = interpolate(x, x0, x1, z0, z1); + + // Do y1 line calculation + // Get z values at x0 and x1 points on y1 line + i = index2d_to_index1d(ix-1, iy, len_x_axis); + z0 = z_values[i]; + z1 = z_values[i+1]; + // Interpolate z value on y0 line + uint16_t zy1 = interpolate(x, x0, x1, z0, z1); + + // Do calculation in y axis on xz line + return interpolate(y, y0, y1, zy0, zy1); +} + +uint16_t util::interpolate(uint16_t x, uint16_t x0, uint16_t x1, uint16_t y0, uint16_t y1) +{ + int32_t dy = (int32_t)y1 - (int32_t)y0; + int32_t dx = (int32_t)x1 - (int32_t)x0; + int32_t d = (int32_t)x - (int32_t)x0; + + int32_t y = dy * d; + y /= dx; + y += y0; + + return util::sat_cast(y); +} + +uint8_t util::find_interval_end_index(uint16_t val, uint16_t* axis_values, uint8_t len_axis) +{ + for(uint8_t i=0; i + +namespace util { + +/**** Public definitions ****/ +/**** Public function declarations ****/ +uint16_t interpolate_1d(uint16_t x, uint16_t* x_axis, uint16_t* y_values, uint8_t len_axis); +uint16_t interpolate_2d(uint16_t x, uint16_t y, uint16_t* x_axis, uint8_t len_x_axis, uint16_t* y_axis, uint8_t len_y_axis, uint16_t* z_values); + +uint8_t find_interval_end_index(uint16_t val, uint16_t* axis_values, uint8_t len_axis); +uint16_t interpolate(uint16_t x, uint16_t x0, uint16_t x1, uint16_t y0, uint16_t y1); +uint16_t index2d_to_index1d(uint8_t ix, uint8_t iy, uint8_t len_x); + +#ifdef TESTING +#endif + +} //namespace + +#endif /* UTILS_INTERPOLATE_H_ */ \ No newline at end of file diff --git a/firmware/src/utils/utils.cpp b/firmware/src/utils/utils.cpp new file mode 100644 index 0000000..ad9e02c --- /dev/null +++ b/firmware/src/utils/utils.cpp @@ -0,0 +1,216 @@ +/**** Includes ****/ +#include "utils.h" + +using namespace util; + +/**** Private definitions ****/ +/**** Private constants ****/ +/**** Private variables ****/ +/**** Private function declarations ****/ +#ifndef TESTING +#endif + +/**** Public function definitions ****/ +uint8_t util::invert(uint8_t x) +{ + if(x!=0) return 0; + else return 1; +} + +uint16_t util::invert(uint16_t x) +{ + if(x!=0) return 0; + else return 1; +} + +uint32_t util::invert(uint32_t x) +{ + if(x!=0) return 0; + else return 1; +} + +uint8_t util::sat_add(uint8_t x, uint8_t y) +{ + uint8_t z = x + y; + // Check for overflow + if((z < x)||(z < y)) return 0xFF; + else return z; +} + +uint16_t util::sat_add(uint16_t x, uint16_t y) +{ + uint16_t z = x + y; + // Check for overflow + if((z < x)||(z < y)) return 0xFF; + else return z; +} + +uint32_t util::sat_add(uint32_t x, uint32_t y) + +{ + uint32_t z = x + y; + // Check for overflow + if((z < x)||(z < y)) return 0xFF; + else return z; +} + +uint8_t util::sat_subtract(uint8_t x, uint8_t y) +{ + uint8_t z = x - y; + // Check for underflow + if(z > x) return 0; + else return z; +} + +uint16_t util::sat_subtract(uint16_t x, uint16_t y) +{ + uint16_t z = x - y; + // Check for underflow + if(z > x) return 0; + else return z; +} +uint32_t util::sat_subtract(uint32_t x, uint32_t y) +{ + uint32_t z = x - y; + // Check for underflow + if(z > x) return 0; + else return z; +} + +uint8_t util::abs_subtract(uint8_t x, uint8_t y) +{ + if(x > y) return x - y; + else return y-x; +} + +uint16_t util::abs_subtract(uint16_t x, uint16_t y) +{ + if(x > y) return x - y; + else return y-x; +} + +uint32_t util::abs_subtract(uint32_t x, uint32_t y) +{ + if(x > y) return x - y; + else return y-x; +} + + +uint16_t util::sat_cast(uint32_t x) +{ + if(x > 0x0000FFFF) return 0xFFFF; + else return (uint16_t)x; +} + +uint16_t util::sat_cast(int32_t x) +{ + if(x < 0) return 0x0000; + else if(x > 0x0000FFFF) return 0xFFFF; + else return (uint16_t)x; +} + +uint8_t util::is_timed_out(uint16_t time, uint16_t limit) +{ + if(time >= limit) return 1; + else return 0; +} + +uint8_t util::is_in_range(uint16_t value, uint16_t min, uint16_t max) +{ + if((value >= min)&&(value <= max)) return 1; + else return 0; +} + +uint16_t util::time_delta(uint16_t start, uint16_t end) +{ + if(end >= start) return (end-start); + uint16_t temp = 0xFFFF - start; + return temp + end; +} + +uint32_t util::time_delta(uint32_t start, uint32_t end) +{ + if(end >= start) return (end-start); + uint32_t temp = 0xFFFFFFFF - start; + return temp + end; +} + +uint16_t util::time_delta(uint16_t start, uint16_t end, uint16_t max) +{ + if(end >= start) return (end-start); + uint16_t temp = max - start; + return temp + end; +} + +uint32_t util::time_delta(uint32_t start, uint32_t end, uint32_t max) +{ + if(end >= start) return (end-start); + uint32_t temp = max - start; + return temp + end; +} + +uint16_t util::convert_muldivoff(uint16_t raw, uint8_t mul, uint8_t div, int16_t offset) +{ + int32_t temp = (int32_t)raw; + + temp = temp * mul; + if(div>1) temp /= div; + temp += offset; + + return sat_cast(temp); +} + +uint16_t util::sat_mul_kilo(uint16_t xk, uint16_t yk) +{ + uint32_t temp = (uint32_t)xk * (uint32_t)yk; + temp /= 1000; + + return sat_cast(temp); +} + +uint16_t util::sat_div_kilo(uint16_t top, uint16_t bot) +{ + //Sanity check bot + if(bot==0) return 0xFFFF; //aka infinity + + uint32_t temp = (uint32_t)top * 1000; + temp /= (uint32_t)bot; + + return sat_cast(temp); +} + +uint16_t util::sat_ratio(uint16_t top, uint16_t bot) +{ + //Sanity check bot + if(bot==0) return 0xFFFF; //aka infinity + + //Easy option + if(top>=bot) return 0xFFFF; + + uint32_t temp = (uint32_t)top * 0x0000FFFF; + temp /= (uint32_t)bot; + + return sat_cast(temp); +} + +uint16_t util::percent_to_16b(uint8_t percent) +{ + uint32_t temp = (uint32_t)percent * 0x0000FFFF; + temp /= 100; + + // Limit to 16 bits + uint16_t pwm = sat_cast(temp); + + return pwm; +} + +uint16_t util::percent_of(uint8_t percent, uint16_t value) +{ + if(percent == 0) return 0; + else if(percent >= 100) return value; + + uint32_t temp = (uint32_t)value * percent; + return temp/100; +} + +/**** Private function definitions ****/ \ No newline at end of file diff --git a/firmware/src/utils/utils.h b/firmware/src/utils/utils.h new file mode 100644 index 0000000..12d6687 --- /dev/null +++ b/firmware/src/utils/utils.h @@ -0,0 +1,52 @@ +#ifndef UTILS_H_ +#define UTILS_H_ + +/**** Includes ****/ +#include + +namespace util { + +/**** Public definitions ****/ +/**** Public function declarations ****/ +uint8_t invert(uint8_t x); +uint16_t invert(uint16_t x); +uint32_t invert(uint32_t x); + +uint8_t sat_add(uint8_t x, uint8_t y); +uint16_t sat_add(uint16_t x, uint16_t y); +uint32_t sat_add(uint32_t x, uint32_t y); + +uint8_t sat_subtract(uint8_t x, uint8_t y); +uint16_t sat_subtract(uint16_t x, uint16_t y); +uint32_t sat_subtract(uint32_t x, uint32_t y); + +uint8_t abs_subtract(uint8_t x, uint8_t y); +uint16_t abs_subtract(uint16_t x, uint16_t y); +uint32_t abs_subtract(uint32_t x, uint32_t y); + +uint16_t sat_cast(uint32_t x); +uint16_t sat_cast(int32_t x); + +uint8_t is_timed_out(uint16_t time, uint16_t limit); +uint8_t is_in_range(uint16_t value, uint16_t min, uint16_t max); + +uint16_t time_delta(uint16_t start, uint16_t end); +uint32_t time_delta(uint32_t start, uint32_t end); + +uint16_t time_delta(uint16_t start, uint16_t end, uint16_t max); +uint32_t time_delta(uint32_t start, uint32_t end, uint32_t max); + +uint16_t convert_muldivoff(uint16_t raw, uint8_t mul, uint8_t div, int16_t offset); +uint16_t sat_mul_kilo(uint16_t xk, uint16_t yk); +uint16_t sat_div_kilo(uint16_t top, uint16_t bot); +uint16_t sat_ratio(uint16_t top, uint16_t bot); +uint16_t percent_to_16b(uint8_t percent); + +uint16_t percent_of(uint8_t percent, uint16_t value); + +#ifdef TESTING +#endif + +} //namespace + +#endif /* UTILS_H_ */ \ No newline at end of file diff --git a/firmware/src/utils/vcounter.cpp b/firmware/src/utils/vcounter.cpp new file mode 100644 index 0000000..6870cc1 --- /dev/null +++ b/firmware/src/utils/vcounter.cpp @@ -0,0 +1,67 @@ +/**** Includes ****/ +#include "utils.h" +#include "vcounter.h" + +using namespace util; + +/**** Private definitions ****/ +/**** Private constants ****/ +/**** Private variables ****/ +/**** Private function declarations ****/ +/**** Public function definitions ****/ +util::VCounter::VCounter(void) +{ + return; +} + +util::VCounter::~VCounter(void) +{ + return; +} + +void util::VCounter::init(uint16_t top, uint16_t step_us) +{ + this->counter = 0; + this->top = top; + this->step_us = step_us; + this->disabled = 1; +} + +void util::VCounter::reset(void) +{ + this->counter = 0; +} + +void util::VCounter::increment(void) +{ + if(this->disabled) return; + this->counter++; + if(this->counter > this->top) this->counter = 0; +} + +uint16_t util::VCounter::read(void) +{ + return this->counter; +} + +uint32_t util::VCounter::read_ms(void) +{ + return this->convert_ms(this->counter); +} + +uint16_t util::VCounter::read_top(void) +{ + return this->top; +} + +uint32_t util::VCounter::convert_ms(uint16_t raw) +{ + if(this->step_us==0) return 0; + + uint32_t out = (uint32_t)raw * (uint32_t)this->step_us; + return out/1000; +} + + +/**** Private function definitions ****/ + diff --git a/firmware/src/utils/vcounter.h b/firmware/src/utils/vcounter.h new file mode 100644 index 0000000..557bac8 --- /dev/null +++ b/firmware/src/utils/vcounter.h @@ -0,0 +1,42 @@ +#ifndef VIRTUAL_COUNTER_H_ +#define VIRTUAL_COUNTER_H_ + +/**** Includes ****/ +#include + +namespace util { + +/**** Public definitions ****/ +class VCounter +{ + public: + VCounter(void); + ~VCounter(void); + + void init(uint16_t top, uint16_t step_us); + + uint8_t disabled; + + void reset(void); + void increment(void); + uint16_t read(void); + uint32_t read_ms(void); + uint16_t read_top(void); + uint32_t convert_ms(uint16_t raw); + + #ifndef TESTING + protected: + #endif + uint16_t step_us; + uint16_t counter; + uint16_t top; +}; + +/**** Public function declarations ****/ + +#ifdef TESTING +#endif + +} //namespace + +#endif /* VIRTUAL_COUNTER_H_ */ \ No newline at end of file diff --git a/firmware/tests/Units_Tests.workspace b/firmware/tests/Units_Tests.workspace deleted file mode 100644 index 35d25d9..0000000 --- a/firmware/tests/Units_Tests.workspace +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/firmware/tests/Units_Tests.workspace.layout b/firmware/tests/Units_Tests.workspace.layout deleted file mode 100644 index 3fa6504..0000000 --- a/firmware/tests/Units_Tests.workspace.layout +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/firmware/tests/bsp_main.c b/firmware/tests/bsp_main.c deleted file mode 100644 index fe5a2b9..0000000 --- a/firmware/tests/bsp_main.c +++ /dev/null @@ -1,147 +0,0 @@ -#include -#include - -#include "ut_utils/ut_utils.h" -#include "ut_utils/ut_fault.h" -#include "ut_utils/ut_fuses.h" - -#include "ut_board/ut_ain.h" -#include "ut_board/ut_din.h" -#include "ut_board/ut_dout.h" -#include "ut_board/ut_halfbridge.h" -#include "ut_board/ut_odout.h" -#include "ut_board/ut_setup.h" - -int main() -{ - int tr; - int pass = 1; - - /* UTILITIES TESTS */ - printf("******************************************************\n"); - - tr = ut_util_invert_8b_test(); - if(!tr) pass = 0; - - tr = ut_util_sat_add_8b_test(); - if(!tr) pass = 0; - - tr = ut_util_sat_subtract_8b_test(); - if(!tr) pass = 0; - - tr = ut_util_sat_util_sat_add_16b_test(); - if(!tr) pass = 0; - - tr = ut_util_sat_subtract_16b_test(); - if(!tr) pass = 0; - - tr = ut_util_limit_u32b_to_u16b_test(); - if(!tr) pass = 0; - - tr = ut_util_limit_s32b_to_u16b_test(); - if(!tr) pass = 0; - - tr = ut_util_convert_muldivoff_test(); - if(!tr) pass = 0; - - tr = ut_util_sat_mul_kilo_test(); - if(!tr) pass = 0; - - tr = ut_util_sat_div_kilo_test(); - if(!tr) pass = 0; - - tr = ut_util_sat_ratio_16b_test(); - if(!tr) pass = 0; - - tr = ut_util_percent_to_16b_test(); - if(!tr) pass = 0; - - /* FAULT TESTS */ - printf("******************************************************\n"); - - tr = ut_fault_process_test(); - if(!tr) pass = 0; - - tr = ut_fault_is_active_test(); - if(!tr) pass = 0; - - tr = ut_fault_is_warning_test(); - if(!tr) pass = 0; - - tr = ut_fault_reset_test(); - if(!tr) pass = 0; - - /* FUSE TESTS */ - printf("******************************************************\n"); - - tr = ut_fuse_reset_test(); - if(!tr) pass = 0; - - /* AIN TESTS */ - printf("******************************************************\n"); - - tr = ut_bsp_ain_read_test(); - if(!tr) pass = 0; - - /* DIN TESTS */ - printf("******************************************************\n"); - - tr = ut_bsp_din_read_test(); - if(!tr) pass = 0; - - /* DOUT TESTS */ - printf("******************************************************\n"); - - tr = ut_bsp_dout_write_test(); - if(!tr) pass = 0; - - /* HALFBRIDGE TESTS */ - printf("******************************************************\n"); - - tr = ut_bsp_hb_write_low_test(); - if(!tr) pass = 0; - - tr = ut_bsp_hb_write_pwm_test(); - if(!tr) pass = 0; - - tr = ut_bsp_hb_read_meas_test(); - if(!tr) pass = 0; - - /* ODOUT TESTS */ - printf("******************************************************\n"); - - tr = ut_bsp_odout_write_test(); - if(!tr) pass = 0; - - tr = ut_bsp_odout_write_common_test(); - if(!tr) pass = 0; - - /* SETUP TESTS */ - printf("******************************************************\n"); - - tr = ut_bsp_startup_test(); - if(!tr) pass = 0; - - /* FINAL RESULT */ - printf("******************************************************\n"); - - tr = ut_util_interpolate_1d_u16b_test(); - if(!tr) pass = 0; - - tr = ut_util_interpolate_2d_u16b_test(); - if(!tr) pass = 0; - - - if(pass) - { - printf("ALL PASS\n\n"); - return 1; - } - else - { - printf("SOME FAIL\n\n"); - return 0; - } - - return 0; -} diff --git a/firmware/tests/hw_main.c b/firmware/tests/hw_main.c deleted file mode 100644 index 442e284..0000000 --- a/firmware/tests/hw_main.c +++ /dev/null @@ -1,102 +0,0 @@ -#include -#include - -#include "ut_hw/ut_analog.h" -#include "ut_hw/ut_buttons.h" -#include "ut_hw/ut_hb_control.h" -#include "ut_hw/ut_led_display.h" -#include "ut_hw/ut_startup.h" - -int main() -{ - int tr; - int pass = 1; - int t_cnt = 0; - int f_cnt = 0; - - /* ANALOG TESTS */ - printf("******************************************************\n"); - - tr = ut_analog_ch_get_test(); - t_cnt++; - if(!tr){ pass = 0; f_cnt++;}; - - /* BUTTON TESTS */ - printf("******************************************************\n"); - - tr = ut_btn_reset_test(); - t_cnt++; - if(!tr){ pass = 0; f_cnt++;}; - - tr = ut_btn_process_test(); - t_cnt++; - if(!tr){ pass = 0; f_cnt++;}; - - tr = ut_btn_ch_process_test(); - t_cnt++; - if(!tr){ pass = 0; f_cnt++;}; - - tr = ut_btn_ch_set_pull_test(); - t_cnt++; - if(!tr){ pass = 0; f_cnt++;}; - - /* HALFBRIDGE CONTROL TESTS */ - printf("******************************************************\n"); - - tr = ut_hb_is_equal_fb_struct_test(); - t_cnt++; - if(!tr){ pass = 0; f_cnt++;}; - - tr = ut_hb_is_equal_ctrl_struct_test(); - t_cnt++; - if(!tr){ pass = 0; f_cnt++;}; - - tr = ut_hb_init_test(); - t_cnt++; - if(!tr){ pass = 0; f_cnt++;}; - - tr = ut_hb_enable_test(); - t_cnt++; - if(!tr){ pass = 0; f_cnt++;}; - - tr = ut_hb_disable_test(); - t_cnt++; - if(!tr){ pass = 0; f_cnt++;}; - - tr = ut_hb_process_test(); - t_cnt++; - if(!tr){ pass = 0; f_cnt++;}; - - /* DISPLAY TESTS */ - printf("******************************************************\n"); - - tr = ut_led_dsp_set_image_test(); - t_cnt++; - if(!tr){ pass = 0; f_cnt++;}; - - tr = ut_led_dsp_backligth_set_test(); - t_cnt++; - if(!tr){ pass = 0; f_cnt++;}; - - /* STARTUP TESTS */ - printf("******************************************************\n"); - - tr = ut_hw_startup_test(); - t_cnt++; - if(!tr){ pass = 0; f_cnt++;}; - - printf("******************************************************\n"); - printf("\n%d TESTS DONE\n", t_cnt); - if(pass) - { - printf("ALL PASS\n\n"); - return 1; - } - else - { - printf("%d FAILED\n\n", f_cnt); - return 0; - } - - return 0; -} diff --git a/firmware/tests/logic_main.c b/firmware/tests/logic_main.c deleted file mode 100644 index 66d6d11..0000000 --- a/firmware/tests/logic_main.c +++ /dev/null @@ -1,98 +0,0 @@ -#include -#include - -#include "ut_logic/ut_coil.h" -#include "ut_logic/ut_display.h" -#include "ut_logic/ut_force.h" -#include "ut_logic/ut_pot.h" -#include "ut_logic/ut_user_force.h" - -int main() -{ - int tr; - int pass = 1; - int t_cnt = 0; - int f_cnt = 0; - - /* COIL TESTS */ - printf("******************************************************\n"); - - tr = ut_coil_target_test(); - t_cnt++; - if(!tr){ pass = 0; f_cnt++;}; - - /* DISPLAY TESTS */ - printf("******************************************************\n"); - - tr = ut_dsp_init_ctrl_test(); - t_cnt++; - if(!tr){ pass = 0; f_cnt++;}; - - tr = ut_dsp_set_lock_test(); - t_cnt++; - if(!tr){ pass = 0; f_cnt++;}; - - tr = ut_dsp_reset_lock_test(); - t_cnt++; - if(!tr){ pass = 0; f_cnt++;}; - - tr = ut_dsp_img_percent_test(); - t_cnt++; - if(!tr){ pass = 0; f_cnt++;}; - - tr = ut_dsp_img_raw_test(); - t_cnt++; - if(!tr){ pass = 0; f_cnt++;}; - - tr = ut_dsp_get_act_img_test(); - t_cnt++; - if(!tr){ pass = 0; f_cnt++;}; - - tr = ut_dsp_backlight_test(); - t_cnt++; - if(!tr){ pass = 0; f_cnt++;}; - - /* FORCE TESTS */ - printf("******************************************************\n"); - - tr = ut_force_cycle_bmode_test(); - t_cnt++; - if(!tr){ pass = 0; f_cnt++;}; - - tr = ut_force_next_test(); - t_cnt++; - if(!tr){ pass = 0; f_cnt++;}; - - /* POT TESTS */ - printf("******************************************************\n"); - - tr = ut_pot_mv_to_percent_test(); - t_cnt++; - if(!tr){ pass = 0; f_cnt++;}; - - /* USER FORCE TESTS */ - printf("******************************************************\n"); - - tr = ut_user_force_btn_test(); - t_cnt++; - if(!tr){ pass = 0; f_cnt++;}; - - tr = ut_user_force_pot_test(); - t_cnt++; - if(!tr){ pass = 0; f_cnt++;}; - - printf("******************************************************\n"); - printf("\n%d TESTS DONE\n", t_cnt); - if(pass) - { - printf("ALL PASS\n\n"); - return 1; - } - else - { - printf("%d FAILED\n\n", f_cnt); - return 0; - } - - return 0; -} diff --git a/firmware/tests/mock_board/mock_board_ain.c b/firmware/tests/mock_board/mock_board_ain.c deleted file mode 100644 index e7ca8f2..0000000 --- a/firmware/tests/mock_board/mock_board_ain.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "mock_board_ain.h" - -#define AIN_CH_CNT 5 -static uint8_t ain_ch = 0; -static uint16_t ain_data[AIN_CH_CNT+1]; - -uint16_t bsp_ain_read(uint8_t ch) -{ - if(ch > AIN_CH_CNT) return 0; - ain_ch = ch; - return ain_data[ch]; -} - -uint8_t mock_board_ain_read_ch(void) -{ - return ain_ch; -} - -void mock_board_ain_write_ch(uint8_t ch) -{ - ain_ch = ch; -} - -uint16_t mock_board_ain_read_data(uint8_t ch) -{ - return ain_data[ch]; -} - -void mock_board_ain_write_data(uint8_t ch, uint16_t value) -{ - ain_data[ch] = value; -} diff --git a/firmware/tests/mock_board/mock_board_ain.h b/firmware/tests/mock_board/mock_board_ain.h deleted file mode 100644 index 7807d3b..0000000 --- a/firmware/tests/mock_board/mock_board_ain.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef MOCK_BOARD_AIN_ -#define MOCK_BOARD_AIN_ - -#include -#include - -#include "..\..\src\hw\board\ain.h" - -uint8_t mock_board_ain_read_ch(void); -void mock_board_ain_write_ch(uint8_t ch); -uint16_t mock_board_ain_read_data(uint8_t ch); -void mock_board_ain_write_data(uint8_t ch, uint16_t value); - -#endif /* MOCK_BOARD_AIN_ */ diff --git a/firmware/tests/mock_board/mock_board_din.c b/firmware/tests/mock_board/mock_board_din.c deleted file mode 100644 index 018d90f..0000000 --- a/firmware/tests/mock_board/mock_board_din.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "mock_board_din.h" - -#define DIN_CH_CNT 9 -static uint8_t din_ch = 0; -static uint8_t din_data[DIN_CH_CNT]; - -uint8_t bsp_din_read(uint8_t ch) -{ - if(ch >= DIN_CH_CNT) return BSP_DIN_LOW; - din_ch = ch; - return din_data[ch]; -} - -uint8_t mock_board_din_read_ch(void) -{ - return din_ch; -} - -void mock_board_din_write_ch(uint8_t ch) -{ - din_ch = ch; -} - -uint8_t mock_board_din_read_data(uint8_t ch) -{ - return din_data[ch]; -} - -void mock_board_din_write_data(uint8_t ch, uint8_t value) -{ - din_data[ch] = value; -} diff --git a/firmware/tests/mock_board/mock_board_din.h b/firmware/tests/mock_board/mock_board_din.h deleted file mode 100644 index d117d60..0000000 --- a/firmware/tests/mock_board/mock_board_din.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef MOCK_BOARD_DIN_ -#define MOCK_BOARD_DIN_ - -#include -#include - -#include "..\..\src\hw\board\din.h" - -uint8_t mock_board_din_read_ch(void); -void mock_board_din_write_ch(uint8_t ch); -uint8_t mock_board_din_read_data(uint8_t ch); -void mock_board_din_write_data(uint8_t ch, uint8_t value); - -#endif /* MOCK_BOARD_DIN_ */ diff --git a/firmware/tests/mock_board/mock_board_dout.c b/firmware/tests/mock_board/mock_board_dout.c deleted file mode 100644 index 3dba81b..0000000 --- a/firmware/tests/mock_board/mock_board_dout.c +++ /dev/null @@ -1,31 +0,0 @@ -#include "mock_board_dout.h" - -#define DOUT_CH_CNT 7 -static uint8_t dout_ch = 0; -static int8_t dout_data[DOUT_CH_CNT]; - -void bsp_dout_write(uint8_t ch, int8_t lvl) -{ - if(ch < DOUT_CH_CNT) dout_data[ch] = lvl; - dout_ch = ch; -} - -uint8_t mock_board_dout_read_ch(void) -{ - return dout_ch; -} - -void mock_board_dout_write_ch(uint8_t ch) -{ - dout_ch = ch; -} - -int8_t mock_board_dout_read_data(uint8_t ch) -{ - return dout_data[ch]; -} - -void mock_board_dout_write_data(uint8_t ch, int8_t lvl) -{ - dout_data[ch] = lvl; -} diff --git a/firmware/tests/mock_board/mock_board_dout.h b/firmware/tests/mock_board/mock_board_dout.h deleted file mode 100644 index 8a9e058..0000000 --- a/firmware/tests/mock_board/mock_board_dout.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef MOCK_BOARD_DOUT_ -#define MOCK_BOARD_DOUT_ - -#include -#include - -#include "..\..\src\hw\board\dout.h" - -uint8_t mock_board_dout_read_ch(void); -void mock_board_dout_write_ch(uint8_t ch); -int8_t mock_board_dout_read_data(uint8_t ch); -void mock_board_dout_write_data(uint8_t ch, int8_t lvl); - -#endif /* MOCK_BOARD_DOUT_ */ diff --git a/firmware/tests/mock_board/mock_board_halfbridge.c b/firmware/tests/mock_board/mock_board_halfbridge.c deleted file mode 100644 index 93e323f..0000000 --- a/firmware/tests/mock_board/mock_board_halfbridge.c +++ /dev/null @@ -1,76 +0,0 @@ -#include "mock_board_halfbridge.h" - -#define DOUT_CH_CNT 6 -static uint8_t low_ctrl = 0; -static uint16_t pwm_ctrl = 0; -static hb_meas_t feedback; - -void bsp_hb_write_low(uint8_t state) -{ - low_ctrl = state; -} - -void bsp_hb_write_pwm(uint16_t pwm) -{ - pwm_ctrl = pwm; -} - -void bsp_hb_read_meas(hb_meas_t* measurements) -{ - measurements->out_voltage = feedback.out_voltage; - measurements->out_current = feedback.out_current; - measurements->sup_voltage = feedback.sup_voltage; - measurements->sup_current = feedback.sup_current; - measurements->out_power = feedback.out_power; - measurements->sup_power = feedback.sup_power; - measurements->out_impedance = feedback.out_impedance; - measurements->low_side_ctrl = feedback.low_side_ctrl; - measurements->pwm = feedback.pwm; -} - - -uint8_t mock_board_halfbridge_read_low(void) -{ - return low_ctrl; -} - -void mock_board_halfbridge_write_low(uint8_t state) -{ - low_ctrl = state; -} - -uint16_t mock_board_halfbridge_read_pwm(void) -{ - return pwm_ctrl; -} - -void mock_board_halfbridge_write_pwm(uint16_t pwm) -{ - pwm_ctrl = pwm; -} - -void mock_board_halfbridge_read_feedback(hb_meas_t* measurements) -{ - measurements->out_voltage = feedback.out_voltage; - measurements->out_current = feedback.out_current; - measurements->sup_voltage = feedback.sup_voltage; - measurements->sup_current = feedback.sup_current; - measurements->out_power = feedback.out_power; - measurements->sup_power = feedback.sup_power; - measurements->out_impedance = feedback.out_impedance; - measurements->low_side_ctrl = feedback.low_side_ctrl; - measurements->pwm = feedback.pwm; -} - -void mock_board_halfbridge_write_feedback(hb_meas_t* new_fb) -{ - feedback.out_voltage = new_fb->out_voltage; - feedback.out_current = new_fb->out_current; - feedback.sup_voltage = new_fb->sup_voltage; - feedback.sup_current = new_fb->sup_current; - feedback.out_power = new_fb->out_power; - feedback.sup_power = new_fb->sup_power; - feedback.out_impedance = new_fb->out_impedance; - feedback.low_side_ctrl = new_fb->low_side_ctrl; - feedback.pwm = new_fb->pwm; -} diff --git a/firmware/tests/mock_board/mock_board_halfbridge.h b/firmware/tests/mock_board/mock_board_halfbridge.h deleted file mode 100644 index 6949928..0000000 --- a/firmware/tests/mock_board/mock_board_halfbridge.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef MOCK_BOARD_HALFBRIDGE_ -#define MOCK_BOARD_HALFBRIDGE_ - -#include -#include - -#include "..\..\src\hw\board\halfbridge.h" - -uint8_t mock_board_halfbridge_read_low(void); -void mock_board_halfbridge_write_low(uint8_t state); - -uint16_t mock_board_halfbridge_read_pwm(void); -void mock_board_halfbridge_write_pwm(uint16_t pwm); - -void mock_board_halfbridge_read_feedback(hb_meas_t* measurements); -void mock_board_halfbridge_write_feedback(hb_meas_t* new_fb); - -#endif /* MOCK_BOARD_HALFBRIDGE_ */ diff --git a/firmware/tests/mock_board/mock_board_odout.c b/firmware/tests/mock_board/mock_board_odout.c deleted file mode 100644 index 33bc914..0000000 --- a/firmware/tests/mock_board/mock_board_odout.c +++ /dev/null @@ -1,47 +0,0 @@ -#include "mock_board_odout.h" - -#define ODOUT_CH_CNT 7 -static uint8_t odout_ch = 0; -static int8_t odout_data[ODOUT_CH_CNT]; -static uint8_t common_pwm = 0; - -void bsp_odout_write(uint8_t ch, int8_t lvl) -{ - if(ch < ODOUT_CH_CNT) odout_data[ch] = lvl; - odout_ch = ch; -} - -void bsp_odout_write_common(uint8_t percent) -{ - common_pwm = percent; -} - -uint8_t mock_board_odout_read_ch(void) -{ - return odout_ch; -} - -void mock_board_odout_write_ch(uint8_t ch) -{ - odout_ch = ch; -} - -int8_t mock_board_odout_read_data(uint8_t ch) -{ - return odout_data[ch]; -} - -void mock_board_odout_write_data(uint8_t ch, int8_t lvl) -{ - odout_data[ch] = lvl; -} - -uint8_t mock_board_odout_read_pwm(void) -{ - return common_pwm; -} - -void mock_board_odout_write_pwm(uint8_t percent) -{ - common_pwm = percent; -} diff --git a/firmware/tests/mock_board/mock_board_odout.h b/firmware/tests/mock_board/mock_board_odout.h deleted file mode 100644 index fed625e..0000000 --- a/firmware/tests/mock_board/mock_board_odout.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef MOCK_BOARD_ODOUT_ -#define MOCK_BOARD_ODOUT_ - -#include -#include - -#include "..\..\src\hw\board\odout.h" - -uint8_t mock_board_odout_read_ch(void); -void mock_board_odout_write_ch(uint8_t ch); -int8_t mock_board_odout_read_data(uint8_t ch); -void mock_board_odout_write_data(uint8_t ch, int8_t lvl); -uint8_t mock_board_odout_read_pwm(void); -void mock_board_odout_write_pwm(uint8_t percent); - -#endif /* MOCK_BOARD_ODOUT_ */ diff --git a/firmware/tests/mock_board/mock_board_setup.c b/firmware/tests/mock_board/mock_board_setup.c deleted file mode 100644 index 96c3f7e..0000000 --- a/firmware/tests/mock_board/mock_board_setup.c +++ /dev/null @@ -1,18 +0,0 @@ -#include "mock_board_setup.h" - -static uint8_t setup_called = 0; - -void bsp_startup(void) -{ - setup_called = 1; -} - -uint8_t mock_board_setup_read_called(void) -{ - return setup_called; -} - -void mock_board_setup_reset_called(void) -{ - setup_called = 0; -} diff --git a/firmware/tests/mock_board/mock_board_setup.h b/firmware/tests/mock_board/mock_board_setup.h deleted file mode 100644 index a339808..0000000 --- a/firmware/tests/mock_board/mock_board_setup.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MOCK_BOARD_SETUP_ -#define MOCK_BOARD_SETUP_ - -#include -#include - -#include "..\..\src\hw\board\setup.h" - -uint8_t mock_board_setup_read_called(void); -void mock_board_setup_reset_called(void); - -#endif /* MOCK_BOARD_SETUP_ */ diff --git a/firmware/tests/mock_mcu/mock_mcu_hal_r8.c b/firmware/tests/mock_mcu/mock_mcu_hal_r8.c deleted file mode 100644 index 7038ce5..0000000 --- a/firmware/tests/mock_mcu/mock_mcu_hal_r8.c +++ /dev/null @@ -1,178 +0,0 @@ -#include "..\..\src\hw\board\mcu\mcu_hal.h" -#include "mock_mcu_hal_r8.h" - -// Startup-Configuration functions -static startupCfg_t saved_hwCfg; - -void mcu_startup(startupCfg_t* hwCfg) -{ - saved_hwCfg.adc_clk = hwCfg->adc_clk; - saved_hwCfg.pwm_clk = hwCfg->pwm_clk; - saved_hwCfg.pwm_top = hwCfg->pwm_top; - saved_hwCfg.pwm_chb_en = hwCfg->pwm_chb_en; -} - -void mock_mcu_startup_read_cfg(startupCfg_t* cfg_out) -{ - cfg_out->adc_clk = saved_hwCfg.adc_clk; - cfg_out->pwm_clk = saved_hwCfg.pwm_clk; - cfg_out->pwm_top = saved_hwCfg.pwm_top; - cfg_out->pwm_chb_en = saved_hwCfg.pwm_chb_en; -} - -void mock_mcu_startup_write_cfg(startupCfg_t* cfg_in) -{ - saved_hwCfg.adc_clk = cfg_in->adc_clk; - saved_hwCfg.pwm_clk = cfg_in->pwm_clk; - saved_hwCfg.pwm_top = cfg_in->pwm_top; - saved_hwCfg.pwm_chb_en = cfg_in->pwm_chb_en; -} - -// ADC Interface functions -#define ADC_CH_CNT 16 -static uint8_t adc_ch = 0; -static uint16_t adc_raw[ADC_CH_CNT]; - -uint16_t mcu_adc_read(uint8_t ch) -{ - adc_ch = ch; - - //Safe guard mux - if(ch > (ADC_CH_CNT-1)) return 0xFFFF; - // Not available channels - if((ch > 8) && (ch<14)) return 0xFFFF; - - return adc_raw[ch]; -} - -uint8_t mock_mcu_adc_read_ch(void) -{ - return adc_ch; -} - -void mock_mcu_adc_set_ch(uint8_t new_ch) -{ - adc_ch = new_ch; -} - -uint16_t mock_mcu_adc_read_raw(uint8_t ch) -{ - return adc_raw[ch]; -} - -void mock_mcu_adc_set_raw(uint16_t new_adc_out, uint8_t ch) -{ - adc_raw[ch] = new_adc_out; -} - -// PWM Timer Interface functions -#define PWM_CH_CNT 2 -static uint8_t pwm_ch = 0; -static uint16_t pwm_raw[PWM_CH_CNT]; - -void mcu_pwm_write(uint8_t ch, uint16_t dc) -{ - pwm_ch = ch; - if(ch < PWM_CH_CNT) pwm_raw[ch] = dc; -} - -uint16_t mcu_pwm_read(uint8_t ch) -{ - pwm_ch = ch; - if(ch < PWM_CH_CNT) return pwm_raw[ch]; - else return 0; -} - -uint8_t mock_mcu_pwm_read_ch(void) -{ - return pwm_ch; -} - -void mock_mcu_pwm_set_ch(uint8_t new_ch) -{ - pwm_ch = new_ch; -} - -uint16_t mock_mcu_pwm_read_raw(uint8_t ch) -{ - return pwm_raw[ch]; -} - -void mock_mcu_pwm_set_raw(uint16_t new_pwm, uint8_t ch) -{ - pwm_raw[ch] = new_pwm; -} - -// GPIO Functions -#define GPIO_CH_CNT 18 -static uint8_t gpio_ch = 0; -static uint8_t gpio_input_lvl[GPIO_CH_CNT]; -static int8_t gpio_output_lvl[GPIO_CH_CNT]; - -uint8_t mcu_gpio_read(uint8_t ch) -{ - gpio_ch = ch; - if(ch < GPIO_CH_CNT) return gpio_input_lvl[ch]; - else return 0; -} - -void mcu_gpio_write(uint8_t ch, int8_t lvl) -{ - gpio_ch = ch; - if(ch < GPIO_CH_CNT) gpio_output_lvl[ch] = lvl; -} - -uint8_t mock_mcu_gpio_read_ch(void) -{ - return gpio_ch; -} - -void mock_mcu_gpio_set_ch(uint8_t new_ch) -{ - gpio_ch = new_ch; -} - -int8_t mock_mcu_gpio_read_output_lvl(uint8_t ch) -{ - return gpio_output_lvl[ch]; -} - -void mock_mcu_gpio_set_output_lvl(int8_t new_output_lvl, uint8_t ch) -{ - gpio_output_lvl[ch] = new_output_lvl; -} - -void mock_mcu_gpio_set_input_lvl(uint8_t new_in_lvl, uint8_t ch) -{ - gpio_input_lvl[ch] = new_in_lvl; -} - -// EEPROM functions -uint8_t mcu_ee_read8b(uint16_t address) -{ - return 0x00; -} - -uint16_t mcu_ee_read16b(uint16_t address) -{ - return 0x0000; -} - -uint32_t mcu_ee_read32b(uint16_t address) -{ - return 0x00000000; -} - -void mcu_ee_write8b(uint16_t address, uint8_t value) -{ - -} - -void mcu_ee_write16b(uint16_t address, uint16_t value) -{ -} - -void mcu_ee_write32b(uint16_t address, uint32_t value) -{ - -} diff --git a/firmware/tests/mock_mcu/mock_mcu_hal_r8.h b/firmware/tests/mock_mcu/mock_mcu_hal_r8.h deleted file mode 100644 index 1303302..0000000 --- a/firmware/tests/mock_mcu/mock_mcu_hal_r8.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef MOCK_MCU_HAL_R8_ -#define MOCK_MCU_HAL_R8_ - -#include -#include - -#include "../../src/hw/board/mcu/mcu_hal.h" - -void mock_mcu_startup_read_cfg(startupCfg_t* cfg_out); -void mock_mcu_startup_write_cfg(startupCfg_t* cfg_in); - -uint8_t mock_mcu_adc_read_ch(void); -void mock_mcu_adc_set_ch(uint8_t ch); -uint16_t mock_mcu_adc_read_raw(uint8_t ch); -void mock_mcu_adc_set_raw(uint16_t new_adc_out, uint8_t ch); - -uint8_t mock_mcu_pwm_read_ch(void); -void mock_mcu_pwm_set_ch(uint8_t new_ch); -uint16_t mock_mcu_pwm_read_raw(uint8_t ch); -void mock_mcu_pwm_set_raw(uint16_t new_pwm, uint8_t ch); - -uint8_t mock_mcu_gpio_read_ch(void); -void mock_mcu_gpio_set_ch(uint8_t new_ch); -int8_t mock_mcu_gpio_read_output_lvl(uint8_t ch); -void mock_mcu_gpio_set_output_lvl(int8_t new_output_lvl, uint8_t ch); -void mock_mcu_gpio_set_input_lvl(uint8_t new_in_lvl, uint8_t ch); - -#endif /* MOCK_MCU_HAL_R8_ */ diff --git a/firmware/tests/uDCCD_Unit_Tests_BSP.cbp b/firmware/tests/uDCCD_Unit_Tests_BSP.cbp deleted file mode 100644 index 563b6aa..0000000 --- a/firmware/tests/uDCCD_Unit_Tests_BSP.cbp +++ /dev/null @@ -1,106 +0,0 @@ - - - - - - diff --git a/firmware/tests/uDCCD_Unit_Tests_BSP.depend b/firmware/tests/uDCCD_Unit_Tests_BSP.depend deleted file mode 100644 index 5bd0319..0000000 --- a/firmware/tests/uDCCD_Unit_Tests_BSP.depend +++ /dev/null @@ -1,348 +0,0 @@ -# depslib dependency file v1.0 -1698696655 source:f:\microrally\udccd_controller\src\hw\board\ain.c - "utils/utils.h" - "mcu/mcu_hal.h" - "ain.h" - -1699031869 f:\microrally\udccd_controller\src\hw\board\utils\utils.h - - -1698776270 f:\microrally\udccd_controller\src\hw\board\mcu\mcu_hal.h - - -1699031869 f:\microrally\udccd_controller\src\hw\board\ain.h - - -1698336545 source:f:\microrally\udccd_controller\src\hw\board\din.c - "utils/utils.h" - "mcu/mcu_hal.h" - "din.h" - -1699031869 f:\microrally\udccd_controller\src\hw\board\din.h - - -1698740890 source:f:\microrally\udccd_controller\src\hw\board\dout.c - "utils/utils.h" - "mcu/mcu_hal.h" - "dout.h" - -1699031869 f:\microrally\udccd_controller\src\hw\board\dout.h - - -1698575529 source:f:\microrally\udccd_controller\src\hw\board\halfbridge.c - "utils/utils.h" - "mcu/mcu_hal.h" - "halfbridge.h" - -1699031869 f:\microrally\udccd_controller\src\hw\board\halfbridge.h - - -1697628825 source:f:\microrally\udccd_controller\src\hw\board\odout.c - "utils/utils.h" - "mcu/mcu_hal.h" - "odout.h" - -1699197585 f:\microrally\udccd_controller\src\hw\board\odout.h - - -1698336545 source:f:\microrally\udccd_controller\src\hw\board\setup.c - "utils/utils.h" - "mcu/mcu_hal.h" - "setup.h" - -1699031869 f:\microrally\udccd_controller\src\hw\board\setup.h - - -1699031869 source:f:\microrally\udccd_controller\src\hw\board\utils\faults.c - "faults.h" - "utils.h" - -1699031869 f:\microrally\udccd_controller\src\hw\board\utils\faults.h - - -1699031869 source:f:\microrally\udccd_controller\src\hw\board\utils\fuses.c - "fuses.h" - "utils.h" - -1699031869 f:\microrally\udccd_controller\src\hw\board\utils\fuses.h - - -1699031869 source:f:\microrally\udccd_controller\src\hw\board\utils\utils.c - "utils.h" - -1699205020 source:f:\microrally\udccd_controller\tests\bsp_main.c - - - "ut_utils/ut_utils.h" - "ut_utils/ut_fault.h" - "ut_utils/ut_fuses.h" - "ut_board/ut_ain.h" - "ut_board/ut_din.h" - "ut_board/ut_dout.h" - "ut_board/ut_halfbridge.h" - "ut_board/ut_odout.h" - "ut_board/ut_setup.h" - -1699204674 f:\microrally\udccd_controller\tests\ut_utils\ut_utils.h - - - -1698870535 f:\microrally\udccd_controller\tests\ut_utils\ut_fault.h - - - -1698959419 f:\microrally\udccd_controller\tests\ut_utils\ut_fuses.h - - - -1699031869 f:\microrally\udccd_controller\tests\ut_board\ut_ain.h - - - -1699041803 f:\microrally\udccd_controller\tests\ut_board\ut_din.h - - - -1699042443 f:\microrally\udccd_controller\tests\ut_board\ut_dout.h - - - -1699051096 f:\microrally\udccd_controller\tests\ut_board\ut_halfbridge.h - - - -1699200555 source:f:\microrally\udccd_controller\tests\mock_mcu\mock_mcu_hal_r8.c - "..\..\src\hw\board\mcu\mcu_hal.h" - "mock_mcu_hal_r8.h" - -1699200561 f:\microrally\udccd_controller\tests\mock_mcu\mock_mcu_hal_r8.h - - - "../../src/hw/board/mcu/mcu_hal.h" - -1699196285 source:f:\microrally\udccd_controller\tests\ut_board\ut_ain.c - "ut_ain.h" - "..\mock_mcu\mock_mcu_hal_r8.h" - "..\..\src\hw\board\ain.h" - -1699196304 source:f:\microrally\udccd_controller\tests\ut_board\ut_din.c - "ut_din.h" - "..\mock_mcu\mock_mcu_hal_r8.h" - "..\..\src\hw\board\din.h" - -1699196320 source:f:\microrally\udccd_controller\tests\ut_board\ut_dout.c - "ut_dout.h" - "..\mock_mcu\mock_mcu_hal_r8.h" - "..\..\src\hw\board\dout.h" - -1699196359 source:f:\microrally\udccd_controller\tests\ut_board\ut_halfbridge.c - "ut_dout.h" - "..\mock_mcu\mock_mcu_hal_r8.h" - "..\..\src\hw\board\halfbridge.h" - -1699196427 source:f:\microrally\udccd_controller\tests\ut_utils\ut_fault.c - "ut_fault.h" - "..\..\src\hw\board\utils\faults.h" - -1699196445 source:f:\microrally\udccd_controller\tests\ut_utils\ut_fuses.c - "ut_fuses.h" - "..\..\src\hw\board\utils\fuses.h" - -1699203820 source:f:\microrally\udccd_controller\tests\ut_utils\ut_utils.c - "ut_utils.h" - "..\..\src\hw\board\utils\utils.h" - -1699200030 f:\microrally\udccd_controller\tests\ut_board\ut_odout.h - - - -1699200020 source:f:\microrally\udccd_controller\tests\ut_board\ut_odout.c - "ut_odout.h" - "..\mock_mcu\mock_mcu_hal_r8.h" - "..\..\src\hw\board\odout.h" - -1699201018 f:\microrally\udccd_controller\tests\ut_board\ut_setup.h - - - -1699201095 source:f:\microrally\udccd_controller\tests\ut_board\ut_setup.c - "ut_odout.h" - "..\mock_mcu\mock_mcu_hal_r8.h" - "..\..\src\hw\board\setup.h" - -1699018375 source:d:\microrally\udccd_controller\src\hw\board\ain.c - "utils/utils.h" - "mcu/mcu_hal.h" - "ain.h" - -1699007962 d:\microrally\udccd_controller\src\hw\board\utils\utils.h - - -1699017409 d:\microrally\udccd_controller\src\hw\board\mcu\mcu_hal.h - - -1699535273 d:\microrally\udccd_controller\src\hw\board\ain.h - - "config.h" - -1698333216 source:d:\microrally\udccd_controller\src\hw\board\din.c - "utils/utils.h" - "mcu/mcu_hal.h" - "din.h" - -1699535289 d:\microrally\udccd_controller\src\hw\board\din.h - - -1698673847 source:d:\microrally\udccd_controller\src\hw\board\dout.c - "utils/utils.h" - "mcu/mcu_hal.h" - "dout.h" - -1699535296 d:\microrally\udccd_controller\src\hw\board\dout.h - - -1698656931 source:d:\microrally\udccd_controller\src\hw\board\halfbridge.c - "utils/utils.h" - "mcu/mcu_hal.h" - "halfbridge.h" - -1699535318 d:\microrally\udccd_controller\src\hw\board\halfbridge.h - - "config.h" - -1697618884 source:d:\microrally\udccd_controller\src\hw\board\odout.c - "utils/utils.h" - "mcu/mcu_hal.h" - "odout.h" - -1699257917 d:\microrally\udccd_controller\src\hw\board\odout.h - - -1698328348 source:d:\microrally\udccd_controller\src\hw\board\setup.c - "utils/utils.h" - "mcu/mcu_hal.h" - "setup.h" - -1699017683 d:\microrally\udccd_controller\src\hw\board\setup.h - - -1699007034 source:d:\microrally\udccd_controller\src\hw\board\utils\faults.c - "faults.h" - "utils.h" - -1699007033 d:\microrally\udccd_controller\src\hw\board\utils\faults.h - - -1699007093 source:d:\microrally\udccd_controller\src\hw\board\utils\fuses.c - "fuses.h" - "utils.h" - -1699007094 d:\microrally\udccd_controller\src\hw\board\utils\fuses.h - - -1699264217 source:d:\microrally\udccd_controller\src\hw\board\utils\utils.c - "utils.h" - -1699257917 source:d:\microrally\udccd_controller\tests\bsp_main.c - - - "ut_utils/ut_utils.h" - "ut_utils/ut_fault.h" - "ut_utils/ut_fuses.h" - "ut_board/ut_ain.h" - "ut_board/ut_din.h" - "ut_board/ut_dout.h" - "ut_board/ut_halfbridge.h" - "ut_board/ut_odout.h" - "ut_board/ut_setup.h" - -1699257917 d:\microrally\udccd_controller\tests\ut_utils\ut_utils.h - - - -1698921312 d:\microrally\udccd_controller\tests\ut_utils\ut_fault.h - - - -1699004735 d:\microrally\udccd_controller\tests\ut_utils\ut_fuses.h - - - -1699018575 d:\microrally\udccd_controller\tests\ut_board\ut_ain.h - - - -1699257917 d:\microrally\udccd_controller\tests\ut_board\ut_din.h - - - -1699257917 d:\microrally\udccd_controller\tests\ut_board\ut_dout.h - - - -1699257917 d:\microrally\udccd_controller\tests\ut_board\ut_halfbridge.h - - - -1699257917 d:\microrally\udccd_controller\tests\ut_board\ut_odout.h - - - -1699257917 d:\microrally\udccd_controller\tests\ut_board\ut_setup.h - - - -1699257917 source:d:\microrally\udccd_controller\tests\mock_mcu\mock_mcu_hal_r8.c - "..\..\src\hw\board\mcu\mcu_hal.h" - "mock_mcu_hal_r8.h" - -1699257917 d:\microrally\udccd_controller\tests\mock_mcu\mock_mcu_hal_r8.h - - - "../../src/hw/board/mcu/mcu_hal.h" - -1699257917 source:d:\microrally\udccd_controller\tests\ut_board\ut_ain.c - "ut_ain.h" - "..\mock_mcu\mock_mcu_hal_r8.h" - "..\..\src\hw\board\ain.h" - -1699257917 source:d:\microrally\udccd_controller\tests\ut_board\ut_din.c - "ut_din.h" - "..\mock_mcu\mock_mcu_hal_r8.h" - "..\..\src\hw\board\din.h" - -1699257917 source:d:\microrally\udccd_controller\tests\ut_board\ut_dout.c - "ut_dout.h" - "..\mock_mcu\mock_mcu_hal_r8.h" - "..\..\src\hw\board\dout.h" - -1699257917 source:d:\microrally\udccd_controller\tests\ut_board\ut_halfbridge.c - "ut_dout.h" - "..\mock_mcu\mock_mcu_hal_r8.h" - "..\..\src\hw\board\halfbridge.h" - -1699257917 source:d:\microrally\udccd_controller\tests\ut_board\ut_odout.c - "ut_odout.h" - "..\mock_mcu\mock_mcu_hal_r8.h" - "..\..\src\hw\board\odout.h" - -1699257917 source:d:\microrally\udccd_controller\tests\ut_board\ut_setup.c - "ut_odout.h" - "..\mock_mcu\mock_mcu_hal_r8.h" - "..\..\src\hw\board\setup.h" - -1699257917 source:d:\microrally\udccd_controller\tests\ut_utils\ut_fault.c - "ut_fault.h" - "..\..\src\hw\board\utils\faults.h" - -1699257917 source:d:\microrally\udccd_controller\tests\ut_utils\ut_fuses.c - "ut_fuses.h" - "..\..\src\hw\board\utils\fuses.h" - -1699264250 source:d:\microrally\udccd_controller\tests\ut_utils\ut_utils.c - "ut_utils.h" - "..\..\src\hw\board\utils\utils.h" - -1699535389 d:\microrally\udccd_controller\src\hw\board\config.h - - diff --git a/firmware/tests/uDCCD_Unit_Tests_BSP.layout b/firmware/tests/uDCCD_Unit_Tests_BSP.layout deleted file mode 100644 index 566a1dd..0000000 --- a/firmware/tests/uDCCD_Unit_Tests_BSP.layout +++ /dev/null @@ -1,90 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/firmware/tests/uDCCD_Unit_Tests_HW.cbp b/firmware/tests/uDCCD_Unit_Tests_HW.cbp deleted file mode 100644 index 808a48b..0000000 --- a/firmware/tests/uDCCD_Unit_Tests_HW.cbp +++ /dev/null @@ -1,105 +0,0 @@ - - - - - - diff --git a/firmware/tests/uDCCD_Unit_Tests_HW.depend b/firmware/tests/uDCCD_Unit_Tests_HW.depend deleted file mode 100644 index 4507af5..0000000 --- a/firmware/tests/uDCCD_Unit_Tests_HW.depend +++ /dev/null @@ -1,378 +0,0 @@ -# depslib dependency file v1.0 -1699007034 source:d:\microrally\udccd_controller\src\hw\board\utils\faults.c - "faults.h" - "utils.h" - -1699007033 d:\microrally\udccd_controller\src\hw\board\utils\faults.h - - -1699007962 d:\microrally\udccd_controller\src\hw\board\utils\utils.h - - -1699007093 source:d:\microrally\udccd_controller\src\hw\board\utils\fuses.c - "fuses.h" - "utils.h" - -1699007094 d:\microrally\udccd_controller\src\hw\board\utils\fuses.h - - -1699264217 source:d:\microrally\udccd_controller\src\hw\board\utils\utils.c - "utils.h" - -1698741271 source:d:\microrally\udccd_controller\src\hw\analog.c - "board/utils/utils.h" - "board/ain.h" - "analog.h" - -1699535273 d:\microrally\udccd_controller\src\hw\board\ain.h - - "config.h" - -1699017683 d:\microrally\udccd_controller\src\hw\analog.h - - -1699283768 source:d:\microrally\udccd_controller\tests\mock_board\mock_board_dout.c - "mock_board_dout.h" - -1699535296 d:\microrally\udccd_controller\src\hw\board\dout.h - - -1699272290 d:\microrally\udccd_controller\tests\mock_board\mock_board_dout.h - - - "..\..\src\hw\board\dout.h" - -1699283776 source:d:\microrally\udccd_controller\tests\mock_board\mock_board_odout.c - "mock_board_odout.h" - -1699257917 d:\microrally\udccd_controller\src\hw\board\odout.h - - -1699272272 d:\microrally\udccd_controller\tests\mock_board\mock_board_odout.h - - - "..\..\src\hw\board\odout.h" - -1699272265 source:d:\microrally\udccd_controller\tests\mock_board\mock_board_setup.c - "mock_board_setup.h" - -1699017683 d:\microrally\udccd_controller\src\hw\board\setup.h - - -1699272264 d:\microrally\udccd_controller\tests\mock_board\mock_board_setup.h - - - "..\..\src\hw\board\setup.h" - -1699516357 source:d:\microrally\udccd_controller\tests\hw_main.c - - - "ut_hw/ut_analog.h" - "ut_hw/ut_buttons.h" - "ut_hw/ut_hb_control.h" - "ut_hw/ut_led_display.h" - "ut_hw/ut_startup.h" - -1699271694 d:\microrally\udccd_controller\tests\ut_hw\ut_analog.h - - - -1699272372 source:d:\microrally\udccd_controller\tests\mock_board\mock_board_ain.c - "mock_board_ain.h" - -1699272245 d:\microrally\udccd_controller\tests\mock_board\mock_board_ain.h - - - "..\..\src\hw\board\ain.h" - -1699283758 source:d:\microrally\udccd_controller\tests\mock_board\mock_board_din.c - "mock_board_din.h" - -1699535289 d:\microrally\udccd_controller\src\hw\board\din.h - - -1699272297 d:\microrally\udccd_controller\tests\mock_board\mock_board_din.h - - - "..\..\src\hw\board\din.h" - -1699535318 d:\microrally\udccd_controller\src\hw\board\halfbridge.h - - "config.h" - -1699272285 source:d:\microrally\udccd_controller\tests\mock_board\mock_board_halfbridge.c - "mock_board_halfbridge.h" - -1699287859 d:\microrally\udccd_controller\tests\mock_board\mock_board_halfbridge.h - - - "..\..\src\hw\board\halfbridge.h" - -1699276363 source:d:\microrally\udccd_controller\tests\ut_hw\ut_analog.c - "ut_analog.h" - "..\mock_board\mock_board_ain.h" - "..\..\src\hw\analog.h" - -1699284536 source:d:\microrally\udccd_controller\tests\ut_hw\ut_buttons.c - "ut_buttons.h" - "..\mock_board\mock_board_din.h" - "..\mock_board\mock_board_dout.h" - "..\..\src\hw\buttons.h" - -1699284495 d:\microrally\udccd_controller\tests\ut_hw\ut_buttons.h - - - -1699535453 d:\microrally\udccd_controller\src\hw\buttons.h - - "config.h" - -1699516357 source:d:\microrally\udccd_controller\src\hw\buttons.c - "board/utils/utils.h" - "board/din.h" - "board/dout.h" - "buttons.h" - -1699373886 source:d:\microrally\udccd_controller\src\hw\hb_control.c - "board/utils/utils.h" - "board/halfbridge.h" - "hb_control.h" - -1699351840 d:\microrally\udccd_controller\src\hw\hb_control.h - - "board/utils/faults.h" - "board/utils/fuses.h" - "board/halfbridge.h" - -1699286008 source:d:\microrally\udccd_controller\src\hw\led_display.c - "board/odout.h" - "led_display.h" - -1699017683 d:\microrally\udccd_controller\src\hw\led_display.h - - -1698328349 source:d:\microrally\udccd_controller\src\hw\startup.c - "board/utils/utils.h" - "board/setup.h" - "startup.h" - -1699017682 d:\microrally\udccd_controller\src\hw\startup.h - - -1699285771 d:\microrally\udccd_controller\tests\ut_hw\ut_startup.h - - - -1699285777 source:d:\microrally\udccd_controller\tests\ut_hw\ut_startup.c - "ut_startup.h" - "..\mock_board\mock_board_setup.h" - "..\..\src\hw\startup.h" - -1699286754 source:d:\microrally\udccd_controller\tests\ut_hw\ut_led_display.c - "ut_led_display.h" - "..\mock_board\mock_board_odout.h" - "..\..\src\hw\led_display.h" - -1699286570 d:\microrally\udccd_controller\tests\ut_hw\ut_led_display.h - - - -1699375169 source:d:\microrally\udccd_controller\tests\ut_hw\ut_hb_control.c - "ut_hb_control.h" - "..\mock_board\mock_board_halfbridge.h" - "..\..\src\hw\hb_control.h" - -1699371510 d:\microrally\udccd_controller\tests\ut_hw\ut_hb_control.h - - - -1699031869 source:f:\microrally\udccd_controller\src\hw\board\utils\faults.c - "faults.h" - "utils.h" - -1699031869 f:\microrally\udccd_controller\src\hw\board\utils\faults.h - - -1699031869 f:\microrally\udccd_controller\src\hw\board\utils\utils.h - - -1699031869 source:f:\microrally\udccd_controller\src\hw\board\utils\fuses.c - "fuses.h" - "utils.h" - -1699031869 f:\microrally\udccd_controller\src\hw\board\utils\fuses.h - - -1698697335 source:f:\microrally\udccd_controller\src\hw\analog.c - "board/utils/utils.h" - "board/ain.h" - "analog.h" - -1699476816 f:\microrally\udccd_controller\src\hw\board\ain.h - - -1699031869 f:\microrally\udccd_controller\src\hw\analog.h - - -1699298687 source:f:\microrally\udccd_controller\src\hw\board\utils\utils.c - "utils.h" - -1699298687 source:f:\microrally\udccd_controller\src\hw\buttons.c - "board/utils/utils.h" - "board/din.h" - "board/dout.h" - "buttons.h" - -1699031869 f:\microrally\udccd_controller\src\hw\board\din.h - - -1699031869 f:\microrally\udccd_controller\src\hw\board\dout.h - - -1699477045 f:\microrally\udccd_controller\src\hw\buttons.h - - -1699298687 source:f:\microrally\udccd_controller\src\hw\led_display.c - "board/odout.h" - "led_display.h" - -1699197585 f:\microrally\udccd_controller\src\hw\board\odout.h - - -1699031869 f:\microrally\udccd_controller\src\hw\led_display.h - - -1698336545 source:f:\microrally\udccd_controller\src\hw\startup.c - "board/utils/utils.h" - "board/setup.h" - "startup.h" - -1699031869 f:\microrally\udccd_controller\src\hw\board\setup.h - - -1699031869 f:\microrally\udccd_controller\src\hw\startup.h - - -1699474639 source:f:\microrally\udccd_controller\tests\hw_main.c - - - "ut_hw/ut_analog.h" - "ut_hw/ut_buttons.h" - "ut_hw/ut_hb_control.h" - "ut_hw/ut_led_display.h" - "ut_hw/ut_startup.h" - -1699298688 f:\microrally\udccd_controller\tests\ut_hw\ut_analog.h - - - -1699298688 f:\microrally\udccd_controller\tests\ut_hw\ut_buttons.h - - - -1699298688 f:\microrally\udccd_controller\tests\ut_hw\ut_startup.h - - - -1699298687 source:f:\microrally\udccd_controller\tests\mock_board\mock_board_ain.c - "mock_board_ain.h" - -1699298687 f:\microrally\udccd_controller\tests\mock_board\mock_board_ain.h - - - "..\..\src\hw\board\ain.h" - -1699298687 source:f:\microrally\udccd_controller\tests\mock_board\mock_board_din.c - "mock_board_din.h" - -1699298687 f:\microrally\udccd_controller\tests\mock_board\mock_board_din.h - - - "..\..\src\hw\board\din.h" - -1699298687 source:f:\microrally\udccd_controller\tests\mock_board\mock_board_dout.c - "mock_board_dout.h" - -1699298687 f:\microrally\udccd_controller\tests\mock_board\mock_board_dout.h - - - "..\..\src\hw\board\dout.h" - -1699298687 source:f:\microrally\udccd_controller\tests\mock_board\mock_board_halfbridge.c - "mock_board_halfbridge.h" - -1699298687 f:\microrally\udccd_controller\tests\mock_board\mock_board_halfbridge.h - - - "..\..\src\hw\board\halfbridge.h" - -1699476970 f:\microrally\udccd_controller\src\hw\board\halfbridge.h - - -1699298687 source:f:\microrally\udccd_controller\tests\mock_board\mock_board_odout.c - "mock_board_odout.h" - -1699298687 f:\microrally\udccd_controller\tests\mock_board\mock_board_odout.h - - - "..\..\src\hw\board\odout.h" - -1699298687 source:f:\microrally\udccd_controller\tests\mock_board\mock_board_setup.c - "mock_board_setup.h" - -1699298688 f:\microrally\udccd_controller\tests\mock_board\mock_board_setup.h - - - "..\..\src\hw\board\setup.h" - -1699298688 source:f:\microrally\udccd_controller\tests\ut_hw\ut_analog.c - "ut_analog.h" - "..\mock_board\mock_board_ain.h" - "..\..\src\hw\analog.h" - -1699298688 source:f:\microrally\udccd_controller\tests\ut_hw\ut_buttons.c - "ut_buttons.h" - "..\mock_board\mock_board_din.h" - "..\mock_board\mock_board_dout.h" - "..\..\src\hw\buttons.h" - -1699298688 source:f:\microrally\udccd_controller\tests\ut_hw\ut_led_display.c - "ut_led_display.h" - "..\mock_board\mock_board_odout.h" - "..\..\src\hw\led_display.h" - -1699298688 f:\microrally\udccd_controller\tests\ut_hw\ut_led_display.h - - - -1699298688 source:f:\microrally\udccd_controller\tests\ut_hw\ut_startup.c - "ut_startup.h" - "..\mock_board\mock_board_setup.h" - "..\..\src\hw\startup.h" - -1699391649 source:f:\microrally\udccd_controller\src\hw\hb_control.c - "board/utils/utils.h" - "board/halfbridge.h" - "hb_control.h" - -1699382733 f:\microrally\udccd_controller\src\hw\hb_control.h - - "board/utils/faults.h" - "board/utils/fuses.h" - "board/halfbridge.h" - -1699393539 source:f:\microrally\udccd_controller\tests\ut_hw\ut_hb_control.c - "ut_hb_control.h" - "..\mock_board\mock_board_halfbridge.h" - "..\..\src\hw\hb_control.h" - -1699382733 f:\microrally\udccd_controller\tests\ut_hw\ut_hb_control.h - - - -1699535389 d:\microrally\udccd_controller\src\hw\board\config.h - - -1699535687 d:\microrally\udccd_controller\src\hw\config.h - - diff --git a/firmware/tests/uDCCD_Unit_Tests_HW.layout b/firmware/tests/uDCCD_Unit_Tests_HW.layout deleted file mode 100644 index 22a15ce..0000000 --- a/firmware/tests/uDCCD_Unit_Tests_HW.layout +++ /dev/null @@ -1,145 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/firmware/tests/uDCCD_Unit_Tests_Logic.cbp b/firmware/tests/uDCCD_Unit_Tests_Logic.cbp deleted file mode 100644 index cf04a15..0000000 --- a/firmware/tests/uDCCD_Unit_Tests_Logic.cbp +++ /dev/null @@ -1,71 +0,0 @@ - - - - - - diff --git a/firmware/tests/uDCCD_Unit_Tests_Logic.depend b/firmware/tests/uDCCD_Unit_Tests_Logic.depend deleted file mode 100644 index b36d4bb..0000000 --- a/firmware/tests/uDCCD_Unit_Tests_Logic.depend +++ /dev/null @@ -1,80 +0,0 @@ -# depslib dependency file v1.0 -1699474847 source:f:\microrally\udccd_controller\src\logic\coil.c - "coil.h" - -1699474848 f:\microrally\udccd_controller\src\logic\coil.h - - -1699472530 source:f:\microrally\udccd_controller\src\logic\display.c - "display.h" - -1699472535 f:\microrally\udccd_controller\src\logic\display.h - - -1699474995 source:f:\microrally\udccd_controller\src\logic\force.c - "force.h" - -1699474996 f:\microrally\udccd_controller\src\logic\force.h - - -1699031869 source:f:\microrally\udccd_controller\src\logic\pot.c - "pot.h" - -1699475345 f:\microrally\udccd_controller\src\logic\pot.h - - -1699475089 source:f:\microrally\udccd_controller\src\logic\user_force.c - "user_force.h" - -1699475337 f:\microrally\udccd_controller\src\logic\user_force.h - - -1699474661 source:f:\microrally\udccd_controller\tests\logic_main.c - - - "ut_logic/ut_coil.h" - "ut_logic/ut_display.h" - "ut_logic/ut_force.h" - "ut_logic/ut_pot.h" - "ut_logic/ut_user_force.h" - -1698869680 f:\microrally\udccd_controller\tests\ut_logic\ut_coil.h - - - -1699473947 f:\microrally\udccd_controller\tests\ut_logic\ut_display.h - - - -1698869680 f:\microrally\udccd_controller\tests\ut_logic\ut_force.h - - - -1698869680 f:\microrally\udccd_controller\tests\ut_logic\ut_pot.h - - - -1698869680 f:\microrally\udccd_controller\tests\ut_logic\ut_user_force.h - - - -1699474942 source:f:\microrally\udccd_controller\tests\ut_logic\ut_coil.c - "ut_coil.h" - "..\..\src\logic\coil.h" - -1699474733 source:f:\microrally\udccd_controller\tests\ut_logic\ut_display.c - "ut_display.h" - "..\..\src\logic\display.h" - -1699475023 source:f:\microrally\udccd_controller\tests\ut_logic\ut_force.c - "ut_force.h" - "..\..\src\logic\force.h" - -1699195810 source:f:\microrally\udccd_controller\tests\ut_logic\ut_pot.c - "ut_pot.h" - "..\..\src\logic\pot.h" - -1699195775 source:f:\microrally\udccd_controller\tests\ut_logic\ut_user_force.c - "ut_user_force.h" - "..\..\src\logic\user_force.h" - diff --git a/firmware/tests/uDCCD_Unit_Tests_Logic.layout b/firmware/tests/uDCCD_Unit_Tests_Logic.layout deleted file mode 100644 index 3b6ecd4..0000000 --- a/firmware/tests/uDCCD_Unit_Tests_Logic.layout +++ /dev/null @@ -1,70 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/firmware/tests/ut_board/ut_ain.c b/firmware/tests/ut_board/ut_ain.c deleted file mode 100644 index 3568ea3..0000000 --- a/firmware/tests/ut_board/ut_ain.c +++ /dev/null @@ -1,96 +0,0 @@ -#include "ut_ain.h" - -#include "..\mock_mcu\mock_mcu_hal_r8.h" -#include "..\..\src\hw\board\ain.h" - -static const uint8_t NOT_ACCESED_ADC_CH = 255; - -static int ut_bsp_ain_read(uint8_t ain_ch, uint16_t adc_raw, uint16_t exp_out, uint8_t exp_adc_ch) -{ - printf(" Input: Ain-Ch:%d Adc-Raw:%d \n", ain_ch, adc_raw); - - mock_mcu_adc_set_ch(NOT_ACCESED_ADC_CH); - mock_mcu_adc_set_raw(adc_raw, exp_adc_ch); - - uint16_t out = bsp_ain_read(ain_ch); - - uint8_t adc_ch = mock_mcu_adc_read_ch(); - - printf(" Output: AIN:%d Adc-Ch:%d \n", out, adc_ch); - printf("Expected: AIN:%d Adc-Ch:%d \n", exp_out, exp_adc_ch); - - if((out==exp_out)&&(adc_ch==exp_adc_ch)) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_bsp_ain_read_test(void) -{ - printf("******************************************************\n"); - printf("uint16_t bsp_ain_read(uint8_t ch)\n"); - - int test_res; - int pass = 1; - - uint8_t ain_ch; - uint16_t adc_raw; - uint16_t exp_out; - uint8_t exp_adc_ch; - - // Normal 1 - ain_ch = BSP_AIN1; - adc_raw = 88; - exp_out = 430; - exp_adc_ch = MCU_ADC5; - test_res = ut_bsp_ain_read(ain_ch, adc_raw, exp_out, exp_adc_ch); - if(!test_res) pass = 0; - - // Normal 2 - ain_ch = BSP_AIN2; - adc_raw = 88; - exp_out = 430; - exp_adc_ch = MCU_ADC4; - test_res = ut_bsp_ain_read(ain_ch, adc_raw, exp_out, exp_adc_ch); - if(!test_res) pass = 0; - - // Normal 3 - ain_ch = BSP_AIN3; - adc_raw = 500; - exp_out = 2443; - exp_adc_ch = MCU_ADC8; - test_res = ut_bsp_ain_read(ain_ch, adc_raw, exp_out, exp_adc_ch); - if(!test_res) pass = 0; - - // Norma 4 - ain_ch = BSP_AIN4; - adc_raw = 1023; - exp_out = 4998; - exp_adc_ch = MCU_ADC14; - test_res = ut_bsp_ain_read(ain_ch, adc_raw, exp_out, exp_adc_ch); - if(!test_res) pass = 0; - - // Normal 5 - ain_ch = BSP_AIN5; - adc_raw = 1; - exp_out = 4; - exp_adc_ch = MCU_ADC15; - test_res = ut_bsp_ain_read(ain_ch, adc_raw, exp_out, exp_adc_ch); - if(!test_res) pass = 0; - - // Not existing ADC channel - ain_ch = 0; - adc_raw = 500; - exp_out = 0; - exp_adc_ch = NOT_ACCESED_ADC_CH; - test_res = ut_bsp_ain_read(ain_ch, adc_raw, exp_out, exp_adc_ch); - if(!test_res) pass = 0; - - return pass; -} diff --git a/firmware/tests/ut_board/ut_ain.h b/firmware/tests/ut_board/ut_ain.h deleted file mode 100644 index 6ff046e..0000000 --- a/firmware/tests/ut_board/ut_ain.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef UT_BOARD_AIN_H_ -#define UT_BOARD_AIN_H_ - -#include -#include - -int ut_bsp_ain_read_test(void); - -#endif /* UT_BOARD_AIN_H_ */ diff --git a/firmware/tests/ut_board/ut_din.c b/firmware/tests/ut_board/ut_din.c deleted file mode 100644 index d55551b..0000000 --- a/firmware/tests/ut_board/ut_din.c +++ /dev/null @@ -1,191 +0,0 @@ -#include "ut_din.h" - -#include "..\mock_mcu\mock_mcu_hal_r8.h" -#include "..\..\src\hw\board\din.h" - -static const uint8_t NOT_ACCESED_GPIO_CH = 255; - -static int ut_bsp_din_read(uint8_t din_ch, uint8_t gpio_lvl, uint8_t exp_out, uint8_t exp_gpio_ch) -{ - printf(" Input: Din-Ch:%d GPIO-lvl:%d \n", din_ch, gpio_lvl); - - mock_mcu_gpio_set_ch(NOT_ACCESED_GPIO_CH); - mock_mcu_gpio_set_input_lvl(gpio_lvl, exp_gpio_ch); - - uint8_t out = bsp_din_read(din_ch); - - uint8_t gpio_ch = mock_mcu_gpio_read_ch(); - - printf(" Output: DIN:%d GPIO-Ch:%d \n", out, gpio_ch); - printf("Expected: DIN:%d GPIO-Ch:%d \n", exp_out, exp_gpio_ch); - - if((out==exp_out)&&(gpio_ch==exp_gpio_ch)) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_bsp_din_read_test(void) -{ - printf("******************************************************\n"); - printf("uint8_t bsp_din_read(uint8_t ch)\n"); - - int test_res; - int pass = 1; - - uint8_t din_ch; - uint8_t gpio_lvl; - uint8_t exp_out; - uint8_t exp_gpio_ch; - - // DIN 1 - din_ch = BSP_DIN1; - gpio_lvl = MCU_GPIO_LOW; - exp_out = 0; - exp_gpio_ch = MCU_GPIO0; - test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch); - if(!test_res) pass = 0; - - din_ch = BSP_DIN1; - gpio_lvl = MCU_GPIO_HIGH; - exp_out = 1; - exp_gpio_ch = MCU_GPIO0; - test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch); - if(!test_res) pass = 0; - - // DIN 2 - din_ch = BSP_DIN2; - gpio_lvl = MCU_GPIO_LOW; - exp_out = 0; - exp_gpio_ch = MCU_GPIO1; - test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch); - if(!test_res) pass = 0; - - din_ch = BSP_DIN2; - gpio_lvl = MCU_GPIO_HIGH; - exp_out = 1; - exp_gpio_ch = MCU_GPIO1; - test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch); - if(!test_res) pass = 0; - - // DIN 3 - din_ch = BSP_DIN3; - gpio_lvl = MCU_GPIO_LOW; - exp_out = 0; - exp_gpio_ch = MCU_GPIO2; - test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch); - if(!test_res) pass = 0; - - din_ch = BSP_DIN3; - gpio_lvl = MCU_GPIO_HIGH; - exp_out = 1; - exp_gpio_ch = MCU_GPIO2; - test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch); - if(!test_res) pass = 0; - - // DIN 4 - din_ch = BSP_DIN4; - gpio_lvl = MCU_GPIO_LOW; - exp_out = 0; - exp_gpio_ch = MCU_GPIO3; - test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch); - if(!test_res) pass = 0; - - din_ch = BSP_DIN4; - gpio_lvl = MCU_GPIO_HIGH; - exp_out = 1; - exp_gpio_ch = MCU_GPIO3; - test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch); - if(!test_res) pass = 0; - - // DIN 5 - din_ch = BSP_DIN5; - gpio_lvl = MCU_GPIO_LOW; - exp_out = 1; - exp_gpio_ch = MCU_GPIO4; - test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch); - if(!test_res) pass = 0; - - din_ch = BSP_DIN5; - gpio_lvl = MCU_GPIO_HIGH; - exp_out = 0; - exp_gpio_ch = MCU_GPIO4; - test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch); - if(!test_res) pass = 0; - - // DIN 6 - din_ch = BSP_DIN6; - gpio_lvl = MCU_GPIO_LOW; - exp_out = 1; - exp_gpio_ch = MCU_GPIO5; - test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch); - if(!test_res) pass = 0; - - din_ch = BSP_DIN6; - gpio_lvl = MCU_GPIO_HIGH; - exp_out = 0; - exp_gpio_ch = MCU_GPIO5; - test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch); - if(!test_res) pass = 0; - - // DIN 7 - din_ch = BSP_DIN7; - gpio_lvl = MCU_GPIO_LOW; - exp_out = 1; - exp_gpio_ch = MCU_GPIO6; - test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch); - if(!test_res) pass = 0; - - din_ch = BSP_DIN7; - gpio_lvl = MCU_GPIO_HIGH; - exp_out = 0; - exp_gpio_ch = MCU_GPIO6; - test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch); - if(!test_res) pass = 0; - - // DIN 7N - din_ch = BSP_DIN7N; - gpio_lvl = MCU_GPIO_LOW; - exp_out = 0; - exp_gpio_ch = MCU_GPIO7; - test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch); - if(!test_res) pass = 0; - - din_ch = BSP_DIN7N; - gpio_lvl = MCU_GPIO_HIGH; - exp_out = 1; - exp_gpio_ch = MCU_GPIO7; - test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch); - if(!test_res) pass = 0; - - // Wrong channel - din_ch = 0; - gpio_lvl = MCU_GPIO_LOW; - exp_out = 0; - exp_gpio_ch = NOT_ACCESED_GPIO_CH; - test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch); - if(!test_res) pass = 0; - - // DSP OUTPUT DEFINITIONS - din_ch = BSP_DIN1; - gpio_lvl = MCU_GPIO_LOW; - exp_out = BSP_DIN_LOW; - exp_gpio_ch = MCU_GPIO0; - test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch); - if(!test_res) pass = 0; - - din_ch = BSP_DIN1; - gpio_lvl = MCU_GPIO_HIGH; - exp_out = BSP_DIN_HIGH; - exp_gpio_ch = MCU_GPIO0; - test_res = ut_bsp_din_read(din_ch, gpio_lvl, exp_out, exp_gpio_ch); - if(!test_res) pass = 0; - - return pass; -} diff --git a/firmware/tests/ut_board/ut_din.h b/firmware/tests/ut_board/ut_din.h deleted file mode 100644 index 970513c..0000000 --- a/firmware/tests/ut_board/ut_din.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef UT_BOARD_DIN_H_ -#define UT_BOARD_DIN_H_ - -#include -#include - -int ut_bsp_din_read_test(void); - -#endif /* UT_BOARD_DIN_H_ */ diff --git a/firmware/tests/ut_board/ut_dout.c b/firmware/tests/ut_board/ut_dout.c deleted file mode 100644 index 294336f..0000000 --- a/firmware/tests/ut_board/ut_dout.c +++ /dev/null @@ -1,142 +0,0 @@ -#include "ut_dout.h" - -#include "..\mock_mcu\mock_mcu_hal_r8.h" -#include "..\..\src\hw\board\dout.h" - -static const uint8_t NOT_ACCESED_GPIO_CH = 255; -static const uint8_t NOT_ACCESED_GPIO_LVL = MCU_GPIO_HIZ; - -static int ut_bsp_dout_write(uint8_t dout_ch, int8_t dout_lvl, int8_t exp_gpio_lvl, uint8_t exp_gpio_ch) -{ - printf(" Input: Dout-Ch:%d Dout-lvl:%d \n", dout_ch, dout_lvl); - - mock_mcu_gpio_set_ch(NOT_ACCESED_GPIO_CH); - mock_mcu_gpio_set_output_lvl(NOT_ACCESED_GPIO_LVL, exp_gpio_ch); - - bsp_dout_write(dout_ch, dout_lvl); - - uint8_t gpio_ch = mock_mcu_gpio_read_ch(); - int8_t gpio_lvl = mock_mcu_gpio_read_output_lvl(gpio_ch); - - printf(" Output: GPIO-lvl:%d GPIO-Ch:%d \n", gpio_lvl, gpio_ch); - printf("Expected: GPIO-lvl:%d GPIO-Ch:%d \n", exp_gpio_lvl, exp_gpio_ch); - - if((gpio_lvl==exp_gpio_lvl)&&(gpio_ch==exp_gpio_ch)) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_bsp_dout_write_test(void) -{ - printf("******************************************************\n"); - printf("void bsp_dout_write(uint8_t ch, int8_t lvl)\n"); - - int test_res; - int pass = 1; - - uint8_t dout_ch; - uint8_t dout_lvl; - int8_t exp_gpio_lvl; - uint8_t exp_gpio_ch; - - // DOUT 1 - dout_ch = BSP_DOUT1; - dout_lvl = 0; - exp_gpio_lvl = MCU_GPIO_LOW; - exp_gpio_ch = MCU_GPIO0; - test_res = ut_bsp_dout_write(dout_ch, dout_lvl, exp_gpio_lvl, exp_gpio_ch); - if(!test_res) pass = 0; - - dout_ch = BSP_DOUT1; - dout_lvl = 1; - exp_gpio_lvl = MCU_GPIO_HIGH; - exp_gpio_ch = MCU_GPIO0; - test_res = ut_bsp_dout_write(dout_ch, dout_lvl, exp_gpio_lvl, exp_gpio_ch); - if(!test_res) pass = 0; - - dout_ch = BSP_DOUT1; - dout_lvl = -1; - exp_gpio_lvl = MCU_GPIO_HIZ; - exp_gpio_ch = MCU_GPIO0; - test_res = ut_bsp_dout_write(dout_ch, dout_lvl, exp_gpio_lvl, exp_gpio_ch); - if(!test_res) pass = 0; - - // Defines test - dout_ch = BSP_DOUT1; - dout_lvl = BSP_DOUT_LOW; - exp_gpio_lvl = MCU_GPIO_LOW; - exp_gpio_ch = MCU_GPIO0; - test_res = ut_bsp_dout_write(dout_ch, dout_lvl, exp_gpio_lvl, exp_gpio_ch); - if(!test_res) pass = 0; - - dout_ch = BSP_DOUT1; - dout_lvl = BSP_DOUT_HIGH; - exp_gpio_lvl = MCU_GPIO_HIGH; - exp_gpio_ch = MCU_GPIO0; - test_res = ut_bsp_dout_write(dout_ch, dout_lvl, exp_gpio_lvl, exp_gpio_ch); - if(!test_res) pass = 0; - - dout_ch = BSP_DOUT1; - dout_lvl = BSP_DOUT_HIZ; - exp_gpio_lvl = MCU_GPIO_HIZ; - exp_gpio_ch = MCU_GPIO0; - test_res = ut_bsp_dout_write(dout_ch, dout_lvl, exp_gpio_lvl, exp_gpio_ch); - if(!test_res) pass = 0; - - // DOUT 2 - dout_ch = BSP_DOUT2; - dout_lvl = BSP_DOUT_LOW; - exp_gpio_lvl = MCU_GPIO_LOW; - exp_gpio_ch = MCU_GPIO1; - test_res = ut_bsp_dout_write(dout_ch, dout_lvl, exp_gpio_lvl, exp_gpio_ch); - if(!test_res) pass = 0; - - // DOUT 3 - dout_ch = BSP_DOUT3; - dout_lvl = BSP_DOUT_HIGH; - exp_gpio_lvl = MCU_GPIO_HIGH; - exp_gpio_ch = MCU_GPIO2; - test_res = ut_bsp_dout_write(dout_ch, dout_lvl, exp_gpio_lvl, exp_gpio_ch); - if(!test_res) pass = 0; - - // DOUT 4 - dout_ch = BSP_DOUT4; - dout_lvl = BSP_DOUT_LOW; - exp_gpio_lvl = MCU_GPIO_LOW; - exp_gpio_ch = MCU_GPIO3; - test_res = ut_bsp_dout_write(dout_ch, dout_lvl, exp_gpio_lvl, exp_gpio_ch); - if(!test_res) pass = 0; - - // DOUT 5 - dout_ch = BSP_DOUT5; - dout_lvl = BSP_DOUT_HIGH; - exp_gpio_lvl = MCU_GPIO_HIGH; - exp_gpio_ch = MCU_GPIO7; - test_res = ut_bsp_dout_write(dout_ch, dout_lvl, exp_gpio_lvl, exp_gpio_ch); - if(!test_res) pass = 0; - - // DOUT 6 - dout_ch = BSP_DOUT6; - dout_lvl = BSP_DOUT_LOW; - exp_gpio_lvl = MCU_GPIO_LOW; - exp_gpio_ch = MCU_GPIO8; - test_res = ut_bsp_dout_write(dout_ch, dout_lvl, exp_gpio_lvl, exp_gpio_ch); - if(!test_res) pass = 0; - - // Wrong channel - dout_ch = 0; - dout_lvl = BSP_DOUT_HIGH; - exp_gpio_lvl = NOT_ACCESED_GPIO_LVL; - exp_gpio_ch = NOT_ACCESED_GPIO_CH; - test_res = ut_bsp_dout_write(dout_ch, dout_lvl, exp_gpio_lvl, exp_gpio_ch); - if(!test_res) pass = 0; - - return pass; -} diff --git a/firmware/tests/ut_board/ut_dout.h b/firmware/tests/ut_board/ut_dout.h deleted file mode 100644 index 7b6108f..0000000 --- a/firmware/tests/ut_board/ut_dout.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef UT_BOARD_DOUT_H_ -#define UT_BOARD_DOUT_H_ - -#include -#include - -int ut_bsp_dout_write_test(void); - -#endif /* UT_BOARD_DOUT_H_ */ diff --git a/firmware/tests/ut_board/ut_halfbridge.c b/firmware/tests/ut_board/ut_halfbridge.c deleted file mode 100644 index 4116b76..0000000 --- a/firmware/tests/ut_board/ut_halfbridge.c +++ /dev/null @@ -1,273 +0,0 @@ -#include "ut_dout.h" - -#include "..\mock_mcu\mock_mcu_hal_r8.h" -#include "..\..\src\hw\board\halfbridge.h" - -static const uint8_t NOT_ACCESED_GPIO_CH = 255; -static const uint8_t NOT_ACCESED_GPIO_LVL = MCU_GPIO_HIZ; - -static int ut_bsp_hb_write_low(uint8_t state, int8_t exp_gpio_lvl, uint8_t exp_gpio_ch) -{ - printf(" Input: State:%d \n", state); - - mock_mcu_gpio_set_ch(NOT_ACCESED_GPIO_CH); - mock_mcu_gpio_set_output_lvl(NOT_ACCESED_GPIO_LVL, exp_gpio_ch); - - bsp_hb_write_low(state); - - uint8_t gpio_ch = mock_mcu_gpio_read_ch(); - int8_t gpio_lvl = mock_mcu_gpio_read_output_lvl(gpio_ch); - - printf(" Output: GPIO-lvl:%d GPIO-Ch:%d \n", gpio_lvl, gpio_ch); - printf("Expected: GPIO-lvl:%d GPIO-Ch:%d \n", exp_gpio_lvl, exp_gpio_ch); - - if((gpio_lvl==exp_gpio_lvl)&&(gpio_ch==exp_gpio_ch)) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_bsp_hb_write_low_test(void) -{ - printf("******************************************************\n"); - printf("void bsp_hb_write_low(uint8_t state) \n"); - - int test_res; - int pass = 1; - - uint8_t state; - int8_t exp_gpio_lvl; - uint8_t exp_gpio_ch; - - // Low - state = 0; - exp_gpio_lvl = MCU_GPIO_LOW; - exp_gpio_ch = MCU_GPIO15; - test_res = ut_bsp_hb_write_low(state, exp_gpio_lvl, exp_gpio_ch); - if(!test_res) pass = 0; - - // High - state = 1; - exp_gpio_lvl = MCU_GPIO_HIGH; - exp_gpio_ch = MCU_GPIO15; - test_res = ut_bsp_hb_write_low(state, exp_gpio_lvl, exp_gpio_ch); - if(!test_res) pass = 0; - - // High - state = 255; - exp_gpio_lvl = MCU_GPIO_HIGH; - exp_gpio_ch = MCU_GPIO15; - test_res = ut_bsp_hb_write_low(state, exp_gpio_lvl, exp_gpio_ch); - if(!test_res) pass = 0; - - return pass; -} - -static const uint8_t NOT_ACCESED_PWM_CH = 255; -static const uint8_t NOT_ACCESED_PWM_VAL = 0xFFFF; - -static int ut_bsp_hb_write_pwm(uint16_t pwm, uint16_t exp_pwm, uint8_t exp_pwm_ch) -{ - printf(" Input: PWM:%d \n", pwm); - - mock_mcu_pwm_set_ch(NOT_ACCESED_PWM_CH); - mock_mcu_pwm_set_raw(NOT_ACCESED_PWM_VAL, exp_pwm_ch); - - bsp_hb_write_pwm(pwm); - - uint8_t pwm_ch = mock_mcu_pwm_read_ch(); - uint16_t pwm_value = mock_mcu_pwm_read_raw(pwm_ch); - - printf(" Output: PWM:%d PWM-Ch:%d \n", pwm_value, pwm_ch); - printf("Expected: PWM:%d PWM-Ch:%d \n", exp_pwm, exp_pwm_ch); - - if((pwm_value==exp_pwm)&&(pwm_ch==exp_pwm_ch)) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_bsp_hb_write_pwm_test(void) -{ - printf("******************************************************\n"); - printf("void bsp_hb_write_pwm(uint16_t pwm) \n"); - - int test_res; - int pass = 1; - - uint16_t pwm; - uint16_t exp_pwm; - uint8_t exp_pwm_ch; - - // 0 - pwm = 0; - exp_pwm = 0; - exp_pwm_ch = MCU_PWM0; - test_res = ut_bsp_hb_write_pwm(pwm, exp_pwm, exp_pwm_ch); - if(!test_res) pass = 0; - - // 100 - pwm = 100; - exp_pwm = 100; - exp_pwm_ch = MCU_PWM0; - test_res = ut_bsp_hb_write_pwm(pwm, exp_pwm, exp_pwm_ch); - if(!test_res) pass = 0; - - // 95% - pwm = 0xFC00; - exp_pwm = 0xFC00; - exp_pwm_ch = MCU_PWM0; - test_res = ut_bsp_hb_write_pwm(pwm, exp_pwm, exp_pwm_ch); - if(!test_res) pass = 0; - - // MAX - pwm = 0xFFFF; - exp_pwm = 0xFC00; - exp_pwm_ch = MCU_PWM0; - test_res = ut_bsp_hb_write_pwm(pwm, exp_pwm, exp_pwm_ch); - if(!test_res) pass = 0; - - return pass; -} - -static const uint8_t NOT_ACCESED_ADC_CH = 255; -static const uint8_t NOT_ACCESED_ADC_VAL = 0xFFFF; - -static int ut_bsp_hb_read_meas(uint16_t adc_sup_u, uint16_t adc_sup_i, uint16_t adc_out_u, uint16_t adc_out_i, uint8_t low_side_lvl, uint16_t act_pwm, hb_meas_t* exp_meas) -{ - printf(" Input: Out-U:%d Out-I:%d Sup-U:%d Sup-I:%d Low-Lvl:%d PWM:%d \n", adc_out_u, adc_out_i, adc_sup_u, adc_sup_i, low_side_lvl, act_pwm); - - mock_mcu_adc_set_ch(NOT_ACCESED_ADC_CH); - mock_mcu_adc_set_raw(adc_sup_u, MCU_ADC2); - mock_mcu_adc_set_raw(adc_sup_i, MCU_ADC3); - mock_mcu_adc_set_raw(adc_out_u, MCU_ADC1); - mock_mcu_adc_set_raw(adc_out_i, MCU_ADC0); - - mock_mcu_gpio_set_ch(NOT_ACCESED_GPIO_CH); - mock_mcu_gpio_set_input_lvl(low_side_lvl, MCU_GPIO15); - - mock_mcu_pwm_set_ch(NOT_ACCESED_PWM_CH); - mock_mcu_pwm_set_raw(act_pwm, MCU_PWM0); - - hb_meas_t out; - - bsp_hb_read_meas(&out); - - uint8_t adc_ch = mock_mcu_adc_read_ch(); - uint8_t gpio_ch = mock_mcu_gpio_read_ch(); - uint8_t pwm_ch = mock_mcu_pwm_read_ch(); - - int equal = 1; - - if(out.out_voltage != exp_meas->out_voltage) equal = 0; - if(out.out_current != exp_meas->out_current) equal = 0; - if(out.sup_voltage != exp_meas->sup_voltage) equal = 0; - if(out.sup_current != exp_meas->sup_current) equal = 0; - if(out.out_power != exp_meas->out_power) equal = 0; - if(out.sup_power != exp_meas->sup_power) equal = 0; - if(out.out_impedance != exp_meas->out_impedance) equal = 0; - if(out.low_side_ctrl != exp_meas->low_side_ctrl) equal = 0; - if(out.pwm != exp_meas->pwm) equal = 0; - - printf(" Output: Out-U:%d Out-I:%d Bat-U:%d Bat-I:%d Out-P:%d Bat-P:%d Out-Z:%d Low:%d PWM:%d \n", out.out_voltage, out.out_current, out.sup_voltage, out.sup_current, out.out_power, out.sup_power, out.out_impedance, out.low_side_ctrl, out.pwm); - printf("Expected: Out-U:%d Out-I:%d Bat-U:%d Bat-I:%d Out-P:%d Bat-P:%d Out-Z:%d Low:%d PWM:%d \n", exp_meas->out_voltage, exp_meas->out_current, exp_meas->sup_voltage, exp_meas->sup_current, exp_meas->out_power, exp_meas->sup_power, exp_meas->out_impedance, exp_meas->low_side_ctrl, exp_meas->pwm); - - if((equal)&&(gpio_ch==MCU_GPIO15)&&(pwm_ch==MCU_PWM0)&&(adc_ch!=NOT_ACCESED_ADC_CH)) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_bsp_hb_read_meas_test(void) -{ - printf("******************************************************\n"); - printf("void bsp_hb_read_meas(hb_meas_t* measurements) \n"); - - int test_res; - int pass = 1; - - uint16_t adc_sup_u; - uint16_t adc_sup_i; - uint16_t adc_out_u; - uint16_t adc_out_i; - uint8_t low_side_lvl; - uint16_t act_pwm; - hb_meas_t exp_meas; - - // 0 - adc_sup_u = 0; - adc_sup_i = 0; - adc_out_u = 0; - adc_out_i = 0; - low_side_lvl = MCU_GPIO_LOW; - act_pwm = 0x0000; - exp_meas.out_voltage = 0; - exp_meas.out_current = 0; - exp_meas.sup_voltage = 0; - exp_meas.sup_current = 0; - exp_meas.out_power = 0; - exp_meas.sup_power = 0; - exp_meas.out_impedance = 0xFFFF; - exp_meas.low_side_ctrl = 0; - exp_meas.pwm = 0; - test_res = ut_bsp_hb_read_meas(adc_sup_u, adc_sup_i, adc_out_u, adc_out_i, low_side_lvl, act_pwm, &exp_meas); - if(!test_res) pass = 0; - - // Limits - adc_sup_u = 1023; - adc_sup_i = 1023; - adc_out_u = 1023; - adc_out_i = 1023; - low_side_lvl = MCU_GPIO_HIGH; - act_pwm = 457; - exp_meas.out_voltage = 20460; - exp_meas.out_current = 9997; - exp_meas.sup_voltage = 20460; - exp_meas.sup_current = 40067; - exp_meas.out_power = 0xFFFF; - exp_meas.sup_power = 0xFFFF; - exp_meas.out_impedance = 2046; - exp_meas.low_side_ctrl = 1; - exp_meas.pwm = 457; - test_res = ut_bsp_hb_read_meas(adc_sup_u, adc_sup_i, adc_out_u, adc_out_i, low_side_lvl, act_pwm, &exp_meas); - if(!test_res) pass = 0; - - // Normal - adc_sup_u = 600; - adc_sup_i = 51; - adc_out_u = 300; - adc_out_i = 409; - low_side_lvl = MCU_GPIO_HIGH; - act_pwm = 0xAAAA; - exp_meas.out_voltage = 6000; - exp_meas.out_current = 3997; - exp_meas.sup_voltage = 12000; - exp_meas.sup_current = 1997; - exp_meas.out_power = 23982; - exp_meas.sup_power = 23964; - exp_meas.out_impedance = 1501; - exp_meas.low_side_ctrl = 1; - exp_meas.pwm = 0xAAAA; - test_res = ut_bsp_hb_read_meas(adc_sup_u, adc_sup_i, adc_out_u, adc_out_i, low_side_lvl, act_pwm, &exp_meas); - if(!test_res) pass = 0; - - return pass; -} diff --git a/firmware/tests/ut_board/ut_halfbridge.h b/firmware/tests/ut_board/ut_halfbridge.h deleted file mode 100644 index 632697e..0000000 --- a/firmware/tests/ut_board/ut_halfbridge.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef UT_BOARD_HALFBRIDGE_H_ -#define UT_BOARD_HALFBRIDGE_H_ - -#include -#include - -int ut_bsp_hb_write_low_test(void); -int ut_bsp_hb_write_pwm_test(void); -int ut_bsp_hb_read_meas_test(void); - -#endif /* UT_BOARD_HALFBRIDGE_H_ */ diff --git a/firmware/tests/ut_board/ut_odout.c b/firmware/tests/ut_board/ut_odout.c deleted file mode 100644 index 9379742..0000000 --- a/firmware/tests/ut_board/ut_odout.c +++ /dev/null @@ -1,212 +0,0 @@ -#include "ut_odout.h" - -#include "..\mock_mcu\mock_mcu_hal_r8.h" -#include "..\..\src\hw\board\odout.h" - -static const uint8_t NOT_ACCESED_GPIO_CH = 255; -static const uint8_t NOT_ACCESED_GPIO_LVL = MCU_GPIO_HIZ; - -static int ut_bsp_odout_write(uint8_t odout_ch, int8_t odout_lvl, int8_t exp_gpio_lvl, uint8_t exp_gpio_ch) -{ - printf(" Input: ODout-Ch:%d ODout-lvl:%d \n", odout_ch, odout_lvl); - - mock_mcu_gpio_set_ch(NOT_ACCESED_GPIO_CH); - mock_mcu_gpio_set_output_lvl(NOT_ACCESED_GPIO_LVL, exp_gpio_ch); - - bsp_odout_write(odout_ch, odout_lvl); - - uint8_t gpio_ch = mock_mcu_gpio_read_ch(); - int8_t gpio_lvl = mock_mcu_gpio_read_output_lvl(gpio_ch); - - printf(" Output: GPIO-lvl:%d GPIO-Ch:%d \n", gpio_lvl, gpio_ch); - printf("Expected: GPIO-lvl:%d GPIO-Ch:%d \n", exp_gpio_lvl, exp_gpio_ch); - - if((gpio_lvl==exp_gpio_lvl)&&(gpio_ch==exp_gpio_ch)) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_bsp_odout_write_test(void) -{ - printf("******************************************************\n"); - printf("void bsp_odout_write(uint8_t ch, int8_t lvl) \n"); - - int test_res; - int pass = 1; - - uint8_t odout_ch; - uint8_t odout_lvl; - int8_t exp_gpio_lvl; - uint8_t exp_gpio_ch; - - // Control level - LOW - odout_ch = BSP_OD1; - odout_lvl = 0; - exp_gpio_lvl = MCU_GPIO_HIGH; - exp_gpio_ch = MCU_GPIO9; - test_res = ut_bsp_odout_write(odout_ch, odout_lvl, exp_gpio_lvl, exp_gpio_ch); - if(!test_res) pass = 0; - - // Control level - HIGH - odout_ch = BSP_OD1; - odout_lvl = 1; - exp_gpio_lvl = MCU_GPIO_LOW; - exp_gpio_ch = MCU_GPIO9; - test_res = ut_bsp_odout_write(odout_ch, odout_lvl, exp_gpio_lvl, exp_gpio_ch); - if(!test_res) pass = 0; - - // Control level - HIZ - odout_ch = BSP_OD1; - odout_lvl = -1; - exp_gpio_lvl = MCU_GPIO_LOW; - exp_gpio_ch = MCU_GPIO9; - test_res = ut_bsp_odout_write(odout_ch, odout_lvl, exp_gpio_lvl, exp_gpio_ch); - if(!test_res) pass = 0; - - // Control level DEFINE - LOW - odout_ch = BSP_OD1; - odout_lvl = BSP_ODOUT_LOW; - exp_gpio_lvl = MCU_GPIO_HIGH; - exp_gpio_ch = MCU_GPIO9; - test_res = ut_bsp_odout_write(odout_ch, odout_lvl, exp_gpio_lvl, exp_gpio_ch); - if(!test_res) pass = 0; - - // Control level DEFINE - HIGH - odout_ch = BSP_OD1; - odout_lvl = BSP_ODOUT_HIGH; - exp_gpio_lvl = MCU_GPIO_LOW; - exp_gpio_ch = MCU_GPIO9; - test_res = ut_bsp_odout_write(odout_ch, odout_lvl, exp_gpio_lvl, exp_gpio_ch); - if(!test_res) pass = 0; - - // Control level DEFINE - HIZ - odout_ch = BSP_OD1; - odout_lvl = BSP_ODOUT_HIZ; - exp_gpio_lvl = MCU_GPIO_LOW; - exp_gpio_ch = MCU_GPIO9; - test_res = ut_bsp_odout_write(odout_ch, odout_lvl, exp_gpio_lvl, exp_gpio_ch); - if(!test_res) pass = 0; - - // ODOUT 2 - odout_ch = BSP_OD2; - odout_lvl = 0; - exp_gpio_lvl = MCU_GPIO_HIGH; - exp_gpio_ch = MCU_GPIO10; - test_res = ut_bsp_odout_write(odout_ch, odout_lvl, exp_gpio_lvl, exp_gpio_ch); - if(!test_res) pass = 0; - - // ODOUT 3 - odout_ch = BSP_OD3; - odout_lvl = 0; - exp_gpio_lvl = MCU_GPIO_HIGH; - exp_gpio_ch = MCU_GPIO11; - test_res = ut_bsp_odout_write(odout_ch, odout_lvl, exp_gpio_lvl, exp_gpio_ch); - if(!test_res) pass = 0; - - // ODOUT 4 - odout_ch = BSP_OD4; - odout_lvl = 0; - exp_gpio_lvl = MCU_GPIO_HIGH; - exp_gpio_ch = MCU_GPIO12; - test_res = ut_bsp_odout_write(odout_ch, odout_lvl, exp_gpio_lvl, exp_gpio_ch); - if(!test_res) pass = 0; - - // ODOUT 5 - odout_ch = BSP_OD5; - odout_lvl = 0; - exp_gpio_lvl = MCU_GPIO_HIGH; - exp_gpio_ch = MCU_GPIO13; - test_res = ut_bsp_odout_write(odout_ch, odout_lvl, exp_gpio_lvl, exp_gpio_ch); - if(!test_res) pass = 0; - - // ODOUT 6 - odout_ch = BSP_OD6; - odout_lvl = 0; - exp_gpio_lvl = MCU_GPIO_HIGH; - exp_gpio_ch = MCU_GPIO14; - test_res = ut_bsp_odout_write(odout_ch, odout_lvl, exp_gpio_lvl, exp_gpio_ch); - if(!test_res) pass = 0; - - // Wrong chanell - odout_ch = 0; - odout_lvl = 0; - exp_gpio_lvl = NOT_ACCESED_GPIO_LVL; - exp_gpio_ch = NOT_ACCESED_GPIO_CH; - test_res = ut_bsp_odout_write(odout_ch, odout_lvl, exp_gpio_lvl, exp_gpio_ch); - if(!test_res) pass = 0; - - return pass; -} - -static const uint8_t NOT_ACCESED_PWM_CH = 255; -static const uint8_t NOT_ACCESED_PWM_VAL = 0xFFFF; - -static int ut_bsp_odout_write_common(uint8_t percent, uint16_t exp_pwm, uint8_t exp_pwm_ch) -{ - printf(" Input: Percent:%d \n", percent); - - mock_mcu_pwm_set_ch(NOT_ACCESED_PWM_CH); - mock_mcu_pwm_set_raw(NOT_ACCESED_PWM_VAL, exp_pwm_ch); - - bsp_odout_write_common(percent); - - uint8_t pwm_ch = mock_mcu_pwm_read_ch(); - uint16_t pwm_value = mock_mcu_pwm_read_raw(pwm_ch); - - printf(" Output: PWM:%d PWM-Ch:%d \n", pwm_value, pwm_ch); - printf("Expected: PWM:%d PWM-Ch:%d \n", exp_pwm, exp_pwm_ch); - - if((pwm_value==exp_pwm)&&(pwm_ch==exp_pwm_ch)) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_bsp_odout_write_common_test(void) -{ - printf("******************************************************\n"); - printf("void bsp_odout_write_common(uint8_t percent) \n"); - - int test_res; - int pass = 1; - - uint8_t percent; - uint16_t exp_pwm; - uint8_t exp_pwm_ch; - - // Zero - percent = 0; - exp_pwm = 0x0000; - exp_pwm_ch = MCU_PWM1; - test_res = ut_bsp_odout_write_common(percent, exp_pwm, exp_pwm_ch); - if(!test_res) pass = 0; - - // 100 - percent = 100; - exp_pwm = 0xFFFF; - exp_pwm_ch = MCU_PWM1; - test_res = ut_bsp_odout_write_common(percent, exp_pwm, exp_pwm_ch); - if(!test_res) pass = 0; - - // 50 - percent = 50; - exp_pwm = 0x7FFF; - exp_pwm_ch = MCU_PWM1; - test_res = ut_bsp_odout_write_common(percent, exp_pwm, exp_pwm_ch); - if(!test_res) pass = 0; - - return pass; -} diff --git a/firmware/tests/ut_board/ut_odout.h b/firmware/tests/ut_board/ut_odout.h deleted file mode 100644 index 4905b2f..0000000 --- a/firmware/tests/ut_board/ut_odout.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef UT_BOARD_ODOUT_H_ -#define UT_BOARD_ODOUT_H_ - -#include -#include - -int ut_bsp_odout_write_test(void); -int ut_bsp_odout_write_common_test(void); - -#endif /* UT_BOARD_ODOUT_H_ */ diff --git a/firmware/tests/ut_board/ut_setup.c b/firmware/tests/ut_board/ut_setup.c deleted file mode 100644 index f15aa37..0000000 --- a/firmware/tests/ut_board/ut_setup.c +++ /dev/null @@ -1,62 +0,0 @@ -#include "ut_odout.h" - -#include "..\mock_mcu\mock_mcu_hal_r8.h" -#include "..\..\src\hw\board\setup.h" - -static adcClkDiv_t not_accesed_adc_clk = MCU_ADC_DIV128; -static timerClkDiv_t not_accesed_pwm_clk = MCU_TIM_DIV1024; -static uint16_t not_accesed_pwm_top = 0; -static uint8_t not_accesed_pwm_chb_en = 255; - -static int ut_bsp_startup(startupCfg_t* exp_cfg) -{ - printf(" Input: \n"); - - startupCfg_t not_accesd_cfg; - not_accesd_cfg.adc_clk = not_accesed_adc_clk; - not_accesd_cfg.pwm_clk = not_accesed_pwm_clk; - not_accesd_cfg.pwm_top = not_accesed_pwm_top; - not_accesd_cfg.pwm_chb_en = not_accesed_pwm_chb_en; - mock_mcu_startup_write_cfg(¬_accesd_cfg); - - bsp_startup(); - - startupCfg_t cfg; - mock_mcu_startup_read_cfg(&cfg); - - printf(" Output: ADC-CLK:%d PWN-CLK:%d PWM-TOP:%d PWM-CHB-EN:%d \n", cfg.adc_clk, cfg.pwm_clk, cfg.pwm_top, cfg.pwm_chb_en); - printf("Expected: ADC-CLK:%d PWN-CLK:%d PWM-TOP:%d PWM-CHB-EN:%d \n", exp_cfg->adc_clk, exp_cfg->pwm_clk, exp_cfg->pwm_top, exp_cfg->pwm_chb_en); - - if((cfg.adc_clk==exp_cfg->adc_clk)&&(cfg.pwm_clk==exp_cfg->pwm_clk)&&(cfg.pwm_top==exp_cfg->pwm_top)&&(cfg.pwm_chb_en==exp_cfg->pwm_chb_en)) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_bsp_startup_test(void) -{ - printf("******************************************************\n"); - printf("void bsp_startup(void) \n"); - - int test_res; - int pass = 1; - - startupCfg_t exp_cfg; - - // Control level - LOW - exp_cfg.adc_clk = MCU_ADC_DIV2; - exp_cfg.pwm_clk = MCU_TIM_DIV1; - exp_cfg.pwm_top = 511; - exp_cfg.pwm_chb_en = 1; - test_res = ut_bsp_startup(&exp_cfg); - if(!test_res) pass = 0; - - return pass; -} - diff --git a/firmware/tests/ut_board/ut_setup.h b/firmware/tests/ut_board/ut_setup.h deleted file mode 100644 index 0957e3b..0000000 --- a/firmware/tests/ut_board/ut_setup.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef UT_BOARD_SETUP_H_ -#define UT_BOARD_SETUP_H_ - -#include -#include - -int ut_bsp_startup_test(void); - -#endif /* UT_BOARD_SETUP_H_ */ diff --git a/firmware/tests/ut_hw/ut_analog.c b/firmware/tests/ut_hw/ut_analog.c deleted file mode 100644 index 2ae20ac..0000000 --- a/firmware/tests/ut_hw/ut_analog.c +++ /dev/null @@ -1,73 +0,0 @@ -#include "ut_analog.h" - -#include "..\mock_board\mock_board_ain.h" - -#include "..\..\src\hw\analog.h" - -static const uint8_t NOT_ACCESED_AIN_CH = 255; - -static int ut_analog_ch_get(uint8_t analog_ch, uint16_t ain_value, uint16_t exp_out, uint8_t exp_ain_ch) -{ - printf(" Input: Analog-Ch:%d AIN-Value:%d \n", analog_ch, ain_value); - - mock_board_ain_write_ch(NOT_ACCESED_AIN_CH); - mock_board_ain_write_data(exp_ain_ch, ain_value); - - uint16_t out = analog_ch_get(analog_ch); - - uint8_t ain_ch = mock_board_ain_read_ch(); - - printf(" Output: ANALOG:%d AIN-Ch:%d \n", out, ain_ch); - printf("Expected: ANALOG:%d AIN-Ch:%d \n", exp_out, exp_ain_ch); - - if((out==exp_out)&&(ain_ch==exp_ain_ch)) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_analog_ch_get_test(void) -{ - printf("******************************************************\n"); - printf("uint16_t analog_ch_get(uint8_t analog_ch) \n"); - - int test_res; - int pass = 1; - - uint8_t analog_ch; - uint16_t ain_value; - uint16_t exp_out; - uint8_t exp_ain_ch; - - // Normal 1 - analog_ch = ANALOG_1; - ain_value = 2500; - exp_out = 2500; - exp_ain_ch = BSP_AIN2; - test_res = ut_analog_ch_get(analog_ch, ain_value, exp_out, exp_ain_ch); - if(!test_res) pass = 0; - - // Normal 2 - analog_ch = ANALOG_2; - ain_value = 3000; - exp_out = 3000; - exp_ain_ch = BSP_AIN1; - test_res = ut_analog_ch_get(analog_ch, ain_value, exp_out, exp_ain_ch); - if(!test_res) pass = 0; - - // Wrong channel - analog_ch = 0; - ain_value = 1200; - exp_out = 0; - exp_ain_ch = NOT_ACCESED_AIN_CH; - test_res = ut_analog_ch_get(analog_ch, ain_value, exp_out, exp_ain_ch); - if(!test_res) pass = 0; - - return pass; -} diff --git a/firmware/tests/ut_hw/ut_analog.h b/firmware/tests/ut_hw/ut_analog.h deleted file mode 100644 index fc3d064..0000000 --- a/firmware/tests/ut_hw/ut_analog.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef UT_HW_ANALOG_H_ -#define UT_HW_ANALOG_H_ - -#include -#include - -int ut_analog_ch_get_test(void); - -#endif /* UT_HW_ANALOG_H_ */ diff --git a/firmware/tests/ut_hw/ut_buttons.c b/firmware/tests/ut_hw/ut_buttons.c deleted file mode 100644 index 7cebd6b..0000000 --- a/firmware/tests/ut_hw/ut_buttons.c +++ /dev/null @@ -1,854 +0,0 @@ -#include "ut_buttons.h" - -#include "..\mock_board\mock_board_din.h" -#include "..\mock_board\mock_board_dout.h" - -#include "..\..\src\hw\buttons.h" - -static const uint8_t NOT_ACCESED_DIN_CH = 255; -static const uint8_t NOT_ACCESED_DIN_LVL = BSP_DIN_LOW; - -static const uint8_t NOT_ACCESED_DOUT_CH = 255; -static const int8_t NOT_ACCESED_DOUT_LVL = BSP_DOUT_HIZ; - -static int ut_btn_reset(btn_t* btn, btn_t* exp_btn) -{ - printf(" Input: State:%d New-State:%d State-time:%d Transition-cntr:%d Debounce-act:%d \n", btn->state, btn->new_state, btn->state_time, btn->transition_cntr, btn->dbnc_active); - - btn_reset(btn); - - printf(" Output: State:%d New-State:%d State-time:%d Transition-cntr:%d Debounce-act:%d \n", btn->state, btn->new_state, btn->state_time, btn->transition_cntr, btn->dbnc_active); - printf("Expected: State:%d New-State:%d State-time:%d Transition-cntr:%d Debounce-act:%d \n", exp_btn->state, exp_btn->new_state, exp_btn->state_time, exp_btn->transition_cntr, exp_btn->dbnc_active); - - int equal = 1; - if(btn->state != exp_btn->state) equal = 0; - if(btn->new_state != exp_btn->new_state) equal = 0; - if(btn->state_time != exp_btn->state_time) equal = 0; - if(btn->transition_cntr != exp_btn->transition_cntr) equal = 0; - if(btn->dbnc_active != exp_btn->dbnc_active) equal = 0; - - if(equal) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_btn_reset_test(void) -{ - printf("******************************************************\n"); - printf("void btn_reset(btn_t* btn) \n"); - - int test_res; - int pass = 1; - - btn_t btn; - btn_t exp_btn; - - // Normal 1 - btn.state = 0; - btn.new_state = 0; - btn.state_time = 0; - btn.transition_cntr = 0; - btn.dbnc_active = 0; - exp_btn.state = 0; - exp_btn.new_state = 0; - exp_btn.state_time = 0; - exp_btn.transition_cntr = 0; - exp_btn.dbnc_active = 1; - test_res = ut_btn_reset(&btn, &exp_btn); - if(!test_res) pass = 0; - - // Normal 1 - btn.state = 1; - btn.new_state = 1; - btn.state_time = 1000; - btn.transition_cntr = 20; - btn.dbnc_active = 0; - exp_btn.state = BTN_INACTIVE; - exp_btn.new_state = 0; - exp_btn.state_time = 0; - exp_btn.transition_cntr = 0; - exp_btn.dbnc_active = 1; - test_res = ut_btn_reset(&btn, &exp_btn); - if(!test_res) pass = 0; - - return pass; -} - -static int ut_btn_process(uint8_t lvl, btn_t* btn, btn_cfg_t* cfg, uint8_t exp_out, btn_t* exp_btn, btn_cfg_t* exp_cfg) -{ - printf(" Input: Level:%d \n", lvl); - printf(" Input: State:%d New-State:%d State-time:%d Transition-cntr:%d Debounce-act:%d \n", btn->state, btn->new_state, btn->state_time, btn->transition_cntr, btn->dbnc_active); - printf(" Input: Act-Lvl:%d Debounce-lim:%d Repeat-Time:%d \n", cfg->act_lvl, cfg->dbnc_lim, cfg->repeat_time); - - uint8_t out = btn_process(lvl, btn, cfg); - - printf(" Output: %d \n", out); - printf(" Output: State:%d New-State:%d State-time:%d Transition-cntr:%d Debounce-act:%d \n", btn->state, btn->new_state, btn->state_time, btn->transition_cntr, btn->dbnc_active); - printf(" Output: Act-Lvl:%d Debounce-lim:%d Repeat-Time:%d \n", cfg->act_lvl, cfg->dbnc_lim, cfg->repeat_time); - - printf("Expected: %d \n", exp_out); - printf("Expected: State:%d New-State:%d State-time:%d Transition-cntr:%d Debounce-act:%d \n", exp_btn->state, exp_btn->new_state, exp_btn->state_time, exp_btn->transition_cntr, exp_btn->dbnc_active); - printf("Expected: Act-Lvl:%d Debounce-lim:%d Repeat-Time:%d \n", exp_cfg->act_lvl, exp_cfg->dbnc_lim, exp_cfg->repeat_time); - - int equal = 1; - if(btn->state != exp_btn->state) equal = 0; - if(btn->new_state != exp_btn->new_state) equal = 0; - if(btn->state_time != exp_btn->state_time) equal = 0; - if(btn->transition_cntr != exp_btn->transition_cntr) equal = 0; - if(btn->dbnc_active != exp_btn->dbnc_active) equal = 0; - if(cfg->act_lvl != exp_cfg->act_lvl) equal = 0; - if(cfg->dbnc_lim != exp_cfg->dbnc_lim) equal = 0; - if(cfg->repeat_time != exp_cfg->repeat_time) equal = 0; - - if((out==exp_out)&&(equal)) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_btn_process_test(void) -{ - printf("******************************************************\n"); - printf("uint8_t btn_process(uint8_t lvl, btn_t* btn, btn_cfg_t* cfg) \n"); - - int test_res; - int pass = 1; - - uint8_t lvl; - btn_t btn; - btn_cfg_t cfg; - uint8_t exp_out; - btn_t exp_btn; - btn_cfg_t exp_cfg; - - // No changes - lvl = 0; - btn.state = 0; - btn.new_state = 0; - btn.state_time = 0; - btn.transition_cntr = 0; - btn.dbnc_active = 0; - cfg.act_lvl = 1; - cfg.dbnc_lim = 0; - cfg.repeat_time = 0; - - exp_out = 0; - exp_btn.state = 0; - exp_btn.new_state = 0; - exp_btn.state_time = 1; - exp_btn.transition_cntr = 0; - exp_btn.dbnc_active = 0; - exp_cfg.act_lvl = cfg.act_lvl; - exp_cfg.dbnc_lim = cfg.dbnc_lim; - exp_cfg.repeat_time = cfg.repeat_time; - - test_res = ut_btn_process(lvl, &btn, &cfg, exp_out, &exp_btn, &exp_cfg); - if(!test_res) pass = 0; - - // State time increase - lvl = 1; - btn.state = 0; - btn.new_state = 0; - btn.state_time = 12345; - btn.transition_cntr = 0; - btn.dbnc_active = 0; - cfg.act_lvl = 0; - cfg.dbnc_lim = 0; - cfg.repeat_time = 0; - - exp_out = 0; - exp_btn.state = 0; - exp_btn.new_state = 0; - exp_btn.state_time = 12346; - exp_btn.transition_cntr = 0; - exp_btn.dbnc_active = 0; - exp_cfg.act_lvl = cfg.act_lvl; - exp_cfg.dbnc_lim = cfg.dbnc_lim; - exp_cfg.repeat_time = cfg.repeat_time; - - test_res = ut_btn_process(lvl, &btn, &cfg, exp_out, &exp_btn, &exp_cfg); - if(!test_res) pass = 0; - - // Activation, first time, act high - lvl = 1; - btn.state = 0; - btn.new_state = 0; - btn.state_time = 38455; - btn.transition_cntr = 0; - btn.dbnc_active = 0; - cfg.act_lvl = 1; - cfg.dbnc_lim = 0; - cfg.repeat_time = 0; - - exp_out = 1; - exp_btn.state = 1; - exp_btn.new_state = 1; - exp_btn.state_time = 0; - exp_btn.transition_cntr = 0; - exp_btn.dbnc_active = 0; - exp_cfg.act_lvl = cfg.act_lvl; - exp_cfg.dbnc_lim = cfg.dbnc_lim; - exp_cfg.repeat_time = cfg.repeat_time; - - test_res = ut_btn_process(lvl, &btn, &cfg, exp_out, &exp_btn, &exp_cfg); - if(!test_res) pass = 0; - - // Activation, first time, act low - lvl = 0; - btn.state = 0; - btn.new_state = 0; - btn.state_time = 38455; - btn.transition_cntr = 0; - btn.dbnc_active = 0; - cfg.act_lvl = 0; - cfg.dbnc_lim = 0; - cfg.repeat_time = 0; - - exp_out = 1; - exp_btn.state = 1; - exp_btn.new_state = 1; - exp_btn.state_time = 0; - exp_btn.transition_cntr = 0; - exp_btn.dbnc_active = 0; - exp_cfg.act_lvl = cfg.act_lvl; - exp_cfg.dbnc_lim = cfg.dbnc_lim; - exp_cfg.repeat_time = cfg.repeat_time; - - test_res = ut_btn_process(lvl, &btn, &cfg, exp_out, &exp_btn, &exp_cfg); - if(!test_res) pass = 0; - - // Active second time, not cleared new flag - lvl = 1; - btn.state = 1; - btn.new_state = 1; - btn.state_time = 0; - btn.transition_cntr = 0; - btn.dbnc_active = 0; - cfg.act_lvl = 1; - cfg.dbnc_lim = 0; - cfg.repeat_time = 0; - - exp_out = 1; - exp_btn.state = 1; - exp_btn.new_state = 1; - exp_btn.state_time = 1; - exp_btn.transition_cntr = 0; - exp_btn.dbnc_active = 0; - exp_cfg.act_lvl = cfg.act_lvl; - exp_cfg.dbnc_lim = cfg.dbnc_lim; - exp_cfg.repeat_time = cfg.repeat_time; - - test_res = ut_btn_process(lvl, &btn, &cfg, exp_out, &exp_btn, &exp_cfg); - if(!test_res) pass = 0; - - // Active second time, cleared new flag - lvl = 1; - btn.state = 1; - btn.new_state = 0; - btn.state_time = 0; - btn.transition_cntr = 0; - btn.dbnc_active = 0; - cfg.act_lvl = 1; - cfg.dbnc_lim = 0; - cfg.repeat_time = 0; - - exp_out = 1; - exp_btn.state = 1; - exp_btn.new_state = 0; - exp_btn.state_time = 1; - exp_btn.transition_cntr = 0; - exp_btn.dbnc_active = 0; - exp_cfg.act_lvl = cfg.act_lvl; - exp_cfg.dbnc_lim = cfg.dbnc_lim; - exp_cfg.repeat_time = cfg.repeat_time; - - test_res = ut_btn_process(lvl, &btn, &cfg, exp_out, &exp_btn, &exp_cfg); - if(!test_res) pass = 0; - - // Deactive, act high - lvl = 0; - btn.state = 1; - btn.new_state = 0; - btn.state_time = 60584; - btn.transition_cntr = 0; - btn.dbnc_active = 0; - cfg.act_lvl = 1; - cfg.dbnc_lim = 0; - cfg.repeat_time = 0; - - exp_out = 0; - exp_btn.state = 0; - exp_btn.new_state = 1; - exp_btn.state_time = 0; - exp_btn.transition_cntr = 0; - exp_btn.dbnc_active = 0; - exp_cfg.act_lvl = cfg.act_lvl; - exp_cfg.dbnc_lim = cfg.dbnc_lim; - exp_cfg.repeat_time = cfg.repeat_time; - - test_res = ut_btn_process(lvl, &btn, &cfg, exp_out, &exp_btn, &exp_cfg); - if(!test_res) pass = 0; - - // Deactive, act low - lvl = 1; - btn.state = 1; - btn.new_state = 0; - btn.state_time = 558; - btn.transition_cntr = 0; - btn.dbnc_active = 0; - cfg.act_lvl = 0; - cfg.dbnc_lim = 0; - cfg.repeat_time = 0; - - exp_out = 0; - exp_btn.state = 0; - exp_btn.new_state = 1; - exp_btn.state_time = 0; - exp_btn.transition_cntr = 0; - exp_btn.dbnc_active = 0; - exp_cfg.act_lvl = cfg.act_lvl; - exp_cfg.dbnc_lim = cfg.dbnc_lim; - exp_cfg.repeat_time = cfg.repeat_time; - - test_res = ut_btn_process(lvl, &btn, &cfg, exp_out, &exp_btn, &exp_cfg); - if(!test_res) pass = 0; - - // Debounce, first - lvl = 1; - btn.state = 0; - btn.new_state = 0; - btn.state_time = 24789; - btn.transition_cntr = 0; - btn.dbnc_active = 0; - cfg.act_lvl = 1; - cfg.dbnc_lim = 10; - cfg.repeat_time = 0; - - exp_out = 0; - exp_btn.state = 0; - exp_btn.new_state = 0; - exp_btn.state_time = 24790; - exp_btn.transition_cntr = 0; - exp_btn.dbnc_active = 1; - exp_cfg.act_lvl = cfg.act_lvl; - exp_cfg.dbnc_lim = cfg.dbnc_lim; - exp_cfg.repeat_time = cfg.repeat_time; - - test_res = ut_btn_process(lvl, &btn, &cfg, exp_out, &exp_btn, &exp_cfg); - if(!test_res) pass = 0; - - // Debounce at end - lvl = 1; - btn.state = 0; - btn.new_state = 0; - btn.state_time = 142; - btn.transition_cntr = 9; - btn.dbnc_active = 1; - cfg.act_lvl = 1; - cfg.dbnc_lim = 10; - cfg.repeat_time = 0; - - exp_out = 1; - exp_btn.state = 1; - exp_btn.new_state = 1; - exp_btn.state_time = 0; - exp_btn.transition_cntr = 0; - exp_btn.dbnc_active = 0; - exp_cfg.act_lvl = cfg.act_lvl; - exp_cfg.dbnc_lim = cfg.dbnc_lim; - exp_cfg.repeat_time = cfg.repeat_time; - - test_res = ut_btn_process(lvl, &btn, &cfg, exp_out, &exp_btn, &exp_cfg); - if(!test_res) pass = 0; - - // Debounce fail, act high, fail to active state - lvl = 0; - btn.state = 0; - btn.new_state = 0; - btn.state_time = 142; - btn.transition_cntr = 5; - btn.dbnc_active = 1; - cfg.act_lvl = 1; - cfg.dbnc_lim = 10; - cfg.repeat_time = 0; - - exp_out = 0; - exp_btn.state = 0; - exp_btn.new_state = 0; - exp_btn.state_time = 143; - exp_btn.transition_cntr = 0; - exp_btn.dbnc_active = 0; - exp_cfg.act_lvl = cfg.act_lvl; - exp_cfg.dbnc_lim = cfg.dbnc_lim; - exp_cfg.repeat_time = cfg.repeat_time; - - test_res = ut_btn_process(lvl, &btn, &cfg, exp_out, &exp_btn, &exp_cfg); - if(!test_res) pass = 0; - - // Debounce fail, act low, fail to active state - lvl = 1; - btn.state = 0; - btn.new_state = 0; - btn.state_time = 257; - btn.transition_cntr = 4; - btn.dbnc_active = 1; - cfg.act_lvl = 0; - cfg.dbnc_lim = 10; - cfg.repeat_time = 0; - - exp_out = 0; - exp_btn.state = 0; - exp_btn.new_state = 0; - exp_btn.state_time = 258; - exp_btn.transition_cntr = 0; - exp_btn.dbnc_active = 0; - exp_cfg.act_lvl = cfg.act_lvl; - exp_cfg.dbnc_lim = cfg.dbnc_lim; - exp_cfg.repeat_time = cfg.repeat_time; - - test_res = ut_btn_process(lvl, &btn, &cfg, exp_out, &exp_btn, &exp_cfg); - if(!test_res) pass = 0; - - // Before New state repeat - lvl = 1; - btn.state = 1; - btn.new_state = 0; - btn.state_time = 4998; - btn.transition_cntr = 0; - btn.dbnc_active = 0; - cfg.act_lvl = 1; - cfg.dbnc_lim = 10; - cfg.repeat_time = 5000; - - exp_out = 1; - exp_btn.state = 1; - exp_btn.new_state = 0; - exp_btn.state_time = 4999; - exp_btn.transition_cntr = 0; - exp_btn.dbnc_active = 0; - exp_cfg.act_lvl = cfg.act_lvl; - exp_cfg.dbnc_lim = cfg.dbnc_lim; - exp_cfg.repeat_time = cfg.repeat_time; - - test_res = ut_btn_process(lvl, &btn, &cfg, exp_out, &exp_btn, &exp_cfg); - if(!test_res) pass = 0; - - // Before New state repeat - lvl = 1; - btn.state = 1; - btn.new_state = 0; - btn.state_time = 4999; - btn.transition_cntr = 0; - btn.dbnc_active = 0; - cfg.act_lvl = 1; - cfg.dbnc_lim = 10; - cfg.repeat_time = 5000; - - exp_out = 1; - exp_btn.state = 1; - exp_btn.new_state = 1; - exp_btn.state_time = 5000; - exp_btn.transition_cntr = 0; - exp_btn.dbnc_active = 0; - exp_cfg.act_lvl = cfg.act_lvl; - exp_cfg.dbnc_lim = cfg.dbnc_lim; - exp_cfg.repeat_time = cfg.repeat_time; - - test_res = ut_btn_process(lvl, &btn, &cfg, exp_out, &exp_btn, &exp_cfg); - if(!test_res) pass = 0; - - // Before New state repeat - lvl = 1; - btn.state = 1; - btn.new_state = 0; - btn.state_time = 5000; - btn.transition_cntr = 0; - btn.dbnc_active = 0; - cfg.act_lvl = 1; - cfg.dbnc_lim = 10; - cfg.repeat_time = 5000; - - exp_out = 1; - exp_btn.state = 1; - exp_btn.new_state = 0; - exp_btn.state_time = 5001; - exp_btn.transition_cntr = 0; - exp_btn.dbnc_active = 0; - exp_cfg.act_lvl = cfg.act_lvl; - exp_cfg.dbnc_lim = cfg.dbnc_lim; - exp_cfg.repeat_time = cfg.repeat_time; - - test_res = ut_btn_process(lvl, &btn, &cfg, exp_out, &exp_btn, &exp_cfg); - if(!test_res) pass = 0; - - // Before New state repeat - lvl = 1; - btn.state = 1; - btn.new_state = 0; - btn.state_time = 19999; - btn.transition_cntr = 0; - btn.dbnc_active = 0; - cfg.act_lvl = 1; - cfg.dbnc_lim = 10; - cfg.repeat_time = 5000; - - exp_out = 1; - exp_btn.state = 1; - exp_btn.new_state = 1; - exp_btn.state_time = 20000; - exp_btn.transition_cntr = 0; - exp_btn.dbnc_active = 0; - exp_cfg.act_lvl = cfg.act_lvl; - exp_cfg.dbnc_lim = cfg.dbnc_lim; - exp_cfg.repeat_time = cfg.repeat_time; - - test_res = ut_btn_process(lvl, &btn, &cfg, exp_out, &exp_btn, &exp_cfg); - if(!test_res) pass = 0; - - // Before New state repeat - lvl = 1; - btn.state = 1; - btn.new_state = 0; - btn.state_time = 0xFFFE; - btn.transition_cntr = 0; - btn.dbnc_active = 0; - cfg.act_lvl = 1; - cfg.dbnc_lim = 10; - cfg.repeat_time = 255; - - exp_out = 1; - exp_btn.state = 1; - exp_btn.new_state = 0; - exp_btn.state_time = 0xFFFF; - exp_btn.transition_cntr = 0; - exp_btn.dbnc_active = 0; - exp_cfg.act_lvl = cfg.act_lvl; - exp_cfg.dbnc_lim = cfg.dbnc_lim; - exp_cfg.repeat_time = cfg.repeat_time; - - test_res = ut_btn_process(lvl, &btn, &cfg, exp_out, &exp_btn, &exp_cfg); - if(!test_res) pass = 0; - - return pass; -} - -static int ut_btn_ch_process(uint8_t btn_ch, btn_t* btn, uint8_t din_lvl, uint8_t exp_out, btn_t* exp_btn, uint8_t exp_din_ch) -{ - printf(" Input: Btn-Ch:%d Din-Lvl:%d\n", btn_ch, din_lvl); - printf(" Input: State:%d New-State:%d State-time:%d Transition-cntr:%d Debounce-act:%d \n", btn->state, btn->new_state, btn->state_time, btn->transition_cntr, btn->dbnc_active); - - mock_board_din_write_ch(NOT_ACCESED_DIN_CH); - mock_board_din_write_data(exp_din_ch, din_lvl); - - uint8_t out = btn_ch_process(btn_ch, btn); - - uint8_t din_ch = mock_board_din_read_ch(); - - printf(" Output: %d \n", out); - printf(" Output: State:%d New-State:%d State-time:%d Transition-cntr:%d Debounce-act:%d \n", btn->state, btn->new_state, btn->state_time, btn->transition_cntr, btn->dbnc_active); - printf(" Output: Din-Ch:%d \n", din_ch); - - printf("Expected: %d \n", exp_out); - printf("Expected: State:%d New-State:%d State-time:%d Transition-cntr:%d Debounce-act:%d \n", exp_btn->state, exp_btn->new_state, exp_btn->state_time, exp_btn->transition_cntr, exp_btn->dbnc_active); - printf("Expected: Din-Ch:%d \n", exp_din_ch); - - int equal = 1; - if(btn->state != exp_btn->state) equal = 0; - if(btn->new_state != exp_btn->new_state) equal = 0; - if(btn->state_time != exp_btn->state_time) equal = 0; - if(btn->transition_cntr != exp_btn->transition_cntr) equal = 0; - if(btn->dbnc_active != exp_btn->dbnc_active) equal = 0; - - if((out==exp_out)&&(equal)&&(din_ch==exp_din_ch)) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_btn_ch_process_test(void) -{ - printf("******************************************************\n"); - printf("uint8_t btn_ch_process(uint8_t btn_ch, btn_t* btn) \n"); - - int test_res; - int pass = 1; - - uint8_t btn_ch; - btn_t btn; - uint8_t din_lvl; - uint8_t exp_out; - btn_t exp_btn; - uint8_t exp_din_ch; - - // Mapping check 1 - btn_ch = BTN_1; - btn.state = 0; - btn.new_state = 0; - btn.state_time = 150; - btn.transition_cntr = 9; - btn.dbnc_active = 1; - din_lvl = BSP_DIN_LOW; - - exp_out = 1; - exp_btn.state = 1; - exp_btn.new_state = 1; - exp_btn.state_time = 0; - exp_btn.transition_cntr = 0; - exp_btn.dbnc_active = 0; - exp_din_ch = BSP_DIN1; - - test_res = ut_btn_ch_process(btn_ch, &btn, din_lvl, exp_out, &exp_btn, exp_din_ch); - if(!test_res) pass = 0; - - // Mapping check 2 - btn_ch = BTN_2; - btn.state = 0; - btn.new_state = 0; - btn.state_time = 150; - btn.transition_cntr = 9; - btn.dbnc_active = 1; - din_lvl = BSP_DIN_LOW; - - exp_out = 1; - exp_btn.state = 1; - exp_btn.new_state = 1; - exp_btn.state_time = 0; - exp_btn.transition_cntr = 0; - exp_btn.dbnc_active = 0; - exp_din_ch = BSP_DIN3; - - test_res = ut_btn_ch_process(btn_ch, &btn, din_lvl, exp_out, &exp_btn, exp_din_ch); - if(!test_res) pass = 0; - - // Mapping check 3 - btn_ch = BTN_3; - btn.state = 0; - btn.new_state = 0; - btn.state_time = 150; - btn.transition_cntr = 9; - btn.dbnc_active = 1; - din_lvl = BSP_DIN_LOW; - - exp_out = 1; - exp_btn.state = 1; - exp_btn.new_state = 1; - exp_btn.state_time = 0; - exp_btn.transition_cntr = 0; - exp_btn.dbnc_active = 0; - exp_din_ch = BSP_DIN4; - - test_res = ut_btn_ch_process(btn_ch, &btn, din_lvl, exp_out, &exp_btn, exp_din_ch); - if(!test_res) pass = 0; - - // Mapping check 4 - btn_ch = BTN_4; - btn.state = 0; - btn.new_state = 0; - btn.state_time = 150; - btn.transition_cntr = 9; - btn.dbnc_active = 1; - din_lvl = BSP_DIN_HIGH; - - exp_out = 1; - exp_btn.state = 1; - exp_btn.new_state = 1; - exp_btn.state_time = 0; - exp_btn.transition_cntr = 0; - exp_btn.dbnc_active = 0; - exp_din_ch = BSP_DIN5; - - test_res = ut_btn_ch_process(btn_ch, &btn, din_lvl, exp_out, &exp_btn, exp_din_ch); - if(!test_res) pass = 0; - - // Mapping check 5 - btn_ch = BTN_5; - btn.state = 0; - btn.new_state = 0; - btn.state_time = 150; - btn.transition_cntr = 9; - btn.dbnc_active = 1; - din_lvl = BSP_DIN_HIGH; - - exp_out = 1; - exp_btn.state = 1; - exp_btn.new_state = 1; - exp_btn.state_time = 0; - exp_btn.transition_cntr = 0; - exp_btn.dbnc_active = 0; - exp_din_ch = BSP_DIN6; - - test_res = ut_btn_ch_process(btn_ch, &btn, din_lvl, exp_out, &exp_btn, exp_din_ch); - if(!test_res) pass = 0; - - // Mapping check 6 - btn_ch = BTN_6; - btn.state = 0; - btn.new_state = 0; - btn.state_time = 150; - btn.transition_cntr = 9; - btn.dbnc_active = 1; - din_lvl = BSP_DIN_LOW; - - exp_out = 1; - exp_btn.state = 1; - exp_btn.new_state = 1; - exp_btn.state_time = 0; - exp_btn.transition_cntr = 0; - exp_btn.dbnc_active = 0; - exp_din_ch = BSP_DIN7; - - test_res = ut_btn_ch_process(btn_ch, &btn, din_lvl, exp_out, &exp_btn, exp_din_ch); - if(!test_res) pass = 0; - - // Mapping check 6N - btn_ch = BTN_6N; - btn.state = 0; - btn.new_state = 0; - btn.state_time = 150; - btn.transition_cntr = 9; - btn.dbnc_active = 1; - din_lvl = BSP_DIN_LOW; - - exp_out = 1; - exp_btn.state = 1; - exp_btn.new_state = 1; - exp_btn.state_time = 0; - exp_btn.transition_cntr = 0; - exp_btn.dbnc_active = 0; - exp_din_ch = BSP_DIN7N; - - test_res = ut_btn_ch_process(btn_ch, &btn, din_lvl, exp_out, &exp_btn, exp_din_ch); - if(!test_res) pass = 0; - - // Wrong channel - btn_ch = 0; - btn.state = 1; - btn.new_state = 0; - btn.state_time = 150; - btn.transition_cntr = 9; - btn.dbnc_active = 1; - din_lvl = BSP_DIN_LOW; - - exp_out = 0; - exp_btn.state = 1; - exp_btn.new_state = 0; - exp_btn.state_time = 150; - exp_btn.transition_cntr = 9; - exp_btn.dbnc_active = 1; - exp_din_ch = NOT_ACCESED_DIN_CH; - - test_res = ut_btn_ch_process(btn_ch, &btn, din_lvl, exp_out, &exp_btn, exp_din_ch); - if(!test_res) pass = 0; - - return pass; -} - -static int ut_btn_ch_set_pull(uint8_t btn_ch, int8_t lvl, int8_t exp_dout_lvl, uint8_t exp_dout_ch) -{ - printf(" Input: Btn-Ch:%d Din-Lvl:%d\n", btn_ch, lvl); - - mock_board_dout_write_ch(NOT_ACCESED_DOUT_CH); - mock_board_dout_write_data(exp_dout_ch, NOT_ACCESED_DOUT_LVL); - - btn_ch_set_pull(btn_ch, lvl); - - uint8_t dout_ch = mock_board_dout_read_ch(); - int8_t dout = mock_board_dout_read_data(exp_dout_ch); - - printf(" Output: Dout-Ch:%d Dout-Lvl:%d \n", dout_ch, dout); - printf("Expected: Dout-Ch:%d Dout-Lvl:%d \n", exp_dout_ch, exp_dout_lvl); - - if((dout==exp_dout_lvl)&&(dout_ch==exp_dout_ch)) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_btn_ch_set_pull_test(void) -{ - printf("******************************************************\n"); - printf("void btn_ch_set_pull(uint8_t btn_ch, int8_t lvl) \n"); - - int test_res; - int pass = 1; - - uint8_t btn_ch; - int8_t lvl; - int8_t exp_dout_lvl; - uint8_t exp_dout_ch; - - // Mapping check 1 - btn_ch = BTN_6; - lvl = 0; - exp_dout_lvl = BSP_DOUT_LOW; - exp_dout_ch = BSP_DOUT5; - test_res = ut_btn_ch_set_pull(btn_ch, lvl, exp_dout_lvl, exp_dout_ch); - if(!test_res) pass = 0; - - // Mapping check 2 - btn_ch = BTN_6N; - lvl = 1; - exp_dout_lvl = BSP_DOUT_HIGH; - exp_dout_ch = BSP_DOUT5; - test_res = ut_btn_ch_set_pull(btn_ch, lvl, exp_dout_lvl, exp_dout_ch); - if(!test_res) pass = 0; - - // Define check 1 - btn_ch = BTN_6N; - lvl = BTN_PULL_LOW; - exp_dout_lvl = BSP_DOUT_LOW; - exp_dout_ch = BSP_DOUT5; - test_res = ut_btn_ch_set_pull(btn_ch, lvl, exp_dout_lvl, exp_dout_ch); - if(!test_res) pass = 0; - - // Define check 2 - btn_ch = BTN_6N; - lvl = BTN_PULL_HIGH; - exp_dout_lvl = BSP_DOUT_HIGH; - exp_dout_ch = BSP_DOUT5; - test_res = ut_btn_ch_set_pull(btn_ch, lvl, exp_dout_lvl, exp_dout_ch); - if(!test_res) pass = 0; - - // Define check 3 - btn_ch = BTN_6N; - lvl = BTN_PULL_NONE; - exp_dout_lvl = BSP_DOUT_HIZ; - exp_dout_ch = BSP_DOUT5; - test_res = ut_btn_ch_set_pull(btn_ch, lvl, exp_dout_lvl, exp_dout_ch); - if(!test_res) pass = 0; - - // Wrong channel - btn_ch = 0; - lvl = 0; - exp_dout_lvl = NOT_ACCESED_DOUT_LVL; - exp_dout_ch = NOT_ACCESED_DOUT_CH; - test_res = ut_btn_ch_set_pull(btn_ch, lvl, exp_dout_lvl, exp_dout_ch); - if(!test_res) pass = 0; - - return pass; -} diff --git a/firmware/tests/ut_hw/ut_buttons.h b/firmware/tests/ut_hw/ut_buttons.h deleted file mode 100644 index dfc509d..0000000 --- a/firmware/tests/ut_hw/ut_buttons.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef UT_HW_BUTTONS_H_ -#define UT_HW_BUTTONS_H_ - -#include -#include - -int ut_btn_reset_test(void); -int ut_btn_process_test(void); -int ut_btn_ch_process_test(void); -int ut_btn_ch_set_pull_test(void); - -#endif /* UT_HW_BUTTONS_H_ */ diff --git a/firmware/tests/ut_hw/ut_hb_control.c b/firmware/tests/ut_hw/ut_hb_control.c deleted file mode 100644 index 8092595..0000000 --- a/firmware/tests/ut_hw/ut_hb_control.c +++ /dev/null @@ -1,2638 +0,0 @@ -#include "ut_hb_control.h" - -#include "..\mock_board\mock_board_halfbridge.h" - -#include "..\..\src\hw\hb_control.h" - -static void print_fb_struct(hb_feedback_t* f1) -{ - printf("Sup-U:%d Sup-I:%d Sup-P:%d \n", f1->analog.sup_voltage, f1->analog.sup_current, f1->analog.sup_power); - printf("Out-U:%d Out-I:%d Out-P:%d Out-Z:%d \n", f1->analog.out_voltage, f1->analog.out_current, f1->analog.out_power, f1->analog.out_impedance); - printf("Low:%d PWM:%d \n", f1->analog.low_side_ctrl, f1->analog.pwm); - printf("Enabled:%d Warnin:%d Fault:%d Fused:%d \n", f1->enabled, f1->warning_act, f1->fault_act, f1->fused); - printf("Sup-UVP:%d Sup-OVP:%d Sup-OCP:%d Sup-OPP:%d \n", f1->warnings.sup_uvp, f1->warnings.sup_ovp, f1->warnings.sup_ocp, f1->warnings.sup_opp); - printf("Out-OVP:%d Out-OCP:%d Out-OPP:%d Out-Short:%d Out-Open:%d \n", f1->warnings.out_ovp, f1->warnings.out_ocp, f1->warnings.out_opp, f1->warnings.out_short, f1->warnings.out_open); - printf("Sup-UVP:%d Sup-OVP:%d Sup-OCP:%d Sup-OPP:%d \n", f1->faults.sup_uvp, f1->faults.sup_ovp, f1->faults.sup_ocp, f1->faults.sup_opp); - printf("Out-OVP:%d Out-OCP:%d Out-OPP:%d Out-Short:%d Out-Open:%d \n", f1->faults.out_ovp, f1->faults.out_ocp, f1->faults.out_opp, f1->faults.out_short, f1->faults.out_open); -} - -static void print_ctrl_struct(hb_control_t* c1) -{ - printf("Enabled:%d \n", c1->enabled); - printf("Sup UVP: Sev:%d W-time:%d F-time:%d \n", c1->out_faults.sup_uvp.severity, c1->out_faults.sup_uvp.w_time, c1->out_faults.sup_uvp.f_time); - printf("Sup OVP: Sev:%d W-time:%d F-time:%d \n", c1->out_faults.sup_ovp.severity, c1->out_faults.sup_ovp.w_time, c1->out_faults.sup_ovp.f_time); - printf("Sup OCP: Sev:%d W-time:%d F-time:%d \n", c1->out_faults.sup_ocp.severity, c1->out_faults.sup_ocp.w_time, c1->out_faults.sup_ocp.f_time); - printf("Sup OPP: Sev:%d W-time:%d F-time:%d \n", c1->out_faults.sup_opp.severity, c1->out_faults.sup_opp.w_time, c1->out_faults.sup_opp.f_time); - printf("Out OVP: Sev:%d W-time:%d F-time:%d \n", c1->out_faults.out_ovp.severity, c1->out_faults.out_ovp.w_time, c1->out_faults.out_ovp.f_time); - printf("Out OCP: Sev:%d W-time:%d F-time:%d \n", c1->out_faults.out_ocp.severity, c1->out_faults.out_ocp.w_time, c1->out_faults.out_ocp.f_time); - printf("Out OPP: Sev:%d W-time:%d F-time:%d \n", c1->out_faults.out_opp.severity, c1->out_faults.out_opp.w_time, c1->out_faults.out_opp.f_time); - printf("Out Short: Sev:%d W-time:%d F-time:%d \n", c1->out_faults.out_short.severity, c1->out_faults.out_short.w_time, c1->out_faults.out_short.f_time); - printf("Out Open: Sev:%d W-time:%d F-time:%d \n", c1->out_faults.out_open.severity, c1->out_faults.out_open.w_time, c1->out_faults.out_open.f_time); - printf("EN-Sup-uvp:%d EN-Sup-ovp:%d EN-Sup-ocp:%d EN-Sup-opp:%d \n", c1->out_faults_en.sup_uvp, c1->out_faults_en.sup_ovp, c1->out_faults_en.sup_ocp, c1->out_faults_en.sup_opp); - printf("EN-Out-ovp:%d EN-Out-ocp:%d EN-Out-opp:%d EN-Out-open:%d EN-Out-short:%d \n", c1->out_faults_en.out_ovp, c1->out_faults_en.out_ocp, c1->out_faults_en.out_opp, c1->out_faults_en.out_open, c1->out_faults_en.out_short); - printf("Fuse: state:%d count:%d timer:%d \n", c1->out_fuse.state, c1->out_fuse.count, c1->out_fuse.timer); - printf("Fuse-Cfg: cooldown:%d Retry-time:%d \n", c1->out_fuse_cfg.cooldown_time, c1->out_fuse_cfg.retry_time); -} - -static int ut_hb_is_equal_fb_struct(hb_feedback_t* f1, hb_feedback_t* f2, uint8_t exp_out, hb_feedback_t* exp_f1, hb_feedback_t* exp_f2) -{ - uint8_t out = hb_is_equal_fb_struct(f1, f2); - - int f1_equal = 1; - if(f1->analog.out_voltage != exp_f1->analog.out_voltage ) f1_equal=0; - if(f1->analog.out_current != exp_f1->analog.out_current ) f1_equal= 0; - if(f1->analog.sup_voltage != exp_f1->analog.sup_voltage ) f1_equal= 0; - if(f1->analog.sup_current != exp_f1->analog.sup_current ) f1_equal= 0; - if(f1->analog.out_power != exp_f1->analog.out_power ) f1_equal= 0; - if(f1->analog.sup_power != exp_f1->analog.sup_power ) f1_equal= 0; - if(f1->analog.out_impedance != exp_f1->analog.out_impedance ) f1_equal= 0; - if(f1->analog.low_side_ctrl != exp_f1->analog.low_side_ctrl ) f1_equal= 0; - if(f1->analog.pwm != exp_f1->analog.pwm ) f1_equal= 0; - if(f1->enabled != exp_f1->enabled ) f1_equal= 0; - if(f1->warning_act != exp_f1->warning_act ) f1_equal= 0; - if(f1->fault_act != exp_f1->fault_act ) f1_equal= 0; - if(f1->fused != exp_f1->fused ) f1_equal= 0; - if(f1->warnings.sup_uvp != exp_f1->warnings.sup_uvp ) f1_equal= 0; - if(f1->warnings.sup_ovp != exp_f1->warnings.sup_ovp ) f1_equal= 0; - if(f1->warnings.sup_ocp != exp_f1->warnings.sup_ocp ) f1_equal= 0; - if(f1->warnings.sup_opp != exp_f1->warnings.sup_opp ) f1_equal= 0; - if(f1->warnings.out_ovp != exp_f1->warnings.out_ovp ) f1_equal= 0; - if(f1->warnings.out_ocp != exp_f1->warnings.out_ocp ) f1_equal= 0; - if(f1->warnings.out_opp != exp_f1->warnings.out_opp ) f1_equal= 0; - if(f1->warnings.out_short != exp_f1->warnings.out_short ) f1_equal= 0; - if(f1->warnings.out_open != exp_f1->warnings.out_open ) f1_equal= 0; - if(f1->faults.sup_uvp != exp_f1->faults.sup_uvp ) f1_equal= 0; - if(f1->faults.sup_ovp != exp_f1->faults.sup_ovp ) f1_equal= 0; - if(f1->faults.sup_ocp != exp_f1->faults.sup_ocp ) f1_equal= 0; - if(f1->faults.sup_opp != exp_f1->faults.sup_opp ) f1_equal= 0; - if(f1->faults.out_ovp != exp_f1->faults.out_ovp ) f1_equal= 0; - if(f1->faults.out_ocp != exp_f1->faults.out_ocp ) f1_equal= 0; - if(f1->faults.out_opp != exp_f1->faults.out_opp ) f1_equal= 0; - if(f1->faults.out_short != exp_f1->faults.out_short ) f1_equal= 0; - if(f1->faults.out_open != exp_f1->faults.out_open ) f1_equal= 0; - - int f2_equal = 1; - if(f2->analog.out_voltage != exp_f2->analog.out_voltage ) f2_equal=0; - if(f2->analog.out_current != exp_f2->analog.out_current ) f2_equal= 0; - if(f2->analog.sup_voltage != exp_f2->analog.sup_voltage ) f2_equal= 0; - if(f2->analog.sup_current != exp_f2->analog.sup_current ) f2_equal= 0; - if(f2->analog.out_power != exp_f2->analog.out_power ) f2_equal= 0; - if(f2->analog.sup_power != exp_f2->analog.sup_power ) f2_equal= 0; - if(f2->analog.out_impedance != exp_f2->analog.out_impedance ) f2_equal= 0; - if(f2->analog.low_side_ctrl != exp_f2->analog.low_side_ctrl ) f2_equal= 0; - if(f2->analog.pwm != exp_f2->analog.pwm ) f2_equal= 0; - if(f2->enabled != exp_f2->enabled ) f2_equal= 0; - if(f2->warning_act != exp_f2->warning_act ) f2_equal= 0; - if(f2->fault_act != exp_f2->fault_act ) f2_equal= 0; - if(f2->fused != exp_f2->fused ) f2_equal= 0; - if(f2->warnings.sup_uvp != exp_f2->warnings.sup_uvp ) f2_equal= 0; - if(f2->warnings.sup_ovp != exp_f2->warnings.sup_ovp ) f2_equal= 0; - if(f2->warnings.sup_ocp != exp_f2->warnings.sup_ocp ) f2_equal= 0; - if(f2->warnings.sup_opp != exp_f2->warnings.sup_opp ) f2_equal= 0; - if(f2->warnings.out_ovp != exp_f2->warnings.out_ovp ) f2_equal= 0; - if(f2->warnings.out_ocp != exp_f2->warnings.out_ocp ) f2_equal= 0; - if(f2->warnings.out_opp != exp_f2->warnings.out_opp ) f2_equal= 0; - if(f2->warnings.out_short != exp_f2->warnings.out_short ) f2_equal= 0; - if(f2->warnings.out_open != exp_f2->warnings.out_open ) f2_equal= 0; - if(f2->faults.sup_uvp != exp_f2->faults.sup_uvp ) f2_equal= 0; - if(f2->faults.sup_ovp != exp_f2->faults.sup_ovp ) f2_equal= 0; - if(f2->faults.sup_ocp != exp_f2->faults.sup_ocp ) f2_equal= 0; - if(f2->faults.sup_opp != exp_f2->faults.sup_opp ) f2_equal= 0; - if(f2->faults.out_ovp != exp_f2->faults.out_ovp ) f2_equal= 0; - if(f2->faults.out_ocp != exp_f2->faults.out_ocp ) f2_equal= 0; - if(f2->faults.out_opp != exp_f2->faults.out_opp ) f2_equal= 0; - if(f2->faults.out_short != exp_f2->faults.out_short ) f2_equal= 0; - if(f2->faults.out_open != exp_f2->faults.out_open ) f2_equal= 0; - - printf("f1-unchanged:%d f2-unchanged:%d \n", f1_equal, f2_equal); - printf(" Output: %d \n", out); - printf("Expected: %d \n", exp_out); - - if((out==exp_out)&&(f1_equal)&&(f2_equal)) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_hb_is_equal_fb_struct_test(void) -{ - printf("******************************************************\n"); - printf("uint8_t hb_is_equal_fb_struct(hb_feedback_t* f1, hb_feedback_t* f2) \n"); - - int test_res; - int pass = 1; - - hb_feedback_t f1; - hb_feedback_t f2; - - uint8_t exp_out; - hb_feedback_t exp_f1; - hb_feedback_t exp_f2; - - // EQUAL - f1.analog.out_voltage = 0xAAAA; - f1.analog.out_current = 0xAAAA; - f1.analog.sup_voltage = 0xAAAA; - f1.analog.sup_current = 0xAAAA; - f1.analog.out_power = 0xAAAA; - f1.analog.sup_power = 0xAAAA; - f1.analog.out_impedance = 0xAAAA; - f1.analog.low_side_ctrl = 0xAA; - f1.analog.pwm = 0xAAAA; - f1.enabled = 0xAA; - f1.warning_act = 0xAA; - f1.fault_act = 0xAA; - f1.fused = 0xAA; - f1.warnings.sup_uvp = 0xAA; - f1.warnings.sup_ovp = 0xAA; - f1.warnings.sup_ocp = 0xAA; - f1.warnings.sup_opp = 0xAA; - f1.warnings.out_ovp = 0xAA; - f1.warnings.out_ocp = 0xAA; - f1.warnings.out_opp = 0xAA; - f1.warnings.out_short = 0xAA; - f1.warnings.out_open = 0xAA; - f1.faults.sup_uvp = 0xAA; - f1.faults.sup_ovp = 0xAA; - f1.faults.sup_ocp = 0xAA; - f1.faults.sup_opp = 0xAA; - f1.faults.out_ovp = 0xAA; - f1.faults.out_ocp = 0xAA; - f1.faults.out_opp = 0xAA; - f1.faults.out_short = 0xAA; - f1.faults.out_open = 0xAA; - - f2.analog.out_voltage = 0xAAAA; - f2.analog.out_current = 0xAAAA; - f2.analog.sup_voltage = 0xAAAA; - f2.analog.sup_current = 0xAAAA; - f2.analog.out_power = 0xAAAA; - f2.analog.sup_power = 0xAAAA; - f2.analog.out_impedance = 0xAAAA; - f2.analog.low_side_ctrl = 0xAA; - f2.analog.pwm = 0xAAAA; - f2.enabled = 0xAA; - f2.warning_act = 0xAA; - f2.fault_act = 0xAA; - f2.fused = 0xAA; - f2.warnings.sup_uvp = 0xAA; - f2.warnings.sup_ovp = 0xAA; - f2.warnings.sup_ocp = 0xAA; - f2.warnings.sup_opp = 0xAA; - f2.warnings.out_ovp = 0xAA; - f2.warnings.out_ocp = 0xAA; - f2.warnings.out_opp = 0xAA; - f2.warnings.out_short = 0xAA; - f2.warnings.out_open = 0xAA; - f2.faults.sup_uvp = 0xAA; - f2.faults.sup_ovp = 0xAA; - f2.faults.sup_ocp = 0xAA; - f2.faults.sup_opp = 0xAA; - f2.faults.out_ovp = 0xAA; - f2.faults.out_ocp = 0xAA; - f2.faults.out_opp = 0xAA; - f2.faults.out_short = 0xAA; - f2.faults.out_open = 0xAA; - - exp_out = 1; - - exp_f1.analog.out_voltage = f1.analog.out_voltage; - exp_f1.analog.out_current = f1.analog.out_current; - exp_f1.analog.sup_voltage = f1.analog.sup_voltage; - exp_f1.analog.sup_current = f1.analog.sup_current; - exp_f1.analog.out_power = f1.analog.out_power; - exp_f1.analog.sup_power = f1.analog.sup_power; - exp_f1.analog.out_impedance = f1.analog.out_impedance; - exp_f1.analog.low_side_ctrl = f1.analog.low_side_ctrl; - exp_f1.analog.pwm = f1.analog.pwm; - exp_f1.enabled = f1.enabled; - exp_f1.warning_act = f1.warning_act; - exp_f1.fault_act = f1.fault_act; - exp_f1.fused = f1.fused; - exp_f1.warnings.sup_uvp = f1.warnings.sup_uvp; - exp_f1.warnings.sup_ovp = f1.warnings.sup_ovp; - exp_f1.warnings.sup_ocp = f1.warnings.sup_ocp; - exp_f1.warnings.sup_opp = f1.warnings.sup_opp; - exp_f1.warnings.out_ovp = f1.warnings.out_ovp; - exp_f1.warnings.out_ocp = f1.warnings.out_ocp; - exp_f1.warnings.out_opp = f1.warnings.out_opp; - exp_f1.warnings.out_short = f1.warnings.out_short; - exp_f1.warnings.out_open = f1.warnings.out_open; - exp_f1.faults.sup_uvp = f1.faults.sup_uvp; - exp_f1.faults.sup_ovp = f1.faults.sup_ovp; - exp_f1.faults.sup_ocp = f1.faults.sup_ocp; - exp_f1.faults.sup_opp = f1.faults.sup_opp; - exp_f1.faults.out_ovp = f1.faults.out_ovp; - exp_f1.faults.out_ocp = f1.faults.out_ocp; - exp_f1.faults.out_opp = f1.faults.out_opp; - exp_f1.faults.out_short = f1.faults.out_short; - exp_f1.faults.out_open = f1.faults.out_open; - - exp_f2.analog.out_voltage = f2.analog.out_voltage; - exp_f2.analog.out_current = f2.analog.out_current; - exp_f2.analog.sup_voltage = f2.analog.sup_voltage; - exp_f2.analog.sup_current = f2.analog.sup_current; - exp_f2.analog.out_power = f2.analog.out_power; - exp_f2.analog.sup_power = f2.analog.sup_power; - exp_f2.analog.out_impedance = f2.analog.out_impedance; - exp_f2.analog.low_side_ctrl = f2.analog.low_side_ctrl; - exp_f2.analog.pwm = f2.analog.pwm; - exp_f2.enabled = f2.enabled; - exp_f2.warning_act = f2.warning_act; - exp_f2.fault_act = f2.fault_act; - exp_f2.fused = f2.fused; - exp_f2.warnings.sup_uvp = f2.warnings.sup_uvp; - exp_f2.warnings.sup_ovp = f2.warnings.sup_ovp; - exp_f2.warnings.sup_ocp = f2.warnings.sup_ocp; - exp_f2.warnings.sup_opp = f2.warnings.sup_opp; - exp_f2.warnings.out_ovp = f2.warnings.out_ovp; - exp_f2.warnings.out_ocp = f2.warnings.out_ocp; - exp_f2.warnings.out_opp = f2.warnings.out_opp; - exp_f2.warnings.out_short = f2.warnings.out_short; - exp_f2.warnings.out_open = f2.warnings.out_open; - exp_f2.faults.sup_uvp = f2.faults.sup_uvp; - exp_f2.faults.sup_ovp = f2.faults.sup_ovp; - exp_f2.faults.sup_ocp = f2.faults.sup_ocp; - exp_f2.faults.sup_opp = f2.faults.sup_opp; - exp_f2.faults.out_ovp = f2.faults.out_ovp; - exp_f2.faults.out_ocp = f2.faults.out_ocp; - exp_f2.faults.out_opp = f2.faults.out_opp; - exp_f2.faults.out_short = f2.faults.out_short; - exp_f2.faults.out_open = f2.faults.out_open; - - test_res = ut_hb_is_equal_fb_struct(&f1, &f2, exp_out, &exp_f1, &exp_f2); - if(!test_res) pass = 0; - - // NOT EQUAL - f1.analog.out_voltage = 0xAAAA; - f1.analog.out_current = 0xAAAA; - f1.analog.sup_voltage = 0xAAAA; - f1.analog.sup_current = 0xAAAA; - f1.analog.out_power = 0xAAAA; - f1.analog.sup_power = 0xAAAA; - f1.analog.out_impedance = 0xAAAA; - f1.analog.low_side_ctrl = 0xAA; - f1.analog.pwm = 0xAAAA; - f1.enabled = 0xAA; - f1.warning_act = 0xAA; - f1.fault_act = 0xAA; - f1.fused = 0xAA; - f1.warnings.sup_uvp = 0xAA; - f1.warnings.sup_ovp = 0xAA; - f1.warnings.sup_ocp = 0xAA; - f1.warnings.sup_opp = 0xAA; - f1.warnings.out_ovp = 0xAA; - f1.warnings.out_ocp = 0xAA; - f1.warnings.out_opp = 0xAA; - f1.warnings.out_short = 0xAA; - f1.warnings.out_open = 0xAA; - f1.faults.sup_uvp = 0xAA; - f1.faults.sup_ovp = 0xAA; - f1.faults.sup_ocp = 0xAA; - f1.faults.sup_opp = 0xAA; - f1.faults.out_ovp = 0xAA; - f1.faults.out_ocp = 0xAA; - f1.faults.out_opp = 0xAA; - f1.faults.out_short = 0xAA; - f1.faults.out_open = 0xAA; - - f2.analog.out_voltage = 0x5555; - f2.analog.out_current = 0x5555; - f2.analog.sup_voltage = 0x5555; - f2.analog.sup_current = 0x5555; - f2.analog.out_power = 0x5555; - f2.analog.sup_power = 0x5555; - f2.analog.out_impedance = 0x5555; - f2.analog.low_side_ctrl = 0x55; - f2.analog.pwm = 0x5555; - f2.enabled = 0x55; - f2.warning_act = 0x55; - f2.fault_act = 0x55; - f2.fused = 0x55; - f2.warnings.sup_uvp = 0x55; - f2.warnings.sup_ovp = 0x55; - f2.warnings.sup_ocp = 0x55; - f2.warnings.sup_opp = 0x55; - f2.warnings.out_ovp = 0x55; - f2.warnings.out_ocp = 0x55; - f2.warnings.out_opp = 0x55; - f2.warnings.out_short = 0x55; - f2.warnings.out_open = 0x55; - f2.faults.sup_uvp = 0x55; - f2.faults.sup_ovp = 0x55; - f2.faults.sup_ocp = 0x55; - f2.faults.sup_opp = 0x55; - f2.faults.out_ovp = 0x55; - f2.faults.out_ocp = 0x55; - f2.faults.out_opp = 0x55; - f2.faults.out_short = 0x55; - f2.faults.out_open = 0x55; - - exp_out = 0; - - exp_f1.analog.out_voltage = f1.analog.out_voltage; - exp_f1.analog.out_current = f1.analog.out_current; - exp_f1.analog.sup_voltage = f1.analog.sup_voltage; - exp_f1.analog.sup_current = f1.analog.sup_current; - exp_f1.analog.out_power = f1.analog.out_power; - exp_f1.analog.sup_power = f1.analog.sup_power; - exp_f1.analog.out_impedance = f1.analog.out_impedance; - exp_f1.analog.low_side_ctrl = f1.analog.low_side_ctrl; - exp_f1.analog.pwm = f1.analog.pwm; - exp_f1.enabled = f1.enabled; - exp_f1.warning_act = f1.warning_act; - exp_f1.fault_act = f1.fault_act; - exp_f1.fused = f1.fused; - exp_f1.warnings.sup_uvp = f1.warnings.sup_uvp; - exp_f1.warnings.sup_ovp = f1.warnings.sup_ovp; - exp_f1.warnings.sup_ocp = f1.warnings.sup_ocp; - exp_f1.warnings.sup_opp = f1.warnings.sup_opp; - exp_f1.warnings.out_ovp = f1.warnings.out_ovp; - exp_f1.warnings.out_ocp = f1.warnings.out_ocp; - exp_f1.warnings.out_opp = f1.warnings.out_opp; - exp_f1.warnings.out_short = f1.warnings.out_short; - exp_f1.warnings.out_open = f1.warnings.out_open; - exp_f1.faults.sup_uvp = f1.faults.sup_uvp; - exp_f1.faults.sup_ovp = f1.faults.sup_ovp; - exp_f1.faults.sup_ocp = f1.faults.sup_ocp; - exp_f1.faults.sup_opp = f1.faults.sup_opp; - exp_f1.faults.out_ovp = f1.faults.out_ovp; - exp_f1.faults.out_ocp = f1.faults.out_ocp; - exp_f1.faults.out_opp = f1.faults.out_opp; - exp_f1.faults.out_short = f1.faults.out_short; - exp_f1.faults.out_open = f1.faults.out_open; - - exp_f2.analog.out_voltage = f2.analog.out_voltage; - exp_f2.analog.out_current = f2.analog.out_current; - exp_f2.analog.sup_voltage = f2.analog.sup_voltage; - exp_f2.analog.sup_current = f2.analog.sup_current; - exp_f2.analog.out_power = f2.analog.out_power; - exp_f2.analog.sup_power = f2.analog.sup_power; - exp_f2.analog.out_impedance = f2.analog.out_impedance; - exp_f2.analog.low_side_ctrl = f2.analog.low_side_ctrl; - exp_f2.analog.pwm = f2.analog.pwm; - exp_f2.enabled = f2.enabled; - exp_f2.warning_act = f2.warning_act; - exp_f2.fault_act = f2.fault_act; - exp_f2.fused = f2.fused; - exp_f2.warnings.sup_uvp = f2.warnings.sup_uvp; - exp_f2.warnings.sup_ovp = f2.warnings.sup_ovp; - exp_f2.warnings.sup_ocp = f2.warnings.sup_ocp; - exp_f2.warnings.sup_opp = f2.warnings.sup_opp; - exp_f2.warnings.out_ovp = f2.warnings.out_ovp; - exp_f2.warnings.out_ocp = f2.warnings.out_ocp; - exp_f2.warnings.out_opp = f2.warnings.out_opp; - exp_f2.warnings.out_short = f2.warnings.out_short; - exp_f2.warnings.out_open = f2.warnings.out_open; - exp_f2.faults.sup_uvp = f2.faults.sup_uvp; - exp_f2.faults.sup_ovp = f2.faults.sup_ovp; - exp_f2.faults.sup_ocp = f2.faults.sup_ocp; - exp_f2.faults.sup_opp = f2.faults.sup_opp; - exp_f2.faults.out_ovp = f2.faults.out_ovp; - exp_f2.faults.out_ocp = f2.faults.out_ocp; - exp_f2.faults.out_opp = f2.faults.out_opp; - exp_f2.faults.out_short = f2.faults.out_short; - exp_f2.faults.out_open = f2.faults.out_open; - - test_res = ut_hb_is_equal_fb_struct(&f1, &f2, exp_out, &exp_f1, &exp_f2); - if(!test_res) pass = 0; - - return pass; -} - -static int ut_hb_is_equal_ctrl_struct(hb_control_t* c1, hb_control_t* c2, uint8_t exp_out, hb_control_t* exp_c1, hb_control_t* exp_c2) -{ - uint8_t out = hb_is_equal_ctrl_struct(c1, c2); - - int c1_equal = 1; - if(c1->enabled != exp_c1->enabled ) c1_equal = 0; - if(c1->out_faults.sup_uvp.severity != exp_c1->out_faults.sup_uvp.severity ) c1_equal = 0; - if(c1->out_faults.sup_uvp.w_time != exp_c1->out_faults.sup_uvp.w_time ) c1_equal = 0; - if(c1->out_faults.sup_uvp.f_time != exp_c1->out_faults.sup_uvp.f_time ) c1_equal = 0; - if(c1->out_faults.sup_ovp.severity != exp_c1->out_faults.sup_ovp.severity ) c1_equal = 0; - if(c1->out_faults.sup_ovp.w_time != exp_c1->out_faults.sup_ovp.w_time ) c1_equal = 0; - if(c1->out_faults.sup_ovp.f_time != exp_c1->out_faults.sup_ovp.f_time ) c1_equal = 0; - if(c1->out_faults.sup_ocp.severity != exp_c1->out_faults.sup_ocp.severity ) c1_equal = 0; - if(c1->out_faults.sup_ocp.w_time != exp_c1->out_faults.sup_ocp.w_time ) c1_equal = 0; - if(c1->out_faults.sup_ocp.f_time != exp_c1->out_faults.sup_ocp.f_time ) c1_equal = 0; - if(c1->out_faults.sup_opp.severity != exp_c1->out_faults.sup_opp.severity ) c1_equal = 0; - if(c1->out_faults.sup_opp.w_time != exp_c1->out_faults.sup_opp.w_time ) c1_equal = 0; - if(c1->out_faults.sup_opp.f_time != exp_c1->out_faults.sup_opp.f_time ) c1_equal = 0; - if(c1->out_faults.out_ovp.severity != exp_c1->out_faults.out_ovp.severity ) c1_equal = 0; - if(c1->out_faults.out_ovp.w_time != exp_c1->out_faults.out_ovp.w_time ) c1_equal = 0; - if(c1->out_faults.out_ovp.f_time != exp_c1->out_faults.out_ovp.f_time ) c1_equal = 0; - if(c1->out_faults.out_ocp.severity != exp_c1->out_faults.out_ocp.severity ) c1_equal = 0; - if(c1->out_faults.out_ocp.w_time != exp_c1->out_faults.out_ocp.w_time ) c1_equal = 0; - if(c1->out_faults.out_ocp.f_time != exp_c1->out_faults.out_ocp.f_time ) c1_equal = 0; - if(c1->out_faults.out_opp.severity != exp_c1->out_faults.out_opp.severity ) c1_equal = 0; - if(c1->out_faults.out_opp.w_time != exp_c1->out_faults.out_opp.w_time ) c1_equal = 0; - if(c1->out_faults.out_opp.f_time != exp_c1->out_faults.out_opp.f_time ) c1_equal = 0; - if(c1->out_faults.out_short.severity != exp_c1->out_faults.out_short.severity ) c1_equal = 0; - if(c1->out_faults.out_short.w_time != exp_c1->out_faults.out_short.w_time ) c1_equal = 0; - if(c1->out_faults.out_short.f_time != exp_c1->out_faults.out_short.f_time ) c1_equal = 0; - if(c1->out_faults.out_open.severity != exp_c1->out_faults.out_open.severity ) c1_equal = 0; - if(c1->out_faults.out_open.w_time != exp_c1->out_faults.out_open.w_time ) c1_equal = 0; - if(c1->out_faults.out_open.f_time != exp_c1->out_faults.out_open.f_time ) c1_equal = 0; - if(c1->out_faults_en.sup_uvp != exp_c1->out_faults_en.sup_uvp ) c1_equal = 0; - if(c1->out_faults_en.sup_ovp != exp_c1->out_faults_en.sup_ovp ) c1_equal = 0; - if(c1->out_faults_en.sup_ocp != exp_c1->out_faults_en.sup_ocp ) c1_equal = 0; - if(c1->out_faults_en.sup_opp != exp_c1->out_faults_en.sup_opp ) c1_equal = 0; - if(c1->out_faults_en.out_ovp != exp_c1->out_faults_en.out_ovp ) c1_equal = 0; - if(c1->out_faults_en.out_ocp != exp_c1->out_faults_en.out_ocp ) c1_equal = 0; - if(c1->out_faults_en.out_opp != exp_c1->out_faults_en.out_opp ) c1_equal = 0; - if(c1->out_faults_en.out_short != exp_c1->out_faults_en.out_short ) c1_equal = 0; - if(c1->out_faults_en.out_open != exp_c1->out_faults_en.out_open ) c1_equal = 0; - if(c1->out_fuse.state != exp_c1->out_fuse.state ) c1_equal = 0; - if(c1->out_fuse.count != exp_c1->out_fuse.count ) c1_equal = 0; - if(c1->out_fuse.timer != exp_c1->out_fuse.timer ) c1_equal = 0; - if(c1->out_fuse_cfg.cooldown_time != exp_c1->out_fuse_cfg.cooldown_time ) c1_equal = 0; - if(c1->out_fuse_cfg.retry_time != exp_c1->out_fuse_cfg.retry_time ) c1_equal = 0; - - int c2_equal = 1; - if(c2->enabled != exp_c2->enabled ) c2_equal = 0; - if(c2->out_faults.sup_uvp.severity != exp_c2->out_faults.sup_uvp.severity ) c2_equal = 0; - if(c2->out_faults.sup_uvp.w_time != exp_c2->out_faults.sup_uvp.w_time ) c2_equal = 0; - if(c2->out_faults.sup_uvp.f_time != exp_c2->out_faults.sup_uvp.f_time ) c2_equal = 0; - if(c2->out_faults.sup_ovp.severity != exp_c2->out_faults.sup_ovp.severity ) c2_equal = 0; - if(c2->out_faults.sup_ovp.w_time != exp_c2->out_faults.sup_ovp.w_time ) c2_equal = 0; - if(c2->out_faults.sup_ovp.f_time != exp_c2->out_faults.sup_ovp.f_time ) c2_equal = 0; - if(c2->out_faults.sup_ocp.severity != exp_c2->out_faults.sup_ocp.severity ) c2_equal = 0; - if(c2->out_faults.sup_ocp.w_time != exp_c2->out_faults.sup_ocp.w_time ) c2_equal = 0; - if(c2->out_faults.sup_ocp.f_time != exp_c2->out_faults.sup_ocp.f_time ) c2_equal = 0; - if(c2->out_faults.sup_opp.severity != exp_c2->out_faults.sup_opp.severity ) c2_equal = 0; - if(c2->out_faults.sup_opp.w_time != exp_c2->out_faults.sup_opp.w_time ) c2_equal = 0; - if(c2->out_faults.sup_opp.f_time != exp_c2->out_faults.sup_opp.f_time ) c2_equal = 0; - if(c2->out_faults.out_ovp.severity != exp_c2->out_faults.out_ovp.severity ) c2_equal = 0; - if(c2->out_faults.out_ovp.w_time != exp_c2->out_faults.out_ovp.w_time ) c2_equal = 0; - if(c2->out_faults.out_ovp.f_time != exp_c2->out_faults.out_ovp.f_time ) c2_equal = 0; - if(c2->out_faults.out_ocp.severity != exp_c2->out_faults.out_ocp.severity ) c2_equal = 0; - if(c2->out_faults.out_ocp.w_time != exp_c2->out_faults.out_ocp.w_time ) c2_equal = 0; - if(c2->out_faults.out_ocp.f_time != exp_c2->out_faults.out_ocp.f_time ) c2_equal = 0; - if(c2->out_faults.out_opp.severity != exp_c2->out_faults.out_opp.severity ) c2_equal = 0; - if(c2->out_faults.out_opp.w_time != exp_c2->out_faults.out_opp.w_time ) c2_equal = 0; - if(c2->out_faults.out_opp.f_time != exp_c2->out_faults.out_opp.f_time ) c2_equal = 0; - if(c2->out_faults.out_short.severity != exp_c2->out_faults.out_short.severity ) c2_equal = 0; - if(c2->out_faults.out_short.w_time != exp_c2->out_faults.out_short.w_time ) c2_equal = 0; - if(c2->out_faults.out_short.f_time != exp_c2->out_faults.out_short.f_time ) c2_equal = 0; - if(c2->out_faults.out_open.severity != exp_c2->out_faults.out_open.severity ) c2_equal = 0; - if(c2->out_faults.out_open.w_time != exp_c2->out_faults.out_open.w_time ) c2_equal = 0; - if(c2->out_faults.out_open.f_time != exp_c2->out_faults.out_open.f_time ) c2_equal = 0; - if(c2->out_faults_en.sup_uvp != exp_c2->out_faults_en.sup_uvp ) c2_equal = 0; - if(c2->out_faults_en.sup_ovp != exp_c2->out_faults_en.sup_ovp ) c2_equal = 0; - if(c2->out_faults_en.sup_ocp != exp_c2->out_faults_en.sup_ocp ) c2_equal = 0; - if(c2->out_faults_en.sup_opp != exp_c2->out_faults_en.sup_opp ) c2_equal = 0; - if(c2->out_faults_en.out_ovp != exp_c2->out_faults_en.out_ovp ) c2_equal = 0; - if(c2->out_faults_en.out_ocp != exp_c2->out_faults_en.out_ocp ) c2_equal = 0; - if(c2->out_faults_en.out_opp != exp_c2->out_faults_en.out_opp ) c2_equal = 0; - if(c2->out_faults_en.out_short != exp_c2->out_faults_en.out_short ) c2_equal = 0; - if(c2->out_faults_en.out_open != exp_c2->out_faults_en.out_open ) c2_equal = 0; - if(c2->out_fuse.state != exp_c2->out_fuse.state ) c2_equal = 0; - if(c2->out_fuse.count != exp_c2->out_fuse.count ) c2_equal = 0; - if(c2->out_fuse.timer != exp_c2->out_fuse.timer ) c2_equal = 0; - if(c2->out_fuse_cfg.cooldown_time != exp_c2->out_fuse_cfg.cooldown_time ) c2_equal = 0; - if(c2->out_fuse_cfg.retry_time != exp_c2->out_fuse_cfg.retry_time ) c2_equal = 0; - - printf("c1-unchanged:%d c2-unchanged:%d \n", c1_equal, c2_equal); - printf(" Output: %d \n", out); - printf("Expected: %d \n", exp_out); - - if((out==exp_out)&&(c1_equal)&&(c2_equal)) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_hb_is_equal_ctrl_struct_test(void) -{ - printf("******************************************************\n"); - printf("uint8_t hb_is_equal_ctrl_struct(hb_control_t* c1, hb_control_t* c2) \n"); - - int test_res; - int pass = 1; - - hb_control_t c1; - hb_control_t c2; - - uint8_t exp_out; - hb_control_t exp_c1; - hb_control_t exp_c2; - - // EQUAL - c1.enabled = 0xAA; - c1.out_faults.sup_uvp.severity = FAULT_LVL_FAULT; - c1.out_faults.sup_uvp.w_time = 0xAAAA; - c1.out_faults.sup_uvp.f_time = 0xAAAA; - c1.out_faults.sup_ovp.severity = FAULT_LVL_FAULT; - c1.out_faults.sup_ovp.w_time = 0xAAAA; - c1.out_faults.sup_ovp.f_time = 0xAAAA; - c1.out_faults.sup_ocp.severity = FAULT_LVL_FAULT; - c1.out_faults.sup_ocp.w_time = 0xAAAA; - c1.out_faults.sup_ocp.f_time = 0xAAAA; - c1.out_faults.sup_opp.severity = FAULT_LVL_FAULT; - c1.out_faults.sup_opp.w_time = 0xAAAA; - c1.out_faults.sup_opp.f_time = 0xAAAA; - c1.out_faults.out_ovp.severity = FAULT_LVL_FAULT; - c1.out_faults.out_ovp.w_time = 0xAAAA; - c1.out_faults.out_ovp.f_time = 0xAAAA; - c1.out_faults.out_ocp.severity = FAULT_LVL_FAULT; - c1.out_faults.out_ocp.w_time = 0xAAAA; - c1.out_faults.out_ocp.f_time = 0xAAAA; - c1.out_faults.out_opp.severity = FAULT_LVL_FAULT; - c1.out_faults.out_opp.w_time = 0xAAAA; - c1.out_faults.out_opp.f_time = 0xAAAA; - c1.out_faults.out_short.severity = FAULT_LVL_FAULT; - c1.out_faults.out_short.w_time = 0xAAAA; - c1.out_faults.out_short.f_time = 0xAAAA; - c1.out_faults.out_open.severity = FAULT_LVL_FAULT; - c1.out_faults.out_open.w_time = 0xAAAA; - c1.out_faults.out_open.f_time = 0xAAAA; - c1.out_faults_en.sup_uvp = 0xAA; - c1.out_faults_en.sup_ovp = 0xAA; - c1.out_faults_en.sup_ocp = 0xAA; - c1.out_faults_en.sup_opp = 0xAA; - c1.out_faults_en.out_ovp = 0xAA; - c1.out_faults_en.out_ocp = 0xAA; - c1.out_faults_en.out_opp = 0xAA; - c1.out_faults_en.out_open = 0xAA; - c1.out_faults_en.out_short = 0xAA; - c1.out_fuse.state = FUSE_ACTIVE; - c1.out_fuse.count = 0xAA; - c1.out_fuse.timer = 0xAAAA; - c1.out_fuse_cfg.cooldown_time = 0xAAAA; - c1.out_fuse_cfg.retry_time = 0xAAAA; - - c2.enabled = 0xAA; - c2.out_faults.sup_uvp.severity = FAULT_LVL_FAULT; - c2.out_faults.sup_uvp.w_time = 0xAAAA; - c2.out_faults.sup_uvp.f_time = 0xAAAA; - c2.out_faults.sup_ovp.severity = FAULT_LVL_FAULT; - c2.out_faults.sup_ovp.w_time = 0xAAAA; - c2.out_faults.sup_ovp.f_time = 0xAAAA; - c2.out_faults.sup_ocp.severity = FAULT_LVL_FAULT; - c2.out_faults.sup_ocp.w_time = 0xAAAA; - c2.out_faults.sup_ocp.f_time = 0xAAAA; - c2.out_faults.sup_opp.severity = FAULT_LVL_FAULT; - c2.out_faults.sup_opp.w_time = 0xAAAA; - c2.out_faults.sup_opp.f_time = 0xAAAA; - c2.out_faults.out_ovp.severity = FAULT_LVL_FAULT; - c2.out_faults.out_ovp.w_time = 0xAAAA; - c2.out_faults.out_ovp.f_time = 0xAAAA; - c2.out_faults.out_ocp.severity = FAULT_LVL_FAULT; - c2.out_faults.out_ocp.w_time = 0xAAAA; - c2.out_faults.out_ocp.f_time = 0xAAAA; - c2.out_faults.out_opp.severity = FAULT_LVL_FAULT; - c2.out_faults.out_opp.w_time = 0xAAAA; - c2.out_faults.out_opp.f_time = 0xAAAA; - c2.out_faults.out_short.severity = FAULT_LVL_FAULT; - c2.out_faults.out_short.w_time = 0xAAAA; - c2.out_faults.out_short.f_time = 0xAAAA; - c2.out_faults.out_open.severity = FAULT_LVL_FAULT; - c2.out_faults.out_open.w_time = 0xAAAA; - c2.out_faults.out_open.f_time = 0xAAAA; - c2.out_faults_en.sup_uvp = 0xAA; - c2.out_faults_en.sup_ovp = 0xAA; - c2.out_faults_en.sup_ocp = 0xAA; - c2.out_faults_en.sup_opp = 0xAA; - c2.out_faults_en.out_ovp = 0xAA; - c2.out_faults_en.out_ocp = 0xAA; - c2.out_faults_en.out_opp = 0xAA; - c2.out_faults_en.out_open = 0xAA; - c2.out_faults_en.out_short = 0xAA; - c2.out_fuse.state = FUSE_ACTIVE; - c2.out_fuse.count = 0xAA; - c2.out_fuse.timer = 0xAAAA; - c2.out_fuse_cfg.cooldown_time = 0xAAAA; - c2.out_fuse_cfg.retry_time = 0xAAAA; - - exp_out = 1; - - exp_c1.enabled = c1.enabled; - exp_c1.out_faults.sup_uvp.severity = c1.out_faults.sup_uvp.severity; - exp_c1.out_faults.sup_uvp.w_time = c1.out_faults.sup_uvp.w_time; - exp_c1.out_faults.sup_uvp.f_time = c1.out_faults.sup_uvp.f_time; - exp_c1.out_faults.sup_ovp.severity = c1.out_faults.sup_ovp.severity; - exp_c1.out_faults.sup_ovp.w_time = c1.out_faults.sup_ovp.w_time; - exp_c1.out_faults.sup_ovp.f_time = c1.out_faults.sup_ovp.f_time; - exp_c1.out_faults.sup_ocp.severity = c1.out_faults.sup_ocp.severity; - exp_c1.out_faults.sup_ocp.w_time = c1.out_faults.sup_ocp.w_time; - exp_c1.out_faults.sup_ocp.f_time = c1.out_faults.sup_ocp.f_time; - exp_c1.out_faults.sup_opp.severity = c1.out_faults.sup_opp.severity; - exp_c1.out_faults.sup_opp.w_time = c1.out_faults.sup_opp.w_time; - exp_c1.out_faults.sup_opp.f_time = c1.out_faults.sup_opp.f_time; - exp_c1.out_faults.out_ovp.severity = c1.out_faults.out_ovp.severity; - exp_c1.out_faults.out_ovp.w_time = c1.out_faults.out_ovp.w_time; - exp_c1.out_faults.out_ovp.f_time = c1.out_faults.out_ovp.f_time; - exp_c1.out_faults.out_ocp.severity = c1.out_faults.out_ocp.severity; - exp_c1.out_faults.out_ocp.w_time = c1.out_faults.out_ocp.w_time; - exp_c1.out_faults.out_ocp.f_time = c1.out_faults.out_ocp.f_time; - exp_c1.out_faults.out_opp.severity = c1.out_faults.out_opp.severity; - exp_c1.out_faults.out_opp.w_time = c1.out_faults.out_opp.w_time; - exp_c1.out_faults.out_opp.f_time = c1.out_faults.out_opp.f_time; - exp_c1.out_faults.out_short.severity = c1.out_faults.out_short.severity; - exp_c1.out_faults.out_short.w_time = c1.out_faults.out_short.w_time; - exp_c1.out_faults.out_short.f_time = c1.out_faults.out_short.f_time; - exp_c1.out_faults.out_open.severity = c1.out_faults.out_open.severity; - exp_c1.out_faults.out_open.w_time = c1.out_faults.out_open.w_time; - exp_c1.out_faults.out_open.f_time = c1.out_faults.out_open.f_time; - exp_c1.out_faults_en.sup_uvp = c1.out_faults_en.sup_uvp; - exp_c1.out_faults_en.sup_ovp = c1.out_faults_en.sup_ovp; - exp_c1.out_faults_en.sup_ocp = c1.out_faults_en.sup_ocp; - exp_c1.out_faults_en.sup_opp = c1.out_faults_en.sup_opp; - exp_c1.out_faults_en.out_ovp = c1.out_faults_en.out_ovp; - exp_c1.out_faults_en.out_ocp = c1.out_faults_en.out_ocp; - exp_c1.out_faults_en.out_opp = c1.out_faults_en.out_opp; - exp_c1.out_faults_en.out_open = c1.out_faults_en.out_open; - exp_c1.out_faults_en.out_short = c1.out_faults_en.out_short; - exp_c1.out_fuse.state = c1.out_fuse.state; - exp_c1.out_fuse.count = c1.out_fuse.count; - exp_c1.out_fuse.timer = c1.out_fuse.timer; - exp_c1.out_fuse_cfg.cooldown_time = c1.out_fuse_cfg.cooldown_time; - exp_c1.out_fuse_cfg.retry_time = c1.out_fuse_cfg.retry_time; - - exp_c2.enabled = c2.enabled; - exp_c2.out_faults.sup_uvp.severity = c2.out_faults.sup_uvp.severity; - exp_c2.out_faults.sup_uvp.w_time = c2.out_faults.sup_uvp.w_time; - exp_c2.out_faults.sup_uvp.f_time = c2.out_faults.sup_uvp.f_time; - exp_c2.out_faults.sup_ovp.severity = c2.out_faults.sup_ovp.severity; - exp_c2.out_faults.sup_ovp.w_time = c2.out_faults.sup_ovp.w_time; - exp_c2.out_faults.sup_ovp.f_time = c2.out_faults.sup_ovp.f_time; - exp_c2.out_faults.sup_ocp.severity = c2.out_faults.sup_ocp.severity; - exp_c2.out_faults.sup_ocp.w_time = c2.out_faults.sup_ocp.w_time; - exp_c2.out_faults.sup_ocp.f_time = c2.out_faults.sup_ocp.f_time; - exp_c2.out_faults.sup_opp.severity = c2.out_faults.sup_opp.severity; - exp_c2.out_faults.sup_opp.w_time = c2.out_faults.sup_opp.w_time; - exp_c2.out_faults.sup_opp.f_time = c2.out_faults.sup_opp.f_time; - exp_c2.out_faults.out_ovp.severity = c2.out_faults.out_ovp.severity; - exp_c2.out_faults.out_ovp.w_time = c2.out_faults.out_ovp.w_time; - exp_c2.out_faults.out_ovp.f_time = c2.out_faults.out_ovp.f_time; - exp_c2.out_faults.out_ocp.severity = c2.out_faults.out_ocp.severity; - exp_c2.out_faults.out_ocp.w_time = c2.out_faults.out_ocp.w_time; - exp_c2.out_faults.out_ocp.f_time = c2.out_faults.out_ocp.f_time; - exp_c2.out_faults.out_opp.severity = c2.out_faults.out_opp.severity; - exp_c2.out_faults.out_opp.w_time = c2.out_faults.out_opp.w_time; - exp_c2.out_faults.out_opp.f_time = c2.out_faults.out_opp.f_time; - exp_c2.out_faults.out_short.severity = c2.out_faults.out_short.severity; - exp_c2.out_faults.out_short.w_time = c2.out_faults.out_short.w_time; - exp_c2.out_faults.out_short.f_time = c2.out_faults.out_short.f_time; - exp_c2.out_faults.out_open.severity = c2.out_faults.out_open.severity; - exp_c2.out_faults.out_open.w_time = c2.out_faults.out_open.w_time; - exp_c2.out_faults.out_open.f_time = c2.out_faults.out_open.f_time; - exp_c2.out_faults_en.sup_uvp = c2.out_faults_en.sup_uvp; - exp_c2.out_faults_en.sup_ovp = c2.out_faults_en.sup_ovp; - exp_c2.out_faults_en.sup_ocp = c2.out_faults_en.sup_ocp; - exp_c2.out_faults_en.sup_opp = c2.out_faults_en.sup_opp; - exp_c2.out_faults_en.out_ovp = c2.out_faults_en.out_ovp; - exp_c2.out_faults_en.out_ocp = c2.out_faults_en.out_ocp; - exp_c2.out_faults_en.out_opp = c2.out_faults_en.out_opp; - exp_c2.out_faults_en.out_open = c2.out_faults_en.out_open; - exp_c2.out_faults_en.out_short = c2.out_faults_en.out_short; - exp_c2.out_fuse.state = c2.out_fuse.state; - exp_c2.out_fuse.count = c2.out_fuse.count; - exp_c2.out_fuse.timer = c2.out_fuse.timer; - exp_c2.out_fuse_cfg.cooldown_time = c2.out_fuse_cfg.cooldown_time; - exp_c2.out_fuse_cfg.retry_time = c2.out_fuse_cfg.retry_time; - - test_res = ut_hb_is_equal_ctrl_struct(&c1, &c2, exp_out, &exp_c1, &exp_c2); - if(!test_res) pass = 0; - - // NOT EQUAL - c1.enabled = 0xAA; - c1.out_faults.sup_uvp.severity = FAULT_LVL_FAULT; - c1.out_faults.sup_uvp.w_time = 0xAAAA; - c1.out_faults.sup_uvp.f_time = 0xAAAA; - c1.out_faults.sup_ovp.severity = FAULT_LVL_FAULT; - c1.out_faults.sup_ovp.w_time = 0xAAAA; - c1.out_faults.sup_ovp.f_time = 0xAAAA; - c1.out_faults.sup_ocp.severity = FAULT_LVL_FAULT; - c1.out_faults.sup_ocp.w_time = 0xAAAA; - c1.out_faults.sup_ocp.f_time = 0xAAAA; - c1.out_faults.sup_opp.severity = FAULT_LVL_FAULT; - c1.out_faults.sup_opp.w_time = 0xAAAA; - c1.out_faults.sup_opp.f_time = 0xAAAA; - c1.out_faults.out_ovp.severity = FAULT_LVL_FAULT; - c1.out_faults.out_ovp.w_time = 0xAAAA; - c1.out_faults.out_ovp.f_time = 0xAAAA; - c1.out_faults.out_ocp.severity = FAULT_LVL_FAULT; - c1.out_faults.out_ocp.w_time = 0xAAAA; - c1.out_faults.out_ocp.f_time = 0xAAAA; - c1.out_faults.out_opp.severity = FAULT_LVL_FAULT; - c1.out_faults.out_opp.w_time = 0xAAAA; - c1.out_faults.out_opp.f_time = 0xAAAA; - c1.out_faults.out_short.severity = FAULT_LVL_FAULT; - c1.out_faults.out_short.w_time = 0xAAAA; - c1.out_faults.out_short.f_time = 0xAAAA; - c1.out_faults.out_open.severity = FAULT_LVL_FAULT; - c1.out_faults.out_open.w_time = 0xAAAA; - c1.out_faults.out_open.f_time = 0xAAAA; - c1.out_faults_en.sup_uvp = 0xAA; - c1.out_faults_en.sup_ovp = 0xAA; - c1.out_faults_en.sup_ocp = 0xAA; - c1.out_faults_en.sup_opp = 0xAA; - c1.out_faults_en.out_ovp = 0xAA; - c1.out_faults_en.out_ocp = 0xAA; - c1.out_faults_en.out_opp = 0xAA; - c1.out_faults_en.out_open = 0xAA; - c1.out_faults_en.out_short = 0xAA; - c1.out_fuse.state = FUSE_ACTIVE; - c1.out_fuse.count = 0xAA; - c1.out_fuse.timer = 0xAAAA; - c1.out_fuse_cfg.cooldown_time = 0xAAAA; - c1.out_fuse_cfg.retry_time = 0xAAAA; - - c2.enabled = 0x55; - c2.out_faults.sup_uvp.severity = FAULT_LVL_WARNING; - c2.out_faults.sup_uvp.w_time = 0x5555; - c2.out_faults.sup_uvp.f_time = 0x5555; - c2.out_faults.sup_ovp.severity = FAULT_LVL_WARNING; - c2.out_faults.sup_ovp.w_time = 0x5555; - c2.out_faults.sup_ovp.f_time = 0x5555; - c2.out_faults.sup_ocp.severity = FAULT_LVL_WARNING; - c2.out_faults.sup_ocp.w_time = 0x5555; - c2.out_faults.sup_ocp.f_time = 0x5555; - c2.out_faults.sup_opp.severity = FAULT_LVL_WARNING; - c2.out_faults.sup_opp.w_time = 0x5555; - c2.out_faults.sup_opp.f_time = 0x5555; - c2.out_faults.out_ovp.severity = FAULT_LVL_WARNING; - c2.out_faults.out_ovp.w_time = 0x5555; - c2.out_faults.out_ovp.f_time = 0x5555; - c2.out_faults.out_ocp.severity = FAULT_LVL_WARNING; - c2.out_faults.out_ocp.w_time = 0x5555; - c2.out_faults.out_ocp.f_time = 0x5555; - c2.out_faults.out_opp.severity = FAULT_LVL_WARNING; - c2.out_faults.out_opp.w_time = 0x5555; - c2.out_faults.out_opp.f_time = 0x5555; - c2.out_faults.out_short.severity = FAULT_LVL_WARNING; - c2.out_faults.out_short.w_time = 0x5555; - c2.out_faults.out_short.f_time = 0x5555; - c2.out_faults.out_open.severity = FAULT_LVL_WARNING; - c2.out_faults.out_open.w_time = 0x5555; - c2.out_faults.out_open.f_time = 0x5555; - c2.out_faults_en.sup_uvp = 0x55; - c2.out_faults_en.sup_ovp = 0x55; - c2.out_faults_en.sup_ocp = 0x55; - c2.out_faults_en.sup_opp = 0x55; - c2.out_faults_en.out_ovp = 0x55; - c2.out_faults_en.out_ocp = 0x55; - c2.out_faults_en.out_opp = 0x55; - c2.out_faults_en.out_open = 0x55; - c2.out_faults_en.out_short = 0x55; - c2.out_fuse.state = FUSE_COOLDOWN; - c2.out_fuse.count = 0x55; - c2.out_fuse.timer = 0x5555; - c2.out_fuse_cfg.cooldown_time = 0x5555; - c2.out_fuse_cfg.retry_time = 0x5555; - - exp_out = 0; - - exp_c1.enabled = c1.enabled; - exp_c1.out_faults.sup_uvp.severity = c1.out_faults.sup_uvp.severity; - exp_c1.out_faults.sup_uvp.w_time = c1.out_faults.sup_uvp.w_time; - exp_c1.out_faults.sup_uvp.f_time = c1.out_faults.sup_uvp.f_time; - exp_c1.out_faults.sup_ovp.severity = c1.out_faults.sup_ovp.severity; - exp_c1.out_faults.sup_ovp.w_time = c1.out_faults.sup_ovp.w_time; - exp_c1.out_faults.sup_ovp.f_time = c1.out_faults.sup_ovp.f_time; - exp_c1.out_faults.sup_ocp.severity = c1.out_faults.sup_ocp.severity; - exp_c1.out_faults.sup_ocp.w_time = c1.out_faults.sup_ocp.w_time; - exp_c1.out_faults.sup_ocp.f_time = c1.out_faults.sup_ocp.f_time; - exp_c1.out_faults.sup_opp.severity = c1.out_faults.sup_opp.severity; - exp_c1.out_faults.sup_opp.w_time = c1.out_faults.sup_opp.w_time; - exp_c1.out_faults.sup_opp.f_time = c1.out_faults.sup_opp.f_time; - exp_c1.out_faults.out_ovp.severity = c1.out_faults.out_ovp.severity; - exp_c1.out_faults.out_ovp.w_time = c1.out_faults.out_ovp.w_time; - exp_c1.out_faults.out_ovp.f_time = c1.out_faults.out_ovp.f_time; - exp_c1.out_faults.out_ocp.severity = c1.out_faults.out_ocp.severity; - exp_c1.out_faults.out_ocp.w_time = c1.out_faults.out_ocp.w_time; - exp_c1.out_faults.out_ocp.f_time = c1.out_faults.out_ocp.f_time; - exp_c1.out_faults.out_opp.severity = c1.out_faults.out_opp.severity; - exp_c1.out_faults.out_opp.w_time = c1.out_faults.out_opp.w_time; - exp_c1.out_faults.out_opp.f_time = c1.out_faults.out_opp.f_time; - exp_c1.out_faults.out_short.severity = c1.out_faults.out_short.severity; - exp_c1.out_faults.out_short.w_time = c1.out_faults.out_short.w_time; - exp_c1.out_faults.out_short.f_time = c1.out_faults.out_short.f_time; - exp_c1.out_faults.out_open.severity = c1.out_faults.out_open.severity; - exp_c1.out_faults.out_open.w_time = c1.out_faults.out_open.w_time; - exp_c1.out_faults.out_open.f_time = c1.out_faults.out_open.f_time; - exp_c1.out_faults_en.sup_uvp = c1.out_faults_en.sup_uvp; - exp_c1.out_faults_en.sup_ovp = c1.out_faults_en.sup_ovp; - exp_c1.out_faults_en.sup_ocp = c1.out_faults_en.sup_ocp; - exp_c1.out_faults_en.sup_opp = c1.out_faults_en.sup_opp; - exp_c1.out_faults_en.out_ovp = c1.out_faults_en.out_ovp; - exp_c1.out_faults_en.out_ocp = c1.out_faults_en.out_ocp; - exp_c1.out_faults_en.out_opp = c1.out_faults_en.out_opp; - exp_c1.out_faults_en.out_open = c1.out_faults_en.out_open; - exp_c1.out_faults_en.out_short = c1.out_faults_en.out_short; - exp_c1.out_fuse.state = c1.out_fuse.state; - exp_c1.out_fuse.count = c1.out_fuse.count; - exp_c1.out_fuse.timer = c1.out_fuse.timer; - exp_c1.out_fuse_cfg.cooldown_time = c1.out_fuse_cfg.cooldown_time; - exp_c1.out_fuse_cfg.retry_time = c1.out_fuse_cfg.retry_time; - - exp_c2.enabled = c2.enabled; - exp_c2.out_faults.sup_uvp.severity = c2.out_faults.sup_uvp.severity; - exp_c2.out_faults.sup_uvp.w_time = c2.out_faults.sup_uvp.w_time; - exp_c2.out_faults.sup_uvp.f_time = c2.out_faults.sup_uvp.f_time; - exp_c2.out_faults.sup_ovp.severity = c2.out_faults.sup_ovp.severity; - exp_c2.out_faults.sup_ovp.w_time = c2.out_faults.sup_ovp.w_time; - exp_c2.out_faults.sup_ovp.f_time = c2.out_faults.sup_ovp.f_time; - exp_c2.out_faults.sup_ocp.severity = c2.out_faults.sup_ocp.severity; - exp_c2.out_faults.sup_ocp.w_time = c2.out_faults.sup_ocp.w_time; - exp_c2.out_faults.sup_ocp.f_time = c2.out_faults.sup_ocp.f_time; - exp_c2.out_faults.sup_opp.severity = c2.out_faults.sup_opp.severity; - exp_c2.out_faults.sup_opp.w_time = c2.out_faults.sup_opp.w_time; - exp_c2.out_faults.sup_opp.f_time = c2.out_faults.sup_opp.f_time; - exp_c2.out_faults.out_ovp.severity = c2.out_faults.out_ovp.severity; - exp_c2.out_faults.out_ovp.w_time = c2.out_faults.out_ovp.w_time; - exp_c2.out_faults.out_ovp.f_time = c2.out_faults.out_ovp.f_time; - exp_c2.out_faults.out_ocp.severity = c2.out_faults.out_ocp.severity; - exp_c2.out_faults.out_ocp.w_time = c2.out_faults.out_ocp.w_time; - exp_c2.out_faults.out_ocp.f_time = c2.out_faults.out_ocp.f_time; - exp_c2.out_faults.out_opp.severity = c2.out_faults.out_opp.severity; - exp_c2.out_faults.out_opp.w_time = c2.out_faults.out_opp.w_time; - exp_c2.out_faults.out_opp.f_time = c2.out_faults.out_opp.f_time; - exp_c2.out_faults.out_short.severity = c2.out_faults.out_short.severity; - exp_c2.out_faults.out_short.w_time = c2.out_faults.out_short.w_time; - exp_c2.out_faults.out_short.f_time = c2.out_faults.out_short.f_time; - exp_c2.out_faults.out_open.severity = c2.out_faults.out_open.severity; - exp_c2.out_faults.out_open.w_time = c2.out_faults.out_open.w_time; - exp_c2.out_faults.out_open.f_time = c2.out_faults.out_open.f_time; - exp_c2.out_faults_en.sup_uvp = c2.out_faults_en.sup_uvp; - exp_c2.out_faults_en.sup_ovp = c2.out_faults_en.sup_ovp; - exp_c2.out_faults_en.sup_ocp = c2.out_faults_en.sup_ocp; - exp_c2.out_faults_en.sup_opp = c2.out_faults_en.sup_opp; - exp_c2.out_faults_en.out_ovp = c2.out_faults_en.out_ovp; - exp_c2.out_faults_en.out_ocp = c2.out_faults_en.out_ocp; - exp_c2.out_faults_en.out_opp = c2.out_faults_en.out_opp; - exp_c2.out_faults_en.out_open = c2.out_faults_en.out_open; - exp_c2.out_faults_en.out_short = c2.out_faults_en.out_short; - exp_c2.out_fuse.state = c2.out_fuse.state; - exp_c2.out_fuse.count = c2.out_fuse.count; - exp_c2.out_fuse.timer = c2.out_fuse.timer; - exp_c2.out_fuse_cfg.cooldown_time = c2.out_fuse_cfg.cooldown_time; - exp_c2.out_fuse_cfg.retry_time = c2.out_fuse_cfg.retry_time; - - test_res = ut_hb_is_equal_ctrl_struct(&c1, &c2, exp_out, &exp_c1, &exp_c2); - if(!test_res) pass = 0; - - return pass; -} - - -static const uint8_t NOT_ACCESD_LOW = 255; -static const uint16_t NOT_ACCESD_PWM = 0xFFFF; - -static int ut_hb_init(hb_feedback_t* hb_fb, hb_control_t* hb_ctrl, hb_meas_t* meas, uint8_t exp_low, uint16_t exp_pwm, hb_feedback_t* exp_hb_fb, hb_control_t* exp_hb_ctrl) -{ - printf("Input:\n"); - - mock_board_halfbridge_write_low(NOT_ACCESD_LOW); - mock_board_halfbridge_write_pwm(NOT_ACCESD_PWM); - mock_board_halfbridge_write_feedback(meas); - - hb_init(hb_fb, hb_ctrl); - - uint8_t out_low = mock_board_halfbridge_read_low(); - uint16_t out_pwm = mock_board_halfbridge_read_pwm(); - uint8_t fb_ok = hb_is_equal_fb_struct(hb_fb, exp_hb_fb); - uint8_t ctrl_ok = hb_is_equal_ctrl_struct(hb_ctrl, exp_hb_ctrl); - - printf(" Output: Low:%d PWM:%d FB:%d CTRL:%d \n", out_low, out_pwm, fb_ok, ctrl_ok); - printf("Expected: Low:%d PWM:%d \n", exp_low, exp_pwm); - - if((out_low==exp_low)&&(out_pwm==exp_pwm)&&(fb_ok)&&(ctrl_ok)) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_hb_init_test(void) -{ - printf("******************************************************\n"); - printf("void hb_init(hb_feedback_t* hb_fb, hb_control_t* hb_ctrl) \n"); - - int test_res; - int pass = 1; - - hb_feedback_t hb_fb; - hb_control_t hb_ctrl; - hb_meas_t meas; - uint8_t exp_low; - uint16_t exp_pwm; - hb_feedback_t exp_hb_fb; - hb_control_t exp_hb_ctrl; - - // Normal 1 - hb_fb.analog.out_voltage = 0xAAAA; - hb_fb.analog.out_current = 0xAAAA; - hb_fb.analog.sup_voltage = 0xAAAA; - hb_fb.analog.sup_current = 0xAAAA; - hb_fb.analog.out_power = 0xAAAA; - hb_fb.analog.sup_power = 0xAAAA; - hb_fb.analog.out_impedance = 0xAAAA; - hb_fb.analog.low_side_ctrl = 0xAA; - hb_fb.analog.pwm = 0xAAAA; - hb_fb.enabled = 0xAA; - hb_fb.warning_act = 0xAA; - hb_fb.fault_act = 0xAA; - hb_fb.fused = 0xAA; - hb_fb.warnings.sup_uvp = 0xAA; - hb_fb.warnings.sup_ovp = 0xAA; - hb_fb.warnings.sup_ocp = 0xAA; - hb_fb.warnings.sup_opp = 0xAA; - hb_fb.warnings.out_ovp = 0xAA; - hb_fb.warnings.out_ocp = 0xAA; - hb_fb.warnings.out_opp = 0xAA; - hb_fb.warnings.out_short = 0xAA; - hb_fb.warnings.out_open = 0xAA; - hb_fb.faults.sup_uvp = 0xAA; - hb_fb.faults.sup_ovp = 0xAA; - hb_fb.faults.sup_ocp = 0xAA; - hb_fb.faults.sup_opp = 0xAA; - hb_fb.faults.out_ovp = 0xAA; - hb_fb.faults.out_ocp = 0xAA; - hb_fb.faults.out_opp = 0xAA; - hb_fb.faults.out_short = 0xAA; - hb_fb.faults.out_open = 0xAA; - - hb_ctrl.enabled = 0xAA; - hb_ctrl.out_faults.sup_uvp.severity = FAULT_LVL_FAULT; - hb_ctrl.out_faults.sup_uvp.w_time = 0xAAAA; - hb_ctrl.out_faults.sup_uvp.f_time = 0xAAAA; - hb_ctrl.out_faults.sup_ovp.severity = FAULT_LVL_FAULT; - hb_ctrl.out_faults.sup_ovp.w_time = 0xAAAA; - hb_ctrl.out_faults.sup_ovp.f_time = 0xAAAA; - hb_ctrl.out_faults.sup_ocp.severity = FAULT_LVL_FAULT; - hb_ctrl.out_faults.sup_ocp.w_time = 0xAAAA; - hb_ctrl.out_faults.sup_ocp.f_time = 0xAAAA; - hb_ctrl.out_faults.sup_opp.severity = FAULT_LVL_FAULT; - hb_ctrl.out_faults.sup_opp.w_time = 0xAAAA; - hb_ctrl.out_faults.sup_opp.f_time = 0xAAAA; - hb_ctrl.out_faults.out_ovp.severity = FAULT_LVL_FAULT; - hb_ctrl.out_faults.out_ovp.w_time = 0xAAAA; - hb_ctrl.out_faults.out_ovp.f_time = 0xAAAA; - hb_ctrl.out_faults.out_ocp.severity = FAULT_LVL_FAULT; - hb_ctrl.out_faults.out_ocp.w_time = 0xAAAA; - hb_ctrl.out_faults.out_ocp.f_time = 0xAAAA; - hb_ctrl.out_faults.out_opp.severity = FAULT_LVL_FAULT; - hb_ctrl.out_faults.out_opp.w_time = 0xAAAA; - hb_ctrl.out_faults.out_opp.f_time = 0xAAAA; - hb_ctrl.out_faults.out_short.severity = FAULT_LVL_FAULT; - hb_ctrl.out_faults.out_short.w_time = 0xAAAA; - hb_ctrl.out_faults.out_short.f_time = 0xAAAA; - hb_ctrl.out_faults.out_open.severity = FAULT_LVL_FAULT; - hb_ctrl.out_faults.out_open.w_time = 0xAAAA; - hb_ctrl.out_faults.out_open.f_time = 0xAAAA; - hb_ctrl.out_faults_en.sup_uvp = 0xAA; - hb_ctrl.out_faults_en.sup_ovp = 0xAA; - hb_ctrl.out_faults_en.sup_ocp = 0xAA; - hb_ctrl.out_faults_en.sup_opp = 0xAA; - hb_ctrl.out_faults_en.out_ovp = 0xAA; - hb_ctrl.out_faults_en.out_ocp = 0xAA; - hb_ctrl.out_faults_en.out_opp = 0xAA; - hb_ctrl.out_faults_en.out_short = 0xAA; - hb_ctrl.out_faults_en.out_open = 0xAA; - hb_ctrl.out_fuse.state = FUSE_ACTIVE; - hb_ctrl.out_fuse.count = 0xAAAA; - hb_ctrl.out_fuse.timer = 0xAAAA; - hb_ctrl.out_fuse_cfg.cooldown_time = 0xAAAA; - hb_ctrl.out_fuse_cfg.retry_time = 0xAAAA; - - meas.out_voltage = 12000; - meas.out_current = 100; - meas.sup_voltage = 0; - meas.sup_current = 0; - meas.out_power = 0; - meas.sup_power = 1200; - meas.out_impedance = 0xFFFF; - meas.low_side_ctrl = 0; - meas.pwm = 0; - - exp_low = 0; - exp_pwm = 0; - - exp_hb_fb.analog.out_voltage = meas.out_voltage; - exp_hb_fb.analog.out_current = meas.out_current; - exp_hb_fb.analog.sup_voltage = meas.sup_voltage; - exp_hb_fb.analog.sup_current = meas.sup_current; - exp_hb_fb.analog.out_power = meas.out_power; - exp_hb_fb.analog.sup_power = meas.sup_power; - exp_hb_fb.analog.out_impedance = meas.out_impedance; - exp_hb_fb.analog.low_side_ctrl = meas.low_side_ctrl; - exp_hb_fb.analog.pwm = meas.pwm; - exp_hb_fb.enabled = 0; - exp_hb_fb.warning_act = 0; - exp_hb_fb.fault_act = 0; - exp_hb_fb.fused = 0; - exp_hb_fb.warnings.sup_uvp = 0; - exp_hb_fb.warnings.sup_ovp = 0; - exp_hb_fb.warnings.sup_ocp = 0; - exp_hb_fb.warnings.sup_opp = 0; - exp_hb_fb.warnings.out_ovp = 0; - exp_hb_fb.warnings.out_ocp = 0; - exp_hb_fb.warnings.out_opp = 0; - exp_hb_fb.warnings.out_short = 0; - exp_hb_fb.warnings.out_open = 0; - exp_hb_fb.faults.sup_uvp = 0; - exp_hb_fb.faults.sup_ovp = 0; - exp_hb_fb.faults.sup_ocp = 0; - exp_hb_fb.faults.sup_opp = 0; - exp_hb_fb.faults.out_ovp = 0; - exp_hb_fb.faults.out_ocp = 0; - exp_hb_fb.faults.out_opp = 0; - exp_hb_fb.faults.out_short = 0; - exp_hb_fb.faults.out_open = 0; - - exp_hb_ctrl.enabled = 0; - exp_hb_ctrl.out_faults.sup_uvp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.sup_uvp.w_time = 0; - exp_hb_ctrl.out_faults.sup_uvp.f_time = 0; - exp_hb_ctrl.out_faults.sup_ovp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.sup_ovp.w_time = 0; - exp_hb_ctrl.out_faults.sup_ovp.f_time = 0; - exp_hb_ctrl.out_faults.sup_ocp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.sup_ocp.w_time = 0; - exp_hb_ctrl.out_faults.sup_ocp.f_time = 0; - exp_hb_ctrl.out_faults.sup_opp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.sup_opp.w_time = 0; - exp_hb_ctrl.out_faults.sup_opp.f_time = 0; - exp_hb_ctrl.out_faults.out_ovp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.out_ovp.w_time = 0; - exp_hb_ctrl.out_faults.out_ovp.f_time = 0; - exp_hb_ctrl.out_faults.out_ocp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.out_ocp.w_time = 0; - exp_hb_ctrl.out_faults.out_ocp.f_time = 0; - exp_hb_ctrl.out_faults.out_opp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.out_opp.w_time = 0; - exp_hb_ctrl.out_faults.out_opp.f_time = 0; - exp_hb_ctrl.out_faults.out_short.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.out_short.w_time = 0; - exp_hb_ctrl.out_faults.out_short.f_time = 0; - exp_hb_ctrl.out_faults.out_open.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.out_open.w_time = 0; - exp_hb_ctrl.out_faults.out_open.f_time = 0; - exp_hb_ctrl.out_faults_en.sup_uvp = 0; - exp_hb_ctrl.out_faults_en.sup_ovp = 0; - exp_hb_ctrl.out_faults_en.sup_ocp = 1; - exp_hb_ctrl.out_faults_en.sup_opp = 0; - exp_hb_ctrl.out_faults_en.out_ovp = 0; - exp_hb_ctrl.out_faults_en.out_ocp = 1; - exp_hb_ctrl.out_faults_en.out_opp = 0; - exp_hb_ctrl.out_faults_en.out_short = 1; - exp_hb_ctrl.out_faults_en.out_open = 0; - exp_hb_ctrl.out_fuse.state = FUSE_OFF; - exp_hb_ctrl.out_fuse.count = 0; - exp_hb_ctrl.out_fuse.timer = 0; - exp_hb_ctrl.out_fuse_cfg.cooldown_time = 1000; - exp_hb_ctrl.out_fuse_cfg.retry_time = 1000; - - test_res = ut_hb_init(&hb_fb, &hb_ctrl, &meas, exp_low, exp_pwm, &exp_hb_fb, &exp_hb_ctrl); - if(!test_res) pass = 0; - - return pass; -} - -static int ut_hb_enable(hb_control_t* hb_ctrl, uint8_t exp_low, uint16_t exp_pwm, hb_control_t* exp_hb_ctrl) -{ - printf(" Input:\n"); - - mock_board_halfbridge_write_low(NOT_ACCESD_LOW); - mock_board_halfbridge_write_pwm(NOT_ACCESD_PWM); - - hb_enable(hb_ctrl); - - uint8_t out_low = mock_board_halfbridge_read_low(); - uint16_t out_pwm = mock_board_halfbridge_read_pwm(); - uint8_t ctrl_ok = hb_is_equal_ctrl_struct(hb_ctrl, exp_hb_ctrl); - - printf(" Output: Low:%d PWM:%d Ctrl:%d\n", out_low, out_pwm, ctrl_ok); - printf("Expected: Low:%d PWM:%d \n", exp_low, exp_pwm); - - if((out_low==exp_low)&&(out_pwm==exp_pwm)&&(ctrl_ok)) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_hb_enable_test(void) -{ - printf("******************************************************\n"); - printf("void hb_enable(hb_control_t* hb_ctrl) \n"); - - int test_res; - int pass = 1; - - hb_control_t hb_ctrl; - uint8_t exp_low; - uint16_t exp_pwm; - hb_control_t exp_hb_ctrl; - - // Normal 1 - hb_ctrl.enabled = 0; - hb_ctrl.out_faults.sup_uvp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.sup_uvp.w_time = 0; - hb_ctrl.out_faults.sup_uvp.f_time = 0; - hb_ctrl.out_faults.sup_ovp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.sup_ovp.w_time = 0; - hb_ctrl.out_faults.sup_ovp.f_time = 0; - hb_ctrl.out_faults.sup_ocp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.sup_ocp.w_time = 0; - hb_ctrl.out_faults.sup_ocp.f_time = 0; - hb_ctrl.out_faults.sup_opp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.sup_opp.w_time = 0; - hb_ctrl.out_faults.sup_opp.f_time = 0; - hb_ctrl.out_faults.out_ovp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_ovp.w_time = 0; - hb_ctrl.out_faults.out_ovp.f_time = 0; - hb_ctrl.out_faults.out_ocp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_ocp.w_time = 0; - hb_ctrl.out_faults.out_ocp.f_time = 0; - hb_ctrl.out_faults.out_opp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_opp.w_time = 0; - hb_ctrl.out_faults.out_opp.f_time = 0; - hb_ctrl.out_faults.out_short.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_short.w_time = 0; - hb_ctrl.out_faults.out_short.f_time = 0; - hb_ctrl.out_faults.out_open.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_open.w_time = 0; - hb_ctrl.out_faults.out_open.f_time = 0; - hb_ctrl.out_faults_en.sup_uvp = 0; - hb_ctrl.out_faults_en.sup_ovp = 0; - hb_ctrl.out_faults_en.sup_ocp = 1; - hb_ctrl.out_faults_en.sup_opp = 0; - hb_ctrl.out_faults_en.out_ovp = 0; - hb_ctrl.out_faults_en.out_ocp = 1; - hb_ctrl.out_faults_en.out_opp = 0; - hb_ctrl.out_faults_en.out_short = 1; - hb_ctrl.out_faults_en.out_open = 0; - hb_ctrl.out_fuse.state = FUSE_OFF; - hb_ctrl.out_fuse.count = 0; - hb_ctrl.out_fuse.timer = 0; - hb_ctrl.out_fuse_cfg.cooldown_time = 1000; - hb_ctrl.out_fuse_cfg.retry_time = 1000; - - exp_low = 1; - exp_pwm = 0; - - exp_hb_ctrl.enabled = 1; - exp_hb_ctrl.out_faults.sup_uvp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.sup_uvp.w_time = 0; - exp_hb_ctrl.out_faults.sup_uvp.f_time = 0; - exp_hb_ctrl.out_faults.sup_ovp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.sup_ovp.w_time = 0; - exp_hb_ctrl.out_faults.sup_ovp.f_time = 0; - exp_hb_ctrl.out_faults.sup_ocp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.sup_ocp.w_time = 0; - exp_hb_ctrl.out_faults.sup_ocp.f_time = 0; - exp_hb_ctrl.out_faults.sup_opp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.sup_opp.w_time = 0; - exp_hb_ctrl.out_faults.sup_opp.f_time = 0; - exp_hb_ctrl.out_faults.out_ovp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.out_ovp.w_time = 0; - exp_hb_ctrl.out_faults.out_ovp.f_time = 0; - exp_hb_ctrl.out_faults.out_ocp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.out_ocp.w_time = 0; - exp_hb_ctrl.out_faults.out_ocp.f_time = 0; - exp_hb_ctrl.out_faults.out_opp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.out_opp.w_time = 0; - exp_hb_ctrl.out_faults.out_opp.f_time = 0; - exp_hb_ctrl.out_faults.out_short.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.out_short.w_time = 0; - exp_hb_ctrl.out_faults.out_short.f_time = 0; - exp_hb_ctrl.out_faults.out_open.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.out_open.w_time = 0; - exp_hb_ctrl.out_faults.out_open.f_time = 0; - exp_hb_ctrl.out_faults_en.sup_uvp = 0; - exp_hb_ctrl.out_faults_en.sup_ovp = 0; - exp_hb_ctrl.out_faults_en.sup_ocp = 1; - exp_hb_ctrl.out_faults_en.sup_opp = 0; - exp_hb_ctrl.out_faults_en.out_ovp = 0; - exp_hb_ctrl.out_faults_en.out_ocp = 1; - exp_hb_ctrl.out_faults_en.out_opp = 0; - exp_hb_ctrl.out_faults_en.out_short = 1; - exp_hb_ctrl.out_faults_en.out_open = 0; - exp_hb_ctrl.out_fuse.state = FUSE_OFF; - exp_hb_ctrl.out_fuse.count = 0; - exp_hb_ctrl.out_fuse.timer = 0; - exp_hb_ctrl.out_fuse_cfg.cooldown_time = 1000; - exp_hb_ctrl.out_fuse_cfg.retry_time = 1000; - - test_res = ut_hb_enable(&hb_ctrl, exp_low, exp_pwm, &exp_hb_ctrl); - if(!test_res) pass = 0; - - return pass; -} - -static int ut_hb_disable(hb_control_t* hb_ctrl, uint8_t exp_low, uint16_t exp_pwm, hb_control_t* exp_hb_ctrl) -{ - printf(" Input:\n"); - - mock_board_halfbridge_write_low(NOT_ACCESD_LOW); - mock_board_halfbridge_write_pwm(NOT_ACCESD_PWM); - - hb_disable(hb_ctrl); - - uint8_t out_low = mock_board_halfbridge_read_low(); - uint16_t out_pwm = mock_board_halfbridge_read_pwm(); - uint8_t ctrl_ok = hb_is_equal_ctrl_struct(hb_ctrl, exp_hb_ctrl); - - printf(" Output: Low:%d PWM:%d Ctrl:%d\n", out_low, out_pwm, ctrl_ok); - printf("Expected: Low:%d PWM:%d \n", exp_low, exp_pwm); - - if((out_low==exp_low)&&(out_pwm==exp_pwm)&&(ctrl_ok)) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - - -int ut_hb_disable_test(void) -{ - printf("******************************************************\n"); - printf("void hb_disable(hb_control_t* hb_ctrl) \n"); - - int test_res; - int pass = 1; - - hb_control_t hb_ctrl; - uint8_t exp_low; - uint16_t exp_pwm; - hb_control_t exp_hb_ctrl; - - // Normal 1 - hb_ctrl.enabled = 1; - hb_ctrl.out_faults.sup_uvp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.sup_uvp.w_time = 0; - hb_ctrl.out_faults.sup_uvp.f_time = 0; - hb_ctrl.out_faults.sup_ovp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.sup_ovp.w_time = 0; - hb_ctrl.out_faults.sup_ovp.f_time = 0; - hb_ctrl.out_faults.sup_ocp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.sup_ocp.w_time = 0; - hb_ctrl.out_faults.sup_ocp.f_time = 0; - hb_ctrl.out_faults.sup_opp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.sup_opp.w_time = 0; - hb_ctrl.out_faults.sup_opp.f_time = 0; - hb_ctrl.out_faults.out_ovp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_ovp.w_time = 0; - hb_ctrl.out_faults.out_ovp.f_time = 0; - hb_ctrl.out_faults.out_ocp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_ocp.w_time = 0; - hb_ctrl.out_faults.out_ocp.f_time = 0; - hb_ctrl.out_faults.out_opp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_opp.w_time = 0; - hb_ctrl.out_faults.out_opp.f_time = 0; - hb_ctrl.out_faults.out_short.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_short.w_time = 0; - hb_ctrl.out_faults.out_short.f_time = 0; - hb_ctrl.out_faults.out_open.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_open.w_time = 0; - hb_ctrl.out_faults.out_open.f_time = 0; - hb_ctrl.out_faults_en.sup_uvp = 0; - hb_ctrl.out_faults_en.sup_ovp = 0; - hb_ctrl.out_faults_en.sup_ocp = 1; - hb_ctrl.out_faults_en.sup_opp = 0; - hb_ctrl.out_faults_en.out_ovp = 0; - hb_ctrl.out_faults_en.out_ocp = 1; - hb_ctrl.out_faults_en.out_opp = 0; - hb_ctrl.out_faults_en.out_short = 1; - hb_ctrl.out_faults_en.out_open = 0; - hb_ctrl.out_fuse.state = FUSE_OFF; - hb_ctrl.out_fuse.count = 0; - hb_ctrl.out_fuse.timer = 0; - hb_ctrl.out_fuse_cfg.cooldown_time = 1000; - hb_ctrl.out_fuse_cfg.retry_time = 1000; - - exp_low = 0; - exp_pwm = 0; - - exp_hb_ctrl.enabled = 0; - exp_hb_ctrl.out_faults.sup_uvp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.sup_uvp.w_time = 0; - exp_hb_ctrl.out_faults.sup_uvp.f_time = 0; - exp_hb_ctrl.out_faults.sup_ovp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.sup_ovp.w_time = 0; - exp_hb_ctrl.out_faults.sup_ovp.f_time = 0; - exp_hb_ctrl.out_faults.sup_ocp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.sup_ocp.w_time = 0; - exp_hb_ctrl.out_faults.sup_ocp.f_time = 0; - exp_hb_ctrl.out_faults.sup_opp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.sup_opp.w_time = 0; - exp_hb_ctrl.out_faults.sup_opp.f_time = 0; - exp_hb_ctrl.out_faults.out_ovp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.out_ovp.w_time = 0; - exp_hb_ctrl.out_faults.out_ovp.f_time = 0; - exp_hb_ctrl.out_faults.out_ocp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.out_ocp.w_time = 0; - exp_hb_ctrl.out_faults.out_ocp.f_time = 0; - exp_hb_ctrl.out_faults.out_opp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.out_opp.w_time = 0; - exp_hb_ctrl.out_faults.out_opp.f_time = 0; - exp_hb_ctrl.out_faults.out_short.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.out_short.w_time = 0; - exp_hb_ctrl.out_faults.out_short.f_time = 0; - exp_hb_ctrl.out_faults.out_open.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.out_open.w_time = 0; - exp_hb_ctrl.out_faults.out_open.f_time = 0; - exp_hb_ctrl.out_faults_en.sup_uvp = 0; - exp_hb_ctrl.out_faults_en.sup_ovp = 0; - exp_hb_ctrl.out_faults_en.sup_ocp = 1; - exp_hb_ctrl.out_faults_en.sup_opp = 0; - exp_hb_ctrl.out_faults_en.out_ovp = 0; - exp_hb_ctrl.out_faults_en.out_ocp = 1; - exp_hb_ctrl.out_faults_en.out_opp = 0; - exp_hb_ctrl.out_faults_en.out_short = 1; - exp_hb_ctrl.out_faults_en.out_open = 0; - exp_hb_ctrl.out_fuse.state = FUSE_OFF; - exp_hb_ctrl.out_fuse.count = 0; - exp_hb_ctrl.out_fuse.timer = 0; - exp_hb_ctrl.out_fuse_cfg.cooldown_time = 1000; - exp_hb_ctrl.out_fuse_cfg.retry_time = 1000; - - test_res = ut_hb_disable(&hb_ctrl, exp_low, exp_pwm, &exp_hb_ctrl); - if(!test_res) pass = 0; - - return pass; -} - -static int ut_hb_process(int16_t target, hb_feedback_t* hb_fb, hb_control_t* hb_ctrl, hb_meas_t* meas, uint8_t exp_low, uint16_t exp_pwm, hb_feedback_t* exp_hb_fb, hb_control_t* exp_hb_ctrl) -{ - printf(" Input: Target:%d Enabled:%d \n", target, hb_ctrl->enabled); - printf("Supply Voltage:%d Current:%d Power:%d \n", meas->sup_voltage, meas->sup_current, meas->sup_power); - printf("Output Voltage:%d Current:%d Power:%d Impedance:%d\n", meas->out_voltage, meas->out_current, meas->out_power, meas->out_impedance); - printf("Low side:%d PWM:%d \n", meas->low_side_ctrl, meas->pwm); - printf("Control struct input: \n"); - print_ctrl_struct(hb_ctrl); - - mock_board_halfbridge_write_low(NOT_ACCESD_LOW); - mock_board_halfbridge_write_pwm(NOT_ACCESD_PWM); - mock_board_halfbridge_write_feedback(meas); - - hb_process(target, hb_fb, hb_ctrl); - - uint8_t out_low = mock_board_halfbridge_read_low(); - uint16_t out_pwm = mock_board_halfbridge_read_pwm(); - uint8_t fb_ok = hb_is_equal_fb_struct(hb_fb, exp_hb_fb); - uint8_t ctrl_ok = hb_is_equal_ctrl_struct(hb_ctrl, exp_hb_ctrl); - - printf("\n"); - printf("Output: \n"); - printf("Low:%d PWM:%d FB:%d CTRL:%d \n", out_low, out_pwm, fb_ok, ctrl_ok); - print_fb_struct(hb_fb); - print_ctrl_struct(hb_ctrl); - - printf("\n"); - printf("Expected: \n"); - printf("Low:%d PWM:%d \n", exp_low, exp_pwm); - print_ctrl_struct(exp_hb_ctrl); - - if((out_low==exp_low)&&(out_pwm==exp_pwm)&&(fb_ok)&&(ctrl_ok)) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_hb_process_test(void) -{ - printf("******************************************************\n"); - printf("void hb_process(int16_t target, hb_feedback_t* hb_fb, hb_control_t* hb_ctrl) \n"); - - int test_res; - int pass = 1; - - int16_t target; - hb_feedback_t hb_fb; - hb_control_t hb_ctrl; - hb_meas_t meas; - - uint8_t exp_low; - uint16_t exp_pwm; - hb_feedback_t exp_hb_fb; - hb_control_t exp_hb_ctrl; - - // 0V target - printf("----- 0V target ------------------ \n"); - target = 0; - - hb_fb.analog.sup_voltage = 12000; - hb_fb.analog.sup_current = 100; - hb_fb.analog.sup_power = 1200; - hb_fb.analog.out_voltage = 0; - hb_fb.analog.out_current = 0; - hb_fb.analog.out_power = 0; - hb_fb.analog.out_impedance = 0xFFFF; - hb_fb.analog.low_side_ctrl = 1; - hb_fb.analog.pwm = 0; - hb_fb.enabled = 1; - hb_fb.warning_act = 0; - hb_fb.fault_act = 0; - hb_fb.fused = 0; - hb_fb.warnings.sup_uvp = 0; - hb_fb.warnings.sup_ovp = 0; - hb_fb.warnings.sup_ocp = 0; - hb_fb.warnings.sup_opp = 0; - hb_fb.warnings.out_ovp = 0; - hb_fb.warnings.out_ocp = 0; - hb_fb.warnings.out_opp = 0; - hb_fb.warnings.out_short = 0; - hb_fb.warnings.out_open = 0; - hb_fb.faults.sup_uvp = 0; - hb_fb.faults.sup_ovp = 0; - hb_fb.faults.sup_ocp = 0; - hb_fb.faults.sup_opp = 0; - hb_fb.faults.out_ovp = 0; - hb_fb.faults.out_ocp = 0; - hb_fb.faults.out_opp = 0; - hb_fb.faults.out_short = 0; - hb_fb.faults.out_open = 0; - - hb_ctrl.enabled = 1; - hb_ctrl.out_faults.sup_uvp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.sup_uvp.w_time = 0; - hb_ctrl.out_faults.sup_uvp.f_time = 0; - hb_ctrl.out_faults.sup_ovp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.sup_ovp.w_time = 0; - hb_ctrl.out_faults.sup_ovp.f_time = 0; - hb_ctrl.out_faults.sup_ocp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.sup_ocp.w_time = 0; - hb_ctrl.out_faults.sup_ocp.f_time = 0; - hb_ctrl.out_faults.sup_opp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.sup_opp.w_time = 0; - hb_ctrl.out_faults.sup_opp.f_time = 0; - hb_ctrl.out_faults.out_ovp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_ovp.w_time = 0; - hb_ctrl.out_faults.out_ovp.f_time = 0; - hb_ctrl.out_faults.out_ocp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_ocp.w_time = 0; - hb_ctrl.out_faults.out_ocp.f_time = 0; - hb_ctrl.out_faults.out_opp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_opp.w_time = 0; - hb_ctrl.out_faults.out_opp.f_time = 0; - hb_ctrl.out_faults.out_short.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_short.w_time = 0; - hb_ctrl.out_faults.out_short.f_time = 0; - hb_ctrl.out_faults.out_open.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_open.w_time = 0; - hb_ctrl.out_faults.out_open.f_time = 0; - hb_ctrl.out_faults_en.sup_uvp = 0; - hb_ctrl.out_faults_en.sup_ovp = 0; - hb_ctrl.out_faults_en.sup_ocp = 1; - hb_ctrl.out_faults_en.sup_opp = 0; - hb_ctrl.out_faults_en.out_ovp = 0; - hb_ctrl.out_faults_en.out_ocp = 1; - hb_ctrl.out_faults_en.out_opp = 0; - hb_ctrl.out_faults_en.out_short = 1; - hb_ctrl.out_faults_en.out_open = 0; - hb_ctrl.out_fuse.state = FUSE_OFF; - hb_ctrl.out_fuse.count = 0; - hb_ctrl.out_fuse.timer = 0; - hb_ctrl.out_fuse_cfg.cooldown_time = 1000; - hb_ctrl.out_fuse_cfg.retry_time = 1000; - - meas.sup_voltage = 12000; - meas.sup_current = 100; - meas.sup_power = 1200; - meas.out_voltage = 0; - meas.out_current = 0; - meas.out_power = 0; - meas.out_impedance = 0xFFFF; - meas.low_side_ctrl = 1; - meas.pwm = 0; - - exp_low = 1; - exp_pwm = 0; - - exp_hb_fb.analog.sup_voltage = meas.sup_voltage; - exp_hb_fb.analog.sup_current = meas.sup_current; - exp_hb_fb.analog.sup_power = meas.sup_power; - exp_hb_fb.analog.out_voltage = meas.out_voltage; - exp_hb_fb.analog.out_current = meas.out_current; - exp_hb_fb.analog.out_power = meas.out_power; - exp_hb_fb.analog.out_impedance = meas.out_impedance; - exp_hb_fb.analog.low_side_ctrl = meas.low_side_ctrl; - exp_hb_fb.analog.pwm = meas.pwm; - exp_hb_fb.enabled = 1; - exp_hb_fb.warning_act = 0; - exp_hb_fb.fault_act = 0; - exp_hb_fb.fused = 0; - exp_hb_fb.warnings.sup_uvp = 0; - exp_hb_fb.warnings.sup_ovp = 0; - exp_hb_fb.warnings.sup_ocp = 0; - exp_hb_fb.warnings.sup_opp = 0; - exp_hb_fb.warnings.out_ovp = 0; - exp_hb_fb.warnings.out_ocp = 0; - exp_hb_fb.warnings.out_opp = 0; - exp_hb_fb.warnings.out_short = 0; - exp_hb_fb.warnings.out_open = 0; - exp_hb_fb.faults.sup_uvp = 0; - exp_hb_fb.faults.sup_ovp = 0; - exp_hb_fb.faults.sup_ocp = 0; - exp_hb_fb.faults.sup_opp = 0; - exp_hb_fb.faults.out_ovp = 0; - exp_hb_fb.faults.out_ocp = 0; - exp_hb_fb.faults.out_opp = 0; - exp_hb_fb.faults.out_short = 0; - exp_hb_fb.faults.out_open = 0; - - exp_hb_ctrl.enabled = 1; - exp_hb_ctrl.out_faults.sup_uvp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.sup_uvp.w_time = 0; - exp_hb_ctrl.out_faults.sup_uvp.f_time = 0; - exp_hb_ctrl.out_faults.sup_ovp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.sup_ovp.w_time = 0; - exp_hb_ctrl.out_faults.sup_ovp.f_time = 0; - exp_hb_ctrl.out_faults.sup_ocp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.sup_ocp.w_time = 0; - exp_hb_ctrl.out_faults.sup_ocp.f_time = 0; - exp_hb_ctrl.out_faults.sup_opp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.sup_opp.w_time = 0; - exp_hb_ctrl.out_faults.sup_opp.f_time = 0; - exp_hb_ctrl.out_faults.out_ovp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.out_ovp.w_time = 0; - exp_hb_ctrl.out_faults.out_ovp.f_time = 0; - exp_hb_ctrl.out_faults.out_ocp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.out_ocp.w_time = 0; - exp_hb_ctrl.out_faults.out_ocp.f_time = 0; - exp_hb_ctrl.out_faults.out_opp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.out_opp.w_time = 0; - exp_hb_ctrl.out_faults.out_opp.f_time = 0; - exp_hb_ctrl.out_faults.out_short.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.out_short.w_time = 0; - exp_hb_ctrl.out_faults.out_short.f_time = 0; - exp_hb_ctrl.out_faults.out_open.severity = FAULT_LVL_WARNING; - exp_hb_ctrl.out_faults.out_open.w_time = 0; - exp_hb_ctrl.out_faults.out_open.f_time = 0; - exp_hb_ctrl.out_faults_en.sup_uvp = 0; - exp_hb_ctrl.out_faults_en.sup_ovp = 0; - exp_hb_ctrl.out_faults_en.sup_ocp = 1; - exp_hb_ctrl.out_faults_en.sup_opp = 0; - exp_hb_ctrl.out_faults_en.out_ovp = 1; - exp_hb_ctrl.out_faults_en.out_ocp = 1; - exp_hb_ctrl.out_faults_en.out_opp = 0; - exp_hb_ctrl.out_faults_en.out_short = 0; - exp_hb_ctrl.out_faults_en.out_open = 0; - exp_hb_ctrl.out_fuse.state = FUSE_OFF; - exp_hb_ctrl.out_fuse.count = 0; - exp_hb_ctrl.out_fuse.timer = 0; - exp_hb_ctrl.out_fuse_cfg.cooldown_time = 1000; - exp_hb_ctrl.out_fuse_cfg.retry_time = 1000; - - test_res = ut_hb_process(target, &hb_fb, &hb_ctrl, &meas, exp_low, exp_pwm, &exp_hb_fb, &exp_hb_ctrl); - if(!test_res) pass = 0; - - // 6V target - printf("----- 6V target ------------------ \n"); - target = 6000; - - hb_fb.analog.sup_voltage = 12000; - hb_fb.analog.sup_current = 100; - hb_fb.analog.sup_power = 1200; - hb_fb.analog.out_voltage = 0; - hb_fb.analog.out_current = 0; - hb_fb.analog.out_power = 0; - hb_fb.analog.out_impedance = 0xFFFF; - hb_fb.analog.low_side_ctrl = 1; - hb_fb.analog.pwm = 0; - hb_fb.enabled = 1; - hb_fb.warning_act = 0; - hb_fb.fault_act = 0; - hb_fb.fused = 0; - hb_fb.warnings.sup_uvp = 0; - hb_fb.warnings.sup_ovp = 0; - hb_fb.warnings.sup_ocp = 0; - hb_fb.warnings.sup_opp = 0; - hb_fb.warnings.out_ovp = 0; - hb_fb.warnings.out_ocp = 0; - hb_fb.warnings.out_opp = 0; - hb_fb.warnings.out_short = 0; - hb_fb.warnings.out_open = 0; - hb_fb.faults.sup_uvp = 0; - hb_fb.faults.sup_ovp = 0; - hb_fb.faults.sup_ocp = 0; - hb_fb.faults.sup_opp = 0; - hb_fb.faults.out_ovp = 0; - hb_fb.faults.out_ocp = 0; - hb_fb.faults.out_opp = 0; - hb_fb.faults.out_short = 0; - hb_fb.faults.out_open = 0; - - hb_ctrl.enabled = 1; - hb_ctrl.out_faults.sup_uvp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.sup_uvp.w_time = 0; - hb_ctrl.out_faults.sup_uvp.f_time = 0; - hb_ctrl.out_faults.sup_ovp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.sup_ovp.w_time = 0; - hb_ctrl.out_faults.sup_ovp.f_time = 0; - hb_ctrl.out_faults.sup_ocp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.sup_ocp.w_time = 0; - hb_ctrl.out_faults.sup_ocp.f_time = 0; - hb_ctrl.out_faults.sup_opp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.sup_opp.w_time = 0; - hb_ctrl.out_faults.sup_opp.f_time = 0; - hb_ctrl.out_faults.out_ovp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_ovp.w_time = 0; - hb_ctrl.out_faults.out_ovp.f_time = 0; - hb_ctrl.out_faults.out_ocp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_ocp.w_time = 0; - hb_ctrl.out_faults.out_ocp.f_time = 0; - hb_ctrl.out_faults.out_opp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_opp.w_time = 0; - hb_ctrl.out_faults.out_opp.f_time = 0; - hb_ctrl.out_faults.out_short.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_short.w_time = 0; - hb_ctrl.out_faults.out_short.f_time = 0; - hb_ctrl.out_faults.out_open.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_open.w_time = 0; - hb_ctrl.out_faults.out_open.f_time = 0; - hb_ctrl.out_faults_en.sup_uvp = 0; - hb_ctrl.out_faults_en.sup_ovp = 0; - hb_ctrl.out_faults_en.sup_ocp = 1; - hb_ctrl.out_faults_en.sup_opp = 0; - hb_ctrl.out_faults_en.out_ovp = 1; - hb_ctrl.out_faults_en.out_ocp = 1; - hb_ctrl.out_faults_en.out_opp = 0; - hb_ctrl.out_faults_en.out_short = 1; - hb_ctrl.out_faults_en.out_open = 0; - hb_ctrl.out_fuse.state = FUSE_OFF; - hb_ctrl.out_fuse.count = 0; - hb_ctrl.out_fuse.timer = 0; - hb_ctrl.out_fuse_cfg.cooldown_time = 1000; - hb_ctrl.out_fuse_cfg.retry_time = 1000; - - meas.sup_voltage = 12000; - meas.sup_current = 100; - meas.sup_power = 1200; - meas.out_voltage = 0; - meas.out_current = 0; - meas.out_power = 0; - meas.out_impedance = 0xFFFF; - meas.low_side_ctrl = 1; - meas.pwm = 0; - - exp_low = 1; - exp_pwm = 0x7FFF; - - exp_hb_fb.analog.sup_voltage = meas.sup_voltage; - exp_hb_fb.analog.sup_current = meas.sup_current; - exp_hb_fb.analog.sup_power = meas.sup_power; - exp_hb_fb.analog.out_voltage = meas.out_voltage; - exp_hb_fb.analog.out_current = meas.out_current; - exp_hb_fb.analog.out_power = meas.out_power; - exp_hb_fb.analog.out_impedance = meas.out_impedance; - exp_hb_fb.analog.low_side_ctrl = meas.low_side_ctrl; - exp_hb_fb.analog.pwm = meas.pwm; - exp_hb_fb.enabled = 1; - exp_hb_fb.warning_act = 0; - exp_hb_fb.fault_act = 0; - exp_hb_fb.fused = 0; - exp_hb_fb.warnings.sup_uvp = 0; - exp_hb_fb.warnings.sup_ovp = 0; - exp_hb_fb.warnings.sup_ocp = 0; - exp_hb_fb.warnings.sup_opp = 0; - exp_hb_fb.warnings.out_ovp = 0; - exp_hb_fb.warnings.out_ocp = 0; - exp_hb_fb.warnings.out_opp = 0; - exp_hb_fb.warnings.out_short = 0; - exp_hb_fb.warnings.out_open = 0; - exp_hb_fb.faults.sup_uvp = 0; - exp_hb_fb.faults.sup_ovp = 0; - exp_hb_fb.faults.sup_ocp = 0; - exp_hb_fb.faults.sup_opp = 0; - exp_hb_fb.faults.out_ovp = 0; - exp_hb_fb.faults.out_ocp = 0; - exp_hb_fb.faults.out_opp = 0; - exp_hb_fb.faults.out_short = 0; - exp_hb_fb.faults.out_open = 0; - - exp_hb_ctrl.enabled = 1; - exp_hb_ctrl.out_faults.sup_uvp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.sup_uvp.w_time = 0; - exp_hb_ctrl.out_faults.sup_uvp.f_time = 0; - exp_hb_ctrl.out_faults.sup_ovp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.sup_ovp.w_time = 0; - exp_hb_ctrl.out_faults.sup_ovp.f_time = 0; - exp_hb_ctrl.out_faults.sup_ocp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.sup_ocp.w_time = 0; - exp_hb_ctrl.out_faults.sup_ocp.f_time = 0; - exp_hb_ctrl.out_faults.sup_opp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.sup_opp.w_time = 0; - exp_hb_ctrl.out_faults.sup_opp.f_time = 0; - exp_hb_ctrl.out_faults.out_ovp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.out_ovp.w_time = 0; - exp_hb_ctrl.out_faults.out_ovp.f_time = 0; - exp_hb_ctrl.out_faults.out_ocp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.out_ocp.w_time = 0; - exp_hb_ctrl.out_faults.out_ocp.f_time = 0; - exp_hb_ctrl.out_faults.out_opp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.out_opp.w_time = 0; - exp_hb_ctrl.out_faults.out_opp.f_time = 0; - exp_hb_ctrl.out_faults.out_short.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.out_short.w_time = 0; - exp_hb_ctrl.out_faults.out_short.f_time = 0; - exp_hb_ctrl.out_faults.out_open.severity = FAULT_LVL_WARNING; - exp_hb_ctrl.out_faults.out_open.w_time = 0; - exp_hb_ctrl.out_faults.out_open.f_time = 0; - exp_hb_ctrl.out_faults_en.sup_uvp = 0; - exp_hb_ctrl.out_faults_en.sup_ovp = 0; - exp_hb_ctrl.out_faults_en.sup_ocp = 1; - exp_hb_ctrl.out_faults_en.sup_opp = 0; - exp_hb_ctrl.out_faults_en.out_ovp = 1; - exp_hb_ctrl.out_faults_en.out_ocp = 1; - exp_hb_ctrl.out_faults_en.out_opp = 0; - exp_hb_ctrl.out_faults_en.out_short = 1; - exp_hb_ctrl.out_faults_en.out_open = 0; - exp_hb_ctrl.out_fuse.state = FUSE_OFF; - exp_hb_ctrl.out_fuse.count = 0; - exp_hb_ctrl.out_fuse.timer = 0; - exp_hb_ctrl.out_fuse_cfg.cooldown_time = 1000; - exp_hb_ctrl.out_fuse_cfg.retry_time = 1000; - - test_res = ut_hb_process(target, &hb_fb, &hb_ctrl, &meas, exp_low, exp_pwm, &exp_hb_fb, &exp_hb_ctrl); - if(!test_res) pass = 0; - - // -1 / Handbrake target - printf("----- -1 Handbarke target ------------------ \n"); - target = -1; - - hb_fb.analog.sup_voltage = 12000; - hb_fb.analog.sup_current = 100; - hb_fb.analog.sup_power = 1200; - hb_fb.analog.out_voltage = 0; - hb_fb.analog.out_current = 0; - hb_fb.analog.out_power = 0; - hb_fb.analog.out_impedance = 0xFFFF; - hb_fb.analog.low_side_ctrl = 1; - hb_fb.analog.pwm = 0; - hb_fb.enabled = 1; - hb_fb.warning_act = 0; - hb_fb.fault_act = 0; - hb_fb.fused = 0; - hb_fb.warnings.sup_uvp = 0; - hb_fb.warnings.sup_ovp = 0; - hb_fb.warnings.sup_ocp = 0; - hb_fb.warnings.sup_opp = 0; - hb_fb.warnings.out_ovp = 0; - hb_fb.warnings.out_ocp = 0; - hb_fb.warnings.out_opp = 0; - hb_fb.warnings.out_short = 0; - hb_fb.warnings.out_open = 0; - hb_fb.faults.sup_uvp = 0; - hb_fb.faults.sup_ovp = 0; - hb_fb.faults.sup_ocp = 0; - hb_fb.faults.sup_opp = 0; - hb_fb.faults.out_ovp = 0; - hb_fb.faults.out_ocp = 0; - hb_fb.faults.out_opp = 0; - hb_fb.faults.out_short = 0; - hb_fb.faults.out_open = 0; - - hb_ctrl.enabled = 1; - hb_ctrl.out_faults.sup_uvp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.sup_uvp.w_time = 0; - hb_ctrl.out_faults.sup_uvp.f_time = 0; - hb_ctrl.out_faults.sup_ovp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.sup_ovp.w_time = 0; - hb_ctrl.out_faults.sup_ovp.f_time = 0; - hb_ctrl.out_faults.sup_ocp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.sup_ocp.w_time = 0; - hb_ctrl.out_faults.sup_ocp.f_time = 0; - hb_ctrl.out_faults.sup_opp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.sup_opp.w_time = 0; - hb_ctrl.out_faults.sup_opp.f_time = 0; - hb_ctrl.out_faults.out_ovp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_ovp.w_time = 0; - hb_ctrl.out_faults.out_ovp.f_time = 0; - hb_ctrl.out_faults.out_ocp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_ocp.w_time = 0; - hb_ctrl.out_faults.out_ocp.f_time = 0; - hb_ctrl.out_faults.out_opp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_opp.w_time = 0; - hb_ctrl.out_faults.out_opp.f_time = 0; - hb_ctrl.out_faults.out_short.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_short.w_time = 0; - hb_ctrl.out_faults.out_short.f_time = 0; - hb_ctrl.out_faults.out_open.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_open.w_time = 0; - hb_ctrl.out_faults.out_open.f_time = 0; - hb_ctrl.out_faults_en.sup_uvp = 0; - hb_ctrl.out_faults_en.sup_ovp = 0; - hb_ctrl.out_faults_en.sup_ocp = 1; - hb_ctrl.out_faults_en.sup_opp = 0; - hb_ctrl.out_faults_en.out_ovp = 0; - hb_ctrl.out_faults_en.out_ocp = 1; - hb_ctrl.out_faults_en.out_opp = 0; - hb_ctrl.out_faults_en.out_short = 1; - hb_ctrl.out_faults_en.out_open = 0; - hb_ctrl.out_fuse.state = FUSE_OFF; - hb_ctrl.out_fuse.count = 0; - hb_ctrl.out_fuse.timer = 0; - hb_ctrl.out_fuse_cfg.cooldown_time = 1000; - hb_ctrl.out_fuse_cfg.retry_time = 1000; - - meas.sup_voltage = 12000; - meas.sup_current = 100; - meas.sup_power = 1200; - meas.out_voltage = 0; - meas.out_current = 0; - meas.out_power = 0; - meas.out_impedance = 0xFFFF; - meas.low_side_ctrl = 1; - meas.pwm = 0; - - exp_low = 0; - exp_pwm = 0; - - exp_hb_fb.analog.sup_voltage = meas.sup_voltage; - exp_hb_fb.analog.sup_current = meas.sup_current; - exp_hb_fb.analog.sup_power = meas.sup_power; - exp_hb_fb.analog.out_voltage = meas.out_voltage; - exp_hb_fb.analog.out_current = meas.out_current; - exp_hb_fb.analog.out_power = meas.out_power; - exp_hb_fb.analog.out_impedance = meas.out_impedance; - exp_hb_fb.analog.low_side_ctrl = meas.low_side_ctrl; - exp_hb_fb.analog.pwm = meas.pwm; - exp_hb_fb.enabled = 1; - exp_hb_fb.warning_act = 0; - exp_hb_fb.fault_act = 0; - exp_hb_fb.fused = 0; - exp_hb_fb.warnings.sup_uvp = 0; - exp_hb_fb.warnings.sup_ovp = 0; - exp_hb_fb.warnings.sup_ocp = 0; - exp_hb_fb.warnings.sup_opp = 0; - exp_hb_fb.warnings.out_ovp = 0; - exp_hb_fb.warnings.out_ocp = 0; - exp_hb_fb.warnings.out_opp = 0; - exp_hb_fb.warnings.out_short = 0; - exp_hb_fb.warnings.out_open = 0; - exp_hb_fb.faults.sup_uvp = 0; - exp_hb_fb.faults.sup_ovp = 0; - exp_hb_fb.faults.sup_ocp = 0; - exp_hb_fb.faults.sup_opp = 0; - exp_hb_fb.faults.out_ovp = 0; - exp_hb_fb.faults.out_ocp = 0; - exp_hb_fb.faults.out_opp = 0; - exp_hb_fb.faults.out_short = 0; - exp_hb_fb.faults.out_open = 0; - - exp_hb_ctrl.enabled = 1; - exp_hb_ctrl.out_faults.sup_uvp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.sup_uvp.w_time = 0; - exp_hb_ctrl.out_faults.sup_uvp.f_time = 0; - exp_hb_ctrl.out_faults.sup_ovp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.sup_ovp.w_time = 0; - exp_hb_ctrl.out_faults.sup_ovp.f_time = 0; - exp_hb_ctrl.out_faults.sup_ocp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.sup_ocp.w_time = 0; - exp_hb_ctrl.out_faults.sup_ocp.f_time = 0; - exp_hb_ctrl.out_faults.sup_opp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.sup_opp.w_time = 0; - exp_hb_ctrl.out_faults.sup_opp.f_time = 0; - exp_hb_ctrl.out_faults.out_ovp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.out_ovp.w_time = 0; - exp_hb_ctrl.out_faults.out_ovp.f_time = 0; - exp_hb_ctrl.out_faults.out_ocp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.out_ocp.w_time = 0; - exp_hb_ctrl.out_faults.out_ocp.f_time = 0; - exp_hb_ctrl.out_faults.out_opp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.out_opp.w_time = 0; - exp_hb_ctrl.out_faults.out_opp.f_time = 0; - exp_hb_ctrl.out_faults.out_short.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.out_short.w_time = 0; - exp_hb_ctrl.out_faults.out_short.f_time = 0; - exp_hb_ctrl.out_faults.out_open.severity = FAULT_LVL_WARNING; - exp_hb_ctrl.out_faults.out_open.w_time = 0; - exp_hb_ctrl.out_faults.out_open.f_time = 0; - exp_hb_ctrl.out_faults_en.sup_uvp = 0; - exp_hb_ctrl.out_faults_en.sup_ovp = 0; - exp_hb_ctrl.out_faults_en.sup_ocp = 1; - exp_hb_ctrl.out_faults_en.sup_opp = 0; - exp_hb_ctrl.out_faults_en.out_ovp = 0; - exp_hb_ctrl.out_faults_en.out_ocp = 1; - exp_hb_ctrl.out_faults_en.out_opp = 0; - exp_hb_ctrl.out_faults_en.out_short = 0; - exp_hb_ctrl.out_faults_en.out_open = 0; - exp_hb_ctrl.out_fuse.state = FUSE_OFF; - exp_hb_ctrl.out_fuse.count = 0; - exp_hb_ctrl.out_fuse.timer = 0; - exp_hb_ctrl.out_fuse_cfg.cooldown_time = 1000; - exp_hb_ctrl.out_fuse_cfg.retry_time = 1000; - - test_res = ut_hb_process(target, &hb_fb, &hb_ctrl, &meas, exp_low, exp_pwm, &exp_hb_fb, &exp_hb_ctrl); - if(!test_res) pass = 0; - - // Warnings 1 - printf("----- Warning 1 ------------------ \n"); - target = 1000; - - hb_fb.analog.sup_voltage = 12000; - hb_fb.analog.sup_current = 100; - hb_fb.analog.sup_power = 1200; - hb_fb.analog.out_voltage = 0; - hb_fb.analog.out_current = 0; - hb_fb.analog.out_power = 0; - hb_fb.analog.out_impedance = 0xFFFF; - hb_fb.analog.low_side_ctrl = 1; - hb_fb.analog.pwm = 0; - hb_fb.enabled = 1; - hb_fb.warning_act = 0; - hb_fb.fault_act = 0; - hb_fb.fused = 0; - hb_fb.warnings.sup_uvp = 0; - hb_fb.warnings.sup_ovp = 0; - hb_fb.warnings.sup_ocp = 0; - hb_fb.warnings.sup_opp = 0; - hb_fb.warnings.out_ovp = 0; - hb_fb.warnings.out_ocp = 0; - hb_fb.warnings.out_opp = 0; - hb_fb.warnings.out_short = 0; - hb_fb.warnings.out_open = 0; - hb_fb.faults.sup_uvp = 0; - hb_fb.faults.sup_ovp = 0; - hb_fb.faults.sup_ocp = 0; - hb_fb.faults.sup_opp = 0; - hb_fb.faults.out_ovp = 0; - hb_fb.faults.out_ocp = 0; - hb_fb.faults.out_opp = 0; - hb_fb.faults.out_short = 0; - hb_fb.faults.out_open = 0; - - hb_ctrl.enabled = 1; - hb_ctrl.out_faults.sup_uvp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.sup_uvp.w_time = 0; - hb_ctrl.out_faults.sup_uvp.f_time = 0; - hb_ctrl.out_faults.sup_ovp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.sup_ovp.w_time = 0; - hb_ctrl.out_faults.sup_ovp.f_time = 0; - hb_ctrl.out_faults.sup_ocp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.sup_ocp.w_time = 0; - hb_ctrl.out_faults.sup_ocp.f_time = 0; - hb_ctrl.out_faults.sup_opp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.sup_opp.w_time = 0; - hb_ctrl.out_faults.sup_opp.f_time = 0; - hb_ctrl.out_faults.out_ovp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_ovp.w_time = 0; - hb_ctrl.out_faults.out_ovp.f_time = 0; - hb_ctrl.out_faults.out_ocp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_ocp.w_time = 0; - hb_ctrl.out_faults.out_ocp.f_time = 0; - hb_ctrl.out_faults.out_opp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_opp.w_time = 0; - hb_ctrl.out_faults.out_opp.f_time = 0; - hb_ctrl.out_faults.out_short.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_short.w_time = 0; - hb_ctrl.out_faults.out_short.f_time = 0; - hb_ctrl.out_faults.out_open.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_open.w_time = 0; - hb_ctrl.out_faults.out_open.f_time = 0; - hb_ctrl.out_faults_en.sup_uvp = 1; - hb_ctrl.out_faults_en.sup_ovp = 1; - hb_ctrl.out_faults_en.sup_ocp = 1; - hb_ctrl.out_faults_en.sup_opp = 1; - hb_ctrl.out_faults_en.out_ovp = 1; - hb_ctrl.out_faults_en.out_ocp = 1; - hb_ctrl.out_faults_en.out_opp = 1; - hb_ctrl.out_faults_en.out_short = 1; - hb_ctrl.out_faults_en.out_open = 1; - hb_ctrl.out_fuse.state = FUSE_OFF; - hb_ctrl.out_fuse.count = 0; - hb_ctrl.out_fuse.timer = 0; - hb_ctrl.out_fuse_cfg.cooldown_time = 1000; - hb_ctrl.out_fuse_cfg.retry_time = 1000; - - meas.sup_voltage = HW_HB_SUPPLY_VOLT_MAX_W+1000; - meas.sup_current = HW_HB_SUPPLY_CURRENT_MAX_W+1000; - meas.sup_power = HW_HB_SUPPLY_POWER_MAX_W+1000; - meas.out_voltage = HW_HB_OUT_VOLTAGE_MAX_W+1000; - meas.out_current = HW_HB_OUT_CURRENT_MAX_W+1000; - meas.out_power = HW_HB_OUT_POWER_MAX_W+1000; - meas.out_impedance = HW_HB_OUT_RESISTANCE_MIN_W-50; - meas.low_side_ctrl = 1; - meas.pwm = 0xFF00; - - exp_low = 1; - exp_pwm = 3855; - - exp_hb_fb.analog.sup_voltage = meas.sup_voltage; - exp_hb_fb.analog.sup_current = meas.sup_current; - exp_hb_fb.analog.sup_power = meas.sup_power; - exp_hb_fb.analog.out_voltage = meas.out_voltage; - exp_hb_fb.analog.out_current = meas.out_current; - exp_hb_fb.analog.out_power = meas.out_power; - exp_hb_fb.analog.out_impedance = meas.out_impedance; - exp_hb_fb.analog.low_side_ctrl = meas.low_side_ctrl; - exp_hb_fb.analog.pwm = meas.pwm; - exp_hb_fb.enabled = 1; - exp_hb_fb.warning_act = 1; - exp_hb_fb.fault_act = 0; - exp_hb_fb.fused = 0; - exp_hb_fb.warnings.sup_uvp = 0; - exp_hb_fb.warnings.sup_ovp = 1; - exp_hb_fb.warnings.sup_ocp = 1; - exp_hb_fb.warnings.sup_opp = 1; - exp_hb_fb.warnings.out_ovp = 1; - exp_hb_fb.warnings.out_ocp = 1; - exp_hb_fb.warnings.out_opp = 1; - exp_hb_fb.warnings.out_short = 1; - exp_hb_fb.warnings.out_open = 0; - exp_hb_fb.faults.sup_uvp = 0; - exp_hb_fb.faults.sup_ovp = 0; - exp_hb_fb.faults.sup_ocp = 0; - exp_hb_fb.faults.sup_opp = 0; - exp_hb_fb.faults.out_ovp = 0; - exp_hb_fb.faults.out_ocp = 0; - exp_hb_fb.faults.out_opp = 0; - exp_hb_fb.faults.out_short = 0; - exp_hb_fb.faults.out_open = 0; - - exp_hb_ctrl.enabled = 1; - exp_hb_ctrl.out_faults.sup_uvp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.sup_uvp.w_time = 0; - exp_hb_ctrl.out_faults.sup_uvp.f_time = 0; - exp_hb_ctrl.out_faults.sup_ovp.severity = FAULT_LVL_WARNING; - exp_hb_ctrl.out_faults.sup_ovp.w_time = 0; - exp_hb_ctrl.out_faults.sup_ovp.f_time = 0; - exp_hb_ctrl.out_faults.sup_ocp.severity = FAULT_LVL_WARNING; - exp_hb_ctrl.out_faults.sup_ocp.w_time = 0; - exp_hb_ctrl.out_faults.sup_ocp.f_time = 0; - exp_hb_ctrl.out_faults.sup_opp.severity = FAULT_LVL_WARNING; - exp_hb_ctrl.out_faults.sup_opp.w_time = 0; - exp_hb_ctrl.out_faults.sup_opp.f_time = 0; - exp_hb_ctrl.out_faults.out_ovp.severity = FAULT_LVL_WARNING; - exp_hb_ctrl.out_faults.out_ovp.w_time = 0; - exp_hb_ctrl.out_faults.out_ovp.f_time = 0; - exp_hb_ctrl.out_faults.out_ocp.severity = FAULT_LVL_WARNING; - exp_hb_ctrl.out_faults.out_ocp.w_time = 0; - exp_hb_ctrl.out_faults.out_ocp.f_time = 0; - exp_hb_ctrl.out_faults.out_opp.severity = FAULT_LVL_WARNING; - exp_hb_ctrl.out_faults.out_opp.w_time = 0; - exp_hb_ctrl.out_faults.out_opp.f_time = 0; - exp_hb_ctrl.out_faults.out_short.severity = FAULT_LVL_WARNING; - exp_hb_ctrl.out_faults.out_short.w_time = 0; - exp_hb_ctrl.out_faults.out_short.f_time = 0; - exp_hb_ctrl.out_faults.out_open.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.out_open.w_time = 0; - exp_hb_ctrl.out_faults.out_open.f_time = 0; - exp_hb_ctrl.out_faults_en.sup_uvp = 1; - exp_hb_ctrl.out_faults_en.sup_ovp = 1; - exp_hb_ctrl.out_faults_en.sup_ocp = 1; - exp_hb_ctrl.out_faults_en.sup_opp = 1; - exp_hb_ctrl.out_faults_en.out_ovp = 1; - exp_hb_ctrl.out_faults_en.out_ocp = 1; - exp_hb_ctrl.out_faults_en.out_opp = 1; - exp_hb_ctrl.out_faults_en.out_short = 1; - exp_hb_ctrl.out_faults_en.out_open = 1; - exp_hb_ctrl.out_fuse.state = FUSE_OFF; - exp_hb_ctrl.out_fuse.count = 0; - exp_hb_ctrl.out_fuse.timer = 0; - exp_hb_ctrl.out_fuse_cfg.cooldown_time = 1000; - exp_hb_ctrl.out_fuse_cfg.retry_time = 1000; - - test_res = ut_hb_process(target, &hb_fb, &hb_ctrl, &meas, exp_low, exp_pwm, &exp_hb_fb, &exp_hb_ctrl); - if(!test_res) pass = 0; - - // Warnings 2 - printf("----- Warning 2 ------------------ \n"); - target = 5000; - - hb_fb.analog.sup_voltage = 12000; - hb_fb.analog.sup_current = 100; - hb_fb.analog.sup_power = 1200; - hb_fb.analog.out_voltage = 0; - hb_fb.analog.out_current = 0; - hb_fb.analog.out_power = 0; - hb_fb.analog.out_impedance = 0xFFFF; - hb_fb.analog.low_side_ctrl = 1; - hb_fb.analog.pwm = 0; - hb_fb.enabled = 1; - hb_fb.warning_act = 0; - hb_fb.fault_act = 0; - hb_fb.fused = 0; - hb_fb.warnings.sup_uvp = 0; - hb_fb.warnings.sup_ovp = 0; - hb_fb.warnings.sup_ocp = 0; - hb_fb.warnings.sup_opp = 0; - hb_fb.warnings.out_ovp = 0; - hb_fb.warnings.out_ocp = 0; - hb_fb.warnings.out_opp = 0; - hb_fb.warnings.out_short = 0; - hb_fb.warnings.out_open = 0; - hb_fb.faults.sup_uvp = 0; - hb_fb.faults.sup_ovp = 0; - hb_fb.faults.sup_ocp = 0; - hb_fb.faults.sup_opp = 0; - hb_fb.faults.out_ovp = 0; - hb_fb.faults.out_ocp = 0; - hb_fb.faults.out_opp = 0; - hb_fb.faults.out_short = 0; - hb_fb.faults.out_open = 0; - - hb_ctrl.enabled = 1; - hb_ctrl.out_faults.sup_uvp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.sup_uvp.w_time = 0; - hb_ctrl.out_faults.sup_uvp.f_time = 0; - hb_ctrl.out_faults.sup_ovp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.sup_ovp.w_time = 0; - hb_ctrl.out_faults.sup_ovp.f_time = 0; - hb_ctrl.out_faults.sup_ocp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.sup_ocp.w_time = 0; - hb_ctrl.out_faults.sup_ocp.f_time = 0; - hb_ctrl.out_faults.sup_opp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.sup_opp.w_time = 0; - hb_ctrl.out_faults.sup_opp.f_time = 0; - hb_ctrl.out_faults.out_ovp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_ovp.w_time = 0; - hb_ctrl.out_faults.out_ovp.f_time = 0; - hb_ctrl.out_faults.out_ocp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_ocp.w_time = 0; - hb_ctrl.out_faults.out_ocp.f_time = 0; - hb_ctrl.out_faults.out_opp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_opp.w_time = 0; - hb_ctrl.out_faults.out_opp.f_time = 0; - hb_ctrl.out_faults.out_short.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_short.w_time = 0; - hb_ctrl.out_faults.out_short.f_time = 0; - hb_ctrl.out_faults.out_open.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_open.w_time = 0; - hb_ctrl.out_faults.out_open.f_time = 0; - hb_ctrl.out_faults_en.sup_uvp = 1; - hb_ctrl.out_faults_en.sup_ovp = 1; - hb_ctrl.out_faults_en.sup_ocp = 1; - hb_ctrl.out_faults_en.sup_opp = 1; - hb_ctrl.out_faults_en.out_ovp = 1; - hb_ctrl.out_faults_en.out_ocp = 1; - hb_ctrl.out_faults_en.out_opp = 1; - hb_ctrl.out_faults_en.out_short = 1; - hb_ctrl.out_faults_en.out_open = 1; - hb_ctrl.out_fuse.state = FUSE_OFF; - hb_ctrl.out_fuse.count = 0; - hb_ctrl.out_fuse.timer = 0; - hb_ctrl.out_fuse_cfg.cooldown_time = 1000; - hb_ctrl.out_fuse_cfg.retry_time = 1000; - - meas.sup_voltage = HW_HB_SUPPLY_VOLT_MIN_W-1000; - meas.sup_current = HW_HB_SUPPLY_CURRENT_MAX_W+1000; - meas.sup_power = HW_HB_SUPPLY_POWER_MAX_W+1000; - meas.out_voltage = HW_HB_OUT_VOLTAGE_MAX_W+1000; - meas.out_current = HW_HB_OUT_CURRENT_MAX_W+1000; - meas.out_power = HW_HB_OUT_POWER_MAX_W+1000; - meas.out_impedance = HW_HB_OUT_RESISTANCE_MAX_W+50; - meas.low_side_ctrl = 1; - meas.pwm = 0xFF00; - - exp_low = 1; - exp_pwm = 36408; - - exp_hb_fb.analog.sup_voltage = meas.sup_voltage; - exp_hb_fb.analog.sup_current = meas.sup_current; - exp_hb_fb.analog.sup_power = meas.sup_power; - exp_hb_fb.analog.out_voltage = meas.out_voltage; - exp_hb_fb.analog.out_current = meas.out_current; - exp_hb_fb.analog.out_power = meas.out_power; - exp_hb_fb.analog.out_impedance = meas.out_impedance; - exp_hb_fb.analog.low_side_ctrl = meas.low_side_ctrl; - exp_hb_fb.analog.pwm = meas.pwm; - exp_hb_fb.enabled = 1; - exp_hb_fb.warning_act = 1; - exp_hb_fb.fault_act = 0; - exp_hb_fb.fused = 0; - exp_hb_fb.warnings.sup_uvp = 1; - exp_hb_fb.warnings.sup_ovp = 0; - exp_hb_fb.warnings.sup_ocp = 1; - exp_hb_fb.warnings.sup_opp = 1; - exp_hb_fb.warnings.out_ovp = 1; - exp_hb_fb.warnings.out_ocp = 1; - exp_hb_fb.warnings.out_opp = 1; - exp_hb_fb.warnings.out_short = 0; - exp_hb_fb.warnings.out_open = 1; - exp_hb_fb.faults.sup_uvp = 0; - exp_hb_fb.faults.sup_ovp = 0; - exp_hb_fb.faults.sup_ocp = 0; - exp_hb_fb.faults.sup_opp = 0; - exp_hb_fb.faults.out_ovp = 0; - exp_hb_fb.faults.out_ocp = 0; - exp_hb_fb.faults.out_opp = 0; - exp_hb_fb.faults.out_short = 0; - exp_hb_fb.faults.out_open = 0; - - exp_hb_ctrl.enabled = 1; - exp_hb_ctrl.out_faults.sup_uvp.severity = FAULT_LVL_WARNING; - exp_hb_ctrl.out_faults.sup_uvp.w_time = 0; - exp_hb_ctrl.out_faults.sup_uvp.f_time = 0; - exp_hb_ctrl.out_faults.sup_ovp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.sup_ovp.w_time = 0; - exp_hb_ctrl.out_faults.sup_ovp.f_time = 0; - exp_hb_ctrl.out_faults.sup_ocp.severity = FAULT_LVL_WARNING; - exp_hb_ctrl.out_faults.sup_ocp.w_time = 0; - exp_hb_ctrl.out_faults.sup_ocp.f_time = 0; - exp_hb_ctrl.out_faults.sup_opp.severity = FAULT_LVL_WARNING; - exp_hb_ctrl.out_faults.sup_opp.w_time = 0; - exp_hb_ctrl.out_faults.sup_opp.f_time = 0; - exp_hb_ctrl.out_faults.out_ovp.severity = FAULT_LVL_WARNING; - exp_hb_ctrl.out_faults.out_ovp.w_time = 0; - exp_hb_ctrl.out_faults.out_ovp.f_time = 0; - exp_hb_ctrl.out_faults.out_ocp.severity = FAULT_LVL_WARNING; - exp_hb_ctrl.out_faults.out_ocp.w_time = 0; - exp_hb_ctrl.out_faults.out_ocp.f_time = 0; - exp_hb_ctrl.out_faults.out_opp.severity = FAULT_LVL_WARNING; - exp_hb_ctrl.out_faults.out_opp.w_time = 0; - exp_hb_ctrl.out_faults.out_opp.f_time = 0; - exp_hb_ctrl.out_faults.out_short.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.out_short.w_time = 0; - exp_hb_ctrl.out_faults.out_short.f_time = 0; - exp_hb_ctrl.out_faults.out_open.severity = FAULT_LVL_WARNING; - exp_hb_ctrl.out_faults.out_open.w_time = 0; - exp_hb_ctrl.out_faults.out_open.f_time = 0; - exp_hb_ctrl.out_faults_en.sup_uvp = 1; - exp_hb_ctrl.out_faults_en.sup_ovp = 1; - exp_hb_ctrl.out_faults_en.sup_ocp = 1; - exp_hb_ctrl.out_faults_en.sup_opp = 1; - exp_hb_ctrl.out_faults_en.out_ovp = 1; - exp_hb_ctrl.out_faults_en.out_ocp = 1; - exp_hb_ctrl.out_faults_en.out_opp = 1; - exp_hb_ctrl.out_faults_en.out_short = 1; - exp_hb_ctrl.out_faults_en.out_open = 1; - exp_hb_ctrl.out_fuse.state = FUSE_OFF; - exp_hb_ctrl.out_fuse.count = 0; - exp_hb_ctrl.out_fuse.timer = 0; - exp_hb_ctrl.out_fuse_cfg.cooldown_time = 1000; - exp_hb_ctrl.out_fuse_cfg.retry_time = 1000; - - test_res = ut_hb_process(target, &hb_fb, &hb_ctrl, &meas, exp_low, exp_pwm, &exp_hb_fb, &exp_hb_ctrl); - if(!test_res) pass = 0; - - // Faults 1 - printf("----- Faults 1 first sample ------------------ \n"); - target = 2500; - - hb_fb.analog.sup_voltage = 12000; - hb_fb.analog.sup_current = 100; - hb_fb.analog.sup_power = 1200; - hb_fb.analog.out_voltage = 0; - hb_fb.analog.out_current = 0; - hb_fb.analog.out_power = 0; - hb_fb.analog.out_impedance = 0xFFFF; - hb_fb.analog.low_side_ctrl = 1; - hb_fb.analog.pwm = 0; - hb_fb.enabled = 1; - hb_fb.warning_act = 0; - hb_fb.fault_act = 0; - hb_fb.fused = 0; - hb_fb.warnings.sup_uvp = 0; - hb_fb.warnings.sup_ovp = 0; - hb_fb.warnings.sup_ocp = 0; - hb_fb.warnings.sup_opp = 0; - hb_fb.warnings.out_ovp = 0; - hb_fb.warnings.out_ocp = 0; - hb_fb.warnings.out_opp = 0; - hb_fb.warnings.out_short = 0; - hb_fb.warnings.out_open = 0; - hb_fb.faults.sup_uvp = 0; - hb_fb.faults.sup_ovp = 0; - hb_fb.faults.sup_ocp = 0; - hb_fb.faults.sup_opp = 0; - hb_fb.faults.out_ovp = 0; - hb_fb.faults.out_ocp = 0; - hb_fb.faults.out_opp = 0; - hb_fb.faults.out_short = 0; - hb_fb.faults.out_open = 0; - - hb_ctrl.enabled = 1; - hb_ctrl.out_faults.sup_uvp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.sup_uvp.w_time = 0; - hb_ctrl.out_faults.sup_uvp.f_time = 0; - hb_ctrl.out_faults.sup_ovp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.sup_ovp.w_time = 0; - hb_ctrl.out_faults.sup_ovp.f_time = 0; - hb_ctrl.out_faults.sup_ocp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.sup_ocp.w_time = 0; - hb_ctrl.out_faults.sup_ocp.f_time = 0; - hb_ctrl.out_faults.sup_opp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.sup_opp.w_time = 0; - hb_ctrl.out_faults.sup_opp.f_time = 0; - hb_ctrl.out_faults.out_ovp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_ovp.w_time = 0; - hb_ctrl.out_faults.out_ovp.f_time = 0; - hb_ctrl.out_faults.out_ocp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_ocp.w_time = 0; - hb_ctrl.out_faults.out_ocp.f_time = 0; - hb_ctrl.out_faults.out_opp.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_opp.w_time = 0; - hb_ctrl.out_faults.out_opp.f_time = 0; - hb_ctrl.out_faults.out_short.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_short.w_time = 0; - hb_ctrl.out_faults.out_short.f_time = 0; - hb_ctrl.out_faults.out_open.severity = FAULT_LVL_OK; - hb_ctrl.out_faults.out_open.w_time = 0; - hb_ctrl.out_faults.out_open.f_time = 0; - hb_ctrl.out_faults_en.sup_uvp = 1; - hb_ctrl.out_faults_en.sup_ovp = 1; - hb_ctrl.out_faults_en.sup_ocp = 1; - hb_ctrl.out_faults_en.sup_opp = 1; - hb_ctrl.out_faults_en.out_ovp = 1; - hb_ctrl.out_faults_en.out_ocp = 1; - hb_ctrl.out_faults_en.out_opp = 1; - hb_ctrl.out_faults_en.out_short = 1; - hb_ctrl.out_faults_en.out_open = 1; - hb_ctrl.out_fuse.state = FUSE_OFF; - hb_ctrl.out_fuse.count = 0; - hb_ctrl.out_fuse.timer = 0; - hb_ctrl.out_fuse_cfg.cooldown_time = 1000; - hb_ctrl.out_fuse_cfg.retry_time = 1000; - - meas.sup_voltage = 20000; - meas.sup_current = 10000; - meas.sup_power = 50000; - meas.out_voltage = 12000; - meas.out_current = 10000; - meas.out_power = 50000; - meas.out_impedance = 200; - meas.low_side_ctrl = 1; - meas.pwm = 0xFF00; - - exp_low = 1; - exp_pwm = 8191; - - exp_hb_fb.analog.sup_voltage = meas.sup_voltage; - exp_hb_fb.analog.sup_current = meas.sup_current; - exp_hb_fb.analog.sup_power = meas.sup_power; - exp_hb_fb.analog.out_voltage = meas.out_voltage; - exp_hb_fb.analog.out_current = meas.out_current; - exp_hb_fb.analog.out_power = meas.out_power; - exp_hb_fb.analog.out_impedance = meas.out_impedance; - exp_hb_fb.analog.low_side_ctrl = meas.low_side_ctrl; - exp_hb_fb.analog.pwm = meas.pwm; - exp_hb_fb.enabled = 1; - exp_hb_fb.warning_act = 1; - exp_hb_fb.fault_act = 0; - exp_hb_fb.fused = 0; - exp_hb_fb.warnings.sup_uvp = 0; - exp_hb_fb.warnings.sup_ovp = 1; - exp_hb_fb.warnings.sup_ocp = 1; - exp_hb_fb.warnings.sup_opp = 1; - exp_hb_fb.warnings.out_ovp = 1; - exp_hb_fb.warnings.out_ocp = 1; - exp_hb_fb.warnings.out_opp = 1; - exp_hb_fb.warnings.out_short = 1; - exp_hb_fb.warnings.out_open = 0; - exp_hb_fb.faults.sup_uvp = 0; - exp_hb_fb.faults.sup_ovp = 0; - exp_hb_fb.faults.sup_ocp = 0; - exp_hb_fb.faults.sup_opp = 0; - exp_hb_fb.faults.out_ovp = 0; - exp_hb_fb.faults.out_ocp = 0; - exp_hb_fb.faults.out_opp = 0; - exp_hb_fb.faults.out_short = 0; - exp_hb_fb.faults.out_open = 0; - - exp_hb_ctrl.enabled = 1; - exp_hb_ctrl.out_faults.sup_uvp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.sup_uvp.w_time = 0; - exp_hb_ctrl.out_faults.sup_uvp.f_time = 0; - exp_hb_ctrl.out_faults.sup_ovp.severity = FAULT_LVL_WARNING; - exp_hb_ctrl.out_faults.sup_ovp.w_time = 0; - exp_hb_ctrl.out_faults.sup_ovp.f_time = 0; - exp_hb_ctrl.out_faults.sup_ocp.severity = FAULT_LVL_WARNING; - exp_hb_ctrl.out_faults.sup_ocp.w_time = 0; - exp_hb_ctrl.out_faults.sup_ocp.f_time = 0; - exp_hb_ctrl.out_faults.sup_opp.severity = FAULT_LVL_WARNING; - exp_hb_ctrl.out_faults.sup_opp.w_time = 0; - exp_hb_ctrl.out_faults.sup_opp.f_time = 0; - exp_hb_ctrl.out_faults.out_ovp.severity = FAULT_LVL_WARNING; - exp_hb_ctrl.out_faults.out_ovp.w_time = 0; - exp_hb_ctrl.out_faults.out_ovp.f_time = 0; - exp_hb_ctrl.out_faults.out_ocp.severity = FAULT_LVL_WARNING; - exp_hb_ctrl.out_faults.out_ocp.w_time = 0; - exp_hb_ctrl.out_faults.out_ocp.f_time = 0; - exp_hb_ctrl.out_faults.out_opp.severity = FAULT_LVL_WARNING; - exp_hb_ctrl.out_faults.out_opp.w_time = 0; - exp_hb_ctrl.out_faults.out_opp.f_time = 0; - exp_hb_ctrl.out_faults.out_short.severity = FAULT_LVL_WARNING; - exp_hb_ctrl.out_faults.out_short.w_time = 0; - exp_hb_ctrl.out_faults.out_short.f_time = 0; - exp_hb_ctrl.out_faults.out_open.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.out_open.w_time = 0; - exp_hb_ctrl.out_faults.out_open.f_time = 0; - exp_hb_ctrl.out_faults_en.sup_uvp = 1; - exp_hb_ctrl.out_faults_en.sup_ovp = 1; - exp_hb_ctrl.out_faults_en.sup_ocp = 1; - exp_hb_ctrl.out_faults_en.sup_opp = 1; - exp_hb_ctrl.out_faults_en.out_ovp = 1; - exp_hb_ctrl.out_faults_en.out_ocp = 1; - exp_hb_ctrl.out_faults_en.out_opp = 1; - exp_hb_ctrl.out_faults_en.out_short = 1; - exp_hb_ctrl.out_faults_en.out_open = 1; - exp_hb_ctrl.out_fuse.state = FUSE_OFF; - exp_hb_ctrl.out_fuse.count = 0; - exp_hb_ctrl.out_fuse.timer = 0; - exp_hb_ctrl.out_fuse_cfg.cooldown_time = 1000; - exp_hb_ctrl.out_fuse_cfg.retry_time = 1000; - - test_res = ut_hb_process(target, &hb_fb, &hb_ctrl, &meas, exp_low, exp_pwm, &exp_hb_fb, &exp_hb_ctrl); - if(!test_res) pass = 0; - - // Faults 1 - printf("----- Faults 1 transition sample ------------------ \n"); - target = 2500; - - hb_fb.analog.sup_voltage = 12000; - hb_fb.analog.sup_current = 100; - hb_fb.analog.sup_power = 1200; - hb_fb.analog.out_voltage = 0; - hb_fb.analog.out_current = 0; - hb_fb.analog.out_power = 0; - hb_fb.analog.out_impedance = 0xFFFF; - hb_fb.analog.low_side_ctrl = 1; - hb_fb.analog.pwm = 0; - hb_fb.enabled = 1; - hb_fb.warning_act = 0; - hb_fb.fault_act = 0; - hb_fb.fused = 0; - hb_fb.warnings.sup_uvp = 0; - hb_fb.warnings.sup_ovp = 0; - hb_fb.warnings.sup_ocp = 0; - hb_fb.warnings.sup_opp = 0; - hb_fb.warnings.out_ovp = 0; - hb_fb.warnings.out_ocp = 0; - hb_fb.warnings.out_opp = 0; - hb_fb.warnings.out_short = 0; - hb_fb.warnings.out_open = 0; - hb_fb.faults.sup_uvp = 0; - hb_fb.faults.sup_ovp = 0; - hb_fb.faults.sup_ocp = 0; - hb_fb.faults.sup_opp = 0; - hb_fb.faults.out_ovp = 0; - hb_fb.faults.out_ocp = 0; - hb_fb.faults.out_opp = 0; - hb_fb.faults.out_short = 0; - hb_fb.faults.out_open = 0; - - hb_ctrl.enabled = 1; - hb_ctrl.out_faults.sup_uvp.severity = FAULT_LVL_WARNING; - hb_ctrl.out_faults.sup_uvp.w_time = 499; - hb_ctrl.out_faults.sup_uvp.f_time = 499; - hb_ctrl.out_faults.sup_ovp.severity = FAULT_LVL_WARNING; - hb_ctrl.out_faults.sup_ovp.w_time = 499; - hb_ctrl.out_faults.sup_ovp.f_time = 499; - hb_ctrl.out_faults.sup_ocp.severity = FAULT_LVL_WARNING; - hb_ctrl.out_faults.sup_ocp.w_time = 499; - hb_ctrl.out_faults.sup_ocp.f_time = 499; - hb_ctrl.out_faults.sup_opp.severity = FAULT_LVL_WARNING; - hb_ctrl.out_faults.sup_opp.w_time = 499; - hb_ctrl.out_faults.sup_opp.f_time = 499; - hb_ctrl.out_faults.out_ovp.severity = FAULT_LVL_WARNING; - hb_ctrl.out_faults.out_ovp.w_time = 499; - hb_ctrl.out_faults.out_ovp.f_time = 499; - hb_ctrl.out_faults.out_ocp.severity = FAULT_LVL_WARNING; - hb_ctrl.out_faults.out_ocp.w_time = 499; - hb_ctrl.out_faults.out_ocp.f_time = 499; - hb_ctrl.out_faults.out_opp.severity = FAULT_LVL_WARNING; - hb_ctrl.out_faults.out_opp.w_time = 499; - hb_ctrl.out_faults.out_opp.f_time = 499; - hb_ctrl.out_faults.out_short.severity = FAULT_LVL_WARNING; - hb_ctrl.out_faults.out_short.w_time = 499; - hb_ctrl.out_faults.out_short.f_time = 499; - hb_ctrl.out_faults.out_open.severity = FAULT_LVL_WARNING; - hb_ctrl.out_faults.out_open.w_time = 499; - hb_ctrl.out_faults.out_open.f_time = 499; - hb_ctrl.out_faults_en.sup_uvp = 1; - hb_ctrl.out_faults_en.sup_ovp = 1; - hb_ctrl.out_faults_en.sup_ocp = 1; - hb_ctrl.out_faults_en.sup_opp = 1; - hb_ctrl.out_faults_en.out_ovp = 1; - hb_ctrl.out_faults_en.out_ocp = 1; - hb_ctrl.out_faults_en.out_opp = 1; - hb_ctrl.out_faults_en.out_short = 1; - hb_ctrl.out_faults_en.out_open = 1; - hb_ctrl.out_fuse.state = FUSE_OFF; - hb_ctrl.out_fuse.count = 0; - hb_ctrl.out_fuse.timer = 0; - hb_ctrl.out_fuse_cfg.cooldown_time = 1000; - hb_ctrl.out_fuse_cfg.retry_time = 1000; - - meas.sup_voltage = 20000; - meas.sup_current = 10000; - meas.sup_power = 50000; - meas.out_voltage = 12000; - meas.out_current = 10000; - meas.out_power = 50000; - meas.out_impedance = 200; - meas.low_side_ctrl = 1; - meas.pwm = 0xFF00; - - exp_low = 0; - exp_pwm = 0; - - exp_hb_fb.analog.sup_voltage = meas.sup_voltage; - exp_hb_fb.analog.sup_current = meas.sup_current; - exp_hb_fb.analog.sup_power = meas.sup_power; - exp_hb_fb.analog.out_voltage = meas.out_voltage; - exp_hb_fb.analog.out_current = meas.out_current; - exp_hb_fb.analog.out_power = meas.out_power; - exp_hb_fb.analog.out_impedance = meas.out_impedance; - exp_hb_fb.analog.low_side_ctrl = meas.low_side_ctrl; - exp_hb_fb.analog.pwm = meas.pwm; - exp_hb_fb.enabled = 1; - exp_hb_fb.warning_act = 0; - exp_hb_fb.fault_act = 1; - exp_hb_fb.fused = 1; - exp_hb_fb.warnings.sup_uvp = 0; - exp_hb_fb.warnings.sup_ovp = 0; - exp_hb_fb.warnings.sup_ocp = 0; - exp_hb_fb.warnings.sup_opp = 0; - exp_hb_fb.warnings.out_ovp = 0; - exp_hb_fb.warnings.out_ocp = 0; - exp_hb_fb.warnings.out_opp = 0; - exp_hb_fb.warnings.out_short = 0; - exp_hb_fb.warnings.out_open = 0; - exp_hb_fb.faults.sup_uvp = 0; - exp_hb_fb.faults.sup_ovp = 1; - exp_hb_fb.faults.sup_ocp = 1; - exp_hb_fb.faults.sup_opp = 1; - exp_hb_fb.faults.out_ovp = 1; - exp_hb_fb.faults.out_ocp = 1; - exp_hb_fb.faults.out_opp = 1; - exp_hb_fb.faults.out_short = 1; - exp_hb_fb.faults.out_open = 0; - - exp_hb_ctrl.enabled = 1; - exp_hb_ctrl.out_faults.sup_uvp.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.sup_uvp.w_time = 0; - exp_hb_ctrl.out_faults.sup_uvp.f_time = 0; - exp_hb_ctrl.out_faults.sup_ovp.severity = FAULT_LVL_FAULT; - exp_hb_ctrl.out_faults.sup_ovp.w_time = 500; - exp_hb_ctrl.out_faults.sup_ovp.f_time = 500; - exp_hb_ctrl.out_faults.sup_ocp.severity = FAULT_LVL_FAULT; - exp_hb_ctrl.out_faults.sup_ocp.w_time = 500; - exp_hb_ctrl.out_faults.sup_ocp.f_time = 500; - exp_hb_ctrl.out_faults.sup_opp.severity = FAULT_LVL_FAULT; - exp_hb_ctrl.out_faults.sup_opp.w_time = 500; - exp_hb_ctrl.out_faults.sup_opp.f_time = 500; - exp_hb_ctrl.out_faults.out_ovp.severity = FAULT_LVL_FAULT; - exp_hb_ctrl.out_faults.out_ovp.w_time = 500; - exp_hb_ctrl.out_faults.out_ovp.f_time = 500; - exp_hb_ctrl.out_faults.out_ocp.severity = FAULT_LVL_FAULT; - exp_hb_ctrl.out_faults.out_ocp.w_time = 500; - exp_hb_ctrl.out_faults.out_ocp.f_time = 500; - exp_hb_ctrl.out_faults.out_opp.severity = FAULT_LVL_FAULT; - exp_hb_ctrl.out_faults.out_opp.w_time = 500; - exp_hb_ctrl.out_faults.out_opp.f_time = 500; - exp_hb_ctrl.out_faults.out_short.severity = FAULT_LVL_FAULT; - exp_hb_ctrl.out_faults.out_short.w_time = 500; - exp_hb_ctrl.out_faults.out_short.f_time = 500; - exp_hb_ctrl.out_faults.out_open.severity = FAULT_LVL_OK; - exp_hb_ctrl.out_faults.out_open.w_time = 0; - exp_hb_ctrl.out_faults.out_open.f_time = 0; - exp_hb_ctrl.out_faults_en.sup_uvp = 1; - exp_hb_ctrl.out_faults_en.sup_ovp = 1; - exp_hb_ctrl.out_faults_en.sup_ocp = 1; - exp_hb_ctrl.out_faults_en.sup_opp = 1; - exp_hb_ctrl.out_faults_en.out_ovp = 1; - exp_hb_ctrl.out_faults_en.out_ocp = 1; - exp_hb_ctrl.out_faults_en.out_opp = 1; - exp_hb_ctrl.out_faults_en.out_short = 1; - exp_hb_ctrl.out_faults_en.out_open = 1; - exp_hb_ctrl.out_fuse.state = FUSE_ACTIVE; - exp_hb_ctrl.out_fuse.count = 1; - exp_hb_ctrl.out_fuse.timer = 0; - exp_hb_ctrl.out_fuse_cfg.cooldown_time = 1000; - exp_hb_ctrl.out_fuse_cfg.retry_time = 1000; - - test_res = ut_hb_process(target, &hb_fb, &hb_ctrl, &meas, exp_low, exp_pwm, &exp_hb_fb, &exp_hb_ctrl); - if(!test_res) pass = 0; - - return pass; -} diff --git a/firmware/tests/ut_hw/ut_hb_control.h b/firmware/tests/ut_hw/ut_hb_control.h deleted file mode 100644 index 5dbc2d4..0000000 --- a/firmware/tests/ut_hw/ut_hb_control.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef UT_HW_HB_CONTROL_H_ -#define UT_HW_HB_CONTROL_H_ - -#include -#include - -int ut_hb_is_equal_fb_struct_test(void); -int ut_hb_is_equal_ctrl_struct_test(void); - -int ut_hb_init_test(void); -int ut_hb_enable_test(void); -int ut_hb_disable_test(void); -int ut_hb_process_test(void); - -#endif /* UT_HW_HB_CONTROL_H_ */ diff --git a/firmware/tests/ut_hw/ut_led_display.c b/firmware/tests/ut_hw/ut_led_display.c deleted file mode 100644 index cce012d..0000000 --- a/firmware/tests/ut_hw/ut_led_display.c +++ /dev/null @@ -1,170 +0,0 @@ -#include "ut_led_display.h" - -#include "..\mock_board\mock_board_odout.h" - -#include "..\..\src\hw\led_display.h" - -static uint8_t NOT_ACCESD_OD_CHANNEL = 255; -static uint8_t NOT_ACCESD_OD_LEVEL = BSP_ODOUT_HIGH; -static uint8_t NOT_ACCESD_PERCENT = 255; - -static int ut_led_dsp_set_image(uint8_t image, uint8_t exp_image) -{ - printf(" Input:%x \n", image); - - // Reset image - mock_board_odout_write_ch(NOT_ACCESD_OD_CHANNEL); - mock_board_odout_write_data(BSP_OD1,NOT_ACCESD_OD_LEVEL); - mock_board_odout_write_data(BSP_OD2,NOT_ACCESD_OD_LEVEL); - mock_board_odout_write_data(BSP_OD3,NOT_ACCESD_OD_LEVEL); - mock_board_odout_write_data(BSP_OD4,NOT_ACCESD_OD_LEVEL); - mock_board_odout_write_data(BSP_OD5,NOT_ACCESD_OD_LEVEL); - mock_board_odout_write_data(BSP_OD6,NOT_ACCESD_OD_LEVEL); - - led_dsp_set_image(image); - - // Read set OD output image - uint8_t i1 = mock_board_odout_read_data(BSP_OD1); - uint8_t i2 = mock_board_odout_read_data(BSP_OD2); - uint8_t i3 = mock_board_odout_read_data(BSP_OD3); - uint8_t i4 = mock_board_odout_read_data(BSP_OD4); - uint8_t i5 = mock_board_odout_read_data(BSP_OD5); - uint8_t i6 = mock_board_odout_read_data(BSP_OD6); - - uint8_t out_image = 0x00; - if(i1==BSP_ODOUT_LOW) out_image |= 0x01; - if(i2==BSP_ODOUT_LOW) out_image |= 0x02; - if(i3==BSP_ODOUT_LOW) out_image |= 0x04; - if(i4==BSP_ODOUT_LOW) out_image |= 0x08; - if(i5==BSP_ODOUT_LOW) out_image |= 0x10; - if(i6==BSP_ODOUT_LOW) out_image |= 0x20; - - printf(" Output:%x \n", out_image); - printf("Expected:%x \n", exp_image); - - if(out_image==exp_image) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_led_dsp_set_image_test(void) -{ - printf("******************************************************\n"); - printf("void led_dsp_set_image(uint8_t image) \n"); - - int test_res; - int pass = 1; - - uint8_t image; - uint8_t exp_image; - - // Normal 1 - image = 0x00; - exp_image = 0x00; - test_res = ut_led_dsp_set_image(image, exp_image); - if(!test_res) pass = 0; - - // Normal 1 - image = 0x3F; - exp_image = 0x3F; - test_res = ut_led_dsp_set_image(image, exp_image); - if(!test_res) pass = 0; - - // Normal 1 - image = 0xAA; - exp_image = 0x2A; - test_res = ut_led_dsp_set_image(image, exp_image); - if(!test_res) pass = 0; - - // Normal 1 - image = 0x55; - exp_image = 0x15; - test_res = ut_led_dsp_set_image(image, exp_image); - if(!test_res) pass = 0; - - return pass; -} - -static int ut_led_dsp_backligth_set(uint8_t percent, uint8_t exp_percent) -{ - printf(" Input:%d \n", percent); - - // Reset image - mock_board_odout_write_pwm(NOT_ACCESD_PERCENT); - - led_dsp_backligth_set(percent); - - // Read set OD output image - uint8_t pwm = mock_board_odout_read_pwm(); - - printf(" Output:%d \n", pwm); - printf("Expected:%d \n", exp_percent); - - if(pwm==exp_percent) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_led_dsp_backligth_set_test(void) -{ - printf("******************************************************\n"); - printf("void led_dsp_backligth_set(uint8_t percent) \n"); - - int test_res; - int pass = 1; - - uint8_t percent; - uint8_t exp_percent; - - // Normal 1 - percent = 0; - exp_percent = 0; - test_res = ut_led_dsp_backligth_set(percent, exp_percent); - if(!test_res) pass = 0; - - // Normal 1 - percent = 25; - exp_percent = 25; - test_res = ut_led_dsp_backligth_set(percent, exp_percent); - if(!test_res) pass = 0; - - // Normal 1 - percent = 50; - exp_percent = 50; - test_res = ut_led_dsp_backligth_set(percent, exp_percent); - if(!test_res) pass = 0; - - // Normal 1 - percent = 75; - exp_percent = 75; - test_res = ut_led_dsp_backligth_set(percent, exp_percent); - if(!test_res) pass = 0; - - // Normal 1 - percent = 100; - exp_percent = 100; - test_res = ut_led_dsp_backligth_set(percent, exp_percent); - if(!test_res) pass = 0; - - // Normal 1 - percent = 200; - exp_percent = 200; - test_res = ut_led_dsp_backligth_set(percent, exp_percent); - if(!test_res) pass = 0; - - return pass; -} diff --git a/firmware/tests/ut_hw/ut_led_display.h b/firmware/tests/ut_hw/ut_led_display.h deleted file mode 100644 index 0f345c8..0000000 --- a/firmware/tests/ut_hw/ut_led_display.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef UT_HW_LED_DISPLAY_H_ -#define UT_HW_LED_DISPLAY_H_ - -#include -#include - -int ut_led_dsp_set_image_test(void); -int ut_led_dsp_backligth_set_test(void); - -#endif /* UT_HW_LED_DISPLAY_H_ */ diff --git a/firmware/tests/ut_hw/ut_startup.c b/firmware/tests/ut_hw/ut_startup.c deleted file mode 100644 index 81ad1f8..0000000 --- a/firmware/tests/ut_hw/ut_startup.c +++ /dev/null @@ -1,48 +0,0 @@ -#include "ut_startup.h" - -#include "..\mock_board\mock_board_setup.h" - -#include "..\..\src\hw\startup.h" - -static int ut_hw_startup(uint8_t exp_called) -{ - printf(" Input: \n"); - - mock_board_setup_reset_called(); - - hw_startup(); - - uint8_t called = mock_board_setup_read_called(); - - printf(" Output: Called:%d \n", called); - printf("Expected: Called:%d \n", exp_called); - - if(called==exp_called) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_hw_startup_test(void) -{ - printf("******************************************************\n"); - printf("void hw_startup(void) \n"); - - int test_res; - int pass = 1; - - uint8_t exp_called; - - // Normal 1 - exp_called = 1; - test_res = ut_hw_startup(exp_called); - if(!test_res) pass = 0; - - return pass; -} diff --git a/firmware/tests/ut_hw/ut_startup.h b/firmware/tests/ut_hw/ut_startup.h deleted file mode 100644 index 27e45af..0000000 --- a/firmware/tests/ut_hw/ut_startup.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef UT_HW_STARTUP_H_ -#define UT_HW_STARTUP_H_ - -#include -#include - -int ut_hw_startup_test(void); - -#endif /* UT_HW_STARTUP_H_ */ diff --git a/firmware/tests/ut_logic/ut_coil.c b/firmware/tests/ut_logic/ut_coil.c deleted file mode 100644 index cc47e1f..0000000 --- a/firmware/tests/ut_logic/ut_coil.c +++ /dev/null @@ -1,86 +0,0 @@ -#include "ut_coil.h" -#include "..\..\src\logic\coil.h" - -static int ut_coil_target(uint8_t force, uint8_t hbrake_act, int16_t exp_out) -{ - int16_t out = coil_target(force, hbrake_act); - - printf("Force:%d Handbrake:%d \n", force, hbrake_act); - printf("Output:%d Expected:%d\n", out, exp_out); - - if(out==exp_out) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_coil_target_test(void) -{ - printf("******************************************************\n"); - printf("int16_t coil_target(uint8_t force, uint8_t hbrake_act)\n"); - - int test_res; - int pass = 1; - - uint8_t force; - uint8_t hbrake; - - int16_t exp_out; - - force = 0; - hbrake = 0; - exp_out = 0; - test_res = ut_coil_target(force, hbrake, exp_out); - if(!test_res) pass = 0; - - force = 50; - hbrake = 0; - exp_out = COIL_LOCK_VOLTAGE/2; - test_res = ut_coil_target(force, hbrake, exp_out); - if(!test_res) pass = 0; - - force = 100; - hbrake = 0; - exp_out = COIL_LOCK_VOLTAGE; - test_res = ut_coil_target(force, hbrake, exp_out); - if(!test_res) pass = 0; - - force = 255; - hbrake = 0; - exp_out = COIL_LOCK_VOLTAGE; - test_res = ut_coil_target(force, hbrake, exp_out); - if(!test_res) pass = 0; - - force = 0; - hbrake = 1; - exp_out = COIL_TARGET_HANDBRAKE; - test_res = ut_coil_target(force, hbrake, exp_out); - if(!test_res) pass = 0; - - force = 50; - hbrake = 1; - exp_out = COIL_TARGET_HANDBRAKE; - test_res = ut_coil_target(force, hbrake, exp_out); - if(!test_res) pass = 0; - - force = 100; - hbrake = 1; - exp_out = COIL_TARGET_HANDBRAKE; - test_res = ut_coil_target(force, hbrake, exp_out); - if(!test_res) pass = 0; - - force = 255; - hbrake = 1; - exp_out = COIL_TARGET_HANDBRAKE; - test_res = ut_coil_target(force, hbrake, exp_out); - if(!test_res) pass = 0; - - return pass; -} - diff --git a/firmware/tests/ut_logic/ut_coil.h b/firmware/tests/ut_logic/ut_coil.h deleted file mode 100644 index c2109a6..0000000 --- a/firmware/tests/ut_logic/ut_coil.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef UT_COIL_H_ -#define UT_COIL_H_ - -#include -#include - -int ut_coil_target_test(void); - -#endif /* UT_COIL_H_ */ diff --git a/firmware/tests/ut_logic/ut_display.c b/firmware/tests/ut_logic/ut_display.c deleted file mode 100644 index 7bf489e..0000000 --- a/firmware/tests/ut_logic/ut_display.c +++ /dev/null @@ -1,552 +0,0 @@ -#include "ut_display.h" -#include "..\..\src\logic\display.h" - -static const uint8_t BACKLIGHT_DIMM = DSP_BACKLIGHT_DIMM_PERCENT; -static const uint8_t BACKLIGHT_BRIGTH = DSP_BACKLIGHT_BRIGTH_PERCENT; - -static int ut_dsp_init_ctrl(dsp_ctrl_t* ctrl, dsp_ctrl_t* exp_ctrl) -{ - printf(" Input: lock:%d act-image:%x \n", ctrl->img_lock, ctrl->act_img); - - dsp_init_ctrl(ctrl); - - printf(" Output: lock:%d act-image:%x \n", ctrl->img_lock, ctrl->act_img); - printf("Expected: lock:%d act-image:%x \n", exp_ctrl->img_lock, exp_ctrl->act_img); - - if((ctrl->img_lock==exp_ctrl->img_lock)&&(ctrl->act_img==exp_ctrl->act_img)) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_dsp_init_ctrl_test(void) -{ - printf("******************************************************\n"); - printf("void dsp_init_ctrl(dsp_ctrl_t* ctrl) \n"); - - int test_res; - int pass = 1; - - dsp_ctrl_t ctrl; - dsp_ctrl_t exp_ctrl; - - ctrl.img_lock = 0; - ctrl.act_img = 0; - exp_ctrl.img_lock = 0; - exp_ctrl.act_img = 0x00; - test_res = ut_dsp_init_ctrl(&ctrl, &exp_ctrl); - if(!test_res) pass = 0; - - ctrl.img_lock = 1; - ctrl.act_img = 0xAA; - exp_ctrl.img_lock = 0; - exp_ctrl.act_img = 0x00; - test_res = ut_dsp_init_ctrl(&ctrl, &exp_ctrl); - if(!test_res) pass = 0; - - return pass; -} - -static int ut_dsp_set_lock(dsp_ctrl_t* ctrl, dsp_ctrl_t* exp_ctrl) -{ - printf(" Input: lock:%d act-image:%x \n", ctrl->img_lock, ctrl->act_img); - - dsp_set_lock(ctrl); - - printf(" Output: lock:%d act-image:%x \n", ctrl->img_lock, ctrl->act_img); - printf("Expected: lock:%d act-image:%x \n", exp_ctrl->img_lock, exp_ctrl->act_img); - - if((ctrl->img_lock==exp_ctrl->img_lock)&&(ctrl->act_img==exp_ctrl->act_img)) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_dsp_set_lock_test(void) -{ - printf("******************************************************\n"); - printf("void dsp_set_lock(dsp_ctrl_t* ctrl)\n"); - - int test_res; - int pass = 1; - - dsp_ctrl_t ctrl; - dsp_ctrl_t exp_ctrl; - - ctrl.img_lock = 0; - ctrl.act_img = 0x18; - exp_ctrl.img_lock = 1; - exp_ctrl.act_img = 0x18; - test_res = ut_dsp_set_lock(&ctrl, &exp_ctrl); - if(!test_res) pass = 0; - - ctrl.img_lock = 1; - ctrl.act_img = 0x3F; - exp_ctrl.img_lock = 1; - exp_ctrl.act_img = 0x3F; - test_res = ut_dsp_set_lock(&ctrl, &exp_ctrl); - if(!test_res) pass = 0; - - return pass; -} - -static int ut_dsp_reset_lock(dsp_ctrl_t* ctrl, dsp_ctrl_t* exp_ctrl) -{ - printf(" Input: lock:%d act-image:%x \n", ctrl->img_lock, ctrl->act_img); - - dsp_reset_lock(ctrl); - - printf(" Output: lock:%d act-image:%x \n", ctrl->img_lock, ctrl->act_img); - printf("Expected: lock:%d act-image:%x \n", exp_ctrl->img_lock, exp_ctrl->act_img); - - if((ctrl->img_lock==exp_ctrl->img_lock)&&(ctrl->act_img==exp_ctrl->act_img)) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_dsp_reset_lock_test(void) -{ - printf("******************************************************\n"); - printf("void dsp_reset_lock(dsp_ctrl_t* ctrl)\n"); - - int test_res; - int pass = 1; - - dsp_ctrl_t ctrl; - dsp_ctrl_t exp_ctrl; - - ctrl.img_lock = 0; - ctrl.act_img = 0x18; - exp_ctrl.img_lock = 0; - exp_ctrl.act_img = 0x18; - test_res = ut_dsp_reset_lock(&ctrl, &exp_ctrl); - if(!test_res) pass = 0; - - ctrl.img_lock = 1; - ctrl.act_img = 0x18; - exp_ctrl.img_lock = 0; - exp_ctrl.act_img = 0x18; - test_res = ut_dsp_reset_lock(&ctrl, &exp_ctrl); - if(!test_res) pass = 0; - - return pass; -} - -static int ut_dsp_img_percent(uint8_t value, dsp_style_t style, dsp_ctrl_t* ctrl, uint8_t exp_out, dsp_ctrl_t* exp_ctrl) -{ - printf(" Input: Percent:%d Style:%d lock:%d act-image:%x \n", value, style, ctrl->img_lock, ctrl->act_img); - - uint8_t out = dsp_img_percent(value, style, ctrl); - - printf(" Output: image:%x lock:%d act-image:%x \n", out, ctrl->img_lock, ctrl->act_img); - printf("Expected: image:%x lock:%d act-image:%x \n", exp_out, exp_ctrl->img_lock, exp_ctrl->act_img); - - if((out==exp_out)&&(ctrl->img_lock==exp_ctrl->img_lock)&&(ctrl->act_img==exp_ctrl->act_img)) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_dsp_img_percent_test(void) -{ - printf("******************************************************\n"); - printf("uint8_t dsp_img_percent(uint8_t value, dsp_style_t style, dsp_ctrl_t* ctrl)\n"); - - int test_res; - int pass = 1; - - uint8_t value; - dsp_style_t style; - dsp_ctrl_t ctrl; - uint8_t exp_out; - dsp_ctrl_t exp_ctrl; - - // Test lock - value = 50; - style = LED_DSP_BAR; - ctrl.img_lock = 1; - ctrl.act_img = 0x2A; - exp_out = 0x2A; - exp_ctrl.img_lock = ctrl.img_lock; - exp_ctrl.act_img = exp_out; - test_res = ut_dsp_img_percent(value, style, &ctrl, exp_out, &exp_ctrl); - if(!test_res) pass = 0; - - // Test styles - value = 50; - style = LED_DSP_BAR; - ctrl.img_lock = 0; - ctrl.act_img = 0x00; - exp_out = 0x07; - exp_ctrl.img_lock = ctrl.img_lock; - exp_ctrl.act_img = exp_out; - test_res = ut_dsp_img_percent(value, style, &ctrl, exp_out, &exp_ctrl); - if(!test_res) pass = 0; - - // Test styles - value = 50; - style = LED_DSP_DOT20; - ctrl.img_lock = 0; - ctrl.act_img = 0x00; - exp_out = 0x04; - exp_ctrl.img_lock = ctrl.img_lock; - exp_ctrl.act_img = exp_out; - test_res = ut_dsp_img_percent(value, style, &ctrl, exp_out, &exp_ctrl); - if(!test_res) pass = 0; - - // Test styles - value = 50; - style = LED_DSP_DOT10; - ctrl.img_lock = 0; - ctrl.act_img = 0x00; - exp_out = 0x0C; - exp_ctrl.img_lock = ctrl.img_lock; - exp_ctrl.act_img = exp_out; - test_res = ut_dsp_img_percent(value, style, &ctrl, exp_out, &exp_ctrl); - if(!test_res) pass = 0; - - // Test values - value = 0; - style = LED_DSP_DOT10; - ctrl.img_lock = 0; - ctrl.act_img = 0x00; - exp_out = 0x01; - exp_ctrl.img_lock = ctrl.img_lock; - exp_ctrl.act_img = exp_out; - test_res = ut_dsp_img_percent(value, style, &ctrl, exp_out, &exp_ctrl); - if(!test_res) pass = 0; - - // Test values - value = 10; - style = LED_DSP_DOT10; - ctrl.img_lock = 0; - ctrl.act_img = 0x00; - exp_out = 0x03; - exp_ctrl.img_lock = ctrl.img_lock; - exp_ctrl.act_img = exp_out; - test_res = ut_dsp_img_percent(value, style, &ctrl, exp_out, &exp_ctrl); - if(!test_res) pass = 0; - - // Test values - value = 20; - style = LED_DSP_DOT10; - ctrl.img_lock = 0; - ctrl.act_img = 0x00; - exp_out = 0x02; - exp_ctrl.img_lock = ctrl.img_lock; - exp_ctrl.act_img = exp_out; - test_res = ut_dsp_img_percent(value, style, &ctrl, exp_out, &exp_ctrl); - if(!test_res) pass = 0; - - // Test values - value = 30; - style = LED_DSP_DOT10; - ctrl.img_lock = 0; - ctrl.act_img = 0x00; - exp_out = 0x06; - exp_ctrl.img_lock = ctrl.img_lock; - exp_ctrl.act_img = exp_out; - test_res = ut_dsp_img_percent(value, style, &ctrl, exp_out, &exp_ctrl); - if(!test_res) pass = 0; - - // Test values - value = 40; - style = LED_DSP_DOT10; - ctrl.img_lock = 0; - ctrl.act_img = 0x00; - exp_out = 0x04; - exp_ctrl.img_lock = ctrl.img_lock; - exp_ctrl.act_img = exp_out; - test_res = ut_dsp_img_percent(value, style, &ctrl, exp_out, &exp_ctrl); - if(!test_res) pass = 0; - - // Test values - value = 50; - style = LED_DSP_DOT10; - ctrl.img_lock = 0; - ctrl.act_img = 0x00; - exp_out = 0x0C; - exp_ctrl.img_lock = ctrl.img_lock; - exp_ctrl.act_img = exp_out; - test_res = ut_dsp_img_percent(value, style, &ctrl, exp_out, &exp_ctrl); - if(!test_res) pass = 0; - - // Test values - value = 60; - style = LED_DSP_DOT10; - ctrl.img_lock = 0; - ctrl.act_img = 0x00; - exp_out = 0x08; - exp_ctrl.img_lock = ctrl.img_lock; - exp_ctrl.act_img = exp_out; - test_res = ut_dsp_img_percent(value, style, &ctrl, exp_out, &exp_ctrl); - if(!test_res) pass = 0; - - // Test values - value = 80; - style = LED_DSP_DOT10; - ctrl.img_lock = 0; - ctrl.act_img = 0x00; - exp_out = 0x10; - exp_ctrl.img_lock = ctrl.img_lock; - exp_ctrl.act_img = exp_out; - test_res = ut_dsp_img_percent(value, style, &ctrl, exp_out, &exp_ctrl); - if(!test_res) pass = 0; - - // Test values - value = 90; - style = LED_DSP_DOT10; - ctrl.img_lock = 0; - ctrl.act_img = 0x00; - exp_out = 0x30; - exp_ctrl.img_lock = ctrl.img_lock; - exp_ctrl.act_img = exp_out; - test_res = ut_dsp_img_percent(value, style, &ctrl, exp_out, &exp_ctrl); - if(!test_res) pass = 0; - - // Test values - value = 110; - style = LED_DSP_DOT10; - ctrl.img_lock = 0; - ctrl.act_img = 0x00; - exp_out = 0x20; - exp_ctrl.img_lock = ctrl.img_lock; - exp_ctrl.act_img = exp_out; - test_res = ut_dsp_img_percent(value, style, &ctrl, exp_out, &exp_ctrl); - if(!test_res) pass = 0; - - return pass; -} - -static int ut_dsp_img_raw(uint8_t image, dsp_ctrl_t* ctrl, uint8_t exp_out, dsp_ctrl_t* exp_ctrl) -{ - printf(" Input: Image:%x lock:%d act-image:%x \n", image, ctrl->img_lock, ctrl->act_img); - - uint8_t out = dsp_img_raw(image, ctrl); - - printf(" Output: image:%x lock:%d act-image:%x \n", out, ctrl->img_lock, ctrl->act_img); - printf("Expected: image:%x lock:%d act-image:%x \n", exp_out, exp_ctrl->img_lock, exp_ctrl->act_img); - - if((out==exp_out)&&(ctrl->img_lock==exp_ctrl->img_lock)&&(ctrl->act_img==exp_ctrl->act_img)) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_dsp_img_raw_test(void) -{ - printf("******************************************************\n"); - printf("uint8_t dsp_img_raw(int8_t image, dsp_ctrl_t* ctrl)\n"); - - int test_res; - int pass = 1; - - uint8_t image; - dsp_ctrl_t ctrl; - uint8_t exp_out; - dsp_ctrl_t exp_ctrl; - - // Test lock - image = 0x17; - ctrl.img_lock = 1; - ctrl.act_img = 0x2A; - exp_out = 0x2A; - exp_ctrl.img_lock = ctrl.img_lock; - exp_ctrl.act_img = exp_out; - test_res = ut_dsp_img_raw(image, &ctrl, exp_out, &exp_ctrl); - if(!test_res) pass = 0; - - // Test normal - image = 0x17; - ctrl.img_lock = 0; - ctrl.act_img = 0x00; - exp_out = 0x17; - exp_ctrl.img_lock = ctrl.img_lock; - exp_ctrl.act_img = exp_out; - test_res = ut_dsp_img_raw(image, &ctrl, exp_out, &exp_ctrl); - if(!test_res) pass = 0; - - // Test limit - image = 0xAA; - ctrl.img_lock = 0; - ctrl.act_img = 0x00; - exp_out = 0x2A; - exp_ctrl.img_lock = ctrl.img_lock; - exp_ctrl.act_img = exp_out; - test_res = ut_dsp_img_raw(image, &ctrl, exp_out, &exp_ctrl); - if(!test_res) pass = 0; - - // Test limit - image = 0xCC; - ctrl.img_lock = 0; - ctrl.act_img = 0x00; - exp_out = 0x0C; - exp_ctrl.img_lock = ctrl.img_lock; - exp_ctrl.act_img = exp_out; - test_res = ut_dsp_img_raw(image, &ctrl, exp_out, &exp_ctrl); - if(!test_res) pass = 0; - - return pass; -} - -static int ut_dsp_get_act_img(dsp_ctrl_t* ctrl, uint8_t exp_out, dsp_ctrl_t* exp_ctrl) -{ - printf(" Input: lock:%d act-image:%x \n", ctrl->img_lock, ctrl->act_img); - - uint8_t out = dsp_get_act_img(ctrl); - - printf(" Output: image:%x lock:%d act-image:%x \n", out, ctrl->img_lock, ctrl->act_img); - printf("Expected: image:%x lock:%d act-image:%x \n", exp_out, exp_ctrl->img_lock, exp_ctrl->act_img); - - if((out==exp_out)&&(ctrl->img_lock==exp_ctrl->img_lock)&&(ctrl->act_img==exp_ctrl->act_img)) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_dsp_get_act_img_test(void) -{ - printf("******************************************************\n"); - printf("uint8_t dsp_get_act_img(void)\n"); - - int test_res; - int pass = 1; - - dsp_ctrl_t ctrl; - uint8_t exp_out; - dsp_ctrl_t exp_ctrl; - - // Test - ctrl.img_lock = 0; - ctrl.act_img = 0x2A; - exp_out = 0x2A; - exp_ctrl.img_lock = ctrl.img_lock; - exp_ctrl.act_img = exp_out; - test_res = ut_dsp_get_act_img(&ctrl, exp_out, &exp_ctrl); - if(!test_res) pass = 0; - - // Test - ctrl.img_lock = 1; - ctrl.act_img = 0x3F; - exp_out = 0x3F; - exp_ctrl.img_lock = ctrl.img_lock; - exp_ctrl.act_img = exp_out; - test_res = ut_dsp_get_act_img(&ctrl, exp_out, &exp_ctrl); - if(!test_res) pass = 0; - - return pass; -} - -static int ut_dsp_backlight(uint8_t dimm_act, dsp_ctrl_t* ctrl, uint8_t exp_out, dsp_ctrl_t* exp_ctrl) -{ - printf(" Input: dimm-act:%d lock:%d act-image:%x \n", dimm_act, ctrl->img_lock, ctrl->act_img); - - uint8_t out = dsp_backlight(dimm_act); - - printf(" Output: percent:%x lock:%d act-image:%x \n", out, ctrl->img_lock, ctrl->act_img); - printf("Expected: percent:%x lock:%d act-image:%x \n", exp_out, exp_ctrl->img_lock, exp_ctrl->act_img); - - if((out==exp_out)&&(ctrl->img_lock==exp_ctrl->img_lock)&&(ctrl->act_img==exp_ctrl->act_img)) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_dsp_backlight_test(void) -{ - printf("******************************************************\n"); - printf("uint8_t dsp_backlight(uint8_t dimm_act)\n"); - - int test_res; - int pass = 1; - - uint8_t dimm_act; - dsp_ctrl_t ctrl; - uint8_t exp_out; - dsp_ctrl_t exp_ctrl; - - // Test - dimm_act = 0; - ctrl.img_lock = 0; - ctrl.act_img = 0x2A; - exp_out = DSP_BACKLIGHT_BRIGTH_PERCENT; - exp_ctrl.img_lock = ctrl.img_lock; - exp_ctrl.act_img = ctrl.act_img; - test_res = ut_dsp_backlight(dimm_act, &ctrl, exp_out, &exp_ctrl); - if(!test_res) pass = 0; - - // Test - dimm_act = 1; - ctrl.img_lock = 0; - ctrl.act_img = 0x2A; - exp_out = DSP_BACKLIGHT_DIMM_PERCENT; - exp_ctrl.img_lock = ctrl.img_lock; - exp_ctrl.act_img = ctrl.act_img; - test_res = ut_dsp_backlight(dimm_act, &ctrl, exp_out, &exp_ctrl); - if(!test_res) pass = 0; - - // Test lock ignore - dimm_act = 0; - ctrl.img_lock = 1; - ctrl.act_img = 0x2A; - exp_out = DSP_BACKLIGHT_BRIGTH_PERCENT; - exp_ctrl.img_lock = ctrl.img_lock; - exp_ctrl.act_img = ctrl.act_img; - test_res = ut_dsp_backlight(dimm_act, &ctrl, exp_out, &exp_ctrl); - if(!test_res) pass = 0; - - // Test lock ignore - dimm_act = 1; - ctrl.img_lock = 1; - ctrl.act_img = 0x2A; - exp_out = DSP_BACKLIGHT_DIMM_PERCENT; - exp_ctrl.img_lock = ctrl.img_lock; - exp_ctrl.act_img = ctrl.act_img; - test_res = ut_dsp_backlight(dimm_act, &ctrl, exp_out, &exp_ctrl); - if(!test_res) pass = 0; - - return pass; -} diff --git a/firmware/tests/ut_logic/ut_display.h b/firmware/tests/ut_logic/ut_display.h deleted file mode 100644 index d085252..0000000 --- a/firmware/tests/ut_logic/ut_display.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef UT_DISPLAY_H_ -#define UT_DISPLAY_H_ - -#include -#include -int ut_dsp_init_ctrl_test(void); - -int ut_dsp_set_lock_test(void); -int ut_dsp_reset_lock_test(void); - -int ut_dsp_img_percent_test(void); - -int ut_dsp_img_raw_test(void); - -int ut_dsp_get_act_img_test(void); - -int ut_dsp_backlight_test(void); - -#endif /* UT_DISPLAY_H_ */ diff --git a/firmware/tests/ut_logic/ut_force.c b/firmware/tests/ut_logic/ut_force.c deleted file mode 100644 index 5820e58..0000000 --- a/firmware/tests/ut_logic/ut_force.c +++ /dev/null @@ -1,170 +0,0 @@ -#include "ut_force.h" -#include "..\..\src\logic\force.h" - -static int ut_force_cycle_bmode(fbrake_mode_t bmode, fbrake_mode_t exp_out) -{ - fbrake_mode_t out = force_cycle_bmode(bmode); - - printf("Brake mode:%d\n", bmode); - printf("Output:%d Expected:%d\n", out, exp_out); - - if(out==exp_out) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_force_cycle_bmode_test(void) -{ - printf("******************************************************\n"); - printf("fbrake_mode_t force_cycle_bmode(fbrake_mode_t bmode)\n"); - - int test_res; - int pass = 1; - - fbrake_mode_t bmode; - - fbrake_mode_t exp_out; - - bmode = FORCE_BMODE_OPEN; - exp_out = FORCE_BMODE_KEEP; - test_res = ut_force_cycle_bmode(bmode,exp_out); - if(!test_res) pass = 0; - - bmode = FORCE_BMODE_KEEP; - exp_out = FORCE_BMODE_LOCK; - test_res = ut_force_cycle_bmode(bmode,exp_out); - if(!test_res) pass = 0; - - bmode = FORCE_BMODE_LOCK; - exp_out = FORCE_BMODE_OPEN; - test_res = ut_force_cycle_bmode(bmode,exp_out); - if(!test_res) pass = 0; - - return pass; -} - -static int ut_force_next(uint8_t handbrake, uint8_t brakes, fbrake_mode_t bmode, uint8_t user_force, uint16_t hbarke_act_time, uint8_t exp_out) -{ - uint8_t out = force_next(handbrake, brakes, bmode, user_force, hbarke_act_time); - - printf("Handbrake:%d Brakes:%d Brake-Mode:%d User-Force:%d Handbrake-time:%d\n", handbrake, brakes, bmode, user_force, hbarke_act_time); - printf("Output:%d Expected:%d\n", out, exp_out); - - if(out==exp_out) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_force_next_test(void) -{ - printf("******************************************************\n"); - printf("uint8_t force_next(uint8_t handbrake, uint8_t brakes, fbrake_mode_t bmode, uint8_t user_force, uint16_t hbarke_act_time)\n"); - - int test_res; - int pass = 1; - - uint8_t handbrake; - uint8_t brakes; - fbrake_mode_t bmode; - uint8_t user_force; - uint16_t hbarke_act_time; - - uint8_t exp_out; - - handbrake = 0; - brakes = 0; - bmode = FORCE_BMODE_OPEN; - user_force = 0; - hbarke_act_time = 0; - exp_out = 0; - test_res = ut_force_next(handbrake, brakes, bmode, user_force, hbarke_act_time, exp_out); - if(!test_res) pass = 0; - - handbrake = 0; - brakes = 0; - bmode = FORCE_BMODE_OPEN; - user_force = 99; - hbarke_act_time = 0; - exp_out = 99; - test_res = ut_force_next(handbrake, brakes, bmode, user_force, hbarke_act_time, exp_out); - if(!test_res) pass = 0; - - handbrake = 0; - brakes = 1; - bmode = FORCE_BMODE_OPEN; - user_force = 99; - hbarke_act_time = 0; - exp_out = 0; - test_res = ut_force_next(handbrake, brakes, bmode, user_force, hbarke_act_time, exp_out); - if(!test_res) pass = 0; - - handbrake = 0; - brakes = 1; - bmode = FORCE_BMODE_KEEP; - user_force = 99; - hbarke_act_time = 0; - exp_out = 99; - test_res = ut_force_next(handbrake, brakes, bmode, user_force, hbarke_act_time, exp_out); - if(!test_res) pass = 0; - - handbrake = 0; - brakes = 1; - bmode = FORCE_BMODE_LOCK; - user_force = 99; - hbarke_act_time = 0; - exp_out = 100; - test_res = ut_force_next(handbrake, brakes, bmode, user_force, hbarke_act_time, exp_out); - if(!test_res) pass = 0; - - handbrake = 1; - brakes = 1; - bmode = FORCE_BMODE_LOCK; - user_force = 99; - hbarke_act_time = 0; - exp_out = 0; - test_res = ut_force_next(handbrake, brakes, bmode, user_force, hbarke_act_time, exp_out); - if(!test_res) pass = 0; - - handbrake = 1; - brakes = 1; - bmode = FORCE_BMODE_LOCK; - user_force = 99; - hbarke_act_time = FORCE_MAX_HBRAKE_HOLD_TIME-1; - exp_out = 0; - test_res = ut_force_next(handbrake, brakes, bmode, user_force, hbarke_act_time, exp_out); - if(!test_res) pass = 0; - - handbrake = 1; - brakes = 1; - bmode = FORCE_BMODE_LOCK; - user_force = 99; - hbarke_act_time = FORCE_MAX_HBRAKE_HOLD_TIME; - exp_out = 100; - test_res = ut_force_next(handbrake, brakes, bmode, user_force, hbarke_act_time, exp_out); - if(!test_res) pass = 0; - - handbrake = 1; - brakes = 1; - bmode = FORCE_BMODE_LOCK; - user_force = 99; - hbarke_act_time = FORCE_MAX_HBRAKE_HOLD_TIME+1; - exp_out = 100; - test_res = ut_force_next(handbrake, brakes, bmode, user_force, hbarke_act_time, exp_out); - if(!test_res) pass = 0; - - return pass; -} diff --git a/firmware/tests/ut_logic/ut_force.h b/firmware/tests/ut_logic/ut_force.h deleted file mode 100644 index e971dd5..0000000 --- a/firmware/tests/ut_logic/ut_force.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef UT_FORCE_H_ -#define UT_FORCE_H_ - -#include -#include - -int ut_force_cycle_bmode_test(void); -int ut_force_next_test(void); - -#endif /* UT_FORCE_H_ */ diff --git a/firmware/tests/ut_logic/ut_pot.c b/firmware/tests/ut_logic/ut_pot.c deleted file mode 100644 index 200cbb9..0000000 --- a/firmware/tests/ut_logic/ut_pot.c +++ /dev/null @@ -1,100 +0,0 @@ -#include "ut_pot.h" -#include "..\..\src\logic\pot.h" - -static int ut_pot_mv_to_percent(uint16_t value, pot_cfg_t* cfg, uint8_t exp_out) -{ - uint8_t out = pot_mv_to_percent(value, cfg); - - printf("Value:%d Reference:%d Deadband:%d \n", value, cfg->reference, cfg->deadband); - printf("Output:%d Expected:%d\n", out, exp_out); - - if(out==exp_out) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_pot_mv_to_percent_test(void) -{ - printf("******************************************************\n"); - printf("uint8_t pot_mv_to_percent(uint16_t value, pot_cfg_t* cfg)\n"); - - int test_res; - int pass = 1; - - uint16_t value; - pot_cfg_t cfg; - - uint8_t exp_out; - - value = 0; - cfg.deadband = 500; - cfg.reference = 5000; - exp_out = 0; - test_res = ut_pot_mv_to_percent(value, &cfg, exp_out); - if(!test_res) pass = 0; - - value = 499; - cfg.deadband = 500; - cfg.reference = 5000; - exp_out = 0; - test_res = ut_pot_mv_to_percent(value, &cfg, exp_out); - if(!test_res) pass = 0; - - value = 500; - cfg.deadband = 500; - cfg.reference = 5000; - exp_out = 0; - test_res = ut_pot_mv_to_percent(value, &cfg, exp_out); - if(!test_res) pass = 0; - - value = 1500; - cfg.deadband = 500; - cfg.reference = 5000; - exp_out = 25; - test_res = ut_pot_mv_to_percent(value, &cfg, exp_out); - if(!test_res) pass = 0; - - value = 2500; - cfg.deadband = 500; - cfg.reference = 5000; - exp_out = 50; - test_res = ut_pot_mv_to_percent(value, &cfg, exp_out); - if(!test_res) pass = 0; - - value = 3500; - cfg.deadband = 500; - cfg.reference = 5000; - exp_out = 75; - test_res = ut_pot_mv_to_percent(value, &cfg, exp_out); - if(!test_res) pass = 0; - - value = 4500; - cfg.deadband = 500; - cfg.reference = 5000; - exp_out = 100; - test_res = ut_pot_mv_to_percent(value, &cfg, exp_out); - if(!test_res) pass = 0; - - value = 4501; - cfg.deadband = 500; - cfg.reference = 5000; - exp_out = 100; - test_res = ut_pot_mv_to_percent(value, &cfg, exp_out); - if(!test_res) pass = 0; - - value = 5000; - cfg.deadband = 500; - cfg.reference = 5000; - exp_out = 100; - test_res = ut_pot_mv_to_percent(value, &cfg, exp_out); - if(!test_res) pass = 0; - - return pass; -} diff --git a/firmware/tests/ut_logic/ut_pot.h b/firmware/tests/ut_logic/ut_pot.h deleted file mode 100644 index 0fb97d0..0000000 --- a/firmware/tests/ut_logic/ut_pot.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef UT_POT_H_ -#define UT_POT_H_ - -#include -#include - -int ut_pot_mv_to_percent_test(void); - -#endif /* UT_POT_H_ */ diff --git a/firmware/tests/ut_logic/ut_user_force.c b/firmware/tests/ut_logic/ut_user_force.c deleted file mode 100644 index b2525e8..0000000 --- a/firmware/tests/ut_logic/ut_user_force.c +++ /dev/null @@ -1,419 +0,0 @@ -#include "ut_user_force.h" -#include "..\..\src\logic\user_force.h" - -static int ut_user_force_btn(uint8_t prev_force, uint8_t up_act, uint8_t down_act, uint8_t delta, uint8_t exp_out) -{ - uint8_t out = user_force_btn(prev_force, up_act, down_act, delta); - - printf("Prev-Force:%d Up-act:%d Down-act:%d Delta:%d\n", prev_force, up_act, down_act, delta); - printf("Output:%d Expected:%d\n", out, exp_out); - - if(out==exp_out) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_user_force_btn_test(void) -{ - printf("******************************************************\n"); - printf("uint8_t user_force_btn(uint8_t prev_force, uint8_t up_act, uint8_t down_act, uint8_t delta)\n"); - - int test_res; - int pass = 1; - - uint8_t prev_force; - uint8_t up_act; - uint8_t down_act; - uint8_t delta; - - uint8_t exp_out; - - // No change - prev_force = 0; - up_act = 0; - down_act = 0; - delta = 5; - exp_out = 0; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - prev_force = USER_FORCE_MIN_PERCENT-1; - up_act = 0; - down_act = 0; - delta = 5; - exp_out = 0; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - prev_force = 50; - up_act = 0; - down_act = 0; - delta = 5; - exp_out = 50; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - prev_force = USER_FORCE_MAX_PERCENT+1; - up_act = 0; - down_act = 0; - delta = 5; - exp_out = 100; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - prev_force = 100; - up_act = 0; - down_act = 0; - delta = 5; - exp_out = 100; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - // Start 0 - prev_force = 0; - up_act = 1; - down_act = 0; - delta = 5; - exp_out = USER_FORCE_MIN_PERCENT; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - prev_force = 0; - up_act = 0; - down_act = 1; - delta = 5; - exp_out = 0; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - prev_force = 0; - up_act = 1; - down_act = 1; - delta = 5; - exp_out = 0; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - prev_force = 0; - up_act = 1; - down_act = 0; - delta = USER_FORCE_MIN_PERCENT+1; - exp_out = USER_FORCE_MIN_PERCENT+1; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - // Start 100 - prev_force = 100; - up_act = 1; - down_act = 0; - delta = 5; - exp_out = 100; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - prev_force = 100; - up_act = 0; - down_act = 1; - delta = 5; - exp_out = USER_FORCE_MAX_PERCENT; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - prev_force = 100; - up_act = 1; - down_act = 1; - delta = 5; - exp_out = USER_FORCE_MAX_PERCENT; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - prev_force = 100; - up_act = 0; - down_act = 1; - delta = 100-USER_FORCE_MAX_PERCENT+1; - exp_out = USER_FORCE_MAX_PERCENT-1; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - // Start 50 - prev_force = 50; - up_act = 1; - down_act = 0; - delta = 5; - exp_out = 55; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - prev_force = 50; - up_act = 0; - down_act = 1; - delta = 5; - exp_out = 45; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - prev_force = 50; - up_act = 1; - down_act = 1; - delta = 5; - exp_out = 45; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - prev_force = 50; - up_act = 1; - down_act = 0; - delta = 10; - exp_out = 60; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - prev_force = 50; - up_act = 0; - down_act = 1; - delta = 10; - exp_out = 40; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - // Start MIN_PERCENT+1 - prev_force = USER_FORCE_MIN_PERCENT+1; - up_act = 1; - down_act = 0; - delta = 5; - exp_out = prev_force+delta; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - prev_force = USER_FORCE_MIN_PERCENT+1; - up_act = 0; - down_act = 1; - delta = 5; - exp_out = 0; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - prev_force = USER_FORCE_MIN_PERCENT+1; - up_act = 1; - down_act = 1; - delta = 5; - exp_out = 0; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - // Start MAX_PERCENT-1 - prev_force = USER_FORCE_MAX_PERCENT-1; - up_act = 1; - down_act = 0; - delta = 5; - exp_out = 100; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - prev_force = USER_FORCE_MAX_PERCENT-1; - up_act = 0; - down_act = 1; - delta = 5; - exp_out = prev_force-delta; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - prev_force = USER_FORCE_MAX_PERCENT-1; - up_act = 1; - down_act = 1; - delta = 5; - exp_out = prev_force-delta; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - // Up down seq - prev_force = 0; - up_act = 1; - down_act = 0; - delta = 20; - exp_out = 20; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - prev_force = 20; - up_act = 1; - down_act = 0; - delta = 20; - exp_out = 40; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - prev_force = 40; - up_act = 1; - down_act = 0; - delta = 20; - exp_out = 60; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - prev_force = 60; - up_act = 1; - down_act = 0; - delta = 20; - exp_out = 80; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - prev_force = 80; - up_act = 1; - down_act = 0; - delta = 20; - exp_out = 100; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - prev_force = 100; - up_act = 1; - down_act = 0; - delta = 20; - exp_out = 100; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - prev_force = 100; - up_act = 0; - down_act = 1; - delta = 20; - exp_out = 80; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - prev_force = 80; - up_act = 0; - down_act = 1; - delta = 20; - exp_out = 60; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - prev_force = 60; - up_act = 0; - down_act = 1; - delta = 20; - exp_out = 40; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - prev_force = 40; - up_act = 0; - down_act = 1; - delta = 20; - exp_out = 20; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - prev_force = 20; - up_act = 0; - down_act = 1; - delta = 20; - exp_out = 0; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - prev_force = 0; - up_act = 0; - down_act = 1; - delta = 20; - exp_out = 0; - test_res = ut_user_force_btn(prev_force, up_act, down_act, delta, exp_out); - if(!test_res) pass = 0; - - return pass; -} - -static int ut_user_force_pot(uint8_t prev_force, uint8_t pot, uint8_t hyst, uint8_t exp_out) -{ - uint8_t out = user_force_pot(prev_force, pot, hyst); - - printf("Prev-Force:%d Pot-percent:%d Hysteresis:%d \n", prev_force, pot, hyst); - printf("Output:%d Expected:%d\n", out, exp_out); - - if(out==exp_out) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_user_force_pot_test(void) -{ - printf("******************************************************\n"); - printf("uint8_t user_force_pot(uint8_t prev_force, uint8_t pot, uint8_t hyst)\n"); - - int test_res; - int pass = 1; - - uint8_t prev_force; - uint8_t pot; - uint8_t hyst; - - uint8_t exp_out; - - prev_force = 50; - pot = 0; - hyst = 10; - exp_out = 0; - test_res = ut_user_force_pot(prev_force, pot, hyst, exp_out); - if(!test_res) pass = 0; - - prev_force = 50; - pot = USER_FORCE_MIN_PERCENT-1; - hyst = 10; - exp_out = 0; - test_res = ut_user_force_pot(prev_force, pot, hyst, exp_out); - if(!test_res) pass = 0; - - prev_force = 50; - pot = USER_FORCE_MIN_PERCENT; - hyst = 10; - exp_out = USER_FORCE_MIN_PERCENT; - test_res = ut_user_force_pot(prev_force, pot, hyst, exp_out); - if(!test_res) pass = 0; - - prev_force = 50; - pot = 50; - hyst = 10; - exp_out = 50; - test_res = ut_user_force_pot(prev_force, pot, hyst, exp_out); - if(!test_res) pass = 0; - - prev_force = 50; - pot = USER_FORCE_MAX_PERCENT; - hyst = 10; - exp_out = USER_FORCE_MAX_PERCENT; - test_res = ut_user_force_pot(prev_force, pot, hyst, exp_out); - if(!test_res) pass = 0; - - prev_force = 50; - pot = USER_FORCE_MAX_PERCENT+1; - hyst = 10; - exp_out = 100; - test_res = ut_user_force_pot(prev_force, pot, hyst, exp_out); - if(!test_res) pass = 0; - - prev_force = 50; - pot = 100; - hyst = 10; - exp_out = 100; - test_res = ut_user_force_pot(prev_force, pot, hyst, exp_out); - if(!test_res) pass = 0; - - return pass; -} diff --git a/firmware/tests/ut_logic/ut_user_force.h b/firmware/tests/ut_logic/ut_user_force.h deleted file mode 100644 index cbaf5a6..0000000 --- a/firmware/tests/ut_logic/ut_user_force.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef UT_USER_FORCE_H_ -#define UT_USER_FORCE_H_ - -#include -#include - -int ut_user_force_btn_test(void); -int ut_user_force_pot_test(void); - -#endif /* UT_USER_FORCE_H_ */ diff --git a/firmware/tests/ut_utils/ut_fault.c b/firmware/tests/ut_utils/ut_fault.c deleted file mode 100644 index 0abcdfd..0000000 --- a/firmware/tests/ut_utils/ut_fault.c +++ /dev/null @@ -1,951 +0,0 @@ -#include "ut_fault.h" - -#include "..\..\src\hw\board\utils\faults.h" - -static int ut_fault_process(fault_t* fault, uint8_t w_trig, uint8_t f_trig, fault_cfg_t* cfg, uint8_t exp_out, fault_t* exp_out_fault, fault_cfg_t* exp_out_cfg) -{ - printf("W-Trig:%d F-trig:%d \n", w_trig, f_trig); - printf("Severity:%d W-time:%d F-time:%d \n", fault->severity, fault->w_time, fault->f_time); - printf("Delay:%d WtoF:%d \n", cfg->delay, cfg->wtof); - - uint8_t out = fault_process(fault, w_trig, f_trig, cfg); - - printf("Output:%d Expected:%d\n", out, exp_out); - printf(" Output: Severity:%d W-time:%d F-time:%d \n", fault->severity, fault->w_time, fault->f_time); - printf("Expected: Severity:%d W-time:%d F-time:%d \n", exp_out_fault->severity, exp_out_fault->w_time, exp_out_fault->f_time); - printf("Delay:%d WtoF:%d \n", cfg->delay, cfg->wtof); - - if((out==exp_out)&&(fault->severity==exp_out_fault->severity)&&(fault->w_time==exp_out_fault->w_time)&&(fault->f_time==exp_out_fault->f_time)&&(cfg->delay==exp_out_cfg->delay)&&(cfg->wtof==exp_out_cfg->wtof)) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_fault_process_test(void) -{ - printf("******************************************************\n"); - printf("uint8_t fault_process(fault_t* fault, uint8_t w_trig, uint8_t f_trig, fault_cfg_t* cfg)\n"); - - int test_res; - int pass = 1; - - fault_t fault; - uint8_t w_trig; - uint8_t f_trig; - fault_cfg_t cfg; - - uint8_t exp_out; - fault_t exp_out_fault; - fault_cfg_t exp_out_cfg; - - // NORMAL NO FAULT CONDITION ************************************************************************* - // No change test, start form OK - fault.severity = FAULT_LVL_OK; - fault.w_time = 0; - fault.f_time = 0; - w_trig = 0; - f_trig = 0; - cfg.delay = 0; - cfg.wtof = 0; - exp_out = 0; - exp_out_fault.severity = FAULT_LVL_OK; - exp_out_fault.w_time = 0; - exp_out_fault.f_time = 0; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // STARTING CONDITIONS ************************************************************************* - // Warning trigger test, start form OK - fault.severity = FAULT_LVL_OK; - fault.w_time = 0; - fault.f_time = 0; - w_trig = 1; - f_trig = 0; - cfg.delay = 0; - cfg.wtof = 0; - exp_out = 0; - exp_out_fault.severity = FAULT_LVL_WARNING; - exp_out_fault.w_time = 0; - exp_out_fault.f_time = 0; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // Fault trigger test, start form OK - fault.severity = FAULT_LVL_OK; - fault.w_time = 0; - fault.f_time = 0; - w_trig = 0; - f_trig = 1; - cfg.delay = 0; - cfg.wtof = 0; - exp_out = 1; - exp_out_fault.severity = FAULT_LVL_FAULT; - exp_out_fault.w_time = 0; - exp_out_fault.f_time = 0; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // Warning and Fault trigger test, start form OK - fault.severity = FAULT_LVL_OK; - fault.w_time = 0; - fault.f_time = 0; - w_trig = 1; - f_trig = 1; - cfg.delay = 0; - cfg.wtof = 0; - exp_out = 1; - exp_out_fault.severity = FAULT_LVL_FAULT; - exp_out_fault.w_time = 0; - exp_out_fault.f_time = 0; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // Wrong start severity WARNING, with no triggers - fault.severity = FAULT_LVL_WARNING; - fault.w_time = 0; - fault.f_time = 0; - w_trig = 0; - f_trig = 0; - cfg.delay = 0; - cfg.wtof = 0; - exp_out = 0; - exp_out_fault.severity = FAULT_LVL_OK; - exp_out_fault.w_time = 0; - exp_out_fault.f_time = 0; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // Wrong start severity FAULT, with no triggers - fault.severity = FAULT_LVL_FAULT; - fault.w_time = 0; - fault.f_time = 0; - w_trig = 0; - f_trig = 0; - cfg.delay = 0; - cfg.wtof = 0; - exp_out = 0; - exp_out_fault.severity = FAULT_LVL_OK; - exp_out_fault.w_time = 0; - exp_out_fault.f_time = 0; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // Wrong start times, with no triggers - fault.severity = FAULT_LVL_OK; - fault.w_time = 78; - fault.f_time = 56; - w_trig = 0; - f_trig = 0; - cfg.delay = 0; - cfg.wtof = 0; - exp_out = 0; - exp_out_fault.severity = FAULT_LVL_OK; - exp_out_fault.w_time = 0; - exp_out_fault.f_time = 0; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - - // TIME INCREASE TESTS - SECOND ITERATION WITH TRIGGER ACTIVE ************************************************************************* - // Warning time increase with continuing warning condition - fault.severity = FAULT_LVL_WARNING; - fault.w_time = 45; - fault.f_time = 0; - w_trig = 1; - f_trig = 0; - cfg.delay = 0; - cfg.wtof = 0; - exp_out = 0; - exp_out_fault.severity = FAULT_LVL_WARNING; - exp_out_fault.w_time = 46; - exp_out_fault.f_time = 0; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // Fault and warning time increase with continuing fault only condition - fault.severity = FAULT_LVL_FAULT; - fault.w_time = 78; - fault.f_time = 23; - w_trig = 0; - f_trig = 1; - cfg.delay = 0; - cfg.wtof = 0; - exp_out = 1; - exp_out_fault.severity = FAULT_LVL_FAULT; - exp_out_fault.w_time = 79; - exp_out_fault.f_time = 24; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // Fault and warning time increase with continuing both triggers condition - fault.severity = FAULT_LVL_FAULT; - fault.w_time = 57; - fault.f_time = 12; - w_trig = 1; - f_trig = 1; - cfg.delay = 0; - cfg.wtof = 0; - exp_out = 1; - exp_out_fault.severity = FAULT_LVL_FAULT; - exp_out_fault.w_time = 58; - exp_out_fault.f_time = 13; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // Time increase and transition to fault with both triggers - fault.severity = FAULT_LVL_WARNING; - fault.w_time = 0; - fault.f_time = 0; - w_trig = 1; - f_trig = 1; - cfg.delay = 0; - cfg.wtof = 0; - exp_out = 1; - exp_out_fault.severity = FAULT_LVL_FAULT; - exp_out_fault.w_time = 1; - exp_out_fault.f_time = 1; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // Warning time increase and transition to fault with only fault trigger - fault.severity = FAULT_LVL_WARNING; - fault.w_time = 0; - fault.f_time = 0; - w_trig = 0; - f_trig = 1; - cfg.delay = 0; - cfg.wtof = 0; - exp_out = 1; - exp_out_fault.severity = FAULT_LVL_FAULT; - exp_out_fault.w_time = 1; - exp_out_fault.f_time = 1; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // Time saturation - fault.severity = FAULT_LVL_FAULT; - fault.w_time = 65535; - fault.f_time = 65535; - w_trig = 1; - f_trig = 1; - cfg.delay = 0; - cfg.wtof = 0; - exp_out = 1; - exp_out_fault.severity = FAULT_LVL_FAULT; - exp_out_fault.w_time = 65535; - exp_out_fault.f_time = 65535; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // Fallback to warning and time increase - fault.severity = FAULT_LVL_FAULT; - fault.w_time = 784; - fault.f_time = 457; - w_trig = 1; - f_trig = 0; - cfg.delay = 0; - cfg.wtof = 0; - exp_out = 0; - exp_out_fault.severity = FAULT_LVL_WARNING; - exp_out_fault.w_time = 785; - exp_out_fault.f_time = 0; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // Fallback to OK and time reset from fault - fault.severity = FAULT_LVL_FAULT; - fault.w_time = 784; - fault.f_time = 457; - w_trig = 0; - f_trig = 0; - cfg.delay = 0; - cfg.wtof = 0; - exp_out = 0; - exp_out_fault.severity = FAULT_LVL_OK; - exp_out_fault.w_time = 0; - exp_out_fault.f_time = 0; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // Fallback to OK and time reset from warning - fault.severity = FAULT_LVL_WARNING; - fault.w_time = 479; - fault.f_time = 0; - w_trig = 0; - f_trig = 0; - cfg.delay = 0; - cfg.wtof = 0; - exp_out = 0; - exp_out_fault.severity = FAULT_LVL_OK; - exp_out_fault.w_time = 0; - exp_out_fault.f_time = 0; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // FAULT DELAY TESTS ************************************************************************* - // Not transition to fault - fault.severity = FAULT_LVL_OK; - fault.w_time = 0; - fault.f_time = 0; - w_trig = 1; - f_trig = 1; - cfg.delay = 100; - cfg.wtof = 0; - exp_out = 0; - exp_out_fault.severity = FAULT_LVL_WARNING; - exp_out_fault.w_time = 0; - exp_out_fault.f_time = 0; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // Not transition to fault second time - fault.severity = FAULT_LVL_WARNING; - fault.w_time = 0; - fault.f_time = 0; - w_trig = 1; - f_trig = 1; - cfg.delay = 100; - cfg.wtof = 0; - exp_out = 0; - exp_out_fault.severity = FAULT_LVL_WARNING; - exp_out_fault.w_time = 1; - exp_out_fault.f_time = 1; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // Not transition to fault before limit - fault.severity = FAULT_LVL_WARNING; - fault.w_time = 128; - fault.f_time = 98; - w_trig = 1; - f_trig = 1; - cfg.delay = 100; - cfg.wtof = 0; - exp_out = 0; - exp_out_fault.severity = FAULT_LVL_WARNING; - exp_out_fault.w_time = 129; - exp_out_fault.f_time = 99; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // Transition to fault at limit - fault.severity = FAULT_LVL_WARNING; - fault.w_time = 358; - fault.f_time = 99; - w_trig = 1; - f_trig = 1; - cfg.delay = 100; - cfg.wtof = 0; - exp_out = 1; - exp_out_fault.severity = FAULT_LVL_FAULT; - exp_out_fault.w_time = 359; - exp_out_fault.f_time = 100; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // Transition to fault after limit - fault.severity = FAULT_LVL_WARNING; - fault.w_time = 786; - fault.f_time = 100; - w_trig = 1; - f_trig = 1; - cfg.delay = 100; - cfg.wtof = 0; - exp_out = 1; - exp_out_fault.severity = FAULT_LVL_FAULT; - exp_out_fault.w_time = 787; - exp_out_fault.f_time = 101; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // Continued fault condition - fault.severity = FAULT_LVL_FAULT; - fault.w_time = 101; - fault.f_time = 101; - w_trig = 1; - f_trig = 1; - cfg.delay = 100; - cfg.wtof = 0; - exp_out = 1; - exp_out_fault.severity = FAULT_LVL_FAULT; - exp_out_fault.w_time = 102; - exp_out_fault.f_time = 102; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // Fallback to warning - fault.severity = FAULT_LVL_FAULT; - fault.w_time = 101; - fault.f_time = 101; - w_trig = 1; - f_trig = 0; - cfg.delay = 100; - cfg.wtof = 0; - exp_out = 0; - exp_out_fault.severity = FAULT_LVL_WARNING; - exp_out_fault.w_time = 102; - exp_out_fault.f_time = 0; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // Fallback to OK - fault.severity = FAULT_LVL_FAULT; - fault.w_time = 101; - fault.f_time = 101; - w_trig = 0; - f_trig = 0; - cfg.delay = 100; - cfg.wtof = 0; - exp_out = 0; - exp_out_fault.severity = FAULT_LVL_OK; - exp_out_fault.w_time = 0; - exp_out_fault.f_time = 0; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // Allready was fault condition, with lower time - fixes to correct state - fault.severity = FAULT_LVL_FAULT; - fault.w_time = 45; - fault.f_time = 45; - w_trig = 1; - f_trig = 1; - cfg.delay = 100; - cfg.wtof = 0; - exp_out = 0; - exp_out_fault.severity = FAULT_LVL_WARNING; - exp_out_fault.w_time = 46; - exp_out_fault.f_time = 46; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // WARNING TO FAULT TRANSITION TESTS ************************************************************************* - // Not transition to fault - fault.severity = FAULT_LVL_OK; - fault.w_time = 0; - fault.f_time = 0; - w_trig = 1; - f_trig = 0; - cfg.delay = 0; - cfg.wtof = 200; - exp_out = 0; - exp_out_fault.severity = FAULT_LVL_WARNING; - exp_out_fault.w_time = 0; - exp_out_fault.f_time = 0; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // Not transition to fault - fault.severity = FAULT_LVL_WARNING; - fault.w_time = 0; - fault.f_time = 0; - w_trig = 1; - f_trig = 0; - cfg.delay = 0; - cfg.wtof = 200; - exp_out = 0; - exp_out_fault.severity = FAULT_LVL_WARNING; - exp_out_fault.w_time = 1; - exp_out_fault.f_time = 0; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // Not transition to fault before limit - fault.severity = FAULT_LVL_WARNING; - fault.w_time = 198; - fault.f_time = 0; - w_trig = 1; - f_trig = 0; - cfg.delay = 0; - cfg.wtof = 200; - exp_out = 0; - exp_out_fault.severity = FAULT_LVL_WARNING; - exp_out_fault.w_time = 199; - exp_out_fault.f_time = 0; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // Not Transition to fault at limit - fault.severity = FAULT_LVL_WARNING; - fault.w_time = 199; - fault.f_time = 0; - w_trig = 1; - f_trig = 0; - cfg.delay = 0; - cfg.wtof = 200; - exp_out = 0; - exp_out_fault.severity = FAULT_LVL_WARNING; - exp_out_fault.w_time = 200; - exp_out_fault.f_time = 0; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // Transition to fault after limit - fault.severity = FAULT_LVL_WARNING; - fault.w_time = 200; - fault.f_time = 0; - w_trig = 1; - f_trig = 0; - cfg.delay = 0; - cfg.wtof = 200; - exp_out = 1; - exp_out_fault.severity = FAULT_LVL_FAULT; - exp_out_fault.w_time = 201; - exp_out_fault.f_time = 1; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // Continued fault - fault.severity = FAULT_LVL_FAULT; - fault.w_time = 201; - fault.f_time = 1; - w_trig = 1; - f_trig = 0; - cfg.delay = 0; - cfg.wtof = 200; - exp_out = 1; - exp_out_fault.severity = FAULT_LVL_FAULT; - exp_out_fault.w_time = 202; - exp_out_fault.f_time = 2; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // Fallback to ok - fault.severity = FAULT_LVL_FAULT; - fault.w_time = 247; - fault.f_time = 0; - w_trig = 0; - f_trig = 0; - cfg.delay = 0; - cfg.wtof = 200; - exp_out = 0; - exp_out_fault.severity = FAULT_LVL_OK; - exp_out_fault.w_time = 0; - exp_out_fault.f_time = 0; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // WARNING TO FAULT TRANSITION WITH FAULT DELAY TESTS ************************************************************************* - // Not transition to fault - fault.severity = FAULT_LVL_OK; - fault.w_time = 0; - fault.f_time = 0; - w_trig = 1; - f_trig = 0; - cfg.delay = 50; - cfg.wtof = 200; - exp_out = 0; - exp_out_fault.severity = FAULT_LVL_WARNING; - exp_out_fault.w_time = 0; - exp_out_fault.f_time = 0; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // Not transition to fault - fault.severity = FAULT_LVL_OK; - fault.w_time = 0; - fault.f_time = 0; - w_trig = 1; - f_trig = 1; - cfg.delay = 50; - cfg.wtof = 200; - exp_out = 0; - exp_out_fault.severity = FAULT_LVL_WARNING; - exp_out_fault.w_time = 0; - exp_out_fault.f_time = 0; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - fault.severity = FAULT_LVL_OK; - fault.w_time = 0; - fault.f_time = 0; - w_trig = 0; - f_trig = 1; - cfg.delay = 50; - cfg.wtof = 200; - exp_out = 0; - exp_out_fault.severity = FAULT_LVL_WARNING; - exp_out_fault.w_time = 0; - exp_out_fault.f_time = 0; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // Transition to fault at delay - fault.severity = FAULT_LVL_WARNING; - fault.w_time = 49; - fault.f_time = 49; - w_trig = 1; - f_trig = 1; - cfg.delay = 50; - cfg.wtof = 200; - exp_out = 1; - exp_out_fault.severity = FAULT_LVL_FAULT; - exp_out_fault.w_time = 50; - exp_out_fault.f_time = 50; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // No Transition to fault at wtof - fault.severity = FAULT_LVL_WARNING; - fault.w_time = 200; - fault.f_time = 0; - w_trig = 1; - f_trig = 0; - cfg.delay = 50; - cfg.wtof = 200; - exp_out = 0; - exp_out_fault.severity = FAULT_LVL_WARNING; - exp_out_fault.w_time = 201; - exp_out_fault.f_time = 1; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // No Transition to fault before wtof + delay - fault.severity = FAULT_LVL_WARNING; - fault.w_time = 248; - fault.f_time = 48; - w_trig = 1; - f_trig = 0; - cfg.delay = 50; - cfg.wtof = 200; - exp_out = 0; - exp_out_fault.severity = FAULT_LVL_WARNING; - exp_out_fault.w_time = 249; - exp_out_fault.f_time = 49; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // Transition to fault before wtof + delay - fault.severity = FAULT_LVL_WARNING; - fault.w_time = 249; - fault.f_time = 49; - w_trig = 1; - f_trig = 0; - cfg.delay = 50; - cfg.wtof = 200; - exp_out = 1; - exp_out_fault.severity = FAULT_LVL_FAULT; - exp_out_fault.w_time = 250; - exp_out_fault.f_time = 50; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // Continued wtof fault condition - fault.severity = FAULT_LVL_FAULT; - fault.w_time = 250; - fault.f_time = 50; - w_trig = 1; - f_trig = 0; - cfg.delay = 50; - cfg.wtof = 200; - exp_out = 1; - exp_out_fault.severity = FAULT_LVL_FAULT; - exp_out_fault.w_time = 251; - exp_out_fault.f_time = 51; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - // Continued wtof fault condition, without warning trigger - fault.severity = FAULT_LVL_FAULT; - fault.w_time = 350; - fault.f_time = 150; - w_trig = 0; - f_trig = 1; - cfg.delay = 50; - cfg.wtof = 200; - exp_out = 1; - exp_out_fault.severity = FAULT_LVL_FAULT; - exp_out_fault.w_time = 351; - exp_out_fault.f_time = 151; - exp_out_cfg.delay = cfg.delay; - exp_out_cfg.wtof = cfg.wtof; - test_res = ut_fault_process(&fault, w_trig, f_trig, &cfg, exp_out, &exp_out_fault, &exp_out_cfg); - if(!test_res) pass = 0; - - return pass; -} - -static int ut_fault_is_active(fault_t* fault, uint8_t exp_out, fault_t* exp_out_fault) -{ - printf("Severity:%d W-time:%d F-time:%d \n", fault->severity, fault->w_time, fault->f_time); - - uint8_t out = fault_is_active(fault); - - printf("Output:%d Expected:%d\n", out, exp_out); - printf(" Output: Severity:%d W-time:%d F-time:%d \n", fault->severity, fault->w_time, fault->f_time); - printf("Expected: Severity:%d W-time:%d F-time:%d \n", exp_out_fault->severity, exp_out_fault->w_time, exp_out_fault->f_time); - - if((out==exp_out)&&(fault->severity==exp_out_fault->severity)&&(fault->w_time==exp_out_fault->w_time)&&(fault->f_time==exp_out_fault->f_time)) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_fault_is_active_test(void) -{ - printf("******************************************************\n"); - printf("uint8_t fault_is_active(fault_t* fault)\n"); - - int test_res; - int pass = 1; - - fault_t fault; - - uint8_t exp_out; - fault_t exp_out_fault; - - fault.severity = FAULT_LVL_OK; - fault.w_time = 500; - fault.f_time = 300; - exp_out = 0; - exp_out_fault.severity = fault.severity; - exp_out_fault.w_time = fault.w_time; - exp_out_fault.f_time = fault.f_time; - test_res = ut_fault_is_active(&fault, exp_out, &exp_out_fault); - if(!test_res) pass = 0; - - fault.severity = FAULT_LVL_WARNING; - fault.w_time = 500; - fault.f_time = 300; - exp_out = 0; - exp_out_fault.severity = fault.severity; - exp_out_fault.w_time = fault.w_time; - exp_out_fault.f_time = fault.f_time; - test_res = ut_fault_is_active(&fault, exp_out, &exp_out_fault); - if(!test_res) pass = 0; - - fault.severity = FAULT_LVL_FAULT; - fault.w_time = 500; - fault.f_time = 300; - exp_out = 1; - exp_out_fault.severity = fault.severity; - exp_out_fault.w_time = fault.w_time; - exp_out_fault.f_time = fault.f_time; - test_res = ut_fault_is_active(&fault, exp_out, &exp_out_fault); - if(!test_res) pass = 0; - - return pass; -} - -static int ut_fault_is_warning(fault_t* fault, uint8_t exp_out, fault_t* exp_out_fault) -{ - printf("Severity:%d W-time:%d F-time:%d \n", fault->severity, fault->w_time, fault->f_time); - - uint8_t out = fault_is_warning(fault); - - printf("Output:%d Expected:%d\n", out, exp_out); - printf(" Output: Severity:%d W-time:%d F-time:%d \n", fault->severity, fault->w_time, fault->f_time); - printf("Expected: Severity:%d W-time:%d F-time:%d \n", exp_out_fault->severity, exp_out_fault->w_time, exp_out_fault->f_time); - - if((out==exp_out)&&(fault->severity==exp_out_fault->severity)&&(fault->w_time==exp_out_fault->w_time)&&(fault->f_time==exp_out_fault->f_time)) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_fault_is_warning_test(void) -{ - printf("******************************************************\n"); - printf("uint8_t fault_is_warning(fault_t* fault)\n"); - - int test_res; - int pass = 1; - - fault_t fault; - - uint8_t exp_out; - fault_t exp_out_fault; - - fault.severity = FAULT_LVL_OK; - fault.w_time = 500; - fault.f_time = 300; - exp_out = 0; - exp_out_fault.severity = fault.severity; - exp_out_fault.w_time = fault.w_time; - exp_out_fault.f_time = fault.f_time; - test_res = ut_fault_is_warning(&fault, exp_out, &exp_out_fault); - if(!test_res) pass = 0; - - fault.severity = FAULT_LVL_WARNING; - fault.w_time = 500; - fault.f_time = 300; - exp_out = 1; - exp_out_fault.severity = fault.severity; - exp_out_fault.w_time = fault.w_time; - exp_out_fault.f_time = fault.f_time; - test_res = ut_fault_is_warning(&fault, exp_out, &exp_out_fault); - if(!test_res) pass = 0; - - fault.severity = FAULT_LVL_FAULT; - fault.w_time = 500; - fault.f_time = 300; - exp_out = 1; - exp_out_fault.severity = fault.severity; - exp_out_fault.w_time = fault.w_time; - exp_out_fault.f_time = fault.f_time; - test_res = ut_fault_is_warning(&fault, exp_out, &exp_out_fault); - if(!test_res) pass = 0; - - return pass; -} - -static int ut_fault_reset(fault_t* fault, fault_t* exp_out_fault) -{ - printf("Severity:%d W-time:%d F-time:%d \n", fault->severity, fault->w_time, fault->f_time); - - fault_reset(fault); - - printf(" Output: Severity:%d W-time:%d F-time:%d \n", fault->severity, fault->w_time, fault->f_time); - printf("Expected: Severity:%d W-time:%d F-time:%d \n", exp_out_fault->severity, exp_out_fault->w_time, exp_out_fault->f_time); - - if((fault->severity==exp_out_fault->severity)&&(fault->w_time==exp_out_fault->w_time)&&(fault->f_time==exp_out_fault->f_time)) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_fault_reset_test(void) -{ - printf("******************************************************\n"); - printf("void fault_reset(fault_t* fault)\n"); - - int test_res; - int pass = 1; - - fault_t fault; - - fault_t exp_out_fault; - - fault.severity = FAULT_LVL_OK; - fault.w_time = 0; - fault.f_time = 0; - exp_out_fault.severity = FAULT_LVL_OK; - exp_out_fault.w_time = 0; - exp_out_fault.f_time = 0; - test_res = ut_fault_reset(&fault, &exp_out_fault); - if(!test_res) pass = 0; - - fault.severity = FAULT_LVL_WARNING; - fault.w_time = 500; - fault.f_time = 0; - exp_out_fault.severity = FAULT_LVL_OK; - exp_out_fault.w_time = 0; - exp_out_fault.f_time = 0; - test_res = ut_fault_reset(&fault, &exp_out_fault); - if(!test_res) pass = 0; - - fault.severity = FAULT_LVL_FAULT; - fault.w_time = 1000; - fault.f_time = 500; - exp_out_fault.severity = FAULT_LVL_OK; - exp_out_fault.w_time = 0; - exp_out_fault.f_time = 0; - test_res = ut_fault_reset(&fault, &exp_out_fault); - if(!test_res) pass = 0; - - return pass; -} - diff --git a/firmware/tests/ut_utils/ut_fault.h b/firmware/tests/ut_utils/ut_fault.h deleted file mode 100644 index 1024805..0000000 --- a/firmware/tests/ut_utils/ut_fault.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef UT_FAULTS_H_ -#define UT_FAULTS_H_ - -#include -#include - -int ut_fault_process_test(void); -int ut_fault_is_active_test(void); -int ut_fault_is_warning_test(void); -int ut_fault_reset_test(void); - -#endif /* UT_FAULTS_H_ */ diff --git a/firmware/tests/ut_utils/ut_fuses.c b/firmware/tests/ut_utils/ut_fuses.c deleted file mode 100644 index 03b7138..0000000 --- a/firmware/tests/ut_utils/ut_fuses.c +++ /dev/null @@ -1,79 +0,0 @@ -#include "ut_fuses.h" - -#include "..\..\src\hw\board\utils\fuses.h" - -static int ut_fuse_reset(fuse_t* fuse, fuse_t* exp_out_fuse) -{ - printf("State:%d Timer:%d Count:%d \n", fuse->state, fuse->timer, fuse->count); - - fuse_reset(fuse); - - printf(" Output: State:%d Timer:%d Count:%d \n", fuse->state, fuse->timer, fuse->count); - printf("Expected: State:%d Timer:%d Count:%d \n", exp_out_fuse->state, exp_out_fuse->timer, exp_out_fuse->count); - - if((fuse->state==exp_out_fuse->state)&&(fuse->timer==exp_out_fuse->timer)&&(fuse->count==exp_out_fuse->count)) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_fuse_reset_test(void) -{ - printf("******************************************************\n"); - printf("void fuse_reset(fuse_t* fuse)\n"); - - int test_res; - int pass = 1; - - fuse_t fuse; - - fuse_t exp_out_fuse; - - // No change test - fuse.state = FUSE_OFF; - fuse.timer = 0; - fuse.count = 0; - exp_out_fuse.state = FUSE_OFF; - exp_out_fuse.timer = 0; - exp_out_fuse.count = 0; - test_res = ut_fuse_reset(&fuse, &exp_out_fuse); - if(!test_res) pass = 0; - - // No change test - fuse.state = FUSE_ACTIVE; - fuse.timer = 1254; - fuse.count = 124; - exp_out_fuse.state = FUSE_OFF; - exp_out_fuse.timer = 0; - exp_out_fuse.count = 0; - test_res = ut_fuse_reset(&fuse, &exp_out_fuse); - if(!test_res) pass = 0; - - // No change test - fuse.state = FUSE_COOLDOWN; - fuse.timer = 4578; - fuse.count = 14; - exp_out_fuse.state = FUSE_OFF; - exp_out_fuse.timer = 0; - exp_out_fuse.count = 0; - test_res = ut_fuse_reset(&fuse, &exp_out_fuse); - if(!test_res) pass = 0; - - // No change test - fuse.state = FUSE_RETRY; - fuse.timer = 0; - fuse.count = 0; - exp_out_fuse.state = FUSE_OFF; - exp_out_fuse.timer = 0; - exp_out_fuse.count = 0; - test_res = ut_fuse_reset(&fuse, &exp_out_fuse); - if(!test_res) pass = 0; - - return pass; -} diff --git a/firmware/tests/ut_utils/ut_fuses.h b/firmware/tests/ut_utils/ut_fuses.h deleted file mode 100644 index 87bd1b7..0000000 --- a/firmware/tests/ut_utils/ut_fuses.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef UT_FUSES_H_ -#define UT_FUSES_H_ - -#include -#include - -int ut_fuse_reset_test(void); - -#endif /* UT_FUSES_H_ */ diff --git a/firmware/tests/ut_utils/ut_utils.c b/firmware/tests/ut_utils/ut_utils.c deleted file mode 100644 index b260687..0000000 --- a/firmware/tests/ut_utils/ut_utils.c +++ /dev/null @@ -1,1334 +0,0 @@ -#include "ut_utils.h" - -#include "..\..\src\hw\board\utils\utils.h" - -static int ut_util_invert_8b(uint8_t x, uint8_t exp_out) -{ - printf(" Input:%d\n", x); - - uint8_t out = util_invert_8b(x); - - printf(" Output:%d\n", out); - printf("Expected:%d\n", exp_out); - - if(out==exp_out) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_util_invert_8b_test(void) -{ - printf("******************************************************\n"); - printf("uint8_t util_invert_8b(uint8_t x)\n"); - - int test_res; - int pass = 1; - - uint8_t inp; - uint8_t exp_out; - - inp = 0; - exp_out = 1; - test_res = ut_util_invert_8b(inp, exp_out); - if(!test_res) pass = 0; - - inp = 1; - exp_out = 0; - test_res = ut_util_invert_8b(inp, exp_out); - if(!test_res) pass = 0; - - inp = 257; - exp_out = 0; - test_res = ut_util_invert_8b(inp, exp_out); - if(!test_res) pass = 0; - - inp = -1; - exp_out = 0; - test_res = ut_util_invert_8b(inp, exp_out); - if(!test_res) pass = 0; - - return pass; -} - -static int ut_util_sat_add_8b(uint8_t x, uint8_t y, uint8_t exp_out) -{ - printf(" Input: x:%d y:%d\n", x, y); - - uint8_t out = util_sat_add_8b(x,y); - - printf(" Output:%d\n", out); - printf("Expected:%d\n", exp_out); - - if(out==exp_out) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_util_sat_add_8b_test(void) -{ - printf("******************************************************\n"); - printf("uint8_t util_sat_add_8b(uint8_t x, uint8_t y)\n"); - - int test_res; - int pass = 1; - - uint8_t inp_x; - uint8_t inp_y; - uint8_t exp_out; - - inp_x = 0; - inp_y = 0; - exp_out = 0; - test_res = ut_util_sat_add_8b(inp_x, inp_y, exp_out); - if(!test_res) pass = 0; - - inp_x = 5; - inp_y = 6; - exp_out = 11; - test_res = ut_util_sat_add_8b(inp_x, inp_y, exp_out); - if(!test_res) pass = 0; - - inp_x = 4; - inp_y = 9; - exp_out = 13; - test_res = ut_util_sat_add_8b(inp_x, inp_y, exp_out); - if(!test_res) pass = 0; - - inp_x = 254; - inp_y = 1; - exp_out = 255; - test_res = ut_util_sat_add_8b(inp_x, inp_y, exp_out); - if(!test_res) pass = 0; - - inp_x = 1; - inp_y = 254; - exp_out = 255; - test_res = ut_util_sat_add_8b(inp_x, inp_y, exp_out); - if(!test_res) pass = 0; - - inp_x = 1; - inp_y = 255; - exp_out = 255; - test_res = ut_util_sat_add_8b(inp_x, inp_y, exp_out); - if(!test_res) pass = 0; - - inp_x = 255; - inp_y = 1; - exp_out = 255; - test_res = ut_util_sat_add_8b(inp_x, inp_y, exp_out); - if(!test_res) pass = 0; - - inp_x = 255; - inp_y = 255; - exp_out = 255; - test_res = ut_util_sat_add_8b(inp_x, inp_y, exp_out); - if(!test_res) pass = 0; - - return pass; -} - - -static int ut_util_sat_subtract_8b(uint8_t x, uint8_t y, uint8_t exp_out) -{ - printf(" Input: x:%d y:%d\n", x, y); - - uint8_t out = util_sat_subtract_8b(x,y); - - printf(" Output:%d\n", out); - printf("Expected:%d\n", exp_out); - - if(out==exp_out) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_util_sat_subtract_8b_test(void) -{ - printf("******************************************************\n"); - printf("uint8_t util_sat_subtract_8b(uint8_t x, uint8_t y)\n"); - - int test_res; - int pass = 1; - - uint8_t inp_x; - uint8_t inp_y; - uint8_t exp_out; - - inp_x = 0; - inp_y = 0; - exp_out = 0; - test_res = ut_util_sat_subtract_8b(inp_x, inp_y, exp_out); - if(!test_res) pass = 0; - - inp_x = 50; - inp_y = 10; - exp_out = 40; - test_res = ut_util_sat_subtract_8b(inp_x, inp_y, exp_out); - if(!test_res) pass = 0; - - inp_x = 70; - inp_y = 0; - exp_out = 70; - test_res = ut_util_sat_subtract_8b(inp_x, inp_y, exp_out); - if(!test_res) pass = 0; - - inp_x = 60; - inp_y = 50; - exp_out = 10; - test_res = ut_util_sat_subtract_8b(inp_x, inp_y, exp_out); - if(!test_res) pass = 0; - - inp_x = 10; - inp_y = 50; - exp_out = 0; - test_res = ut_util_sat_subtract_8b(inp_x, inp_y, exp_out); - if(!test_res) pass = 0; - - inp_x = 0; - inp_y = 255; - exp_out = 0; - test_res = ut_util_sat_subtract_8b(inp_x, inp_y, exp_out); - if(!test_res) pass = 0; - - return pass; -} - -static int ut_util_sat_add_16b(uint16_t x, uint16_t y, uint16_t exp_out) -{ - printf(" Input: x:%d y:%d\n", x, y); - - uint16_t out = util_sat_add_16b(x,y); - - printf(" Output:%d\n", out); - printf("Expected:%d\n", exp_out); - - if(out==exp_out) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_util_sat_util_sat_add_16b_test(void) -{ - printf("******************************************************\n"); - printf("uint16_t util_sat_add_16b(uint16_t x, uint16_t y)\n"); - - int test_res; - int pass = 1; - - uint16_t inp_x; - uint16_t inp_y; - uint16_t exp_out; - - inp_x = 0; - inp_y = 0; - exp_out = 0; - test_res = ut_util_sat_add_16b(inp_x, inp_y, exp_out); - if(!test_res) pass = 0; - - inp_x = 10; - inp_y = 15; - exp_out = 25; - test_res = ut_util_sat_add_16b(inp_x, inp_y, exp_out); - if(!test_res) pass = 0; - - inp_x = 25; - inp_y = 35; - exp_out = 60; - test_res = ut_util_sat_add_16b(inp_x, inp_y, exp_out); - if(!test_res) pass = 0; - - inp_x = 0; - inp_y = 0xFFFF; - exp_out = 0xFFFF; - test_res = ut_util_sat_add_16b(inp_x, inp_y, exp_out); - if(!test_res) pass = 0; - - inp_x = 100; - inp_y = 0xFFFF; - exp_out = 0xFFFF; - test_res = ut_util_sat_add_16b(inp_x, inp_y, exp_out); - if(!test_res) pass = 0; - - inp_x = 45867; - inp_y = 47841; - exp_out = 0xFFFF; - test_res = ut_util_sat_add_16b(inp_x, inp_y, exp_out); - if(!test_res) pass = 0; - - inp_x = 0xFFFF; - inp_y = 0xFFFF; - exp_out = 0xFFFF; - test_res = ut_util_sat_add_16b(inp_x, inp_y, exp_out); - if(!test_res) pass = 0; - - return pass; -} - -static int ut_util_sat_subtract_16b(uint16_t x, uint16_t y, uint16_t exp_out) -{ - printf(" Input: x:%d y:%d\n", x, y); - - uint16_t out = util_sat_subtract_16b(x,y); - - printf(" Output:%d\n", out); - printf("Expected:%d\n", exp_out); - - if(out==exp_out) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_util_sat_subtract_16b_test(void) -{ - printf("******************************************************\n"); - printf("uint16_t util_sat_subtract_16b(uint16_t x, uint16_t y)\n"); - - int test_res; - int pass = 1; - - uint16_t inp_x; - uint16_t inp_y; - uint16_t exp_out; - - inp_x = 0; - inp_y = 0; - exp_out = 0; - test_res = ut_util_sat_subtract_16b(inp_x, inp_y, exp_out); - if(!test_res) pass = 0; - - inp_x = 50; - inp_y = 10; - exp_out = 40; - test_res = ut_util_sat_subtract_16b(inp_x, inp_y, exp_out); - if(!test_res) pass = 0; - - inp_x = 70; - inp_y = 0; - exp_out = 70; - test_res = ut_util_sat_subtract_16b(inp_x, inp_y, exp_out); - if(!test_res) pass = 0; - - inp_x = 60; - inp_y = 50; - exp_out = 10; - test_res = ut_util_sat_subtract_16b(inp_x, inp_y, exp_out); - if(!test_res) pass = 0; - - inp_x = 10; - inp_y = 50; - exp_out = 0; - test_res = ut_util_sat_subtract_16b(inp_x, inp_y, exp_out); - if(!test_res) pass = 0; - - inp_x = 401; - inp_y = 0x3FFF; - exp_out = 0; - test_res = ut_util_sat_subtract_16b(inp_x, inp_y, exp_out); - if(!test_res) pass = 0; - - inp_x = 0; - inp_y = 0x7FFF; - exp_out = 0; - test_res = ut_util_sat_subtract_16b(inp_x, inp_y, exp_out); - if(!test_res) pass = 0; - - inp_x = 0; - inp_y = 0xFFFF; - exp_out = 0; - test_res = ut_util_sat_subtract_16b(inp_x, inp_y, exp_out); - if(!test_res) pass = 0; - - return pass; -} - -static int ut_util_limit_u32b_to_u16b(uint32_t inp, uint16_t exp_out) -{ - printf(" Input: %d\n", inp); - - uint16_t out = util_limit_u32b_to_u16b(inp); - - printf(" Output:%d\n", out); - printf("Expected:%d\n", exp_out); - - if(out==exp_out) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_util_limit_u32b_to_u16b_test(void) -{ - printf("******************************************************\n"); - printf("uint16_t util_limit_u32b_to_u16b(uint32_t in)\n"); - - int test_res; - int pass = 1; - - uint32_t inp; - uint16_t exp_out; - - inp = 0; - exp_out = 0; - test_res = ut_util_limit_u32b_to_u16b(inp, exp_out); - if(!test_res) pass = 0; - - inp = 0x0000FFFE; - exp_out = 0xFFFE; - test_res = ut_util_limit_u32b_to_u16b(inp, exp_out); - if(!test_res) pass = 0; - - inp = 0x0000FFFF; - exp_out = 0xFFFF; - test_res = ut_util_limit_u32b_to_u16b(inp, exp_out); - if(!test_res) pass = 0; - - inp = 0x0001FFFF; - exp_out = 0xFFFF; - test_res = ut_util_limit_u32b_to_u16b(inp, exp_out); - if(!test_res) pass = 0; - - inp = 0x7FFFFFFF; - exp_out = 0xFFFF; - test_res = ut_util_limit_u32b_to_u16b(inp, exp_out); - if(!test_res) pass = 0; - - inp = 0xFFFFFFFF; - exp_out = 0xFFFF; - test_res = ut_util_limit_u32b_to_u16b(inp, exp_out); - if(!test_res) pass = 0; - - return pass; -} - -static int ut_util_limit_s32b_to_u16b(int32_t inp, uint16_t exp_out) -{ - printf(" Input: %d\n", inp); - - uint16_t out = util_limit_s32b_to_u16b(inp); - - printf(" Output:%d\n", out); - printf("Expected:%d\n", exp_out); - - if(out==exp_out) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_util_limit_s32b_to_u16b_test(void) -{ - printf("******************************************************\n"); - printf("uint16_t util_limit_s32b_to_u16b(int32_t in)\n"); - - int test_res; - int pass = 1; - - int32_t inp; - uint16_t exp_out; - - inp = 0; - exp_out = 0; - test_res = ut_util_limit_s32b_to_u16b(inp, exp_out); - if(!test_res) pass = 0; - - inp = -1; - exp_out = 0; - test_res = ut_util_limit_s32b_to_u16b(inp, exp_out); - if(!test_res) pass = 0; - - inp = -32768; - exp_out = 0; - test_res = ut_util_limit_s32b_to_u16b(inp, exp_out); - if(!test_res) pass = 0; - - inp = -2147483648; - exp_out = 0; - test_res = ut_util_limit_s32b_to_u16b(inp, exp_out); - if(!test_res) pass = 0; - - inp = 1; - exp_out = 1; - test_res = ut_util_limit_s32b_to_u16b(inp, exp_out); - if(!test_res) pass = 0; - - inp = 32767; - exp_out = 32767; - test_res = ut_util_limit_s32b_to_u16b(inp, exp_out); - if(!test_res) pass = 0; - - inp = 65535; - exp_out = 0xFFFF; - test_res = ut_util_limit_s32b_to_u16b(inp, exp_out); - if(!test_res) pass = 0; - - inp = 1000000000; - exp_out = 0xFFFF; - test_res = ut_util_limit_s32b_to_u16b(inp, exp_out); - if(!test_res) pass = 0; - - inp = 2147483647; - exp_out = 0xFFFF; - test_res = ut_util_limit_s32b_to_u16b(inp, exp_out); - if(!test_res) pass = 0; - - return pass; -} - -static int ut_util_convert_muldivoff(uint16_t raw, uint8_t mul, uint8_t div, int16_t offset, uint16_t exp_out) -{ - printf(" Input: Raw:%d Mul:%d Div:%d Offset:%d\n", raw, mul, div, offset); - uint16_t out = util_convert_muldivoff(raw, mul, div, offset); - - printf(" Output:%d\n", out); - printf("Expected:%d\n", exp_out); - - if(out==exp_out) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_util_convert_muldivoff_test(void) -{ - printf("******************************************************\n"); - printf("uint16_t util_convert_muldivoff(uint16_t raw, uint8_t mul, uint8_t div, int16_t offset) \n"); - - int test_res; - int pass = 1; - - uint16_t raw; - uint8_t mul; - uint8_t div; - int16_t offset; - uint16_t exp_out; - - // Normal case - raw = 100; - mul = 1; - div = 1; - offset = 100; - exp_out = 200; - test_res = ut_util_convert_muldivoff(raw, mul, div, offset, exp_out); - if(!test_res) pass = 0; - - // Normal case - raw = 0; - mul = 1; - div = 1; - offset = 0; - exp_out = 0; - test_res = ut_util_convert_muldivoff(raw, mul, div, offset, exp_out); - if(!test_res) pass = 0; - - // max raw - raw = 0xFFFF; - mul = 1; - div = 1; - offset = 0; - exp_out = 0xFFFF; - test_res = ut_util_convert_muldivoff(raw, mul, div, offset, exp_out); - if(!test_res) pass = 0; - - // Saturation + - raw = 40000; - mul = 1; - div = 1; - offset = 30000; - exp_out = 0xFFFF; - test_res = ut_util_convert_muldivoff(raw, mul, div, offset, exp_out); - if(!test_res) pass = 0; - - // Saturation - - raw = 20000; - mul = 1; - div = 1; - offset = -30000; - exp_out = 0; - test_res = ut_util_convert_muldivoff(raw, mul, div, offset, exp_out); - if(!test_res) pass = 0; - - // Multiplier - raw = 10; - mul = 30; - div = 1; - offset = 200; - exp_out = 500; - test_res = ut_util_convert_muldivoff(raw, mul, div, offset, exp_out); - if(!test_res) pass = 0; - - // Divider - raw = 10; - mul = 30; - div = 6; - offset = 200; - exp_out = 250; - test_res = ut_util_convert_muldivoff(raw, mul, div, offset, exp_out); - if(!test_res) pass = 0; - - // Zero mul - raw = 10; - mul = 0; - div = 6; - offset = 99; - exp_out = 99; - test_res = ut_util_convert_muldivoff(raw, mul, div, offset, exp_out); - if(!test_res) pass = 0; - - // Zero div - raw = 10; - mul = 2; - div = 0; - offset = 80; - exp_out = 100; - test_res = ut_util_convert_muldivoff(raw, mul, div, offset, exp_out); - if(!test_res) pass = 0; - - // Zero div - raw = 0xFFFE; - mul = 255; - div = 255; - offset = -1; - exp_out = 0xFFFD; - test_res = ut_util_convert_muldivoff(raw, mul, div, offset, exp_out); - if(!test_res) pass = 0; - - return pass; -} - -static int ut_util_sat_mul_kilo(uint16_t xk, uint16_t yk, uint16_t exp_out) -{ - printf(" Input: X:%d Y:%d \n", xk, yk); - - uint16_t out = util_sat_mul_kilo(xk, yk); - - printf(" Output:%d\n", out); - printf("Expected:%d\n", exp_out); - - if(out==exp_out) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_util_sat_mul_kilo_test(void) -{ - printf("******************************************************\n"); - printf("uint16_t util_sat_mul_kilo(uint16_t xk, uint16_t yk) \n"); - - int test_res; - int pass = 1; - - uint16_t xk; - uint16_t yk; - uint16_t exp_out; - - // Normal case - xk = 1000; - yk = 1000; - exp_out = 1000; - test_res = ut_util_sat_mul_kilo(xk, yk, exp_out); - if(!test_res) pass = 0; - - // Normal case - xk = 60000; - yk = 1; - exp_out = 60; - test_res = ut_util_sat_mul_kilo(xk, yk, exp_out); - if(!test_res) pass = 0; - - // Normal case - xk = 2; - yk = 30000; - exp_out = 60; - test_res = ut_util_sat_mul_kilo(xk, yk, exp_out); - if(!test_res) pass = 0; - - // Normal case - xk = 0xFFFF; - yk = 0xFFFF; - exp_out = 0xFFFF; - test_res = ut_util_sat_mul_kilo(xk, yk, exp_out); - if(!test_res) pass = 0; - - // Normal case - xk = 8095; - yk = 8095; - exp_out = 65529; - test_res = ut_util_sat_mul_kilo(xk, yk, exp_out); - if(!test_res) pass = 0; - - // Saturation - xk = 10000; - yk = 20000; - exp_out = 0xFFFF; - test_res = ut_util_sat_mul_kilo(xk, yk, exp_out); - if(!test_res) pass = 0; - - return pass; -} - -static int ut_util_sat_div_kilo(uint16_t top, uint16_t bot, uint16_t exp_out) -{ - printf(" Input: Top:%d Bottom:%d \n", top, bot); - - uint16_t out = util_sat_div_kilo(top, bot); - - printf(" Output:%d\n", out); - printf("Expected:%d\n", exp_out); - - if(out==exp_out) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_util_sat_div_kilo_test(void) -{ - printf("******************************************************\n"); - printf("uint16_t util_sat_div_kilo(uint16_t top, uint16_t bot) \n"); - - int test_res; - int pass = 1; - - uint16_t top; - uint16_t bot; - uint16_t exp_out; - - // Normal case - top = 1000; - bot = 1000; - exp_out = 1000; - test_res = ut_util_sat_div_kilo(top, bot, exp_out); - if(!test_res) pass = 0; - - // Normal case - top = 12000; - bot = 6000; - exp_out = 2000; - test_res = ut_util_sat_div_kilo(top, bot, exp_out); - if(!test_res) pass = 0; - - // Saturation - top = 40000; - bot = 500; - exp_out = 0xFFFF; - test_res = ut_util_sat_div_kilo(top, bot, exp_out); - if(!test_res) pass = 0; - - // Zero - top = 40000; - bot = 0; - exp_out = 0xFFFF; - test_res = ut_util_sat_div_kilo(top, bot, exp_out); - if(!test_res) pass = 0; - - // Zero - top = 0; - bot = 2000; - exp_out = 0; - test_res = ut_util_sat_div_kilo(top, bot, exp_out); - if(!test_res) pass = 0; - - return pass; -} - -static int ut_util_sat_ratio_16b(uint16_t top, uint16_t bot, uint16_t exp_out) -{ - printf(" Input: Top:%d Bottom:%d \n", top, bot); - - uint16_t out = util_sat_ratio_16b(top, bot); - - printf(" Output:%d\n", out); - printf("Expected:%d\n", exp_out); - - if(out==exp_out) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_util_sat_ratio_16b_test(void) -{ - printf("******************************************************\n"); - printf("uint16_t util_sat_ratio_16b(uint16_t top, uint16_t bot) \n"); - - int test_res; - int pass = 1; - - uint16_t top; - uint16_t bot; - uint16_t exp_out; - - // Normal case - top = 1000; - bot = 1000; - exp_out = 0xFFFF; - test_res = ut_util_sat_ratio_16b(top, bot, exp_out); - if(!test_res) pass = 0; - - // Normal case - top = 0xFFFF; - bot = 0xFFFF; - exp_out = 0xFFFF; - test_res = ut_util_sat_ratio_16b(top, bot, exp_out); - if(!test_res) pass = 0; - - // Normal case - top = 6000; - bot = 12000; - exp_out = 0x7FFF; - test_res = ut_util_sat_ratio_16b(top, bot, exp_out); - if(!test_res) pass = 0; - - // Normal case - top = 11000; - bot = 44000; - exp_out = 0x3FFF; - test_res = ut_util_sat_ratio_16b(top, bot, exp_out); - if(!test_res) pass = 0; - - // Zero - top = 0; - bot = 212; - exp_out = 0; - test_res = ut_util_sat_ratio_16b(top, bot, exp_out); - if(!test_res) pass = 0; - - // Zero - top = 158; - bot = 0; - exp_out = 0xFFFF; - test_res = ut_util_sat_ratio_16b(top, bot, exp_out); - if(!test_res) pass = 0; - - return pass; -} - -static int ut_util_percent_to_16b(uint8_t percent, uint16_t exp_out) -{ - printf(" Input: Percent:%d \n", percent); - - uint16_t out = util_percent_to_16b(percent); - - printf(" Output:%d\n", out); - printf("Expected:%d\n", exp_out); - - if(out==exp_out) - { - printf("PASS\n\n"); - return 1; - } - else - { - printf("FAIL\n\n"); - return 0; - } -} - -int ut_util_percent_to_16b_test(void) -{ - printf("******************************************************\n"); - printf("uint16_t util_percent_to_16b(uint8_t percent) \n"); - - int test_res; - int pass = 1; - - uint8_t percent; - uint16_t exp_out; - - // 0% - percent = 0; - exp_out = 0; - test_res = ut_util_percent_to_16b(percent, exp_out); - if(!test_res) pass = 0; - - // 25% - percent = 25; - exp_out = 16383; - test_res = ut_util_percent_to_16b(percent, exp_out); - if(!test_res) pass = 0; - - // 50% - percent = 50; - exp_out = 0x7FFF; - test_res = ut_util_percent_to_16b(percent, exp_out); - if(!test_res) pass = 0; - - // 75% - percent = 75; - exp_out = 49151; - test_res = ut_util_percent_to_16b(percent, exp_out); - if(!test_res) pass = 0; - - // 100% - percent = 100; - exp_out = 65535; - test_res = ut_util_percent_to_16b(percent, exp_out); - if(!test_res) pass = 0; - - // 200% - percent = 200; - exp_out = 0xFFFF; - test_res = ut_util_percent_to_16b(percent, exp_out); - if(!test_res) pass = 0; - - return pass; -} - -static int ut_util_interpolate_1d_u16b(uint16_t x, uint16_t* x_axis, uint16_t* y_values, uint8_t len_axis, uint16_t exp_out) -{ - printf(" Input: X:%d \n", x); - printf("X values, Y values\n"); - for(uint8_t i=0; i -#include - -int ut_util_invert_8b_test(void); -int ut_util_sat_add_8b_test(void); -int ut_util_sat_subtract_8b_test(void); -int ut_util_sat_util_sat_add_16b_test(void); -int ut_util_sat_subtract_16b_test(void); - -int ut_util_limit_u32b_to_u16b_test(void); -int ut_util_limit_s32b_to_u16b_test(void); - -int ut_util_convert_muldivoff_test(void); - -int ut_util_sat_mul_kilo_test(void); -int ut_util_sat_div_kilo_test(void); - -int ut_util_sat_ratio_16b_test(void); -int ut_util_percent_to_16b_test(void); - -int ut_util_interpolate_1d_u16b_test(void); -int ut_util_interpolate_2d_u16b_test(void); - -#endif /* UT_UTILS_H_ */