Mercurial > public > ostc4
comparison Small_CPU/Src/spi.c @ 264:b3685fbada3b IPC_Sync_Improvment_2
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
Added function to synchronize RTE to the timestamp provided by Main 100ms callback. This was introduced to compensated small shifts in execution and program flow shifts (for example during long operation times)
author | ideenmodellierer |
---|---|
date | Sun, 14 Apr 2019 11:43:29 +0200 |
parents | e4207f0aaa4b |
children | 580822b5d3d1 |
comparison
equal
deleted
inserted
replaced
263:a6c0375bc950 | 264:b3685fbada3b |
---|---|
315 | 315 |
316 void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi) { | 316 void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi) { |
317 /* restart SPI */ | 317 /* restart SPI */ |
318 if (hspi == &hspi1) | 318 if (hspi == &hspi1) |
319 { | 319 { |
320 Scheduler_SyncToSPI(); | 320 if(SPI_check_header_and_footer_ok()) /* process timestamp provided by main */ |
321 { | |
322 Scheduler_SyncToSPI(global.dataSendToSlave.header.checkCode[SPI_HEADER_INDEX_TX_TICK]); | |
323 } | |
324 else | |
325 { | |
326 Scheduler_SyncToSPI(0); /* => no async will be calculated */ | |
327 } | |
328 | |
321 SPIDataRX = 1; | 329 SPIDataRX = 1; |
322 | 330 |
323 /* stop data exchange? */ | 331 /* stop data exchange? */ |
324 if (global.mode == MODE_SHUTDOWN) { | 332 if (global.mode == MODE_SHUTDOWN) { |
325 global.mode = MODE_SLEEP; | 333 global.mode = MODE_SLEEP; |
328 global.dataSendToSlaveIsNotValidCount = 0; | 336 global.dataSendToSlaveIsNotValidCount = 0; |
329 } | 337 } |
330 } | 338 } |
331 } | 339 } |
332 | 340 |
333 void SPI_Evaluate_RX_Data() | 341 uint8_t SPI_Evaluate_RX_Data() |
334 { | 342 { |
335 uint8_t resettimeout = 1; | 343 uint8_t resettimeout = 1; |
344 uint8_t ret = SPIDataRX; | |
336 | 345 |
337 if ((global.mode != MODE_SHUTDOWN) && ( global.mode != MODE_SLEEP) && (SPIDataRX)) | 346 if ((global.mode != MODE_SHUTDOWN) && ( global.mode != MODE_SLEEP) && (SPIDataRX)) |
338 { | 347 { |
339 SPIDataRX = 0; | 348 SPIDataRX = 0; |
340 /* data consistent? */ | 349 /* data consistent? */ |
383 global.deviceDataSendToMaster.power_on_reset = 0; | 392 global.deviceDataSendToMaster.power_on_reset = 0; |
384 | 393 |
385 scheduleSpecial_Evaluate_DataSendToSlave(); | 394 scheduleSpecial_Evaluate_DataSendToSlave(); |
386 | 395 |
387 SPI_Start_single_TxRx_with_Master(); | 396 SPI_Start_single_TxRx_with_Master(); |
388 } | 397 |
389 | 398 if(resettimeout) |
390 if(resettimeout) | 399 { |
391 { | 400 global.check_sync_not_running = 0; |
392 global.check_sync_not_running = 0; | 401 } |
393 } | 402 } |
403 return ret; | |
394 } | 404 } |
395 | 405 |
396 static uint8_t SPI_check_header_and_footer_ok(void) { | 406 static uint8_t SPI_check_header_and_footer_ok(void) { |
397 if (global.dataSendToSlave.header.checkCode[0] != 0xBB) | 407 if (global.dataSendToSlave.header.checkCode[0] != 0xBB) |
398 return 0; | 408 return 0; |