Rev 18 | Rev 20 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 18 | Rev 19 | ||
---|---|---|---|
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" |
Line 75... | Line 75... | ||
75 | int32_t timing = 0; |
75 | int32_t timing = 0; |
76 | 76 | ||
77 | // 6 degrees error in timing wheel this time .. |
77 | // 6 degrees error in timing wheel this time .. |
78 | int const TIMING_OFFSET = -6 * TIMING_SCALE; |
78 | int const TIMING_OFFSET = -6 * TIMING_SCALE; |
79 | 79 | ||
- | 80 | // Switch over to double sparking |
|
- | 81 | int const DOUBLE_SPARK_RPM = 1200; |
|
80 | // default atmospheric pressure |
82 | // default atmospheric pressure |
81 | uint32_t const DEFAULT_ATMOSPHERIC_PRESSURE = 1014 * 100; |
83 | uint32_t const DEFAULT_ATMOSPHERIC_PRESSURE = 1014 * 100; |
82 | 84 | ||
83 | uint32_t const DEFAULT_ATMOSPHERIC_TEMPERATURE = 25 * 100; |
85 | uint32_t const DEFAULT_ATMOSPHERIC_TEMPERATURE = 25 * 100; |
- | 86 | ||
- | 87 | // Serial buffers |
|
- | 88 | #define TX_BUFFER_SIZE 128 |
|
- | 89 | #define RX_BUFFER_SIZE 128 |
|
- | 90 | unsigned volatile char tx_buffer[TX_BUFFER_SIZE]; |
|
- | 91 | unsigned volatile char rx_buffer[RX_BUFFER_SIZE]; |
|
- | 92 | ||
84 | /* USER CODE END PV */ |
93 | /* USER CODE END PV */ |
85 | 94 | ||
86 | /* Private function prototypes -----------------------------------------------*/ |
95 | /* Private function prototypes -----------------------------------------------*/ |
87 | void SystemClock_Config(void); |
96 | void SystemClock_Config(void); |
88 | static void MX_GPIO_Init(void); |
97 | static void MX_GPIO_Init(void); |
Line 94... | Line 103... | ||
94 | static void MX_USART2_UART_Init(void); |
103 | static void MX_USART2_UART_Init(void); |
95 | static void MX_TIM3_Init(void); |
104 | static void MX_TIM3_Init(void); |
96 | static void MX_IWDG_Init(void); |
105 | static void MX_IWDG_Init(void); |
97 | /* USER CODE BEGIN PFP */ |
106 | /* USER CODE BEGIN PFP */ |
98 | 107 | ||
- | 108 | void libPLXcallbackRecievedData(PLX_SensorInfo * info) |
|
- | 109 | { (void)info; } |
|
99 | 110 | ||
100 | void libPLXcallbackSendUserData() |
111 | void libPLXcallbackSendUserData() |
101 | { |
112 | { |
102 | // send MAP |
113 | // send MAP |
103 | PLX_SensorInfo info; |
114 | PLX_SensorInfo info; |
Line 166... | Line 177... | ||
166 | MX_USART2_UART_Init(); |
177 | MX_USART2_UART_Init(); |
167 | MX_TIM3_Init(); |
178 | MX_TIM3_Init(); |
168 | MX_IWDG_Init(); |
179 | MX_IWDG_Init(); |
169 | /* USER CODE BEGIN 2 */ |
180 | /* USER CODE BEGIN 2 */ |
170 | 181 | ||
171 | init_usart_ctl(&uc2, &huart2); |
182 | init_usart_ctl(&uc2, &huart2, tx_buffer, |
- | 183 | rx_buffer, |
|
- | 184 | TX_BUFFER_SIZE, |
|
- | 185 | RX_BUFFER_SIZE); |
|
172 | 186 | ||
173 | cc_init(); |
187 | cc_init(); |
174 | 188 | ||
175 | HAL_TIM_Base_MspInit(&htim1); |
189 | HAL_TIM_Base_MspInit(&htim1); |
176 | 190 | ||
Line 186... | Line 200... | ||
186 | // Start the input capture and the falling edge interrupt |
200 | // Start the input capture and the falling edge interrupt |
187 | HAL_TIM_IC_Start_IT(&htim2, TIM_CHANNEL_2); |
201 | HAL_TIM_IC_Start_IT(&htim2, TIM_CHANNEL_2); |
188 | 202 | ||
189 | __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 5); // delay of 5 uS |
203 | __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 5); // delay of 5 uS |
190 | 204 | ||
191 | HAL_I2C_ClearBusyFlagErrata_2_14_7(&hi2c1); |
205 | // HAL_I2C_ClearBusyFlagErrata_2_14_7(&hi2c1); |
192 | MX_I2C1_Init(); |
206 | MX_I2C1_Init(); |
193 | init_bmp(&hi2c1); |
207 | init_bmp(&hi2c1); |
194 | uint32_t lastTick = HAL_GetTick(); |
208 | uint32_t lastTick = HAL_GetTick(); |
195 | 209 | ||
196 | uint32_t displayOff = lastTick + 10000; |
210 | uint32_t displayOff = lastTick + 10000; |
Line 283... | Line 297... | ||
283 | { |
297 | { |
284 | cc_feed_rpm(rpm); |
298 | cc_feed_rpm(rpm); |
285 | // compute timing value, feed to display |
299 | // compute timing value, feed to display |
286 | timing = mapTiming(rpm, 1000 - comp_pres / 100); |
300 | timing = mapTiming(rpm, 1000 - comp_pres / 100); |
287 | cc_feed_timing(timing); |
301 | cc_feed_timing(timing); |
- | 302 | // enable double spark below 1200 rpm |
|
288 | int microsecs = mapTimingToMicroseconds(timing + TIMING_OFFSET, 0); |
303 | int microsecs = mapTimingToMicroseconds(timing + TIMING_OFFSET, rpm > DOUBLE_SPARK_RPM); |
289 | __HAL_TIM_SET_AUTORELOAD(&htim1, microsecs + SAW_DELAY); |
304 | __HAL_TIM_SET_AUTORELOAD(&htim1, microsecs + SAW_DELAY); |
290 | } |
305 | } |
291 | } |
306 | } |
292 | 307 | ||
293 | // Handle PLX |
308 | // Handle PLX |