blob: e26ab0d6987b0e10b49f71ff9b2415eb17df7200 [file] [log] [blame]
Kevin Pengb1614192023-11-15 17:39:55 +08001/*
2 * SPDX-License-Identifier: BSD-3-Clause
3 * SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
4 *
5 */
6
7#include <stdint.h>
8#include <stdio.h>
9#include <string.h>
10
11#include "erpc_client_start.h"
12#include "erpc_port.h"
13#include "psa/client.h"
14#include "tfm_erpc.h"
15
16#include "non_secure_suites.h"
17
18#if (!defined(ERPC_TRANSPORT_UART)) && (!defined(ERPC_TRANSPORT_TCP))
19#include <stdlib.h>
20#include <getopt.h>
21
22#define ARGC_UART 3
23#define ARGC_TCP 4
24#endif /* !ERPC_TRANSPORT_UART && !ERPC_TRANSPORT_TCP */
25
26int main(int argc, char *argv[])
27{
28 erpc_transport_t transport;
29
30#if (!defined(ERPC_TRANSPORT_UART)) && (!defined(ERPC_TRANSPORT_TCP))
31 int erpc_uart_flag = 0, erpc_tcp_flag = 0;
32 char *uart_dev = NULL, *tcp_host = NULL, *tcp_port = NULL;
33 struct option erpc_transport_options[] =
34 {
35 {"UART", no_argument, &erpc_uart_flag, 1},
36 {"TCP", no_argument, &erpc_tcp_flag, 1},
37 {0, 0, 0, 0}
38 };
39#endif /* !ERPC_TRANSPORT_UART && !ERPC_TRANSPORT_TCP */
40
41#ifdef ERPC_TRANSPORT_UART
42 transport = erpc_transport_serial_init(PORT_NAME, 115200);
43#elif defined(ERPC_TRANSPORT_TCP)
44 transport = erpc_transport_tcp_init(ERPC_HOST, ERPC_PORT, false);
45#else
46 /* Check if argc is correct */
47 if (argc != ARGC_UART && argc != ARGC_TCP) {
48 printf("Incorrect argument numbers.\r\n");
49 printf("Please input --UART PORT or --TCP HOST PORT\r\n");
50 return 1;
51 }
52
53 /* Loop check to set _flag and parse arguments */
54 while (getopt_long(argc, argv, "", erpc_transport_options, NULL) != -1);
55 if (!erpc_uart_flag && !erpc_tcp_flag) {
56 printf("No valid transportation layer selected.\r\n");
57 return 1;
58 } else if (erpc_uart_flag && erpc_tcp_flag) {
59 printf("UART and TCP cannot be set at the same time.\r\n");
60 return 1;
61 } else if (erpc_uart_flag) {
62 if (argc - optind != 1) {
63 printf("Incorrect argument numbers for --UART.\r\n");
64 return 1;
65 }
66 uart_dev = argv[optind];
67 } else if (erpc_tcp_flag) {
68 if (argc - optind != 2) {
69 printf("Incorrect argument numbers for --TCP.\r\n");
70 return 1;
71 }
72 tcp_host = argv[optind];
73 tcp_port = argv[optind + 1];
74 }
75
76 /* eRPC transport initialization */
77 if (erpc_uart_flag) {
78 printf("UART device is being set to %s\r\n", uart_dev);
79 transport = erpc_transport_serial_init(uart_dev, 115200);
80 } else if (erpc_tcp_flag) {
81 printf("TCP connection is being set to %s:%s\r\n", tcp_host, tcp_port);
82 transport = erpc_transport_tcp_init(tcp_host, atoi(tcp_port), false);
83 }
84#endif /* !ERPC_TRANSPORT_UART && !ERPC_TRANSPORT_TCP */
85
86 if (!transport) {
87 printf("eRPC transport initialization failed!\r\n");
88 return 1;
89 } else {
90 printf("eRPC transport initialization succeeded.\r\n");
91 }
92
93 erpc_client_start(transport);
94
95 printf("psa_framework_version: 0x%x\r\n", psa_framework_version());
96
97 ns_reg_test_start();
98
99 return 0;
100}