imc_kernel.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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_IMC_EXTENSION)
  7. #include "ImC/imc_extension.h"
  8. #endif
  9. #if(imcUSE_CHECKPOINT_VOLTAGE_CHECK)
  10. extern ADC_HandleTypeDef ADC_HANDLER_SBC;
  11. #endif
  12. #if(imcUSE_CHECKPOINT_PASS_COUNTER)
  13. int checkpointCounter = 0;
  14. const int checkpoint_pass_count = imcCHECKPOINT_PASS_COUNT;
  15. #endif
  16. void imcInit()
  17. {
  18. FPU->FPCCR &= ~(FPU_FPCCR_LSPEN_Msk); // turn off lazy stacking
  19. #if(imcUSE_IMC_EXTENSION)
  20. imc_init_energy_estimation();
  21. #endif
  22. }
  23. int needCheckpointExecution() {
  24. #if(imcPRINT_STATS)
  25. imc_checkpoint_triggered++;
  26. #endif
  27. #if(imcUSE_CHECKPOINT_VOLTAGE_CHECK)
  28. int capacitor_voltage0 = measure_voltage(ADC_HANDLER_SBC, EPS_CAP_ID_SBC);
  29. return capacitor_voltage0 < imcCHECKPOINT_VOLTAGE;
  30. printf("\t\t\t\t\t\t[EPS] CAP VOLT: %d.%03d\r\n", capacitor_voltage0 / 1000, capacitor_voltage0 % 1000);
  31. #endif
  32. #if(imcUSE_CHECKPOINT_PASS_COUNTER)
  33. if (checkpointCounter == checkpoint_pass_count) {
  34. checkpointCounter = 0;
  35. return 1;
  36. } else {
  37. checkpointCounter++;
  38. return 0;
  39. }
  40. #endif
  41. #if(!imcUSE_CHECKPOINT_VOLTAGE_CHECK && !imcUSE_CHECKPOINT_PASS_COUNTER)
  42. return 1;
  43. #endif
  44. }