Initial import of STM32CubeIDE project

This commit is contained in:
2026-03-26 16:11:00 +01:00
commit 523e57a6ae
177 changed files with 197768 additions and 0 deletions

72
Core/Inc/FBKW.h Normal file
View File

@@ -0,0 +1,72 @@
/*
* FBKW.h
*
* Created on: Nov 20, 2024
* Author: herli
*/
#ifndef INC_FBKW_H_
#define INC_FBKW_H_
#include "main.h"
extern TIM_HandleTypeDef htim4;
extern uint8_t CKP_PULSE_AVAILABLE;
extern uint8_t FBKW_PID_OPEN;
extern volatile uint32_t IC_SYNCOUT;
extern volatile uint32_t IC_CKP2;
extern volatile float RPM;
extern float refClock;
extern uint8_t safetySHUTOFF;
extern float errorFBKW;
extern float targetFBKW;
extern float Kp;
extern float Ki;
extern float intFBKWerror; //add += error * tstep
extern float FBKW_DEMAND;
extern float FBKW_DC;
extern float FBKW_FEEDBACK;
extern float B_FB_KW;
extern float B_FB_NW;
extern uint8_t forceDC;
typedef struct PID
{
float Kp; // Proportional gain constant
float Ki; // Integral gain constant
float Kd; // Derivative gain constant
float Kaw; // Anti-windup gain constant
float Bias; // Output bias
float T_C; // Time constant for derivative filtering
float T; // Time step
float max; // Max command
float min; // Min command
float max_rate; // Max rate of change of the command
float integral; // Integral term
float err_prev; // Previous error
float deriv_prev; // Previous derivative
float command_sat_prev;// Previous saturated command
float command_prev; // Previous command
} PID;
extern PID myPID; //antes era volatile
extern void FBKW_RESET_CKP_COUNT();
extern void FBKW_PIDInterrupt();
extern void FBKW_PROCESS_CKP_PULSE();
extern void updatePIDfreq(struct PID *pid, uint8_t millis);
extern void definePID(struct PID *pid, float Kp, float Ki, float Kd, float Kaw, float Bias, float T_C, float T, float max, float min, float max_rate, float integral, float err_prev, float deriv_prev, float command_sat_prev, float command_prev);
extern void initPID(struct PID *pid, float T_C, float T);
extern void UpdateFBKW_MODULATION(TIM_HandleTypeDef* pwmHandle, uint32_t pwmChannel, float dutyCycle);
extern float UpdateFBKW_DEMAND(float FBKW);
float UpdateFBKW_OpenDutyCycle(float RPM);
extern void UpdatePID(struct PID *pid);
float F_clamp(float val, float min, float max);
#endif /* INC_FBKW_H_ */

52
Core/Inc/ee.h Normal file
View File

@@ -0,0 +1,52 @@
#ifndef _EE_H_
#define _EE_H_
#ifdef __cplusplus
extern "C"
{
#endif
/************************************************************************************************************
************** Include Headers
************************************************************************************************************/
#include <stdbool.h>
#include "main.h"
/************************************************************************************************************
************** Public Definitions
************************************************************************************************************/
// none
/************************************************************************************************************
************** Public struct/enum
************************************************************************************************************/
typedef struct
{
uint8_t *pData;
uint32_t Size;
uint32_t PageSectorSize;
uint32_t Address;
uint8_t PageSectorNumber;
#if (defined FLASH_BANK_1) || (defined FLASH_BANK_2)
uint8_t BankNumber;
#endif
} EE_HandleTypeDef;
/************************************************************************************************************
************** Public Functions
************************************************************************************************************/
bool EE_Init(void *pData, uint32_t Size);
uint32_t EE_Capacity(void);
bool EE_Format(void);
void EE_Read(void);
bool EE_Write(void);
#ifdef __cplusplus
}
#endif
#endif

61
Core/Inc/ee_conf.h Normal file
View File

@@ -0,0 +1,61 @@
/**
******************************************************************************
* File Name : NimaLTD.I-CUBE-EE_conf.h
* Description : This file provides code for the configuration
* of the NimaLTD.I-CUBE-EE_conf.h instances.
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef _NIMALTD_I_CUBE_EE_CONF_H_
#define _NIMALTD_I_CUBE_EE_CONF_H_
#ifdef __cplusplus
extern "C" {
#endif
#define EE_PAGE_SECTOR_SIZE_1K (1024 * 1)
#define EE_PAGE_SECTOR_SIZE_2K (1024 * 2)
#define EE_PAGE_SECTOR_SIZE_4K (1024 * 4)
#define EE_PAGE_SECTOR_SIZE_8K (1024 * 8)
#define EE_PAGE_SECTOR_SIZE_16K (1024 * 16)
#define EE_PAGE_SECTOR_SIZE_32K (1024 * 32)
#define EE_PAGE_SECTOR_SIZE_64K (1024 * 64)
#define EE_PAGE_SECTOR_SIZE_128K (1024 * 128)
#define EE_PAGE_SECTOR_SIZE_256K (1024 * 256)
/*---------- EE_MANUAL_CONFIG -----------*/
#define EE_MANUAL_CONFIG false
/*---------- EE_SELECTED_PAGE_SECTOR_NUMBER -----------*/
#define EE_SELECTED_PAGE_SECTOR_NUMBER 16
/*---------- EE_SELECTED_PAGE_SECTOR_SIZE -----------*/
#define EE_SELECTED_PAGE_SECTOR_SIZE EE_PAGE_SECTOR_SIZE_1K
/*---------- EE_SELECTED_BANK -----------*/
#define EE_SELECTED_BANK FLASH_BANK_1
/*---------- EE_SELECTED_ADDRESS -----------*/
#define EE_SELECTED_ADDRESS 0x08000000
#ifdef __cplusplus
}
#endif
#endif /* _NIMALTD_I_CUBE_EE_CONF_H_ */
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

32
Core/Inc/ee_manager.h Normal file
View File

@@ -0,0 +1,32 @@
/*
* ee_manager.h
*
* Created on: Jul 16, 2025
* Author: herli
*/
#ifndef INC_EE_MANAGER_H_
#define INC_EE_MANAGER_H_
#include <stdint.h>
//#include "injection.h"
extern uint8_t memWrite;
/* EEprom values in ram */
extern float dFi;
extern uint8_t inj_mode;
extern uint8_t requestWriteHours;
extern void MEM_Init(void);
extern void MEM_WriteAll(void);
extern void MEM_RetrieveValues(void);
extern void MEM_WriteCustom(float c_dFi, uint8_t c_inj_mode);
extern void IncrementQuartHourCounter(void);
void MEM_WriteDefault(void);
#endif /* INC_EE_MANAGER_H_ */

56
Core/Inc/fuel_map.h Normal file
View File

@@ -0,0 +1,56 @@
/*
* fuel_map.h
*
* Created on: Oct 18, 2024
* Author: herli
*/
#ifndef FUEL_MAP_H_
#define FUEL_MAP_H_
#include <id.h>
#include <stdint.h>
//extern float PHIAD_TEIN;
// Function declarations
extern void init_FuelMap(float* PHIAD);
float GetAlpha(float RPM, float ME, float Tein, float Temp);
float GetBeta(float RPM, float Tein);
float FM_GET_PHIAD(float RPM, float ME, float Temp);
struct AlphaStruct {
//float ME_RPM_Beta_array[N_ME][N_RPM];
float ME_RPM_Beta_array[FM_N_RPM][FM_N_ME]; //para la transpuesta
};
extern struct AlphaStruct fuelmap_m12;
//extern struct AlphaStruct fuelmap_m5;
extern struct AlphaStruct fuelmap_10;
extern struct AlphaStruct fuelmap_25;
extern struct AlphaStruct fuelmap_60;
extern struct AlphaStruct fuelmap_80;
extern struct fuelMapIndexes fuelMapI;
static const struct AlphaStruct* g_FuelMaps[] = {
&fuelmap_m12,
//&fuelmap_m5,
&fuelmap_10,
&fuelmap_25,
&fuelmap_60,
&fuelmap_80
// add/remove as needed; order must match fuelMapI.T_Index_array
};
struct fuelMapIndexes {
float RPM_Index_array[FM_N_RPM];
float ME_Index_array[FM_N_ME];
float T_Index_array[FM_N_T];
};
// Declare the lookup table
//extern struct AlphaStruct fuelmap;
extern float BoostMultiplier(uint8_t mode, float RPM, float ME);
#endif /* FUEL_MAP2_H_ */

106
Core/Inc/id.h Normal file
View File

