i2c_example_cargo.c
Go to the documentation of this file.
1 // Copyright (c) Acconeer AB, 2025
2 // All rights reserved
3 // This file is subject to the terms and conditions defined in the file
4 // 'LICENSES/license_acconeer.txt', (BSD 3-Clause License) which is part
5 // of this source code package.
6 
7 #include <complex.h>
8 #include <stdarg.h>
9 #include <stdbool.h>
10 #include <stdint.h>
11 #include <stdio.h>
12 #include <string.h>
13 
14 #include "acc_definitions_a121.h"
17 #include "acc_integration.h"
18 #include "acc_integration_log.h"
19 #include "acc_rss_a121.h"
20 #include "acc_version.h"
21 #include "example_cargo.h"
22 
23 #include "acc_reg_protocol.h"
25 #include "i2c_application_system.h"
26 #include "i2c_example_cargo.h"
27 
28 #define SENSOR_ID (1U)
29 #define SENSOR_TIMEOUT_MS (10000U)
30 
31 static struct
32 {
40  void *buffer;
41  uint32_t buffer_size;
42 
46 } g_resources;
47 
48 static struct
49 {
52  uint32_t measure_counter;
53 
56 
59 
60 static struct
61 {
67 
68 #define UART_LOG_BUFFER_SIZE 100
69 
70 /**
71  * @brief Get the i2c_detector_command values
72  *
73  * The i2c_application_command is cleared during this read
74  * The read and clear are protected by a critical section
75  *
76  * @return The command sent from the host
77  */
78 static uint32_t get_command(void);
79 
80 /**
81  * @brief Set bits in the i2c_application_status
82  *
83  * The i2c_application_status is protected by a critical section
84  *
85  * @param[in] bit_mask The bit_mask to set
86  */
87 static void application_status_set_bits(uint32_t bit_mask);
88 
89 /**
90  * @brief Clear bits in the i2c_application_status
91  *
92  * The i2c_application_status is protected by a critical section
93  *
94  * @param[in] bit_mask The bit_mask to clear
95  */
96 static void application_status_clr_bits(uint32_t bit_mask);
97 
98 /**
99  * @brief Test bits in the i2c_application_status
100  *
101  * The i2c_application_status is protected by a critical section
102  *
103  * @param[in] bit_mask The bit_mask to test
104  * @return true if all the bits in bit_mask is set in i2c_application_status
105  */
106 static bool application_status_test_bits(uint32_t bit_mask);
107 
108 /**
109  * @brief Create sensor
110  */
111 static void create_sensor(void);
112 
113 /**
114  * @brief Calibrate sensor
115  *
116  * @return true if successful
117  */
118 static bool calibrate_sensor(void);
119 
120 /**
121  * @brief Performs cargo calibration
122  */
123 static bool do_cargo_calibration(bool full_calibration);
124 
125 /**
126  * @brief Enter sensor hibernation state
127  *
128  * @ref exit_hibernate needs to be called before the sensor can measure again.
129  */
130 static bool enter_hibernation(void);
131 
132 /**
133  * @brief Exit sensor hibernation state
134  */
135 static bool exit_hibernation(void);
136 
137 /**
138  * @brief Validate Cargo config for this I2C application
139  *
140  * @return true if config is valid
141  */
142 static bool validate_application_config_for_i2c(void);
143 
144 /**
145  * @brief Apply config
146  *
147  * This function will create the distance- & presence detector and
148  * allocate the needed memory
149  */
150 static void apply_application_config(void);
151 
152 /**
153  * @brief Get next utilization level measurement
154  *
155  * @return true if successful
156  */
157 static bool utilization_get_next(void);
158 
159 /**
160  * @brief Get next presence measurement
161  *
162  * @return true if successful
163  */
164 static bool presence_get_next(void);
165 
166 /**
167  * @brief Reset presence burst result
168  */
169 static void presence_reset_burst_result(void);
170 
171 /**
172  * @brief Update presence brust result
173  */
174 static void presence_update_burst_result(const cargo_result_t *cargo_result);
175 
176 /**
177  * @brief Increment measure counter by one
178  */
179 static void increment_measure_counter(void);
180 
181 /**
182  * @brief Update presence frame estimation
183  */
184 static void update_presence_update_rate_estimate(void);
185 
186 /**
187  * @brief Set most recent temperature to the passed temperature
188  */
189 static void update_most_recent_temperature(int16_t temperature);
190 
191 /**
192  * @brief Try to set module in low power mode
193  */
194 static void module_low_power(void);
195 
196 /**
197  * @brief Print the application result
198  *
199  * Only available when the UART logs have been enabled with ENABLE_UART_LOGS
200  *
201  * @param[in] result The cargo result
202  */
204 
205 /**
206  * @brief UART logging function (can be enabled/disabled by command)
207  */
208 static void uart_log(const char *format, ...);
209 
210 //
211 // PUBLIC FUNCTIONS
212 //
213 
215 {
216  return &(g_resources.config);
217 }
218 
219 bool i2c_example_cargo_command(uint32_t command)
220 {
221  bool status = false;
222 
223  /* Make sure we do not have a race for i2c_application_command/i2c_application_status */
225 
226  if (g_application_state.i2c_application_command == 0U)
227  {
228  /* Set Ready PIN to LOW while processing the command */
230 
231  /* Set status BUSY bit */
233  g_application_state.i2c_application_command = command;
234  status = true;
235  }
236 
238  return status;
239 }
240 
242 {
243  /* Make sure we do not have a race for i2c_application_status */
245 
246  uint32_t status = g_application_state.i2c_application_status;
247 
249 
250  return status;
251 }
252 
254 {
256 
257  uint32_t measure_counter = g_application_state.measure_counter;
258 
260 
261  return measure_counter;
262 }
263 
265 {
267 
268  uint32_t estimated_update_rate_mhz = g_application_state.presence_estimated_frame_rate_mhz;
269 
271 
272  return estimated_update_rate_mhz;
273 }
274 
276 {
278 
279  dst_result->presence_valid = false;
280 
281  dst_result->utilization_valid = g_resources.result.utilization_valid;
282  dst_result->distance = g_resources.result.distance;
283  dst_result->level_m = g_resources.result.level_m;
284  dst_result->level_percent = g_resources.result.level_percent;
285 
287 }
288 
290 {
292 
293  dst_result->utilization_valid = false;
294 
295  dst_result->presence_valid = g_presence_burst_result.presence_valid;
296  dst_result->presence_detected = g_presence_burst_result.presence_detected;
297  dst_result->inter_presence_score = g_presence_burst_result.max_inter_presence_score;
298  dst_result->intra_presence_score = g_presence_burst_result.max_intra_presence_score;
299 
301 }
302 
304 {
306 
307  int16_t temperature = g_resources.most_recent_temperature;
308 
310 
311  return temperature;
312 }
313 
314 //
315 // MAIN
316 //
317 
318 int acconeer_main(int argc, char *argv[]);
319 
320 int acconeer_main(int argc, char *argv[])
321 {
322  (void)argc;
323  (void)argv;
324 
325  bool setup_status = true;
326 
327  printf("I2C Example Cargo\n");
328  printf("Acconeer software version %s\n", acc_version_get());
329 
331 
332  if (acc_rss_hal_register(hal))
333  {
335  }
336  else
337  {
338  printf("ERROR: acc_rss_hal_register() failed\n\n");
341  setup_status = false;
342  }
343 
344  if (setup_status)
345  {
347  }
348 
349  /* Turn the sensor on */
351 
352  if (setup_status)
353  {
354  /* Create sensor */
355  create_sensor();
356  }
357 
359 
360  /* Setup i2c register protocol */
362 
363  while (true)
364  {
365 
366  /* Handle Commands */
367  uint32_t command = get_command();
368 
369  if (command == 0) // no command
370  {
372  {
373  /* If wakeup is HIGH do WFI */
375  }
376  else
377  {
378  /* If wakeup is LOW do SLEEP */
379 
380  /* Set ready pin LOW, we are about to power down */
382 
383  uart_log("Enter low power state\n");
385 
386  /* We will restart here when WAKEUP goes HIGH */
387 
388  uart_log("Exit low power state\n");
389  }
391 
392  /* No command to process */
393  continue;
394  }
395  /* Special command, always handle reset module command, even if error has occured */
397  {
398  /* Reset system */
400  continue;
401  }
402 
404  {
405  /* Do not process commands after error state */
406  continue;
407  }
408 
409  /* Handle command */
410  switch (command)
411  {
414  {
415  // Apply configuration
417  }
418  break;
421 
422  if (utilization_get_next())
423  {
425  }
426  else
427  {
428  printf("ERROR: Could not get next result\n");
430  }
431 
433  break;
436 
438  g_resources.sensor,
439  &g_resources.sensor_cal_result,
440  g_resources.buffer,
441  g_resources.buffer_size))
442  {
443  printf("ERROR: cargo_prepare_presence() failed\n");
445  }
446  else
447  {
448  if (!enter_hibernation())
449  {
451  }
452  else
453  {
454  uint32_t sleep_time_ms = (uint32_t)(1000.0f / g_resources.config.presence.update_rate);
456 
458 
459  do
460  {
462 
464  {
466 
467  if (presence_get_next())
468  {
471  }
472  else
473  {
474  printf("ERROR: Could not get next result\n");
476  }
477  }
478 
481 
483  }
484  }
485 
486  i2c_application_set_periodic_wakeup(0U); // disable periodic wakeup
487 
489  break;
491  g_application_state.uart_logs_enabed = true;
492  uart_log("UART logs enabled\n");
493  break;
495  g_application_state.uart_logs_enabed = false;
496  uart_log("UART logs disabled\n");
497  break;
499  cargo_config_log(&g_resources.config);
500  break;
501  default:
502  printf("ERROR: Unknown command: %" PRIu32 "", command);
503  break;
504  }
505 
506  /* Command handling done, clear busy bit */
508 
509  /* Set Ready PIN to HIGH when command processing is done */
511  }
512 
513  return EXIT_FAILURE;
514 }
515 
516 //
517 // PRIVATE HELPER FUNCTIONS
518 //
519 
520 static uint32_t get_command(void)
521 {
522  /* Make sure we do not have a race for i2c_application_command */
524 
525  uint32_t command = g_application_state.i2c_application_command;
526 
527  g_application_state.i2c_application_command = 0U;
528 
530 
531  return command;
532 }
533 
534 static void application_status_set_bits(uint32_t bit_mask)
535 {
536  /* Make sure we do not have a race for i2c_application_status */
538 
539  g_application_state.i2c_application_status |= bit_mask;
540  uint32_t temp_application_status = g_application_state.i2c_application_status;
541 
543 
544  uart_log("Application Status = 0x%" PRIx32 "\n", temp_application_status);
545 }
546 
547 static void application_status_clr_bits(uint32_t bit_mask)
548 {
549  /* Make sure we do not have a race for i2c_application_status */
551 
552  g_application_state.i2c_application_status &= ~bit_mask;
553  uint32_t temp_application_status = g_application_state.i2c_application_status;
554 
556 
557  uart_log("Application Status = 0x%" PRIx32 "\n", temp_application_status);
558 }
559 
560 static bool application_status_test_bits(uint32_t bit_mask)
561 {
562  /* Make sure we do not have a race for i2c_application_status */
564 
565  bool status = (g_application_state.i2c_application_status & bit_mask) == bit_mask;
566 
568 
569  return status;
570 }
571 
572 static void create_sensor(void)
573 {
575 
577 
579 
580  if (g_resources.sensor != NULL)
581  {
583  }
584  else
585  {
588  printf("ERROR: acc_sensor_create() failed\n");
589  }
590 }
591 
592 static bool calibrate_sensor(void)
593 {
595 
598 
599  bool status;
600  bool cal_complete = false;
601 
602  do
603  {
604  status = acc_sensor_calibrate(g_resources.sensor, &cal_complete, &g_resources.sensor_cal_result, g_resources.buffer, g_resources.buffer_size);
605 
606  if (cal_complete)
607  {
608  break;
609  }
610 
611  if (status)
612  {
614  }
615  } while (status);
616 
617  if (status)
618  {
620  }
621  else
622  {
624  printf("ERROR: acc_sensor_calibrate() failed\n");
625  }
626 
627  /* Reset sensor after calibration by disabling it */
629 
630  return status;
631 }
632 
633 static bool do_cargo_calibration(bool full_calibration)
634 {
635  bool status = true;
636  bool calibration_done = false;
637 
640 
642 
643  while (status && !calibration_done)
644  {
645  if (full_calibration)
646  {
647  status = cargo_calibrate(g_resources.handle,
648  g_resources.sensor,
649  &(g_resources.sensor_cal_result),
650  g_resources.buffer,
651  g_resources.buffer_size,
652  g_resources.distance_cal_result_static,
653  g_resources.distance_cal_result_static_size,
654  &(g_resources.distance_cal_result_dynamic),
655  &calibration_done);
656  }
657  else
658  {
659  status = cargo_update_calibration(g_resources.handle,
660  g_resources.sensor,
661  &(g_resources.sensor_cal_result),
662  g_resources.buffer,
663  g_resources.buffer_size,
664  &(g_resources.distance_cal_result_dynamic),
665  &calibration_done);
666  }
667 
668  if (status && !calibration_done)
669  {
671  }
672  }
673 
674  if (status)
675  {
677  }
678  else
679  {
681  }
682  return status;
683 }
684 
685 static bool enter_hibernation(void)
686 {
687  bool status = true;
688 
690  {
691  printf("ERROR: acc_sensor_hibernate_on failed\n");
692  status = false;
693  }
694 
696  return status;
697 }
698 
699 static bool exit_hibernation(void)
700 {
701  bool status = true;
702 
705  {
706  printf("ERROR: acc_sensor_hibernate_off failed\n");
707  status = false;
708  }
709 
710  return status;
711 }
712 
713 static void apply_application_config(void)
714 {
715  g_resources.config.presence.rate_is_app_driven = true;
716 
717  bool status = validate_application_config_for_i2c();
718 
719  if (status)
720  {
721  g_resources.handle = cargo_handle_create(&g_resources.config);
722  if (g_resources.handle != NULL)
723  {
725  }
726  else
727  {
730  printf("ERROR: cargo_handle_create() failed\n");
731  status = false;
732  }
733  }
734 
735  if (status)
736  {
737  if (cargo_get_buffer_size(g_resources.handle, &g_resources.buffer_size))
738  {
740  }
741  else
742  {
745  printf("ERROR: cargo_get_buffer_size() failed\n");
746  status = false;
747  }
748  }
749 
750  if (status)
751  {
752  g_resources.buffer = acc_integration_mem_alloc(g_resources.buffer_size);
753  if (g_resources.buffer != NULL)
754  {
756  }
757  else
758  {
761  printf("ERROR: sensor buffer allocation failed\n");
762  status = false;
763  }
764  }
765 
766  if (status)
767  {
768  if (cargo_get_distance_cal_result_static_size(g_resources.handle, &(g_resources.distance_cal_result_static_size)))
769  {
771  }
772  else
773  {
776  printf("ERROR: cargo_get_distance_cal_result_static_size() failed\n");
777  status = false;
778  }
779  }
780 
781  if (status && (g_resources.distance_cal_result_static_size > 0U))
782  {
783  g_resources.distance_cal_result_static = acc_integration_mem_alloc(g_resources.distance_cal_result_static_size);
784  if (g_resources.buffer != NULL)
785  {
787  }
788  else
789  {
792  printf("ERROR: Cargo buffer allocation failed\n");
793  status = false;
794  }
795  }
796 
797  if (status)
798  {
799  status = calibrate_sensor();
800  }
801 
802  if (status)
803  {
804  status = do_cargo_calibration(true);
805  }
806 
807  if (status)
808  {
810  }
811  else
812  {
813  printf("ERROR: apply application config failed\n");
816  }
817 }
818 
820 {
821  /* Hibernate is used in this I2C application, which is most optimal <10Hz */
822  if (g_resources.config.presence.update_rate > 10.0f)
823  {
824  printf("Presence update rate should be lower than 10Hz for optimal current consumption.\n");
825  }
826 
827  return true;
828 }
829 
830 static bool utilization_get_next()
831 {
832  bool status = true;
833 
835  g_resources.sensor,
836  &g_resources.sensor_cal_result,
837  g_resources.buffer,
838  g_resources.buffer_size))
839  {
840  status = false;
841  printf("ERROR: cargo_prepare_utilization() failed\n");
842  }
843 
844  if (status)
845  {
846  if (!acc_sensor_measure(g_resources.sensor))
847  {
848  printf("ERROR: acc_sensor_measure() failed\n");
849  status = false;
850  }
851  }
852 
853  if (status)
854  {
856  {
857  printf("ERROR: Sensor interrupt timeout\n");
858  status = false;
859  }
860  }
861 
862  if (status)
863  {
864  if (!acc_sensor_read(g_resources.sensor, g_resources.buffer, g_resources.buffer_size))
865  {
866  printf("ERROR: acc_sensor_read() failed\n");
867  status = false;
868  }
869  }
870 
871  acc_detector_distance_result_t distance_result = {0};
872 
873  if (status)
874  {
875  bool result_available = false;
876 
878  g_resources.distance_cal_result_static,
879  &(g_resources.distance_cal_result_dynamic),
880  g_resources.buffer,
881  &g_resources.result,
882  &result_available,
883  &distance_result))
884  {
885  printf("ERROR: cargo_process_utilization() failed\n");
886  status = false;
887  }
888  else
889  {
890  g_resources.utilization_result_available = result_available;
891  }
892  }
893 
894  if (status)
895  {
897 
899 
900  if (g_resources.result.calibration_needed)
901  {
902  uart_log("Recalibration\n");
903 
905 
906  status = calibrate_sensor();
907 
908  if (status)
909  {
911  }
912 
913  if (status)
914  {
915  status = do_cargo_calibration(false); // only a calibration update is needed here.
916  }
917  }
918  }
919 
920  return status;
921 }
922 
923 static bool presence_get_next(void)
924 {
925  bool status = exit_hibernation();
926 
927  if (status)
928  {
929  if (!acc_sensor_measure(g_resources.sensor))
930  {
931  printf("ERROR: acc_sensor_measure() failed\n");
932  status = false;
933  }
934  }
935 
936  if (status)
937  {
939  {
940  printf("ERROR: Sensor interrupt timeout\n");
941  status = false;
942  }
943  }
944 
945  if (status)
946  {
947  if (!acc_sensor_read(g_resources.sensor, g_resources.buffer, g_resources.buffer_size))
948  {
949  printf("ERROR: acc_sensor_read() failed\n");
950  status = false;
951  }
952  }
953 
954  if (status)
955  {
956  status = enter_hibernation();
957  }
958 
959  acc_detector_presence_result_t presence_result = {0};
960 
961  if (status)
962  {
963  if (!cargo_process_presence(g_resources.handle, g_resources.buffer, &g_resources.result, &presence_result))
964  {
965  printf("ERROR: cargo_process_presence() failed\n");
966  status = false;
967  }
968  }
969 
970  if (status)
971  {
973 
975 
976  if (g_resources.result.calibration_needed)
977  {
978  uart_log("Recalibration\n");
979 
981 
982  status = calibrate_sensor();
983 
984  if (status)
985  {
987  }
988  }
989  }
990 
991  return status;
992 }
993 
995 {
997 
998  g_presence_burst_result.presence_valid = false;
999  g_presence_burst_result.presence_detected = false;
1000  g_presence_burst_result.max_inter_presence_score = 0.0f;
1001  g_presence_burst_result.max_intra_presence_score = 0.0f;
1002 
1004 }
1005 
1006 static void presence_update_burst_result(const cargo_result_t *cargo_result)
1007 {
1009 
1010  if (cargo_result->presence_valid)
1011  {
1012  g_presence_burst_result.presence_valid = true;
1013 
1014  if (cargo_result->presence_detected)
1015  {
1016  g_presence_burst_result.presence_detected = true;
1017  }
1018 
1019  if (cargo_result->inter_presence_score > g_presence_burst_result.max_inter_presence_score)
1020  {
1021  g_presence_burst_result.max_inter_presence_score = cargo_result->inter_presence_score;
1022  }
1023 
1024  if (cargo_result->intra_presence_score > g_presence_burst_result.max_intra_presence_score)
1025  {
1026  g_presence_burst_result.max_intra_presence_score = cargo_result->intra_presence_score;
1027  }
1028  }
1029 
1031 }
1032 
1033 static void increment_measure_counter(void)
1034 {
1035  /* Make sure we do not have a race for the measure counter */
1037 
1038  g_application_state.measure_counter++;
1039 
1041 
1042  printf("measure_counter is now %" PRIu32 "\n", g_application_state.measure_counter);
1043 }
1044 
1046 {
1048 
1049  uint32_t time_ms = acc_integration_get_time();
1050  uint32_t diff_ms = time_ms - g_application_state.presence_last_tick_ms;
1051  g_application_state.presence_last_tick_ms = time_ms;
1052  g_application_state.presence_estimated_frame_rate_mhz = (diff_ms > 0) ? (1000000 / diff_ms) : 0;
1053 
1055 }
1056 
1057 static void update_most_recent_temperature(int16_t temperature)
1058 {
1060 
1061  g_resources.most_recent_temperature = temperature;
1062 
1064 }
1065 
1066 static void module_low_power(void)
1067 {
1069  {
1071  }
1072  else
1073  {
1074  /* Set ready pin LOW, we are about to power down */
1076 
1077  uart_log("Enter low power state\n");
1079  uart_log("Exit low power state\n");
1080  }
1081 
1083  {
1084  /* Set ready pin HIGH, we are ready for a command */
1086  }
1087 }
1088 
1090 {
1091  if (g_application_state.uart_logs_enabed)
1092  {
1094  {
1095  uart_log("Utilization Distance: %" PRIfloat " ", ACC_LOG_FLOAT_TO_INTEGER(result->distance));
1096  uart_log("Level (m): %" PRIfloat " ", ACC_LOG_FLOAT_TO_INTEGER(result->level_m));
1098  uart_log("\n");
1099  }
1100 
1101  if (result->presence_valid)
1102  {
1103  uart_log("Presence detected: %s ", result->presence_detected ? "True" : "False");
1104 
1106  {
1107  uart_log("Inter Presence Score: %" PRIfloat " ", ACC_LOG_FLOAT_TO_INTEGER(result->inter_presence_score));
1108  uart_log("Intra Presence Score: %" PRIfloat " ", ACC_LOG_FLOAT_TO_INTEGER(result->intra_presence_score));
1109  }
1110  uart_log("\n");
1111  }
1112  }
1113 }
1114 
1115 static void uart_log(const char *format, ...)
1116 {
1117  char log_buffer[UART_LOG_BUFFER_SIZE];
1118 
1119  va_list ap;
1120 
1121  va_start(ap, format);
1122 
1123  if (g_application_state.uart_logs_enabed)
1124  {
1125  int ret = vsnprintf(log_buffer, UART_LOG_BUFFER_SIZE, format, ap);
1126 
1127  if (ret >= UART_LOG_BUFFER_SIZE)
1128  {
1129  log_buffer[UART_LOG_BUFFER_SIZE - 4] = '.';
1130  log_buffer[UART_LOG_BUFFER_SIZE - 3] = '.';
1131  log_buffer[UART_LOG_BUFFER_SIZE - 2] = '.';
1132  log_buffer[UART_LOG_BUFFER_SIZE - 1] = 0;
1133  }
1134 
1135  printf("%s", log_buffer);
1136  }
1137 
1138  va_end(ap);
1139 }
utilization_get_next
static bool utilization_get_next(void)
Get next utilization level measurement.
Definition: i2c_example_cargo.c:830
acc_detector_distance_result_t::processing_result
acc_processing_result_t * processing_result
Definition: acc_detector_distance.h:105
EXAMPLE_CARGO_REG_APPLICATION_STATUS_FIELD_BUSY_MASK
#define EXAMPLE_CARGO_REG_APPLICATION_STATUS_FIELD_BUSY_MASK
Definition: example_cargo_reg_protocol.h:95
acc_rss_a121.h
EXAMPLE_CARGO_REG_APPLICATION_STATUS_FIELD_CONFIG_APPLY_ERROR_MASK
#define EXAMPLE_CARGO_REG_APPLICATION_STATUS_FIELD_CONFIG_APPLY_ERROR_MASK
Definition: example_cargo_reg_protocol.h:91
module_low_power
static void module_low_power(void)
Try to set module in low power mode.
Definition: i2c_example_cargo.c:1066
presence_reset_burst_result
static void presence_reset_burst_result(void)
Reset presence burst result.
Definition: i2c_example_cargo.c:994
max_inter_presence_score
float max_inter_presence_score
Definition: i2c_example_cargo.c:64
cargo_handle_create
cargo_handle_t * cargo_handle_create(const cargo_config_t *cargo_config)
Create a cargo handle.
Definition: example_cargo.c:164
acc_hal_integration_sensor_supply_on
void acc_hal_integration_sensor_supply_on(acc_sensor_id_t sensor_id)
Power on sensor supply.
Definition: acc_hal_integration_stm32cube_xm.c:99
measure_counter
uint32_t measure_counter
Definition: i2c_example_cargo.c:52
distance_cal_result_static_size
uint32_t distance_cal_result_static_size
Definition: i2c_example_cargo.c:39
cargo_process_presence
bool cargo_process_presence(cargo_handle_t *handle, void *buffer, cargo_result_t *cargo_result, acc_detector_presence_result_t *nullable_presence_result)
Process Sparse IQ data into a Cargo result.
Definition: example_cargo.c:558
acc_integration_get_time
uint32_t acc_integration_get_time(void)
Get current time.
Definition: acc_integration_stm32.c:587
i2c_example_cargo_get_temperature
int16_t i2c_example_cargo_get_temperature(void)
Get most recently measured temperature.
Definition: i2c_example_cargo.c:303
i2c_example_cargo_get_config
cargo_config_t * i2c_example_cargo_get_config(void)
Get pointer to internal cargo config struct.
Definition: i2c_example_cargo.c:214
EXAMPLE_CARGO_REG_COMMAND_ENUM_RESET_MODULE
#define EXAMPLE_CARGO_REG_COMMAND_ENUM_RESET_MODULE
Definition: example_cargo_reg_protocol.h:112
acc_sensor_read
bool acc_sensor_read(const acc_sensor_t *sensor, void *buffer, uint32_t buffer_size)
Read out radar data.
cargo_prepare_presence
bool cargo_prepare_presence(cargo_handle_t *handle, acc_sensor_t *sensor, const acc_cal_result_t *sensor_cal_result, void *buffer, uint32_t buffer_size)
Prepare Cargo presence for measurements.
Definition: example_cargo.c:423
buffer
void * buffer
Definition: i2c_example_cargo.c:40
vsnprintf
#define vsnprintf
Definition: printf.h:85
acc_version.h
sensor_cal_result
acc_cal_result_t sensor_cal_result
Definition: i2c_example_cargo.c:36
i2c_application_system_reset
void i2c_application_system_reset(void)
Reset the system.
Definition: i2c_application_system_stm32.c:158
EXAMPLE_CARGO_REG_APPLICATION_STATUS_FIELD_SENSOR_CALIBRATE_OK_MASK
#define EXAMPLE_CARGO_REG_APPLICATION_STATUS_FIELD_SENSOR_CALIBRATE_OK_MASK
Definition: example_cargo_reg_protocol.h:65
most_recent_temperature
int16_t most_recent_temperature
Definition: i2c_example_cargo.c:44
i2c_example_cargo_get_status
uint32_t i2c_example_cargo_get_status(void)
Get cargo example app status.
Definition: i2c_example_cargo.c:241
i2c_example_cargo_copy_presence_burst_result_fields
void i2c_example_cargo_copy_presence_burst_result_fields(cargo_result_t *dst_result)
Copy presence example app cargo result.
Definition: i2c_example_cargo.c:289
EXAMPLE_CARGO_REG_APPLICATION_STATUS_FIELD_SENSOR_CALIBRATE_ERROR_MASK
#define EXAMPLE_CARGO_REG_APPLICATION_STATUS_FIELD_SENSOR_CALIBRATE_ERROR_MASK
Definition: example_cargo_reg_protocol.h:81
acc_detector_presence_result_t::processing_result
acc_processing_result_t processing_result
Definition: acc_detector_presence.h:82
cargo_result_t::distance
float distance
Definition: example_cargo.h:118
apply_application_config
static void apply_application_config(void)
Apply config.
Definition: i2c_example_cargo.c:713
acc_cal_result_t
The result from a completed calibration.
Definition: acc_definitions_a121.h:30
distance_cal_result_static
uint8_t * distance_cal_result_static
Definition: i2c_example_cargo.c:38
application_status_clr_bits
static void application_status_clr_bits(uint32_t bit_mask)
Clear bits in the i2c_application_status.
Definition: i2c_example_cargo.c:547
EXAMPLE_CARGO_REG_APPLICATION_STATUS_FIELD_SENSOR_CREATE_OK_MASK
#define EXAMPLE_CARGO_REG_APPLICATION_STATUS_FIELD_SENSOR_CREATE_OK_MASK
Definition: example_cargo_reg_protocol.h:63
acc_integration_critical_section_exit
void acc_integration_critical_section_exit(void)
Definition: acc_integration_cortex.c:16
cargo_result_t::level_m
float level_m
Definition: example_cargo.h:123
i2c_example_cargo_get_actual_presence_update_rate
uint32_t i2c_example_cargo_get_actual_presence_update_rate(void)
Get the estimated presence update rate of the.
Definition: i2c_example_cargo.c:264
EXAMPLE_CARGO_REG_APPLICATION_STATUS_FIELD_CARGO_BUFFER_OK_MASK
#define EXAMPLE_CARGO_REG_APPLICATION_STATUS_FIELD_CARGO_BUFFER_OK_MASK
Definition: example_cargo_reg_protocol.h:73
g_presence_burst_result
static struct @4 g_presence_burst_result
update_most_recent_temperature
static void update_most_recent_temperature(int16_t temperature)
Set most recent temperature to the passed temperature.
Definition: i2c_example_cargo.c:1057
acc_integration.h
cargo_config_initialize
void cargo_config_initialize(cargo_config_t *cargo_config, cargo_preset_t preset)
Initialize cargo config struct with a preset.
Definition: example_cargo.c:80
i2c_example_cargo_get_measure_counter
uint32_t i2c_example_cargo_get_measure_counter(void)
Get the count of number of measurements performed.
Definition: i2c_example_cargo.c:253
cargo_config_t
Configuration struct for cargo.
Definition: example_cargo.h:43
application_status_set_bits
static void application_status_set_bits(uint32_t bit_mask)
Set bits in the i2c_application_status.
Definition: i2c_example_cargo.c:534
SENSOR_ID
#define SENSOR_ID
Definition: i2c_example_cargo.c:28
config
cargo_config_t config
Definition: i2c_example_cargo.c:34
example_cargo_reg_protocol_setup
void example_cargo_reg_protocol_setup(void)
Definition: example_cargo_reg_protocol.c:142
cargo_result_t::inter_presence_score
float inter_presence_score
Definition: example_cargo.h:137
acc_hal_rss_integration_get_implementation
const acc_hal_a121_t * acc_hal_rss_integration_get_implementation(void)
Get hal implementation reference.
Definition: acc_hal_integration_stm32cube_xm.c:152
i2c_example_cargo_command
bool i2c_example_cargo_command(uint32_t command)
Send command to be executed to cargo i2c app.
Definition: i2c_example_cargo.c:219
get_command
static uint32_t get_command(void)
Get the i2c_detector_command values.
Definition: i2c_example_cargo.c:520
validate_application_config_for_i2c
static bool validate_application_config_for_i2c(void)
Validate Cargo config for this I2C application.
Definition: i2c_example_cargo.c:819
cargo_result_t::level_percent
float level_percent
Definition: example_cargo.h:128
acc_integration_mem_alloc
void * acc_integration_mem_alloc(size_t size)
Allocate dynamic memory.
Definition: acc_integration_stm32.c:592
i2c_application_command
uint32_t i2c_application_command
Definition: i2c_example_cargo.c:50
acc_hal_a121_t
Definition: acc_hal_definitions_a121.h:82
i2c_application_status
uint32_t i2c_application_status
Definition: i2c_example_cargo.c:51
increment_measure_counter
static void increment_measure_counter(void)
Increment measure counter by one.
Definition: i2c_example_cargo.c:1033
create_sensor
static void create_sensor(void)
Create sensor.
Definition: i2c_example_cargo.c:572
EXAMPLE_CARGO_REG_APPLICATION_STATUS_FIELD_CARGO_CALIBRATE_ERROR_MASK
#define EXAMPLE_CARGO_REG_APPLICATION_STATUS_FIELD_CARGO_CALIBRATE_ERROR_MASK
Definition: example_cargo_reg_protocol.h:85
acc_rss_hal_register
bool acc_rss_hal_register(const acc_hal_a121_t *hal)
Register an integration.
i2c_application_system_wait_for_interrupt
void i2c_application_system_wait_for_interrupt(void)
Wait for interrupt to occur.
Definition: i2c_application_system_stm32.c:169
acc_detector_presence_result_t
Presence detector results container.
Definition: acc_detector_presence.h:46
buffer_size
uint32_t buffer_size
Definition: i2c_example_cargo.c:41
acc_detector_cal_result_dynamic_t
The result from a completed calibration update.
Definition: acc_detector_distance_definitions.h:23
sensor
acc_sensor_t * sensor
Definition: i2c_example_cargo.c:33
update_presence_update_rate_estimate
static void update_presence_update_rate_estimate(void)
Update presence frame estimation.
Definition: i2c_example_cargo.c:1045
g_application_state
static struct @3 g_application_state
cargo_calibrate
bool cargo_calibrate(cargo_handle_t *handle, acc_sensor_t *sensor, const acc_cal_result_t *sensor_cal_result, void *buffer, uint32_t buffer_size, uint8_t *distance_cal_result_static, uint32_t distance_cal_result_static_size, acc_detector_cal_result_dynamic_t *distance_cal_result_dynamic, bool *calibration_complete)
Calibrate Cargo.
Definition: example_cargo.c:318
presence_update_burst_result
static void presence_update_burst_result(const cargo_result_t *cargo_result)
Update presence brust result.
Definition: i2c_example_cargo.c:1006
example_cargo.h
presence_detected
bool presence_detected
Definition: i2c_example_cargo.c:63
EXAMPLE_CARGO_REG_APPLICATION_STATUS_FIELD_CARGO_CALIBRATE_OK_MASK
#define EXAMPLE_CARGO_REG_APPLICATION_STATUS_FIELD_CARGO_CALIBRATE_OK_MASK
Definition: example_cargo_reg_protocol.h:69
acc_hal_integration_wait_for_sensor_interrupt
bool acc_hal_integration_wait_for_sensor_interrupt(acc_sensor_id_t sensor_id, uint32_t timeout_ms)
Wait for a sensor interrupt.
Definition: acc_hal_integration_stm32cube_xm.c:130
cargo_result_t::utilization_valid
bool utilization_valid
Definition: example_cargo.h:115
acc_hal_integration_a121.h
utilization_result_available
bool utilization_result_available
Definition: i2c_example_cargo.c:45
handle
cargo_handle_t * handle
Definition: i2c_example_cargo.c:35
i2c_application_system.h
cargo_result_t::presence_valid
bool presence_valid
Definition: example_cargo.h:131
acc_sensor_hibernate_off
bool acc_sensor_hibernate_off(const acc_sensor_t *sensor)
Restore sensor after exiting hibernation.
result
cargo_result_t result
Definition: i2c_example_cargo.c:43
application_status_test_bits
static bool application_status_test_bits(uint32_t bit_mask)
Test bits in the i2c_application_status.
Definition: i2c_example_cargo.c:560
acc_version_get
const char * acc_version_get(void)
Get the version of the Acconeer software.
acconeer_main
int acconeer_main(int argc, char *argv[])
Assembly test example.
Definition: i2c_example_cargo.c:320
uart_logs_enabed
bool uart_logs_enabed
Definition: i2c_example_cargo.c:57
printf
#define printf
Definition: printf.h:60
EXAMPLE_CARGO_REG_COMMAND_ENUM_MEASURE_UTILIZATION_LEVEL
#define EXAMPLE_CARGO_REG_COMMAND_ENUM_MEASURE_UTILIZATION_LEVEL
Definition: example_cargo_reg_protocol.h:107
i2c_application_enter_low_power_state
void i2c_application_enter_low_power_state(void)
Make the MCU enter its low power state.
Definition: i2c_application_system_stm32.c:215
acc_hal_integration_sensor_enable
void acc_hal_integration_sensor_enable(acc_sensor_id_t sensor_id)
Enable sensor.
Definition: acc_hal_integration_stm32cube_xm.c:109
acc_hal_definitions_a121.h
EXAMPLE_CARGO_REG_APPLICATION_STATUS_FIELD_CARGO_CREATE_ERROR_MASK
#define EXAMPLE_CARGO_REG_APPLICATION_STATUS_FIELD_CARGO_CREATE_ERROR_MASK
Definition: example_cargo_reg_protocol.h:83
EXAMPLE_CARGO_REG_APPLICATION_STATUS_FIELD_CARGO_CREATE_OK_MASK
#define EXAMPLE_CARGO_REG_APPLICATION_STATUS_FIELD_CARGO_CREATE_OK_MASK
Definition: example_cargo_reg_protocol.h:67
uart_log
static void uart_log(const char *format,...)
UART logging function (can be enabled/disabled by command)
Definition: i2c_example_cargo.c:1115
cargo_get_buffer_size
bool cargo_get_buffer_size(const cargo_handle_t *handle, uint32_t *buffer_size)
Get the required buffer sensor data buffer size.
Definition: example_cargo.c:272
cargo_get_distance_cal_result_static_size
bool cargo_get_distance_cal_result_static_size(const cargo_handle_t *handle, uint32_t *distance_cal_result_static_size)
Get the required buffer for static distance detector calibration.
Definition: example_cargo.c:298
enter_hibernation
static bool enter_hibernation(void)
Enter sensor hibernation state.
Definition: i2c_example_cargo.c:685
EXAMPLE_CARGO_REG_COMMAND_ENUM_MEASURE_PRESENCE
#define EXAMPLE_CARGO_REG_COMMAND_ENUM_MEASURE_PRESENCE
Definition: example_cargo_reg_protocol.h:108
i2c_example_cargo.h
SENSOR_TIMEOUT_MS
#define SENSOR_TIMEOUT_MS
Definition: i2c_example_cargo.c:29
EXAMPLE_CARGO_REG_APPLICATION_STATUS_FIELD_SENSOR_BUFFER_ERROR_MASK
#define EXAMPLE_CARGO_REG_APPLICATION_STATUS_FIELD_SENSOR_BUFFER_ERROR_MASK
Definition: example_cargo_reg_protocol.h:87
acc_detector_distance_result_t
Distance Detector result returned from acc_detector_distance_process.
Definition: acc_detector_distance.h:48
EXAMPLE_CARGO_REG_APPLICATION_STATUS_FIELD_CONFIG_APPLY_OK_MASK
#define EXAMPLE_CARGO_REG_APPLICATION_STATUS_FIELD_CONFIG_APPLY_OK_MASK
Definition: example_cargo_reg_protocol.h:75
i2c_application_system_set_ready_pin
void i2c_application_system_set_ready_pin(bool enable)
Set the ready pin state.
Definition: i2c_application_system_stm32.c:181
cargo_result_t::intra_presence_score
float intra_presence_score
Definition: example_cargo.h:140
acc_hal_integration_sensor_disable
void acc_hal_integration_sensor_disable(acc_sensor_id_t sensor_id)
Disable sensor.
Definition: acc_hal_integration_stm32cube_xm.c:119
i2c_application_set_periodic_wakeup
void i2c_application_set_periodic_wakeup(uint32_t period_ms)
Set up a periodic timer used to wake up the system from sleep.
Definition: i2c_application_system_stm32.c:238
acc_integration_log.h
EXAMPLE_CARGO_REG_COMMAND_ENUM_LOG_CONFIGURATION
#define EXAMPLE_CARGO_REG_COMMAND_ENUM_LOG_CONFIGURATION
Definition: example_cargo_reg_protocol.h:111
acc_sensor_hibernate_on
bool acc_sensor_hibernate_on(acc_sensor_t *sensor)
Prepare sensor for entering hibernation.
ACC_LOG_FLOAT_TO_INTEGER
#define ACC_LOG_FLOAT_TO_INTEGER(a)
Definition: acc_integration_log.h:26
exit_hibernation
static bool exit_hibernation(void)
Exit sensor hibernation state.
Definition: i2c_example_cargo.c:699
EXAMPLE_CARGO_REG_APPLICATION_STATUS_FIELD_APPLICATION_ERROR_MASK
#define EXAMPLE_CARGO_REG_APPLICATION_STATUS_FIELD_APPLICATION_ERROR_MASK
Definition: example_cargo_reg_protocol.h:93
calibrate_sensor
static bool calibrate_sensor(void)
Calibrate sensor.
Definition: i2c_example_cargo.c:592
i2c_application_system_init
void i2c_application_system_init(void)
Init the system.
Definition: i2c_application_system_stm32.c:130
cargo_config_log
void cargo_config_log(const cargo_config_t *cargo_config)
Log cargo config to debug uart.
Definition: example_cargo.c:135
i2c_example_cargo_copy_utilization_result_fields
void i2c_example_cargo_copy_utilization_result_fields(cargo_result_t *dst_result)
Copy utilization example app cargo result.
Definition: i2c_example_cargo.c:275
max_intra_presence_score
float max_intra_presence_score
Definition: i2c_example_cargo.c:65
EXAMPLE_CARGO_REG_APPLICATION_STATUS_FIELD_CARGO_BUFFER_ERROR_MASK
#define EXAMPLE_CARGO_REG_APPLICATION_STATUS_FIELD_CARGO_BUFFER_ERROR_MASK
Definition: example_cargo_reg_protocol.h:89
acc_reg_protocol.h
i2c_application_is_periodic_wakeup
bool i2c_application_is_periodic_wakeup(void)
Test if a periodic wake up has occurred.
Definition: i2c_application_system_stm32.c:244
acc_integration_critical_section_enter
void acc_integration_critical_section_enter(void)
Definition: acc_integration_cortex.c:9
EXAMPLE_CARGO_REG_COMMAND_ENUM_ENABLE_UART_LOGS
#define EXAMPLE_CARGO_REG_COMMAND_ENUM_ENABLE_UART_LOGS
Definition: example_cargo_reg_protocol.h:109
presence_estimated_frame_rate_mhz
uint32_t presence_estimated_frame_rate_mhz
Definition: i2c_example_cargo.c:55
do_cargo_calibration
static bool do_cargo_calibration(bool full_calibration)
Performs cargo calibration.
Definition: i2c_example_cargo.c:633
acc_processing_result_t::temperature
int16_t temperature
Definition: acc_processing.h:89
EXAMPLE_CARGO_REG_APPLICATION_STATUS_FIELD_RSS_REGISTER_OK_MASK
#define EXAMPLE_CARGO_REG_APPLICATION_STATUS_FIELD_RSS_REGISTER_OK_MASK
Definition: example_cargo_reg_protocol.h:61
cargo_process_utilization
bool cargo_process_utilization(cargo_handle_t *handle, uint8_t *distance_cal_result_static, acc_detector_cal_result_dynamic_t *distance_cal_result_dynamic, void *buffer, cargo_result_t *cargo_result, bool *result_available, acc_detector_distance_result_t *nullable_distance_result)
Process Sparse IQ data into a Cargo result.
Definition: example_cargo.c:462
g_resources
static struct @2 g_resources
log_cargo_result_on_uart
static void log_cargo_result_on_uart(const cargo_result_t *result)
Print the application result.
Definition: i2c_example_cargo.c:1089
EXAMPLE_CARGO_REG_COMMAND_ENUM_APPLY_CONFIGURATION
#define EXAMPLE_CARGO_REG_COMMAND_ENUM_APPLY_CONFIGURATION
Definition: example_cargo_reg_protocol.h:106
distance_cal_result_dynamic
acc_detector_cal_result_dynamic_t distance_cal_result_dynamic
Definition: i2c_example_cargo.c:37
cargo_current_mode_get
cargo_mode_t cargo_current_mode_get(const cargo_handle_t *handle)
Get current mode of the cargo handle.
Definition: example_cargo.c:622
EXAMPLE_CARGO_REG_APPLICATION_STATUS_FIELD_SENSOR_CREATE_ERROR_MASK
#define EXAMPLE_CARGO_REG_APPLICATION_STATUS_FIELD_SENSOR_CREATE_ERROR_MASK
Definition: example_cargo_reg_protocol.h:79
cargo_handle
Cargo handle.
Definition: example_cargo.c:27
acc_sensor_calibrate
bool acc_sensor_calibrate(acc_sensor_t *sensor, bool *cal_complete, acc_cal_result_t *cal_result, void *buffer, uint32_t buffer_size)
Calibrate a sensor.
UART_LOG_BUFFER_SIZE
#define UART_LOG_BUFFER_SIZE
Definition: i2c_example_cargo.c:68
PRIfloat
#define PRIfloat
Specifier for printing float type using integers.
Definition: acc_integration_log.h:31
cargo_result_t
Result type.
Definition: example_cargo.h:109
cargo_result_t::presence_detected
bool presence_detected
Definition: example_cargo.h:134
presence_valid
bool presence_valid
Definition: i2c_example_cargo.c:62
presence_last_tick_ms
uint32_t presence_last_tick_ms
Definition: i2c_example_cargo.c:54
EXAMPLE_CARGO_REG_COMMAND_ENUM_DISABLE_UART_LOGS
#define EXAMPLE_CARGO_REG_COMMAND_ENUM_DISABLE_UART_LOGS
Definition: example_cargo_reg_protocol.h:110
CARGO_PRESET_NO_LENS
@ CARGO_PRESET_NO_LENS
Definition: example_cargo.h:27
acc_sensor_measure
bool acc_sensor_measure(acc_sensor_t *sensor)
Start a radar measurement with previously prepared configuration.
cargo_update_calibration
bool cargo_update_calibration(cargo_handle_t *handle, acc_sensor_t *sensor, const acc_cal_result_t *sensor_cal_result, void *buffer, uint32_t buffer_size, acc_detector_cal_result_dynamic_t *distance_cal_result_dynamic, bool *calibration_complete)
Update Cargo calibration.
Definition: example_cargo.c:353
i2c_application_system_test_wakeup_pin
bool i2c_application_system_test_wakeup_pin(void)
Check if wakeup pin is high.
Definition: i2c_application_system_stm32.c:174
cargo_prepare_utilization
bool cargo_prepare_utilization(cargo_handle_t *handle, acc_sensor_t *sensor, const acc_cal_result_t *sensor_cal_result, void *buffer, uint32_t buffer_size)
Prepare Cargo utilization for measurements.
Definition: example_cargo.c:384
acc_sensor_t
struct acc_sensor acc_sensor_t
Definition: acc_sensor.h:31
example_cargo_reg_protocol.h
EXAMPLE_CARGO_REG_APPLICATION_STATUS_FIELD_SENSOR_BUFFER_OK_MASK
#define EXAMPLE_CARGO_REG_APPLICATION_STATUS_FIELD_SENSOR_BUFFER_OK_MASK
Definition: example_cargo_reg_protocol.h:71
acc_definitions_a121.h
CARGO_MODE_PRESENCE
@ CARGO_MODE_PRESENCE
Definition: example_cargo.h:157
presence_get_next
static bool presence_get_next(void)
Get next presence measurement.
Definition: i2c_example_cargo.c:923
acc_sensor_create
acc_sensor_t * acc_sensor_create(acc_sensor_id_t sensor_id)
Create a sensor instance.