|
@@ -1,11 +1,58 @@
|
|
|
#include <stdio.h>
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
+#include "ImC/imc_kernel.h"
|
|
|
#include "ImC/imc_extension.h"
|
|
#include "ImC/imc_extension.h"
|
|
|
|
|
+#include "ImC/imc_api.h"
|
|
|
|
|
+
|
|
|
|
|
+extern ADC_HandleTypeDef ADC_HANDLER_SBC;
|
|
|
|
|
+
|
|
|
|
|
+float loop_energy_estimation[imcMAX_LOOP_IDS] IMC_GLOBAL;
|
|
|
|
|
+int imc_is_passing_loops IMC_GLOBAL;
|
|
|
|
|
+int imc_energy_estimation_initialized IMC_GLOBAL;
|
|
|
|
|
+
|
|
|
|
|
+void imc_init_energy_estimation() {
|
|
|
|
|
+ if(!imc_energy_estimation_initialized) {
|
|
|
|
|
+ for(int i=0; i<imcMAX_LOOP_IDS; i++) {
|
|
|
|
|
+ loop_energy_estimation[i] = 0.1;
|
|
|
|
|
+ }
|
|
|
|
|
+ imc_energy_estimation_initialized = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ if(imc_is_passing_loops != -1) {
|
|
|
|
|
+ float current_estimation = loop_energy_estimation[imc_is_passing_loops];
|
|
|
|
|
+ current_estimation *= 2;
|
|
|
|
|
+ if(current_estimation > 1) current_estimation = 1;
|
|
|
|
|
+ loop_energy_estimation[imc_is_passing_loops] = current_estimation;
|
|
|
|
|
+ // printf("estimation for loop%d is updated to %f\r\n", imc_is_passing_loops, current_estimation);
|
|
|
|
|
+ }
|
|
|
|
|
+ imc_is_passing_loops = -1;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void __imc_finish_loop_skipping() {
|
|
|
|
|
+ if(imc_is_passing_loops >= 0) {
|
|
|
|
|
+ int volt = measure_voltage(ADC_HANDLER_SBC, EPS_CAP_ID_SBC);
|
|
|
|
|
+ float energy_available = (float)(volt * volt - imcCAP_VOL_LOW * imcCAP_VOL_LOW) / imcENERGY_TOTAL;
|
|
|
|
|
+ if(energy_available > 0.2) {
|
|
|
|
|
+ float current_estimation = loop_energy_estimation[imc_is_passing_loops];
|
|
|
|
|
+ current_estimation /= 2;
|
|
|
|
|
+ loop_energy_estimation[imc_is_passing_loops] = current_estimation;
|
|
|
|
|
+ // printf("estimation for loop%d is updated to %f\r\n", imc_is_passing_loops, current_estimation);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ imc_is_passing_loops = -1;
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
int __imc_get_loop_pass_count(int loop_id) {
|
|
int __imc_get_loop_pass_count(int loop_id) {
|
|
|
// printf("__imc_get_loop_pass_count() called\r\n");
|
|
// printf("__imc_get_loop_pass_count() called\r\n");
|
|
|
#if(imcENABLE_STATIC_LOOP_PASS_COUNT)
|
|
#if(imcENABLE_STATIC_LOOP_PASS_COUNT)
|
|
|
return imcLOOP_PASS_COUNT;
|
|
return imcLOOP_PASS_COUNT;
|
|
|
|
|
+ #elif(imcENABLE_ADAPTIVE_LOOP_PASS_COUNT)
|
|
|
|
|
+ int volt = measure_voltage(ADC_HANDLER_SBC, EPS_CAP_ID_SBC);
|
|
|
|
|
+ float energy_available = (float)(volt*volt - imcCAP_VOL_LOW*imcCAP_VOL_LOW) / imcENERGY_TOTAL;
|
|
|
|
|
+ imc_is_passing_loops = loop_id;
|
|
|
|
|
+ // printf("energy available: %f\r\n", energy_available);
|
|
|
|
|
+ if(energy_available > 1) return (int)(energy_available / loop_energy_estimation[loop_id]);
|
|
|
|
|
+ else if(energy_available < 0) return 0;
|
|
|
|
|
+ else return (int)(energy_available / loop_energy_estimation[loop_id]);
|
|
|
#else
|
|
#else
|
|
|
return 0;
|
|
return 0;
|
|
|
#endif
|
|
#endif
|