comparison Small_CPU/Src/scheduler.c @ 181:331882a89421 Cleanup_Compass_Wireless

Removed not suppoted wireless feature The code contains parts of a wireless sensor feature which is not supported by the OSTC4 hardware.
author ideenmodellierer
date Wed, 13 Mar 2019 21:51:25 +0100
parents c659fda83e44
children f11f0bf6ef2d
comparison
equal deleted inserted replaced
180:9ecc2e60418d 181:331882a89421
38 #include "dma.h" 38 #include "dma.h"
39 #include "adc.h" 39 #include "adc.h"
40 #include "calc_crush.h" 40 #include "calc_crush.h"
41 #include "stm32f4xx_hal_rtc_ex.h" 41 #include "stm32f4xx_hal_rtc_ex.h"
42 #include "decom.h" 42 #include "decom.h"
43 #include "wireless.h"
44 #include "tm_stm32f4_otp.h" 43 #include "tm_stm32f4_otp.h"
45 44
46 45
47 #define INVALID_PREASURE_VALUE (100.0F) 46 #define INVALID_PREASURE_VALUE (100.0F)
48 47
85 //void copyBatteryData(void); now in header 84 //void copyBatteryData(void); now in header
86 void copyAmbientLightData(void); 85 void copyAmbientLightData(void);
87 void copyTissueData(void); 86 void copyTissueData(void);
88 void copyVpmCrushingData(void); 87 void copyVpmCrushingData(void);
89 void copyDeviceData(void); 88 void copyDeviceData(void);
90 void changeAgeWirelessData(void);
91 void copyWirelessData(void);
92 void copyPICdata(void); 89 void copyPICdata(void);
93 uint16_t schedule_update_timer_helper(int8_t thisSeconds); 90 uint16_t schedule_update_timer_helper(int8_t thisSeconds);
94 91
95 92
96 uint32_t time_elapsed_ms(uint32_t ticksstart,uint32_t ticksnow); 93 uint32_t time_elapsed_ms(uint32_t ticksstart,uint32_t ticksnow);
476 Scheduler.tickstart = HAL_GetTick() - 1000; 473 Scheduler.tickstart = HAL_GetTick() - 1000;
477 Scheduler.counterSPIdata100msec = 0; 474 Scheduler.counterSPIdata100msec = 0;
478 Scheduler.counterCompass100msec = 0; 475 Scheduler.counterCompass100msec = 0;
479 Scheduler.counterPressure100msec = 0; 476 Scheduler.counterPressure100msec = 0;
480 Scheduler.counterAmbientLight100msec = 0; 477 Scheduler.counterAmbientLight100msec = 0;
481 Scheduler.counterWireless1msec = 0;
482 478
483 global.deviceData.diveCycles.value_int32++; 479 global.deviceData.diveCycles.value_int32++;
484 scheduleSetDate(&global.deviceData.diveCycles); 480 scheduleSetDate(&global.deviceData.diveCycles);
485 global.lifeData.counterSecondsShallowDepth = 0; 481 global.lifeData.counterSecondsShallowDepth = 0;
486 482
487 while(global.mode == MODE_DIVE) 483 while(global.mode == MODE_DIVE)
488 { 484 {
489 schedule_check_resync(); 485 schedule_check_resync();
490 lasttick = HAL_GetTick(); 486 lasttick = HAL_GetTick();
491 ticksdiff = time_elapsed_ms(Scheduler.tickstart,lasttick); 487 ticksdiff = time_elapsed_ms(Scheduler.tickstart,lasttick);
492
493
494 //Evaluate wireless data every ms, if present
495 if(ticksdiff > Scheduler.counterWireless1msec)
496 {
497 Scheduler.counterWireless1msec++;
498 changeAgeWirelessData();
499 global.wirelessReceived = wireless_evaluate(global.wirelessdata,MAX_WIRELESS_BYTES, &global.wirelessConfidenceStatus);
500 if((global.wirelessReceived > 0) && !wireless_evaluate_crc_error(global.wirelessdata,global.wirelessReceived))
501 {
502 copyWirelessData();
503 }
504 }
505 488
506 if(ticksdiff >= Scheduler.counterSPIdata100msec * 100 + 10) 489 if(ticksdiff >= Scheduler.counterSPIdata100msec * 100 + 10)
507 { 490 {
508 SPI_Evaluate_RX_Data(); 491 SPI_Evaluate_RX_Data();
509 Scheduler.counterSPIdata100msec++; 492 Scheduler.counterSPIdata100msec++;
664 } 647 }
665 Scheduler.counterSPIdata100msec = 0; 648 Scheduler.counterSPIdata100msec = 0;
666 Scheduler.counterCompass100msec = 0; 649 Scheduler.counterCompass100msec = 0;
667 Scheduler.counterPressure100msec = 0; 650 Scheduler.counterPressure100msec = 0;
668 Scheduler.counterAmbientLight100msec = 0; 651 Scheduler.counterAmbientLight100msec = 0;
669 Scheduler.counterWireless1msec = 0;
670 } 652 }
671 } 653 }
672 } 654 }
673 655
674 656
765 Scheduler.tickstart = HAL_GetTick(); 747 Scheduler.tickstart = HAL_GetTick();
766 Scheduler.counterSPIdata100msec = 0; 748 Scheduler.counterSPIdata100msec = 0;
767 Scheduler.counterCompass100msec = 0; 749 Scheduler.counterCompass100msec = 0;
768 Scheduler.counterPressure100msec = 0; 750 Scheduler.counterPressure100msec = 0;
769 Scheduler.counterAmbientLight100msec = 0; 751 Scheduler.counterAmbientLight100msec = 0;
770 Scheduler.counterWireless1msec = 0;
771 752
772 global.dataSendToMaster.mode = MODE_SURFACE; 753 global.dataSendToMaster.mode = MODE_SURFACE;
773 global.deviceDataSendToMaster.mode = MODE_SURFACE; 754 global.deviceDataSendToMaster.mode = MODE_SURFACE;
774 755
775 while(global.mode == MODE_SURFACE) 756 while(global.mode == MODE_SURFACE)
778 // SPI_Start_single_TxRx_with_Master(); 759 // SPI_Start_single_TxRx_with_Master();
779 schedule_check_resync(); 760 schedule_check_resync();
780 lasttick = HAL_GetTick(); 761 lasttick = HAL_GetTick();
781 ticksdiff = time_elapsed_ms(Scheduler.tickstart,lasttick); 762 ticksdiff = time_elapsed_ms(Scheduler.tickstart,lasttick);
782 763
783 if(ticksdiff > Scheduler.counterWireless1msec)
784 {
785 Scheduler.counterWireless1msec++;
786 changeAgeWirelessData();
787 global.wirelessReceived = wireless_evaluate(global.wirelessdata,MAX_WIRELESS_BYTES, &global.wirelessConfidenceStatus);
788 if((global.wirelessReceived > 0) && !wireless_evaluate_crc_error(global.wirelessdata,global.wirelessReceived))
789 {
790 copyWirelessData();
791 }
792 }
793 if(setButtonsNow == 1) 764 if(setButtonsNow == 1)
794 { 765 {
795 if(scheduleSetButtonResponsiveness()) 766 if(scheduleSetButtonResponsiveness())
796 setButtonsNow = 0; 767 setButtonsNow = 0;
797 } 768 }
905 } 876 }
906 Scheduler.counterSPIdata100msec = 0; 877 Scheduler.counterSPIdata100msec = 0;
907 Scheduler.counterCompass100msec = 0; 878 Scheduler.counterCompass100msec = 0;
908 Scheduler.counterPressure100msec = 0; 879 Scheduler.counterPressure100msec = 0;
909 Scheduler.counterAmbientLight100msec = 0; 880 Scheduler.counterAmbientLight100msec = 0;
910 Scheduler.counterWireless1msec = 0;
911 } 881 }
912 } 882 }
913 } 883 }
914 884
915 void HardSyncToSPI() 885 void HardSyncToSPI()
920 Scheduler.tickstart = HAL_GetTick(); 890 Scheduler.tickstart = HAL_GetTick();
921 Scheduler.counterSPIdata100msec = 0; 891 Scheduler.counterSPIdata100msec = 0;
922 Scheduler.counterCompass100msec = 0; 892 Scheduler.counterCompass100msec = 0;
923 Scheduler.counterPressure100msec = 0; 893 Scheduler.counterPressure100msec = 0;
924 Scheduler.counterAmbientLight100msec = 0; 894 Scheduler.counterAmbientLight100msec = 0;
925 Scheduler.counterWireless1msec = 0;
926 dohardspisync = 0; 895 dohardspisync = 0;
927 } 896 }
928 } 897 }
929 898
930 /** 899 /**
1517 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.max_actual_gradient, &global.vpm.max_actual_gradient, sizeof(16*4)); 1486 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.max_actual_gradient, &global.vpm.max_actual_gradient, sizeof(16*4));
1518 global.deviceDataSendToMaster.VpmRepetitiveData.repetitive_variables_not_valid = global.vpm.repetitive_variables_not_valid; 1487 global.deviceDataSendToMaster.VpmRepetitiveData.repetitive_variables_not_valid = global.vpm.repetitive_variables_not_valid;
1519 global.deviceDataSendToMaster.boolVpmRepetitiveDataValid = 1; 1488 global.deviceDataSendToMaster.boolVpmRepetitiveDataValid = 1;
1520 } 1489 }
1521 1490
1522 void changeAgeWirelessData(void)
1523 {
1524 for(int i=0;i<4;i++)
1525 {
1526 if(global.dataSendToMaster.data[global.dataSendToMaster.boolWirelessData].wireless_data[i].ageInMilliSeconds)
1527 global.dataSendToMaster.data[global.dataSendToMaster.boolWirelessData].wireless_data[i].ageInMilliSeconds++;
1528 }
1529 }
1530
1531 void copyWirelessData(void)
1532 {
1533 uint8_t boolWirelessData = !global.dataSendToMaster.boolWirelessData;
1534 SDataWireless *dataOld, *dataNew;
1535 for(int i=0;i<3;i++)
1536 {
1537 dataNew = &global.dataSendToMaster.data[boolWirelessData].wireless_data[i+1];
1538 dataOld = &global.dataSendToMaster.data[!boolWirelessData].wireless_data[i];
1539 dataNew->ageInMilliSeconds = dataOld->ageInMilliSeconds;
1540 dataNew->numberOfBytes = dataOld->numberOfBytes;
1541 dataNew->status = dataOld->status;
1542 memcpy(dataNew->data, dataOld->data,8);
1543 }
1544
1545 global.dataSendToMaster.data[boolWirelessData].wireless_data[0].ageInMilliSeconds = 1;
1546 global.dataSendToMaster.data[boolWirelessData].wireless_data[0].numberOfBytes = global.wirelessReceived;
1547 global.dataSendToMaster.data[boolWirelessData].wireless_data[0].status = global.wirelessConfidenceStatus;
1548 for(int i=0;i<MAX_WIRELESS_BYTES;i++)
1549 global.dataSendToMaster.data[boolWirelessData].wireless_data[0].data[i] = global.wirelessdata[i];
1550 for(int i=MAX_WIRELESS_BYTES;i<12;i++)
1551 global.dataSendToMaster.data[boolWirelessData].wireless_data[0].data[i] = 0xFF;
1552
1553 global.dataSendToMaster.boolWirelessData = boolWirelessData;
1554 }
1555
1556 /* copyPICdata(); is used in spi.c */ 1491 /* copyPICdata(); is used in spi.c */
1557 void copyPICdata(void) 1492 void copyPICdata(void)
1558 { 1493 {
1559 uint8_t boolPICdata = !global.dataSendToMaster.boolPICdata; 1494 uint8_t boolPICdata = !global.dataSendToMaster.boolPICdata;
1560 for(int i = 0; i < 3; i++) 1495 for(int i = 0; i < 3; i++)
1561 { 1496 {
1562 global.dataSendToMaster.data[boolPICdata].button_setting[i] = global.ButtonPICdata[i]; 1497 global.dataSendToMaster.data[boolPICdata].button_setting[i] = global.ButtonPICdata[i];
1563 } 1498 }
1564 global.dataSendToMaster.boolPICdata = boolPICdata; 1499 global.dataSendToMaster.boolPICdata = boolPICdata;
1565 } 1500 }
1566
1567
1568 1501
1569 1502
1570 typedef enum 1503 typedef enum
1571 { 1504 {
1572 SPI3_OK = 0x00, 1505 SPI3_OK = 0x00,