@@ -0,0 +1,106 @@
/*
* id.h
*
* Created on: Jul 28, 2025
* Author: herli
*/
#ifndef INC_ID_H_
#define INC_ID_H_
/* DEBUG PARAMETERS*/
#define T06301 //ford 004 -> 002 004 006 || 504 -> 010 018
//#define T06215 //bmw rover 004 -> 005 014 015 016 017 || 504 -> 005 007 017 || 006 -> 001 002 003 004 007 008
//#define T15021 //audi 506 -> 030 033
//#define T31804 //audi 506 -> 037 038
/* FORD */
#define FORD_SYNC_PULSE_OUT 1
#define ENABLE_AUDI_IMMO 0
#define HAS_PREINJECTION 0
#define CYLINDERS 4
/* TIMING COMPENSATIONS */
#define PHI1 25.102
#define TEIN_NOMINAL 0
#define TEIN_FAULT 950.5
/* ALL FBKW */
#define FBKW_DEM_M 0.5
#define FBKW_DEM_TEMP_M -0.0146
#define FBKW_DEM_TEMP_N 2.25
#define FBKW_DEM_A1 0.576
#define FBKW_DEM_A2 2.2
#define FBKW_DEM_A3 -0.636
#define FBKW_DEM_MIN 0
#define FBKW_FEEDBACK_ZERO 7.75
#define FBKW_FEEDBACK_MIN -3.16
#define FBKW_FEEDBACK_MAX 17.84
#define FBKW_FEEDBACK_IC_DT 27
#define FBKW_PID_KP 90 //16
#define FBKW_PID_KI 0 //18
#define FBKW_PID_KD 0
#define FBKW_PID_KAW 0 //16
#define FBKW_PID_BIAS 60
#define FBKW_PID_INTEGRAL 0
#define FBKW_PID_MAXRATE 10000
#define FBKW_PWM_MAX 95
#define FBKW_PWM_MIN 5
#define FBKW_MAX 90 //en 504 parece que era 506
#define FBKW_MAX_REAL_DEM 165
/* CAN DEFINITIONS */
#define CAN_BAUDRATE 500
#define CAN_RPM_SEND_ASYNC 250
#define CAN_EMPF2_INSTANT 0
/* ALL FUELMAP */
#define FM_N_RPM 10
#define FM_N_ME 12
#define FM_N_T 5
/* PEAK AND HOLD */
#define PH_PEAK_DEF 600
/* ANALOG CALIBRATION PARAMETERS */
// MOSFET
#define V_PEAK 2.94
#define V_HOLD 1.94
#define INJ_CLOSING_MARGIN 0 //o cero, o 20
// TOOTHED WHEEL
#define TW_MT_THRESHOLD 2.4
#define TW_THEETHS 120
#define TW_TOOTH_ALPHA 3
#define TW_STARTED_RPM 400
#define MIN_RPM 20
#define USTODEG 0.000006
// TIMINGS
#define TEIN_READING_OFFSET 8
/* ifdef things */
#if CYLINDERS == 4
#define TW_PERCYL_TEETH 26
#elif CYLINDERS == 6
#define TW_PERCYL_TEETH 16
#else
#define TW_PERCYL_TEETH 26
#error "Unsupported number of cylinders"
#endif
#endif /* INC_ID_H_ */

111
Core/Inc/id_004002.h Normal file
View File

@@ -0,0 +1,111 @@
/*
* id.h
*
* Created on: Jul 28, 2025
* Author: herli
*/
#ifndef INC_ID_H_
#define INC_ID_H_
/* DEBUG PARAMETERS*/
#define T06301 //ford 004 -> 002 004 006 || 504 -> 010 018
//#define T06215 //bmw rover 004 -> 005 014 015 016 017 || 504 -> 005 007 017 || 006 -> 001 002 003 004 007 008
//#define T15021 //audi 506 -> 030 033
//#define T31804 //audi 506 -> 037 038
//#define T06209 //eq: T06216
//#define T06211
/* FORD */
#define FORD_SYNC_PULSE_OUT 1
#define ENABLE_AUDI_IMMO 0
#define HAS_PREINJECTION 0
#define CYLINDERS 4
/* TIMING COMPENSATIONS */
#define PHI1 24.914
#define TEIN_NOMINAL 0
#define TEIN_FAULT 950.5
/* ALL FBKW */
#define FBKW_DEM_M 0.5
#define FBKW_DEM_TEMP_M -0.0145
#define FBKW_DEM_TEMP_N 0.53
#define FBKW_DEM_A1 1.42
#define FBKW_DEM_A2 1.45
#define FBKW_DEM_A3 -0.459
#define FBKW_DEM_ME_M 0.0031
#define FBKW_DEM_ME_N 0.527
#define FBKW_DEM_MIN 0
#define FBKW_FEEDBACK_ZERO 7.617
#define FBKW_FEEDBACK_MIN -3.188
#define FBKW_FEEDBACK_MAX 17.813
#define FBKW_FEEDBACK_IC_DT 27
#define FBKW_PID_KP 90 //16
#define FBKW_PID_KI 0 //18
#define FBKW_PID_KD 0
#define FBKW_PID_KAW 0 //16
#define FBKW_PID_BIAS 60
#define FBKW_PID_INTEGRAL 0
#define FBKW_PID_MAXRATE 10000
#define FBKW_PWM_MAX 95
#define FBKW_PWM_MIN 5
#define FBKW_MAX 90 //en 504 parece que era 506
#define FBKW_MAX_REAL_DEM 165
/* CAN DEFINITIONS */
#define CAN_BAUDRATE 500
#define CAN_RPM_SEND_ASYNC 250
#define CAN_EMPF2_INSTANT 0
/* ALL FUELMAP */
#define FM_N_RPM 10
#define FM_N_ME 12
#define FM_N_T 6
/* PEAK AND HOLD */
#define PH_PEAK_DEF 600
/* ANALOG CALIBRATION PARAMETERS */
// MOSFET
#define V_PEAK 2.94
#define V_HOLD 1.94
#define INJ_CLOSING_MARGIN 0 //o cero, o 20
// TOOTHED WHEEL
#define TW_MT_THRESHOLD 2.4
#define TW_THEETHS 120
#define TW_TOOTH_ALPHA 3
#define TW_STARTED_RPM 400
#define MIN_RPM 20
#define USTODEG 0.000006
// TIMINGS
#define TEIN_READING_OFFSET 8
/* ifdef things */
#if CYLINDERS == 4
#define TW_PERCYL_TEETH 26
#elif CYLINDERS == 6
#define TW_PERCYL_TEETH 16
#else
#define TW_PERCYL_TEETH 26
#error "Unsupported number of cylinders"
#endif
#endif /* INC_ID_H_ */

106
Core/Inc/id_004004.h Normal file
View File

@@ -0,0 +1,106 @@
/*
* id.h
*
* Created on: Jul 28, 2025
* Author: herli
*/
#ifndef INC_ID_H_
#define INC_ID_H_
/* DEBUG PARAMETERS*/
#define T06301 //ford 004 -> 002 004 006 || 504 -> 010 018
//#define T06215 //bmw rover 004 -> 005 014 015 016 017 || 504 -> 005 007 017 || 006 -> 001 002 003 004 007 008
//#define T15021 //audi 506 -> 030 033
//#define T31804 //audi 506 -> 037 038
/* FORD */
#define FORD_SYNC_PULSE_OUT 1
#define ENABLE_AUDI_IMMO 0
#define HAS_PREINJECTION 0
#define CYLINDERS 4
/* TIMING COMPENSATIONS */
#define PHI1 25.4 //25.4??
#define TEIN_NOMINAL 0
#define TEIN_FAULT 950.5
/* ALL FBKW */
#define FBKW_DEM_M 0.5
#define FBKW_DEM_TEMP_M -0.0138271344
#define FBKW_DEM_TEMP_N 1.619546633
#define FBKW_DEM_A1 -0.649
#define FBKW_DEM_A2 3.86
#define FBKW_DEM_A3 -0.795
#define FBKW_DEM_MIN 0
#define FBKW_FEEDBACK_ZERO 8.345
#define FBKW_FEEDBACK_MIN -3.77
#define FBKW_FEEDBACK_MAX 18
#define FBKW_FEEDBACK_IC_DT 27
#define FBKW_PID_KP 90 //16
#define FBKW_PID_KI 0 //18
#define FBKW_PID_KD 0
#define FBKW_PID_KAW 0 //16
#define FBKW_PID_BIAS 60
#define FBKW_PID_INTEGRAL 0
#define FBKW_PID_MAXRATE 10000
#define FBKW_PWM_MAX 95
#define FBKW_PWM_MIN 5
#define FBKW_MAX 90 //en 504 parece que era 506
#define FBKW_MAX_REAL_DEM 165
/* CAN DEFINITIONS */
#define CAN_BAUDRATE 500
#define CAN_RPM_SEND_ASYNC 250
#define CAN_EMPF2_INSTANT 0
/* ALL FUELMAP */
#define FM_N_RPM 10
#define FM_N_ME 12
#define FM_N_T 5
/* PEAK AND HOLD */
#define PH_PEAK_DEF 600
/* ANALOG CALIBRATION PARAMETERS */
// MOSFET
#define V_PEAK 2.94
#define V_HOLD 1.94
#define INJ_CLOSING_MARGIN 0 //o cero, o 20
// TOOTHED WHEEL
#define TW_MT_THRESHOLD 2.4
#define TW_THEETHS 120
#define TW_TOOTH_ALPHA 3
#define TW_STARTED_RPM 400
#define MIN_RPM 20
#define USTODEG 0.000006
// TIMINGS
#define TEIN_READING_OFFSET 8
/* ifdef things */
#if CYLINDERS == 4
#define TW_PERCYL_TEETH 26
#elif CYLINDERS == 6
#define TW_PERCYL_TEETH 16
#else
#define TW_PERCYL_TEETH 26
#error "Unsupported number of cylinders"
#endif
#endif /* INC_ID_H_ */

