查看: 3757|回复: 0

[Wio Terminal开发板测评]+RTOS操作系统测试

[复制链接]
  • TA的每日心情
    奋斗
    2023-5-10 20:09
  • 签到天数: 1742 天

    连续签到: 1 天

    [LV.Master]伴坛终老

    发表于 2021-8-23 00:35:40 | 显示全部楼层 |阅读模式
    分享到:
    Wio终端不但支持裸机运行,还为其配置了RTOS操作系统。
    利用所提供的例程可测试其性能,并可学习其编程思想并加以应用。
    该例程含有2个线程,即线程A和线程B,相应的程序内容如下:
    1. //*****************************************************************
    2. // Create a thread that prints out A to the screen every two seconds
    3. // this task will delete its self after printing out afew messages
    4. //*****************************************************************
    5. static void threadA(void* pvParameters) {
    6. SERIAL.println("Thread A: Started");
    7. for (int x = 0; x < 20; ++x) {
    8. SERIAL.print("A");
    9. delay(500);
    10. }
    11. // delete ourselves.
    12. // Have to call this or the system crashes when you reach the end bracket and then get scheduled.
    13. SERIAL.println("Thread A: Deleting");
    14. vTaskDelete(NULL);
    15. }

    16. //*****************************************************************
    17. // Create a thread that prints out B to the screen every second
    18. // this task will run forever
    19. //*****************************************************************
    20. static void threadB(void* pvParameters) {
    21. SERIAL.println("Thread B: Started");
    22. while (1) {
    23. SERIAL.println("B");
    24. delay(2000);
    25. }
    26. }
    复制代码

    其中,线程A的作用是通过延时来打印输出字符“A”,以表示是线程A的处理;而线程B的作用也与其基本相同,所打印输出的是字符“B”,并实行换行。两者最大的区别在于延时值的不同,其中线程A的打印间隔是500毫秒,而线程B的打印间隔是2000毫秒,这样将就导致其输出时出现出交叠的情况。
    为监控线程的运行,其任务监视器的程序为:
    1. //*****************************************************************
    2. // Task will periodicallt print out useful information about the tasks running
    3. // Is a useful tool to help figure out stack sizes being used
    4. //*****************************************************************
    5. void taskMonitor(void* pvParameters) {
    6. int x;
    7. int measurement;
    8. SERIAL.println("Task Monitor: Started");
    9. // run this task afew times before exiting forever
    10. for (x = 0; x < 10; ++x) {
    11. SERIAL.println("");
    12. SERIAL.println("******************************");
    13. SERIAL.println("[Stacks Free Bytes Remaining] ");
    14. measurement = uxTaskGetStackHighWaterMark(Handle_aTask);
    15. SERIAL.print("Thread A: ");
    16. SERIAL.println(measurement);
    17. measurement = uxTaskGetStackHighWaterMark(Handle_bTask);
    18. SERIAL.print("Thread B: ");
    19. SERIAL.println(measurement);
    20. measurement = uxTaskGetStackHighWaterMark(Handle_monitorTask);
    21. SERIAL.print("Monitor Stack: ");
    22. SERIAL.println(measurement);
    23. SERIAL.println("******************************");
    24. delay(10000); // print every 10 seconds
    25. }
    26. // delete ourselves.
    27. // Have to call this or the system crashes when you reach the end bracket and then get scheduled.
    28. SERIAL.println("Task Monitor: Deleting");
    29. vTaskDelete(NULL);
    30. }
    复制代码

    状态配置和循环程序为:
    1. void setup() {
    2. SERIAL.begin(115200);
    3. vNopDelayMS(1000); // prevents usb driver crash on startup, do not omit this
    4. while (!SERIAL) ;  // Wait for serial terminal to open port before starting program
    5. SERIAL.println("");
    6. SERIAL.println("******************************");
    7. SERIAL.println("        Program start         ");
    8. SERIAL.println("******************************");
    9. // Set the led the rtos will blink when we have a fatal rtos error
    10. // RTOS also Needs to know if high/low is the state that turns on the led.
    11. // Error Blink Codes:
    12. //    3 blinks - Fatal Rtos Error, something bad happened. Think really hard about what you just changed.
    13. //    2 blinks - Malloc Failed, Happens when you couldn't create a rtos object.
    14. //               Probably ran out of heap.
    15. //    1 blink  - Stack overflow, Task needs more bytes defined for its stack!
    16. //               Use the taskMonitor thread to help gauge how much more you need
    17. vSetErrorLed(ERROR_LED_PIN, ERROR_LED_LIGHTUP_STATE);
    18. // Create the threads that will be managed by the rtos
    19. // Sets the stack size and priority of each task
    20. // Also initializes a handler pointer to each task, which are important to communicate with and retrieve info from tasks
    21. xTaskCreate(threadA,     "Task A",       256, NULL, tskIDLE_PRIORITY + 3, &Handle_aTask);
    22. xTaskCreate(threadB,     "Task B",       256, NULL, tskIDLE_PRIORITY + 2, &Handle_bTask);
    23. xTaskCreate(taskMonitor, "Task Monitor", 256, NULL, tskIDLE_PRIORITY + 1, &Handle_monitorTask);
    24. // Start the RTOS, this function will never return and will schedule the tasks.
    25. vTaskStartScheduler();
    26. while(1);
    27. }

    28. void loop() {
    29. }
    复制代码

    经程序的编译上传,其结果如图1和图2所示。
    由于线程A的打印间隔是500毫秒,而线程B的打印间隔是2000毫秒且换行,故每打印4个字符“A”,打印1个字符“B”,且自动换行(2000/500=4 --> AAAAB)。
    仿此,我们可以设计自己的并行程度要求较高的线程任务。
                                  
    1.jpg
    图1 程序编译与上传

    2.jpg
    图2 运行效果
    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /4 下一条

    手机版|小黑屋|与非网

    GMT+8, 2024-11-19 12:22 , Processed in 0.113003 second(s), 16 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.