main.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. #define THREAD_STACK_SIZE 512
  15. #define THREAD_TIMESLICE 5
  16. #define THREAD_NUM 5
  17. /* Align stack when using static thread */
  18. ALIGN(RT_ALIGN_SIZE)
  19. static rt_uint8_t thread_stack[THREAD_NUM][THREAD_STACK_SIZE];
  20. static struct rt_thread tid[THREAD_NUM];
  21. /* Thread entry function */
  22. static void thread_entry(void* parameter)
  23. {
  24. rt_uint32_t count = 0;
  25. while (1) {
  26. rt_kprintf("thread %d count: %d\n", (rt_uint32_t)parameter, count++);
  27. rt_thread_mdelay(250);
  28. }
  29. }
  30. /* Thread demo */
  31. int create_thread_demo(void)
  32. {
  33. unsigned long i;
  34. for (i = 0; i < THREAD_NUM; i ++) {
  35. /* Create static threads */
  36. rt_thread_init(&tid[i], "thread", thread_entry, (void*)i, thread_stack[i],
  37. THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
  38. }
  39. /* Startup threads */
  40. for (i = 0; i < THREAD_NUM; i ++) {
  41. rt_thread_startup(&tid[i]);
  42. }
  43. return 0;
  44. }
  45. int main(void)
  46. {
  47. rt_uint32_t count = 0;
  48. create_thread_demo();
  49. while (1) {
  50. rt_kprintf("Main thread count: %d\n", count++);
  51. rt_thread_mdelay(500);
  52. #ifdef CFG_SIMULATION
  53. if (count > 2) {
  54. // directly exit if in nuclei internally simulation
  55. SIMULATION_EXIT(0);
  56. }
  57. #endif
  58. }
  59. }