95
Core/Inc/id_004005.h Normal file
View File

@@ -0,0 +1,95 @@
/*
* id.h
*
* Created on: Jul 28, 2025
* Author: herli
*/
#ifndef INC_ID_H_
#define INC_ID_H_
/* DEBUG PARAMETERS*/
//#define T06301 //ford 004 -> 002 004 006 || 504 -> 010 018
#define T06215 //bmw rover 004 -> 005 014 015 016 017 || 504 -> 005 007 017 || 006 -> 001 002 003 004 007 008
//#define T15021 //audi 506 -> 030 033
//#define T31804 //audi 506 -> 037 038
/* ROVER */
#define ENABLE_AUDI_IMMO 0
#define HAS_PREINJECTION 0
#define CYLINDERS 4
/* TIMING COMPENSATIONS */
#define PHI1 25.45
#define TEIN_NOMINAL 1000
#define TEIN_FAULT 950
/* ALL FBKW */
#define FBKW_DEM_M 0.5
#define FBKW_DEM_N 7.2
#define FBKW_DEM_MIN -6.0
#define FBKW_FEEDBACK_ZERO 37.6//58.28
#define FBKW_FEEDBACK_MIN -3.7
#define FBKW_FEEDBACK_MAX 18.8
#define FBKW_FEEDBACK_IC_DT 27
#define FBKW_PID_KP 90 //16
#define FBKW_PID_KI 0 //18
#define FBKW_PID_KD 0
#define FBKW_PID_KAW 0 //16
#define FBKW_PID_BIAS 60
#define FBKW_PID_INTEGRAL 0
#define FBKW_PID_MAXRATE 10000
#define FBKW_PWM_MAX 95
#define FBKW_PWM_MIN 5
/* CAN DEFINITIONS */
#define CAN_BAUDRATE 500
#define CAN_RPM_SEND_ASYNC 250
#define CAN_EMPF2_INSTANT 1
/* ALL FUELMAP */
#define FM_N_RPM 11
#define FM_N_ME 11
#define FM_N_T 2
/* PEAK AND HOLD */
#define PH_PEAK_DEF 600
/* ANALOG CALIBRATION PARAMETERS */
// MOSFET
#define V_PEAK 2.94
#define V_HOLD 1.94
#define INJ_CLOSING_MARGIN 0 //o cero, o 20
// TOOTHED WHEEL
#define TW_MT_THRESHOLD 2.4
#define TW_THEETHS 120
#define TW_TOOTH_ALPHA 3
#define TW_STARTED_RPM 400
#define MIN_RPM 20
#define USTODEG 0.000006
// TIMINGS
#define TEIN_READING_OFFSET 8
/* ifdef things */
#if CYLINDERS == 4
#define TW_PERCYL_TEETH 26
#elif CYLINDERS == 6
#define TW_PERCYL_TEETH 16
#else
#define TW_PERCYL_TEETH 26
#error "Unsupported number of cylinders"
#endif
#endif /* INC_ID_H_ */

106
Core/Inc/id_004006.h Normal file
View File

@@ -0,0 +1,106 @@
/*
* id.h
*
* Created on: Jul 28, 2025
* Author: herli
*/
#ifndef INC_ID_H_
#define INC_ID_H_
/* DEBUG PARAMETERS*/
#define T06301 //ford 004 -> 002 004 006 || 504 -> 010 018
//#define T06215 //bmw rover 004 -> 005 014 015 016 017 || 504 -> 005 007 017 || 006 -> 001 002 003 004 007 008
//#define T15021 //audi 506 -> 030 033
//#define T31804 //audi 506 -> 037 038
/* FORD */
#define FORD_SYNC_PULSE_OUT 1
#define ENABLE_AUDI_IMMO 0
#define HAS_PREINJECTION 0
#define CYLINDERS 4
/* TIMING COMPENSATIONS */
#define PHI1 25.102
#define TEIN_NOMINAL 0
#define TEIN_FAULT 950.5
/* ALL FBKW */
#define FBKW_DEM_M 0.5
#define FBKW_DEM_TEMP_M -0.0146
#define FBKW_DEM_TEMP_N 2.25
#define FBKW_DEM_A1 0.576
#define FBKW_DEM_A2 2.2
#define FBKW_DEM_A3 -0.636
#define FBKW_DEM_MIN 0
#define FBKW_FEEDBACK_ZERO 7.75
#define FBKW_FEEDBACK_MIN -3.16
#define FBKW_FEEDBACK_MAX 17.84
#define FBKW_FEEDBACK_IC_DT 27
#define FBKW_PID_KP 90 //16
#define FBKW_PID_KI 0 //18
#define FBKW_PID_KD 0
#define FBKW_PID_KAW 0 //16
#define FBKW_PID_BIAS 60
#define FBKW_PID_INTEGRAL 0
#define FBKW_PID_MAXRATE 10000
#define FBKW_PWM_MAX 95
#define FBKW_PWM_MIN 5
#define FBKW_MAX 90 //en 504 parece que era 506
#define FBKW_MAX_REAL_DEM 165
/* CAN DEFINITIONS */
#define CAN_BAUDRATE 500
#define CAN_RPM_SEND_ASYNC 250
#define CAN_EMPF2_INSTANT 0
/* ALL FUELMAP */
#define FM_N_RPM 10
#define FM_N_ME 12
#define FM_N_T 5
/* PEAK AND HOLD */
#define PH_PEAK_DEF 600
/* ANALOG CALIBRATION PARAMETERS */
// MOSFET
#define V_PEAK 2.94
#define V_HOLD 1.94
#define INJ_CLOSING_MARGIN 0 //o cero, o 20
// TOOTHED WHEEL
#define TW_MT_THRESHOLD 2.4
#define TW_THEETHS 120
#define TW_TOOTH_ALPHA 3
#define TW_STARTED_RPM 400
#define MIN_RPM 20
#define USTODEG 0.000006
// TIMINGS
#define TEIN_READING_OFFSET 8
/* ifdef things */
#if CYLINDERS == 4
#define TW_PERCYL_TEETH 26
#elif CYLINDERS == 6
#define TW_PERCYL_TEETH 16
#else
#define TW_PERCYL_TEETH 26
#error "Unsupported number of cylinders"
#endif
#endif /* INC_ID_H_ */

108
Core/Inc/id_504003.h Normal file
View File

@@ -0,0 +1,108 @@
/*
* id.h
*
* Created on: Jul 28, 2025
* Author: herli
*/
#ifndef INC_ID_H_
#define INC_ID_H_
/* DEBUG PARAMETERS*/
//#define T06301 //ford 004 -> 002 004 006 || 504 -> 010 018
//#define T06215 //bmw rover 004 -> 005 014 015 016 017 || 504 -> 005 007 017 || 006 -> 001 002 003 004 007 008
//#define T15021 //audi 506 -> 030 033
//#define T31804 //audi 506 -> 037 038
#define T06209 //eq: T06216
/* FORD */
#define FORD_SYNC_PULSE_OUT 0
#define ENABLE_AUDI_IMMO 0
#define HAS_PREINJECTION 0
#define CYLINDERS 4
/* TIMING COMPENSATIONS */
#define PHI1 41.016
#define TEIN_NOMINAL 1550
#define TEIN_FAULT 1092.5
/* ALL FBKW */
#define FBKW_DEM_M 0.5
#define FBKW_DEM_TEMP_M 0
#define FBKW_DEM_TEMP_N -6.05
//rpm comp
#define FBKW_DEM_A1 0
#define FBKW_DEM_A2 0
#define FBKW_DEM_A3 0
#define FBKW_DEM_MIN -6
#define FBKW_FEEDBACK_ZERO 55.12//6.04?
#define FBKW_FEEDBACK_MIN -4.24
#define FBKW_FEEDBACK_MAX 19.75
#define FBKW_FEEDBACK_IC_DT 27
#define FBKW_PID_KP 90 //16
#define FBKW_PID_KI 0 //18
#define FBKW_PID_KD 0
#define FBKW_PID_KAW 0 //16
#define FBKW_PID_BIAS 60
#define FBKW_PID_INTEGRAL 0
#define FBKW_PID_MAXRATE 10000
#define FBKW_PWM_MAX 95
#define FBKW_PWM_MIN 5
#define FBKW_MAX 90 //en 504 parece que era 506
#define FBKW_MAX_REAL_DEM 165 //wtf is this
/* CAN DEFINITIONS */
#define CAN_BAUDRATE 500
#define CAN_RPM_SEND_ASYNC 250
#define CAN_EMPF2_INSTANT 0
/* ALL FUELMAP */
#define FM_N_RPM 6
#define FM_N_ME 10
#define FM_N_T 5
/* PEAK AND HOLD */
#define PH_PEAK_DEF 600
/* ANALOG CALIBRATION PARAMETERS */
// MOSFET
#define V_PEAK 2.94
#define V_HOLD 1.94
#define INJ_CLOSING_MARGIN 0 //o cero, o 20
// TOOTHED WHEEL
#define TW_MT_THRESHOLD 2.4
#define TW_THEETHS 120
#define TW_TOOTH_ALPHA 3
#define TW_STARTED_RPM 400
#define MIN_RPM 20
#define USTODEG 0.000006
// TIMINGS
#define TEIN_READING_OFFSET 8
/* ifdef things */
#if CYLINDERS == 4
#define TW_PERCYL_TEETH 26
#elif CYLINDERS == 6
#define TW_PERCYL_TEETH 16
#else
#define TW_PERCYL_TEETH 26
#error "Unsupported number of cylinders"
#endif
#endif /* INC_ID_H_ */

