comparison Discovery/Src/ostc.c @ 1032:33b91584d827 Puls_Integration

New CV Pulse: The basic infrastructure for external puls measurement via Bluetooth has been added. Precondition is an OSTC with an activated central role. The OSTC will then search for a BLE device with puls measurement service. Reading data and visualization is not implemented yet.
author Ideenmodellierer
date Mon, 28 Jul 2025 18:34:45 +0200
parents 8d3f3a635397
children 5865f0aeb438
comparison
equal deleted inserted replaced
1031:cd4561c33758 1032:33b91584d827
25 /// You should have received a copy of the GNU General Public License 25 /// You should have received a copy of the GNU General Public License
26 /// along with this program. If not, see <http://www.gnu.org/licenses/>. 26 /// along with this program. If not, see <http://www.gnu.org/licenses/>.
27 ////////////////////////////////////////////////////////////////////////////// 27 //////////////////////////////////////////////////////////////////////////////
28 28
29 /* Includes ------------------------------------------------------------------*/ 29 /* Includes ------------------------------------------------------------------*/
30 #include "configuration.h"
30 #include "ostc.h" 31 #include "ostc.h"
31 #include "stm32f4xx_hal.h" 32 #include "stm32f4xx_hal.h"
33 #include "cv_heartbeat.h"
32 34
33 #ifndef BOOTLOADER_STANDALONE 35 #ifndef BOOTLOADER_STANDALONE
34 #include "tCCR.h" 36 #include "tCCR.h"
35 #endif 37 #endif
36 38
52 54
53 /* Private variables ---------------------------------------------------------*/ 55 /* Private variables ---------------------------------------------------------*/
54 56
55 /* Private variables with external access via get_xxx() function -------------*/ 57 /* Private variables with external access via get_xxx() function -------------*/
56 static uint8_t hardwareDisplay = 0; //< either OSTC4 LCD (=0) or new Screen (=1) 58 static uint8_t hardwareDisplay = 0; //< either OSTC4 LCD (=0) or new Screen (=1)
59
60 static uint16_t rxBufRead = 0;
61 static uint16_t rxBufWrite = 0;
62 static uint8_t rxBufferUart[CHUNK_SIZE * CHUNKS_PER_BUFFER]; /* The complete buffer has a X * chunk size to allow variations in buffer read time */
63
57 /* Private function prototypes -----------------------------------------------*/ 64 /* Private function prototypes -----------------------------------------------*/
58 65
59 /* Exported functions --------------------------------------------------------*/ 66 /* Exported functions --------------------------------------------------------*/
60 67
61 /** SPI init function 68 /** SPI init function
378 385
379 HAL_UART_Init(&UartIR_HUD_Handle); 386 HAL_UART_Init(&UartIR_HUD_Handle);
380 #endif 387 #endif
381 } 388 }
382 389
390 static DMA_HandleTypeDef hdma_uart_BT_rx;
391
392 void MX_UART_BT_Init_DMA()
393 {
394
395 __DMA2_CLK_ENABLE();
396 __HAL_RCC_DMA2_CLK_ENABLE();
397
398 hdma_uart_BT_rx.Instance = DMA2_Stream2;
399 hdma_uart_BT_rx.Init.Channel = DMA_CHANNEL_4;
400 hdma_uart_BT_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
401 hdma_uart_BT_rx.Init.PeriphInc = DMA_PINC_DISABLE;
402 hdma_uart_BT_rx.Init.MemInc = DMA_MINC_ENABLE;
403 hdma_uart_BT_rx.Init.PeriphDataAlignment = DMA_MDATAALIGN_BYTE;
404 hdma_uart_BT_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
405 hdma_uart_BT_rx.Init.Mode = DMA_NORMAL;
406 hdma_uart_BT_rx.Init.Priority = DMA_PRIORITY_LOW;
407 hdma_uart_BT_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
408 HAL_DMA_Init(&hdma_uart_BT_rx);
409
410 __HAL_LINKDMA(&UartHandle, hdmarx, hdma_uart_BT_rx);
411
412 HAL_NVIC_SetPriority(DMA2_Stream2_IRQn, 0, 0);
413 HAL_NVIC_EnableIRQ(DMA2_Stream2_IRQn);
414 }
415
416
417 uint8_t UART_getChar()
418 {
419 uint8_t retChar = 0;
420
421 if((rxBufRead != rxBufWrite) && (rxBufferUart[rxBufRead] != 0))
422 {
423 retChar = rxBufferUart[rxBufRead];
424 rxBufferUart[rxBufRead++] = 0;
425 if(rxBufRead == CHUNK_SIZE * CHUNKS_PER_BUFFER)
426 {
427 rxBufRead = 0;
428 }
429 }
430 return retChar;
431 }
432
433 void UART_StartDMARx()
434 {
435 HAL_UART_Receive_DMA (&UartHandle, &rxBufferUart[rxBufWrite], CHUNK_SIZE);
436 rxBufWrite += CHUNK_SIZE;
437 if(rxBufWrite >= CHUNK_SIZE * CHUNKS_PER_BUFFER)
438 {
439 rxBufWrite = 0;
440 }
441 }
442
443 void DMA2_Stream2_IRQHandler(void)
444 {
445 HAL_DMA_IRQHandler(&hdma_uart_BT_rx);
446 }
447
383 void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) 448 void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
384 { 449 {
385 if(huart == &UartHandle) 450 if(huart == &UartHandle)
386 UartReady = SET; 451 UartReady = SET;
387 } 452 }
388 453
389 454
390 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) 455 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
391 { 456 {
392 if(huart == &UartHandle) 457 if(huart == &UartHandle)
393 UartReady = SET; 458 {
459 #ifdef ENABLE_PULSE_SENSOR_BT
460 if(cv_heartbeat_getState() != SENSOR_HB_OFFLINE)
461 {
462 UART_StartDMARx();
463 }
464 else
465 {
466 UartReady = SET;
467 }
468 #else
469 UartReady = SET;
470 #endif
471 }
394 else 472 else
395 if(huart == &UartIR_HUD_Handle) 473 if(huart == &UartIR_HUD_Handle)
396 { 474 {
397 #ifndef BOOTLOADER_STANDALONE 475 #ifndef BOOTLOADER_STANDALONE
398 tCCR_SetRXIndication(); 476 tCCR_SetRXIndication();