Broken spark implementation
This commit is contained in:
@@ -11,9 +11,13 @@
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "global_state.h"
|
||||
#include "macros.h"
|
||||
#include "ring_buffer.h"
|
||||
#include "stm32h7xx_hal_tim.h"
|
||||
#include "tasks.h"
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#ifdef DEBUG
|
||||
#include "SEGGER_RTT.h"
|
||||
#endif
|
||||
@@ -101,6 +105,25 @@ extern void camHandler(void *argument);
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim) {
|
||||
if (htim->Instance == TIM2 && htim->Channel == HAL_TIM_ACTIVE_CHANNEL_3) {
|
||||
if (state_g.next_spark_state == SPARK_IDLE &&
|
||||
state_g.current_spark_state == SPARK_CHARGING) {
|
||||
DEBUG_LOG("Releasing spark");
|
||||
} else if (state_g.next_spark_state == SPARK_CHARGING &&
|
||||
state_g.current_spark_state == SPARK_IDLE) {
|
||||
DEBUG_LOG("Charging spark");
|
||||
osThreadFlagsSet(crankTaskHandle, 0x02);
|
||||
}
|
||||
|
||||
if (state_g.next_spark_state != SPARK_NONE) {
|
||||
state_g.current_spark_state = state_g.next_spark_state;
|
||||
state_g.next_spark_state = SPARK_NONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim) {
|
||||
if (htim->Instance == TIM2) {
|
||||
switch (htim->Channel) {
|
||||
@@ -164,6 +187,8 @@ int main(void)
|
||||
state_g.crank_state = CYCLE_UNKNOWN;
|
||||
state_g.cam_state = CAM_IDLE;
|
||||
state_g.cam_miss_ctr = 0;
|
||||
state_g.next_spark_state = SPARK_NONE;
|
||||
state_g.current_spark_state = SPARK_IDLE;
|
||||
/* USER CODE END Init */
|
||||
|
||||
/* Configure the system clock */
|
||||
@@ -377,7 +402,7 @@ static void MX_TIM2_Init(void)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
sConfigOC.OCMode = TIM_OCMODE_FORCED_INACTIVE;
|
||||
sConfigOC.OCMode = TIM_OCMODE_TOGGLE;
|
||||
sConfigOC.Pulse = 0;
|
||||
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
||||
|
||||
Reference in New Issue
Block a user