Skip to content

Commit b476970

Browse files
committed
refactor: clang-format.
1 parent 272327e commit b476970

File tree

7 files changed

+162
-151
lines changed

7 files changed

+162
-151
lines changed

examples/linux/spi_devkit/fw_update/main.c

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,20 @@
55
* @license For the license see file LICENSE.txt file in the root directory of this source tree.
66
*/
77

8-
#include <string.h>
98
#include <stdio.h>
9+
#include <string.h>
1010
#include <time.h>
1111

12-
#include "libtropic.h"
13-
#include "libtropic_common.h"
14-
#include "libtropic_port_linux_spi.h"
1512
#include "fw_CPU.h"
1613
#include "fw_SPECT.h"
17-
14+
#include "libtropic.h"
15+
#include "libtropic_common.h"
1816
#include "libtropic_mbedtls_v4.h"
17+
#include "libtropic_port_linux_spi.h"
1918
#include "psa/crypto.h"
2019

21-
int get_fw_versions(lt_handle_t *lt_handle) {
22-
20+
int get_fw_versions(lt_handle_t *lt_handle)
21+
{
2322
uint8_t cpu_fw_ver[TR01_L2_GET_INFO_RISCV_FW_SIZE] = {0};
2423
uint8_t spect_fw_ver[TR01_L2_GET_INFO_SPECT_FW_SIZE] = {0};
2524

@@ -48,45 +47,48 @@ int main(void)
4847
printf("==========================================\n");
4948
printf("==== TROPIC01 Firmware Update Example ====\n");
5049
printf("==========================================\n");
51-
50+
5251
// Cryptographic function provider initialization.
53-
//
54-
// In production, this would typically be done only once,
55-
// usually at the start of the application or before
52+
//
53+
// In production, this would typically be done only once,
54+
// usually at the start of the application or before
5655
// the first use of cryptographic functions but no later than
57-
// the first occurrence of any Libtropic function
56+
// the first occurrence of any Libtropic function
5857
psa_status_t status = psa_crypto_init();
5958
if (status != PSA_SUCCESS) {
6059
fprintf(stderr, "PSA Crypto initialization failed, status=%d (psa_status_t)\n", status);
6160
return -1;
6261
}
63-
62+
6463
// Libtropic handle.
6564
//
66-
// It is declared here (on stack) for
65+
// It is declared here (on stack) for
6766
// simplicity. In production, you put it on heap if needed.
6867
lt_handle_t lt_handle = {0};
6968
#if LT_SEPARATE_L3_BUFF
7069
uint8_t l3_buffer[LT_SIZE_OF_L3_BUFF] __attribute__((aligned(16))) = {0};
7170
lt_handle.l3.buff = l3_buffer;
7271
lt_handle.l3.buff_len = sizeof(l3_buffer);
7372
#endif
74-
73+
7574
// Device structure.
7675
//
7776
// Modify this according to your environment. Default values
78-
// are compatible with RPi and our RPi shield.
77+
// are compatible with RPi and our RPi shield.
7978
lt_dev_linux_spi_t device = {0};
80-
strcpy(device.gpio_dev, LT_SPI_DEVKIT_GPIO_PATH); // LT_SPI_DEVKIT_GPIO_PATH is defined in CMakeLists.txt. Pass -DLT_SPI_DEVKIT_GPIO_PATH=<path> to cmake if you want to change it.
81-
strcpy(device.spi_dev, LT_SPI_DEVKIT_SPI_PATH); // LT_SPI_DEVKIT_SPI_PATH is defined in CMakeLists.txt. Pass -DLT_SPI_DEVKIT_SPI_PATH=<path> to cmake if you want to change it.
82-
device.spi_speed = 5000000; // 5 MHz (change if needed).
83-
device.gpio_cs_num = 25; // GPIO 25 as on RPi shield.
79+
strcpy(device.gpio_dev,
80+
LT_SPI_DEVKIT_GPIO_PATH); // LT_SPI_DEVKIT_GPIO_PATH is defined in CMakeLists.txt. Pass
81+
// -DLT_SPI_DEVKIT_GPIO_PATH=<path> to cmake if you want to change it.
82+
strcpy(device.spi_dev,
83+
LT_SPI_DEVKIT_SPI_PATH); // LT_SPI_DEVKIT_SPI_PATH is defined in CMakeLists.txt. Pass
84+
// -DLT_SPI_DEVKIT_SPI_PATH=<path> to cmake if you want to change it.
85+
device.spi_speed = 5000000; // 5 MHz (change if needed).
86+
device.gpio_cs_num = 25; // GPIO 25 as on RPi shield.
8487
#if LT_USE_INT_PIN
8588
device.gpio_int_num = 5; // GPIO 5 as on RPi shield.
8689
#endif
8790
lt_handle.l2.device = &device;
8891

89-
9092
// Crypto abstraction layer (CAL) context.
9193
lt_ctx_mbedtls_v4_t crypto_ctx;
9294
lt_handle.l3.crypto_ctx = &crypto_ctx;
@@ -113,7 +115,7 @@ int main(void)
113115
}
114116
printf("OK\n");
115117

116-
if(get_fw_versions(&lt_handle) != LT_OK) {
118+
if (get_fw_versions(&lt_handle) != LT_OK) {
117119
lt_deinit(&lt_handle);
118120
mbedtls_psa_crypto_free();
119121
return -1;
@@ -133,7 +135,6 @@ int main(void)
133135
}
134136
printf("\nStarting firmware update...\n");
135137

136-
137138
// The chip must be in Start-up Mode to be able to perform a firmware update.
138139
printf("- Sending maintenance reboot request...");
139140
ret = lt_reboot(&lt_handle, TR01_MAINTENANCE_REBOOT);
@@ -198,7 +199,7 @@ int main(void)
198199
}
199200
printf("OK!\nTROPIC01 is executing Application FW now\n");
200201

201-
if(get_fw_versions(&lt_handle) != LT_OK) {
202+
if (get_fw_versions(&lt_handle) != LT_OK) {
202203
lt_deinit(&lt_handle);
203204
mbedtls_psa_crypto_free();
204205
return -1;
@@ -212,11 +213,11 @@ int main(void)
212213
return -1;
213214
}
214215
printf("OK\n");
215-
216+
216217
// Cryptographic function provider deinitialization.
217-
//
218-
// In production, this would be done only once, typically
219-
// during termination of the application.
218+
//
219+
// In production, this would be done only once, typically
220+
// during termination of the application.
220221
mbedtls_psa_crypto_free();
221222

222223
return 0;

examples/linux/spi_devkit/hello_world/main.c

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
* @license For the license see file LICENSE.txt file in the root directory of this source tree.
66
*/
77

8-
#include <string.h>
98
#include <stdio.h>
9+
#include <string.h>
1010
#include <time.h>
1111

1212
#include "libtropic.h"
1313
#include "libtropic_common.h"
14-
#include "libtropic_port_linux_spi.h"
15-
1614
#include "libtropic_mbedtls_v4.h"
15+
#include "libtropic_port_linux_spi.h"
1716
#include "psa/crypto.h"
1817

1918
// Message to send with Ping L3 command.
@@ -37,43 +36,46 @@ int main(void)
3736
printf("======================================\n");
3837

3938
// Cryptographic function provider initialization.
40-
//
41-
// In production, this would typically be done only once,
42-
// usually at the start of the application or before
39+
//
40+
// In production, this would typically be done only once,
41+
// usually at the start of the application or before
4342
// the first use of cryptographic functions but no later than
44-
// the first occurrence of any Libtropic function
43+
// the first occurrence of any Libtropic function
4544
psa_status_t status = psa_crypto_init();
4645
if (status != PSA_SUCCESS) {
4746
fprintf(stderr, "PSA Crypto initialization failed, status=%d (psa_status_t)\n", status);
4847
return -1;
4948
}
50-
49+
5150
// Libtropic handle.
5251
//
53-
// It is declared here (on stack) for
52+
// It is declared here (on stack) for
5453
// simplicity. In production, you put it on heap if needed.
5554
lt_handle_t lt_handle = {0};
5655
#if LT_SEPARATE_L3_BUFF
5756
uint8_t l3_buffer[LT_SIZE_OF_L3_BUFF] __attribute__((aligned(16))) = {0};
5857
lt_handle.l3.buff = l3_buffer;
5958
lt_handle.l3.buff_len = sizeof(l3_buffer);
6059
#endif
61-
60+
6261
// Device structure.
6362
//
6463
// Modify this according to your environment. Default values
65-
// are compatible with RPi and our RPi shield.
64+
// are compatible with RPi and our RPi shield.
6665
lt_dev_linux_spi_t device = {0};
67-
strcpy(device.gpio_dev, LT_SPI_DEVKIT_GPIO_PATH); // LT_SPI_DEVKIT_GPIO_PATH is defined in CMakeLists.txt. Pass -DLT_SPI_DEVKIT_GPIO_PATH=<path> to cmake if you want to change it.
68-
strcpy(device.spi_dev, LT_SPI_DEVKIT_SPI_PATH); // LT_SPI_DEVKIT_SPI_PATH is defined in CMakeLists.txt. Pass -DLT_SPI_DEVKIT_SPI_PATH=<path> to cmake if you want to change it.
69-
device.spi_speed = 5000000; // 5 MHz (change if needed).
70-
device.gpio_cs_num = 25; // GPIO 25 as on RPi shield.
66+
strcpy(device.gpio_dev,
67+
LT_SPI_DEVKIT_GPIO_PATH); // LT_SPI_DEVKIT_GPIO_PATH is defined in CMakeLists.txt. Pass
68+
// -DLT_SPI_DEVKIT_GPIO_PATH=<path> to cmake if you want to change it.
69+
strcpy(device.spi_dev,
70+
LT_SPI_DEVKIT_SPI_PATH); // LT_SPI_DEVKIT_SPI_PATH is defined in CMakeLists.txt. Pass
71+
// -DLT_SPI_DEVKIT_SPI_PATH=<path> to cmake if you want to change it.
72+
device.spi_speed = 5000000; // 5 MHz (change if needed).
73+
device.gpio_cs_num = 25; // GPIO 25 as on RPi shield.
7174
#if LT_USE_INT_PIN
7275
device.gpio_int_num = 5; // GPIO 5 as on RPi shield.
7376
#endif
7477
lt_handle.l2.device = &device;
7578

76-
7779
// Crypto abstraction layer (CAL) context.
7880
lt_ctx_mbedtls_v4_t crypto_ctx;
7981
lt_handle.l3.crypto_ctx = &crypto_ctx;
@@ -101,11 +103,14 @@ int main(void)
101103

102104
printf("Starting Secure Session with key slot %d...", (int)TR01_PAIRING_KEY_SLOT_INDEX_0);
103105
// Keys are chosen based on the CMake option LT_SH0_KEYS.
104-
ret = lt_verify_chip_and_start_secure_session(&lt_handle, LT_EX_SH0_PRIV, LT_EX_SH0_PUB, TR01_PAIRING_KEY_SLOT_INDEX_0);
106+
ret = lt_verify_chip_and_start_secure_session(&lt_handle, LT_EX_SH0_PRIV, LT_EX_SH0_PUB,
107+
TR01_PAIRING_KEY_SLOT_INDEX_0);
105108
if (LT_OK != ret) {
106109
fprintf(stderr, "\nFailed to start Secure Session with key %d, ret=%s\n", (int)TR01_PAIRING_KEY_SLOT_INDEX_0,
107-
lt_ret_verbose(ret));
108-
fprintf(stderr, "Check if you use correct SH0 keys! Hint: if you use an engineering sample chip, compile with -DLT_SH0_KEYS=eng_sample\n");
110+
lt_ret_verbose(ret));
111+
fprintf(stderr,
112+
"Check if you use correct SH0 keys! Hint: if you use an engineering sample chip, compile with "
113+
"-DLT_SH0_KEYS=eng_sample\n");
109114
lt_deinit(&lt_handle);
110115
mbedtls_psa_crypto_free();
111116
return -1;
@@ -143,11 +148,11 @@ int main(void)
143148
return -1;
144149
}
145150
printf("OK\n");
146-
151+
147152
// Cryptographic function provider deinitialization.
148-
//
149-
// In production, this would be done only once, typically
150-
// during termination of the application.
153+
//
154+
// In production, this would be done only once, typically
155+
// during termination of the application.
151156
mbedtls_psa_crypto_free();
152157

153158
return 0;

examples/linux/spi_devkit/identify_chip/main.c

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
* @license For the license see file LICENSE.txt file in the root directory of this source tree.
66
*/
77

8-
#include <string.h>
98
#include <stdio.h>
9+
#include <string.h>
1010
#include <time.h>
1111

1212
#include "libtropic.h"
1313
#include "libtropic_common.h"
14-
#include "libtropic_port_linux_spi.h"
15-
1614
#include "libtropic_mbedtls_v4.h"
15+
#include "libtropic_port_linux_spi.h"
1716
#include "psa/crypto.h"
1817

1918
int main(void)
@@ -23,43 +22,46 @@ int main(void)
2322
printf("==============================================\n");
2423

2524
// Cryptographic function provider initialization.
26-
//
27-
// In production, this would typically be done only once,
28-
// usually at the start of the application or before
25+
//
26+
// In production, this would typically be done only once,
27+
// usually at the start of the application or before
2928
// the first use of cryptographic functions but no later than
30-
// the first occurrence of any Libtropic function
29+
// the first occurrence of any Libtropic function
3130
psa_status_t status = psa_crypto_init();
3231
if (status != PSA_SUCCESS) {
3332
fprintf(stderr, "PSA Crypto initialization failed, status=%d (psa_status_t)\n", status);
3433
return -1;
3534
}
36-
35+
3736
// Libtropic handle.
3837
//
39-
// It is declared here (on stack) for
38+
// It is declared here (on stack) for
4039
// simplicity. In production, you put it on heap if needed.
4140
lt_handle_t lt_handle = {0};
4241
#if LT_SEPARATE_L3_BUFF
4342
uint8_t l3_buffer[LT_SIZE_OF_L3_BUFF] __attribute__((aligned(16))) = {0};
4443
lt_handle.l3.buff = l3_buffer;
4544
lt_handle.l3.buff_len = sizeof(l3_buffer);
4645
#endif
47-
46+
4847
// Device structure.
4948
//
5049
// Modify this according to your environment. Default values
51-
// are compatible with RPi and our RPi shield.
50+
// are compatible with RPi and our RPi shield.
5251
lt_dev_linux_spi_t device = {0};
53-
strcpy(device.gpio_dev, LT_SPI_DEVKIT_GPIO_PATH); // LT_SPI_DEVKIT_GPIO_PATH is defined in CMakeLists.txt. Pass -DLT_SPI_DEVKIT_GPIO_PATH=<path> to cmake if you want to change it.
54-
strcpy(device.spi_dev, LT_SPI_DEVKIT_SPI_PATH); // LT_SPI_DEVKIT_SPI_PATH is defined in CMakeLists.txt. Pass -DLT_SPI_DEVKIT_SPI_PATH=<path> to cmake if you want to change it.
55-
device.spi_speed = 5000000; // 5 MHz (change if needed).
56-
device.gpio_cs_num = 25; // GPIO 25 as on RPi shield.
52+
strcpy(device.gpio_dev,
53+
LT_SPI_DEVKIT_GPIO_PATH); // LT_SPI_DEVKIT_GPIO_PATH is defined in CMakeLists.txt. Pass
54+
// -DLT_SPI_DEVKIT_GPIO_PATH=<path> to cmake if you want to change it.
55+
strcpy(device.spi_dev,
56+
LT_SPI_DEVKIT_SPI_PATH); // LT_SPI_DEVKIT_SPI_PATH is defined in CMakeLists.txt. Pass
57+
// -DLT_SPI_DEVKIT_SPI_PATH=<path> to cmake if you want to change it.
58+
device.spi_speed = 5000000; // 5 MHz (change if needed).
59+
device.gpio_cs_num = 25; // GPIO 25 as on RPi shield.
5760
#if LT_USE_INT_PIN
5861
device.gpio_int_num = 5; // GPIO 5 as on RPi shield.
5962
#endif
6063
lt_handle.l2.device = &device;
6164

62-
6365
// Crypto abstraction layer (CAL) context.
6466
lt_ctx_mbedtls_v4_t crypto_ctx;
6567
lt_handle.l3.crypto_ctx = &crypto_ctx;
@@ -96,8 +98,8 @@ int main(void)
9698
mbedtls_psa_crypto_free();
9799
return -1;
98100
}
99-
printf(" RISC-V FW version: %" PRIX8 ".%" PRIX8 ".%" PRIX8 " (.%" PRIX8 ")\n", fw_ver[3], fw_ver[2],
100-
fw_ver[1], fw_ver[0]);
101+
printf(" RISC-V FW version: %" PRIX8 ".%" PRIX8 ".%" PRIX8 " (.%" PRIX8 ")\n", fw_ver[3], fw_ver[2], fw_ver[1],
102+
fw_ver[0]);
101103

