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