Subversion Repositories EDIS_Ignition

Rev

Rev 17 | Rev 19 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 17 Rev 18
Line 21... Line 21...
21
 
21
 
22
/* Private includes ----------------------------------------------------------*/
22
/* Private includes ----------------------------------------------------------*/
23
/* USER CODE BEGIN Includes */
23
/* USER CODE BEGIN Includes */
24
#include "memory.h"
24
#include "memory.h"
25
#include "display.h"
25
#include "display.h"
26
#include "bmp280driver.h"
26
#include "bmp280driver.h" 
27
#include "libMisc/fixI2C.h"
27
#include "libMisc/fixI2C.h"
28
#include "libPlx/plx.h"
28
#include "libPlx/plx.h"
29
#include "libSerial/serial.h"
29
#include "libSerial/serial.h"
30
#include "libIgnTiming/timing.h"
30
#include "libIgnTiming/timing.h"
31
#include "libIgnTiming/edis.h"
31
#include "libIgnTiming/edis.h"
-
 
32
#include "libIgnTiming/rpm.h"
32
#include "saveTiming.h"
33
#include "saveTiming.h"
33
#include "libPLX/commsLib.h"
34
#include "libPLX/commsLib.h"
34
/* USER CODE END Includes */
35
/* USER CODE END Includes */
35
 
36
 
36
/* Private typedef -----------------------------------------------------------*/
37
/* Private typedef -----------------------------------------------------------*/
Line 71... Line 72...
71
// compensated temperature
72
// compensated temperature
72
int32_t comp_temp = -10000;
73
int32_t comp_temp = -10000;
73
 
74
 
74
int32_t timing = 0;
75
int32_t timing = 0;
75
 
76
 
76
// 6 degrees error in timing wheel this time .. 
77
// 6 degrees error in timing wheel this time ..
77
int const TIMING_OFFSET = -6 * TIMING_SCALE;
78
int const TIMING_OFFSET = -6 * TIMING_SCALE;
-
 
79
 
-
 
80
// default atmospheric pressure
-
 
81
uint32_t const DEFAULT_ATMOSPHERIC_PRESSURE = 1014 * 100;
-
 
82
 
-
 
83
uint32_t const DEFAULT_ATMOSPHERIC_TEMPERATURE = 25 * 100;
78
/* USER CODE END PV */
84
/* USER CODE END PV */
79
 
85
 
80
/* Private function prototypes -----------------------------------------------*/
86
/* Private function prototypes -----------------------------------------------*/
81
void SystemClock_Config(void);
87
void SystemClock_Config(void);
82
static void MX_GPIO_Init(void);
88
static void MX_GPIO_Init(void);
Line 88... Line 94...
88
static void MX_USART2_UART_Init(void);
94
static void MX_USART2_UART_Init(void);
89
static void MX_TIM3_Init(void);
95
static void MX_TIM3_Init(void);
90
static void MX_IWDG_Init(void);
96
static void MX_IWDG_Init(void);
91
/* USER CODE BEGIN PFP */
97
/* USER CODE BEGIN PFP */
92
 
98
 
93
// send a PLX_SensorInfo structure to the usart.
-
 
94
void sendInfo(usart_ctl *uc, PLX_SensorInfo *info)
-
 
95
{
-
 
96
  for (int i = 0; i < sizeof(PLX_SensorInfo); ++i)
-
 
97
    PutCharSerial(uc, info->bytes[i]);
-
 
98
}
-
 
99
 
-
 
100
 
99
 
