|
13 | 13 | #include "drv_openamp.h" |
14 | 14 |
|
15 | 15 | static uint32_t g_last_req; |
| 16 | +static volatile int g_smp_hart1 = -1; |
16 | 17 |
|
17 | 18 | static void busy_nop(volatile uint32_t n) |
18 | 19 | { |
19 | 20 | while (n--) |
20 | 21 | __asm__ volatile("nop"); |
21 | 22 | } |
22 | 23 |
|
| 24 | +#ifdef RT_USING_SMP |
| 25 | +static void smp_hart1_entry(void *parameter) |
| 26 | +{ |
| 27 | + RT_UNUSED(parameter); |
| 28 | + /* No printk here — shared UART mangles dual-hart prints. */ |
| 29 | + g_smp_hart1 = rt_hw_cpu_id(); |
| 30 | +} |
| 31 | + |
| 32 | +/* Bind main on CPU0 and a worker on CPU1; require distinct hart ids. */ |
| 33 | +static int smp_bringup_check(void) |
| 34 | +{ |
| 35 | + rt_thread_t tid; |
| 36 | + rt_thread_t self; |
| 37 | + int i; |
| 38 | + int cpu0; |
| 39 | + |
| 40 | + self = rt_thread_self(); |
| 41 | + rt_thread_control(self, RT_THREAD_CTRL_BIND_CPU, (void *)(rt_ubase_t)0); |
| 42 | + rt_thread_mdelay(1); |
| 43 | + cpu0 = rt_hw_cpu_id(); |
| 44 | + rt_kprintf("[C907] SMP cpus=%d main_cpu=%d\n", RT_CPUS_NR, cpu0); |
| 45 | + |
| 46 | + g_smp_hart1 = -1; |
| 47 | + tid = rt_thread_create("smp1", smp_hart1_entry, RT_NULL, 1024, 8, 10); |
| 48 | + if (tid == RT_NULL) |
| 49 | + { |
| 50 | + rt_kprintf("[C907] SMP-FAIL create\n"); |
| 51 | + return -1; |
| 52 | + } |
| 53 | + rt_thread_control(tid, RT_THREAD_CTRL_BIND_CPU, (void *)(rt_ubase_t)1); |
| 54 | + rt_thread_startup(tid); |
| 55 | + for (i = 0; i < 400; i++) |
| 56 | + { |
| 57 | + if (g_smp_hart1 >= 0) |
| 58 | + break; |
| 59 | + rt_thread_mdelay(5); |
| 60 | + } |
| 61 | + |
| 62 | + if (cpu0 == 0 && g_smp_hart1 == 1) |
| 63 | + { |
| 64 | + rt_kprintf("[C907] SMP-OK hart0=0 hart1=1\n"); |
| 65 | + return 0; |
| 66 | + } |
| 67 | + rt_kprintf("[C907] SMP-FAIL main_cpu=%d hart1_seen=%d\n", |
| 68 | + cpu0, g_smp_hart1); |
| 69 | + return -1; |
| 70 | +} |
| 71 | +#endif |
| 72 | + |
23 | 73 | static int ping_looks_valid(uint32_t req) |
24 | 74 | { |
25 | 75 | if (req == AMP_PING_REQ) |
@@ -71,7 +121,10 @@ int main(void) |
71 | 121 |
|
72 | 122 | if (wait_new_req(&req, 4000000U) != 0) |
73 | 123 | { |
74 | | - rt_kprintf("[C907] no ping (solo) — mmc then msh\n"); |
| 124 | + rt_kprintf("[C907] no ping (solo) — smp/mmc then msh\n"); |
| 125 | +#ifdef RT_USING_SMP |
| 126 | + (void)smp_bringup_check(); |
| 127 | +#endif |
75 | 128 | (void)rt_hw_mmc0_probe_from_fdt(); |
76 | 129 | return 0; |
77 | 130 | } |
|
0 commit comments