example_cargo_reg_protocol_access.c
Go to the documentation of this file.
1 // Copyright (c) Acconeer AB, 2023-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 <stdbool.h>
8 #include <stdint.h>
9 
10 #include "acc_integration.h"
11 #include "acc_version.h"
12 #include "example_cargo.h"
13 
14 #include "acc_reg_protocol.h"
16 #include "i2c_example_cargo.h"
17 
18 /**
19  * @brief Get the protocol error status flags
20  *
21  * @return error flags as uint32 register value
22  */
23 static uint32_t get_protocol_error_flags(void);
24 
25 //
26 // REGISTER READ/WRITE ACCESS FUNCTIONS
27 //
28 
30 {
32 }
33 
34 void example_cargo_reg_read_version(uint32_t *value)
35 {
36  *value = acc_version_get_hex();
37 }
38 
40 {
41  uint32_t error_flags = get_protocol_error_flags();
42  uint32_t protocol_status = 0;
43 
44  if ((error_flags & ACC_REG_ERROR_FLAG_PROTOCOL_STATE_ERROR) != 0)
45  {
47  }
48 
49  if ((error_flags & ACC_REG_ERROR_FLAG_PACKET_LENGTH_ERROR) != 0)
50  {
52  }
53 
54  if ((error_flags & ACC_REG_ERROR_FLAG_ADDRESS_ERROR) != 0)
55  {
57  }
58 
59  if ((error_flags & ACC_REG_ERROR_FLAG_WRITE_FAILED) != 0)
60  {
62  }
63 
64  if ((error_flags & ACC_REG_ERROR_FLAG_WRITE_TO_READ_ONLY) != 0)
65  {
67  }
68 
69  *value = protocol_status;
70 }
71 
73 {
75 }
76 
78 {
80 }
81 
82 bool example_cargo_reg_write_command(const uint32_t value)
83 {
84  return i2c_example_cargo_command(value);
85 }
86 
88 {
90 }
91 
93 {
95 
96  switch (config->container_size)
97  {
99  *value = 10U;
100  break;
102  *value = 20U;
103  break;
105  *value = 40U;
106  break;
107  default:
108  *value = 0U;
109  break;
110  }
111 }
112 
114 {
115  bool status = true;
116 
118 
119  switch (value)
120  {
121  case 10U:
123  break;
124  case 20U:
126  break;
127  case 40U:
129  break;
130  default:
131  status = false;
132  break;
133  }
134  return status;
135 }
136 
138 {
140 
141  *value = (uint32_t)config->activate_utilization_level;
142 }
143 
145 {
147 
148  config->activate_utilization_level = (bool)value;
149 
150  return true;
151 }
152 
154 {
156 
158 }
159 
161 {
163 
165 
166  return true;
167 }
168 
170 {
172 
174 }
175 
177 {
179 
181 
182  return true;
183 }
184 
186 {
188 
189  *value = (bool)config->activate_presence;
190 }
191 
193 {
195 
196  config->activate_presence = (bool)value;
197 
198  return true;
199 }
200 
202 {
204 
206 }
207 
209 {
211 
213 
214  return true;
215 }
216 
218 {
220 
221  *value = (uint32_t)config->presence.sweeps_per_frame;
222 }
223 
225 {
227 
228  config->presence.sweeps_per_frame = (uint16_t)value;
229 
230  return true;
231 }
232 
234 {
236 
238 }
239 
241 {
243 
245 
246  return true;
247 }
248 
250 {
252 
254 }
255 
257 {
259 
261 
262  return true;
263 }
264 
266 {
268 
270 }
271 
273 {
275 
277 
278  return true;
279 }
280 
282 {
283  cargo_result_t result = {0};
284  int16_t temperature = i2c_example_cargo_get_temperature();
285 
286  uint32_t temperature_bits =
288 
290 
291  uint32_t utilization_valid_bit = (((uint32_t)result.utilization_valid) << EXAMPLE_CARGO_REG_RESULT_HEADER_FIELD_UTILIZATION_LEVEL_VALID_POS) &
293 
295 
296  uint32_t presence_valid_bit = (((uint32_t)result.presence_valid) << EXAMPLE_CARGO_REG_RESULT_HEADER_FIELD_PRESENCE_VALID_POS) &
298 
299  uint32_t packed = temperature_bits | utilization_valid_bit | presence_valid_bit;
300  *value = packed;
301 }
302 
304 {
305  cargo_result_t result = {0};
306 
308 
310 }
311 
313 {
314  cargo_result_t result = {0};
315 
317 
319 }
320 
322 {
323  cargo_result_t result = {0};
324 
326 
327  *value = (uint32_t)result.level_percent;
328 }
329 
331 {
332  cargo_result_t result = {0};
333 
335 
336  *value = (uint32_t)result.presence_detected;
337 }
338 
340 {
341  cargo_result_t result = {0};
342 
344 
346 }
347 
349 {
350  cargo_result_t result = {0};
351 
353 
355 }
356 
357 //
358 // PRIVATE HELPER FUNCTIONS
359 //
360 
361 static uint32_t get_protocol_error_flags(void)
362 {
363  /* Make sure we do not have a race for error flags */
365 
366  uint32_t error_flags = acc_reg_protocol_get_error_flags();
367 
369 
370  return error_flags;
371 }
example_cargo_reg_read_application_status
void example_cargo_reg_read_application_status(uint32_t *value)
Definition: example_cargo_reg_protocol_access.c:87
acc_reg_protocol_float_to_uint32_milli
uint32_t acc_reg_protocol_float_to_uint32_milli(float value)
Convert 1000 * float to uint32.
Definition: acc_reg_protocol.c:336
example_cargo_reg_read_result_header
void example_cargo_reg_read_result_header(uint32_t *value)
Definition: example_cargo_reg_protocol_access.c:281
example_cargo_reg_write_utilization_threshold_sensitivity
bool example_cargo_reg_write_utilization_threshold_sensitivity(uint32_t value)
Definition: example_cargo_reg_protocol_access.c:176
cargo_config_t::update_rate
float update_rate
Definition: example_cargo.h:75
get_protocol_error_flags
static uint32_t get_protocol_error_flags(void)
Get the protocol error status flags.
Definition: example_cargo_reg_protocol_access.c:361
example_cargo_reg_read_utilization_threshold_sensitivity
void example_cargo_reg_read_utilization_threshold_sensitivity(uint32_t *value)
Definition: example_cargo_reg_protocol_access.c:169
example_cargo_reg_write_activate_presence
bool example_cargo_reg_write_activate_presence(uint32_t value)
Definition: example_cargo_reg_protocol_access.c:192
cargo_config_t::intra_detection_threshold
float intra_detection_threshold
Definition: example_cargo.h:96
acc_reg_protocol_get_error_flags
uint32_t acc_reg_protocol_get_error_flags(void)
Get the error flags for the register protocol.
Definition: acc_reg_protocol.c:319
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_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
ACC_REG_ERROR_FLAG_PACKET_LENGTH_ERROR
#define ACC_REG_ERROR_FLAG_PACKET_LENGTH_ERROR
Definition: acc_reg_protocol.h:15
acc_version.h
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
EXAMPLE_CARGO_REG_RESULT_HEADER_FIELD_PRESENCE_VALID_POS
#define EXAMPLE_CARGO_REG_RESULT_HEADER_FIELD_PRESENCE_VALID_POS
Definition: example_cargo_reg_protocol.h:102
cargo_config_t::signal_quality
float signal_quality
Definition: example_cargo.h:57
ACC_REG_ERROR_FLAG_ADDRESS_ERROR
#define ACC_REG_ERROR_FLAG_ADDRESS_ERROR
Definition: acc_reg_protocol.h:16
example_cargo_reg_read_actual_presence_update_rate
void example_cargo_reg_read_actual_presence_update_rate(uint32_t *value)
Definition: example_cargo_reg_protocol_access.c:77
cargo_result_t::distance
float distance
Definition: example_cargo.h:118
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
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_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::utilization
struct cargo_config_t::@0 utilization
example_cargo_reg_write_presence_signal_quality
bool example_cargo_reg_write_presence_signal_quality(uint32_t value)
Definition: example_cargo_reg_protocol_access.c:240
acc_integration.h
example_cargo_reg_write_presence_intra_detection_threshold
bool example_cargo_reg_write_presence_intra_detection_threshold(uint32_t value)
Definition: example_cargo_reg_protocol_access.c:272
acc_version_get_hex
uint32_t acc_version_get_hex(void)
Get the version of the Acconeer software as a hex number.
cargo_config_t
Configuration struct for cargo.
Definition: example_cargo.h:43
example_cargo_reg_read_protocol_status
void example_cargo_reg_read_protocol_status(uint32_t *value)
Definition: example_cargo_reg_protocol_access.c:39
example_cargo_reg_read_presence_detected
void example_cargo_reg_read_presence_detected(uint32_t *value)
Definition: example_cargo_reg_protocol_access.c:330
config
cargo_config_t config
Definition: i2c_example_cargo.c:34
cargo_result_t::inter_presence_score
float inter_presence_score
Definition: example_cargo.h:137
example_cargo_reg_read_max_inter_presence_score
void example_cargo_reg_read_max_inter_presence_score(uint32_t *value)
Definition: example_cargo_reg_protocol_access.c:339
example_cargo_reg_read_presence_inter_detection_threshold
void example_cargo_reg_read_presence_inter_detection_threshold(uint32_t *value)
Definition: example_cargo_reg_protocol_access.c:249
cargo_result_t::level_percent
float level_percent
Definition: example_cargo.h:128
cargo_config_t::sweeps_per_frame
uint16_t sweeps_per_frame
Definition: example_cargo.h:80
CARGO_CONTAINER_SIZE_10_FT
@ CARGO_CONTAINER_SIZE_10_FT
Definition: example_cargo.h:35
ACC_REG_ERROR_FLAG_WRITE_FAILED
#define ACC_REG_ERROR_FLAG_WRITE_FAILED
Definition: acc_reg_protocol.h:17
CARGO_CONTAINER_SIZE_40_FT
@ CARGO_CONTAINER_SIZE_40_FT
Definition: example_cargo.h:37
example_cargo.h
EXAMPLE_CARGO_REG_RESULT_HEADER_FIELD_TEMPERATURE_POS
#define EXAMPLE_CARGO_REG_RESULT_HEADER_FIELD_TEMPERATURE_POS
Definition: example_cargo_reg_protocol.h:98
EXAMPLE_CARGO_REG_RESULT_HEADER_FIELD_TEMPERATURE_MASK
#define EXAMPLE_CARGO_REG_RESULT_HEADER_FIELD_TEMPERATURE_MASK
Definition: example_cargo_reg_protocol.h:99
cargo_result_t::utilization_valid
bool utilization_valid
Definition: example_cargo.h:115
example_cargo_reg_read_presence_intra_detection_threshold
void example_cargo_reg_read_presence_intra_detection_threshold(uint32_t *value)
Definition: example_cargo_reg_protocol_access.c:265
cargo_result_t::presence_valid
bool presence_valid
Definition: example_cargo.h:131
EXAMPLE_CARGO_REG_PROTOCOL_STATUS_FIELD_PACKET_LENGTH_ERROR_MASK
#define EXAMPLE_CARGO_REG_PROTOCOL_STATUS_FIELD_PACKET_LENGTH_ERROR_MASK
Definition: example_cargo_reg_protocol.h:51
example_cargo_reg_read_version
void example_cargo_reg_read_version(uint32_t *value)
Definition: example_cargo_reg_protocol_access.c:34
result
cargo_result_t result
Definition: i2c_example_cargo.c:43
cargo_config_t::presence
struct cargo_config_t::@1 presence
example_cargo_reg_write_command
bool example_cargo_reg_write_command(const uint32_t value)
Definition: example_cargo_reg_protocol_access.c:82
example_cargo_reg_read_activate_presence
void example_cargo_reg_read_activate_presence(uint32_t *value)
Definition: example_cargo_reg_protocol_access.c:185
CARGO_CONTAINER_SIZE_20_FT
@ CARGO_CONTAINER_SIZE_20_FT
Definition: example_cargo.h:36
EXAMPLE_CARGO_REG_PROTOCOL_STATUS_FIELD_PROTOCOL_STATE_ERROR_MASK
#define EXAMPLE_CARGO_REG_PROTOCOL_STATUS_FIELD_PROTOCOL_STATE_ERROR_MASK
Definition: example_cargo_reg_protocol.h:49
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_read_utilization_level_percent
void example_cargo_reg_read_utilization_level_percent(uint32_t *value)
Definition: example_cargo_reg_protocol_access.c:321
example_cargo_reg_read_presence_sweeps_per_frame
void example_cargo_reg_read_presence_sweeps_per_frame(uint32_t *value)
Definition: example_cargo_reg_protocol_access.c:217
i2c_example_cargo.h
acc_reg_protocol_uint32_milli_to_float
float acc_reg_protocol_uint32_milli_to_float(uint32_t value)
Convert uint32 / 1000 to float.
Definition: acc_reg_protocol.c:351
example_cargo_reg_write_presence_update_rate
bool example_cargo_reg_write_presence_update_rate(uint32_t value)
Definition: example_cargo_reg_protocol_access.c:208
cargo_config_t::activate_utilization_level
bool activate_utilization_level
Definition: example_cargo.h:49
cargo_result_t::intra_presence_score
float intra_presence_score
Definition: example_cargo.h:140
example_cargo_reg_read_presence_signal_quality
void example_cargo_reg_read_presence_signal_quality(uint32_t *value)
Definition: example_cargo_reg_protocol_access.c:233
example_cargo_reg_read_utilization_signal_quality
void example_cargo_reg_read_utilization_signal_quality(uint32_t *value)
Definition: example_cargo_reg_protocol_access.c:153
ACC_REG_ERROR_FLAG_PROTOCOL_STATE_ERROR
#define ACC_REG_ERROR_FLAG_PROTOCOL_STATE_ERROR
Definition: acc_reg_protocol.h:14
i2c_example_cargo_get_temperature
int16_t i2c_example_cargo_get_temperature(void)
Get most recently measured temperature.
Definition: i2c_example_cargo.c:303
example_cargo_reg_read_utilization_distance
void example_cargo_reg_read_utilization_distance(uint32_t *value)
Definition: example_cargo_reg_protocol_access.c:303
EXAMPLE_CARGO_REG_APPLICATION_ID_ENUM_EXAMPLE_CARGO
#define EXAMPLE_CARGO_REG_APPLICATION_ID_ENUM_EXAMPLE_CARGO
Definition: example_cargo_reg_protocol.h:118
ACC_REG_ERROR_FLAG_WRITE_TO_READ_ONLY
#define ACC_REG_ERROR_FLAG_WRITE_TO_READ_ONLY
Definition: acc_reg_protocol.h:18
example_cargo_reg_write_presence_inter_detection_threshold
bool example_cargo_reg_write_presence_inter_detection_threshold(uint32_t value)
Definition: example_cargo_reg_protocol_access.c:256
acc_reg_protocol.h
acc_integration_critical_section_enter
void acc_integration_critical_section_enter(void)
Definition: acc_integration_cortex.c:9
EXAMPLE_CARGO_REG_RESULT_HEADER_FIELD_UTILIZATION_LEVEL_VALID_POS
#define EXAMPLE_CARGO_REG_RESULT_HEADER_FIELD_UTILIZATION_LEVEL_VALID_POS
Definition: example_cargo_reg_protocol.h:100
cargo_config_t::container_size
cargo_container_size_t container_size
Definition: example_cargo.h:47
example_cargo_reg_read_container_size
void example_cargo_reg_read_container_size(uint32_t *value)
Definition: example_cargo_reg_protocol_access.c:92
example_cargo_reg_read_max_intra_presence_score
void example_cargo_reg_read_max_intra_presence_score(uint32_t *value)
Definition: example_cargo_reg_protocol_access.c:348
EXAMPLE_CARGO_REG_PROTOCOL_STATUS_FIELD_ADDRESS_ERROR_MASK
#define EXAMPLE_CARGO_REG_PROTOCOL_STATUS_FIELD_ADDRESS_ERROR_MASK
Definition: example_cargo_reg_protocol.h:53
cargo_result_t
Result type.
Definition: example_cargo.h:109
EXAMPLE_CARGO_REG_PROTOCOL_STATUS_FIELD_WRITE_FAILED_MASK
#define EXAMPLE_CARGO_REG_PROTOCOL_STATUS_FIELD_WRITE_FAILED_MASK
Definition: example_cargo_reg_protocol.h:55
cargo_result_t::presence_detected
bool presence_detected
Definition: example_cargo.h:134
example_cargo_reg_write_container_size
bool example_cargo_reg_write_container_size(uint32_t value)
Definition: example_cargo_reg_protocol_access.c:113
EXAMPLE_CARGO_REG_PROTOCOL_STATUS_FIELD_WRITE_TO_READ_ONLY_MASK
#define EXAMPLE_CARGO_REG_PROTOCOL_STATUS_FIELD_WRITE_TO_READ_ONLY_MASK
Definition: example_cargo_reg_protocol.h:57
example_cargo_reg_read_measure_counter
void example_cargo_reg_read_measure_counter(uint32_t *value)
Definition: example_cargo_reg_protocol_access.c:72
EXAMPLE_CARGO_REG_RESULT_HEADER_FIELD_UTILIZATION_LEVEL_VALID_MASK
#define EXAMPLE_CARGO_REG_RESULT_HEADER_FIELD_UTILIZATION_LEVEL_VALID_MASK
Definition: example_cargo_reg_protocol.h:101
example_cargo_reg_write_activate_utilization_level
bool example_cargo_reg_write_activate_utilization_level(uint32_t value)
Definition: example_cargo_reg_protocol_access.c:144
cargo_config_t::inter_detection_threshold
float inter_detection_threshold
Definition: example_cargo.h:91
cargo_config_t::threshold_sensitivity
float threshold_sensitivity
Definition: example_cargo.h:65
example_cargo_reg_protocol.h
example_cargo_reg_write_utilization_signal_quality
bool example_cargo_reg_write_utilization_signal_quality(uint32_t value)
Definition: example_cargo_reg_protocol_access.c:160
example_cargo_reg_read_presence_update_rate
void example_cargo_reg_read_presence_update_rate(uint32_t *value)
Definition: example_cargo_reg_protocol_access.c:201
example_cargo_reg_read_application_id
void example_cargo_reg_read_application_id(uint32_t *value)
Definition: example_cargo_reg_protocol_access.c:29
cargo_config_t::activate_presence
bool activate_presence
Definition: example_cargo.h:68
example_cargo_reg_write_presence_sweeps_per_frame
bool example_cargo_reg_write_presence_sweeps_per_frame(uint32_t value)
Definition: example_cargo_reg_protocol_access.c:224
EXAMPLE_CARGO_REG_RESULT_HEADER_FIELD_PRESENCE_VALID_MASK
#define EXAMPLE_CARGO_REG_RESULT_HEADER_FIELD_PRESENCE_VALID_MASK
Definition: example_cargo_reg_protocol.h:103
example_cargo_reg_read_utilization_level_mm
void example_cargo_reg_read_utilization_level_mm(uint32_t *value)
Definition: example_cargo_reg_protocol_access.c:312
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_read_activate_utilization_level
void example_cargo_reg_read_activate_utilization_level(uint32_t *value)
Definition: example_cargo_reg_protocol_access.c:137