101
void libPLXcallbackSendUserData()
100
void libPLXcallbackSendUserData()
102
{
101
{
103
  // send MAP
102
  // send MAP
104
  PLX_SensorInfo info;
103
  PLX_SensorInfo info;
Line 197... Line 196...
197
  uint32_t displayOff = lastTick + 10000;
196
  uint32_t displayOff = lastTick + 10000;
198
  uint32_t displayReinitialise = lastTick + DISPLAY_REINITIALISE; // every minute, reinitialise display because of risk of noise
197
  uint32_t displayReinitialise = lastTick + DISPLAY_REINITIALISE; // every minute, reinitialise display because of risk of noise
199
 
198
 
200
  uint8_t intensity = 2;
199
  uint8_t intensity = 2;
201
 
200
 
202
 
-
 
203
  ResetRxBuffer(&uc2);
201
  ResetRxBuffer(&uc2);
204
 
202
 
205
  resetPLX();
203
  resetPLX();
206
 
204
 
207
  // HAL_IWDG_Init(&hiwdg);
205
  // HAL_IWDG_Init(&hiwdg);
Line 252... Line 250...
252
      lastTick = HAL_GetTick();
250
      lastTick = HAL_GetTick();
253
      /* Reading the raw data from sensor */
251
      /* Reading the raw data from sensor */
254
      struct bmp280_uncomp_data ucomp_data;
252
      struct bmp280_uncomp_data ucomp_data;
255
      uint8_t rslt = bmp280_get_uncomp_data(&ucomp_data, &bmp);
253
      uint8_t rslt = bmp280_get_uncomp_data(&ucomp_data, &bmp);
256
 
254
 
-
 
255
      uint8_t rslt2 = 1;
-
 
256
      uint8_t rslt3 = 1;
-
 
257
 
257
      if (rslt == 0)
258
      if (rslt == 0)
258
      {
259
      {
259
        uint8_t rslt2 = bmp280_get_comp_pres_32bit(&comp_pres, ucomp_data.uncomp_press, &bmp);
260
        rslt2 = bmp280_get_comp_pres_32bit(&comp_pres, ucomp_data.uncomp_press, &bmp);
260
 
261
 
261
        uint8_t rslt3 = bmp280_get_comp_temp_32bit(&comp_temp, ucomp_data.uncomp_temp, &bmp);
262
        rslt3 = bmp280_get_comp_temp_32bit(&comp_temp, ucomp_data.uncomp_temp, &bmp);
262
 
263
 
263
#if defined TEST_CODE
264
#if defined TEST_CODE
264
        comp_pres = 100000;
265
        comp_pres = 100000;
265
        comp_temp = 4000;
266
        comp_temp = 4000;
266
#endif
267
#endif
267
        if (rslt2 == 0 && rslt3 == 0)
-
 
268
          cc_feed_env(comp_pres, comp_temp);
-
 
269
      }
268
      }
-
 
269
      // if the BMP280 pressure is good, then allow it through, otherwise drop to
-
 
270
      // centrifugal advance only.
-
 
271
      if (rslt == BMP280_OK && rslt2 == BMP280_OK && rslt3 == BMP280_OK)
-
 
272
        cc_feed_env(comp_pres, comp_temp);
-
 
273
      else
-
 
274
        cc_feed_env(DEFAULT_ATMOSPHERIC_PRESSURE, DEFAULT_ATMOSPHERIC_TEMPERATURE);
270
 
275
 
271
      // compute RPM value, feed to display
276
        // compute RPM value, feed to display
272
#if defined TEST_CODE
277
#if defined TEST_CODE
273
      int rpm = 1000;
278
      int rpm = 1000;
274
#else
279
#else
275
      int rpm = CalculateRPM();
280
      int rpm = CalculateRPM();
276
#endif
281
#endif
277
      if (rpm > 0)
282
      if (rpm > 0)
278
      {
283
      {
279
        cc_feed_rpm(rpm);
284
        cc_feed_rpm(rpm);
280
        // compute timing value, feed to display
285
        // compute timing value, feed to display
281
        timing = mapTiming(rpm, 1000 - comp_pres / 100);
286
        timing = mapTiming(rpm, 1000 - comp_pres / 100);
282
        cc_feed_timing(timing );
287
        cc_feed_timing(timing);
283
        int microsecs = mapTimingToMicroseconds(timing + TIMING_OFFSET, 0);
288
        int microsecs = mapTimingToMicroseconds(timing + TIMING_OFFSET, 0);
284
        __HAL_TIM_SET_AUTORELOAD(&htim1, microsecs + SAW_DELAY);
289
        __HAL_TIM_SET_AUTORELOAD(&htim1, microsecs + SAW_DELAY);
285
      }
290
      }
286
    }
291
    }
287
 
292
 
288
   
-
 
289
    // Handle PLX
293
    // Handle PLX
290
    libPLXpollData(&uc2);
294
    libPLXpollData(&uc2);
291
 
295
 
292
    /* USER CODE END WHILE */
296
    /* USER CODE END WHILE */
293
 
297
 
294
    /* USER CODE BEGIN 3 */
298
    /* USER CODE BEGIN 3 */
295
    watchdogWrite();
299
    watchdogWrite();
296
 
300
 
-
 
301
    HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
-
 
302
 
297
    // todo occasionally     saveTimingInfoToNvram();
303
    // todo occasionally     saveTimingInfoToNvram();
