imc_kernel.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. #if(imcPRINT_STATS)
  22. if(first_checkpoint == -1) {
  23. no_forward_progress += 1;
  24. imc_backup_stats();
  25. }
  26. first_checkpoint = -1;
  27. #endif
  28. #endif
  29. }
  30. int needCheckpointExecution() {
  31. #if(imcPRINT_STATS)
  32. imc_checkpoint_triggered++;
  33. #endif
  34. #if(imcUSE_CHECKPOINT_VOLTAGE_CHECK)
  35. int capacitor_voltage0 = measure_voltage(ADC_HANDLER_SBC, EPS_CAP_ID_SBC);
  36. return capacitor_voltage0 < imcCHECKPOINT_VOLTAGE;
  37. printf("\t\t\t\t\t\t[EPS] CAP VOLT: %d.%03d\r\n", capacitor_voltage0 / 1000, capacitor_voltage0 % 1000);
  38. #endif
  39. #if(imcUSE_CHECKPOINT_PASS_COUNTER)
  40. if (checkpointCounter == checkpoint_pass_count) {
  41. checkpointCounter = 0;
  42. return 1;
  43. } else {
  44. checkpointCounter++;
  45. return 0;
  46. }
  47. #endif
  48. #if(!imcUSE_CHECKPOINT_VOLTAGE_CHECK && !imcUSE_CHECKPOINT_PASS_COUNTER)
  49. return 1;
  50. #endif
  51. }
  52. void HAL_GPIO_EXTI_Falling_Callback(uint16_t GPIO_Pin) {
  53. // if(GPIO_Pin == GPIO_PIN_9 || GPIO_Pin == GPIO_PIN_3) {
  54. // HAL_GPIO_WritePin(GPIOF, GPIO_PIN_11, GPIO_PIN_SET);
  55. // printf("interrupt (falling)\r\n");
  56. // }
  57. HAL_GPIO_WritePin(GPIOF, GPIO_PIN_11, GPIO_PIN_SET);
  58. }
  59. // void HAL_GPIO_EXTI_Rising_Callback(uint16_t GPIO_Pin) {
  60. // if(GPIO_Pin == GPIO_PIN_9 || GPIO_Pin == GPIO_PIN_3) {
  61. // HAL_GPIO_WritePin(GPIOF, GPIO_PIN_11, GPIO_PIN_SET);
  62. // printf("interrupt (rising)\r\n");
  63. // }
  64. // }