K210 FreeRTOS多任务多核系统调度

一、目的

众所周知,K210这款AI新品是一款64bit 双核芯片,其支持裸机编程,并且官方也提供freertos sdk,方便开发者在其上进行多任务应用开发。那么如何进行任务创建和多核开发呢。

二、参考

#include <stdio.h>
#include "FreeRTOS.h"
#include "task.h"

static void task_0(void *args) {
    while (1) {
        printf("task 0 on core %d is polling\n", (int)uxPortGetProcessorId());
        vTaskDelay(1000 / portTICK_PERIOD_MS);
    }
    vTaskDelete(NULL);
}

static void task_1(void *args) {
    while (1) {
        printf("task 1 on core %d is polling\n", (int)uxPortGetProcessorId());
        vTaskDelay(1000 / portTICK_PERIOD_MS);
    }
    vTaskDelete(NULL);
}

int main() {
    printf("Hello K210!!!\n");
    //在core 0上创建一个优先级为5的任务task_0
    xTaskCreateAtProcessor(0, task_0, "task0", 1024, NULL, 5, NULL);
    //在core 1上创建一个优先级为5的任务task_0
    xTaskCreateAtProcessor(1, task_1, "task1", 1024, NULL, 5, NULL);
    while (1) {
        printf("main on core %d is polling\n", (int)uxPortGetProcessorId());
        vTaskDelay(2000 / portTICK_PERIOD_MS);
    }
}

在上一篇博文中,我们已经介绍过,main函数是freertos在core 0上创建的一个线程,构建烧写后从日志上可以看到跟预期一下。

--- Miniterm on /dev/ttyUSB0  115200,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
Hello K210!!!
task 0 on core 0 is polling
task 1  nocer0 i  polling
g
task 0 on core 0 is polling
task 1 on core 1 is polling
task 0 on core 0 is polling
main on core 0 ta ko1lon 
ore 1 is polling
task 0 on core 0 is polling
task 1 on core 1 is polling
task 0 on core 0 is polling
main on core 0 is polling
task 1 on core 1 is polling
task 0 on core 0 is polling
task 1 on core 1 is polling
task 0 on core 0 is polling
main on core 0 is polling
task 1 on core 1 is polling

至此,一个最简单的多任务多核应用介绍结束。

  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值