92
Core/Inc/id_504005.h Normal file
View File

@@ -0,0 +1,92 @@
/*
* id.h
*
* Created on: Jul 28, 2025
* Author: herli
*/
#ifndef INC_ID_H_
#define INC_ID_H_
/* DEBUG PARAMETERS*/
#define ENABLE_AUDI_IMMO 0
#define HAS_PREINJECTION 0
#define CYLINDERS 4
/* TIMING COMPENSATIONS */
#define PHI1 41.05
#define TEIN_NOMINAL 1550
#define TEIN_FAULT 986.5
/* ALL FBKW */
#define FBKW_DEM_M 0.5
#define FBKW_DEM_N 8.05
#define FBKW_DEM_MIN -6.0
#define FBKW_FEEDBACK_ZERO 59.1 //58.4
#define FBKW_FEEDBACK_MIN -3.35
#define FBKW_FEEDBACK_MAX 30.13
#define FBKW_FEEDBACK_IC_DT 27
#define FBKW_PID_KP 5 //14
#define FBKW_PID_KI 20 //24
#define FBKW_PID_KD 0
#define FBKW_PID_KAW 20 //24
#define FBKW_PID_BIAS 20
#define FBKW_PID_INTEGRAL 00
#define FBKW_PID_MAXRATE 10000
#define FBKW_PWM_MAX 95
#define FBKW_PWM_MIN 5
/* CAN DEFINITIONS */
#define CAN_BAUDRATE 500
#define CAN_RPM_SEND_ASYNC 250
#define CAN_EMPF2_INSTANT 1
/* ALL FUELMAP */
#define FM_N_RPM 6
#define FM_N_ME 10
#define FM_N_T 2
/* PEAK AND HOLD */
#define PH_PEAK_DEF 600
/* ANALOG CALIBRATION PARAMETERS */
// MOSFET
#define V_PEAK 2.94
#define V_HOLD 1.94
#define INJ_CLOSING_MARGIN 0 //o cero, o 20
// TOOTHED WHEEL
#define TW_MT_THRESHOLD 2.4 //sacado del original
#define TW_THEETHS 120
#define TW_TOOTH_ALPHA 3
#define TW_STARTED_RPM 400
#define MIN_RPM 20
#define USTODEG 0.000006
// TIMINGS
#define TEIN_READING_OFFSET 8
/* ifdef things */
#if CYLINDERS == 4
#define TW_PERCYL_TEETH 26
#elif CYLINDERS == 6
#define TW_PERCYL_TEETH 16
#else
#define TW_PERCYL_TEETH 26
#error "Unsupported number of cylinders"
#endif
#endif /* INC_ID_H_ */

110
Core/Inc/id_504010.h Normal file
View File

@@ -0,0 +1,110 @@
/*
* id.h
*
* Created on: Jul 28, 2025
* Author: herli
*/
#ifndef INC_ID_H_
#define INC_ID_H_
/* 504 010 */
/* DEBUG PARAMETERS*/
#define T06301 //ford 004 -> 002 004 006 || 504 -> 010 018
//#define T06215 //bmw rover 004 -> 005 014 015 016 017 || 504 -> 005 007 017 || 006 -> 001 002 003 004 007 008
//#define T15021 //audi 506 -> 030 033
//#define T31804 //audi 506 -> 037 038
/* FORD */
#define FORD_SYNC_PULSE_OUT 1
#define ENABLE_AUDI_IMMO 0
#define HAS_PREINJECTION 0
#define CYLINDERS 4
/* TIMING COMPENSATIONS */
#define PHI1 41
#define TEIN_NOMINAL 0
#define TEIN_FAULT 1018
/* ALL FBKW */
#define FBKW_DEM_M 0.5
#define FBKW_DEM_TEMP_M 0
#define FBKW_DEM_TEMP_N 0.996
#define FBKW_DEM_A1 4.75
#define FBKW_DEM_A2 -2.28
#define FBKW_DEM_A3 0.969
#define FBKW_DEM_ME_M 0.0021
#define FBKW_DEM_ME_N 0
#define FBKW_DEM_MIN -6
#define FBKW_FEEDBACK_ZERO 23
#define FBKW_FEEDBACK_MIN -3.410
#define FBKW_FEEDBACK_MAX 20.59
#define FBKW_FEEDBACK_IC_DT 27
#define FBKW_PID_KP 90 //16
#define FBKW_PID_KI 0 //18
#define FBKW_PID_KD 0
#define FBKW_PID_KAW 0 //16
#define FBKW_PID_BIAS 60
#define FBKW_PID_INTEGRAL 0
#define FBKW_PID_MAXRATE 10000
#define FBKW_PWM_MAX 95
#define FBKW_PWM_MIN 5
#define FBKW_MAX 90 //en 504 parece que era 506
#define FBKW_MAX_REAL_DEM 165
/* CAN DEFINITIONS */
#define CAN_BAUDRATE 500
#define CAN_RPM_SEND_ASYNC 250
#define CAN_EMPF2_INSTANT 0
/* ALL FUELMAP */
#define FM_N_RPM 10
#define FM_N_ME 12
#define FM_N_T 5
/* PEAK AND HOLD */
#define PH_PEAK_DEF 600
/* ANALOG CALIBRATION PARAMETERS */
// MOSFET
#define V_PEAK 2.94
#define V_HOLD 1.94
#define INJ_CLOSING_MARGIN 0 //o cero, o 20
// TOOTHED WHEEL
#define TW_MT_THRESHOLD 2.4
#define TW_THEETHS 120
#define TW_TOOTH_ALPHA 3
#define TW_STARTED_RPM 400
#define MIN_RPM 20
#define USTODEG 0.000006
// TIMINGS
#define TEIN_READING_OFFSET 8
/* ifdef things */
#if CYLINDERS == 4
#define TW_PERCYL_TEETH 26
#elif CYLINDERS == 6
#define TW_PERCYL_TEETH 16
#else
#define TW_PERCYL_TEETH 26
#error "Unsupported number of cylinders"
#endif
#endif /* INC_ID_H_ */

113
Core/Inc/id_504012.h Normal file
View File

