Skip to content

Commit 5ea9fa3

Browse files
增加全志 V861 C907 双核 SMP 支持
1 parent dc16a7e commit 5ea9fa3

1 file changed

Lines changed: 56 additions & 1 deletion

File tree

  • bsp/allwinner/avaota-f2/applications

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

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
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
{
@@ -22,6 +23,57 @@ static void busy_nop(volatile uint32_t n)
2223
}
2324
}
2425

26+
#ifdef RT_USING_SMP
27+
static void smp_hart1_entry(void *parameter)
28+
{
29+
RT_UNUSED(parameter);
30+
/* No printk here — shared UART mangles dual-hart prints. */
31+
g_smp_hart1 = rt_hw_cpu_id();
32+
}
33+
34+
/* Bind main on CPU0 and a worker on CPU1; require distinct hart ids. */
35+
static int smp_bringup_check(void)
36+
{
37+
rt_thread_t tid;
38+
rt_thread_t self;
39+
int i;
40+
int cpu0;
41+
42+
self = rt_thread_self();
43+
rt_thread_control(self, RT_THREAD_CTRL_BIND_CPU, (void *)(rt_ubase_t)0);
44+
rt_thread_mdelay(1);
45+
cpu0 = rt_hw_cpu_id();
46+
rt_kprintf("[C907] SMP cpus=%d main_cpu=%d\n", RT_CPUS_NR, cpu0);
47+
48+
g_smp_hart1 = -1;
49+
tid = rt_thread_create("smp1", smp_hart1_entry, RT_NULL, 1024, 8, 10);
50+
if (tid == RT_NULL)
51+
{
52+
rt_kprintf("[C907] SMP-FAIL create\n");
53+
return -1;
54+
}
55+
rt_thread_control(tid, RT_THREAD_CTRL_BIND_CPU, (void *)(rt_ubase_t)1);
56+
rt_thread_startup(tid);
57+
for (i = 0; i < 400; i++)
58+
{
59+
if (g_smp_hart1 >= 0)
60+
{
61+
break;
62+
}
63+
rt_thread_mdelay(5);
64+
}
65+
66+
if (cpu0 == 0 && g_smp_hart1 == 1)
67+
{
68+
rt_kprintf("[C907] SMP-OK hart0=0 hart1=1\n");
69+
return 0;
70+
}
71+
rt_kprintf("[C907] SMP-FAIL main_cpu=%d hart1_seen=%d\n",
72+
cpu0, g_smp_hart1);
73+
return -1;
74+
}
75+
#endif
76+
2577
static int ping_looks_valid(uint32_t req)
2678
{
2779
if (req == AMP_PING_REQ)
@@ -79,7 +131,10 @@ int main(void)
79131

80132
if (wait_new_req(&req, 4000000U) != 0)
81133
{
82-
rt_kprintf("[C907] no ping (solo) — mmc then msh\n");
134+
rt_kprintf("[C907] no ping (solo) — smp/mmc then msh\n");
135+
#ifdef RT_USING_SMP
136+
(void)smp_bringup_check();
137+
#endif
83138
(void)rt_hw_mmc0_probe_from_fdt();
84139
return 0;
85140
}

0 commit comments

Comments
 (0)