Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7f012b1611 |
@@ -1,120 +0,0 @@
|
|||||||
/**** Includes ****/
|
|
||||||
#include "hal/udccd_hal.h"
|
|
||||||
#include "analog.h"
|
|
||||||
|
|
||||||
/**** Private variables ****/
|
|
||||||
static const uint8_t ICOIL_MUL = 215;
|
|
||||||
static const uint8_t ICOIL_DIV = 22;
|
|
||||||
static const int16_t ICOIL_OFF = 0;
|
|
||||||
static const uint8_t ICOIL_CNT = 1;
|
|
||||||
|
|
||||||
static const uint8_t UCOIL_MUL = 20;
|
|
||||||
static const uint8_t UCOIL_DIV = 1;
|
|
||||||
static const int16_t UCOIL_OFF = 0;
|
|
||||||
static const uint8_t UCOIL_CNT = 1;
|
|
||||||
|
|
||||||
static const uint8_t UBAT_MUL = 20;
|
|
||||||
static const uint8_t UBAT_DIV = 1;
|
|
||||||
static const int16_t UBAT_OFF = 0;
|
|
||||||
static const uint8_t UBAT_CNT = 1;
|
|
||||||
|
|
||||||
static const uint8_t IBAT_MUL = 235;
|
|
||||||
static const uint8_t IBAT_DIV = 6;
|
|
||||||
static const int16_t IBAT_OFF = 0;
|
|
||||||
static const uint8_t IBAT_CNT = 1;
|
|
||||||
|
|
||||||
static const uint8_t POT_MUL = 215;
|
|
||||||
static const uint8_t POT_DIV = 44;
|
|
||||||
static const int16_t POT_OFF = 0;
|
|
||||||
static const uint8_t POT_CNT = 1;
|
|
||||||
|
|
||||||
static const uint8_t MODE_MUL = 215;
|
|
||||||
static const uint8_t MODE_DIV = 44;
|
|
||||||
static const int16_t MODE_OFF = 0;
|
|
||||||
static const uint8_t MODE_CNT = 1;
|
|
||||||
|
|
||||||
|
|
||||||
/**** Private function declarations ****/
|
|
||||||
static uint16_t ConvertSIntShort(int32_t in);
|
|
||||||
static uint16_t ConvertUintShort(uint32_t in);
|
|
||||||
static uint16_t read_ch(adcCh_t ch, uint16_t gnd_raw, uint8_t mul, uint8_t div, int16_t offset, uint8_t samples);
|
|
||||||
|
|
||||||
/**** Public function definitions ****/
|
|
||||||
void Analog_UpdateAll(analog_t* meas)
|
|
||||||
{
|
|
||||||
uint16_t gnd_lvl = HAL_ADC_Read(ADC_GND);
|
|
||||||
|
|
||||||
meas->hb_currnet = read_ch(ADC_ICOIL, 0, ICOIL_MUL, ICOIL_DIV, ICOIL_OFF, ICOIL_CNT ); //mA
|
|
||||||
meas->hb_voltage = read_ch(ADC_UCOIL, 0, UCOIL_MUL, UCOIL_DIV, UCOIL_OFF, UCOIL_CNT ); //mV
|
|
||||||
meas->supply_current = read_ch(ADC_IBAT , 0, IBAT_MUL , IBAT_DIV , IBAT_OFF , IBAT_CNT ); //mA
|
|
||||||
meas->supply_voltage = read_ch(ADC_UBAT , 0, UBAT_MUL , UBAT_DIV , UBAT_OFF , UBAT_CNT ); //mV
|
|
||||||
meas->pot_voltage = read_ch(ADC_POT , 0, POT_MUL , POT_DIV , POT_OFF , POT_CNT ); //mV
|
|
||||||
meas->mode_voltage = read_ch(ADC_MODE , 0, MODE_MUL , MODE_DIV , MODE_OFF , MODE_CNT ); //mV
|
|
||||||
|
|
||||||
// Calculate derived measurements
|
|
||||||
// Halfbridge output power
|
|
||||||
uint32_t temp = (uint32_t)meas->hb_currnet * (uint32_t)meas->hb_voltage;
|
|
||||||
temp /= 1000;
|
|
||||||
meas->hb_power = ConvertUintShort(temp);
|
|
||||||
|
|
||||||
// Halfbridge output resistance
|
|
||||||
if(meas->hb_currnet == 0) meas->hb_resistance = 0xFFFF;
|
|
||||||
else if(meas->hb_voltage == 0) meas->hb_resistance = 0;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
temp = (uint32_t)meas->hb_voltage * 1000;
|
|
||||||
temp /= (uint32_t)meas->hb_currnet;
|
|
||||||
meas->hb_resistance = ConvertUintShort(temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Supply power
|
|
||||||
temp = (uint32_t)meas->supply_current * (uint32_t)meas->supply_voltage;
|
|
||||||
temp /= 1000;
|
|
||||||
meas->supply_power = ConvertUintShort(temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint16_t read_ch(adcCh_t ch, uint16_t gnd_raw, uint8_t mul, uint8_t div, int16_t offset, uint8_t samples)
|
|
||||||
{
|
|
||||||
//Sanity check
|
|
||||||
if(div==0) return 0xFFFF;
|
|
||||||
|
|
||||||
// Do at least one sample
|
|
||||||
if(samples<1) samples = 1;
|
|
||||||
|
|
||||||
// Read ADC value
|
|
||||||
int32_t raw = 0;
|
|
||||||
for(uint8_t i=0; i<samples; i++)
|
|
||||||
{
|
|
||||||
raw += (int32_t)HAL_ADC_Read(ch);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do average
|
|
||||||
if(samples != 1)
|
|
||||||
{
|
|
||||||
raw /= samples;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Remove GND level
|
|
||||||
if(gnd_raw) raw = raw - (int32_t)gnd_raw;
|
|
||||||
|
|
||||||
// Convert to target units
|
|
||||||
raw = raw * mul;
|
|
||||||
if(div!=1) raw /= div;
|
|
||||||
raw += offset;
|
|
||||||
|
|
||||||
return ConvertSIntShort(raw);
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint16_t ConvertSIntShort(int32_t in)
|
|
||||||
{
|
|
||||||
if(in <= 0) return 0;
|
|
||||||
else if(in >= 0x0000FFFF) return 0xFFFF;
|
|
||||||
else return (uint16_t)in;
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint16_t ConvertUintShort(uint32_t in)
|
|
||||||
{
|
|
||||||
if(in == 0) return 0;
|
|
||||||
else if(in >= 0x0000FFFF) return 0xFFFF;
|
|
||||||
else return (uint16_t)in;
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
#ifndef ANALOG_H_
|
|
||||||
#define ANALOG_H_
|
|
||||||
|
|
||||||
/**** Includes ****/
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
/**** Public definitions ****/
|
|
||||||
typedef struct {
|
|
||||||
uint16_t hb_currnet;
|
|
||||||
uint16_t hb_voltage;
|
|
||||||
uint16_t hb_power;
|
|
||||||
uint16_t hb_resistance;
|
|
||||||
uint16_t supply_current;
|
|
||||||
uint16_t supply_voltage;
|
|
||||||
uint16_t supply_power;
|
|
||||||
uint16_t pot_voltage;
|
|
||||||
uint16_t mode_voltage;
|
|
||||||
} analog_t;
|
|
||||||
|
|
||||||
/**** Public function declarations ****/
|
|
||||||
void Analog_UpdateAll(analog_t* meas);
|
|
||||||
|
|
||||||
#endif /* ANALOG_H_ */
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
#ifndef LEVEL_T_H_
|
|
||||||
#define LEVEL_T_H_
|
|
||||||
|
|
||||||
/**** Public definitions ****/
|
|
||||||
typedef enum {
|
|
||||||
HIZ = -1,
|
|
||||||
LOW = 0,
|
|
||||||
HIGH = 1
|
|
||||||
} level_t;
|
|
||||||
|
|
||||||
#endif /* LEVEL_T_H_ */
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
/**** Includes ****/
|
|
||||||
#include "hal/udccd_hal.h"
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
/**** Public function definitions ****/
|
|
||||||
void Init_HW(void)
|
|
||||||
{
|
|
||||||
hwConfig_t hwCfg;
|
|
||||||
hwCfg.adc_clk_prescaler = ADC_DIV2;
|
|
||||||
hwCfg.adc_auto_wake = 1;
|
|
||||||
// 64kHz PWM
|
|
||||||
hwCfg.pwm_timer_prescaler = TIM_DIV1;
|
|
||||||
hwCfg.pwm_timer_top = 0x01FF;
|
|
||||||
// 1.9Hz..62.5kHz Speed input
|
|
||||||
hwCfg.freq_timer_prescaler = TIM_DIV64;
|
|
||||||
// 1kHz systick
|
|
||||||
hwCfg.systick_timer_top = 125;
|
|
||||||
hwCfg.systick_timer_prescaler = TIM_DIV64;
|
|
||||||
// No extra features
|
|
||||||
hwCfg.uart_prescaler = 0;
|
|
||||||
hwCfg.disable_unused = 0;
|
|
||||||
hwCfg.en_watchdog = 0;
|
|
||||||
HAL_Init_Min(&hwCfg);
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
#ifndef CONFIG_H_
|
|
||||||
#define CONFIG_H_
|
|
||||||
|
|
||||||
/**** Includes ****/
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
/**** Public function declarations ****/
|
|
||||||
void Init_HW(void);
|
|
||||||
|
|
||||||
#endif /* CONFIG_H_ */
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
/**** Includes ****/
|
|
||||||
#include "filter_iir_lpf.h"
|
|
||||||
|
|
||||||
/**** Private variables ****/
|
|
||||||
|
|
||||||
/**** Public function definitions ****/
|
|
||||||
uint16_t LPF_Update(uint16_t new, uint16_t last, uint8_t strength)
|
|
||||||
{
|
|
||||||
if(strength==0) return new;
|
|
||||||
else if(strength==255) return last;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
uint32_t temp = (uint32_t)last * strength;
|
|
||||||
temp += new * (255-strength);
|
|
||||||
temp /= 255;
|
|
||||||
|
|
||||||
//Limit to 16bits
|
|
||||||
if(temp > 0x0000FFFF) return 0xFFFF;
|
|
||||||
else return (uint16_t) temp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
#ifndef FILTER_IIR_LPF_H_
|
|
||||||
#define FILTER_IIR_LPF_H_
|
|
||||||
|
|
||||||
/**** Includes ****/
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
/**** Public function declarations ****/
|
|
||||||
uint16_t LPF_Update(uint16_t new, uint16_t last, uint8_t strength);
|
|
||||||
|
|
||||||
#endif /* FILTER_IIR_LPF_H_ */
|
|
||||||
@@ -1,102 +0,0 @@
|
|||||||
#ifndef UDCCD_R8_BSP_H_
|
|
||||||
#define UDCCD_R8_BSP_H_
|
|
||||||
|
|
||||||
/**** Includes ****/
|
|
||||||
#include <stdint.h>
|
|
||||||
#include "../common/level.h"
|
|
||||||
|
|
||||||
/**** Public definitions ****/
|
|
||||||
//ADC definitions
|
|
||||||
typedef enum {
|
|
||||||
ADC_ICOIL = 0x00,
|
|
||||||
ADC_UCOIL = 0x01,
|
|
||||||
ADC_UBAT = 0x02,
|
|
||||||
ADC_IBAT = 0x03,
|
|
||||||
ADC_POT = 0x04,
|
|
||||||
ADC_MODE = 0x05,
|
|
||||||
ADC_TEMP = 0x08,
|
|
||||||
ADC_INTREF = 0x0E,
|
|
||||||
ADC_GND = 0x0F
|
|
||||||
} adcCh_t;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
ADC_DIV2 = 0x01,
|
|
||||||
ADC_DIV4 = 0x02,
|
|
||||||
ADC_DIV8 = 0x03,
|
|
||||||
ADC_DIV16 = 0x04,
|
|
||||||
ADC_DIV32 = 0x05,
|
|
||||||
ADC_DIV64 = 0x06,
|
|
||||||
ADC_DIV128 = 0x07
|
|
||||||
} adcDiv_t;
|
|
||||||
|
|
||||||
//Timer definitions
|
|
||||||
typedef enum {
|
|
||||||
TIM_DIV1 = 0x01,
|
|
||||||
TIM_DIV8 = 0x02,
|
|
||||||
TIM_DIV64 = 0x03,
|
|
||||||
TIM_DIV256 = 0x04,
|
|
||||||
TIM_DIV1024 = 0x05
|
|
||||||
} timerDiv_t;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
PWM_COIL = 'A',
|
|
||||||
PWM_LED = 'B'
|
|
||||||
} pwmCh_t;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
SPEED_1 = 3,
|
|
||||||
SPEED_0 = 4
|
|
||||||
} speedCh_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
adcDiv_t adc_clk_prescaler;
|
|
||||||
uint8_t adc_auto_wake;
|
|
||||||
timerDiv_t pwm_timer_prescaler;
|
|
||||||
uint16_t pwm_timer_top;
|
|
||||||
timerDiv_t freq_timer_prescaler;
|
|
||||||
uint16_t uart_prescaler;
|
|
||||||
uint8_t systick_timer_top;
|
|
||||||
timerDiv_t systick_timer_prescaler;
|
|
||||||
uint8_t disable_unused;
|
|
||||||
uint8_t en_watchdog;
|
|
||||||
} hwConfig_t;
|
|
||||||
|
|
||||||
/**** Public function declarations ****/
|
|
||||||
void HAL_Init_Min(hwConfig_t* hwCfg);
|
|
||||||
void HAL_Init_Extra(hwConfig_t* hwCfg);
|
|
||||||
|
|
||||||
level_t HAL_ReadLvl_Handbrake(void);
|
|
||||||
level_t HAL_ReadLvl_Brake(void);
|
|
||||||
level_t HAL_ReadLvl_Dimm(void);
|
|
||||||
level_t HAL_ReadLvl_BtnUp(void);
|
|
||||||
level_t HAL_ReadLvl_BtnDown(void);
|
|
||||||
level_t HAL_ReadLvl_BtnMode(void);
|
|
||||||
level_t HAL_ReadLvl_HandbrakePull(void);
|
|
||||||
level_t HAL_ReadLvl_CoilLow(void);
|
|
||||||
level_t HAL_ReadLvl_CoilHigh(void);
|
|
||||||
level_t HAL_ReadLvl_LedsPwm(void);
|
|
||||||
level_t HAL_ReadLvl_Speed0(void);
|
|
||||||
level_t HAL_ReadLvl_Speed1(void);
|
|
||||||
level_t HAL_ReadLvl_SpeedPull(void);
|
|
||||||
|
|
||||||
void HAL_SetPull_Handbrake(level_t lvl);
|
|
||||||
void HAL_SetPull_Speed(level_t lvl);
|
|
||||||
|
|
||||||
void HAL_ADC_Wake(void);
|
|
||||||
void HAL_ADC_Sleep(void);
|
|
||||||
uint16_t HAL_ADC_Read(adcCh_t ch);
|
|
||||||
|
|
||||||
void HAL_Coil_SetLowSide(uint8_t on);
|
|
||||||
void HAL_Coil_SetPWM(uint8_t percent);
|
|
||||||
void HAL_Coil_SetPWM16b(uint16_t value);
|
|
||||||
|
|
||||||
void HAL_LEDS_Set(uint8_t image);
|
|
||||||
uint8_t HAL_LEDS_Get(void);
|
|
||||||
void HAL_LEDS_SetPWM(uint8_t percent);
|
|
||||||
|
|
||||||
void HAL_PWM_Wake(void);
|
|
||||||
void HAL_PWM_Sleep(void);
|
|
||||||
void HAL_PWM_SetDuty16b(pwmCh_t ch, uint16_t value);
|
|
||||||
void HAL_PWM_SetDuty100(pwmCh_t ch, uint8_t percent);
|
|
||||||
|
|
||||||
#endif /* UDCCD_R8_BSP_H_ */
|
|
||||||
@@ -1,463 +0,0 @@
|
|||||||
/**** Includes ****/
|
|
||||||
#include <avr/io.h>
|
|
||||||
#include "udccd_hal.h"
|
|
||||||
|
|
||||||
/**** Private variables ****/
|
|
||||||
static uint8_t tim0_prescaler = 0x00;
|
|
||||||
static uint8_t tim1_prescaler = 0x00;
|
|
||||||
static uint8_t tim3_prescaler = 0x00;
|
|
||||||
static uint8_t tim4_prescaler = 0x00;
|
|
||||||
|
|
||||||
/**** Private function declarations ****/
|
|
||||||
static void PWM_SetOCx(pwmCh_t ch, uint16_t value);
|
|
||||||
|
|
||||||
/**** Public function definitions ****/
|
|
||||||
void HAL_Init_Min(hwConfig_t* hwCfg)
|
|
||||||
{
|
|
||||||
// PIN Configuration
|
|
||||||
//DCCD Enable and PWM
|
|
||||||
PORTB &= ~0x03; //Set low
|
|
||||||
DDRB |= 0x03; //Set as outputs
|
|
||||||
|
|
||||||
//LED PWM
|
|
||||||
PORTB &= ~0x04; //Set low
|
|
||||||
DDRB |= 0x04; //Set as output
|
|
||||||
|
|
||||||
//UART TX
|
|
||||||
PORTB |= 0x18; //Set high / pull-up on
|
|
||||||
DDRB |= 0x08; //Set as output
|
|
||||||
DDRB &= ~0x10; //Set as input
|
|
||||||
|
|
||||||
//Handbrake pull-up
|
|
||||||
PORTB |= 0x20; //Set high
|
|
||||||
DDRB |= 0x20; //Set as output
|
|
||||||
|
|
||||||
//Handbrake and Brake inputs
|
|
||||||
PORTB |= 0xC0; //Pull-up on
|
|
||||||
DDRB &= ~0xC0; //Set as input
|
|
||||||
|
|
||||||
// ADC inputs
|
|
||||||
PORTC &= ~0x3F; //Pull-up off
|
|
||||||
DDRC &= ~0x3F; //Set as inputs
|
|
||||||
|
|
||||||
// Reset
|
|
||||||
PORTC |= 0x40; //Pull-up on
|
|
||||||
DDRC &= ~0x40; //Set as input
|
|
||||||
|
|
||||||
// LED control
|
|
||||||
PORTD &= ~0x3F; //Set low
|
|
||||||
DDRD |= 0x3F; //Set as outputs
|
|
||||||
|
|
||||||
// Speed pull
|
|
||||||
PORTD &= ~0x40; //Set low
|
|
||||||
DDRD |= 0x40; //Set as outputs
|
|
||||||
|
|
||||||
// Dim input
|
|
||||||
PORTD |= 0x80; //Set pull-up on
|
|
||||||
DDRD &= ~0x80; //Set as input
|
|
||||||
|
|
||||||
// Speed inputs
|
|
||||||
PORTE &= ~0x05; //Set pull-down
|
|
||||||
DDRE |= 0x05; //Set as output
|
|
||||||
|
|
||||||
// Up/Down inputs
|
|
||||||
PORTE |= 0x0A; //Set pull-up on
|
|
||||||
DDRE &= ~0x0A; //Set as input
|
|
||||||
|
|
||||||
|
|
||||||
//ADC configuration
|
|
||||||
PRR0 &= ~0x01; //Enable ADC power
|
|
||||||
DIDR0 |= 0x1F; //Disable digital inputs, ADC0-ADC4
|
|
||||||
|
|
||||||
ADMUX = 0x40; //Set AVCC reference, Right adjust
|
|
||||||
ADCSRA = 0x00; //ADC Disabled, Single conversion, no IT
|
|
||||||
ADCSRA |= (uint8_t)hwCfg->adc_clk_prescaler;
|
|
||||||
ADCSRB = 0x00; //no trigger input
|
|
||||||
|
|
||||||
if(hwCfg->adc_auto_wake) ADCSRA |= 0x80; //Enable ADC
|
|
||||||
else PRR0 |= 0x01;
|
|
||||||
|
|
||||||
|
|
||||||
//DCCD and LED PWM configuration
|
|
||||||
PRR0 &= ~0x80; //Enable Timer1 power
|
|
||||||
TCCR1A = 0xF2; //Connect OC1A and OC1B, normal logic
|
|
||||||
TCCR1B = 0x18; //PWM, Phase & Frequency Correct ICR1 top, no clock, WGM:0xE
|
|
||||||
TCCR1C = 0x00;
|
|
||||||
TCNT1 = 0x0000;
|
|
||||||
OCR1A = 0x0000;
|
|
||||||
OCR1B = 0x0000;
|
|
||||||
ICR1 = (hwCfg->pwm_timer_top);
|
|
||||||
TIMSK1 = 0x00; //No interrupts
|
|
||||||
TIFR1 = 0x00; //Clear all flags
|
|
||||||
|
|
||||||
tim1_prescaler = (uint8_t)hwCfg->pwm_timer_prescaler;
|
|
||||||
TCCR1B |= tim1_prescaler; //Enable timer
|
|
||||||
}
|
|
||||||
|
|
||||||
void HAL_Init_Extra(hwConfig_t* hwCfg)
|
|
||||||
{
|
|
||||||
//Speed 1 input timer configuration
|
|
||||||
PRR1 &= ~0x01; //Enable Timer3 power
|
|
||||||
TCCR3A = 0x00; //OCx disconnected, WGM:0x0
|
|
||||||
TCCR3B = 0x80; //ICP Noise filter, Falling edge, no clock
|
|
||||||
TCCR3C = 0x00;
|
|
||||||
TCNT3 = 0x0000;
|
|
||||||
OCR3A = 0x0000;
|
|
||||||
OCR3B = 0x0000;
|
|
||||||
ICR3 = 0x0000;
|
|
||||||
TIMSK3 = 0x00;
|
|
||||||
//TIMSK3 |= 0x21; //ICP and OVF interrupts
|
|
||||||
TIFR3 = 0x00; //Clear all flags
|
|
||||||
|
|
||||||
tim3_prescaler = (uint8_t)hwCfg->freq_timer_prescaler;
|
|
||||||
TCCR3B |= tim3_prescaler; //Enable timer
|
|
||||||
|
|
||||||
|
|
||||||
//Speed 0 input timer configuration
|
|
||||||
PRR1 &= ~0x08; //Enable Timer4 power
|
|
||||||
TCCR4A = 0x00; //OCx disconnected, WGM:0x0
|
|
||||||
TCCR4B = 0x80; //ICP Noise filter, Falling edge, no clock
|
|
||||||
TCCR4C = 0x00;
|
|
||||||
TCNT4 = 0x0000;
|
|
||||||
OCR4A = 0x0000;
|
|
||||||
OCR4B = 0x0000;
|
|
||||||
ICR4 = 0x0000;
|
|
||||||
TIMSK4 = 0x00;
|
|
||||||
//TIMSK4 |= 0x21; //ICP and OVF interrupts
|
|
||||||
TIFR4 = 0x00; //Clear all flags
|
|
||||||
|
|
||||||
tim4_prescaler = (uint8_t)hwCfg->freq_timer_prescaler;
|
|
||||||
TCCR4B |= tim4_prescaler; //Enable timer
|
|
||||||
|
|
||||||
|
|
||||||
//UART1 configuration
|
|
||||||
PRR0 &= 0x10; //Enable UART1 power
|
|
||||||
UCSR1A = 0x00; //Clear flags, Single UART speed, Single processor mode
|
|
||||||
UCSR1B = 0x18; //Enable RX/TX hardware, 8bit char
|
|
||||||
//UCSR1B |= 0xC0; //Enable RX/TX interrupt,
|
|
||||||
UCSR1C = 0x06; ; //async, No parity, 1 stop bit, 8bit char,
|
|
||||||
UBRR1 = hwCfg->uart_prescaler; //UART baud rate select
|
|
||||||
|
|
||||||
|
|
||||||
//"Systick" timer configuration
|
|
||||||
PRR0 &= ~0x20; //Enable Timer0 power
|
|
||||||
TCCR0A = 0x02 ;//OC0x not connected, WGM 0x01-CTC OC0A TOP
|
|
||||||
TCCR0B = 0x00; //WGM 0x01-CTC, No clock
|
|
||||||
TIMSK0 = 0x00;
|
|
||||||
//TIMSK0 |= 0x01; //OVF interrupt enabled
|
|
||||||
TCNT0 = 0x00;
|
|
||||||
OCR0A = hwCfg->systick_timer_top;
|
|
||||||
OCR0B= 0x00;
|
|
||||||
TIFR0 = 0x00; //Reset all flags
|
|
||||||
|
|
||||||
tim0_prescaler = (uint8_t)hwCfg->systick_timer_prescaler;
|
|
||||||
TCCR0B |= tim0_prescaler;
|
|
||||||
|
|
||||||
|
|
||||||
//Disabled not used power configuration
|
|
||||||
if(hwCfg->disable_unused)
|
|
||||||
{
|
|
||||||
//Disable power to not used peripherals
|
|
||||||
PRR0 |= 0xC6; //Disable TWI0, TIM2, SPI0, UART0
|
|
||||||
PRR1 |= 0x34; //Disable TWI1, PRTC, SPI1
|
|
||||||
}
|
|
||||||
|
|
||||||
//Watchdog configuration
|
|
||||||
if(hwCfg->en_watchdog)
|
|
||||||
{
|
|
||||||
//watchdog timer setup
|
|
||||||
WDTCSR |= 0x10; //Change enable
|
|
||||||
WDTCSR |= 0x0D; //System reset mode, 0.5s period.
|
|
||||||
//use special instruction to reset watchdog timer
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Handbrake input
|
|
||||||
level_t HAL_ReadLvl_Handbrake(void)
|
|
||||||
{
|
|
||||||
if(PINB & 0x40) return HIGH;
|
|
||||||
else return LOW;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Brakes input
|
|
||||||
level_t HAL_ReadLvl_Brake(void)
|
|
||||||
{
|
|
||||||
if(PINB & 0x80) return HIGH;
|
|
||||||
else return LOW;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dimm input
|
|
||||||
level_t HAL_ReadLvl_Dimm(void)
|
|
||||||
{
|
|
||||||
if(PIND & 0x80) return HIGH;
|
|
||||||
else return LOW;
|
|
||||||
}
|
|
||||||
|
|
||||||
// UP button
|
|
||||||
level_t HAL_ReadLvl_BtnUp(void)
|
|
||||||
{
|
|
||||||
if(PINE & 0x08) return HIGH;
|
|
||||||
else return LOW;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Down button
|
|
||||||
level_t HAL_ReadLvl_BtnDown(void)
|
|
||||||
{
|
|
||||||
if(PINE & 0x02) return HIGH;
|
|
||||||
else return LOW;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mode button
|
|
||||||
level_t HAL_ReadLvl_BtnMode(void)
|
|
||||||
{
|
|
||||||
if(PINC & 0x20) return HIGH;
|
|
||||||
else return LOW;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handbrake pull
|
|
||||||
level_t HAL_ReadLvl_HandbrakePull(void)
|
|
||||||
{
|
|
||||||
if(PINB & 0x20) return HIGH;
|
|
||||||
else return LOW;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Coil driver control low
|
|
||||||
level_t HAL_ReadLvl_CoilLow(void)
|
|
||||||
{
|
|
||||||
if(PINB & 0x01) return HIGH;
|
|
||||||
else return LOW;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Coil driver control high
|
|
||||||
level_t HAL_ReadLvl_CoilHigh(void)
|
|
||||||
{
|
|
||||||
if(PINB & 0x02) return HIGH;
|
|
||||||
else return LOW;
|
|
||||||
}
|
|
||||||
|
|
||||||
// LED PWM control
|
|
||||||
level_t HAL_ReadLvl_LedsPwm(void)
|
|
||||||
{
|
|
||||||
if(PINB & 0x04) return HIGH;
|
|
||||||
else return LOW;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Speed 0 input pin
|
|
||||||
level_t HAL_ReadLvl_Speed0(void)
|
|
||||||
{
|
|
||||||
if(PINE & 0x04) return HIGH;
|
|
||||||
else return LOW;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Speed 1 input pin
|
|
||||||
level_t HAL_ReadLvl_Speed1(void)
|
|
||||||
{
|
|
||||||
if(PINE & 0x01) return HIGH;
|
|
||||||
else return LOW;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Speed common pull pin
|
|
||||||
level_t HAL_ReadLvl_SpeedPull(void)
|
|
||||||
{
|
|
||||||
if(PIND & 0x40) return HIGH;
|
|
||||||
else return LOW;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Set handbrake pull-up
|
|
||||||
void HAL_SetPull_Handbrake(level_t lvl)
|
|
||||||
{
|
|
||||||
switch(lvl)
|
|
||||||
{
|
|
||||||
case HIGH:
|
|
||||||
PORTB |= 0x20; //Set high
|
|
||||||
DDRB |= 0x20; //Set as output
|
|
||||||
break;
|
|
||||||
|
|
||||||
case LOW:
|
|
||||||
PORTB &= ~0x20; //Set low
|
|
||||||
DDRB |= 0x20; //Set as output
|
|
||||||
|
|
||||||
default:
|
|
||||||
DDRB &= ~0x20; //Set as input
|
|
||||||
PORTB |= 0x20; //Set high
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set speed inputs common pull
|
|
||||||
void HAL_SetPull_Speed(level_t lvl)
|
|
||||||
{
|
|
||||||
switch(lvl)
|
|
||||||
{
|
|
||||||
case HIGH:
|
|
||||||
PORTD |= 0x40; //Set high
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
PORTD &= ~0x40; //Set low
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ADC Wake
|
|
||||||
void HAL_ADC_Wake(void)
|
|
||||||
{
|
|
||||||
//Enable ADC power
|
|
||||||
PRR0 &= ~0x01;
|
|
||||||
//Enable ADC
|
|
||||||
ADCSRA |= 0x80;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ADC Sleep
|
|
||||||
void HAL_ADC_Sleep(void)
|
|
||||||
{
|
|
||||||
//wait to finish
|
|
||||||
while(ADCSRA&0x40);
|
|
||||||
//Disable ADC
|
|
||||||
ADCSRA &= ~0x80;
|
|
||||||
//Disable ADC power
|
|
||||||
PRR0 |= 0x01;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ADC Read
|
|
||||||
uint16_t HAL_ADC_Read(adcCh_t ch)
|
|
||||||
{
|
|
||||||
//check if ADC is enabled
|
|
||||||
if(!(ADCSRA&0x80)) return 0xFFFF;
|
|
||||||
|
|
||||||
uint8_t mux = (uint8_t)ch;
|
|
||||||
//Safe guard mux
|
|
||||||
if(mux > 15) return 0xFFFF;
|
|
||||||
// Not available channels
|
|
||||||
if((mux > 8) && (mux<14)) return 0xFFFF;
|
|
||||||
|
|
||||||
ADMUX &= ~0x0F;
|
|
||||||
ADMUX |= mux;
|
|
||||||
ADCSRA |= 0x40;
|
|
||||||
while(ADCSRA&0x40); //wait to finish
|
|
||||||
return ADC;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Coil Driver Low Side control
|
|
||||||
void HAL_Coil_SetLowSide(uint8_t on)
|
|
||||||
{
|
|
||||||
if(on) PORTB |= 0x01;
|
|
||||||
else PORTB &= ~0x01;
|
|
||||||
}
|
|
||||||
|
|
||||||
void HAL_Coil_SetPWM(uint8_t percent)
|
|
||||||
{
|
|
||||||
HAL_PWM_SetDuty100(PWM_COIL, percent);
|
|
||||||
}
|
|
||||||
|
|
||||||
void HAL_Coil_SetPWM16b(uint16_t value)
|
|
||||||
{
|
|
||||||
HAL_PWM_SetDuty16b(PWM_COIL, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// LED Display
|
|
||||||
void HAL_LEDS_Set(uint8_t image)
|
|
||||||
{
|
|
||||||
//Read current PORTD pin6, pin7
|
|
||||||
uint8_t keep = PORTD & 0xC0;
|
|
||||||
|
|
||||||
//Safe guard display
|
|
||||||
image &= 0x3F;
|
|
||||||
|
|
||||||
//Calculate new PORTD
|
|
||||||
keep |= image;
|
|
||||||
|
|
||||||
//Set PORTD
|
|
||||||
PORTD = keep;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t HAL_LEDS_Get(void)
|
|
||||||
{
|
|
||||||
return (PIND & 0x3F);
|
|
||||||
}
|
|
||||||
|
|
||||||
void HAL_LEDS_SetPWM(uint8_t percent)
|
|
||||||
{
|
|
||||||
HAL_PWM_SetDuty100(PWM_LED, percent);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// PWM Direct functions
|
|
||||||
void HAL_PWM_Wake(void)
|
|
||||||
{
|
|
||||||
//Enable Timer1 power
|
|
||||||
PRR0 &= ~0x80;
|
|
||||||
//Prepare Timer1 settings
|
|
||||||
TCNT1 = 0x0000;
|
|
||||||
OCR1A = 0x0000;
|
|
||||||
OCR1B = 0x0000;
|
|
||||||
//Enable clock
|
|
||||||
TCCR1B |= tim1_prescaler; //Enable timer
|
|
||||||
}
|
|
||||||
|
|
||||||
void HAL_PWM_Sleep(void)
|
|
||||||
{
|
|
||||||
// Turn off outputs
|
|
||||||
OCR1A = 0x0000;
|
|
||||||
OCR1B = 0x0000;
|
|
||||||
// Force timer to bottom
|
|
||||||
TCNT1 = (ICR1-1);
|
|
||||||
// Wait for outputs to be off
|
|
||||||
while((PINB&0x06)!=0x00) continue;
|
|
||||||
// Disable clock
|
|
||||||
TCCR1B &= ~0x07;
|
|
||||||
// Disable Timer1 power
|
|
||||||
PRR0 |= 0x80;
|
|
||||||
}
|
|
||||||
|
|
||||||
void HAL_PWM_SetDuty16b(pwmCh_t ch, uint16_t value)
|
|
||||||
{
|
|
||||||
value = 0xFFFF - value;
|
|
||||||
|
|
||||||
uint32_t top = (uint32_t)ICR1;
|
|
||||||
uint32_t temp = (uint32_t)value * top;
|
|
||||||
temp = temp/0x0000FFFF;
|
|
||||||
//Limit temp
|
|
||||||
if(temp>0x0000FFFF) temp = 0x0000FFFF;
|
|
||||||
uint16_t ocrx = (uint16_t) temp;
|
|
||||||
|
|
||||||
PWM_SetOCx(ch, ocrx);
|
|
||||||
}
|
|
||||||
|
|
||||||
void HAL_PWM_SetDuty100(pwmCh_t ch, uint8_t percent)
|
|
||||||
{
|
|
||||||
if(percent > 100) percent = 100;
|
|
||||||
percent = 100 - percent;
|
|
||||||
|
|
||||||
uint32_t top = (uint32_t)ICR1;
|
|
||||||
uint32_t temp = (uint32_t)percent * top;
|
|
||||||
temp = temp/100;
|
|
||||||
//Limit temp
|
|
||||||
if(temp>0x0000FFFF) temp = 0x0000FFFF;
|
|
||||||
uint16_t ocrx = (uint16_t) temp;
|
|
||||||
|
|
||||||
PWM_SetOCx(ch, ocrx);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**** Private function definitions ****/
|
|
||||||
static void PWM_SetOCx(pwmCh_t ch, uint16_t value)
|
|
||||||
{
|
|
||||||
switch(ch)
|
|
||||||
{
|
|
||||||
case PWM_COIL:
|
|
||||||
OCR1A = value;
|
|
||||||
return;
|
|
||||||
|
|
||||||
case PWM_LED:
|
|
||||||
OCR1B = value;
|
|
||||||
return;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,127 +0,0 @@
|
|||||||
/**** Includes ****/
|
|
||||||
#include "hal/udccd_hal.h"
|
|
||||||
#include "halfbridge.h"
|
|
||||||
|
|
||||||
/**** Private variables ****/
|
|
||||||
static const uint16_t min_dc = 3277; //5%
|
|
||||||
static const uint16_t max_dc = 62258; //95%
|
|
||||||
|
|
||||||
static uint16_t target = 0;
|
|
||||||
static uint8_t low_side_on = 1;
|
|
||||||
|
|
||||||
static uint16_t active_dc = 0;
|
|
||||||
|
|
||||||
static uint8_t is_en = 0;
|
|
||||||
|
|
||||||
/**** Private function declarations ****/
|
|
||||||
static uint16_t CalculateDuty16b(uint16_t target, uint16_t supply);
|
|
||||||
|
|
||||||
/**** Public function definitions ****/
|
|
||||||
void HB_SetTarget(uint16_t voltage)
|
|
||||||
{
|
|
||||||
target = voltage;
|
|
||||||
}
|
|
||||||
|
|
||||||
void HB_SetLowSide(uint8_t on)
|
|
||||||
{
|
|
||||||
low_side_on = on;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t HB_GetTarget(void)
|
|
||||||
{
|
|
||||||
return target;
|
|
||||||
}
|
|
||||||
|
|
||||||
void HB_UpdateOutput(uint16_t supply)
|
|
||||||
{
|
|
||||||
uint16_t temp_dc = CalculateDuty16b(target, supply);
|
|
||||||
|
|
||||||
HB_SetDirect(temp_dc);
|
|
||||||
}
|
|
||||||
|
|
||||||
void HB_SetDirect(uint16_t duty)
|
|
||||||
{
|
|
||||||
/// Limit duty cycle
|
|
||||||
if(duty > max_dc) active_dc = max_dc;
|
|
||||||
else if(duty < min_dc) active_dc = 0;
|
|
||||||
else active_dc = duty;
|
|
||||||
|
|
||||||
// Set duty cycle
|
|
||||||
if(!is_en) return;
|
|
||||||
HAL_Coil_SetLowSide(low_side_on);
|
|
||||||
HAL_Coil_SetPWM16b(active_dc);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t HB_IsLowOn(void)
|
|
||||||
{
|
|
||||||
if(HAL_ReadLvl_CoilLow() == HIGH) return 1;
|
|
||||||
else return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void HB_Enable(void)
|
|
||||||
{
|
|
||||||
// Restore low side
|
|
||||||
if(low_side_on) HAL_Coil_SetLowSide(1);
|
|
||||||
// Restore duty cycle
|
|
||||||
HAL_Coil_SetPWM(active_dc);
|
|
||||||
is_en = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void HB_Disable(void)
|
|
||||||
{
|
|
||||||
// Set 0 DC
|
|
||||||
HAL_Coil_SetPWM(0);
|
|
||||||
// Disable low side
|
|
||||||
HAL_Coil_SetLowSide(0);
|
|
||||||
is_en = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t HB_IsEnabled(void)
|
|
||||||
{
|
|
||||||
if(is_en) return 1;
|
|
||||||
else return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int8_t HB_IsOutputMatch(uint16_t fb_output_voltage, uint16_t limit)
|
|
||||||
{
|
|
||||||
// No fault if output not enabled
|
|
||||||
if(!is_en) return -1;
|
|
||||||
|
|
||||||
// Can't check voltage if low side is off
|
|
||||||
if(!low_side_on) return -1;
|
|
||||||
|
|
||||||
if(target==0)
|
|
||||||
{
|
|
||||||
// Output can be only 0
|
|
||||||
if(fb_output_voltage != 0) return 0;
|
|
||||||
else return 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Calculate upper and lower bounds
|
|
||||||
uint16_t max = target + limit;
|
|
||||||
uint16_t min = target - limit;
|
|
||||||
|
|
||||||
//Sanity check
|
|
||||||
if(max < target) max = 0xFFFF;
|
|
||||||
if(min > target) min = 0;
|
|
||||||
|
|
||||||
//Do check
|
|
||||||
if((fb_output_voltage < min)||(fb_output_voltage > max)) return 0;
|
|
||||||
else return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**** Private function definitions ****/
|
|
||||||
static uint16_t CalculateDuty16b(uint16_t target, uint16_t supply)
|
|
||||||
{
|
|
||||||
if(target==0) return 0;
|
|
||||||
if(supply==0) return 0;
|
|
||||||
if(target > supply) return 0xFFFF;
|
|
||||||
|
|
||||||
// Calculate Duty cycle, in 16bit format
|
|
||||||
uint32_t temp = (uint32_t)target * 0x0000FFFF;
|
|
||||||
temp = temp / supply;
|
|
||||||
|
|
||||||
//Limit output to 16 bits
|
|
||||||
if(temp > 0x0000FFFF) return 0xFFFF;
|
|
||||||
else return (uint16_t)temp;
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
#ifndef HALFBRIDGE_H_
|
|
||||||
#define HALFBRIDGE_H_
|
|
||||||
|
|
||||||
/**** Includes ****/
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
/**** Public function declarations ****/
|
|
||||||
void HB_UpdateOutput(uint16_t supply);
|
|
||||||
|
|
||||||
void HB_SetTarget(uint16_t voltage);
|
|
||||||
void HB_SetLowSide(uint8_t on);
|
|
||||||
|
|
||||||
void HB_SetDirect(uint16_t duty);
|
|
||||||
|
|
||||||
void HB_Enable(void);
|
|
||||||
void HB_Disable(void);
|
|
||||||
|
|
||||||
uint16_t HB_GetTarget(void);
|
|
||||||
|
|
||||||
uint8_t HB_IsLowOn(void);
|
|
||||||
uint8_t HB_IsEnabled(void);
|
|
||||||
int8_t HB_IsOutputMatch(uint16_t fb_output_voltage, uint16_t limit);
|
|
||||||
|
|
||||||
#endif /* HALFBRIDGE_H_ */
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
/**** Includes ****/
|
|
||||||
#include "hal/udccd_hal.h"
|
|
||||||
#include "inputs.h"
|
|
||||||
|
|
||||||
/**** Private definitions ****/
|
|
||||||
|
|
||||||
/**** Private variables ****/
|
|
||||||
static const uint8_t def_debounce_lim = 10;
|
|
||||||
|
|
||||||
/**** Private function declarations ****/
|
|
||||||
static void InitDefaultInput(inCh_t* inp);
|
|
||||||
static void ProcessInput(uint8_t read_lvl, inCh_t* inp);
|
|
||||||
|
|
||||||
/**** Public function definitions ****/
|
|
||||||
void Inputs_DefInit(inputs_t* inputs)
|
|
||||||
{
|
|
||||||
InitDefaultInput(&inputs->handbrake);
|
|
||||||
InitDefaultInput(&inputs->brakes);
|
|
||||||
InitDefaultInput(&inputs->dimm);
|
|
||||||
InitDefaultInput(&inputs->up);
|
|
||||||
InitDefaultInput(&inputs->down);
|
|
||||||
InitDefaultInput(&inputs->mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Inputs_UpdateAll(inputs_t* inputs)
|
|
||||||
{
|
|
||||||
// Chassis inputs
|
|
||||||
ProcessInput(HAL_ReadLvl_Handbrake(), &inputs->handbrake);
|
|
||||||
ProcessInput(HAL_ReadLvl_Brake(), &inputs->brakes);
|
|
||||||
ProcessInput(HAL_ReadLvl_Dimm(), &inputs->dimm);
|
|
||||||
|
|
||||||
// User inputs
|
|
||||||
ProcessInput(HAL_ReadLvl_BtnUp(), &inputs->up);
|
|
||||||
ProcessInput(HAL_ReadLvl_BtnDown(), &inputs->down);
|
|
||||||
ProcessInput(HAL_ReadLvl_BtnMode(), &inputs->mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Inputs_SetHanbrakePullUp(uint8_t on)
|
|
||||||
{
|
|
||||||
if(on) HAL_SetPull_Handbrake(HIGH);
|
|
||||||
else HAL_SetPull_Handbrake(HIZ);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**** Private function definitions ****/
|
|
||||||
static void InitDefaultInput(inCh_t* inp)
|
|
||||||
{
|
|
||||||
inp->is_active = 0;
|
|
||||||
inp->is_new = 0;
|
|
||||||
inp->state_timer = 0;
|
|
||||||
inp->cfg.act_level = LOW;
|
|
||||||
inp->cfg.dbnc_treshold = def_debounce_lim;
|
|
||||||
inp->proc.level = LOW;
|
|
||||||
inp->proc.dbnc_counter = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ProcessInput(uint8_t read_lvl, inCh_t* inp)
|
|
||||||
{
|
|
||||||
if(inp->state_timer < 0xFFFF) inp->state_timer++;
|
|
||||||
|
|
||||||
if(read_lvl != inp->proc.level)
|
|
||||||
{
|
|
||||||
//Debounce ongoing
|
|
||||||
inp->proc.dbnc_counter++;
|
|
||||||
if(inp->proc.dbnc_counter < inp->cfg.dbnc_treshold) return;
|
|
||||||
|
|
||||||
//Save level
|
|
||||||
inp->proc.level = read_lvl;
|
|
||||||
//Change state
|
|
||||||
if(inp->proc.level == inp->cfg.act_level) inp->is_active = 1;
|
|
||||||
else inp->is_active = 0;
|
|
||||||
// Update new flag
|
|
||||||
inp->is_new = 1;
|
|
||||||
// Reset state timer
|
|
||||||
inp->state_timer = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//Debounce failed
|
|
||||||
if(inp->proc.dbnc_counter) inp->proc.dbnc_counter = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
#ifndef INPUTS_H_
|
|
||||||
#define INPUTS_H_
|
|
||||||
|
|
||||||
/**** Includes ****/
|
|
||||||
#include <stdint.h>
|
|
||||||
#include "common/level.h"
|
|
||||||
|
|
||||||
/**** Public definitions ****/
|
|
||||||
typedef struct {
|
|
||||||
level_t act_level;
|
|
||||||
uint8_t dbnc_treshold;
|
|
||||||
} inChCfg_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
level_t level;
|
|
||||||
uint8_t dbnc_counter;
|
|
||||||
} inChRaw_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
uint8_t is_active;
|
|
||||||
uint8_t is_new;
|
|
||||||
uint16_t state_timer;
|
|
||||||
inChRaw_t proc;
|
|
||||||
inChCfg_t cfg;
|
|
||||||
} inCh_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
inCh_t handbrake;
|
|
||||||
inCh_t brakes;
|
|
||||||
inCh_t dimm;
|
|
||||||
inCh_t up;
|
|
||||||
inCh_t down;
|
|
||||||
inCh_t mode;
|
|
||||||
} inputs_t;
|
|
||||||
|
|
||||||
/**** Public function declarations ****/
|
|
||||||
void Inputs_DefInit(inputs_t* inputs);
|
|
||||||
|
|
||||||
void Inputs_UpdateAll(inputs_t* inputs);
|
|
||||||
|
|
||||||
void Inputs_SetHanbrakePullUp(uint8_t on);
|
|
||||||
|
|
||||||
#endif /* INPUTS_H_ */
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
/**** Includes ****/
|
|
||||||
#include "hal/udccd_hal.h"
|
|
||||||
#include "led_display.h"
|
|
||||||
|
|
||||||
/**** Private variables ****/
|
|
||||||
|
|
||||||
/**** Private function declarations ****/
|
|
||||||
|
|
||||||
/**** Public function definitions ****/
|
|
||||||
void LED_DSP_ShowImage(uint8_t image)
|
|
||||||
{
|
|
||||||
HAL_LEDS_Set(image);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LED_DSP_SetBrightness(uint8_t percent)
|
|
||||||
{
|
|
||||||
HAL_LEDS_SetPWM(percent);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**** Private function definitions ****/
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
/**** Includes ****/
|
|
||||||
#include <avr/eeprom.h>
|
|
||||||
#include "memory.h"
|
|
||||||
|
|
||||||
/**** Public function definitions ****/
|
|
||||||
uint8_t MEM_Read8b(uint8_t address)
|
|
||||||
{
|
|
||||||
return eeprom_read_byte((uint8_t*)address);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t MEM_Read16b(uint8_t address)
|
|
||||||
{
|
|
||||||
return eeprom_read_word((uint8_t*)address);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t MEM_Read32b(uint8_t address)
|
|
||||||
{
|
|
||||||
return eeprom_read_dword((uint8_t*)address);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MEM_Write8b(uint8_t address, uint8_t value)
|
|
||||||
{
|
|
||||||
return eeprom_write_byte((uint8_t*)address, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MEM_Write16b(uint8_t address, uint16_t value)
|
|
||||||
{
|
|
||||||
return eeprom_write_word((uint8_t*)address, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MEM_Write32b(uint8_t address, uint32_t value)
|
|
||||||
{
|
|
||||||
return eeprom_write_dword((uint8_t*)address, value);
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
#ifndef MEMORY_H_
|
|
||||||
#define MEMORY_H_
|
|
||||||
|
|
||||||
/**** Includes ****/
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
/**** Public function declarations ****/
|
|
||||||
uint8_t MEM_Read8b(uint8_t address);
|
|
||||||
uint16_t MEM_Read16b(uint8_t address);
|
|
||||||
uint32_t MEM_Read32b(uint8_t address);
|
|
||||||
|
|
||||||
void MEM_Write8b(uint8_t address, uint8_t value);
|
|
||||||
void MEM_Write16b(uint8_t address, uint16_t value);
|
|
||||||
void MEM_Write32b(uint8_t address, uint32_t value);
|
|
||||||
|
|
||||||
#endif /* MEMORY_H_ */
|
|
||||||
@@ -1,125 +0,0 @@
|
|||||||
/**** Includes ****/
|
|
||||||
#include "display.h"
|
|
||||||
|
|
||||||
/**** Private definitions ****/
|
|
||||||
|
|
||||||
/**** Private variables ****/
|
|
||||||
static uint8_t PWM_DIMM = 50;
|
|
||||||
static uint8_t PWM_BRIGTH = 100;
|
|
||||||
|
|
||||||
static uint8_t set_image = 0x00;
|
|
||||||
|
|
||||||
static uint16_t lock_timer = 0;
|
|
||||||
|
|
||||||
/**** Private function declarations ****/
|
|
||||||
static uint8_t ImageGen_Dot10(uint8_t percent);
|
|
||||||
static uint8_t ImageGen_Dot20(uint8_t percent);
|
|
||||||
static uint8_t ImageGen_Bar(uint8_t percent);
|
|
||||||
|
|
||||||
/**** Public function definitions ****/
|
|
||||||
void Display_CfgBacklight(uint8_t brigth, uint8_t dimm)
|
|
||||||
{
|
|
||||||
//Limit values
|
|
||||||
if(brigth>100) brigth = 100;
|
|
||||||
else if(brigth==0) brigth = 1;
|
|
||||||
|
|
||||||
if(dimm>100) dimm = 100;
|
|
||||||
else if(dimm==0) dimm = 1;
|
|
||||||
|
|
||||||
//Save values
|
|
||||||
PWM_BRIGTH = brigth;
|
|
||||||
PWM_DIMM = dimm;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Display_SetImage(uint8_t image)
|
|
||||||
{
|
|
||||||
if(lock_timer) return;
|
|
||||||
|
|
||||||
set_image = image & 0x3F;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Display_SetPercent(uint8_t value, dspStyle_t style)
|
|
||||||
{
|
|
||||||
switch(style)
|
|
||||||
{
|
|
||||||
case BAR:
|
|
||||||
Display_SetImage(ImageGen_Bar(value));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DOT10:
|
|
||||||
Display_SetImage(ImageGen_Dot10(value));
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
Display_SetImage(ImageGen_Dot20(value));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Display_SetScale(uint16_t value, uint16_t max_value ,dspStyle_t style)
|
|
||||||
{
|
|
||||||
//Convert value to percent
|
|
||||||
uint32_t temp = (uint32_t)value *100;
|
|
||||||
temp /= max_value;
|
|
||||||
|
|
||||||
//Limit value to 100 percent
|
|
||||||
uint8_t percent = 0;
|
|
||||||
if(temp >= 100) percent = 100;
|
|
||||||
else if(temp == 0) percent = 0;
|
|
||||||
else percent = (uint8_t)temp;
|
|
||||||
|
|
||||||
Display_SetPercent(percent, style);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Display_SetLock(uint16_t time)
|
|
||||||
{
|
|
||||||
lock_timer = time;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Display_Update(inputs_t* inputs)
|
|
||||||
{
|
|
||||||
// Brightness control
|
|
||||||
if(inputs->dimm.is_active) LED_DSP_SetBrightness(PWM_DIMM);
|
|
||||||
else LED_DSP_SetBrightness(PWM_BRIGTH);
|
|
||||||
|
|
||||||
if(lock_timer) lock_timer--;
|
|
||||||
|
|
||||||
// Set image
|
|
||||||
LED_DSP_ShowImage(set_image);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**** Private function definitions ****/
|
|
||||||
static uint8_t ImageGen_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 ImageGen_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 ImageGen_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;
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
#ifndef DISPLAY_DRV_H_
|
|
||||||
#define DISPLAY_DRV_H_
|
|
||||||
|
|
||||||
/**** Includes ****/
|
|
||||||
#include <avr/io.h>
|
|
||||||
#include "../devices/led_display.h"
|
|
||||||
#include "../devices/inputs.h"
|
|
||||||
|
|
||||||
/**** Public definitions ****/
|
|
||||||
typedef enum {
|
|
||||||
DOT20,
|
|
||||||
DOT10,
|
|
||||||
BAR
|
|
||||||
} dspStyle_t;
|
|
||||||
|
|
||||||
/**** Public function declarations ****/
|
|
||||||
void Display_SetImage(uint8_t image);
|
|
||||||
void Display_SetPercent(uint8_t value, dspStyle_t style);
|
|
||||||
void Display_SetScale(uint16_t value, uint16_t max_value ,dspStyle_t style);
|
|
||||||
|
|
||||||
void Display_SetLock(uint16_t time);
|
|
||||||
|
|
||||||
void Display_Update(inputs_t* inputs);
|
|
||||||
|
|
||||||
void Display_CfgBacklight(uint8_t brigth, uint8_t dimm);
|
|
||||||
|
|
||||||
#endif /* DISPLAY_DRV_H_ */
|
|
||||||
@@ -1,341 +0,0 @@
|
|||||||
/**** Includes ****/
|
|
||||||
#include "output.h"
|
|
||||||
|
|
||||||
/**** Private definitions ****/
|
|
||||||
typedef struct {
|
|
||||||
uint8_t active;
|
|
||||||
uint8_t time;
|
|
||||||
} warn_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
warn_t supply_voltage;
|
|
||||||
warn_t supply_current;
|
|
||||||
warn_t supply_power;
|
|
||||||
warn_t output_voltage;
|
|
||||||
warn_t output_current;
|
|
||||||
warn_t output_power;
|
|
||||||
warn_t output_open;
|
|
||||||
warn_t output_short;
|
|
||||||
warn_t output_mismatch;
|
|
||||||
} warnings_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
uint8_t supply_uvlo;
|
|
||||||
uint8_t supply_ovp;
|
|
||||||
uint8_t supply_ocp;
|
|
||||||
uint8_t supply_opp;
|
|
||||||
uint8_t output_ovp;
|
|
||||||
uint8_t output_ocp;
|
|
||||||
uint8_t output_opp;
|
|
||||||
uint8_t output_open;
|
|
||||||
uint8_t output_short;
|
|
||||||
} faults_t;
|
|
||||||
|
|
||||||
/**** Private constants ****/
|
|
||||||
static const uint16_t LIM_SUPPLY_UVLO = 8000; //mV
|
|
||||||
static const uint16_t LIM_SUPPLY_OVP = 18000; //mV
|
|
||||||
static const uint16_t LIM_SUPPLY_OCP = 7000; //mA
|
|
||||||
static const uint16_t LIM_SUPPLY_OPP = 40000; //mW
|
|
||||||
|
|
||||||
static const uint16_t LIM_OUTPUT_OVP = 12000; //mV
|
|
||||||
static const uint16_t LIM_OUTPUT_OCP = 7000; //mA
|
|
||||||
static const uint16_t LIM_OUTPUT_OPP = 40000; //mW
|
|
||||||
|
|
||||||
static const uint16_t LIM_OUTPUT_OPEN = 40000; //mR
|
|
||||||
static const uint16_t LIM_OUTPUT_SHORT = 750; //mR
|
|
||||||
|
|
||||||
static const uint16_t LIM_OUTPUT_MATCH = 100; //mV
|
|
||||||
|
|
||||||
static const uint8_t OCP_WARNING_LIMIT = 10; //cycles
|
|
||||||
static const uint8_t SHORT_WARNING_LIMIT = 50; //cycles
|
|
||||||
|
|
||||||
static const uint16_t MAX_OUTPUT_VOLTAGE = 10000; //mV
|
|
||||||
static const uint16_t MIN_OUTPUT_VOLTAGE = 100; //mV
|
|
||||||
|
|
||||||
static const uint16_t COOLDOWN_TIME = 5000;
|
|
||||||
|
|
||||||
/**** Private variables ****/
|
|
||||||
static warnings_t warnings;
|
|
||||||
static faults_t faults;
|
|
||||||
|
|
||||||
static uint16_t target_output = 0;
|
|
||||||
static uint16_t adj_target = 0;
|
|
||||||
|
|
||||||
static int32_t hb_volt_sum = 0;
|
|
||||||
|
|
||||||
static uint8_t new_target = 1;
|
|
||||||
|
|
||||||
static uint8_t steady_state = 0;
|
|
||||||
|
|
||||||
static faultState_t fault_state = F_NONE;
|
|
||||||
|
|
||||||
static uint16_t cooldown_timer = 0;
|
|
||||||
|
|
||||||
static outState_t out_state = O_OFF;
|
|
||||||
|
|
||||||
/**** Private function declarations ****/
|
|
||||||
static void Process_Warnings(analog_t* meas);
|
|
||||||
static uint8_t Process_Faults(void);
|
|
||||||
|
|
||||||
static void ProcessWarningTime(warn_t* w);
|
|
||||||
static uint8_t isAnyFaultActive(faults_t* f);
|
|
||||||
static uint8_t isFaultWarningActive(warnings_t* w, faults_t* f);
|
|
||||||
static void ResetFaults(faults_t* f);
|
|
||||||
|
|
||||||
/**** Public function definitions ****/
|
|
||||||
void Output_Enable(void)
|
|
||||||
{
|
|
||||||
ResetFaults(&faults);
|
|
||||||
target_output = 0;
|
|
||||||
out_state = O_ACTIVE;
|
|
||||||
HB_SetTarget(0) ;
|
|
||||||
HB_SetLowSide(1);
|
|
||||||
HB_Enable();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Output_Update(analog_t* meas)
|
|
||||||
{
|
|
||||||
Process_Warnings(meas);
|
|
||||||
|
|
||||||
// Convert Warnings to Faults
|
|
||||||
uint8_t active_fault = Process_Faults();
|
|
||||||
|
|
||||||
/// Ignore faults
|
|
||||||
active_fault = 0;
|
|
||||||
|
|
||||||
// Determine coil state
|
|
||||||
switch(out_state)
|
|
||||||
{
|
|
||||||
case O_ACTIVE:
|
|
||||||
if(active_fault)
|
|
||||||
{
|
|
||||||
// Disable output
|
|
||||||
HB_Disable();
|
|
||||||
out_state = O_FAULTED;
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
|
|
||||||
//Do target adjustment logic
|
|
||||||
if(steady_state >= 10)
|
|
||||||
{
|
|
||||||
//Calculate average HB voltage
|
|
||||||
hb_volt_sum /= 11;
|
|
||||||
|
|
||||||
// Calculate feedback adjusted HB output
|
|
||||||
int32_t error = hb_volt_sum - (int32_t)target_output;
|
|
||||||
int32_t temp = (int32_t)adj_target - error;
|
|
||||||
// Limit to 16bits
|
|
||||||
if(temp<=0) adj_target = 0;
|
|
||||||
else if(temp >= 0x0000FFFF) adj_target = 0xFFFF;
|
|
||||||
else adj_target = (uint16_t)temp;
|
|
||||||
steady_state = 0;
|
|
||||||
hb_volt_sum = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
hb_volt_sum += meas->hb_voltage;
|
|
||||||
steady_state++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Closed loop or open loop target set
|
|
||||||
if(new_target)
|
|
||||||
{
|
|
||||||
// Set open-loop HB output
|
|
||||||
HB_SetTarget(target_output);
|
|
||||||
adj_target = target_output;
|
|
||||||
steady_state = 0;
|
|
||||||
new_target = 0;
|
|
||||||
hb_volt_sum = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
HB_SetTarget(adj_target);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update output
|
|
||||||
HB_UpdateOutput(meas->supply_voltage);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case O_FAULTED:
|
|
||||||
if(!active_fault)
|
|
||||||
{
|
|
||||||
//Return to normal state
|
|
||||||
HB_Enable();
|
|
||||||
out_state = O_ACTIVE;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default: //OFF
|
|
||||||
if(HB_IsEnabled()) HB_Disable();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Output_SetTarget(uint16_t voltage)
|
|
||||||
{
|
|
||||||
if(voltage > MAX_OUTPUT_VOLTAGE) voltage = MAX_OUTPUT_VOLTAGE;
|
|
||||||
else if((voltage > 0)&&(voltage < MIN_OUTPUT_VOLTAGE)) voltage = MIN_OUTPUT_VOLTAGE;
|
|
||||||
|
|
||||||
if(voltage != target_output) new_target = 1;
|
|
||||||
target_output = voltage;
|
|
||||||
}
|
|
||||||
|
|
||||||
outState_t Output_GetOutputState(void)
|
|
||||||
{
|
|
||||||
return out_state;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**** Private function definitions ****/
|
|
||||||
static void Process_Warnings(analog_t* meas)
|
|
||||||
{
|
|
||||||
// Supply UVLO and OVP
|
|
||||||
if((meas->supply_voltage > LIM_SUPPLY_OVP)||(meas->supply_voltage < LIM_SUPPLY_UVLO)) warnings.supply_voltage.active = 1;
|
|
||||||
else warnings.supply_voltage.active = 0;
|
|
||||||
|
|
||||||
// Supply OCP
|
|
||||||
if(meas->supply_current > LIM_SUPPLY_OCP) warnings.supply_current.active = 1;
|
|
||||||
else warnings.supply_current.active = 0;
|
|
||||||
|
|
||||||
// Supply OPP
|
|
||||||
if(meas->supply_power > LIM_SUPPLY_OPP) warnings.supply_power.active = 1;
|
|
||||||
else warnings.supply_power.active = 0;
|
|
||||||
|
|
||||||
// Halfbridge output conditions
|
|
||||||
// Output Target mismatch
|
|
||||||
if(HB_IsOutputMatch(meas->hb_voltage, LIM_OUTPUT_MATCH) == 0) warnings.output_mismatch.active = 1;
|
|
||||||
else warnings.output_mismatch.active = 0;
|
|
||||||
|
|
||||||
// Output OCP
|
|
||||||
if((HB_IsLowOn())&&(meas->hb_currnet > LIM_OUTPUT_OCP)) warnings.output_current.active = 1;
|
|
||||||
else warnings.output_current.active = 0;
|
|
||||||
|
|
||||||
// Output OVP
|
|
||||||
if((HB_IsLowOn())&&(meas->hb_voltage > LIM_OUTPUT_OVP)) warnings.output_voltage.active = 1;
|
|
||||||
else warnings.output_voltage.active = 0;
|
|
||||||
|
|
||||||
// Output OPP
|
|
||||||
if((HB_IsEnabled())&&(meas->hb_power > LIM_OUTPUT_OPP)) warnings.output_power.active = 1;
|
|
||||||
else warnings.output_power.active = 0;
|
|
||||||
|
|
||||||
// Output Short
|
|
||||||
if((HB_IsEnabled())&&(meas->hb_resistance < LIM_OUTPUT_SHORT)) warnings.output_short.active = 1;
|
|
||||||
else warnings.output_short.active = 0;
|
|
||||||
|
|
||||||
// Output Open - Load loss
|
|
||||||
if((HB_IsEnabled())&&(meas->hb_resistance > LIM_OUTPUT_OPEN)) warnings.output_open.active = 1;
|
|
||||||
else warnings.output_open.active = 0;
|
|
||||||
|
|
||||||
ProcessWarningTime(&warnings.supply_voltage);
|
|
||||||
ProcessWarningTime(&warnings.supply_current);
|
|
||||||
ProcessWarningTime(&warnings.supply_power);
|
|
||||||
ProcessWarningTime(&warnings.output_mismatch);
|
|
||||||
ProcessWarningTime(&warnings.output_voltage);
|
|
||||||
ProcessWarningTime(&warnings.output_current);
|
|
||||||
ProcessWarningTime(&warnings.output_power);
|
|
||||||
ProcessWarningTime(&warnings.output_open);
|
|
||||||
ProcessWarningTime(&warnings.output_short);
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint8_t Process_Faults(void)
|
|
||||||
{
|
|
||||||
// Check warnings to escalate to fault
|
|
||||||
// Supply OCP
|
|
||||||
if(warnings.supply_current.time > OCP_WARNING_LIMIT) faults.supply_ocp = 1;
|
|
||||||
|
|
||||||
// Output OCP
|
|
||||||
if(warnings.output_current.time > OCP_WARNING_LIMIT) faults.output_ocp = 1;
|
|
||||||
|
|
||||||
// Output short
|
|
||||||
if(warnings.output_short.time > SHORT_WARNING_LIMIT) faults.output_short = 1;
|
|
||||||
|
|
||||||
switch(fault_state)
|
|
||||||
{
|
|
||||||
case F_ACTIVE:
|
|
||||||
// Check if fault still active
|
|
||||||
if(!isFaultWarningActive(&warnings, &faults))
|
|
||||||
{
|
|
||||||
// Fault cause ended, go to cooldown
|
|
||||||
cooldown_timer = COOLDOWN_TIME;
|
|
||||||
fault_state = F_COOLDOWN;
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
|
|
||||||
case F_COOLDOWN:
|
|
||||||
// Check if fault reoccurs
|
|
||||||
if(isFaultWarningActive(&warnings, &faults))
|
|
||||||
{
|
|
||||||
fault_state = F_ACTIVE;
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Wait for cooldown timer, reset fault flags
|
|
||||||
if(cooldown_timer) cooldown_timer--;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ResetFaults(&faults);
|
|
||||||
fault_state = F_NONE;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default: //NONE
|
|
||||||
// Check for new faults
|
|
||||||
if(isAnyFaultActive(&faults))
|
|
||||||
{
|
|
||||||
// Start fault process
|
|
||||||
fault_state = F_ACTIVE;
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(fault_state != F_NONE) return 1;
|
|
||||||
else return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ProcessWarningTime(warn_t* w)
|
|
||||||
{
|
|
||||||
if((w->active)&&(w->time < 0xFF)) w->time++;
|
|
||||||
else if(w->active == 0) w->time = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint8_t isAnyFaultActive(faults_t* f)
|
|
||||||
{
|
|
||||||
if(f->supply_uvlo) return 1;
|
|
||||||
if(f->supply_ovp) return 1;
|
|
||||||
if(f->supply_ocp) return 1;
|
|
||||||
if(f->supply_opp) return 1;
|
|
||||||
if(f->output_ovp) return 1;
|
|
||||||
if(f->output_ocp) return 1;
|
|
||||||
if(f->output_opp) return 1;
|
|
||||||
if(f->output_open) return 1;
|
|
||||||
if(f->output_short) return 1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint8_t isFaultWarningActive(warnings_t* w, faults_t* f)
|
|
||||||
{
|
|
||||||
if((f->supply_uvlo) && (w->supply_voltage.active)) return 1;
|
|
||||||
if((f->supply_ovp) && (w->supply_voltage.active)) return 1;
|
|
||||||
if((f->supply_ocp) && (w->supply_current.active)) return 1;
|
|
||||||
if((f->supply_opp) && (w->supply_power.active) ) return 1;
|
|
||||||
if((f->output_ovp) && (w->output_voltage.active)) return 1;
|
|
||||||
if((f->output_ocp) && (w->output_current.active)) return 1;
|
|
||||||
if((f->output_opp) && (w->output_power.active) ) return 1;
|
|
||||||
if((f->output_open) && (w->output_open.active) ) return 1;
|
|
||||||
if((f->output_short) && (w->output_short.active) ) return 1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ResetFaults(faults_t* f)
|
|
||||||
{
|
|
||||||
f->supply_uvlo = 0;
|
|
||||||
f->supply_ovp = 0;
|
|
||||||
f->supply_ocp = 0;
|
|
||||||
f->supply_opp = 0;
|
|
||||||
f->output_ovp = 0;
|
|
||||||
f->output_ocp = 0;
|
|
||||||
f->output_opp = 0;
|
|
||||||
f->output_open = 0;
|
|
||||||
f->output_short = 0;
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
#ifndef OUTPUT_DRV_H_
|
|
||||||
#define OUTPUT_DRV_H_
|
|
||||||
|
|
||||||
/**** Includes ****/
|
|
||||||
#include <avr/io.h>
|
|
||||||
#include "../devices/analog.h"
|
|
||||||
#include "../devices/halfbridge.h"
|
|
||||||
|
|
||||||
/**** Public definitions ****/
|
|
||||||
typedef enum {
|
|
||||||
F_NONE,
|
|
||||||
F_ACTIVE,
|
|
||||||
F_COOLDOWN
|
|
||||||
} faultState_t;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
O_OFF,
|
|
||||||
O_ACTIVE,
|
|
||||||
O_FAULTED
|
|
||||||
} outState_t;
|
|
||||||
|
|
||||||
/**** Public function declarations ****/
|
|
||||||
void Output_Enable(void);
|
|
||||||
void Output_Update(analog_t* meas);
|
|
||||||
|
|
||||||
void Output_SetTarget(uint16_t voltage);
|
|
||||||
|
|
||||||
outState_t Output_GetOutputState(void);
|
|
||||||
|
|
||||||
#endif /* OUTPUT_DRV_H_ */
|
|
||||||
@@ -1,127 +0,0 @@
|
|||||||
/**** Includes ****/
|
|
||||||
#include "coil.h"
|
|
||||||
|
|
||||||
/**** Private definitions ****/
|
|
||||||
|
|
||||||
/**** Private constants ****/
|
|
||||||
|
|
||||||
/**** Private variables ****/
|
|
||||||
static uint16_t lock_current = 4500; //mA
|
|
||||||
static uint16_t min_current = 100; //mA
|
|
||||||
static uint16_t target_current = 0; //mA
|
|
||||||
static uint8_t new_target = 1;
|
|
||||||
|
|
||||||
static uint16_t adj_target_current = 0; //mA
|
|
||||||
static uint16_t target_voltage = 0; //mV
|
|
||||||
|
|
||||||
static uint8_t act_force = 0;
|
|
||||||
|
|
||||||
static uint16_t nominal_resitance = 1500; //mR
|
|
||||||
|
|
||||||
static int32_t sum_current = 0;
|
|
||||||
static uint8_t sum_cnt = 0;
|
|
||||||
|
|
||||||
|
|
||||||
/**** Private function declarations ****/
|
|
||||||
static uint16_t UpdateVoltage(uint16_t cur, uint16_t res);
|
|
||||||
|
|
||||||
/**** Public function definitions ****/
|
|
||||||
void Coil_SetLockCurrent(uint16_t lock_i)
|
|
||||||
{
|
|
||||||
lock_current = lock_i;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Coil_SetTarget_Force(uint8_t force)
|
|
||||||
{
|
|
||||||
// Check if worth doing
|
|
||||||
if(force == act_force) return;
|
|
||||||
|
|
||||||
// Calculate new target current
|
|
||||||
act_force = force;
|
|
||||||
|
|
||||||
// Check simple answer
|
|
||||||
uint16_t new_current = 0;
|
|
||||||
if(force==0) new_current = 0;
|
|
||||||
else if(force >= 100) new_current = lock_current;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
uint32_t temp = (uint32_t)force * lock_current;
|
|
||||||
temp /= 100;
|
|
||||||
|
|
||||||
if(temp > 0x0000FFFF) new_current = lock_current;
|
|
||||||
else new_current = (uint16_t) temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update new target
|
|
||||||
Coil_SetTarget_Current(new_current);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Coil_SetTarget_Current(uint16_t current)
|
|
||||||
{
|
|
||||||
if(current >= lock_current) current = lock_current;
|
|
||||||
else if((current > 0)&&(current <= min_current)) current = min_current;
|
|
||||||
|
|
||||||
if(current != target_current) new_target = 1;
|
|
||||||
target_current = current;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t Coil_GetTargetVolatge(void)
|
|
||||||
{
|
|
||||||
return target_voltage;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t Coil_Update(analog_t* meas)
|
|
||||||
{
|
|
||||||
// Collect average current
|
|
||||||
sum_current += meas->hb_currnet;
|
|
||||||
sum_cnt++;
|
|
||||||
|
|
||||||
// Update measurement
|
|
||||||
if(sum_cnt >= 10)
|
|
||||||
{
|
|
||||||
// Calculate average
|
|
||||||
sum_current /= sum_cnt;
|
|
||||||
|
|
||||||
// Calculate error
|
|
||||||
int32_t error = sum_current - (int32_t)target_current;
|
|
||||||
int32_t temp = (int32_t)adj_target_current - error;
|
|
||||||
|
|
||||||
// Limit to 16bits
|
|
||||||
if(temp<0) adj_target_current = 0;
|
|
||||||
else if(temp > 0x0000FFFF) adj_target_current = 0xFFFF;
|
|
||||||
else adj_target_current = (uint16_t)temp;
|
|
||||||
sum_cnt = 0;
|
|
||||||
sum_current = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Closed loop or open loop target set
|
|
||||||
if(new_target)
|
|
||||||
{
|
|
||||||
// Set open-loop HB output
|
|
||||||
target_voltage = UpdateVoltage(target_current, nominal_resitance);
|
|
||||||
adj_target_current = target_current;
|
|
||||||
new_target = 0;
|
|
||||||
sum_cnt = 0;
|
|
||||||
sum_current = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
target_voltage = UpdateVoltage(adj_target_current, nominal_resitance);
|
|
||||||
}
|
|
||||||
|
|
||||||
return target_voltage;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**** Private function definitions ****/
|
|
||||||
static uint16_t UpdateVoltage(uint16_t cur, uint16_t res)
|
|
||||||
{
|
|
||||||
// Update settable voltage
|
|
||||||
if(cur==0) return 0;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
uint32_t volt = (uint32_t)cur * res;
|
|
||||||
volt /= 1000;
|
|
||||||
if(volt > 0x0000FFFF) return 0xFFFF;
|
|
||||||
else return (uint16_t)volt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
#ifndef COIL_LOGIC_H_
|
|
||||||
#define COIL_LOGIC_H_
|
|
||||||
|
|
||||||
/**** Includes ****/
|
|
||||||
#include <stdint.h>
|
|
||||||
#include "../devices/analog.h"
|
|
||||||
|
|
||||||
/**** Public definitions ****/
|
|
||||||
|
|
||||||
/**** Public function declarations ****/
|
|
||||||
void Coil_SetTarget_Force(uint8_t force);
|
|
||||||
void Coil_SetTarget_Current(uint16_t current);
|
|
||||||
uint16_t Coil_GetTargetVolatge(void);
|
|
||||||
|
|
||||||
uint16_t Coil_Update(analog_t* meas);
|
|
||||||
|
|
||||||
void Coil_SetLockCurrent(uint16_t lock_i);
|
|
||||||
|
|
||||||
#endif /* COIL_LOGIC_H_ */
|
|
||||||
@@ -1,186 +0,0 @@
|
|||||||
/**** Includes ****/
|
|
||||||
#include "force.h"
|
|
||||||
|
|
||||||
/**** Private definitions ****/
|
|
||||||
|
|
||||||
/**** Private constants ****/
|
|
||||||
static const int8_t BUTTONS_STEP = 10;
|
|
||||||
static const uint16_t BUTTON_HOLD_TIME = 250;
|
|
||||||
static const uint16_t MODE_HOLD_TIME = 500;
|
|
||||||
|
|
||||||
/**** Private variables ****/
|
|
||||||
static inputMode_t input_mode = IM_BUTTONS;
|
|
||||||
|
|
||||||
static uint8_t user_force = 0;
|
|
||||||
static uint8_t new_user_force = 0;
|
|
||||||
|
|
||||||
static brakeMode_t brake_mode = BM_OPEN;
|
|
||||||
static uint8_t new_brake_mode = 1;
|
|
||||||
|
|
||||||
/**** Private function declarations ****/
|
|
||||||
static uint8_t SaturatedAdd(uint8_t base, int8_t delta);
|
|
||||||
|
|
||||||
/**** Public function definitions ****/
|
|
||||||
inputMode_t Force_GetInputMode(void)
|
|
||||||
{
|
|
||||||
return input_mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Force_CfgInputMode(inputMode_t in_mode)
|
|
||||||
{
|
|
||||||
input_mode = in_mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Force_SetUserForce(uint8_t force)
|
|
||||||
{
|
|
||||||
if(force > 100) force = 100;
|
|
||||||
user_force = force;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Force_SetBrakeMode(uint8_t bmode)
|
|
||||||
{
|
|
||||||
brake_mode = bmode;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t Force_Update(inputs_t* inputs, analog_t* meas)
|
|
||||||
{
|
|
||||||
// Process user inputs
|
|
||||||
if(input_mode==IM_POT)
|
|
||||||
{
|
|
||||||
// Process potentiometer
|
|
||||||
if(meas->pot_voltage <= 500) user_force = 0;
|
|
||||||
else if(meas->pot_voltage >= 4500 ) user_force = 100;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
uint16_t pot_u = meas->pot_voltage;
|
|
||||||
pot_u /= 50;
|
|
||||||
|
|
||||||
//Limit to 100
|
|
||||||
if(pot_u > 100) user_force = 100;
|
|
||||||
else if(pot_u < 10) user_force = 10;
|
|
||||||
else user_force = (uint8_t)pot_u;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Process +/- timer
|
|
||||||
if((inputs->down.is_active)&&(inputs->down.state_timer > BUTTON_HOLD_TIME))
|
|
||||||
{
|
|
||||||
inputs->down.is_new = 1;
|
|
||||||
inputs->down.state_timer = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
if((inputs->up.is_active)&&(inputs->up.state_timer > BUTTON_HOLD_TIME))
|
|
||||||
{
|
|
||||||
inputs->up.is_new = 1;
|
|
||||||
inputs->up.state_timer = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Process +/- logic
|
|
||||||
if((inputs->down.is_new)&&(inputs->down.is_active))
|
|
||||||
{
|
|
||||||
user_force = SaturatedAdd(user_force, -1 * BUTTONS_STEP);
|
|
||||||
new_user_force = 1;
|
|
||||||
}
|
|
||||||
else if((inputs->up.is_new)&&(inputs->up.is_active))
|
|
||||||
{
|
|
||||||
user_force = SaturatedAdd(user_force, BUTTONS_STEP);
|
|
||||||
new_user_force = 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
inputs->down.is_new = 0;
|
|
||||||
inputs->up.is_new = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process mode timer
|
|
||||||
if((inputs->mode.is_active)&&(inputs->mode.state_timer > MODE_HOLD_TIME))
|
|
||||||
{
|
|
||||||
inputs->mode.is_new = 1;
|
|
||||||
inputs->mode.state_timer = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Process mode logic
|
|
||||||
if((inputs->mode.is_new)&&(inputs->mode.is_active))
|
|
||||||
{
|
|
||||||
//Cycle mode
|
|
||||||
switch(brake_mode)
|
|
||||||
{
|
|
||||||
case BM_OPEN:
|
|
||||||
brake_mode = BM_KEEP;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BM_KEEP:
|
|
||||||
brake_mode = BM_LOCK;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BM_LOCK:
|
|
||||||
brake_mode = BM_OPEN;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
brake_mode = BM_OPEN;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
new_brake_mode = 1;
|
|
||||||
};
|
|
||||||
inputs->mode.is_new = 0;
|
|
||||||
|
|
||||||
|
|
||||||
// Determine next target force from inputs
|
|
||||||
if(inputs->handbrake.is_active)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else if(inputs->brakes.is_active)
|
|
||||||
{
|
|
||||||
switch(brake_mode)
|
|
||||||
{
|
|
||||||
case BM_LOCK:
|
|
||||||
return 100;
|
|
||||||
|
|
||||||
case BM_KEEP:
|
|
||||||
return user_force;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return user_force;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t Force_IsNewUserForce(void)
|
|
||||||
{
|
|
||||||
return new_user_force;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Force_ResetNewUserForce(void)
|
|
||||||
{
|
|
||||||
new_user_force = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
brakeMode_t Force_GetBrakeMode(void)
|
|
||||||
{
|
|
||||||
return brake_mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t Force_IsNewBrakeMode(void)
|
|
||||||
{
|
|
||||||
return new_brake_mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Force_ResetNewBrakeMode(void)
|
|
||||||
{
|
|
||||||
new_brake_mode = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**** Private function definitions ****/
|
|
||||||
static uint8_t SaturatedAdd(uint8_t base, int8_t delta)
|
|
||||||
{
|
|
||||||
int16_t temp = (int16_t)base + delta;
|
|
||||||
if(temp < 0) return 0;
|
|
||||||
else if(temp >= 100) return 100;
|
|
||||||
else return (uint8_t)temp;
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
#ifndef FORCE_LOGIC_H_
|
|
||||||
#define FORCE_LOGIC_H_
|
|
||||||
|
|
||||||
/**** Includes ****/
|
|
||||||
#include <stdint.h>
|
|
||||||
#include "../devices/analog.h"
|
|
||||||
#include "../devices/inputs.h"
|
|
||||||
|
|
||||||
/**** Public definitions ****/
|
|
||||||
typedef enum {
|
|
||||||
BM_OPEN,
|
|
||||||
BM_KEEP,
|
|
||||||
BM_LOCK
|
|
||||||
} brakeMode_t;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
IM_BUTTONS,
|
|
||||||
IM_POT
|
|
||||||
} inputMode_t;
|
|
||||||
|
|
||||||
/**** Public function declarations ****/
|
|
||||||
void Force_CfgInputMode(inputMode_t in_mode);
|
|
||||||
inputMode_t Force_GetInputMode(void);
|
|
||||||
|
|
||||||
uint8_t Force_Update(inputs_t* inputs, analog_t* meas);
|
|
||||||
|
|
||||||
void Force_SetBrakeMode(uint8_t bmode);
|
|
||||||
brakeMode_t Force_GetBrakeMode(void);
|
|
||||||
uint8_t Force_IsNewBrakeMode(void);
|
|
||||||
void Force_ResetNewBrakeMode(void);
|
|
||||||
|
|
||||||
void Force_SetUserForce(uint8_t force);
|
|
||||||
uint8_t Force_IsNewUserForce(void);
|
|
||||||
void Force_ResetNewUserForce(void);
|
|
||||||
|
|
||||||
#endif /* FORCE_LOGIC_H_ */
|
|
||||||
@@ -1,184 +0,0 @@
|
|||||||
/**** Includes ****/
|
|
||||||
#include "settings.h"
|
|
||||||
|
|
||||||
/**** Private definitions ****/
|
|
||||||
|
|
||||||
/**** Private constants ****/
|
|
||||||
static const uint8_t addr_force = 0x01;
|
|
||||||
static const uint8_t addr_bmode = 0x02;
|
|
||||||
static const uint8_t addr_inmode = 0x03;
|
|
||||||
|
|
||||||
static const uint8_t addr_dsp_bright = 0x04;
|
|
||||||
static const uint8_t addr_dsp_dimm = 0x05;
|
|
||||||
|
|
||||||
static const uint8_t addr_lock_amps = 0x06;
|
|
||||||
|
|
||||||
/**** Private variables ****/
|
|
||||||
static uint16_t save_force_timer = 0;
|
|
||||||
static uint16_t save_bmode_timer = 0;
|
|
||||||
|
|
||||||
/**** Private function declarations ****/
|
|
||||||
|
|
||||||
/**** Public function definitions ****/
|
|
||||||
void Setings_Update(uint8_t is_new_force, uint8_t force, uint8_t is_new_bmode, brakeMode_t bmode)
|
|
||||||
{
|
|
||||||
if(is_new_force) save_force_timer = 5000;
|
|
||||||
|
|
||||||
if(is_new_bmode) save_bmode_timer = 5000;
|
|
||||||
|
|
||||||
if(save_force_timer)
|
|
||||||
{
|
|
||||||
save_force_timer--;
|
|
||||||
if(!save_force_timer)
|
|
||||||
{
|
|
||||||
// Save force setting
|
|
||||||
Setings_SaveForce(force);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
if(save_bmode_timer)
|
|
||||||
{
|
|
||||||
save_bmode_timer--;
|
|
||||||
if(!save_bmode_timer)
|
|
||||||
{
|
|
||||||
// Save mode setting
|
|
||||||
Setings_SaveBrakeMode(bmode);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Setings_SaveForce(uint8_t value)
|
|
||||||
{
|
|
||||||
MEM_Write8b(addr_force, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t Setings_GetForce(void)
|
|
||||||
{
|
|
||||||
uint8_t val = MEM_Read8b(addr_force);
|
|
||||||
if(val > 100) return 0;
|
|
||||||
else return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Setings_SaveBrakeMode(brakeMode_t bmode)
|
|
||||||
{
|
|
||||||
// Convert and save input mode setting
|
|
||||||
// Convert and save mode setting
|
|
||||||
uint8_t val = 0x00;
|
|
||||||
switch(bmode)
|
|
||||||
{
|
|
||||||
case BM_LOCK:
|
|
||||||
val = 'L';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BM_KEEP:
|
|
||||||
val = 'K';
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
val = 'O';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
MEM_Write8b(addr_bmode, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
brakeMode_t Setings_GetBrakeMode(void)
|
|
||||||
{
|
|
||||||
// Convert and return mode setting
|
|
||||||
uint8_t val = MEM_Read8b(addr_bmode);
|
|
||||||
switch(val)
|
|
||||||
{
|
|
||||||
case 'L':
|
|
||||||
return BM_LOCK;
|
|
||||||
|
|
||||||
case 'K':
|
|
||||||
return BM_KEEP;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return BM_OPEN;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Setings_SaveInputMode(inputMode_t inmode)
|
|
||||||
{
|
|
||||||
// Convert and save input mode setting
|
|
||||||
uint8_t val = 0x00;
|
|
||||||
switch(inmode)
|
|
||||||
{
|
|
||||||
case IM_POT:
|
|
||||||
val = 'P';
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
val = 'B';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
MEM_Write8b(addr_inmode, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
inputMode_t Setings_GetInputMode(void)
|
|
||||||
{
|
|
||||||
// Convert and return input mode setting
|
|
||||||
uint8_t val = MEM_Read8b(addr_inmode);
|
|
||||||
switch(val)
|
|
||||||
{
|
|
||||||
case 'P':
|
|
||||||
return IM_POT;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return IM_BUTTONS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Setings_SaveDisplayBrigthLvl(uint8_t value)
|
|
||||||
{
|
|
||||||
MEM_Write8b(addr_dsp_bright, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t Setings_GetDisplayBrigthLvl(void)
|
|
||||||
{
|
|
||||||
uint8_t val = MEM_Read8b(addr_dsp_bright);
|
|
||||||
if(val > 100) return 100;
|
|
||||||
else return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Setings_SaveDisplayDimmLvl(uint8_t value)
|
|
||||||
{
|
|
||||||
MEM_Write8b(addr_dsp_dimm, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t Setings_GetDisplayDimmLvl(void)
|
|
||||||
{
|
|
||||||
uint8_t val = MEM_Read8b(addr_dsp_dimm);
|
|
||||||
if(val > 100) return 50;
|
|
||||||
else return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Setings_SaveLockCurrent(uint16_t value)
|
|
||||||
{
|
|
||||||
MEM_Write16b(addr_lock_amps, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t Setings_GetLockCurrent(void)
|
|
||||||
{
|
|
||||||
uint16_t val = MEM_Read16b(addr_lock_amps);
|
|
||||||
if(val > 6000) return 4500;
|
|
||||||
else return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Setings_SaveDefault(void)
|
|
||||||
{
|
|
||||||
Setings_SaveForce(0);
|
|
||||||
Setings_SaveBrakeMode(BM_OPEN);
|
|
||||||
Setings_SaveInputMode(IM_BUTTONS);
|
|
||||||
Setings_SaveDisplayBrigthLvl(100);
|
|
||||||
Setings_SaveDisplayDimmLvl(50);
|
|
||||||
Setings_SaveLockCurrent(4500);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**** Private function definitions ****/
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
#ifndef SETTINGS_LOGIC_H_
|
|
||||||
#define SETTINGS_LOGIC_H_
|
|
||||||
|
|
||||||
/**** Includes ****/
|
|
||||||
#include <stdint.h>
|
|
||||||
#include "../devices/memory.h"
|
|
||||||
#include "force.h"
|
|
||||||
|
|
||||||
/**** Public definitions ****/
|
|
||||||
|
|
||||||
/**** Public function declarations ****/
|
|
||||||
void Setings_Update(uint8_t is_new_force, uint8_t force, uint8_t is_new_bmode, brakeMode_t bmode);
|
|
||||||
|
|
||||||
void Setings_SaveForce(uint8_t value);
|
|
||||||
uint8_t Setings_GetForce(void);
|
|
||||||
|
|
||||||
void Setings_SaveBrakeMode(brakeMode_t bmode);
|
|
||||||
brakeMode_t Setings_GetBrakeMode(void);
|
|
||||||
|
|
||||||
void Setings_SaveInputMode(inputMode_t inmode);
|
|
||||||
inputMode_t Setings_GetInputMode(void);
|
|
||||||
|
|
||||||
void Setings_SaveDisplayBrigthLvl(uint8_t value);
|
|
||||||
uint8_t Setings_GetDisplayBrigthLvl(void);
|
|
||||||
|
|
||||||
void Setings_SaveDisplayDimmLvl(uint8_t value);
|
|
||||||
uint8_t Setings_GetDisplayDimmLvl(void);
|
|
||||||
|
|
||||||
void Setings_SaveLockCurrent(uint16_t value);
|
|
||||||
uint16_t Setings_GetLockCurrent(void);
|
|
||||||
|
|
||||||
void Setings_SaveDefault(void);
|
|
||||||
|
|
||||||
#endif /* SETTINGS_LOGIC_H_ */
|
|
||||||
170
firmware/main.c
170
firmware/main.c
@@ -1,170 +0,0 @@
|
|||||||
/**** Includes ****/
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#include "devices/config.h"
|
|
||||||
#include "devices/analog.h"
|
|
||||||
#include "devices/inputs.h"
|
|
||||||
#include "devices/memory.h"
|
|
||||||
|
|
||||||
#include "drivers/output.h"
|
|
||||||
#include "drivers/display.h"
|
|
||||||
|
|
||||||
#include "logic/force.h"
|
|
||||||
#include "logic/coil.h"
|
|
||||||
#include "logic/settings.h"
|
|
||||||
|
|
||||||
/**** Private definitions ****/
|
|
||||||
|
|
||||||
/**** Private constants ****/
|
|
||||||
|
|
||||||
/**** Private variables ****/
|
|
||||||
inputs_t inputs;
|
|
||||||
analog_t analog;
|
|
||||||
|
|
||||||
/**** Private function declarations ****/
|
|
||||||
void Setup(void);
|
|
||||||
void GatherData(uint8_t times);
|
|
||||||
|
|
||||||
/**** Public function definitions ****/
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
Setup();
|
|
||||||
|
|
||||||
while(1)
|
|
||||||
{
|
|
||||||
// Read all inputs
|
|
||||||
GatherData(1);
|
|
||||||
|
|
||||||
// Process force logic
|
|
||||||
uint8_t force = Force_Update(&inputs, &analog);
|
|
||||||
|
|
||||||
// Save values
|
|
||||||
uint8_t new_bmode = Force_IsNewBrakeMode();
|
|
||||||
uint8_t new_force = Force_IsNewUserForce();
|
|
||||||
if(Force_GetInputMode()==IM_POT) new_force = 0;
|
|
||||||
Setings_Update(new_force, force, new_bmode, Force_GetBrakeMode());
|
|
||||||
|
|
||||||
// Set coil current target
|
|
||||||
Coil_SetTarget_Force(force);
|
|
||||||
|
|
||||||
// Calculate next target voltage
|
|
||||||
uint16_t next_u = Coil_Update(&analog);
|
|
||||||
|
|
||||||
// Set next output voltage
|
|
||||||
Output_SetTarget(next_u);
|
|
||||||
|
|
||||||
// Update output
|
|
||||||
Output_Update(&analog);
|
|
||||||
|
|
||||||
|
|
||||||
// Display logic
|
|
||||||
if(Output_GetOutputState()==O_FAULTED)
|
|
||||||
{
|
|
||||||
// Show fault code
|
|
||||||
Display_SetLock(0);
|
|
||||||
Display_SetImage(0x33);
|
|
||||||
}
|
|
||||||
else if(Force_IsNewBrakeMode())
|
|
||||||
{
|
|
||||||
Display_SetLock(0);
|
|
||||||
switch(Force_GetBrakeMode())
|
|
||||||
{
|
|
||||||
case BM_LOCK:
|
|
||||||
Display_SetImage(0x38);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BM_KEEP:
|
|
||||||
Display_SetImage(0x1E);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
Display_SetImage(0x07);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
Display_SetLock(1000);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Display_SetPercent(force, DOT10);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update display
|
|
||||||
Display_Update(&inputs);
|
|
||||||
|
|
||||||
// Reset new flags
|
|
||||||
Force_ResetNewBrakeMode();
|
|
||||||
Force_ResetNewUserForce();
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**** Private function definitions ****/
|
|
||||||
void Setup(void)
|
|
||||||
{
|
|
||||||
// Initialize low level hardware
|
|
||||||
Init_HW();
|
|
||||||
|
|
||||||
// Prime EEPROM
|
|
||||||
//Setings_SaveDefault();
|
|
||||||
|
|
||||||
// Configure inputs
|
|
||||||
Inputs_DefInit(&inputs);
|
|
||||||
|
|
||||||
inputs.handbrake.cfg.act_level = HIGH;
|
|
||||||
inputs.handbrake.cfg.dbnc_treshold = 10;
|
|
||||||
|
|
||||||
inputs.brakes.cfg.act_level = LOW;
|
|
||||||
inputs.brakes.cfg.dbnc_treshold = 20;
|
|
||||||
|
|
||||||
inputs.dimm.cfg.act_level = LOW;
|
|
||||||
inputs.dimm.cfg.dbnc_treshold = 20;
|
|
||||||
|
|
||||||
inputs.up.cfg.act_level = LOW;
|
|
||||||
inputs.up.cfg.dbnc_treshold = 20;
|
|
||||||
|
|
||||||
inputs.down.cfg.act_level = LOW;
|
|
||||||
inputs.down.cfg.dbnc_treshold = 20;
|
|
||||||
|
|
||||||
inputs.mode.cfg.act_level = LOW;
|
|
||||||
inputs.mode.cfg.dbnc_treshold = 20;
|
|
||||||
|
|
||||||
Inputs_SetHanbrakePullUp(0);
|
|
||||||
|
|
||||||
// Configure display
|
|
||||||
Display_CfgBacklight(100,50);
|
|
||||||
// Show startup display
|
|
||||||
Display_SetImage(0xFF);
|
|
||||||
Display_Update(&inputs);
|
|
||||||
|
|
||||||
// Configure force logic
|
|
||||||
Force_CfgInputMode(IM_POT); //IM_BUTTONS IM_POT
|
|
||||||
|
|
||||||
// Restore saved force
|
|
||||||
Force_SetUserForce(Setings_GetForce());
|
|
||||||
|
|
||||||
// Restore saved brake mode
|
|
||||||
Force_SetBrakeMode(Setings_GetBrakeMode());
|
|
||||||
|
|
||||||
// Prime analog channels
|
|
||||||
GatherData(100);
|
|
||||||
|
|
||||||
// Show default display
|
|
||||||
Display_SetImage(0x01);
|
|
||||||
Display_Update(&inputs);
|
|
||||||
|
|
||||||
// Enable output
|
|
||||||
Output_Enable();
|
|
||||||
Output_SetTarget(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GatherData(uint8_t times)
|
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
|
||||||
Analog_UpdateAll(&analog);
|
|
||||||
Inputs_UpdateAll(&inputs);
|
|
||||||
if(times) times--;
|
|
||||||
}
|
|
||||||
while(times);
|
|
||||||
}
|
|
||||||
45
firmware/src/hw/analog.c
Normal file
45
firmware/src/hw/analog.c
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
/**** 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;
|
||||||
|
}
|
||||||
20
firmware/src/hw/analog.h
Normal file
20
firmware/src/hw/analog.h
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#ifndef ANALOG_H_
|
||||||
|
#define ANALOG_H_
|
||||||
|
|
||||||
|
/*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**** Includes ****/
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/**** 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_ */
|
||||||
77
firmware/src/hw/board/ain.c
Normal file
77
firmware/src/hw/board/ain.c
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
/**** 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;
|
||||||
|
}
|
||||||
26
firmware/src/hw/board/ain.h
Normal file
26
firmware/src/hw/board/ain.h
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#ifndef AIN_H_
|
||||||
|
#define AIN_H_
|
||||||
|
|
||||||
|
/*
|
||||||
|
AIN1 MODE
|
||||||
|
AIN2 POT
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**** Includes ****/
|
||||||
|
#include <stdint.h>
|
||||||
|
#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_ */
|
||||||
32
firmware/src/hw/board/config.h
Normal file
32
firmware/src/hw/board/config.h
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#ifndef BSP_CONFIG_H_
|
||||||
|
#define BSP_CONFIG_H_
|
||||||
|
|
||||||
|
/**** Includes ****/
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/**** 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_ */
|
||||||
83
firmware/src/hw/board/din.c
Normal file
83
firmware/src/hw/board/din.c
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
/**** 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;
|
||||||
|
}
|
||||||
37
firmware/src/hw/board/din.h
Normal file
37
firmware/src/hw/board/din.h
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#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 <stdint.h>
|
||||||
|
|
||||||
|
/**** 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_ */
|
||||||
58
firmware/src/hw/board/dout.c
Normal file
58
firmware/src/hw/board/dout.c
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
/**** 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;
|
||||||
|
}
|
||||||
34
firmware/src/hw/board/dout.h
Normal file
34
firmware/src/hw/board/dout.h
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#ifndef DOUT_H_
|
||||||
|
#define DOUT_H_
|
||||||
|
|
||||||
|
/*
|
||||||
|
DOUT1 MODE
|
||||||
|
DOUT2 POT
|
||||||
|
DOUT3 DOWN
|
||||||
|
DOUT4 UP
|
||||||
|
DOUT5 HBRAKE PULL
|
||||||
|
DOUT6 SPEED PULL
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**** Includes ****/
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/**** 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_ */
|
||||||
179
firmware/src/hw/board/halfbridge.c
Normal file
179
firmware/src/hw/board/halfbridge.c
Normal file
@@ -0,0 +1,179 @@
|
|||||||
|
/**** 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;
|
||||||
|
}
|
||||||
|
|
||||||
34
firmware/src/hw/board/halfbridge.h
Normal file
34
firmware/src/hw/board/halfbridge.h
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#ifndef HALFBRIDGE_H_
|
||||||
|
#define HALFBRIDGE_H_
|
||||||
|
|
||||||
|
/*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**** Includes ****/
|
||||||
|
#include <stdint.h>
|
||||||
|
#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_ */
|
||||||
120
firmware/src/hw/board/mcu/mcu_hal.h
Normal file
120
firmware/src/hw/board/mcu/mcu_hal.h
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
#ifndef MCU_HAL_H_
|
||||||
|
#define MCU_HAL_H_
|
||||||
|
|
||||||
|
/**** Includes ****/
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/**** 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_ */
|
||||||
418
firmware/src/hw/board/mcu/mcu_hal_r8.c
Normal file
418
firmware/src/hw/board/mcu/mcu_hal_r8.c
Normal file
@@ -0,0 +1,418 @@
|
|||||||
|
/**** Includes ****/
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/eeprom.h>
|
||||||
|
#include "mcu_hal.h"
|
||||||
|
|
||||||
|
/**** Private definitions ****/
|
||||||
|
/**** Private constants ****/
|
||||||
|
/**** Private variables ****/
|
||||||
|
/**** Private function declarations ****/
|
||||||
|
static uint8_t gpio_read(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)
|
||||||
|
{
|
||||||
|
// Fail-safe GPIO init
|
||||||
|
PORTB = 0xF8; // Set PORTB pull-ups
|
||||||
|
DDRB = 0x00; // Set all as inputs
|
||||||
|
|
||||||
|
PORTC = 0x40; // Set PORTC pull-ups
|
||||||
|
DDRC = 0x00; // Set all as inputs
|
||||||
|
|
||||||
|
PORTD = 0x80; // Set PORTD pull-ups
|
||||||
|
DDRD = 0x00; // Set all as inputs
|
||||||
|
|
||||||
|
PORTE = 0x0A; // Set PORTE pull-ups
|
||||||
|
DDRE = 0x00; // Set all as inputs
|
||||||
|
|
||||||
|
// Half-bridge related pins
|
||||||
|
PORTB &= ~0x03; //Set low
|
||||||
|
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
|
||||||
|
|
||||||
|
// OD control pins
|
||||||
|
PORTD &= ~0x3F; //Set low (off)
|
||||||
|
DDRD |= 0x3F; //Set as outputs
|
||||||
|
|
||||||
|
// Handbrake pull-up pin
|
||||||
|
PORTB |= 0x20; //Set high
|
||||||
|
DDRB |= 0x20; //Set as output
|
||||||
|
|
||||||
|
// Handbrake and brakes pins
|
||||||
|
PORTB |= 0xC0; //Set pull-up on
|
||||||
|
DDRB &= ~0xC0; //Set as inputs
|
||||||
|
|
||||||
|
// Dimm
|
||||||
|
PORTD |= 0x80; //Set pull-up on
|
||||||
|
DDRD &= ~0x80; //Set as input
|
||||||
|
|
||||||
|
// Up and Down
|
||||||
|
PORTE |= 0x0A; //Set pull-up on
|
||||||
|
DDRE &= ~0x0A; //Set as inputs
|
||||||
|
|
||||||
|
// Internal ADC inputs
|
||||||
|
PORTC &= ~0x0F; //Pull-up off
|
||||||
|
DDRC &= ~0x0F; //Set as inputs
|
||||||
|
|
||||||
|
// Potentiometer & Mode
|
||||||
|
PORTC &= ~0x30; //Pull-up off
|
||||||
|
DDRC &= ~0x30; //Set as inputs
|
||||||
|
|
||||||
|
//ADC configuration
|
||||||
|
PRR0 &= ~0x01; //Enable ADC power
|
||||||
|
DIDR0 |= 0x0F; //Disable digital inputs, ADC0-ADC3
|
||||||
|
|
||||||
|
ADMUX = 0x40; //Set AVCC reference, Right adjust
|
||||||
|
ADCSRA = 0x00; //ADC Disabled, Single conversion, no IT
|
||||||
|
ADCSRA |= (uint8_t)hwCfg->adc_clk;
|
||||||
|
ADCSRB = 0x00; //no trigger input
|
||||||
|
|
||||||
|
ADCSRA |= 0x80; //Enable ADC
|
||||||
|
|
||||||
|
//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
|
||||||
|
TCCR1B = 0x18; //PWM, Phase & Frequency Correct ICR1 top, no clock, WGM:0xE
|
||||||
|
TCCR1C = 0x00;
|
||||||
|
TCNT1 = 0x0000;
|
||||||
|
OCR1A = 0xFFFF;
|
||||||
|
OCR1B = 0xFFFF;
|
||||||
|
ICR1 = hwCfg->pwm_top;
|
||||||
|
TIMSK1 = 0x00; //No interrupts
|
||||||
|
TIFR1 = 0x00; //Clear all flags
|
||||||
|
|
||||||
|
uint8_t tim1_prescaler = (uint8_t)hwCfg->pwm_clk;
|
||||||
|
TCCR1B |= tim1_prescaler; //Enable timer
|
||||||
|
}
|
||||||
|
|
||||||
|
// ADC Interface functions
|
||||||
|
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 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)
|
||||||
|
{
|
||||||
|
switch(ch)
|
||||||
|
{
|
||||||
|
case MCU_GPIO0: // Mode DIN1
|
||||||
|
return gpio_read(PINC,0x20);
|
||||||
|
|
||||||
|
case MCU_GPIO1: // Pot DIN2
|
||||||
|
return gpio_read(PINC,0x10);
|
||||||
|
|
||||||
|
case MCU_GPIO2: // Down DIN3
|
||||||
|
return gpio_read(PINE,0x02);
|
||||||
|
|
||||||
|
case MCU_GPIO3: // Up DIN4
|
||||||
|
return gpio_read(PINE,0x08);
|
||||||
|
|
||||||
|
case MCU_GPIO4: // Dimm DIN5
|
||||||
|
return gpio_read(PIND,0x80);
|
||||||
|
|
||||||
|
case MCU_GPIO5: // Brakes DIN6
|
||||||
|
return gpio_read(PINB,0x80);
|
||||||
|
|
||||||
|
case MCU_GPIO6: // Handbrake DIN7
|
||||||
|
return gpio_read(PINB,0x40);
|
||||||
|
|
||||||
|
case MCU_GPIO7: // Handbrake pull DIN8
|
||||||
|
return gpio_read(PINB,0x20);
|
||||||
|
|
||||||
|
case MCU_GPIO8: // Speed-pull
|
||||||
|
return gpio_read(PIND,0x40);
|
||||||
|
|
||||||
|
case MCU_GPIO9: // LED 0
|
||||||
|
return gpio_read(PIND,0x01);
|
||||||
|
|
||||||
|
case MCU_GPIO10: // LED 1
|
||||||
|
return gpio_read(PIND,0x02);
|
||||||
|
|
||||||
|
case MCU_GPIO11: // LED 2
|
||||||
|
return gpio_read(PIND,0x04);
|
||||||
|
|
||||||
|
case MCU_GPIO12: // LED 3
|
||||||
|
return gpio_read(PIND,0x08);
|
||||||
|
|
||||||
|
case MCU_GPIO13: // LED 4
|
||||||
|
return gpio_read(PIND,0x10);
|
||||||
|
|
||||||
|
case MCU_GPIO14: // LED 5
|
||||||
|
return gpio_read(PIND,0x20);
|
||||||
|
|
||||||
|
case MCU_GPIO15: // DCCD Enable
|
||||||
|
return gpio_read(PINB,0x01);
|
||||||
|
|
||||||
|
case MCU_GPIO16: // DCCD PWM
|
||||||
|
return gpio_read(PINB,0x02);
|
||||||
|
|
||||||
|
case MCU_GPIO17: // LED PWM
|
||||||
|
return gpio_read(PINB,0x04);
|
||||||
|
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void mcu_gpio_write(uint8_t ch, int8_t lvl)
|
||||||
|
{
|
||||||
|
switch(ch)
|
||||||
|
{
|
||||||
|
case MCU_GPIO0: // Mode DIN1
|
||||||
|
if(lvl>0)
|
||||||
|
{
|
||||||
|
PORTC |= 0x20;
|
||||||
|
DDRC |= 0x20;
|
||||||
|
}
|
||||||
|
else if(lvl<0)
|
||||||
|
{
|
||||||
|
DDRC &= ~0x20;
|
||||||
|
PORTC &= ~0x20;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PORTC &= ~0x20;
|
||||||
|
DDRC |= 0x20;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
|
||||||
|
case MCU_GPIO1: // Pot DIN2
|
||||||
|
if(lvl>0)
|
||||||
|
{
|
||||||
|
PORTC |= 0x10;
|
||||||
|
DDRC |= 0x10;
|
||||||
|
}
|
||||||
|
else if(lvl<0)
|
||||||
|
{
|
||||||
|
DDRC &= ~0x10;
|
||||||
|
PORTC &= ~0x10;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PORTC &= ~0x10;
|
||||||
|
DDRC |= 0x10;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
|
||||||
|
case MCU_GPIO2: // Down DIN3
|
||||||
|
if(lvl>0)
|
||||||
|
{
|
||||||
|
PORTE |= 0x02;
|
||||||
|
DDRE |= 0x02;
|
||||||
|
}
|
||||||
|
else if(lvl<0)
|
||||||
|
{
|
||||||
|
DDRE &= ~0x02;
|
||||||
|
PORTE &= ~0x02;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PORTE &= ~0x02;
|
||||||
|
DDRE |= 0x02;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
|
||||||
|
case MCU_GPIO3: // Up DIN4
|
||||||
|
if(lvl>0)
|
||||||
|
{
|
||||||
|
PORTE |= 0x08;
|
||||||
|
DDRE |= 0x08;
|
||||||
|
}
|
||||||
|
else if(lvl<0)
|
||||||
|
{
|
||||||
|
DDRE &= ~0x08;
|
||||||
|
PORTE &= ~0x08;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PORTE &= ~0x08;
|
||||||
|
DDRE |= 0x08;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
|
||||||
|
case MCU_GPIO7: // Handbrake pull DIN
|
||||||
|
if(lvl>0)
|
||||||
|
{
|
||||||
|
PORTB |= 0x20;
|
||||||
|
DDRB |= 0x20;
|
||||||
|
}
|
||||||
|
else if(lvl<0)
|
||||||
|
{
|
||||||
|
DDRB &= ~0x20;
|
||||||
|
PORTB &= ~0x20;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PORTB &= ~0x20;
|
||||||
|
DDRB |= 0x20;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
|
||||||
|
case MCU_GPIO8: // Speed-pull
|
||||||
|
if(lvl>0) PORTD |= 0x40;
|
||||||
|
else PORTD &= ~0x40;
|
||||||
|
return;
|
||||||
|
|
||||||
|
case MCU_GPIO9: // LED 0
|
||||||
|
if(lvl>0) PORTD |= 0x01;
|
||||||
|
else PORTD &= ~0x01;
|
||||||
|
return;
|
||||||
|
|
||||||
|
case MCU_GPIO10: // LED 1
|
||||||
|
if(lvl>0) PORTD |= 0x02;
|
||||||
|
else PORTD &= ~0x02;
|
||||||
|
return;
|
||||||
|
|
||||||
|
case MCU_GPIO11: // LED 2
|
||||||
|
if(lvl>0) PORTD |= 0x04;
|
||||||
|
else PORTD &= ~0x04;
|
||||||
|
return;
|
||||||
|
|
||||||
|
case MCU_GPIO12: // LED 3
|
||||||
|
if(lvl>0) PORTD |= 0x08;
|
||||||
|
else PORTD &= ~0x08;
|
||||||
|
return;
|
||||||
|
|
||||||
|
case MCU_GPIO13: // LED 4
|
||||||
|
if(lvl>0) PORTD |= 0x10;
|
||||||
|
else PORTD &= ~0x10;
|
||||||
|
return;
|
||||||
|
|
||||||
|
case MCU_GPIO14: // LED 5
|
||||||
|
if(lvl>0) PORTD |= 0x20;
|
||||||
|
else PORTD &= ~0x20;
|
||||||
|
return;
|
||||||
|
|
||||||
|
case MCU_GPIO15: // DCCD Enable
|
||||||
|
if(lvl>0) PORTB |= 0x01;
|
||||||
|
else PORTB &= ~0x01;
|
||||||
|
return;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t mcu_ee_read8b(uint16_t address)
|
||||||
|
{
|
||||||
|
return eeprom_read_byte((uint8_t*)address);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t mcu_ee_read16b(uint16_t address)
|
||||||
|
{
|
||||||
|
return eeprom_read_word((uint16_t*)address);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t mcu_ee_read32b(uint16_t address)
|
||||||
|
{
|
||||||
|
return eeprom_read_dword((uint32_t*)address);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mcu_ee_write8b(uint16_t address, uint8_t value)
|
||||||
|
{
|
||||||
|
eeprom_write_byte((uint8_t*)address, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mcu_ee_write16b(uint16_t address, uint16_t value)
|
||||||
|
{
|
||||||
|
eeprom_write_word((uint16_t*)address, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mcu_ee_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)
|
||||||
|
{
|
||||||
|
if(pin_reg&mask) return MCU_GPIO_HIGH;
|
||||||
|
else return MCU_GPIO_LOW;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void pwm_write_ocx(uint8_t ch, uint16_t value)
|
||||||
|
{
|
||||||
|
switch(ch)
|
||||||
|
{
|
||||||
|
case MCU_PWM0:
|
||||||
|
OCR1A = value;
|
||||||
|
return;
|
||||||
|
|
||||||
|
case MCU_PWM1:
|
||||||
|
OCR1B = value;
|
||||||
|
return;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint16_t pwm_read_ocx(uint8_t ch)
|
||||||
|
{
|
||||||
|
switch(ch)
|
||||||
|
{
|
||||||
|
case MCU_PWM0:
|
||||||
|
return OCR1A;
|
||||||
|
|
||||||
|
case MCU_PWM1:
|
||||||
|
return OCR1B ;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return 0x0000;
|
||||||
|
}
|
||||||
|
}
|
||||||
80
firmware/src/hw/board/odout.c
Normal file
80
firmware/src/hw/board/odout.c
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
/**** 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;
|
||||||
|
}
|
||||||
37
firmware/src/hw/board/odout.h
Normal file
37
firmware/src/hw/board/odout.h
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#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 <stdint.h>
|
||||||
|
|
||||||
|
/**** 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_ */
|
||||||
23
firmware/src/hw/board/setup.c
Normal file
23
firmware/src/hw/board/setup.c
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/**** 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);
|
||||||
|
}
|
||||||
14
firmware/src/hw/board/setup.h
Normal file
14
firmware/src/hw/board/setup.h
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#ifndef BSP_SETUP_H_
|
||||||
|
#define BSP_SETUP_H_
|
||||||
|
|
||||||
|
/**** Includes ****/
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/**** Public definitions ****/
|
||||||
|
/**** Public function declarations ****/
|
||||||
|
void bsp_startup(void);
|
||||||
|
|
||||||
|
#ifdef TESTING
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* BSP_SETUP_H_ */
|
||||||
67
firmware/src/hw/board/utils/faults.c
Normal file
67
firmware/src/hw/board/utils/faults.c
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
/**** 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 ****/
|
||||||
37
firmware/src/hw/board/utils/faults.h
Normal file
37
firmware/src/hw/board/utils/faults.h
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#ifndef FAULTS_H_
|
||||||
|
#define FAULTS_H_
|
||||||
|
|
||||||
|
/*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**** Includes ****/
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/**** 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_ */
|
||||||
81
firmware/src/hw/board/utils/fuses.c
Normal file
81
firmware/src/hw/board/utils/fuses.c
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
/**** 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 ****/
|
||||||
36
firmware/src/hw/board/utils/fuses.h
Normal file
36
firmware/src/hw/board/utils/fuses.h
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#ifndef FUSES_H_
|
||||||
|
#define FUSES_H_
|
||||||
|
|
||||||
|
/*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**** Includes ****/
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/**** 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_ */
|
||||||
272
firmware/src/hw/board/utils/utils.c
Normal file
272
firmware/src/hw/board/utils/utils.c
Normal file
@@ -0,0 +1,272 @@
|
|||||||
|
/**** 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<len_axis; i++)
|
||||||
|
{
|
||||||
|
if(val < axis_values[i]) return i;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return len_axis;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint16_t index2d_to_index1d(uint8_t ix, uint8_t iy, uint8_t len_x)
|
||||||
|
{
|
||||||
|
return ((uint16_t)len_x * iy) + ix;
|
||||||
|
}
|
||||||
37
firmware/src/hw/board/utils/utils.h
Normal file
37
firmware/src/hw/board/utils/utils.h
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#ifndef UTILS_H_
|
||||||
|
#define UTILS_H_
|
||||||
|
|
||||||
|
/**** Includes ****/
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/**** 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_ */
|
||||||
173
firmware/src/hw/buttons.c
Normal file
173
firmware/src/hw/buttons.c
Normal file
@@ -0,0 +1,173 @@
|
|||||||
|
/**** 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;
|
||||||
|
}
|
||||||
54
firmware/src/hw/buttons.h
Normal file
54
firmware/src/hw/buttons.h
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
#ifndef BUTTONS_H_
|
||||||
|
#define BUTTONS_H_
|
||||||
|
|
||||||
|
/*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**** Includes ****/
|
||||||
|
#include <stdint.h>
|
||||||
|
#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_ */
|
||||||
45
firmware/src/hw/config.h
Normal file
45
firmware/src/hw/config.h
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#ifndef HW_CONFIG_H_
|
||||||
|
#define HW_CONFIG_H_
|
||||||
|
|
||||||
|
/**** Includes ****/
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/**** 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_ */
|
||||||
399
firmware/src/hw/hb_control.c
Normal file
399
firmware/src/hw/hb_control.c
Normal file
@@ -0,0 +1,399 @@
|
|||||||
|
/**** 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
|
||||||
67
firmware/src/hw/hb_control.h
Normal file
67
firmware/src/hw/hb_control.h
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
#ifndef HB_CONTROL_H_
|
||||||
|
#define HB_CONTROL_H_
|
||||||
|
|
||||||
|
/**** Includes ****/
|
||||||
|
#include <stdint.h>
|
||||||
|
#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_ */
|
||||||
38
firmware/src/hw/led_display.c
Normal file
38
firmware/src/hw/led_display.c
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
/**** 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 ****/
|
||||||
|
|
||||||
@@ -1,13 +1,19 @@
|
|||||||
#ifndef LED_DISPLAY_H_
|
#ifndef LED_DISPLAY_H_
|
||||||
#define LED_DISPLAY_H_
|
#define LED_DISPLAY_H_
|
||||||
|
|
||||||
|
/*
|
||||||
|
*/
|
||||||
|
|
||||||
/**** Includes ****/
|
/**** Includes ****/
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
/**** Public definitions ****/
|
/**** Public definitions ****/
|
||||||
|
|
||||||
/**** Public function declarations ****/
|
/**** Public function declarations ****/
|
||||||
void LED_DSP_ShowImage(uint8_t image);
|
void led_dsp_set_image(uint8_t image);
|
||||||
void LED_DSP_SetBrightness(uint8_t percent);
|
void led_dsp_backligth_set(uint8_t percent);
|
||||||
|
|
||||||
|
#ifdef TESTING
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* LED_DISPLAY_H_ */
|
#endif /* LED_DISPLAY_H_ */
|
||||||
16
firmware/src/hw/startup.c
Normal file
16
firmware/src/hw/startup.c
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
/**** 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 ****/
|
||||||
14
firmware/src/hw/startup.h
Normal file
14
firmware/src/hw/startup.h
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#ifndef HW_STARTUP_H_
|
||||||
|
#define HW_STARTUP_H_
|
||||||
|
|
||||||
|
/**** Includes ****/
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/**** Public definitions ****/
|
||||||
|
/**** Public function declarations ****/
|
||||||
|
void hw_startup(void);
|
||||||
|
|
||||||
|
#ifdef TESTING
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* HW_STARTUP_H_ */
|
||||||
41
firmware/src/logic/coil.c
Normal file
41
firmware/src/logic/coil.c
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
/**** 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 ****/
|
||||||
|
|
||||||
17
firmware/src/logic/coil.h
Normal file
17
firmware/src/logic/coil.h
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#ifndef COIL_H_
|
||||||
|
#define COIL_H_
|
||||||
|
|
||||||
|
/**** Includes ****/
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/**** 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_ */
|
||||||
108
firmware/src/logic/display.c
Normal file
108
firmware/src/logic/display.c
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
/**** 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;
|
||||||
|
}
|
||||||
37
firmware/src/logic/display.h
Normal file
37
firmware/src/logic/display.h
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#ifndef LOGIC_DISPLAY_H_
|
||||||
|
#define LOGIC_DISPLAY_H_
|
||||||
|
|
||||||
|
/**** Includes ****/
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/**** 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_ */
|
||||||
63
firmware/src/logic/force.c
Normal file
63
firmware/src/logic/force.c
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
/**** 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 ****/
|
||||||
|
|
||||||
23
firmware/src/logic/force.h
Normal file
23
firmware/src/logic/force.h
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#ifndef FORCE_H_
|
||||||
|
#define FORCE_H_
|
||||||
|
|
||||||
|
/**** Includes ****/
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/**** 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_ */
|
||||||
42
firmware/src/logic/pot.c
Normal file
42
firmware/src/logic/pot.c
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
/**** 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 ****/
|
||||||
|
|
||||||
19
firmware/src/logic/pot.h
Normal file
19
firmware/src/logic/pot.h
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#ifndef POTENTIOMETER_H_
|
||||||
|
#define POTENTIOMETER_H_
|
||||||
|
|
||||||
|
/**** Includes ****/
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/**** 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_ */
|
||||||
52
firmware/src/logic/user_force.c
Normal file
52
firmware/src/logic/user_force.c
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
/**** 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 ****/
|
||||||
18
firmware/src/logic/user_force.h
Normal file
18
firmware/src/logic/user_force.h
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#ifndef USER_FORCE_H_
|
||||||
|
#define USER_FORCE_H_
|
||||||
|
|
||||||
|
/**** Includes ****/
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/**** 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_ */
|
||||||
127
firmware/src/main.c
Normal file
127
firmware/src/main.c
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
/**** Includes ****/
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
// 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 ****/
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
<OverrideVtorValue>exception_table</OverrideVtorValue>
|
<OverrideVtorValue>exception_table</OverrideVtorValue>
|
||||||
<BootSegment>2</BootSegment>
|
<BootSegment>2</BootSegment>
|
||||||
<ResetRule>0</ResetRule>
|
<ResetRule>0</ResetRule>
|
||||||
<eraseonlaunchrule>0</eraseonlaunchrule>
|
<eraseonlaunchrule>1</eraseonlaunchrule>
|
||||||
<EraseKey />
|
<EraseKey />
|
||||||
<AsfFrameworkConfig>
|
<AsfFrameworkConfig>
|
||||||
<framework-data>
|
<framework-data>
|
||||||
@@ -36,7 +36,7 @@
|
|||||||
<documentation help="" />
|
<documentation help="" />
|
||||||
<offline-documentation help="" />
|
<offline-documentation help="" />
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.42.0" />
|
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.44.1" />
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</framework-data>
|
</framework-data>
|
||||||
</AsfFrameworkConfig>
|
</AsfFrameworkConfig>
|
||||||
@@ -48,13 +48,13 @@
|
|||||||
<InterfaceProperties>
|
<InterfaceProperties>
|
||||||
<IspClock>125000</IspClock>
|
<IspClock>125000</IspClock>
|
||||||
</InterfaceProperties>
|
</InterfaceProperties>
|
||||||
<InterfaceName>ISP</InterfaceName>
|
<InterfaceName>debugWIRE</InterfaceName>
|
||||||
</ToolOptions>
|
</ToolOptions>
|
||||||
<ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>
|
<ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>
|
||||||
<ToolNumber>J42700001490</ToolNumber>
|
<ToolNumber>J42700001490</ToolNumber>
|
||||||
<ToolName>Atmel-ICE</ToolName>
|
<ToolName>Atmel-ICE</ToolName>
|
||||||
</com_atmel_avrdbg_tool_atmelice>
|
</com_atmel_avrdbg_tool_atmelice>
|
||||||
<avrtoolinterface>ISP</avrtoolinterface>
|
<avrtoolinterface>debugWIRE</avrtoolinterface>
|
||||||
<avrtoolinterfaceclock>125000</avrtoolinterfaceclock>
|
<avrtoolinterfaceclock>125000</avrtoolinterfaceclock>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||||
@@ -131,71 +131,104 @@
|
|||||||
</ListValues>
|
</ListValues>
|
||||||
</avrgcc.assembler.general.IncludePaths>
|
</avrgcc.assembler.general.IncludePaths>
|
||||||
<avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
|
<avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
|
||||||
</AvrGcc>
|
</AvrGcc>
|
||||||
</ToolchainSettings>
|
</ToolchainSettings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="devices\analog.c">
|
<Compile Include="hw\analog.c">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="devices\analog.h">
|
<Compile Include="hw\analog.h">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="devices\common\level.h">
|
<Compile Include="hw\board\config.h">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="devices\config.c">
|
<Compile Include="hw\board\dout.c">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="devices\config.h">
|
<Compile Include="hw\board\dout.h">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="devices\led_display.c">
|
<Compile Include="hw\board\setup.c">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="devices\led_display.h">
|
<Compile Include="hw\board\setup.h">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="devices\filter_iir_lpf.c">
|
<Compile Include="hw\board\utils\faults.c">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="devices\filter_iir_lpf.h">
|
<Compile Include="hw\board\utils\faults.h">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="devices\halfbridge.c">
|
<Compile Include="hw\board\utils\fuses.c">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="devices\halfbridge.h">
|
<Compile Include="hw\board\utils\fuses.h">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="devices\hal\udccd_r7_hal.c">
|
<Compile Include="hw\buttons.c">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="devices\hal\udccd_hal.h">
|
<Compile Include="hw\buttons.h">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="devices\inputs.c">
|
<Compile Include="hw\board\ain.c">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="devices\inputs.h">
|
<Compile Include="hw\board\ain.h">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="devices\memory.c">
|
<Compile Include="hw\board\din.c">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="devices\memory.h">
|
<Compile Include="hw\board\din.h">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="drivers\display.c">
|
<Compile Include="hw\board\halfbridge.c">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="drivers\display.h">
|
<Compile Include="hw\board\halfbridge.h">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="drivers\output.c">
|
<Compile Include="hw\board\mcu\mcu_hal.h">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="drivers\output.h">
|
<Compile Include="hw\board\mcu\mcu_hal_r8.c">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="hw\board\odout.c">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="hw\board\odout.h">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="hw\board\utils\utils.c">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="hw\board\utils\utils.h">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="hw\config.h">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="hw\hb_control.c">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="hw\hb_control.h">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="hw\led_display.c">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="hw\led_display.h">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="hw\startup.c">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="hw\startup.h">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="logic\coil.c">
|
<Compile Include="logic\coil.c">
|
||||||
@@ -204,16 +237,28 @@
|
|||||||
<Compile Include="logic\coil.h">
|
<Compile Include="logic\coil.h">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="logic\display.c">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="logic\display.h">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
<Compile Include="logic\force.c">
|
<Compile Include="logic\force.c">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="logic\force.h">
|
<Compile Include="logic\force.h">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="logic\settings.c">
|
<Compile Include="logic\pot.c">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="logic\settings.h">
|
<Compile Include="logic\pot.h">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="logic\user_force.c">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="logic\user_force.h">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="main.c">
|
<Compile Include="main.c">
|
||||||
@@ -221,10 +266,10 @@
|
|||||||
</Compile>
|
</Compile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="devices" />
|
<Folder Include="hw" />
|
||||||
<Folder Include="devices\hal" />
|
<Folder Include="hw\board" />
|
||||||
<Folder Include="devices\common" />
|
<Folder Include="hw\board\mcu" />
|
||||||
<Folder Include="drivers" />
|
<Folder Include="hw\board\utils" />
|
||||||
<Folder Include="logic" />
|
<Folder Include="logic" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
|
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
|
||||||
8
firmware/tests/Units_Tests.workspace
Normal file
8
firmware/tests/Units_Tests.workspace
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||||
|
<CodeBlocks_workspace_file>
|
||||||
|
<Workspace title="Workspace">
|
||||||
|
<Project filename="uDCCD_Unit_Tests_BSP.cbp" />
|
||||||
|
<Project filename="uDCCD_Unit_Tests_HW.cbp" />
|
||||||
|
<Project filename="uDCCD_Unit_Tests_Logic.cbp" />
|
||||||
|
</Workspace>
|
||||||
|
</CodeBlocks_workspace_file>
|
||||||
6
firmware/tests/Units_Tests.workspace.layout
Normal file
6
firmware/tests/Units_Tests.workspace.layout
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||||
|
<CodeBlocks_workspace_layout_file>
|
||||||
|
<FileVersion major="1" minor="0" />
|
||||||
|
<ActiveProject path="uDCCD_Unit_Tests_Logic.cbp" />
|
||||||
|
<PreferredTarget name="Debug" />
|
||||||
|
</CodeBlocks_workspace_layout_file>
|
||||||
147
firmware/tests/bsp_main.c
Normal file
147
firmware/tests/bsp_main.c
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
||||||
102
firmware/tests/hw_main.c
Normal file
102
firmware/tests/hw_main.c
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
||||||
98
firmware/tests/logic_main.c
Normal file
98
firmware/tests/logic_main.c
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
||||||
32
firmware/tests/mock_board/mock_board_ain.c
Normal file
32
firmware/tests/mock_board/mock_board_ain.c
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#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;
|
||||||
|
}
|
||||||
14
firmware/tests/mock_board/mock_board_ain.h
Normal file
14
firmware/tests/mock_board/mock_board_ain.h
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#ifndef MOCK_BOARD_AIN_
|
||||||
|
#define MOCK_BOARD_AIN_
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#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_ */
|
||||||
32
firmware/tests/mock_board/mock_board_din.c
Normal file
32
firmware/tests/mock_board/mock_board_din.c
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#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;
|
||||||
|
}
|
||||||
14
firmware/tests/mock_board/mock_board_din.h
Normal file
14
firmware/tests/mock_board/mock_board_din.h
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#ifndef MOCK_BOARD_DIN_
|
||||||
|
#define MOCK_BOARD_DIN_
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#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_ */
|
||||||
31
firmware/tests/mock_board/mock_board_dout.c
Normal file
31
firmware/tests/mock_board/mock_board_dout.c
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#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;
|
||||||
|
}
|
||||||
14
firmware/tests/mock_board/mock_board_dout.h
Normal file
14
firmware/tests/mock_board/mock_board_dout.h
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#ifndef MOCK_BOARD_DOUT_
|
||||||
|
#define MOCK_BOARD_DOUT_
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#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_ */
|
||||||
76
firmware/tests/mock_board/mock_board_halfbridge.c
Normal file
76
firmware/tests/mock_board/mock_board_halfbridge.c
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
#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;
|
||||||
|
}
|
||||||
18
firmware/tests/mock_board/mock_board_halfbridge.h
Normal file
18
firmware/tests/mock_board/mock_board_halfbridge.h
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#ifndef MOCK_BOARD_HALFBRIDGE_
|
||||||
|
#define MOCK_BOARD_HALFBRIDGE_
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#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_ */
|
||||||
47
firmware/tests/mock_board/mock_board_odout.c
Normal file
47
firmware/tests/mock_board/mock_board_odout.c
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
#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;
|
||||||
|
}
|
||||||
16
firmware/tests/mock_board/mock_board_odout.h
Normal file
16
firmware/tests/mock_board/mock_board_odout.h
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#ifndef MOCK_BOARD_ODOUT_
|
||||||
|
#define MOCK_BOARD_ODOUT_
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#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_ */
|
||||||
18
firmware/tests/mock_board/mock_board_setup.c
Normal file
18
firmware/tests/mock_board/mock_board_setup.c
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#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;
|
||||||
|
}
|
||||||
12
firmware/tests/mock_board/mock_board_setup.h
Normal file
12
firmware/tests/mock_board/mock_board_setup.h
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#ifndef MOCK_BOARD_SETUP_
|
||||||
|
#define MOCK_BOARD_SETUP_
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#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_ */
|
||||||
178
firmware/tests/mock_mcu/mock_mcu_hal_r8.c
Normal file
178
firmware/tests/mock_mcu/mock_mcu_hal_r8.c
Normal file
@@ -0,0 +1,178 @@
|
|||||||
|
#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)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
28
firmware/tests/mock_mcu/mock_mcu_hal_r8.h
Normal file
28
firmware/tests/mock_mcu/mock_mcu_hal_r8.h
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#ifndef MOCK_MCU_HAL_R8_
|
||||||
|
#define MOCK_MCU_HAL_R8_
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#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_ */
|
||||||
106
firmware/tests/uDCCD_Unit_Tests_BSP.cbp
Normal file
106
firmware/tests/uDCCD_Unit_Tests_BSP.cbp
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||||
|
<CodeBlocks_project_file>
|
||||||
|
<FileVersion major="1" minor="6" />
|
||||||
|
<Project>
|
||||||
|
<Option title="uDCCD_Unit_Tests_BSP" />
|
||||||
|
<Option pch_mode="2" />
|
||||||
|
<Option compiler="gcc" />
|
||||||
|
<Build>
|
||||||
|
<Target title="Debug">
|
||||||
|
<Option output="bin/Debug/uDCCD_Unit_Tests_BSP" prefix_auto="1" extension_auto="1" />
|
||||||
|
<Option object_output="obj/Debug/" />
|
||||||
|
<Option type="1" />
|
||||||
|
<Option compiler="gcc" />
|
||||||
|
<Compiler>
|
||||||
|
<Add option="-g" />
|
||||||
|
</Compiler>
|
||||||
|
</Target>
|
||||||
|
</Build>
|
||||||
|
<Compiler>
|
||||||
|
<Add option="-Wall" />
|
||||||
|
</Compiler>
|
||||||
|
<Unit filename="../src/hw/board/ain.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="../src/hw/board/ain.h" />
|
||||||
|
<Unit filename="../src/hw/board/din.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="../src/hw/board/din.h" />
|
||||||
|
<Unit filename="../src/hw/board/dout.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="../src/hw/board/dout.h" />
|
||||||
|
<Unit filename="../src/hw/board/halfbridge.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="../src/hw/board/halfbridge.h" />
|
||||||
|
<Unit filename="../src/hw/board/mcu/mcu_hal.h" />
|
||||||
|
<Unit filename="../src/hw/board/odout.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="../src/hw/board/odout.h" />
|
||||||
|
<Unit filename="../src/hw/board/setup.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="../src/hw/board/setup.h" />
|
||||||
|
<Unit filename="../src/hw/board/utils/faults.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="../src/hw/board/utils/faults.h" />
|
||||||
|
<Unit filename="../src/hw/board/utils/fuses.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="../src/hw/board/utils/fuses.h" />
|
||||||
|
<Unit filename="../src/hw/board/utils/utils.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="../src/hw/board/utils/utils.h" />
|
||||||
|
<Unit filename="bsp_main.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="mock_mcu/mock_mcu_hal_r8.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="mock_mcu/mock_mcu_hal_r8.h" />
|
||||||
|
<Unit filename="ut_board/ut_ain.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="ut_board/ut_ain.h" />
|
||||||
|
<Unit filename="ut_board/ut_din.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="ut_board/ut_din.h" />
|
||||||
|
<Unit filename="ut_board/ut_dout.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="ut_board/ut_dout.h" />
|
||||||
|
<Unit filename="ut_board/ut_halfbridge.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="ut_board/ut_halfbridge.h" />
|
||||||
|
<Unit filename="ut_board/ut_odout.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="ut_board/ut_odout.h" />
|
||||||
|
<Unit filename="ut_board/ut_setup.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="ut_board/ut_setup.h" />
|
||||||
|
<Unit filename="ut_utils/ut_fault.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="ut_utils/ut_fault.h" />
|
||||||
|
<Unit filename="ut_utils/ut_fuses.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="ut_utils/ut_fuses.h" />
|
||||||
|
<Unit filename="ut_utils/ut_utils.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="ut_utils/ut_utils.h" />
|
||||||
|
<Extensions>
|
||||||
|
<lib_finder disable_auto="1" />
|
||||||
|
</Extensions>
|
||||||
|
</Project>
|
||||||
|
</CodeBlocks_project_file>
|
||||||
348
firmware/tests/uDCCD_Unit_Tests_BSP.depend
Normal file
348
firmware/tests/uDCCD_Unit_Tests_BSP.depend
Normal file
@@ -0,0 +1,348 @@
|
|||||||
|
# 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
|
||||||
|
<stdint.h>
|
||||||
|
|
||||||
|
1698776270 f:\microrally\udccd_controller\src\hw\board\mcu\mcu_hal.h
|
||||||
|
<stdint.h>
|
||||||
|
|
||||||
|
1699031869 f:\microrally\udccd_controller\src\hw\board\ain.h
|
||||||
|
<stdint.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
|
||||||
|
<stdint.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
|
||||||
|
<stdint.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
|
||||||
|
<stdint.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
|
||||||
|
<stdint.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
|
||||||
|
<stdint.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
|
||||||
|
<stdint.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
|
||||||
|
<stdint.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
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.h>
|
||||||
|
"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
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.h>
|
||||||
|
|
||||||
|
1698870535 f:\microrally\udccd_controller\tests\ut_utils\ut_fault.h
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.h>
|
||||||
|
|
||||||
|
1698959419 f:\microrally\udccd_controller\tests\ut_utils\ut_fuses.h
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.h>
|
||||||
|
|
||||||
|
1699031869 f:\microrally\udccd_controller\tests\ut_board\ut_ain.h
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.h>
|
||||||
|
|
||||||
|
1699041803 f:\microrally\udccd_controller\tests\ut_board\ut_din.h
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.h>
|
||||||
|
|
||||||
|
1699042443 f:\microrally\udccd_controller\tests\ut_board\ut_dout.h
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.h>
|
||||||
|
|
||||||
|
1699051096 f:\microrally\udccd_controller\tests\ut_board\ut_halfbridge.h
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.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
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.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
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.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
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.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
|
||||||
|
<stdint.h>
|
||||||
|
|
||||||
|
1699017409 d:\microrally\udccd_controller\src\hw\board\mcu\mcu_hal.h
|
||||||
|
<stdint.h>
|
||||||
|
|
||||||
|
1699535273 d:\microrally\udccd_controller\src\hw\board\ain.h
|
||||||
|
<stdint.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
|
||||||
|
<stdint.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
|
||||||
|
<stdint.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
|
||||||
|
<stdint.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
|
||||||
|
<stdint.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
|
||||||
|
<stdint.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
|
||||||
|
<stdint.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
|
||||||
|
<stdint.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
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.h>
|
||||||
|
"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
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.h>
|
||||||
|
|
||||||
|
1698921312 d:\microrally\udccd_controller\tests\ut_utils\ut_fault.h
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.h>
|
||||||
|
|
||||||
|
1699004735 d:\microrally\udccd_controller\tests\ut_utils\ut_fuses.h
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.h>
|
||||||
|
|
||||||
|
1699018575 d:\microrally\udccd_controller\tests\ut_board\ut_ain.h
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.h>
|
||||||
|
|
||||||
|
1699257917 d:\microrally\udccd_controller\tests\ut_board\ut_din.h
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.h>
|
||||||
|
|
||||||
|
1699257917 d:\microrally\udccd_controller\tests\ut_board\ut_dout.h
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.h>
|
||||||
|
|
||||||
|
1699257917 d:\microrally\udccd_controller\tests\ut_board\ut_halfbridge.h
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.h>
|
||||||
|
|
||||||
|
1699257917 d:\microrally\udccd_controller\tests\ut_board\ut_odout.h
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.h>
|
||||||
|
|
||||||
|
1699257917 d:\microrally\udccd_controller\tests\ut_board\ut_setup.h
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.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
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.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
|
||||||
|
<stdint.h>
|
||||||
|
|
||||||
90
firmware/tests/uDCCD_Unit_Tests_BSP.layout
Normal file
90
firmware/tests/uDCCD_Unit_Tests_BSP.layout
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||||
|
<CodeBlocks_layout_file>
|
||||||
|
<FileVersion major="1" minor="0" />
|
||||||
|
<ActiveTarget name="Debug" />
|
||||||
|
<File name="ut_utils\ut_utils.c" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="-1" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="30322" topLine="1293" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="ut_board\ut_ain.c" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="1582" topLine="41" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="ut_board\ut_odout.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="169" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="mock_mcu\mock_mcu_hal_r8.c" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="1" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="2789" topLine="117" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="ut_board\ut_dout.c" open="0" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="4236" topLine="87" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="..\src\hw\board\mcu\mcu_hal.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="844" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="mock_mcu\mock_mcu_hal_r8.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="231" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="ut_board\ut_setup.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="4" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="715" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="..\src\hw\board\utils\utils.c" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="1" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="5492" topLine="188" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="ut_utils\ut_utils.h" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="4" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="664" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="ut_utils\ut_fuses.c" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="1650" topLine="24" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="ut_board\ut_setup.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="8" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="122" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="bsp_main.c" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="5" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="3165" topLine="121" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="ut_board\ut_halfbridge.c" open="0" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="5" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="2947" topLine="90" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="ut_utils\ut_fault.c" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="29993" topLine="896" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="ut_board\ut_odout.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="6" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="5245" topLine="172" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="ut_board\ut_din.c" open="0" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="815" topLine="135" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
</CodeBlocks_layout_file>
|
||||||
105
firmware/tests/uDCCD_Unit_Tests_HW.cbp
Normal file
105
firmware/tests/uDCCD_Unit_Tests_HW.cbp
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||||
|
<CodeBlocks_project_file>
|
||||||
|
<FileVersion major="1" minor="6" />
|
||||||
|
<Project>
|
||||||
|
<Option title="uDCCD_Unit_Tests_HW" />
|
||||||
|
<Option pch_mode="2" />
|
||||||
|
<Option compiler="gcc" />
|
||||||
|
<Build>
|
||||||
|
<Target title="Debug">
|
||||||
|
<Option output="bin/Debug/uDCCD_Unit_Tests_HW" prefix_auto="1" extension_auto="1" />
|
||||||
|
<Option object_output="obj/Debug/" />
|
||||||
|
<Option type="1" />
|
||||||
|
<Option compiler="gcc" />
|
||||||
|
<Compiler>
|
||||||
|
<Add option="-g" />
|
||||||
|
<Add option="-DTESTING" />
|
||||||
|
</Compiler>
|
||||||
|
</Target>
|
||||||
|
</Build>
|
||||||
|
<Compiler>
|
||||||
|
<Add option="-Wall" />
|
||||||
|
<Add option="-DTESTING" />
|
||||||
|
</Compiler>
|
||||||
|
<Unit filename="../src/hw/analog.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="../src/hw/analog.h" />
|
||||||
|
<Unit filename="../src/hw/board/utils/faults.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="../src/hw/board/utils/faults.h" />
|
||||||
|
<Unit filename="../src/hw/board/utils/fuses.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="../src/hw/board/utils/fuses.h" />
|
||||||
|
<Unit filename="../src/hw/board/utils/utils.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="../src/hw/board/utils/utils.h" />
|
||||||
|
<Unit filename="../src/hw/buttons.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="../src/hw/buttons.h" />
|
||||||
|
<Unit filename="../src/hw/hb_control.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="../src/hw/hb_control.h" />
|
||||||
|
<Unit filename="../src/hw/led_display.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="../src/hw/led_display.h" />
|
||||||
|
<Unit filename="../src/hw/startup.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="../src/hw/startup.h" />
|
||||||
|
<Unit filename="hw_main.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="mock_board/mock_board_ain.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="mock_board/mock_board_ain.h" />
|
||||||
|
<Unit filename="mock_board/mock_board_din.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="mock_board/mock_board_din.h" />
|
||||||
|
<Unit filename="mock_board/mock_board_dout.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="mock_board/mock_board_dout.h" />
|
||||||
|
<Unit filename="mock_board/mock_board_halfbridge.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="mock_board/mock_board_halfbridge.h" />
|
||||||
|
<Unit filename="mock_board/mock_board_odout.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="mock_board/mock_board_odout.h" />
|
||||||
|
<Unit filename="mock_board/mock_board_setup.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="mock_board/mock_board_setup.h" />
|
||||||
|
<Unit filename="ut_hw/ut_analog.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="ut_hw/ut_analog.h" />
|
||||||
|
<Unit filename="ut_hw/ut_buttons.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="ut_hw/ut_buttons.h" />
|
||||||
|
<Unit filename="ut_hw/ut_hb_control.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="ut_hw/ut_hb_control.h" />
|
||||||
|
<Unit filename="ut_hw/ut_led_display.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="ut_hw/ut_led_display.h" />
|
||||||
|
<Unit filename="ut_hw/ut_startup.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="ut_hw/ut_startup.h" />
|
||||||
|
<Extensions />
|
||||||
|
</Project>
|
||||||
|
</CodeBlocks_project_file>
|
||||||
378
firmware/tests/uDCCD_Unit_Tests_HW.depend
Normal file
378
firmware/tests/uDCCD_Unit_Tests_HW.depend
Normal file
@@ -0,0 +1,378 @@
|
|||||||
|
# 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
|
||||||
|
<stdint.h>
|
||||||
|
|
||||||
|
1699007962 d:\microrally\udccd_controller\src\hw\board\utils\utils.h
|
||||||
|
<stdint.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
|
||||||
|
<stdint.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
|
||||||
|
<stdint.h>
|
||||||
|
"config.h"
|
||||||
|
|
||||||
|
1699017683 d:\microrally\udccd_controller\src\hw\analog.h
|
||||||
|
<stdint.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
|
||||||
|
<stdint.h>
|
||||||
|
|
||||||
|
1699272290 d:\microrally\udccd_controller\tests\mock_board\mock_board_dout.h
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.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
|
||||||
|
<stdint.h>
|
||||||
|
|
||||||
|
1699272272 d:\microrally\udccd_controller\tests\mock_board\mock_board_odout.h
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.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
|
||||||
|
<stdint.h>
|
||||||
|
|
||||||
|
1699272264 d:\microrally\udccd_controller\tests\mock_board\mock_board_setup.h
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.h>
|
||||||
|
"..\..\src\hw\board\setup.h"
|
||||||
|
|
||||||
|
1699516357 source:d:\microrally\udccd_controller\tests\hw_main.c
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.h>
|
||||||
|
"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
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.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
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.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
|
||||||
|
<stdint.h>
|
||||||
|
|
||||||
|
1699272297 d:\microrally\udccd_controller\tests\mock_board\mock_board_din.h
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.h>
|
||||||
|
"..\..\src\hw\board\din.h"
|
||||||
|
|
||||||
|
1699535318 d:\microrally\udccd_controller\src\hw\board\halfbridge.h
|
||||||
|
<stdint.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
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.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
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.h>
|
||||||
|
|
||||||
|
1699535453 d:\microrally\udccd_controller\src\hw\buttons.h
|
||||||
|
<stdint.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
|
||||||
|
<stdint.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
|
||||||
|
<stdint.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
|
||||||
|
<stdint.h>
|
||||||
|
|
||||||
|
1699285771 d:\microrally\udccd_controller\tests\ut_hw\ut_startup.h
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.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
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.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
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.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
|
||||||
|
<stdint.h>
|
||||||
|
|
||||||
|
1699031869 f:\microrally\udccd_controller\src\hw\board\utils\utils.h
|
||||||
|
<stdint.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
|
||||||
|
<stdint.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
|
||||||
|
<stdint.h>
|
||||||
|
|
||||||
|
1699031869 f:\microrally\udccd_controller\src\hw\analog.h
|
||||||
|
<stdint.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
|
||||||
|
<stdint.h>
|
||||||
|
|
||||||
|
1699031869 f:\microrally\udccd_controller\src\hw\board\dout.h
|
||||||
|
<stdint.h>
|
||||||
|
|
||||||
|
1699477045 f:\microrally\udccd_controller\src\hw\buttons.h
|
||||||
|
<stdint.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
|
||||||
|
<stdint.h>
|
||||||
|
|
||||||
|
1699031869 f:\microrally\udccd_controller\src\hw\led_display.h
|
||||||
|
<stdint.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
|
||||||
|
<stdint.h>
|
||||||
|
|
||||||
|
1699031869 f:\microrally\udccd_controller\src\hw\startup.h
|
||||||
|
<stdint.h>
|
||||||
|
|
||||||
|
1699474639 source:f:\microrally\udccd_controller\tests\hw_main.c
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.h>
|
||||||
|
"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
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.h>
|
||||||
|
|
||||||
|
1699298688 f:\microrally\udccd_controller\tests\ut_hw\ut_buttons.h
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.h>
|
||||||
|
|
||||||
|
1699298688 f:\microrally\udccd_controller\tests\ut_hw\ut_startup.h
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.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
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.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
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.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
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.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
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.h>
|
||||||
|
"..\..\src\hw\board\halfbridge.h"
|
||||||
|
|
||||||
|
1699476970 f:\microrally\udccd_controller\src\hw\board\halfbridge.h
|
||||||
|
<stdint.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
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.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
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.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
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.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
|
||||||
|
<stdint.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
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.h>
|
||||||
|
|
||||||
|
1699535389 d:\microrally\udccd_controller\src\hw\board\config.h
|
||||||
|
<stdint.h>
|
||||||
|
|
||||||
|
1699535687 d:\microrally\udccd_controller\src\hw\config.h
|
||||||
|
<stdint.h>
|
||||||
|
|
||||||
145
firmware/tests/uDCCD_Unit_Tests_HW.layout
Normal file
145
firmware/tests/uDCCD_Unit_Tests_HW.layout
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||||
|
<CodeBlocks_layout_file>
|
||||||
|
<FileVersion major="1" minor="0" />
|
||||||
|
<ActiveTarget name="Debug" />
|
||||||
|
<File name="mock_board\mock_board_setup.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="228" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="..\src\hw\hb_control.c" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="5" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="5123" topLine="145" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="mock_board\mock_board_odout.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="56" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="mock_board\mock_board_odout.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="366" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="ut_hw\ut_hb_control.c" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="3" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="88492" topLine="2027" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="mock_board\mock_board_ain.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="357" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="..\src\hw\buttons.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="1649" topLine="24" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="ut_hw\ut_led_display.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="176" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="ut_hw\ut_analog.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="496" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="ut_hw\ut_led_display.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="2" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="856" topLine="60" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="..\src\hw\hb_control.h" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="391" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="ut_hw\ut_startup.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="161" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="mock_board\mock_board_dout.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="326" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="ut_hw\ut_analog.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="129" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="mock_board\mock_board_halfbridge.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="281" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="mock_board\mock_board_din.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="164" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="ut_hw\ut_buttons.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="221" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="mock_board\mock_board_din.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="52" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="mock_board\mock_board_halfbridge.h" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="529" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="mock_board\mock_board_ain.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="550" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="ut_hw\ut_buttons.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="10084" topLine="798" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="hw_main.c" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="3" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="2087" topLine="55" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="..\src\hw\board\utils\utils.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="181" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="ut_hw\ut_hb_control.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="302" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="ut_hw\ut_startup.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="606" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="mock_board\mock_board_setup.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="117" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="..\src\hw\analog.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="588" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="mock_board\mock_board_dout.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="54" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
</CodeBlocks_layout_file>
|
||||||
71
firmware/tests/uDCCD_Unit_Tests_Logic.cbp
Normal file
71
firmware/tests/uDCCD_Unit_Tests_Logic.cbp
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||||
|
<CodeBlocks_project_file>
|
||||||
|
<FileVersion major="1" minor="6" />
|
||||||
|
<Project>
|
||||||
|
<Option title="uDCCD_Unit_Tests_Logic" />
|
||||||
|
<Option pch_mode="2" />
|
||||||
|
<Option compiler="gcc" />
|
||||||
|
<Build>
|
||||||
|
<Target title="Debug">
|
||||||
|
<Option output="bin/Debug/uDCCD_Unit_Tests_Logic" prefix_auto="1" extension_auto="1" />
|
||||||
|
<Option object_output="obj/Debug/" />
|
||||||
|
<Option type="1" />
|
||||||
|
<Option compiler="gcc" />
|
||||||
|
<Compiler>
|
||||||
|
<Add option="-g" />
|
||||||
|
<Add option="-DTESTING" />
|
||||||
|
</Compiler>
|
||||||
|
</Target>
|
||||||
|
</Build>
|
||||||
|
<Compiler>
|
||||||
|
<Add option="-Wall" />
|
||||||
|
<Add option="-DTESTING" />
|
||||||
|
</Compiler>
|
||||||
|
<Unit filename="../src/logic/coil.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="../src/logic/coil.h" />
|
||||||
|
<Unit filename="../src/logic/display.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="../src/logic/display.h" />
|
||||||
|
<Unit filename="../src/logic/force.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="../src/logic/force.h" />
|
||||||
|
<Unit filename="../src/logic/pot.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="../src/logic/pot.h" />
|
||||||
|
<Unit filename="../src/logic/user_force.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="../src/logic/user_force.h" />
|
||||||
|
<Unit filename="logic_main.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="ut_logic/ut_coil.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="ut_logic/ut_coil.h" />
|
||||||
|
<Unit filename="ut_logic/ut_display.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="ut_logic/ut_display.h" />
|
||||||
|
<Unit filename="ut_logic/ut_force.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="ut_logic/ut_force.h" />
|
||||||
|
<Unit filename="ut_logic/ut_pot.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="ut_logic/ut_pot.h" />
|
||||||
|
<Unit filename="ut_logic/ut_user_force.c">
|
||||||
|
<Option compilerVar="CC" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="ut_logic/ut_user_force.h" />
|
||||||
|
<Extensions>
|
||||||
|
<lib_finder disable_auto="1" />
|
||||||
|
</Extensions>
|
||||||
|
</Project>
|
||||||
|
</CodeBlocks_project_file>
|
||||||
80
firmware/tests/uDCCD_Unit_Tests_Logic.depend
Normal file
80
firmware/tests/uDCCD_Unit_Tests_Logic.depend
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
# 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
|
||||||
|
<stdint.h>
|
||||||
|
|
||||||
|
1699472530 source:f:\microrally\udccd_controller\src\logic\display.c
|
||||||
|
"display.h"
|
||||||
|
|
||||||
|
1699472535 f:\microrally\udccd_controller\src\logic\display.h
|
||||||
|
<stdint.h>
|
||||||
|
|
||||||
|
1699474995 source:f:\microrally\udccd_controller\src\logic\force.c
|
||||||
|
"force.h"
|
||||||
|
|
||||||
|
1699474996 f:\microrally\udccd_controller\src\logic\force.h
|
||||||
|
<stdint.h>
|
||||||
|
|
||||||
|
1699031869 source:f:\microrally\udccd_controller\src\logic\pot.c
|
||||||
|
"pot.h"
|
||||||
|
|
||||||
|
1699475345 f:\microrally\udccd_controller\src\logic\pot.h
|
||||||
|
<stdint.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
|
||||||
|
<stdint.h>
|
||||||
|
|
||||||
|
1699474661 source:f:\microrally\udccd_controller\tests\logic_main.c
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.h>
|
||||||
|
"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
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.h>
|
||||||
|
|
||||||
|
1699473947 f:\microrally\udccd_controller\tests\ut_logic\ut_display.h
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.h>
|
||||||
|
|
||||||
|
1698869680 f:\microrally\udccd_controller\tests\ut_logic\ut_force.h
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.h>
|
||||||
|
|
||||||
|
1698869680 f:\microrally\udccd_controller\tests\ut_logic\ut_pot.h
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.h>
|
||||||
|
|
||||||
|
1698869680 f:\microrally\udccd_controller\tests\ut_logic\ut_user_force.h
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.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"
|
||||||
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user