@@ -0,0 +1,113 @@
/*
* id.h
*
* Created on: Jul 28, 2025
* Author: herli
*/
#ifndef INC_ID_H_
#define INC_ID_H_
/* 504 012 */
/* DEBUG PARAMETERS*/
//#define T06301 //ford 004 -> 002 004 006 || 504 -> 010 018
//#define T06215 //bmw rover 004 -> 005 014 015 016 017 || 504 -> 005 007 017 || 006 -> 001 002 003 004 007 008
//#define T15021 //audi 506 -> 030 033
//#define T31804 //audi 506 -> 037 038
//#define T06209 //eq: T06216
#define T06211
/* FORD */
#define FORD_SYNC_PULSE_OUT 0
#define ENABLE_AUDI_IMMO 0
#define HAS_PREINJECTION 0
#define CYLINDERS 4
/* TIMING COMPENSATIONS */
#define PHI1 41.016
#define TEIN_NOMINAL 1550
//(phiad - injangle with fault tein)*totime = teinnom
#define TEIN_FAULT 950
/* ALL FBKW */
#define FBKW_DEM_M 0.5
#define FBKW_DEM_TEMP_M 0
#define FBKW_DEM_TEMP_N -7.7
//rpm comp
#define FBKW_DEM_A1 0
#define FBKW_DEM_A2 0
#define FBKW_DEM_A3 0
#define FBKW_DEM_MIN -6
#define FBKW_FEEDBACK_ZERO 53.75
#define FBKW_FEEDBACK_MIN -5.367
#define FBKW_FEEDBACK_MAX 21.27
#define FBKW_FEEDBACK_IC_DT 27
#define FBKW_PID_KP 90 //16
#define FBKW_PID_KI 0 //18
#define FBKW_PID_KD 0
#define FBKW_PID_KAW 0 //16
#define FBKW_PID_BIAS 60
#define FBKW_PID_INTEGRAL 0
#define FBKW_PID_MAXRATE 10000
#define FBKW_PWM_MAX 95
#define FBKW_PWM_MIN 5
#define FBKW_MAX 90 //en 504 parece que era 506
#define FBKW_MAX_REAL_DEM 165 //wtf is this
/* CAN DEFINITIONS */
#define CAN_BAUDRATE 500
#define CAN_RPM_SEND_ASYNC 250
#define CAN_EMPF2_INSTANT 0
/* ALL FUELMAP */
#define FM_N_RPM 6
#define FM_N_ME 11
#define FM_N_T 5
/* PEAK AND HOLD */
#define PH_PEAK_DEF 600
/* ANALOG CALIBRATION PARAMETERS */
// MOSFET
#define V_PEAK 2.94
#define V_HOLD 1.94
#define INJ_CLOSING_MARGIN 0 //o cero, o 20
// TOOTHED WHEEL
#define TW_MT_THRESHOLD 2.4
#define TW_THEETHS 120
#define TW_TOOTH_ALPHA 3
#define TW_STARTED_RPM 400
#define MIN_RPM 20
#define USTODEG 0.000006
// TIMINGS
#define TEIN_READING_OFFSET 8
/* ifdef things */
#if CYLINDERS == 4
#define TW_PERCYL_TEETH 26
#elif CYLINDERS == 6
#define TW_PERCYL_TEETH 16
#else
#define TW_PERCYL_TEETH 26
#error "Unsupported number of cylinders"
#endif
#endif /* INC_ID_H_ */

86
Core/Inc/id_506033.h Normal file
View File

@@ -0,0 +1,86 @@
/*
* id.h
*
* Created on: Jul 28, 2025
* Author: herli
*/
#ifndef INC_ID_H_
#define INC_ID_H_
/* 506 033 */
/* DEBUG PARAMETERS*/
#define ENABLE_AUDI_IMMO 1
#define HAS_PREINJECTION 1
#define CYLINDERS 6
/* TIMING COMPENSATIONS */
#define PHI1 25.7
#define TEIN_NOMINAL 1550
#define TEIN_FAULT 879.5
/* ALL FBKW */
#define FBKW_DEM_M 0.5
#define FBKW_DEM_N 4.44
#define FBKW_DEM_MIN -4.44
#define FBKW_FEEDBACK_ZERO 41.67//58.28
#define FBKW_FEEDBACK_MIN -4.17
#define FBKW_FEEDBACK_MAX 16.83
#define FBKW_PID_KP 15 //16
#define FBKW_PID_KI 10 //18
#define FBKW_PID_KD 0
#define FBKW_PID_KAW 5 //16
#define FBKW_PID_BIAS 0
#define FBKW_PID_INTEGRAL 20
#define FBKW_PID_MAXRATE 10000
#define FBKW_PWM_MAX 95
#define FBKW_PWM_MIN 5
/* CAN DEFINITIONS */
#define CAN_BAUDRATE 500
#define CAN_SEND_ASYNC_RPM 200
#define CAN_EMPF2_INSTANT 0
/* ALL FUELMAP */
#define FM_N_RPM 7
#define FM_N_ME 11
#define FM_N_T 2
/* PEAK AND HOLD */
#define PH_PEAK_DEF 600
/* ANALOG CALIBRATION PARAMETERS */
// MOSFET
#define V_PEAK 2.94
#define V_HOLD 1.94
#define INJ_CLOSING_MARGIN 0 //o cero, o 20
// TOOTHED WHEEL
#define TW_MT_THRESHOLD 2
#define TW_THEETHS 120
#define TW_TOOTH_ALPHA 3
#define TW_STARTED_RPM 350
#define MIN_RPM 20
/* ifdef things */
#if CYLINDERS == 4
#define TW_PERCYL_TEETH 26
#elif CYLINDERS == 6
#define TW_PERCYL_TEETH 16
#else
#define TW_PERCYL_TEETH 26
#error "Unsupported number of cylinders"
#endif
#endif /* INC_ID_H_ */

57
Core/Inc/injection.h Normal file
View File

@@ -0,0 +1,57 @@
/*
* injection.h
*
* Created on: Aug 4, 2025
* Author: herli
*/
#ifndef INC_INJECTION_H_
#define INC_INJECTION_H_
#include "stdint.h"
#include "stm32g4xx_hal.h"
#include "stm32g4xx_hal_dac.h"
#include "can_schema.h"
extern DAC_HandleTypeDef hdac1;
extern TIM_HandleTypeDef htim1;
extern volatile uint8_t isInjecting;
extern volatile uint8_t hasInjected;
extern volatile uint8_t hasInjectionEnded;
extern volatile uint8_t hasInjectionEndedFlag;
extern float dFi;
extern uint8_t INJ_closingTeeth;
extern float ME;
extern float MEPI;
extern uint8_t safetySHUTOFF;
extern uint8_t timer1started;
extern uint32_t T_hold; //Time on in microseconds
extern uint16_t T_peak;
extern uint32_t T_integrated;
extern float current_Beta;
extern float current_Alpha;
extern void INJ_EVAL_EOI_COMPENSATION(void);
extern void INJ_UPDATE_ALPHA(void);
extern void INJ_UPDATE_CLOSING_TEETH(void);
extern void INJ_EVAL_END();
extern void INJ_END(void);
extern void INJ_SET_DAC(uint8_t isPeak);
extern void INJ_UPDATE_BOI_TRIGGER(void);
extern float INJ_GET_TARGET_BETA();
extern float INJ_GET_TARGET_EOI();
extern void INJ_UPDATE_BOI_MARGIN(float rpm);
float DEGTOTIME(float DEG, float revs);
float TIMETODEG(float TIME, float revs);
extern void SEND1_Handler();
#endif /* INC_INJECTION_H_ */

109
Core/Inc/main.h Normal file
View File

@@ -0,0 +1,109 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.h
* @brief : Header for main.c file.
* This file contains the common defines of the application.
******************************************************************************
* @attention
*
* Copyright (c) 2025 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H
#define __MAIN_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32g4xx_hal.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
/* USER CODE END EC */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
/* USER CODE END EM */
void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
/* Exported functions prototypes ---------------------------------------------*/
void Error_Handler(void);
/* USER CODE BEGIN EFP */
extern void StartSampling(void);
extern void DAC_Voltaje(uint8_t isPeak);
extern void Set_Tein_Status(uint8_t status);
extern void PIDInterrupt();
extern void Start_DAC_DMA_Output();
extern void Start_DAC_DMA();
extern void DAC_Soft_Trigger();
extern void PrepareDACTimer();
extern void EndInjection();
extern void OnEnd();
extern volatile uint8_t isInjecting;
extern float V_on; // Modulo con Transistor lfpak56
extern float V_peak; // Modulo con Transistor lfpak56
extern volatile uint32_t IC_INJ;
extern volatile uint32_t IC_SYNCOUT;
extern uint8_t awaitingTein;
extern uint8_t teinStatus;
extern uint8_t compensatingEOI;
extern FDCAN_RxHeaderTypeDef RxHeader;
/* USER CODE END EFP */
/* Private defines -----------------------------------------------------------*/
#define DAC_PEAK_Pin GPIO_PIN_4
#define DAC_PEAK_GPIO_Port GPIOA
#define ADC_TEIN_Pin GPIO_PIN_5
#define ADC_TEIN_GPIO_Port GPIOA
#define IN_CKP_Pin GPIO_PIN_0
#define IN_CKP_GPIO_Port GPIOB
#define SYNC_OUT_Pin GPIO_PIN_15
#define SYNC_OUT_GPIO_Port GPIOA
#define IDLE_IN_Pin GPIO_PIN_3
#define IDLE_IN_GPIO_Port GPIOB
#define SHUT_OFF_Pin GPIO_PIN_4
#define SHUT_OFF_GPIO_Port GPIOB
#define HOLD_CONTROL_Pin GPIO_PIN_6
#define HOLD_CONTROL_GPIO_Port GPIOB
#define ADVANCE_PWM_Pin GPIO_PIN_7
#define ADVANCE_PWM_GPIO_Port GPIOB
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
#ifdef __cplusplus
}
#endif
#endif /* __MAIN_H */

17
Core/Inc/pre_injection.h Normal file
View File

@@ -0,0 +1,17 @@
/*
* pre_injection.h
*
* Created on: Sep 16, 2025
* Author: herli
*/
#ifndef INC_PRE_INJECTION_H_
#define INC_PRE_INJECTION_H_
#include "stdint.h"
extern uint8_t active_PI;
extern float MEPI;
extern void PI_EVAL(float RPM, float ME, float MEPI);
#endif /* INC_PRE_INJECTION_H_ */

