comparison Small_CPU/Src/scheduler.c @ 554:3328189786e7

Added external ADC interface functionality (MCP3424): Added communication protocoll to read data from external ADC. At the moment 16bit and 18bit resolutions are supported. External data will be read and forwarded depending on the conversion time of the ADC.
author Ideenmodellierer
date Thu, 12 Nov 2020 19:46:03 +0100
parents 9eeab3fead8f
children 5149cd644fbc
comparison
equal deleted inserted replaced
553:43a2dd4ba30f 554:3328189786e7
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 "tm_stm32f4_otp.h" 43 #include "tm_stm32f4_otp.h"
44 #include "externalInterface.h"
44 45
45 /* uncomment to enable restoting of last known date in case of a power loss (RTC looses timing data) */ 46 /* uncomment to enable restoting of last known date in case of a power loss (RTC looses timing data) */
46 /* #define RESTORE_LAST_KNOWN_DATE */ 47 /* #define RESTORE_LAST_KNOWN_DATE */
47 48
48 #define INVALID_PREASURE_VALUE (0.0f) 49 #define INVALID_PREASURE_VALUE (0.0f)
86 void copyAmbientLightData(void); 87 void copyAmbientLightData(void);
87 void copyTissueData(void); 88 void copyTissueData(void);
88 void copyVpmCrushingData(void); 89 void copyVpmCrushingData(void);
89 void copyDeviceData(void); 90 void copyDeviceData(void);
90 void copyPICdata(void); 91 void copyPICdata(void);
92 void copyExtADCdata();
91 static void schedule_update_timer_helper(int8_t thisSeconds); 93 static void schedule_update_timer_helper(int8_t thisSeconds);
92 uint32_t time_elapsed_ms(uint32_t ticksstart,uint32_t ticksnow); 94 uint32_t time_elapsed_ms(uint32_t ticksstart,uint32_t ticksnow);
93 95
94 void scheduleSetDate(SDeviceLine *line); 96 void scheduleSetDate(SDeviceLine *line);
95 97
452 */ 454 */
453 void scheduleDiveMode(void) 455 void scheduleDiveMode(void)
454 { 456 {
455 uint32_t ticksdiff = 0; 457 uint32_t ticksdiff = 0;
456 uint32_t lasttick = 0; 458 uint32_t lasttick = 0;
459 uint8_t extAdcChannel = 0;
457 uint8_t counterAscentRate = 0; 460 uint8_t counterAscentRate = 0;
458 float lastPressure_bar = 0.0f; 461 float lastPressure_bar = 0.0f;
459 global.dataSendToMaster.mode = MODE_DIVE; 462 global.dataSendToMaster.mode = MODE_DIVE;
460 global.deviceDataSendToMaster.mode = MODE_DIVE; 463 global.deviceDataSendToMaster.mode = MODE_DIVE;
461 uint8_t counter_exit = 0; 464 uint8_t counter_exit = 0;
489 if(SPI_Evaluate_RX_Data()!=0) /* did we receive something ? */ 492 if(SPI_Evaluate_RX_Data()!=0) /* did we receive something ? */
490 { 493 {
491 Scheduler.counterSPIdata100msec++; 494 Scheduler.counterSPIdata100msec++;
492 } 495 }
493 schedule_check_resync(); 496 schedule_check_resync();
497
498 extAdcChannel = externalInterface_ReadAndSwitch();
499 if(extAdcChannel != EXTERNAL_ADC_NO_DATA)
500 {
501 externalInterface_CalculateADCValue(extAdcChannel);
502 copyExtADCdata();
503 }
494 } 504 }
495 505
496 //Evaluate pressure at 20 ms, 120 ms, 220 ms,.... 506 //Evaluate pressure at 20 ms, 120 ms, 220 ms,....
497 if(ticksdiff >= Scheduler.counterPressure100msec * 100 + 20) 507 if(ticksdiff >= Scheduler.counterPressure100msec * 100 + 20)
498 { 508 {
752 void scheduleSurfaceMode(void) 762 void scheduleSurfaceMode(void)
753 { 763 {
754 764
755 uint32_t ticksdiff = 0; 765 uint32_t ticksdiff = 0;
756 uint32_t lasttick = 0; 766 uint32_t lasttick = 0;
767 uint8_t extAdcChannel = 0;
757 Scheduler.tickstart = HAL_GetTick(); 768 Scheduler.tickstart = HAL_GetTick();
758 Scheduler.counterSPIdata100msec = 0; 769 Scheduler.counterSPIdata100msec = 0;
759 Scheduler.counterCompass100msec = 0; 770 Scheduler.counterCompass100msec = 0;
760 Scheduler.counterPressure100msec = 0; 771 Scheduler.counterPressure100msec = 0;
761 Scheduler.counterAmbientLight100msec = 0; 772 Scheduler.counterAmbientLight100msec = 0;
782 if(SPI_Evaluate_RX_Data()!=0) /* did we receive something ? */ 793 if(SPI_Evaluate_RX_Data()!=0) /* did we receive something ? */
783 { 794 {
784 Scheduler.counterSPIdata100msec++; 795 Scheduler.counterSPIdata100msec++;
785 } 796 }
786 schedule_check_resync(); 797 schedule_check_resync();
798 extAdcChannel = externalInterface_ReadAndSwitch();
799 if(extAdcChannel != EXTERNAL_ADC_NO_DATA)
800 {
801 externalInterface_CalculateADCValue(extAdcChannel);
802 copyExtADCdata();
803 }
787 } 804 }
788 805
789 /* Evaluate pressure at 20 ms, 120 ms, 220 ms,... duration ~22ms] */ 806 /* Evaluate pressure at 20 ms, 120 ms, 220 ms,... duration ~22ms] */
790 if(ticksdiff >= Scheduler.counterPressure100msec * 100 + 20) 807 if(ticksdiff >= Scheduler.counterPressure100msec * 100 + 20)
791 { 808 {
1604 global.dataSendToMaster.data[boolPICdata].button_setting[i] = global.ButtonPICdata[i]; 1621 global.dataSendToMaster.data[boolPICdata].button_setting[i] = global.ButtonPICdata[i];
1605 } 1622 }
1606 global.dataSendToMaster.boolPICdata = boolPICdata; 1623 global.dataSendToMaster.boolPICdata = boolPICdata;
1607 } 1624 }
1608 1625
1626 void copyExtADCdata()
1627 {
1628 float value;
1629
1630 uint8_t channel = 0;
1631
1632 for(channel = 0; channel < MAX_ADC_CHANNEL; channel++)
1633 {
1634 value = getExternalInterfaceChannel(channel);
1635 global.dataSendToMaster.data[0].extADC_voltage[channel] = value;
1636 }
1637 }
1638
1609 1639
1610 typedef enum 1640 typedef enum
1611 { 1641 {
1612 SPI3_OK = 0x00, 1642 SPI3_OK = 0x00,
1613 SPI3_DEINIT = 0x01, 1643 SPI3_DEINIT = 0x01,