找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 311|回复: 0
打印 上一主题 下一主题
收起左侧

TencentOS移植到CH32V307

[复制链接]
跳转到指定楼层
楼主
TencentOS是腾讯公司开发的一款应用于嵌入式平台的物联网操作系统,提供了物联网相关的组件;本项目把TencentOS系统移植到CH32V307单片机上面,本例程下载之后可以直接应用,无须考滤复杂的移植过程,快速进入操作系统应用。
整个系统工程目录如图所示:


对于操作系统相关的源码,单独建立了一个文件夹,


下面是main.c文件中的代码:
  1. /********************************** (C) COPYRIGHT *******************************
  2. * File Name          : main.c
  3. * Author             : WCH
  4. * Version            : V1.0.0
  5. * Date               : 2021/06/06
  6. * Description        : Main program body.
  7. *********************************************************************************
  8. * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
  9. * Attention: This software (modified or not) and binary are used for
  10. * microcontroller manufactured by Nanjing Qinheng Microelectronics.
  11. *******************************************************************************/

  12. /*
  13. *@Note
  14. GPIO routine:
  15. PA0push-pull output.

  16. */

  17. #include "debug.h"
  18. #include "tos_k.h"


  19. /* Global define */


  20. /* Global Variable */


  21. /*********************************************************************
  22. * @fn      GPIO_Toggle_INIT
  23. *
  24. * @brief   Initializes GPIOA.0
  25. *
  26. * @return  none
  27. */
  28. void GPIO_Toggle_INIT(void)
  29. {
  30.   GPIO_InitTypeDef  GPIO_InitStructure;

  31.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
  32.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
  33.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  34.   GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
  35.   GPIO_Init(GPIOA, &GPIO_InitStructure);
  36. }


  37. #define TASK1_STK_SIZE       1024
  38. k_task_t task1;
  39. __aligned(4) uint8_t task1_stk[TASK1_STK_SIZE];


  40. #define TASK2_STK_SIZE       1024
  41. k_task_t task2;
  42. __aligned(4) uint8_t task2_stk[TASK2_STK_SIZE];

  43. void task1_entry(void *arg)
  44. {
  45.     while (1)
  46.     {
  47.         printf("###I am task1\r\n");
  48.         tos_task_delay(2000);
  49.     }
  50. }

  51. void task2_entry(void *arg)
  52. {
  53.     while (1)
  54.     {
  55.         printf("***I am task2\r\n");
  56.         tos_task_delay(1000);
  57.     }
  58. }


  59. /*********************************************************************
  60. * @fn      main
  61. *
  62. * @brief   Main program.
  63. *
  64. * @return  none
  65. */
  66. int main(void)
  67. {
  68.         USART_Printf_Init(115200);
  69.         SystemCoreClockUpdate();        
  70.         printf("SystemClk:%d\r\n",SystemCoreClock);
  71.         printf( "ChipID:%08x\r\n", DBGMCU_GetCHIPID() );
  72.         printf("Welcome to TencentOS tiny(%s)\r\n", TOS_VERSION);
  73.     tos_knl_init();
  74.     tos_task_create(&task1, "task1", task1_entry, NULL, 3, task1_stk, TASK1_STK_SIZE, 0); // Create task1
  75.     tos_task_create(&task2, "task2", task2_entry, NULL, 3, task2_stk, TASK2_STK_SIZE, 0);// Create task2
  76.     tos_knl_start();

  77.     printf("should not run at here!\r\n");

  78.     while(1)
  79.         {
  80.             asm("nop");
  81.         }
  82. }
复制代码
原理图: 无
仿真: 无
代码: TencentOS.rar (133.29 KB, 下载次数: 2)
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表