task_example.c 948 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Copyright (c) 2021, Meco Jianting Man <jiantingman@foxmail.com>
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-09-30 Meco Man first version
  9. */
  10. #include <ucos_ii.h>
  11. #define TASK_SIZE 256
  12. #define TASK_PRIO 5
  13. static OS_STK task_stack [TASK_SIZE];
  14. static void task(void *p_arg)
  15. {
  16. OS_STK_DATA stk;
  17. while(1)
  18. {
  19. OSTaskStkChk(OS_PRIO_SELF, &stk);
  20. rt_kprintf("task stack free: %d\r\n", stk.OSFree);
  21. #if OS_TASK_STAT_EN > 0u
  22. rt_kprintf("CPU Usage:%d%%\r\n",OSCPUUsage);
  23. #endif
  24. OSTimeDly(500);
  25. }
  26. }
  27. void task_example (void)
  28. {
  29. #if OS_STK_GROWTH == 0u
  30. OSTaskCreateExt(task,0,&task_stack[0],TASK_PRIO,0,&task_stack[TASK_SIZE-1],TASK_SIZE,0,OS_TASK_OPT_STK_CHK|OS_TASK_OPT_STK_CLR);
  31. #else
  32. OSTaskCreateExt(task,0,&task_stack[TASK_SIZE-1],TASK_PRIO,0,&task_stack[0],TASK_SIZE,0,OS_TASK_OPT_STK_CHK|OS_TASK_OPT_STK_CLR);
  33. #endif
  34. }