main.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Email: opensource_embedded@phytium.com.cn
  7. *
  8. * Change Logs:
  9. * Date Author Notes
  10. * 2022-10-26 huanghe first commit
  11. *
  12. */
  13. #include <rthw.h>
  14. #include <rtthread.h>
  15. #include <board.h>
  16. #define ASSERT_STATIC(expression) \
  17. extern int assert_static[(expression) ? 1 : -1]
  18. /* check if SMP related setting ok */
  19. #ifndef RT_USING_SMP
  20. ASSERT_STATIC(RT_CPUS_NR == 1U); /* please set RT_CPUS_NR = 1 when SMP off */
  21. #else
  22. #if defined(TARGET_E2000D)
  23. ASSERT_STATIC(RT_CPUS_NR <= 2U); /* use 2 cores at most */
  24. #elif defined(TARGET_E2000Q) || defined(TARGET_PHYTIUMPI)
  25. ASSERT_STATIC(RT_CPUS_NR <= 4U); /* use 4 cores at most */
  26. #endif
  27. #endif
  28. #ifdef RT_USING_SMP
  29. struct rt_thread test_core[RT_CPUS_NR];
  30. static char *core_thread_name[8] =
  31. {
  32. "core0_test",
  33. "core1_test",
  34. "core2_test",
  35. "core3_test",
  36. "core4_test",
  37. "core5_test",
  38. "core6_test",
  39. "core7_test"
  40. };
  41. static rt_uint8_t core_stack[RT_CPUS_NR][4096];
  42. static void demo_core_thread(void *parameter)
  43. {
  44. rt_base_t level;
  45. while (1)
  46. {
  47. /* code */
  48. level = rt_cpus_lock();
  49. rt_kprintf("Hi, core%d \r\n", rt_hw_cpu_id());
  50. rt_cpus_unlock(level);
  51. rt_thread_mdelay(200000);
  52. }
  53. }
  54. void demo_core(void)
  55. {
  56. rt_ubase_t i;
  57. rt_ubase_t cpu_id = 0;
  58. for (i = 0; i < RT_CPUS_NR; i++)
  59. {
  60. cpu_id = i;
  61. rt_thread_init(&test_core[i],
  62. core_thread_name[i],
  63. demo_core_thread,
  64. RT_NULL,
  65. &core_stack[i],
  66. 4096,
  67. 20,
  68. 32);
  69. rt_thread_control(&test_core[i], RT_THREAD_CTRL_BIND_CPU, (void *)cpu_id);
  70. rt_thread_startup(&test_core[i]);
  71. }
  72. }
  73. #endif
  74. int main(void)
  75. {
  76. #ifdef RT_USING_SMP
  77. demo_core();
  78. #endif
  79. return RT_EOK;
  80. }