main.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. #define ASSERT_STATIC(expression) \
  19. extern int assert_static[(expression) ? 1 : -1]
  20. /* check if SMP related setting ok */
  21. #ifndef RT_USING_SMP
  22. ASSERT_STATIC(RT_CPUS_NR == 1U); /* please set RT_CPUS_NR = 1 when SMP off */
  23. #else
  24. #if defined(TARGET_E2000D)
  25. ASSERT_STATIC(RT_CPUS_NR <= 2U); /* use 2 cores at most */
  26. #elif defined(TARGET_E2000Q) || defined(TARGET_PHYTIUMPI)
  27. ASSERT_STATIC(RT_CPUS_NR <= 4U); /* use 4 cores at most */
  28. #endif
  29. #endif
  30. #ifdef RT_USING_SMP
  31. struct rt_thread test_core[RT_CPUS_NR];
  32. static char *core_thread_name[8] =
  33. {
  34. "core0_test",
  35. "core1_test",
  36. "core2_test",
  37. "core3_test",
  38. "core4_test",
  39. "core5_test",
  40. "core6_test",
  41. "core7_test"
  42. };
  43. static rt_uint8_t core_stack[RT_CPUS_NR][1024];
  44. static void demo_core_thread(void *parameter)
  45. {
  46. rt_base_t level;
  47. while (1)
  48. {
  49. /* code */
  50. level = rt_cpus_lock();
  51. rt_kprintf("Hi, core%d \r\n", rt_hw_cpu_id());
  52. rt_cpus_unlock(level);
  53. rt_thread_mdelay(2000000);
  54. }
  55. }
  56. void demo_core(void)
  57. {
  58. rt_ubase_t i;
  59. rt_ubase_t cpu_id = 0;
  60. for (i = 0; i < RT_CPUS_NR; i++)
  61. {
  62. cpu_id = i;
  63. rt_thread_init(&test_core[i],
  64. core_thread_name[i],
  65. demo_core_thread,
  66. RT_NULL,
  67. &core_stack[i],
  68. 1024,
  69. 20,
  70. 32);
  71. rt_thread_control(&test_core[i], RT_THREAD_CTRL_BIND_CPU, (void *)cpu_id);
  72. rt_thread_startup(&test_core[i]);
  73. }
  74. }
  75. #endif
  76. int main(void)
  77. {
  78. #ifdef RT_USING_SMP
  79. // demo_core();
  80. #endif
  81. return RT_EOK;
  82. }