main.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (c) 2006-2019, RT-Thread Development Team
  3. * Copyright (c) 2019-Present Nuclei Limited. All rights reserved.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0
  6. *
  7. * Change Logs:
  8. * Date Author Notes
  9. * 2020-03-26 Huaqi the first version
  10. */
  11. #include "nuclei_sdk_soc.h"
  12. #include <rtthread.h>
  13. #define THREAD_PRIORITY 2
  14. /* Reserve enough stack if rvv autovectorization enabled,
  15. * it will use stack to save and restore rvv registers,
  16. * which may corrupt stack, take care */
  17. #define THREAD_STACK_SIZE 1024
  18. #define THREAD_TIMESLICE 5
  19. #define THREAD_NUM 5
  20. /* Align stack when using static thread */
  21. ALIGN(RT_ALIGN_SIZE)
  22. static rt_uint8_t thread_stack[THREAD_NUM][THREAD_STACK_SIZE];
  23. static struct rt_thread tid[THREAD_NUM];
  24. /* Thread entry function */
  25. static void thread_entry(void* parameter)
  26. {
  27. rt_uint32_t count = 0;
  28. while (1) {
  29. rt_kprintf("thread %d count: %d\n", (rt_uint32_t)(unsigned long)parameter, count++);
  30. rt_thread_mdelay(250);
  31. }
  32. }
  33. /* Thread demo */
  34. int create_thread_demo(void)
  35. {
  36. unsigned long i;
  37. for (i = 0; i < THREAD_NUM; i ++) {
  38. /* Create static threads */
  39. rt_thread_init(&tid[i], "thread", thread_entry, (void*)i, thread_stack[i],
  40. THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
  41. }
  42. /* Startup threads */
  43. for (i = 0; i < THREAD_NUM; i ++) {
  44. rt_thread_startup(&tid[i]);
  45. }
  46. return 0;
  47. }
  48. int main(void)
  49. {
  50. rt_uint32_t count = 0;
  51. create_thread_demo();
  52. while (1) {
  53. rt_kprintf("Main thread count: %d\n", count++);
  54. rt_thread_mdelay(500);
  55. #ifdef CFG_SIMULATION
  56. if (count > 2) {
  57. // directly exit if in nuclei internally simulation
  58. SIMULATION_EXIT(0);
  59. }
  60. #endif
  61. }
  62. }