找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1256|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

TencentOS移植到CH32V307

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
TencentOS是騰訊公司開發(fā)的一款應(yīng)用于嵌入式平臺(tái)的物聯(lián)網(wǎng)操作系統(tǒng),提供了物聯(lián)網(wǎng)相關(guān)的組件;本項(xiàng)目把TencentOS系統(tǒng)移植到CH32V307單片機(jī)上面,本例程下載之后可以直接應(yīng)用,無須考濾復(fù)雜的移植過程,快速進(jìn)入操作系統(tǒng)應(yīng)用。
整個(gè)系統(tǒng)工程目錄如圖所示:


對于操作系統(tǒng)相關(guān)的源碼,單獨(dú)建立了一個(gè)文件夾,


下面是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. }
復(fù)制代碼
原理圖: 無
仿真: 無
代碼: TencentOS.rar (133.29 KB, 下載次數(shù): 4)
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表