View File

@@ -0,0 +1,380 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32g4xx_hal_conf.h
* @author MCD Application Team
* @brief HAL configuration file
******************************************************************************
* @attention
*
* Copyright (c) 2019 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef STM32G4xx_HAL_CONF_H
#define STM32G4xx_HAL_CONF_H
#ifdef __cplusplus
extern "C" {
#endif
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* ########################## Module Selection ############################## */
/**
* @brief This is the list of modules to be used in the HAL driver
*/
#define HAL_MODULE_ENABLED
#define HAL_ADC_MODULE_ENABLED
#define HAL_COMP_MODULE_ENABLED
/*#define HAL_CORDIC_MODULE_ENABLED */
/*#define HAL_CRC_MODULE_ENABLED */
/*#define HAL_CRYP_MODULE_ENABLED */
#define HAL_DAC_MODULE_ENABLED
#define HAL_FDCAN_MODULE_ENABLED
/*#define HAL_FMAC_MODULE_ENABLED */
/*#define HAL_HRTIM_MODULE_ENABLED */
/*#define HAL_IRDA_MODULE_ENABLED */
/*#define HAL_IWDG_MODULE_ENABLED */
/*#define HAL_I2C_MODULE_ENABLED */
/*#define HAL_I2S_MODULE_ENABLED */
/*#define HAL_LPTIM_MODULE_ENABLED */
/*#define HAL_NAND_MODULE_ENABLED */
/*#define HAL_NOR_MODULE_ENABLED */
#define HAL_OPAMP_MODULE_ENABLED
/*#define HAL_PCD_MODULE_ENABLED */
/*#define HAL_QSPI_MODULE_ENABLED */
/*#define HAL_RNG_MODULE_ENABLED */
#define HAL_RTC_MODULE_ENABLED
/*#define HAL_SAI_MODULE_ENABLED */
/*#define HAL_SMARTCARD_MODULE_ENABLED */
/*#define HAL_SMBUS_MODULE_ENABLED */
/*#define HAL_SPI_MODULE_ENABLED */
/*#define HAL_SRAM_MODULE_ENABLED */
#define HAL_TIM_MODULE_ENABLED
#define HAL_UART_MODULE_ENABLED
/*#define HAL_USART_MODULE_ENABLED */
/*#define HAL_WWDG_MODULE_ENABLED */
#define HAL_GPIO_MODULE_ENABLED
#define HAL_EXTI_MODULE_ENABLED
#define HAL_DMA_MODULE_ENABLED
#define HAL_RCC_MODULE_ENABLED
#define HAL_FLASH_MODULE_ENABLED
#define HAL_PWR_MODULE_ENABLED
#define HAL_CORTEX_MODULE_ENABLED
/* ########################## Register Callbacks selection ############################## */
/**
* @brief This is the list of modules where register callback can be used
*/
#define USE_HAL_ADC_REGISTER_CALLBACKS 0U
#define USE_HAL_COMP_REGISTER_CALLBACKS 0U
#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U
#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U
#define USE_HAL_DAC_REGISTER_CALLBACKS 0U
#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U
#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U
#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U
#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U
#define USE_HAL_I2C_REGISTER_CALLBACKS 0U
#define USE_HAL_I2S_REGISTER_CALLBACKS 0U
#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U
#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U
#define USE_HAL_NAND_REGISTER_CALLBACKS 0U
#define USE_HAL_NOR_REGISTER_CALLBACKS 0U
#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U
#define USE_HAL_PCD_REGISTER_CALLBACKS 0U
#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U
#define USE_HAL_RNG_REGISTER_CALLBACKS 0U
#define USE_HAL_RTC_REGISTER_CALLBACKS 0U
#define USE_HAL_SAI_REGISTER_CALLBACKS 0U
#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U
#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U
#define USE_HAL_SPI_REGISTER_CALLBACKS 0U
#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U
#define USE_HAL_TIM_REGISTER_CALLBACKS 0U
#define USE_HAL_UART_REGISTER_CALLBACKS 0U
#define USE_HAL_USART_REGISTER_CALLBACKS 0U
#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U
/* ########################## Oscillator Values adaptation ####################*/
/**
* @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
* This value is used by the RCC HAL module to compute the system frequency
* (when HSE is used as system clock source, directly or through the PLL).
*/
#if !defined (HSE_VALUE)
#define HSE_VALUE (16000000UL) /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */
#if !defined (HSE_STARTUP_TIMEOUT)
#define HSE_STARTUP_TIMEOUT (100UL) /*!< Time out for HSE start up, in ms */
#endif /* HSE_STARTUP_TIMEOUT */
/**
* @brief Internal High Speed oscillator (HSI) value.
* This value is used by the RCC HAL module to compute the system frequency
* (when HSI is used as system clock source, directly or through the PLL).
*/
#if !defined (HSI_VALUE)
#define HSI_VALUE (16000000UL) /*!< Value of the Internal oscillator in Hz*/
#endif /* HSI_VALUE */
/**
* @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG.
* This internal oscillator is mainly dedicated to provide a high precision clock to
* the USB peripheral by means of a special Clock Recovery System (CRS) circuitry.
* When the CRS is not used, the HSI48 RC oscillator runs on it default frequency
* which is subject to manufacturing process variations.
*/
#if !defined (HSI48_VALUE)
#define HSI48_VALUE (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz.
The real value my vary depending on manufacturing process variations.*/
#endif /* HSI48_VALUE */
/**
* @brief Internal Low Speed oscillator (LSI) value.
*/
#if !defined (LSI_VALUE)
/*!< Value of the Internal Low Speed oscillator in Hz
The real value may vary depending on the variations in voltage and temperature.*/
#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/
#endif /* LSI_VALUE */
/**
* @brief External Low Speed oscillator (LSE) value.
* This value is used by the UART, RTC HAL module to compute the system frequency
*/
#if !defined (LSE_VALUE)
#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */
#endif /* LSE_VALUE */
#if !defined (LSE_STARTUP_TIMEOUT)
#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */
#endif /* LSE_STARTUP_TIMEOUT */
/**
* @brief External clock source for I2S and SAI peripherals
* This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source
* frequency, this source is inserted directly through I2S_CKIN pad.
*/
#if !defined (EXTERNAL_CLOCK_VALUE)
#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator in Hz*/
#endif /* EXTERNAL_CLOCK_VALUE */
/* Tip: To avoid modifying this file each time you need to use different HSE,
=== you can define the HSE value in your toolchain compiler preprocessor. */
/* ########################### System Configuration ######################### */
/**
* @brief This is the HAL system configuration section
*/
#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */
#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */
#define USE_RTOS 0U
#define PREFETCH_ENABLE 0U
#define INSTRUCTION_CACHE_ENABLE 1U
#define DATA_CACHE_ENABLE 1U
/* ########################## Assert Selection ############################## */
/**
* @brief Uncomment the line below to expanse the "assert_param" macro in the
* HAL drivers code
*/
/* #define USE_FULL_ASSERT 1U */
/* ################## SPI peripheral configuration ########################## */
/* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver
* Activated: CRC code is present inside driver
* Deactivated: CRC code cleaned from driver
*/
#define USE_SPI_CRC 0U
/* Includes ------------------------------------------------------------------*/
/**
* @brief Include module's header file
*/
#ifdef HAL_RCC_MODULE_ENABLED
#include "stm32g4xx_hal_rcc.h"
#endif /* HAL_RCC_MODULE_ENABLED */
#ifdef HAL_GPIO_MODULE_ENABLED
#include "stm32g4xx_hal_gpio.h"
#endif /* HAL_GPIO_MODULE_ENABLED */
#ifdef HAL_DMA_MODULE_ENABLED
#include "stm32g4xx_hal_dma.h"
#endif /* HAL_DMA_MODULE_ENABLED */
#ifdef HAL_CORTEX_MODULE_ENABLED
#include "stm32g4xx_hal_cortex.h"
#endif /* HAL_CORTEX_MODULE_ENABLED */
#ifdef HAL_ADC_MODULE_ENABLED
#include "stm32g4xx_hal_adc.h"
#endif /* HAL_ADC_MODULE_ENABLED */
#ifdef HAL_COMP_MODULE_ENABLED
#include "stm32g4xx_hal_comp.h"
#endif /* HAL_COMP_MODULE_ENABLED */
#ifdef HAL_CORDIC_MODULE_ENABLED
#include "stm32g4xx_hal_cordic.h"
#endif /* HAL_CORDIC_MODULE_ENABLED */
#ifdef HAL_CRC_MODULE_ENABLED
#include "stm32g4xx_hal_crc.h"
#endif /* HAL_CRC_MODULE_ENABLED */
#ifdef HAL_CRYP_MODULE_ENABLED
#include "stm32g4xx_hal_cryp.h"
#endif /* HAL_CRYP_MODULE_ENABLED */
#ifdef HAL_DAC_MODULE_ENABLED
#include "stm32g4xx_hal_dac.h"
#endif /* HAL_DAC_MODULE_ENABLED */
#ifdef HAL_EXTI_MODULE_ENABLED
#include "stm32g4xx_hal_exti.h"
#endif /* HAL_EXTI_MODULE_ENABLED */
#ifdef HAL_FDCAN_MODULE_ENABLED
#include "stm32g4xx_hal_fdcan.h"
#endif /* HAL_FDCAN_MODULE_ENABLED */
#ifdef HAL_FLASH_MODULE_ENABLED
#include "stm32g4xx_hal_flash.h"
#endif /* HAL_FLASH_MODULE_ENABLED */
#ifdef HAL_FMAC_MODULE_ENABLED
#include "stm32g4xx_hal_fmac.h"
#endif /* HAL_FMAC_MODULE_ENABLED */
#ifdef HAL_HRTIM_MODULE_ENABLED
#include "stm32g4xx_hal_hrtim.h"
#endif /* HAL_HRTIM_MODULE_ENABLED */
#ifdef HAL_IRDA_MODULE_ENABLED
#include "stm32g4xx_hal_irda.h"
#endif /* HAL_IRDA_MODULE_ENABLED */
#ifdef HAL_IWDG_MODULE_ENABLED
#include "stm32g4xx_hal_iwdg.h"
#endif /* HAL_IWDG_MODULE_ENABLED */
#ifdef HAL_I2C_MODULE_ENABLED
#include "stm32g4xx_hal_i2c.h"
#endif /* HAL_I2C_MODULE_ENABLED */
#ifdef HAL_I2S_MODULE_ENABLED
#include "stm32g4xx_hal_i2s.h"
#endif /* HAL_I2S_MODULE_ENABLED */
#ifdef HAL_LPTIM_MODULE_ENABLED
#include "stm32g4xx_hal_lptim.h"
#endif /* HAL_LPTIM_MODULE_ENABLED */
#ifdef HAL_NAND_MODULE_ENABLED
#include "stm32g4xx_hal_nand.h"
#endif /* HAL_NAND_MODULE_ENABLED */
#ifdef HAL_NOR_MODULE_ENABLED
#include "stm32g4xx_hal_nor.h"
#endif /* HAL_NOR_MODULE_ENABLED */
#ifdef HAL_OPAMP_MODULE_ENABLED
#include "stm32g4xx_hal_opamp.h"
#endif /* HAL_OPAMP_MODULE_ENABLED */
#ifdef HAL_PCD_MODULE_ENABLED
#include "stm32g4xx_hal_pcd.h"
#endif /* HAL_PCD_MODULE_ENABLED */
#ifdef HAL_PWR_MODULE_ENABLED
#include "stm32g4xx_hal_pwr.h"
#endif /* HAL_PWR_MODULE_ENABLED */
#ifdef HAL_QSPI_MODULE_ENABLED
#include "stm32g4xx_hal_qspi.h"
#endif /* HAL_QSPI_MODULE_ENABLED */
#ifdef HAL_RNG_MODULE_ENABLED
#include "stm32g4xx_hal_rng.h"
#endif /* HAL_RNG_MODULE_ENABLED */
#ifdef HAL_RTC_MODULE_ENABLED
#include "stm32g4xx_hal_rtc.h"
#endif /* HAL_RTC_MODULE_ENABLED */
#ifdef HAL_SAI_MODULE_ENABLED
#include "stm32g4xx_hal_sai.h"
#endif /* HAL_SAI_MODULE_ENABLED */
#ifdef HAL_SMARTCARD_MODULE_ENABLED
#include "stm32g4xx_hal_smartcard.h"
#endif /* HAL_SMARTCARD_MODULE_ENABLED */
#ifdef HAL_SMBUS_MODULE_ENABLED
#include "stm32g4xx_hal_smbus.h"
#endif /* HAL_SMBUS_MODULE_ENABLED */
#ifdef HAL_SPI_MODULE_ENABLED
#include "stm32g4xx_hal_spi.h"
#endif /* HAL_SPI_MODULE_ENABLED */
#ifdef HAL_SRAM_MODULE_ENABLED
#include "stm32g4xx_hal_sram.h"
#endif /* HAL_SRAM_MODULE_ENABLED */
#ifdef HAL_TIM_MODULE_ENABLED
#include "stm32g4xx_hal_tim.h"
#endif /* HAL_TIM_MODULE_ENABLED */
#ifdef HAL_UART_MODULE_ENABLED
#include "stm32g4xx_hal_uart.h"
#endif /* HAL_UART_MODULE_ENABLED */
#ifdef HAL_USART_MODULE_ENABLED
#include "stm32g4xx_hal_usart.h"
#endif /* HAL_USART_MODULE_ENABLED */
#ifdef HAL_WWDG_MODULE_ENABLED
#include "stm32g4xx_hal_wwdg.h"
#endif /* HAL_WWDG_MODULE_ENABLED */
/* Exported macro ------------------------------------------------------------*/
#ifdef USE_FULL_ASSERT
/**
* @brief The assert_param macro is used for function's parameters check.
* @param expr: If expr is false, it calls assert_failed function
* which reports the name of the source file and the source
* line number of the call that failed.
* If expr is true, it returns no value.
* @retval None
*/
#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__))
/* Exported functions ------------------------------------------------------- */
void assert_failed(uint8_t *file, uint32_t line);
#else
#define assert_param(expr) ((void)0U)
#endif /* USE_FULL_ASSERT */
#ifdef __cplusplus
}
#endif
#endif /* STM32G4xx_HAL_CONF_H */

