comparison Discovery/Src/data_exchange_main.c @ 115:3834b6272ee5 FlipDisplay

Merge with 68181cd61f2069d061621c2cd2a6afddb7486f5e
author Ideenmodellierer
date Thu, 03 Jan 2019 19:59:36 +0100
parents 65a6e352ce08 22a1094545f3
children acc98f5bd8c4
comparison
equal deleted inserted replaced
114:79b19d56ab08 115:3834b6272ee5
165 } 165 }
166 166
167 void DataEX_init(void) 167 void DataEX_init(void)
168 { 168 {
169 SDiveState * pStateReal = stateRealGetPointerWrite(); 169 SDiveState * pStateReal = stateRealGetPointerWrite();
170 pStateReal->data_old__lost_connection_to_slave = 1; 170 pStateReal->data_old__lost_connection_to_slave = 0; //initial value
171 data_old__lost_connection_to_slave_counter_temp = 0; 171 data_old__lost_connection_to_slave_counter_temp = 0;
172 data_old__lost_connection_to_slave_counter_total = 0; 172 data_old__lost_connection_to_slave_counter_total = 0;
173 173
174 memset((void *)&dataOut, 0, sizeof(SDataReceiveFromMaster)); 174 memset((void *)&dataOut, 0, sizeof(SDataReceiveFromMaster));
175 // old 160307: for(int i=0;i<EXCHANGE_BUFFERSIZE;i++) 175 // old 160307: for(int i=0;i<EXCHANGE_BUFFERSIZE;i++)
304 uint8_t DataEX_call(void) 304 uint8_t DataEX_call(void)
305 { 305 {
306 uint8_t SPI_DMA_answer = 0; 306 uint8_t SPI_DMA_answer = 0;
307 307
308 HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_SET); 308 HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_SET);
309 delayMicros(10); 309 delayMicros(20); //~exchange time(+20% reserve)
310 310 HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_RESET);
311 /* one cycle with NotChipSelect true to clear slave spi buffer */ 311 /* one cycle with NotChipSelect true to clear slave spi buffer */
312 312
313 if(data_old__lost_connection_to_slave_counter_temp >= 3) 313 if(data_old__lost_connection_to_slave_counter_temp >= 3)
314 { 314 {
315 data_old__lost_connection_to_slave_counter_temp = 0; 315 data_old__lost_connection_to_slave_counter_temp = 0;
316 data_old__lost_connection_to_slave_counter_retry++; 316 data_old__lost_connection_to_slave_counter_retry++;
317 } 317 }
318 else 318 // else
319 { 319 // {
320 HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_RESET); 320 // HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_RESET);
321 } 321 // }
322 322
323 DataEx_call_helper_requests(); 323 DataEx_call_helper_requests();
324 324
325 systick_last = HAL_GetTick(); 325 systick_last = HAL_GetTick();
326 326
327 //HAL_GPIO_WritePin(OSCILLOSCOPE2_GPIO_PORT,OSCILLOSCOPE2_PIN,GPIO_PIN_RESET); /* only for testing with Oscilloscope */ 327 //HAL_GPIO_WritePin(OSCILLOSCOPE2_GPIO_PORT,OSCILLOSCOPE2_PIN,GPIO_PIN_RESET); /* only for testing with Oscilloscope */
328 328
329 SPI_DMA_answer = HAL_SPI_TransmitReceive_DMA(&cpu2DmaSpi, (uint8_t *)&dataOut, (uint8_t *)&dataIn, EXCHANGE_BUFFERSIZE+1); 329 SPI_DMA_answer = HAL_SPI_TransmitReceive_DMA(&cpu2DmaSpi, (uint8_t *)&dataOut, (uint8_t *)&dataIn, EXCHANGE_BUFFERSIZE);
330 // HAL_Delay(3);
330 if(SPI_DMA_answer != HAL_OK) 331 if(SPI_DMA_answer != HAL_OK)
331 DataEX_Error_Handler(SPI_DMA_answer); 332 DataEX_Error_Handler(SPI_DMA_answer);
333 // HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_SET);
332 //HAL_Delay(3); 334 //HAL_Delay(3);
333 //HAL_GPIO_WritePin(OSCILLOSCOPE2_GPIO_PORT,OSCILLOSCOPE2_PIN,GPIO_PIN_SET); /* only for testing with Oscilloscope */ 335 //HAL_GPIO_WritePin(OSCILLOSCOPE2_GPIO_PORT,OSCILLOSCOPE2_PIN,GPIO_PIN_SET); /* only for testing with Oscilloscope */
334 336
335 return 1; 337 return 1;
336 } 338 }
339
340
341 uint32_t SPI_CALLBACKS;
342 uint32_t get_num_SPI_CALLBACKS(void){
343 return SPI_CALLBACKS;
344 }
345
346 SDataExchangeSlaveToMaster* get_dataInPointer(void){
347 return &dataIn;
348 }
349
350
351 void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)
352 {
353
354
355 if(hspi == &cpu2DmaSpi)
356 {
357 SPI_CALLBACKS+=1;
358 }
359 }
360
361
362
363
337 364
338 void DateEx_copy_to_dataOut(void) 365 void DateEx_copy_to_dataOut(void)
339 { 366 {
340 const SDiveState * pStateReal = stateRealGetPointer(); 367 const SDiveState * pStateReal = stateRealGetPointer();
341 SSettings *settings = settingsGetPointer(); 368 SSettings *settings = settingsGetPointer();
429 SDiveState * pStateUsed; 456 SDiveState * pStateUsed;
430 if(decoLock == DECO_CALC_running) 457 if(decoLock == DECO_CALC_running)
431 return; 458 return;
432 if(stateUsed == stateRealGetPointer()) 459 if(stateUsed == stateRealGetPointer())
433 pStateUsed = stateRealGetPointerWrite(); 460 pStateUsed = stateRealGetPointerWrite();
434 else 461 else{
435 pStateUsed = stateSimGetPointerWrite(); 462 pStateUsed = stateSimGetPointerWrite();
436 463 }
437 464
438 if(decoLock == DECO_CALC_init_as_is_start_of_dive) 465 if(decoLock == DECO_CALC_init_as_is_start_of_dive)
439 { 466 {
440 vpm_init(&pStateUsed->vpm, pStateUsed->diveSettings.vpm_conservatism, 0, 0); 467 vpm_init(&pStateUsed->vpm, pStateUsed->diveSettings.vpm_conservatism, 0, 0);
441 buehlmann_init(); 468 buehlmann_init();