298
  }
304
  }
299
  /* USER CODE END 3 */
305
  /* USER CODE END 3 */
300
}
306
}
301
 
307
 
Line 694... Line 700...
694
 * @retval None
700
 * @retval None
695
 */
701
 */
696
static void MX_GPIO_Init(void)
702
static void MX_GPIO_Init(void)
697
{
703
{
698
  GPIO_InitTypeDef GPIO_InitStruct = {0};
704
  GPIO_InitTypeDef GPIO_InitStruct = {0};
-
 
705
  /* USER CODE BEGIN MX_GPIO_Init_1 */
-
 
706
  /* USER CODE END MX_GPIO_Init_1 */
699
 
707
 
700
  /* GPIO Ports Clock Enable */
708
  /* GPIO Ports Clock Enable */
-
 
709
  __HAL_RCC_GPIOC_CLK_ENABLE();
701
  __HAL_RCC_GPIOD_CLK_ENABLE();
710
  __HAL_RCC_GPIOD_CLK_ENABLE();
702
  __HAL_RCC_GPIOA_CLK_ENABLE();
711
  __HAL_RCC_GPIOA_CLK_ENABLE();
703
  __HAL_RCC_GPIOB_CLK_ENABLE();
712
  __HAL_RCC_GPIOB_CLK_ENABLE();
704
 
713
 
705
  /*Configure GPIO pin Output Level */
714
  /*Configure GPIO pin Output Level */
-
 
715
  HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);
-
 
716
 
-
 
717
  /*Configure GPIO pin Output Level */
706
  HAL_GPIO_WritePin(GPIOA, SPI1_NSS_Pin | SPI1_RESET_Pin, GPIO_PIN_RESET);
718
  HAL_GPIO_WritePin(GPIOA, SPI1_NSS_Pin | SPI1_RESET_Pin, GPIO_PIN_RESET);
707
 
719
 
708
  /*Configure GPIO pin Output Level */
720
  /*Configure GPIO pin Output Level */
709
  HAL_GPIO_WritePin(SPI1_CD_GPIO_Port, SPI1_CD_Pin, GPIO_PIN_RESET);
721
  HAL_GPIO_WritePin(SPI1_CD_GPIO_Port, SPI1_CD_Pin, GPIO_PIN_RESET);
710
 
722
 
-
 
723
  /*Configure GPIO pin : LED_Pin */
-
 
724
  GPIO_InitStruct.Pin = LED_Pin;
-
 
725
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
-
 
726
  GPIO_InitStruct.Pull = GPIO_NOPULL;
-
 
727
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
-
 
728
  HAL_GPIO_Init(LED_GPIO_Port, &GPIO_InitStruct);
-
 
729
 
711
  /*Configure GPIO pins : SPI1_NSS_Pin SPI1_RESET_Pin */
730
  /*Configure GPIO pins : SPI1_NSS_Pin SPI1_RESET_Pin */
712
  GPIO_InitStruct.Pin = SPI1_NSS_Pin | SPI1_RESET_Pin;
731
  GPIO_InitStruct.Pin = SPI1_NSS_Pin | SPI1_RESET_Pin;
713
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
732
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
714
  GPIO_InitStruct.Pull = GPIO_NOPULL;
733
  GPIO_InitStruct.Pull = GPIO_NOPULL;
715
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
734
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
Line 731... Line 750...
731
  /*Configure GPIO pin : dualSpark_Pin */
750
  /*Configure GPIO pin : dualSpark_Pin */
732
  GPIO_InitStruct.Pin = dualSpark_Pin;
751
  GPIO_InitStruct.Pin = dualSpark_Pin;
733
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
752
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
734
  GPIO_InitStruct.Pull = GPIO_PULLUP;
753
  GPIO_InitStruct.Pull = GPIO_PULLUP;
735
  HAL_GPIO_Init(dualSpark_GPIO_Port, &GPIO_InitStruct);
754
  HAL_GPIO_Init(dualSpark_GPIO_Port, &GPIO_InitStruct);
-
 
755
 
-
 
756
  /* USER CODE BEGIN MX_GPIO_Init_2 */
-
 
757
  /* USER CODE END MX_GPIO_Init_2 */
736
}
758
}
737
 
759
 
738
/* USER CODE BEGIN 4 */
760
/* USER CODE BEGIN 4 */
739
 
761
 
740
/* USER CODE END 4 */
762
/* USER CODE END 4 */