rusefi-1/firmware/controllers/core/efi_wave.h

90 lines
2.7 KiB
C
Raw Normal View History

2015-07-10 06:01:56 -07:00
/**
2019-03-29 06:11:13 -07:00
* @file efi_wave.h
2015-07-10 06:01:56 -07:00
*
* @date May 18, 2014
2017-01-03 03:05:22 -08:00
* @author Andrey Belomutskiy, (c) 2012-2017
2015-07-10 06:01:56 -07:00
*/
#ifndef EFI_WAVE_H_
#define EFI_WAVE_H_
2018-12-24 19:40:48 -08:00
#include "global.h"
2015-07-10 06:01:56 -07:00
2019-03-29 07:37:33 -07:00
/**
* This layer has two primary usages:
* 1) 'simple' PWM generation is used to produce actuator square control wave
* 2) 'complex' PWM generation is used for trigger simulator.
* Some triggers like Nissan 360 slot optical wheel need a lot of points to describe the shape of the wave.
2019-03-29 07:49:56 -07:00
* Looks like 252 is explained by 60 tooth * 2 (number of fronts) * 2 (number of crank rotations within engine cycle)
2019-03-29 07:37:33 -07:00
*/
#ifndef PWM_PHASE_MAX_COUNT
2015-07-10 06:01:56 -07:00
#define PWM_PHASE_MAX_COUNT 252
#endif /* PWM_PHASE_MAX_COUNT */
2015-07-10 06:01:56 -07:00
#define PWM_PHASE_MAX_WAVE_PER_PWM 3
/**
* int8_t is probably less efficient then int32_t but we need
* to reduce memory footprint
*
2017-01-02 11:03:17 -08:00
* todo: migrate to bit-array to save memory?
* this would cost some CPU cycles. see std::vector<bool>
2015-07-10 06:01:56 -07:00
*/
2019-02-02 22:27:47 -08:00
typedef trigger_value_e pin_state_t;
2015-07-10 06:01:56 -07:00
/**
2018-12-24 19:40:48 -08:00
* This class represents one channel of a digital signal state sequence
* Each element represents either a HIGH or LOW state - while at the moment this
* is not implemented using a bit array, it could absolutely be a bit array
*
* This sequence does not know anything about signal lengths - only signal state at a given index
*
2015-07-10 06:01:56 -07:00
* @brief PWM configuration for the specific output pin
*/
2018-12-25 05:27:52 -08:00
class SingleWave {
2015-07-10 06:01:56 -07:00
public:
2018-12-25 05:27:52 -08:00
SingleWave();
explicit SingleWave(pin_state_t *pinStates);
2015-07-10 06:01:56 -07:00
void init(pin_state_t *pinStates);
2018-12-24 19:40:48 -08:00
/**
* todo: confirm that we only deal with two states here, no magic '-1'?
* @return HIGH or LOW state at given index
*/
pin_state_t getState(int switchIndex) const;
2019-02-02 22:19:16 -08:00
void setState(int switchIndex, pin_state_t state);
2018-12-24 19:40:48 -08:00
2018-12-24 19:57:36 -08:00
// todo: make this private by using 'getState' and 'setState' methods
2015-07-10 06:01:56 -07:00
pin_state_t *pinStates;
};
2018-12-24 19:57:36 -08:00
/**
* This class represents multi-channel logical signals with shared time axis
*
*/
2018-12-08 13:59:16 -08:00
class MultiWave {
2015-07-10 06:01:56 -07:00
public:
2018-12-08 13:59:16 -08:00
MultiWave();
2018-12-25 05:27:52 -08:00
MultiWave(float *switchTimes, SingleWave *waves);
void init(float *switchTimes, SingleWave *waves);
2015-07-10 06:01:56 -07:00
void reset(void);
2019-03-02 19:54:28 -08:00
float getSwitchTime(const int phaseIndex) const;
void setSwitchTime(const int phaseIndex, const float value);
void checkSwitchTimes(const int size);
pin_state_t getChannelState(const int channelIndex, const int phaseIndex) const;
2015-07-10 06:01:56 -07:00
2019-03-02 19:54:28 -08:00
int findAngleMatch(const float angle, const int size) const;
int findInsertionAngle(const float angle, const int size) const;
2015-07-10 06:01:56 -07:00
/**
2018-12-25 07:13:00 -08:00
* Number of signal channels
2015-07-10 06:01:56 -07:00
*/
int waveCount;
2019-10-07 22:26:35 -07:00
SingleWave *channels = nullptr;
2015-07-10 06:01:56 -07:00
//private:
/**
* values in the (0..1] range which refer to points within the period at at which pin state should be changed
* So, in the simplest case we turn pin off at 0.3 and turn it on at 1 - that would give us a 70% duty cycle PWM
*/
2019-10-07 22:26:35 -07:00
float *switchTimes = nullptr;
2015-07-10 06:01:56 -07:00
};
#endif /* EFI_WAVE_H_ */