Morse Micro IoT SDK  2.12.3
porting_assistant.c
Go to the documentation of this file.
1/*
2 * Copyright 2021-2023 Morse Micro
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
27#include "porting_assistant.h"
28#include "mmhal_core.h"
29#include "mmhal_app.h"
30#include "mmversion.h"
31
32#if defined(ENABLE_EXT_XTAL_INIT) && ENABLE_EXT_XTAL_INIT
33/* The crystal initialization requires chip specific configuration which we do not have access
34 * to in the porting assistant example application. */
35#error "With ENABLE_EXT_XTAL_INIT defined this device is not supported by porting assistant."
36#endif
37
38/* Test step declarations */
39extern const struct test_step test_step_os_malloc;
40extern const struct test_step test_step_os_realloc;
41extern const struct test_step test_step_os_time;
42extern const struct test_step test_step_os_task_creation;
44extern const struct test_step test_step_mmhal_wlan_init;
47extern const struct test_step test_step_read_chip_id;
48extern const struct test_step test_step_bulk_write_read;
49extern const struct test_step test_step_raw_tput;
54extern const struct test_step test_step_verify_busy_pin;
59static const struct test_step *const test_steps[] = {
74};
75
78{
80 unsigned no_result;
82 unsigned pass;
84 unsigned fail;
85};
86
94static const char *result_code_to_string(enum test_result result)
95{
96 switch (result)
97 {
98 case TEST_NO_RESULT:
99 return "";
100 case TEST_PASSED:
101 return F_GREEN("PASS");
102 case TEST_SKIPPED:
103 return F_BLUE("SKIP");
104 case TEST_FAILED:
105 return F_RED("FAIL");
106 case TEST_FAILED_NON_CRITICAL:
107 return F_YELLOW("FAIL");
108 }
109 MMOSAL_ASSERT(false);
110}
111
120static void run_test_steps(const struct test_step *const steps[],
121 size_t num_steps,
122 struct test_counters *ctrs)
123{
124 static char log_buf[1024];
125
126 size_t ii;
127 for (ii = 0; ii < num_steps; ii++)
128 {
129 const struct test_step *step = steps[ii];
130 size_t log_buf_len = sizeof(log_buf);
131 log_buf[0] = '\0';
132
133 LOG_PRINTF(F_BOLD("%-60s "), step->description);
134 LOG_FLUSH();
135
136 enum test_result result = step->exec(log_buf, log_buf_len);
137 if (result != TEST_NO_RESULT)
138 {
139 LOG_PRINTF("[ %s ]", result_code_to_string(result));
140 }
141 LOG_WRITE("\n");
142
143 if (log_buf[0] != '\0')
144 {
145 LOG_WRITE("\n");
146 LOG_WRITE(log_buf);
147 }
148
149 switch (result)
150 {
151 case TEST_NO_RESULT:
152 ctrs->no_result++;
153 break;
154 case TEST_PASSED:
155 ctrs->pass++;
156 break;
157 case TEST_SKIPPED:
158 break;
159 case TEST_FAILED:
160 ctrs->fail++;
161 break;
162 case TEST_FAILED_NON_CRITICAL:
163 ctrs->fail++;
164 break;
165 }
166
167 if (result == TEST_FAILED)
168 {
169 break;
170 }
171 }
172}
173
178void app_init(void)
179{
180 /* Having deep sleep enabled can complicate debugging. Given the purpose of this applications
181 * is to validate that you can communicate to the MM-Chip it will be disabled by default. */
183
184 struct test_counters ctrs = { 0 };
185 unsigned num_tests = sizeof(test_steps) / sizeof(test_steps[0]);
186
187 char hw_version_string[32] = { 0 };
188
189 bool ok = mmhal_get_hardware_version(hw_version_string, sizeof(hw_version_string));
190 if (!ok)
191 {
192 snprintf(hw_version_string, sizeof(hw_version_string), "%s", "Unknown");
193 }
194
195 LOG_WRITE(F_BOLD("\n\nMM-IoT-SDK Porting Assistant\n"));
196 LOG_WRITE("----------------------------\n");
197 LOG_PRINTF(" HW Version: %s\n", hw_version_string);
198 LOG_PRINTF(" Morselib version: %s\n", MM_VERSION_BUILDID);
199 LOG_WRITE("----------------------------\n\n");
200
201 run_test_steps(test_steps, num_tests, &ctrs);
202
203 LOG_PRINTF("\n\n%u total test steps. %u passed, %u failed, %u no result, %u skipped\n",
204 num_tests,
205 ctrs.pass,
206 ctrs.fail,
207 ctrs.no_result,
208 num_tests - ctrs.no_result - ctrs.pass - ctrs.fail);
209}
bool mmhal_get_hardware_version(char *version_buffer, size_t version_buffer_length)
Reads information that can be used to identify the hardware platform, such as hardware ID and version...
void mmhal_set_deep_sleep_veto(uint8_t veto_id)
Sets a deep sleep veto that will prevent the device from entering deep sleep.
@ MMHAL_VETO_ID_APP_MIN
Start of deep sleep veto ID range that is available for application use.
Definition: mmhal_core.h:41
#define MMOSAL_ASSERT(expr)
Assert that the given expression evaluates to true and abort execution if not.
Definition: mmosal.h:1006
#define MM_VERSION_BUILDID
Build identifier string.
Definition: mmversion.h:32
const struct test_step test_step_mmhal_wlan_validate_bcf
Test definition.
const struct test_step test_step_read_chip_id
Test definition.
const struct test_step test_step_os_malloc
Test definition.
const struct test_step test_step_verify_busy_pin
Test definition.
const struct test_step test_step_os_realloc
Test definition.
const struct test_step test_step_mmhal_wlan_sdio_startup
Test definition.
const struct test_step test_step_raw_tput
Test definition.
const struct test_step test_step_benchmark_cpu_mem_stack_perf
Test definition.
const struct test_step test_step_mmhal_wlan_validate_fw
Test definition.
const struct test_step test_step_bulk_write_read
Test definition.
const struct test_step test_step_os_time
Test definition.
const struct test_step test_step_mmhal_wlan_hard_reset
Test definition.
static void run_test_steps(const struct test_step *const steps[], size_t num_steps, struct test_counters *ctrs)
Iterate through the given list of test steps and execute until complete or until a critical failure o...
const struct test_step test_step_os_task_creation
Test definition.
void app_init(void)
Main entry point to the application.
static const struct test_step *const test_steps[]
Array of test steps.
const struct test_step test_step_mmhal_wlan_init
Test definition.
static const char * result_code_to_string(enum test_result result)
Convert a test_result code to string.
Counters to track test runs.
unsigned no_result
Number of tests that did not return a pass/fail result.
unsigned pass
Number of tests that passed.
unsigned fail
Number of tests that failed.
Test step descriptor.
const char * description
Short, user friendly description of the test step.
enum test_result(* exec)(char *log_buf, size_t log_buf_len)
Test step execution function.