main.c 2.1 KB

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