fome-fw/firmware/controllers/system/pwm_generator_logic.h

100 lines
2.1 KiB
C
Raw Normal View History

2014-08-29 07:52:33 -07:00
/**
* @file pwm_generator_logic.h
*
* @date Mar 2, 2014
* @author Andrey Belomutskiy, (c) 2012-2014
*/
#ifndef PWM_GENERATOR_LOGIC_H_
#define PWM_GENERATOR_LOGIC_H_
#include "global.h"
#include "EfiWave.h"
#include "io_pins.h"
#include "scheduler.h"
2015-01-07 16:03:45 -08:00
#include "efiGpio.h"
2014-08-29 07:52:33 -07:00
typedef struct {
/**
* a copy so that all phases are executed on the same period, even if another thread
* would be adjusting PWM parameters
*/
2014-09-12 21:02:43 -07:00
float periodNt;
2014-08-29 07:52:33 -07:00
/**
* Iteration counter
*/
int iteration;
/**
* Start time of current iteration
*/
2014-09-12 20:04:25 -07:00
uint64_t startNt;
2014-08-29 07:52:33 -07:00
int phaseIndex;
} pwm_config_safe_state_s;
class PwmConfig;
typedef void (pwm_cycle_callback)(PwmConfig *state);
typedef void (pwm_gen_callback)(PwmConfig *state, int stateIndex);
/**
* @brief Multi-channel software PWM output configuration
*/
class PwmConfig {
public:
PwmConfig();
PwmConfig(float *switchTimes, single_wave_s *waves);
void init(float *switchTimes, single_wave_s *waves);
2015-01-08 07:03:44 -08:00
void weComplexInit(const char *msg,
int phaseCount, float *swithcTimes, int waveCount, int **pinStates,
pwm_cycle_callback *cycleCallback,
pwm_gen_callback *callback);
2014-08-29 07:52:33 -07:00
void handleCycleStart();
2015-01-07 16:03:45 -08:00
OutputPin *outputPins[PWM_PHASE_MAX_WAVE_PER_PWM];
2014-08-29 07:52:33 -07:00
multi_wave_s multiWave;
const char *name;
/**
* float value of PWM period
* PWM generation is not happening while this value is zero
*/
2014-09-12 21:02:43 -07:00
float periodNt;
2014-08-29 07:52:33 -07:00
scheduling_s scheduling;
pwm_config_safe_state_s safe;
/**
* Number of events in the cycle
*/
int phaseCount;
/**
* this callback is invoked before each wave generation cycle
*/
pwm_cycle_callback *cycleCallback;
/**
* this main callback is invoked when it's time to switch level on amy of the output channels
*/
pwm_gen_callback *stateChangeCallback;
};
class SimplePwm : public PwmConfig {
public:
SimplePwm();
void setSimplePwmDutyCycle(float dutyCycle);
int pinStates[2];
single_wave_s wave;
single_wave_s sr[1];
float _switchTimes[2];
};
void copyPwmParameters(PwmConfig *state, int phaseCount, float *switchTimes,
int waveCount, int **pinStates);
#endif /* PWM_GENERATOR_LOGIC_H_ */