example_bring_up.c
Go to the documentation of this file.
1 // Copyright (c) Acconeer AB, 2022-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 #include <stdio.h>
10 #include <stdlib.h>
11
12 #include "acc_definitions_a121.h"
13 #include "acc_definitions_common.h"
14 #include "acc_hal_definitions_a121.h"
15 #include "acc_hal_integration_a121.h"
16 #include "acc_integration.h"
17 #include "acc_rss_a121.h"
18 #include "acc_version.h"
19
20 /** \example example_bring_up.c
21 * @brief This is an example on how the assembly test can be used to ease bring-up
22 * @n
23 * The example executes as follows:
24 * - Register the RSS HAL
25 * - Create assembly test
26 * - Enable one assembly test at a time
27 * - Power on the sensor
28 * - Enable the sensor
29 * - Exceute assembly test
30 * - Disable the sensor
31 * - Power off the sensor
32 * - Destroy assembly test
33 */
34
35 #define SENSOR_ID (1U)
36
37 #define SENSOR_TIMEOUT_MS (1000U)
38
39 static bool run_test(acc_rss_assembly_test_t *assembly_test, acc_sensor_id_t sensor_id);
40
41 int acconeer_main(int argc, char *argv[]);
42
43 int acconeer_main(int argc, char *argv[])
44 {
45 (void)argc;
46 (void)argv;
47
48 bool test_ok = true;
49
50 printf("Acconeer software version %s\n", acc_version_get());
51
52 const acc_hal_a121_t *hal = acc_hal_rss_integration_get_implementation();
53
54 if (!acc_rss_hal_register(hal))
55 {
56 return EXIT_FAILURE;
57 }
58
59 void *buffer = acc_integration_mem_alloc(ACC_RSS_ASSEMBLY_TEST_MIN_BUFFER_SIZE);
60 if (buffer == NULL)
61 {
62 printf("Assembly test: Memory allocation failed\n");
63 return EXIT_FAILURE;
64 }
65
66 // Create
67 acc_rss_assembly_test_t *assembly_test = acc_rss_assembly_test_create(SENSOR_ID, buffer, ACC_RSS_ASSEMBLY_TEST_MIN_BUFFER_SIZE);
68 if (assembly_test == NULL)
69 {
70 printf("Bring-up: Could not create assembly test\n");
71 acc_integration_mem_free(buffer);
72 return EXIT_FAILURE;
73 }
74
75 // Enable and run: Basic read test
76 acc_rss_assembly_test_disable_all_tests(assembly_test);
77 acc_rss_assembly_test_enable(assembly_test, ACC_RSS_ASSEMBLY_TEST_ID_BASIC_READ);
78 if (!run_test(assembly_test, SENSOR_ID))
79 {
80 printf("Bring-up: Basic read test failed\n");
81 test_ok = false;
82 }
83
84 // Enable and run: Communication test
85 acc_rss_assembly_test_disable_all_tests(assembly_test);
86 acc_rss_assembly_test_enable(assembly_test, ACC_RSS_ASSEMBLY_TEST_ID_COMMUNICATION);
87 if (!run_test(assembly_test, SENSOR_ID))
88 {
89 printf("Bring-up: Communication test failed\n");
90 test_ok = false;
91 }
92
93 // Enable and run: Enable test
94 acc_rss_assembly_test_disable_all_tests(assembly_test);
95 acc_rss_assembly_test_enable(assembly_test, ACC_RSS_ASSEMBLY_TEST_ID_ENABLE_PIN);
96 if (!run_test(assembly_test, SENSOR_ID))
97 {
98 printf("Bring-up: Enable test failed\n");
99 test_ok = false;
100 }
101
102 // Enable and run: Interrupt test
103 acc_rss_assembly_test_disable_all_tests(assembly_test);
104 acc_rss_assembly_test_enable(assembly_test, ACC_RSS_ASSEMBLY_TEST_ID_INTERRUPT);
105 if (!run_test(assembly_test, SENSOR_ID))
106 {
107 printf("Bring-up: Interrupt test failed\n");
108 test_ok = false;
109 }
110
111 // Enable and run: Clock and Supply test
112 acc_rss_assembly_test_disable_all_tests(assembly_test);
113 acc_rss_assembly_test_enable(assembly_test, ACC_RSS_ASSEMBLY_TEST_ID_CLOCK_AND_SUPPLY);
114 if (!run_test(assembly_test, SENSOR_ID))
115 {
116 printf("Bring-up: Clock and Supply test failed\n");
117 test_ok = false;
118 }
119
120 // Enable and run: Sensor calibration test
121 acc_rss_assembly_test_disable_all_tests(assembly_test);
122 acc_rss_assembly_test_enable(assembly_test, ACC_RSS_ASSEMBLY_TEST_ID_SENSOR_CALIBRATION);
123 if (!run_test(assembly_test, SENSOR_ID))
124 {
125 printf("Bring-up: Calibration test failed\n");
126 test_ok = false;
127 }
128
129 // Destroy
130 acc_rss_assembly_test_destroy(assembly_test);
131
132 if (buffer != NULL)
133 {
134 acc_integration_mem_free(buffer);
135 }
136
137 if (test_ok)
138 {
139 printf("Bring-up: All tests passed\n");
140
141 printf("Application finished OK\n");
142 return EXIT_SUCCESS;
143 }
144
145 return EXIT_FAILURE;
146 }
147
148 static bool run_test(acc_rss_assembly_test_t *assembly_test, acc_sensor_id_t sensor_id)
149 {
150 bool all_passed = true;
151
152 acc_hal_integration_sensor_supply_on(sensor_id);
153 acc_hal_integration_sensor_enable(sensor_id);
154
155 acc_rss_test_state_t assembly_test_state = ACC_RSS_TEST_STATE_ONGOING;
156 acc_rss_test_integration_status_t integration_status = ACC_RSS_TEST_INTEGRATION_STATUS_OK;
157
158 do
159 {
160 assembly_test_state = acc_rss_assembly_test_execute(assembly_test, integration_status);
161
162 switch (assembly_test_state)
163 {
164 case ACC_RSS_TEST_STATE_TOGGLE_ENABLE_PIN:
165 acc_hal_integration_sensor_disable(sensor_id);
166 acc_hal_integration_sensor_enable(sensor_id);
167 integration_status = ACC_RSS_TEST_INTEGRATION_STATUS_OK;
168 break;
169 case ACC_RSS_TEST_STATE_WAIT_FOR_INTERRUPT:
170 if (!acc_hal_integration_wait_for_sensor_interrupt(sensor_id, SENSOR_TIMEOUT_MS))
171 {
172 /* Wait for interrupt failed */
173 integration_status = ACC_RSS_TEST_INTEGRATION_STATUS_TIMEOUT;
174 }
175 else
176 {
177 integration_status = ACC_RSS_TEST_INTEGRATION_STATUS_OK;
178 }
179
180 break;
181 default:
182 integration_status = ACC_RSS_TEST_INTEGRATION_STATUS_OK;
183 break;
184 }
185 } while (assembly_test_state != ACC_RSS_TEST_STATE_COMPLETE);
186
187 acc_hal_integration_sensor_disable(sensor_id);
188 acc_hal_integration_sensor_supply_off(sensor_id);
189
190 uint16_t nbr_of_test_results = 0U;
191
192 const acc_rss_assembly_test_result_t *test_results = acc_rss_assembly_test_get_results(assembly_test, &nbr_of_test_results);
193
194 for (uint16_t idx = 0; idx < nbr_of_test_results; idx++)
195 {
196 printf("Bring-up: '%s' [%s]\n", test_results[idx].test_name, test_results[idx].test_result ? "PASS" : "FAIL");
197 if (!test_results[idx].test_result)
198 {
199 all_passed = false;
200 }
201 }
202
203 return all_passed;
204 }
ACC_RSS_TEST_STATE_WAIT_FOR_INTERRUPT
@ ACC_RSS_TEST_STATE_WAIT_FOR_INTERRUPT
Definition: acc_rss_a121.h:41
acc_rss_assembly_test_result_t
The result struct of acc_rss_assembly_test.
Definition: acc_rss_a121.h:85
acc_rss_assembly_test_execute
acc_rss_test_state_t acc_rss_assembly_test_execute(acc_rss_assembly_test_t *assembly_test, acc_rss_test_integration_status_t integration_status)
Execute the assembly test.
acc_hal_integration_sensor_supply_off
void acc_hal_integration_sensor_supply_off(acc_sensor_id_t sensor_id)
Power off sensor supply.
Definition: acc_hal_integration_stm32cube_xm.c:104
acc_rss_a121.h
acc_rss_assembly_test_get_results
const acc_rss_assembly_test_result_t * acc_rss_assembly_test_get_results(const acc_rss_assembly_test_t *assembly_test, uint16_t *nbr_of_test_results)
A function to get the results from the sensor assembly test.
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
ACC_RSS_ASSEMBLY_TEST_ID_ENABLE_PIN
@ ACC_RSS_ASSEMBLY_TEST_ID_ENABLE_PIN
Definition: acc_rss_a121.h:71
buffer
void * buffer
Definition: i2c_example_cargo.c:40
acc_version.h
ACC_RSS_ASSEMBLY_TEST_ID_CLOCK_AND_SUPPLY
@ ACC_RSS_ASSEMBLY_TEST_ID_CLOCK_AND_SUPPLY
Definition: acc_rss_a121.h:75
ACC_RSS_ASSEMBLY_TEST_ID_BASIC_READ
@ ACC_RSS_ASSEMBLY_TEST_ID_BASIC_READ
Definition: acc_rss_a121.h:67
ACC_RSS_TEST_INTEGRATION_STATUS_TIMEOUT
@ ACC_RSS_TEST_INTEGRATION_STATUS_TIMEOUT
Definition: acc_rss_a121.h:56
ACC_RSS_ASSEMBLY_TEST_ID_SENSOR_CALIBRATION
@ ACC_RSS_ASSEMBLY_TEST_ID_SENSOR_CALIBRATION
Definition: acc_rss_a121.h:77
acc_integration.h
ACC_RSS_ASSEMBLY_TEST_MIN_BUFFER_SIZE
#define ACC_RSS_ASSEMBLY_TEST_MIN_BUFFER_SIZE
The minimum buffer size needed for the assembly test.
Definition: acc_rss_a121.h:27
acc_rss_assembly_test_destroy
void acc_rss_assembly_test_destroy(acc_rss_assembly_test_t *assembly_test)
Destroy a sensor assembly test instance freeing any resources allocated.
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
acc_integration_mem_alloc
void * acc_integration_mem_alloc(size_t size)
Allocate dynamic memory.
Definition: acc_integration_stm32.c:592
SENSOR_ID
#define SENSOR_ID
Definition: example_bring_up.c:35
acc_hal_a121_t
Definition: acc_hal_definitions_a121.h:82
acc_rss_hal_register
bool acc_rss_hal_register(const acc_hal_a121_t *hal)
Register an integration.
ACC_RSS_TEST_INTEGRATION_STATUS_OK
@ ACC_RSS_TEST_INTEGRATION_STATUS_OK
Definition: acc_rss_a121.h:54
acc_rss_assembly_test_create
acc_rss_assembly_test_t * acc_rss_assembly_test_create(acc_sensor_id_t sensor_id, void *buffer, uint32_t buffer_size)
Create a sensor assembly test instance.
SENSOR_TIMEOUT_MS
#define SENSOR_TIMEOUT_MS
Definition: example_bring_up.c:37
ACC_RSS_TEST_STATE_ONGOING
@ ACC_RSS_TEST_STATE_ONGOING
Definition: acc_rss_a121.h:37
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
acc_hal_integration_a121.h
acc_version_get
const char * acc_version_get(void)
Get the version of the Acconeer software.
printf
#define printf
Definition: printf.h:60
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
ACC_RSS_TEST_STATE_COMPLETE
@ ACC_RSS_TEST_STATE_COMPLETE
Definition: acc_rss_a121.h:43
ACC_RSS_ASSEMBLY_TEST_ID_COMMUNICATION
@ ACC_RSS_ASSEMBLY_TEST_ID_COMMUNICATION
Definition: acc_rss_a121.h:69
acc_rss_test_state_t
acc_rss_test_state_t
Return code for rss tests.
Definition: acc_rss_a121.h:34
acconeer_main
int acconeer_main(int argc, char *argv[])
Assembly test example.
Definition: example_bring_up.c:43
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
acc_sensor_id_t
uint32_t acc_sensor_id_t
Type representing a sensor ID.
Definition: acc_definitions_common.h:13
acc_rss_test_integration_status_t
acc_rss_test_integration_status_t
Integration status for rss tests.
Definition: acc_rss_a121.h:51
acc_rss_assembly_test_t
struct acc_rss_assembly_test acc_rss_assembly_test_t
Definition: acc_rss_a121.h:98
acc_rss_assembly_test_disable_all_tests
void acc_rss_assembly_test_disable_all_tests(acc_rss_assembly_test_t *assembly_test)
Disable all assembly tests.
ACC_RSS_TEST_STATE_TOGGLE_ENABLE_PIN
@ ACC_RSS_TEST_STATE_TOGGLE_ENABLE_PIN
Definition: acc_rss_a121.h:39
acc_integration_mem_free
void acc_integration_mem_free(void *ptr)
Free dynamic memory.
Definition: acc_integration_stm32.c:602
acc_definitions_common.h
ACC_RSS_ASSEMBLY_TEST_ID_INTERRUPT
@ ACC_RSS_ASSEMBLY_TEST_ID_INTERRUPT
Definition: acc_rss_a121.h:73
run_test
static bool run_test(acc_rss_assembly_test_t *assembly_test, acc_sensor_id_t sensor_id)
Definition: example_bring_up.c:148
acc_rss_assembly_test_enable
void acc_rss_assembly_test_enable(acc_rss_assembly_test_t *assembly_test, acc_rss_assembly_test_test_id_t test_id)
Enable a test in assembly test.
acc_definitions_a121.h