按照GitHub给的教程,把TencentOS tiny 移植到keil:
TencentOS tiny 移植到STM32F103全教程(基于标准库)
1、…\TencentOS\kernel\core\tos_mutex.c(105): error: #136: struct “k_mutex_st” has no field “knl_obj”
knl_object_alloc_set_dynamic(&the_mutex->knl_obj);
首先,指针the_mutex定义在此:
k_mutex_t *the_mutex;
然后,看k_mutex_t 的定义
typedef struct k_mutex_st {
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
knl_obj_t knl_obj;
#endif
pend_obj_t pend_obj;
k_nesting_t pend_nesting;
k_task_t *owner;
k_prio_t owner_orig_prio;
k_list_t owner_anchor;
} k_mutex_t;
发现需要TOS_CFG_OBJECT_VERIFY_EN > 0u
,这相比教程里的博客进行了代码更新,这是增加的代码,在编译时为了不报错,需要将tos_config.h
中的TOS_CFG_OBJECT_VERIFY_EN
从0u
改为1u
。
2、编译,中断函数报错,按照教程里的修改中断函数即可解决
3、修改SysTick_handle中断函数
TencentOS-tiny内核需要Systick提供时钟节拍,在 SysTick_Handler 函数中添加 TencentOS tiny 的调度处理函数;
tos_knl_is_running() 函数判断内核是否正在运行;
os_tick_handler() 函数是系统用于更新时基用的。
此处参考:原文链接:TencentOS-tiny 移植到STM32F407(MDK)
4、运行
利用教程的主函数,运行
#include "stm32f10x.h"
#include "bsp_usart.h"
#include "tos_k.h"
k_task_t task;
k_stack_t task_stack[1024];
void test_task(void *Parameter)
{
while(1)
{
printf("hello world!\r\n");
tos_task_delay(1000);
}
}
/**
* @brief 主函数
* @author 杰杰
* @retval 无
*/
int main(void)
{
k_err_t err;
/*初始化USART 配置模式为 115200 8-N-1,中断接收*/
USART_Config();
printf("Welcome to TencentOS tiny\r\n");
tos_knl_init(); // TOS Tiny kernel initialize
err = tos_task_create(&task,
"task1",
test_task,
NULL,
2,
task_stack,
1024,
20);
if(err != K_ERR_NONE)
printf("TencentOS Create task fail! code : %d \r\n",err);
tos_knl_start(); // Start TOS Tiny
}