75
Core/Inc/stm32g4xx_it.h Normal file
View File

@@ -0,0 +1,75 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32g4xx_it.h
* @brief This file contains the headers of the interrupt handlers.
******************************************************************************
* @attention
*
* Copyright (c) 2025 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32G4xx_IT_H
#define __STM32G4xx_IT_H
#ifdef __cplusplus
extern "C" {
#endif
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
/* USER CODE END EC */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
/* USER CODE END EM */
/* Exported functions prototypes ---------------------------------------------*/
void NMI_Handler(void);
void HardFault_Handler(void);
void MemManage_Handler(void);
void BusFault_Handler(void);
void UsageFault_Handler(void);
void SVC_Handler(void);
void DebugMon_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
void RTC_WKUP_IRQHandler(void);
void DMA1_Channel1_IRQHandler(void);
void DMA1_Channel2_IRQHandler(void);
void FDCAN1_IT0_IRQHandler(void);
void TIM1_BRK_TIM15_IRQHandler(void);
void TIM1_CC_IRQHandler(void);
void TIM2_IRQHandler(void);
void TIM3_IRQHandler(void);
void TIM6_DAC_IRQHandler(void);
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */
#ifdef __cplusplus
}
#endif
#endif /* __STM32G4xx_IT_H */

38
Core/Inc/sync_pulse.h Normal file
View File

@@ -0,0 +1,38 @@
/*
* sync_pulse.h
*
* Created on: Nov 25, 2025
* Author: herli
*/
#ifndef INC_SYNC_PULSE_H_
#define INC_SYNC_PULSE_H_
#include "main.h"
#include "stm32g4xx_hal.h"
// Extern TIM8 handle (generated by CubeMX in tim.c)
extern TIM_HandleTypeDef htim8;
//extern volatile int watchdog_active;
uint8_t SYNC_Pulse_IsSyncoutMode(void);
void SYNC_Pulse_Poll(void);
/**
* @brief Switch PA15 into TIM8_CH1 PWM output mode.
*/
void SYNC_Pulse_EnableTIM8(void);
void SYNC_PULSE_TIM_START(void);
void SYNC_PULSE_TIM_STOP(void);
void SYNC_Pulse_SetCallback(void (*cb)(void));
/**
* @brief Switch PA15 back to GPIO push-pull output for software toggling.
*/
void SYNC_Pulse_EnableGPIO(void);
void SYNC_Pulse_GPIO_set(uint8_t state);
#endif /* INC_SYNC_PULSE_H_ */

37
Core/Inc/tein_detection.h Normal file
View File

@@ -0,0 +1,37 @@
/*
* tein_detection.h
*
* Created on: May 17, 2025
* Author: herli
*/
#ifndef INC_TEIN_DETECTION_H_
#define INC_TEIN_DETECTION_H_
#include <stdint.h>
#define DMA_BUFFER_SIZE_TEIN 127
#define ADC_MID 128
#define AcquisitionTime 2048 //2000us at 20us the sample goes to 100 length
#define samplePeriod 16 //50khz -> 20us 62.5khz ->16
extern uint8_t dma_buffer_tein[DMA_BUFFER_SIZE_TEIN]; // Buffer to hold results
extern float T_ein_filtered;
extern float T_ein_in;
extern float T_ein;
extern int CompensateTein;
extern int ProcessTein;
extern uint32_t TeinProcessedTime;
extern uint32_t lastTeinProcessedTime;
extern uint8_t T_ein_status;
extern uint32_t diff_ConvCallback;
extern volatile uint8_t hasTeinDetEnded;
extern volatile uint8_t hasTeinDetEndedFlag;
extern void ProcessAdcSignal(uint32_t IC_INJ, uint16_t PeakEndIndex, uint16_t T_on);
extern void TEIN_STATUS_ONFAULT(void);
#endif /* INC_TEIN_DETECTION_H_ */

