Skip to content

Commit 644f548

Browse files
增加全志 V861 C907 双核 SMP 支持
1 parent 385cddd commit 644f548

1 file changed

Lines changed: 54 additions & 1 deletion

File tree

  • bsp/allwinner/avaota-f2/applications

‎bsp/allwinner/avaota-f2/applications/main.c‎

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,63 @@
1313
#include "drv_openamp.h"
1414

1515
static uint32_t g_last_req;
16+
static volatile int g_smp_hart1 = -1;
1617

1718
static void busy_nop(volatile uint32_t n)
1819
{
1920
while (n--)
2021
__asm__ volatile("nop");
2122
}
2223

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+
2373
static int ping_looks_valid(uint32_t req)
2474
{
2575
if (req == AMP_PING_REQ)
@@ -71,7 +121,10 @@ int main(void)
71121

72122
if (wait_new_req(&req, 4000000U) != 0)
73123
{
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
75128
(void)rt_hw_mmc0_probe_from_fdt();
76129
return 0;
77130
}

0 commit comments

Comments
 (0)