102104
ret = lt_get_info_spect_fw_ver(&lt_handle, fw_ver);
103105
if (ret != LT_OK) {
@@ -106,8 +108,8 @@ int main(void)
106108
mbedtls_psa_crypto_free();
107109
return -1;
108110
}
109-
printf(" SPECT FW version: %" PRIX8 ".%" PRIX8 ".%" PRIX8 " (.%" PRIX8 ")\n", fw_ver[3], fw_ver[2],
110-
fw_ver[1], fw_ver[0]);
111+
printf(" SPECT FW version: %" PRIX8 ".%" PRIX8 ".%" PRIX8 " (.%" PRIX8 ")\n", fw_ver[3], fw_ver[2], fw_ver[1],
112+
fw_ver[0]);
111113

112114
// We need to do the maintenance reboot to check bootloader version and FW bank headers in the Startup Mode.
113115
printf("Sending maintenance reboot request...");
@@ -130,8 +132,8 @@ int main(void)
130132
mbedtls_psa_crypto_free();
131133
return -1;
132134
}
133-
printf(" RISC-V bootloader version: %" PRIX8 ".%" PRIX8 ".%" PRIX8 " (.%" PRIX8 ")\n", fw_ver[3] & 0x7f,
134-
fw_ver[2], fw_ver[1], fw_ver[0]);
135+
printf(" RISC-V bootloader version: %" PRIX8 ".%" PRIX8 ".%" PRIX8 " (.%" PRIX8 ")\n", fw_ver[3] & 0x7f, fw_ver[2],
136+
fw_ver[1], fw_ver[0]);
135137

136138
printf("Firmware bank headers:\n");
137139
ret = lt_print_fw_header(&lt_handle, TR01_FW_BANK_FW1, printf);
@@ -173,7 +175,7 @@ int main(void)
173175
mbedtls_psa_crypto_free();
174176
return -1;
175177
}
176-
178+
177179
printf("---------------------------------------------------------\n");
178180
ret = lt_print_chip_id(&chip_id, printf);
179181
if (ret != LT_OK) {
@@ -202,11 +204,11 @@ int main(void)
202204
return -1;
203205
}
204206
printf("OK\n");
205-
207+
206208
// Cryptographic function provider deinitialization.
207-
//
208-
// In production, this would be done only once, typically
209-
// during termination of the application.
209+
//
210+
// In production, this would be done only once, typically
211+
// during termination of the application.
210212
mbedtls_psa_crypto_free();
211213

212214
return 0;

0 commit comments

Comments
 (0)