OPTIGA™ Trust M
Host Library Documentation
optiga_example.h
Go to the documentation of this file.
1
39
#ifndef _OPTIGA_EXAMPLE_H_
40
#define _OPTIGA_EXAMPLE_H_
41
42
#ifdef __cplusplus
43
extern
"C"
{
44
#endif
45
#include "
optiga/optiga_lib_config.h
"
46
#include "
optiga/common/optiga_lib_logger.h
"
47
48
extern
char
performance_buffer_string
[30];
49
extern
void
example_performance_measurement
(uint32_t* time_value, uint8_t time_reset_flag);
50
51
#define START_TIMER (TRUE)
52
53
#define STOPTIMER_AND_CALCULATE (FALSE)
54
55
// Macro to enable logger for Application
56
#define OPTIGA_LIB_ENABLE_EXAMPLE_LOGGING
57
58
// Logger levels
59
#define OPTIGA_EXAMPLE "[optiga example] : "
60
61
// Logger color for different layers and data
62
#define OPTIGA_EXAMPLE_COLOR OPTIGA_LIB_LOGGER_COLOR_DEFAULT
63
64
//Start timer for performance measurement
65
#define START_PERFORMANCE_MEASUREMENT(time_taken) example_performance_measurement(&time_taken, START_TIMER)
66
67
//Stop timer and calculate performance measurement
68
#define READ_PERFORMANCE_MEASUREMENT(time_taken) example_performance_measurement(&time_taken, STOPTIMER_AND_CALCULATE)
69
70
// Check return status
71
#define WAIT_AND_CHECK_STATUS(return_status, optiga_lib_status)\
72
if (OPTIGA_LIB_SUCCESS != return_status)\
73
{\
74
break;\
75
}\
76
while (OPTIGA_LIB_BUSY == optiga_lib_status)\
77
{ }\
78
if (OPTIGA_LIB_SUCCESS != optiga_lib_status)\
79
{\
80
return_status = optiga_lib_status;\
81
break;\
82
}\
83
84
#if defined (OPTIGA_LIB_ENABLE_EXAMPLE_LOGGING)
85
99
#define OPTIGA_EXAMPLE_LOG_MESSAGE(msg) \
100
{\
101
optiga_lib_print_message(msg,OPTIGA_EXAMPLE,OPTIGA_EXAMPLE_COLOR);\
102
}
103
119
#define OPTIGA_EXAMPLE_LOG_HEX_DATA(array,array_len) \
120
{\
121
optiga_lib_print_array_hex_format(array,array_len,OPTIGA_UNPROTECTED_DATA_COLOR);\
122
}
123
138
#define OPTIGA_EXAMPLE_LOG_STATUS(return_value) \
139
{ \
140
if (OPTIGA_LIB_SUCCESS != return_value) \
141
{ \
142
optiga_lib_print_status(OPTIGA_EXAMPLE,OPTIGA_ERROR_COLOR,return_value); \
143
} \
144
else\
145
{ \
146
optiga_lib_print_status(OPTIGA_EXAMPLE,OPTIGA_EXAMPLE_COLOR,return_value); \
147
} \
148
}
149
#else
150
151
#define OPTIGA_EXAMPLE_LOG_MESSAGE(msg)
152
#define OPTIGA_EXAMPLE_LOG_HEX_DATA(array, array_len)
153
#define OPTIGA_EXAMPLE_LOG_STATUS(return_value)
154
155
#endif
156
157
#define OPTIGA_EXAMPLE_LOG_PERFORMANCE_VALUE(time_taken,return_value) \
158
{ \
159
if(OPTIGA_LIB_SUCCESS == return_value) \
160
{ \
161
sprintf(performance_buffer_string, "Example takes %d msec", (int)time_taken); \
162
OPTIGA_EXAMPLE_LOG_MESSAGE(performance_buffer_string); \
163
} \
164
}
165
166
#define OPTIGA_EXAMPLE_PROTECTED_UPDATE_PERFORMANCE_VALUE(time_taken) \
167
{ \
168
sprintf(performance_buffer_string, "Execution time %d msec", (int)time_taken); \
169
OPTIGA_EXAMPLE_LOG_MESSAGE(performance_buffer_string); \
170
}
171
#ifdef __cplusplus
172
}
173
#endif
174
175
#endif
/*_OPTIGA_EXAMPLE_H_ */
176
optiga_lib_config.h
This file is defines the compilation switches to build code with required features.
performance_buffer_string
char performance_buffer_string[30]
optiga_lib_logger.h
This file provides the prototypes for the OPTIGA library logger.
example_performance_measurement
void example_performance_measurement(uint32_t *time_value, uint8_t time_reset_flag)
Copyright © 2021 Infineon Technologies AG