main.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include <stdint.h>
  2. #include <ucos_ii.h>
  3. #include "nuclei_sdk_soc.h"
  4. #define mainQUEUE_LENGTH (1)
  5. static void prvSetupHardware(void);
  6. extern void idle_task(void);
  7. void prvSetupHardware(void)
  8. {
  9. }
  10. #define STK_LEN 256
  11. OS_STK task1_stk[STK_LEN];
  12. OS_STK task2_stk[STK_LEN];
  13. OS_STK task3_stk[STK_LEN];
  14. OS_STK start_stk[STK_LEN];
  15. #define TASK1_PRIO 13
  16. #define TASK2_PRIO 12
  17. #define TASK3_PRIO 11
  18. #define TASK_START_PRIO 10
  19. void task1(void* args)
  20. {
  21. int cnt = 0;
  22. for (;;) {
  23. cnt++;
  24. printf("task1 is running... %d\r\n", cnt);
  25. OSTimeDlyHMSM(0, 0, 0, 500);
  26. }
  27. }
  28. void task2(void* args)
  29. {
  30. int cnt = 0;
  31. for (;;) {
  32. cnt++;
  33. printf("task2 is running... %d\r\n", cnt);
  34. OSTimeDlyHMSM(0, 0, 0, 250);
  35. }
  36. }
  37. void task3(void* args)
  38. {
  39. int cnt = 0;
  40. for (;;) {
  41. cnt++;
  42. printf("task3 is running... %d\r\n", cnt);
  43. OSTimeDlyHMSM(0, 0, 0, 250);
  44. #ifdef CFG_SIMULATION
  45. if (cnt > 2) {
  46. // directly exit if in nuclei internally simulation
  47. SIMULATION_EXIT(0);
  48. }
  49. #endif
  50. }
  51. }
  52. void start_task(void* args)
  53. {
  54. printf("start all task...\r\n");
  55. OSTaskCreate(task1, NULL, &task1_stk[STK_LEN - 1], TASK1_PRIO);
  56. OSTaskCreate(task2, NULL, &task2_stk[STK_LEN - 1], TASK2_PRIO);
  57. OSTaskCreate(task3, NULL, &task3_stk[STK_LEN - 1], TASK3_PRIO);
  58. OSTaskSuspend(TASK_START_PRIO);
  59. }
  60. int main(void)
  61. {
  62. printf("Start ucosii...\r\n");
  63. prvSetupHardware();
  64. OSInit();
  65. OSTaskCreate(start_task, NULL, &start_stk[STK_LEN - 1], TASK_START_PRIO);
  66. printf("create start task success\r\n");
  67. OSStart();
  68. while (1) {
  69. }
  70. }