Mercurial > public > ostc4
comparison Discovery/Src/data_exchange_main.c @ 133:acc98f5bd8c4 FlipDisplay
Intoduced transfer abort function for data exchange recovery
author | Ideenmodellierer |
---|---|
date | Tue, 19 Feb 2019 18:15:35 +0100 |
parents | 3834b6272ee5 |
children | 9eda5a75c5fd |
comparison
equal
deleted
inserted
replaced
132:135eae957389 | 133:acc98f5bd8c4 |
---|---|
53 * | 53 * |
54 ****************************************************************************** | 54 ****************************************************************************** |
55 */ | 55 */ |
56 | 56 |
57 /* Includes ------------------------------------------------------------------*/ | 57 /* Includes ------------------------------------------------------------------*/ |
58 #include <stdlib.h> | |
58 #include <string.h> // for memcopy | 59 #include <string.h> // for memcopy |
59 #include "stm32f4xx_hal.h" | 60 #include "stm32f4xx_hal.h" |
60 #include "stdio.h" | 61 #include "stdio.h" |
61 #include "ostc.h" | 62 #include "ostc.h" |
62 #include "settings.h" | 63 #include "settings.h" |
87 | 88 |
88 SDataReceiveFromMaster dataOut; | 89 SDataReceiveFromMaster dataOut; |
89 SDataExchangeSlaveToMaster dataIn; | 90 SDataExchangeSlaveToMaster dataIn; |
90 | 91 |
91 uint32_t systick_last; | 92 uint32_t systick_last; |
93 uint32_t systick_last_spi; | |
92 uint8_t data_old__lost_connection_to_slave_counter_temp = 0; | 94 uint8_t data_old__lost_connection_to_slave_counter_temp = 0; |
93 uint8_t data_old__lost_connection_to_slave_counter_retry = 0; | 95 uint8_t data_old__lost_connection_to_slave_counter_retry = 0; |
94 uint32_t data_old__lost_connection_to_slave_counter_total = 0; | 96 uint32_t data_old__lost_connection_to_slave_counter_total = 0; |
95 | 97 |
96 /* Private types -------------------------------------------------------------*/ | 98 /* Private types -------------------------------------------------------------*/ |
133 | 135 |
134 void DataEX_Error_Handler(uint8_t answer) | 136 void DataEX_Error_Handler(uint8_t answer) |
135 { | 137 { |
136 count_DataEX_Error_Handler++; | 138 count_DataEX_Error_Handler++; |
137 last_error_DataEX_Error_Handler = answer; | 139 last_error_DataEX_Error_Handler = answer; |
140 | |
141 /* A wrong footer indicates a communication interrupt. Statemachine is waiting for new data which is not received because no new transmission is triggered */ | |
142 /* ==> Abort data exchange to enable a new RX / TX cycle */ | |
143 if(answer == HAL_BUSY) | |
144 { | |
145 HAL_SPI_Abort_IT(&cpu2DmaSpi); | |
146 data_old__lost_connection_to_slave_counter_total = 1000; /* add significant error offset to indicate error causing an abort event */ | |
147 } | |
148 data_old__lost_connection_to_slave_counter_total = answer; | |
138 return; | 149 return; |
139 } | 150 } |
140 | 151 |
141 | 152 |
142 uint32_t DataEX_lost_connection_count(void) | 153 uint32_t DataEX_lost_connection_count(void) |
311 /* one cycle with NotChipSelect true to clear slave spi buffer */ | 322 /* one cycle with NotChipSelect true to clear slave spi buffer */ |
312 | 323 |
313 if(data_old__lost_connection_to_slave_counter_temp >= 3) | 324 if(data_old__lost_connection_to_slave_counter_temp >= 3) |
314 { | 325 { |
315 data_old__lost_connection_to_slave_counter_temp = 0; | 326 data_old__lost_connection_to_slave_counter_temp = 0; |
327 HAL_SPI_Abort_IT(&cpu2DmaSpi); | |
328 __HAL_SPI_CLEAR_OVRFLAG(&cpu2DmaSpi); | |
316 data_old__lost_connection_to_slave_counter_retry++; | 329 data_old__lost_connection_to_slave_counter_retry++; |
317 } | 330 } |
318 // else | |
319 // { | |
320 // HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_RESET); | |
321 // } | |
322 | 331 |
323 DataEx_call_helper_requests(); | 332 DataEx_call_helper_requests(); |
324 | 333 |
325 systick_last = HAL_GetTick(); | 334 systick_last = HAL_GetTick(); |
326 | 335 |
327 //HAL_GPIO_WritePin(OSCILLOSCOPE2_GPIO_PORT,OSCILLOSCOPE2_PIN,GPIO_PIN_RESET); /* only for testing with Oscilloscope */ | 336 //HAL_GPIO_WritePin(OSCILLOSCOPE2_GPIO_PORT,OSCILLOSCOPE2_PIN,GPIO_PIN_RESET); /* only for testing with Oscilloscope */ |
337 | |
328 | 338 |
329 SPI_DMA_answer = HAL_SPI_TransmitReceive_DMA(&cpu2DmaSpi, (uint8_t *)&dataOut, (uint8_t *)&dataIn, EXCHANGE_BUFFERSIZE); | 339 SPI_DMA_answer = HAL_SPI_TransmitReceive_DMA(&cpu2DmaSpi, (uint8_t *)&dataOut, (uint8_t *)&dataIn, EXCHANGE_BUFFERSIZE); |
330 // HAL_Delay(3); | 340 // HAL_Delay(3); |
331 if(SPI_DMA_answer != HAL_OK) | 341 if(SPI_DMA_answer != HAL_OK) |
332 DataEX_Error_Handler(SPI_DMA_answer); | 342 DataEX_Error_Handler(SPI_DMA_answer); |
343 | |
333 // HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_SET); | 344 // HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_SET); |
334 //HAL_Delay(3); | 345 //HAL_Delay(3); |
335 //HAL_GPIO_WritePin(OSCILLOSCOPE2_GPIO_PORT,OSCILLOSCOPE2_PIN,GPIO_PIN_SET); /* only for testing with Oscilloscope */ | 346 //HAL_GPIO_WritePin(OSCILLOSCOPE2_GPIO_PORT,OSCILLOSCOPE2_PIN,GPIO_PIN_SET); /* only for testing with Oscilloscope */ |
336 | 347 |
337 return 1; | 348 return 1; |
352 { | 363 { |
353 | 364 |
354 | 365 |
355 if(hspi == &cpu2DmaSpi) | 366 if(hspi == &cpu2DmaSpi) |
356 { | 367 { |
368 systick_last_spi = HAL_GetTick(); | |
357 SPI_CALLBACKS+=1; | 369 SPI_CALLBACKS+=1; |
358 } | 370 } |
359 } | 371 } |
360 | 372 |
361 | 373 |