Mercurial > public > ostc4
comparison Discovery/Src/tCCR.c @ 323:b43fa6a6c85a
Merged in Ideenmodellierer/ostc4/O2_SensorSync (pull request #28)
O2 SensorSync
author | heinrichsweikamp <bitbucket@heinrichsweikamp.com> |
---|---|
date | Sun, 30 Jun 2019 19:52:46 +0000 |
parents | 31e471d60797 |
children | f1257a32f2d4 |
comparison
equal
deleted
inserted
replaced
320:117a7ec23385 | 323:b43fa6a6c85a |
---|---|
44 uint8_t temp1; | 44 uint8_t temp1; |
45 uint16_t battery_voltage_mV; | 45 uint16_t battery_voltage_mV; |
46 uint16_t checksum; | 46 uint16_t checksum; |
47 } SIrLink; | 47 } SIrLink; |
48 | 48 |
49 #define HUD_BABBLING_IDIOT (30u) /* 30 Bytes received without break */ | |
50 #define HUD_RX_FRAME_LENGTH (15u) /* Length of a HUD data frame */ | |
51 #define HUD_RX_FRAME_BREAK_MS (100u) /* Time used to detect a gap between two byte receptions => frame start */ | |
52 #define HUD_RX_START_DELAY_MS (500u) /* Delay for start of RX function to avoid start of reception while a transmission is ongoing. */ | |
53 /* Based on an assumed cycle time by the sensor of 1 second. Started at time of last RX */ | |
54 | |
49 /* Private variables ---------------------------------------------------------*/ | 55 /* Private variables ---------------------------------------------------------*/ |
50 SIrLink receiveHUD[2]; | 56 static SIrLink receiveHUD[2]; |
51 uint8_t boolHUDdata = 0; | 57 static uint8_t boolHUDdata = 0; |
52 uint8_t data_old__lost_connection_to_HUD = 1; | 58 static uint8_t data_old__lost_connection_to_HUD = 1; |
53 | 59 |
54 uint8_t receiveHUDraw[16]; | 60 static uint8_t receiveHUDraw[16]; |
55 | 61 |
56 uint8_t StartListeningToUART_HUD = 0; | 62 static uint8_t StartListeningToUART_HUD = 0; |
57 uint16_t count = 0; | 63 static uint16_t HUDTimeoutCount = 0; |
64 | |
65 static __IO ITStatus UartReadyHUD = RESET; | |
66 static uint32_t LastReceivedTick_HUD = 0; | |
58 | 67 |
59 /* Private variables with external access via get_xxx() function -------------*/ | 68 /* Private variables with external access via get_xxx() function -------------*/ |
60 | 69 |
61 /* Private function prototypes -----------------------------------------------*/ | 70 /* Private function prototypes -----------------------------------------------*/ |
62 static void tCCR_fallbackToFixedSetpoint(void); | 71 static void tCCR_fallbackToFixedSetpoint(void); |
287 /* after 3 seconds without update from HUD | 296 /* after 3 seconds without update from HUD |
288 * data is considered old | 297 * data is considered old |
289 */ | 298 */ |
290 void tCCR_tick(void) | 299 void tCCR_tick(void) |
291 { | 300 { |
292 if(count < 3 * 10) | 301 if(HUDTimeoutCount < 3 * 10) |
293 count++; | 302 HUDTimeoutCount++; |
294 else | 303 else |
295 { | 304 { |
296 data_old__lost_connection_to_HUD = 1; | 305 data_old__lost_connection_to_HUD = 1; |
297 if(count < 20 * 10) | 306 if(HUDTimeoutCount < 20 * 10) |
298 count++; | 307 HUDTimeoutCount++; |
299 else | 308 else |
300 tCCR_fallbackToFixedSetpoint(); | 309 tCCR_fallbackToFixedSetpoint(); |
301 } | 310 } |
302 } | 311 } |
303 | 312 |
313 void tCCR_SetRXIndication(void) | |
314 { | |
315 static uint8_t floatingRXCount = 0; | |
316 | |
317 if((UartIR_HUD_Handle.RxXferSize == HUD_RX_FRAME_LENGTH) || (UartIR_HUD_Handle.RxXferSize == HUD_RX_FRAME_LENGTH - 1)) /* we expected a complete frame */ | |
318 { | |
319 UartReadyHUD = SET; | |
320 LastReceivedTick_HUD = HAL_GetTick(); | |
321 floatingRXCount = 0; | |
322 } | |
323 else /* follow up of error handling */ | |
324 { | |
325 if(time_elapsed_ms(LastReceivedTick_HUD, HAL_GetTick()) > HUD_RX_FRAME_BREAK_MS) /* Reception took a while => frame start detected */ | |
326 { | |
327 HAL_UART_Receive_IT(&UartIR_HUD_Handle, &receiveHUDraw[1], 14); /* We have already the first byte => get the missing 14 */ | |
328 } | |
329 else | |
330 { | |
331 if(floatingRXCount++ < HUD_BABBLING_IDIOT) | |
332 { | |
333 HAL_UART_Receive_IT(&UartIR_HUD_Handle, receiveHUDraw, 1); /* Start polling of incoming bytes */ | |
334 } | |
335 else /* Significant amount of data comming in without break => disable input */ | |
336 { /* by not reactivation HUD RX, no recovery fromthis state */ | |
337 stateUsedWrite->diveSettings.ppo2sensors_deactivated = 0x07; /* Display deactivation */ | |
338 } | |
339 } | |
340 } | |
341 | |
342 } | |
304 | 343 |
305 void tCCR_restart(void) | 344 void tCCR_restart(void) |
306 { | 345 { |
307 HAL_UART_Receive_IT(&UartIR_HUD_Handle, receiveHUDraw, 15);/* 15*/ | 346 HAL_UART_AbortReceive_IT(&UartIR_HUD_Handle); /* Called by the error handler. RX will be restarted by control function */ |
347 StartListeningToUART_HUD = 1; | |
308 } | 348 } |
309 | 349 |
310 | 350 |
311 void tCCR_control(void) | 351 void tCCR_control(void) |
312 { | 352 { |
313 if((UartReadyHUD == RESET) && StartListeningToUART_HUD) | 353 |
314 { | 354 if((UartReadyHUD == RESET) && StartListeningToUART_HUD && (time_elapsed_ms(LastReceivedTick_HUD, HAL_GetTick()) > HUD_RX_START_DELAY_MS)) |
315 StartListeningToUART_HUD = 0; | 355 { |
316 HAL_UART_Receive_IT(&UartIR_HUD_Handle, receiveHUDraw, 15);/* 15*/ | 356 StartListeningToUART_HUD = 0; |
317 } | 357 HAL_UART_Receive_IT(&UartIR_HUD_Handle, receiveHUDraw, HUD_RX_FRAME_LENGTH); |
358 } | |
318 | 359 |
319 if(UartReadyHUD == SET) | 360 if(UartReadyHUD == SET) |
320 { | 361 { |
321 UartReadyHUD = RESET; | 362 UartReadyHUD = RESET; |
363 StartListeningToUART_HUD = 1; | |
322 | 364 |
323 memcpy(&receiveHUD[!boolHUDdata], receiveHUDraw, 11); | 365 memcpy(&receiveHUD[!boolHUDdata], receiveHUDraw, 11); |
324 receiveHUD[!boolHUDdata].battery_voltage_mV = receiveHUDraw[11] + (256 * receiveHUDraw[12]); | 366 receiveHUD[!boolHUDdata].battery_voltage_mV = receiveHUDraw[11] + (256 * receiveHUDraw[12]); |
325 receiveHUD[!boolHUDdata].checksum = receiveHUDraw[13] + (256 * receiveHUDraw[14]); | 367 receiveHUD[!boolHUDdata].checksum = receiveHUDraw[13] + (256 * receiveHUDraw[14]); |
326 | 368 |
331 checksum += receiveHUDraw[i]; | 373 checksum += receiveHUDraw[i]; |
332 } | 374 } |
333 if(checksum == receiveHUD[!boolHUDdata].checksum) | 375 if(checksum == receiveHUD[!boolHUDdata].checksum) |
334 { | 376 { |
335 boolHUDdata = !boolHUDdata; | 377 boolHUDdata = !boolHUDdata; |
336 count = 0; | 378 HUDTimeoutCount = 0; |
337 data_old__lost_connection_to_HUD = 0; | 379 data_old__lost_connection_to_HUD = 0; |
338 } | 380 } |
339 StartListeningToUART_HUD = 1; | 381 else |
382 { | |
383 if(data_old__lost_connection_to_HUD) /* we lost connection, maybe due to RX shift => start single byte read to resynchronize */ | |
384 { | |
385 HAL_UART_Receive_IT(&UartIR_HUD_Handle, receiveHUDraw, 1); | |
386 StartListeningToUART_HUD = 0; | |
387 } | |
388 } | |
389 memset(receiveHUDraw,0,sizeof(receiveHUDraw)); | |
340 } | 390 } |
341 } | 391 } |
342 | 392 |
343 #endif | 393 #endif |
344 /* Private functions ---------------------------------------------------------*/ | 394 /* Private functions ---------------------------------------------------------*/ |