example_diagnostic_test.c
Go to the documentation of this file.
1 // Copyright (c) Acconeer AB, 2022-2024
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_diagnostic_test.c
21 * @brief This is an example on how to use RSS to execute the diagnostic test
22 * @n
23 * The example executes as follows:
24 * - Register the RSS HAL
25 * - Power on the sensor
26 * - Create diagnostic test
27 * - Enable the sensor
28 * - Execute diagnostic test
29 * - Destroy diagnostic test
30 * - Disable the sensor
31 * - Power off the sensor
32 */
33
34 #define SENSOR_ID (1U)
35
36 #define SENSOR_TIMEOUT_MS (1000U)
37
38 int acconeer_main(int argc, char *argv[]);
39
40 int acconeer_main(int argc, char *argv[])
41 {
42 (void)argc;
43 (void)argv;
44
45 bool test_ok = true;
46
47 printf("Acconeer software version %s\n", acc_version_get());
48
49 const acc_hal_a121_t *hal = acc_hal_rss_integration_get_implementation();
50
51 if (!acc_rss_hal_register(hal))
52 {
53 return EXIT_FAILURE;
54 }
55
56 void *buffer = acc_integration_mem_alloc(ACC_RSS_ASSEMBLY_TEST_MIN_BUFFER_SIZE);
57 if (buffer == NULL)
58 {
59 printf("Diagnostic test: Memory allocation failed\n");
60 return EXIT_FAILURE;
61 }
62
63 acc_rss_test_state_t test_state = ACC_RSS_TEST_STATE_ONGOING;
64 acc_rss_test_integration_status_t integration_status = ACC_RSS_TEST_INTEGRATION_STATUS_OK;
65
66 acc_rss_assembly_test_t *assembly_test = acc_rss_assembly_test_create(SENSOR_ID, buffer, ACC_RSS_ASSEMBLY_TEST_MIN_BUFFER_SIZE);
67
68 if (assembly_test != NULL)
69 {
70 /* Enable all tests */
71 acc_rss_assembly_test_enable_all_tests(assembly_test);
72
73 /* Enable the diagnostic logs from the assembly test */
74 acc_rss_assembly_test_enable_diagnostic_logs();
75
76 acc_hal_integration_sensor_supply_on(SENSOR_ID);
77 acc_hal_integration_sensor_enable(SENSOR_ID);
78
79 do
80 {
81 test_state = acc_rss_assembly_test_execute(assembly_test, integration_status);
82
83 switch (test_state)
84 {
85 case ACC_RSS_TEST_STATE_TOGGLE_ENABLE_PIN:
86 acc_hal_integration_sensor_disable(SENSOR_ID);
87 acc_hal_integration_sensor_enable(SENSOR_ID);
88 integration_status = ACC_RSS_TEST_INTEGRATION_STATUS_OK;
89 break;
90 case ACC_RSS_TEST_STATE_WAIT_FOR_INTERRUPT:
91 if (!acc_hal_integration_wait_for_sensor_interrupt(SENSOR_ID, SENSOR_TIMEOUT_MS))
92 {
93 /* Wait for interrupt failed */
94 integration_status = ACC_RSS_TEST_INTEGRATION_STATUS_TIMEOUT;
95 }
96
97 break;
98 default:
99 integration_status = ACC_RSS_TEST_INTEGRATION_STATUS_OK;
100 break;
101 }
102 } while (test_state != ACC_RSS_TEST_STATE_COMPLETE);
103
104 acc_rss_assembly_test_destroy(assembly_test);
105
106 acc_hal_integration_sensor_disable(SENSOR_ID);
107 acc_hal_integration_sensor_supply_off(SENSOR_ID);
108 }
109 else
110 {
111 printf("Diagnostic test: Could not create assembly test\n");
112 test_ok = false;
113 }
114
115 if (buffer != NULL)
116 {
117 acc_integration_mem_free(buffer);
118 }
119
120 if (test_ok)
121 {
122 printf("Diagnostic test completed\n");
123
124 printf("Application finished OK\n");
125 return EXIT_SUCCESS;
126 }
127
128 return EXIT_FAILURE;
129 }
ACC_RSS_TEST_STATE_WAIT_FOR_INTERRUPT
@ ACC_RSS_TEST_STATE_WAIT_FOR_INTERRUPT
Definition: acc_rss_a121.h:41
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_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
buffer
void * buffer
Definition: i2c_example_cargo.c:40
acc_version.h
SENSOR_ID
#define SENSOR_ID
Definition: example_diagnostic_test.c:34
ACC_RSS_TEST_INTEGRATION_STATUS_TIMEOUT
@ ACC_RSS_TEST_INTEGRATION_STATUS_TIMEOUT
Definition: acc_rss_a121.h:56
acc_rss_assembly_test_enable_diagnostic_logs
void acc_rss_assembly_test_enable_diagnostic_logs(void)
Enable diagnostic logs for the assembly test,.
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
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.
ACC_RSS_TEST_STATE_ONGOING
@ ACC_RSS_TEST_STATE_ONGOING
Definition: acc_rss_a121.h:37
acc_rss_assembly_test_enable_all_tests
void acc_rss_assembly_test_enable_all_tests(acc_rss_assembly_test_t *assembly_test)
Enable all assembly tests.
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
SENSOR_TIMEOUT_MS
#define SENSOR_TIMEOUT_MS
Definition: example_diagnostic_test.c:36
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
acconeer_main
int acconeer_main(int argc, char *argv[])
Assembly test example.
Definition: example_diagnostic_test.c:40
acc_rss_test_state_t
acc_rss_test_state_t
Return code for rss tests.
Definition: acc_rss_a121.h:34
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_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_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_definitions_a121.h