GCC Code Coverage Report


Directory: main/
File: main.c
Date: 2025-10-04 14:03:00
Exec Total Coverage
Lines: 42 50 84.0%
Functions: 3 3 100.0%
Branches: 10 18 55.6%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2019-2024, Jacques Gagnon
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6 #include <string.h>
7 #include <freertos/FreeRTOS.h>
8 #include <freertos/task.h>
9 #include <nvs_flash.h>
10 #include <esp_ota_ops.h>
11 #include <esp32/rom/ets_sys.h>
12 #include <soc/efuse_reg.h>
13 #include <esp_efuse.h>
14 #include "system/bare_metal_app_cpu.h"
15 #include "system/core0_stall.h"
16 #include "system/delay.h"
17 #include "system/fs.h"
18 #include "system/led.h"
19 #include "adapter/adapter.h"
20 #include "adapter/adapter_debug.h"
21 #include "adapter/config.h"
22 #include "bluetooth/host.h"
23 #include "wired/detect.h"
24 #include "wired/wired_bare.h"
25 #include "wired/wired_rtos.h"
26 #include "adapter/memory_card.h"
27 #include "system/manager.h"
28 #include "tests/ws_srv.h"
29 #include "tests/coverage.h"
30 #include "sdkconfig.h"
31
32 static uint32_t chip_package = EFUSE_RD_CHIP_VER_PKG_ESP32D0WDQ6;
33
34 1 static void wired_init_task(void) {
35 #ifdef CONFIG_BLUERETRO_SYSTEM_UNIVERSAL
36 detect_init();
37 while (wired_adapter.system_id <= WIRED_AUTO) {
38 if (config.magic == CONFIG_MAGIC && config.global_cfg.system_cfg < WIRED_MAX
39 && config.global_cfg.system_cfg != WIRED_AUTO) {
40 break;
41 }
42 delay_us(1000);
43 }
44 detect_deinit();
45
46 if (wired_adapter.system_id >= 0) {
47 ets_printf("# Detected system : %d: %s\n", wired_adapter.system_id, wired_get_sys_name());
48 }
49 #else
50 1 wired_adapter.system_id = HARDCODED_SYS;
51 1 ets_printf("# Hardcoded system : %d: %s\n", wired_adapter.system_id, wired_get_sys_name());
52 #endif
53
54
2/2
✓ Branch 0 (6→5) taken 129 times.
✓ Branch 1 (6→7) taken 1 times.
130 while (config.magic != CONFIG_MAGIC) {
55 129 delay_us(1000);
56 }
57
58
1/2
✗ Branch 0 (7→8) not taken.
✓ Branch 1 (7→10) taken 1 times.
1 if (config.global_cfg.system_cfg < WIRED_MAX && config.global_cfg.system_cfg != WIRED_AUTO) {
59 wired_adapter.system_id = config.global_cfg.system_cfg;
60 ets_printf("# Config override system : %d: %s\n", wired_adapter.system_id, wired_get_sys_name());
61 }
62
63
2/2
✓ Branch 0 (13→11) taken 8 times.
✓ Branch 1 (13→14) taken 1 times.
9 for (uint32_t i = 0; i < WIRED_MAX_DEV; i++) {
64 8 adapter_init_buffer(i);
65 }
66
67 1 struct raw_fb fb_data = {0};
68 1 const char *sysname = wired_get_sys_name();
69 1 fb_data.header.wired_id = 0;
70 1 fb_data.header.type = FB_TYPE_SYS_ID;
71 1 fb_data.header.data_len = strlen(sysname);
72 1 memcpy(fb_data.data, sysname, fb_data.header.data_len);
73 1 adapter_q_fb(&fb_data);
74
75
1/2
✓ Branch 0 (17→18) taken 1 times.
✗ Branch 1 (17→19) not taken.
1 if (wired_adapter.system_id < WIRED_MAX) {
76 1 wired_bare_init(chip_package);
77 }
78 1 }
79
80 1 static void wl_init_task(void *arg) {
81 1 uint32_t err = 0;
82
83 1 const esp_partition_t *running = esp_ota_get_running_partition();
84 1 esp_ota_img_states_t ota_state;
85 1 esp_ota_get_state_partition(running, &ota_state);
86
87 1 chip_package = esp_efuse_get_pkg_ver();
88
89 #ifdef CONFIG_BLUERETRO_COVERAGE
90 1 cov_init();
91 #endif
92
93 1 err_led_init(chip_package);
94
95 1 core0_stall_init();
96
97 #ifndef CONFIG_BLUERETRO_QEMU
98 if (fs_init()) {
99 err_led_set();
100 err = 1;
101 printf("FS init fail!\n");
102 }
103 #endif
104
105 /* Initialize NVS for PHY cal and default config */
106 1 int32_t ret = nvs_flash_init();
107
1/2
✗ Branch 0 (9→10) not taken.
✓ Branch 1 (9→14) taken 1 times.
1 if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
108 ESP_ERROR_CHECK(nvs_flash_erase());
109 ret = nvs_flash_init();
110 }
111
1/2
✗ Branch 0 (14→15) not taken.
✓ Branch 1 (14→16) taken 1 times.
1 ESP_ERROR_CHECK(ret);
112
113 1 config_init(DEFAULT_CFG);
114 1 mc_init_mem();
115
116 #ifndef CONFIG_BLUERETRO_BT_DISABLE
117 if (bt_host_init()) {
118 err_led_set();
119 err = 1;
120 printf("Bluetooth init fail!\n");
121 }
122 #endif
123
124
1/2
✓ Branch 0 (18→19) taken 1 times.
✗ Branch 1 (18→20) not taken.
1 if (wired_adapter.system_id < WIRED_MAX) {
125 1 wired_rtos_init();
126 }
127
128 #ifndef CONFIG_BLUERETRO_QEMU
129 mc_init();
130
131 sys_mgr_init(chip_package);
132 #endif
133
134 #ifdef CONFIG_BLUERETRO_WS_CMDS
135 1 ws_srv_init();
136 #endif
137
138
1/2
✗ Branch 0 (21→22) not taken.
✓ Branch 1 (21→24) taken 1 times.
1 if (ota_state == ESP_OTA_IMG_PENDING_VERIFY) {
139 if (err) {
140 printf("Boot error on pending img, rollback to the previous version.");
141 esp_ota_mark_app_invalid_rollback_and_reboot();
142 }
143 else {
144 printf("Pending img valid!");
145 esp_ota_mark_app_valid_cancel_rollback();
146 }
147 }
148 1 vTaskDelete(NULL);
149 }
150
151 1 void app_main()
152 {
153 1 adapter_init();
154
155 1 start_app_cpu(wired_init_task);
156 1 xTaskCreatePinnedToCore(wl_init_task, "wl_init_task", 2560, NULL, 10, NULL, 0);
157 1 }
158