23
Core/Inc/temperature.h Normal file
View File

@@ -0,0 +1,23 @@
/*
* temperature.h
*
* Created on: Aug 4, 2025
* Author: herli
*/
#ifndef INC_TEMPERATURE_H_
#define INC_TEMPERATURE_H_
#include <stdint.h>
#define DMA_SAMPLES_TEMP 5
#define DMA_BUFFER_SIZE 1 * DMA_SAMPLES_TEMP
extern float Temp;
extern uint32_t temp_avg;
extern uint16_t dma_buffer[2 * DMA_BUFFER_SIZE];
extern void process_buffer_Temp(uint16_t *buffer);
#endif /* INC_TEMPERATURE_H_ */

61
Core/Inc/timeouts.h Normal file
View File

@@ -0,0 +1,61 @@
/*
* timeouts.h
*
* Created on: May 29, 2025
* Author: herli
*/
#ifndef INC_TIMEOUTS_H_
#define INC_TIMEOUTS_H_
#include "main.h" // for uint16_t etc.
#include <stdbool.h>
extern uint32_t BitStatus;
extern volatile float RPM;
extern float PHI_AD;
extern float ME;
extern uint8_t forceDC;
extern uint8_t safetySHUTOFF;
extern uint8_t startup;
extern volatile uint8_t startedEngine;
extern uint8_t CKP_PULSE_AVAILABLE;
extern uint8_t captorOK;
extern uint8_t maxTeeth;
typedef void (*TimeoutCallback)(void); // Define a function pointer type
typedef struct {
uint8_t enabled;
uint16_t* last_tick_ptr; // Pointer to externally updated tick
uint16_t timeout_duration; // Timeout in timer ticks (e.g., 500 = 50ms)
uint32_t* status_bit_ptr; // Pointer to byte holding status flag
uint16_t bit_mask; // Bit mask to set if timeout occurred
uint8_t inverted;
TimeoutCallback on_timeout; // Callback function (can be NULL)
uint8_t started;
} TimeoutEntry;
uint8_t has_timed_out(uint16_t start, uint16_t duration);
void CheckTimeouts(uint16_t current_time, TimeoutEntry* timeouts);
void Timeout_Reset(uint16_t* tick_ptr, uint16_t new_tick, uint16_t* status_ptr, uint16_t bit_mask);
void Timeout_ResetByIndex(uint8_t index, uint16_t new_tick);
void Timeout_ResetByIndexNoStatus(uint8_t index, uint16_t new_tick);
void Set_Timeout_Period_ByIndex(uint8_t index, uint16_t period);
bool Timeout_IsStarted(uint8_t index);
extern void Timeout_StartIfStopped(uint8_t index, uint16_t now);
bool Timeout_HasElapsed(uint8_t index, uint16_t now); // uses entrys own duration
void Timeout_StopByIndex(uint8_t index);
uint16_t* Timeout_GetCanTickPtr(void);
uint16_t* Timeout_GetIcRPMTickPtr(void);
uint16_t* Timeout_GetTurnOffTickPtr(void);
void Timeout_CheckAll(uint16_t current_time); // shortcut
void Timeout_PollActions(void);
#endif /* INC_TIMEOUTS_H_ */

62
Core/Inc/timing_manager.h Normal file
View File

@@ -0,0 +1,62 @@
/*
* timing_manager.h
*
* Created on: Oct 3, 2025
* Author: herli
*/
#ifndef INC_TIMING_MANAGER_H_
#define INC_TIMING_MANAGER_H_
#include "stdint.h"
#include "id.h"
extern float refClock;
static inline uint8_t TM_GET_IN_BUFFER_ID(uint32_t C);
typedef struct {
uint32_t ic; // TIM2->CNT capture
float rpm; // instantaneous rpm estimated for this edge's interval
float accel;
uint8_t isInj;
uint8_t new;
} EdgeSample;
extern volatile EdgeSample edgeBuf[TW_PERCYL_TEETH+1];
extern void UpdateEdgeBuffer(uint32_t tickNew, float rpm_est, uint8_t tooth, uint8_t isInj);
extern void ClearEdgeBuffer();
//extern uint8_t TM_GET_IN_BUFFER_ID(uint32_t C);
extern float TM_TIME_FROM_NEAREST_TOOTH(uint32_t C_Ticks, uint8_t fw);
extern float TM_GET_REAL_BIP_ANGLE(uint32_t C_Ticks);
extern float TM_INTEGRATE_ANGLE_FROM_NEAREST_TOOTH(uint32_t C_Ticks, uint8_t fw);
extern float INTEGRATE_ANGLE_FROM_REFERENCE(float time, float reference, uint8_t fw);
extern float TM_INTEGRATE_ANGLE_FROM_REFERENCE(uint32_t C_Ticks, float refAngle, uint8_t fw);
extern float TM_INTEGRATE_TIME_FROM_REFERENCE(float C_Angle, uint8_t teeth_f);
extern float TM_INTEGRATE_TIME_FROM_REFERENCE_PREDICTIVE(float C_Angle, uint8_t teeth_f);
extern float TM_INTEGRATE_TIME_BIP(float C_Angle, uint8_t teeth_i);
extern float TM_INTEGRATE_TIME_BIP_PREDICTIVE(float C_Angle, uint8_t teeth_i);
extern float TM_GET_PHIAD_dTEIN(float EOI_Angle, float MT_RPM);
extern float TM_INTEGRATE_TIME_TO_EOI(float C_Angle, uint8_t teeth_i);
extern float TM_INTEGRATE_TIME_FROM_REFERENCE_Forward(float C_Angle, uint8_t teeth_i, float InitInj);
extern float TM_GET_LOCAL_ACC_TO_ANGLE(float C_Angle, uint8_t roundingMode);
extern float TM_GET_RPM_FROM_NEAREST_TOOTH(uint32_t C_Ticks, uint8_t fw);
extern uint8_t TM_GET_TRIGGER_TEETH_FROM_REFERENCE_AND_TIME(float C_Angle, float time);
extern float TM_UPDATE_ACCELERATION(float last_MT_RPM, float now_MT_RPM, uint32_t dt_mt);
extern float TM_GET_ACCEL_CORRECTION(float last_MT_RPM, float now_MT_RPM, float TEETH_RPM, uint8_t triggerTeeth);
extern float TM_GET_INJ_ACCEL(uint8_t currentTooth);
extern float TM_UPDATE_ACCEL_CORRECTION_BIP(float last_MT_RPM, float now_MT_RPM, float TEETH_RPM);
extern uint16_t TM_GET_T_DELAY_END();
extern void TM_UPDATE_INJECTION_RPM_AND_ALPHA(float EOI_angle, float BIP_angle, uint32_t IC_EOI, uint32_t IC_BIP);
#endif /* INC_TIMING_MANAGER_H_ */

49
Core/Inc/toothed_wheel.h Normal file
View File

@@ -0,0 +1,49 @@
/*
* toothedwheel.h
*
* Created on: Aug 4, 2025
* Author: herli
*/
#ifndef INC_TOOTHED_WHEEL_H_
#define INC_TOOTHED_WHEEL_H_
#include <id.h>
#include "stdint.h"
extern volatile uint32_t IC_RPM_Val1;
extern volatile uint32_t IC_RPM_Val2;
extern volatile uint32_t IC_EOI;
extern volatile uint8_t currentTooth;
extern volatile uint32_t IC_INJ;
extern float refClock;
extern float toothAlpha;
extern volatile float TEETH_RPM;
extern volatile float MT_RPM;
extern volatile float last_MT_RPM;
extern volatile float RPM;
extern uint8_t blankInj;
extern volatile uint8_t TW_RPM_SENSOR_STATE;
/*typedef struct {
uint32_t ic; // TIM2->CNT capture
float rpm; // instantaneous rpm estimated for this edge's interval
} EdgeSample;
extern volatile EdgeSample edgeBuf[TW_PERCYL_TEETH+1];*/
extern float correction_beta;
extern float correction_eoi;
extern float nominal_boi_angle;
extern void TW_RESET_SENSOR();
extern void TW_EVAL_MAX_TEETH();
extern void TW_DEFER_BOI_EVAL(uint32_t ic);
extern void TW_DEFER_EOI_EVAL(uint32_t ic);
extern void TW_Service();
float fclamp(float value, float min, float max);
#endif /* INC_TOOTHED_WHEEL_H_ */