Changeset 67 for ctrl/firmware/Main/SES/Core
- Timestamp:
- Jan 22, 2025, 4:41:16 PM (5 days ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ctrl/firmware/Main/SES/Core/Src/fan_thread.cpp
r66 r67 6 6 7 7 #include "fan_thread.h" 8 #include "utils.h" 8 9 9 static constexpr unsigned INPUT_BUF_SIZE = 256U; // Must be dev by 410 static constexpr unsigned INPUT_BUF_SIZE = 64U; // Must be dev by 4 10 11 11 alignas(32) static char ibuf[INPUT_BUF_SIZE] __attribute__((section(".RAM1"))); 12 alignas(32) static char obuf[INPUT_BUF_SIZE] __attribute__((section(".RAM1"))); 12 alignas(32) static unsigned ibuf[INPUT_BUF_SIZE] __attribute__((section(".RAM1"))); 13 //alignas(32) static char obuf[INPUT_BUF_SIZE] __attribute__((section(".RAM1"))); 14 15 static volatile uint32_t rawCnt; 16 17 //TX_EVENT_FLAGS_GROUP fanEG; 13 18 14 19 VOID fanThread(ULONG initial_input) 15 20 { 16 21 (void)initial_input; 17 extern DMA_HandleTypeDef hdma_tim3_ch1; 22 //extern DMA_HandleTypeDef hdma_tim8_ch1; 23 extern TX_THREAD fan_thread_ptr; 18 24 19 25 // Compute the value of ARR register to generate signal frequency at 25Khz … … 26 32 27 33 28 auto start = __HAL_TIM_GET_COMPARE(&htim3, TIM_CHANNEL_2);29 auto end = __HAL_TIM_GET_AUTORELOAD(&htim3) - 300;34 //auto start = __HAL_TIM_GET_COMPARE(&htim3, TIM_CHANNEL_2); 35 //auto end = __HAL_TIM_GET_AUTORELOAD(&htim3) - 300; 30 36 31 HAL_TIM_IC_Start_IT(&htim8, TIM_CHANNEL_1);//, (uint32_t*)ibuf, INPUT_BUF_SIZE); 32 //__HAL_DMA_DISABLE_IT(&hdma_tim3_ch1, DMA_IT_HT); 33 34 37 //tx_event_flags_create(&fanEG, (char*)"FAN TACHO event group"); 38 //ULONG actual_flags; 35 39 36 40 while(1) 37 41 { 42 for (auto i = 0U; i < INPUT_BUF_SIZE; i++) 43 { 44 HAL_TIM_IC_Start_IT(&htim8, TIM_CHANNEL_1);//, (uint32_t*)ibuf, INPUT_BUF_SIZE); 45 //__HAL_DMA_DISABLE_IT(&hdma_tim8_ch1, DMA_IT_HT); 46 47 tx_thread_suspend(&fan_thread_ptr); 48 //tx_event_flags_get(&fanEG, 1, TX_AND_CLEAR, &actual_flags, TX_WAIT_FOREVER); 49 50 //printf("%u, ", rawCnt); 51 ibuf[i] = rawCnt; 52 } 53 54 unsigned sum = 0; 55 for (auto i = 0U; i < INPUT_BUF_SIZE; i += 4) 56 { 57 unsigned tmp = 0; 58 for (auto j = 0U; j < 4U; j++) 59 tmp += ibuf[i + j]; 60 sum += tmp; 61 } 62 63 sum /= (INPUT_BUF_SIZE / 4U); 64 65 uint32_t div = htim8.Instance->PSC + 1; 66 uint32_t clockHz = SystemCoreClock / div; 67 //uint32_t arr = htim8.Instance->ARR + 1; 68 69 uint32_t rpm = (60U * clockHz) / sum; 70 printf("RPM = %u\n", rpm); 71 72 73 //SCB_InvalidateDCache_by_Addr((uint32_t*)ibuf, INPUT_BUF_SIZE); 74 75 38 76 /*for (auto i = start; i < end; i++) 39 77 { … … 51 89 //HAL_DMA_PollForTransfer() 52 90 53 tx_thread_sleep(1000);91 //tx_thread_sleep(1); 54 92 } 55 93 } … … 59 97 void pulseMeasured(void) 60 98 { 61 volatile static uint32_t rawCnt;99 extern TX_THREAD fan_thread_ptr; 62 100 //static uint32_t lastTime; 63 101 /*extern DMA_HandleTypeDef hdma_tim3_ch1; … … 71 109 72 110 rawCnt = HAL_TIM_ReadCapturedValue(&htim8, TIM_CHANNEL_1); 111 //tx_event_flags_set(&fanEG, 1, TX_OR); 73 112 113 /*SCB_InvalidateDCache_by_Addr((uint32_t*)ibuf, INPUT_BUF_SIZE); 114 115 for (auto i = 0U; i < INPUT_BUF_SIZE; i++) 116 { 117 printf("%u,", ibuf[i]); 118 }*/ 119 //printf("%u\n", HAL_GetTick()); 120 121 122 tx_thread_resume(&fan_thread_ptr); 74 123 }
Note: See TracChangeset
for help on using the changeset viewer.