imc_kernel.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include <stdio.h>
  2. #include "ImC/imc_kernel.h"
  3. #include "ImC/imc_api.h"
  4. #include "stm32l5xx.h"
  5. #include "cmsis_os.h"
  6. #if(imcUSE_CHECKPOINT_VOLTAGE_CHECK)
  7. extern ADC_HandleTypeDef ADC_HANDLER_SBC;
  8. #endif
  9. #if(imcUSE_CHECKPOINT_PASS_COUNTER)
  10. int checkpointCounter = 0;
  11. const int checkpoint_pass_count = imcCHECKPOINT_PASS_COUNT;
  12. #endif
  13. void imcInit()
  14. {
  15. FPU->FPCCR &= ~(FPU_FPCCR_LSPEN_Msk); // turn off lazy stacking
  16. }
  17. int needCheckpointExecution() {
  18. #if(imcUSE_CHECKPOINT_VOLTAGE_CHECK)
  19. int capacitor_voltage0 = measure_voltage(ADC_HANDLER_SBC, EPS_CAP_ID_SBC);
  20. return capacitor_voltage0 < imcCHECKPOINT_VOLTAGE;
  21. printf("\t\t\t\t\t\t[EPS] CAP VOLT: %d.%03d\r\n", capacitor_voltage0 / 1000, capacitor_voltage0 % 1000);
  22. #endif
  23. #if(imcUSE_CHECKPOINT_PASS_COUNTER)
  24. if (checkpointCounter == checkpoint_pass_count) {
  25. checkpointCounter = 0;
  26. return 1;
  27. } else {
  28. checkpointCounter++;
  29. return 0;
  30. }
  31. #endif
  32. #if(!imcUSE_CHECKPOINT_VOLTAGE_CHECK && !imcUSE_CHECKPOINT_PASS_COUNTER)
  33. return 1;
  34. #endif
  35. }