找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

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

鴻蒙系統(tǒng)移植到CH32V307單片機(jī)上

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
鴻蒙系統(tǒng)開(kāi)始被越來(lái)越多的設(shè)備所應(yīng)用,它是一款基于物聯(lián)網(wǎng)的操作系統(tǒng),本例程是把它移植到CH32V307這個(gè)國(guó)產(chǎn)32位單片機(jī)上面,讓越來(lái)越多的朋友使用華為的操作系統(tǒng),系統(tǒng)已經(jīng)移植好,大家下載之后可直接使用,無(wú)需關(guān)心移植的復(fù)雜過(guò)程。
以下是系統(tǒng)工程目錄:


以下是鴻蒙系統(tǒng)目錄:



以下是部分展示的代碼:
  1. /*
  2. * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
  3. * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this list of
  9. *    conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice, this list
  12. *    of conditions and the following disclaimer in the documentation and/or other materials
  13. *    provided with the distribution.
  14. *
  15. * 3. Neither the name of the copyright holder nor the names of its contributors may be used
  16. *    to endorse or promote products derived from this software without specific prior written
  17. *    permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  21. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  23. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  24. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  25. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  26. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  27. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  28. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  29. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. */

  31. #include "debug.h"
  32. #include "los_tick.h"
  33. #include "los_task.h"
  34. #include "los_config.h"
  35. #include "los_interrupt.h"
  36. #include "los_debug.h"
  37. #include "los_compiler.h"

  38. /* Global define */


  39. /* Global Variable */
  40. __attribute__((aligned (8))) UINT8 g_memStart[LOSCFG_SYS_HEAP_SIZE];
  41. UINT32 g_VlaueSp=0;


  42. /*********************************************************************
  43. * @fn      taskSampleEntry2
  44. *
  45. * @brief   taskSampleEntry2 program.
  46. *
  47. * @return  none
  48. */
  49. VOID taskSampleEntry2(VOID)
  50. {
  51.     while(1) {
  52.       LOS_TaskDelay(5000);
  53.       printf("taskSampleEntry2 running,task2 SP:%08x\n",__get_SP());
  54.     }
  55. }

  56. /*********************************************************************
  57. * @fn      taskSampleEntry1
  58. *
  59. * @brief   taskSampleEntry1 program.
  60. *
  61. * @return  none
  62. */
  63. VOID taskSampleEntry1(VOID)
  64. {
  65.     while(1) {
  66.       LOS_TaskDelay(1000);
  67.       printf("taskSampleEntry1 running,task1 SP:%08x\n",__get_SP());
  68.     }

  69. }

  70. /*********************************************************************
  71. * @fn      EXTI0_INT_INIT
  72. *
  73. * @brief   Initializes EXTI0 collection.
  74. *
  75. * @return  none
  76. */
  77. void EXTI0_INT_INIT(void)
  78. {
  79.   GPIO_InitTypeDef  GPIO_InitStructure={0};
  80.   EXTI_InitTypeDef EXTI_InitStructure={0};
  81.   NVIC_InitTypeDef NVIC_InitStructure={0};

  82.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO|RCC_APB2Periph_GPIOA,ENABLE);

  83.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
  84.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  85.   GPIO_Init(GPIOA, &GPIO_InitStructure);

  86.    /* GPIOA ----> EXTI_Line0 */
  87.   GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource0);
  88.   EXTI_InitStructure.EXTI_Line=EXTI_Line0;
  89.   EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  90.   EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
  91.   EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  92.   EXTI_Init(&EXTI_InitStructure);

  93.   NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
  94.   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  95.   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 4;
  96.   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  97.   NVIC_Init(&NVIC_InitStructure);
  98. }

  99. /*********************************************************************
  100. * @fn      taskSample
  101. *
  102. * @brief   taskSample program.
  103. *
  104. * @return  none
  105. */
  106. UINT32 taskSample(VOID)
  107. {
  108.     UINT32  uwRet;
  109.     UINT32 taskID1,taskID2;
  110.     TSK_INIT_PARAM_S stTask={0};
  111.     stTask.pfnTaskEntry = (TSK_ENTRY_FUNC)taskSampleEntry1;
  112.     stTask.uwStackSize  = 0X500;
  113.     stTask.pcName       = "taskSampleEntry1";
  114.     stTask.usTaskPrio   = 6;/* 高優(yōu)先級(jí) */
  115.     uwRet = LOS_TaskCreate(&taskID1, &stTask);
  116.     if (uwRet != LOS_OK) {
  117.         printf("create task1 failed\n");
  118.     }

  119.     stTask.pfnTaskEntry = (TSK_ENTRY_FUNC)taskSampleEntry2;
  120.     stTask.uwStackSize  = 0X500;
  121.     stTask.pcName       = "taskSampleEntry2";
  122.     stTask.usTaskPrio   = 7;/* 低優(yōu)先級(jí) */
  123.     uwRet = LOS_TaskCreate(&taskID2, &stTask);
  124.     if (uwRet != LOS_OK) {
  125.         printf("create task2 failed\n");
  126.     }

  127.     EXTI0_INT_INIT();
  128.     return LOS_OK;
  129. }

  130. /*********************************************************************
  131. * @fn      main
  132. *
  133. * @brief   Main program.
  134. *
  135. * @return  none
  136. */
  137. LITE_OS_SEC_TEXT_INIT int main(void)
  138. {
  139.     unsigned int ret;

  140.           NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
  141.     SystemCoreClockUpdate();
  142.     Delay_Init();
  143.           USART_Printf_Init(115200);
  144.                
  145.           printf("SystemClk:%d\r\n",SystemCoreClock);
  146.           printf( "ChipID:%08x\r\n", DBGMCU_GetCHIPID() );

  147.     ret = LOS_KernelInit();
  148.     taskSample();
  149.     if (ret == LOS_OK)
  150.     {
  151.         LOS_Start();
  152.     }

  153.     while (1) {
  154.         __asm volatile("nop");
  155.     }

  156. }


  157. /*********************************************************************
  158. * @fn      EXTI0_IRQHandler
  159. *
  160. * @brief   This function handles EXTI0 Handler.
  161. *
  162. * @return  none
  163. */
  164. void EXTI0_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
  165. void EXTI0_IRQHandler(void)
  166. {
  167.   /* 中斷棧使用的是原來(lái)調(diào)用main設(shè)置的值,將中斷棧和線程棧分開(kāi),這樣線程跳中斷,中斷函數(shù)如果嵌套深度較大,不至于
  168.    * 線程棧被壓滿溢出,但是采用當(dāng)前方式,線程進(jìn)中斷時(shí),編譯器保存到的16個(gè)caller寄存器任然壓入線程棧,如果需要希
  169.    * 望caller寄存器壓入中斷棧,則中斷函數(shù)的入口和出口需要使用匯編,中間調(diào)用用戶中斷處理函數(shù)即可,詳見(jiàn)los_exc.S
  170.    * 中的ipq_entry例子
  171.    *  */
  172.   GET_INT_SP();
  173.   HalIntEnter();
  174.   if(EXTI_GetITStatus(EXTI_Line0)!=RESET)
  175.   {
  176.     g_VlaueSp= __get_SP();
  177.     printf("Run at EXTI:");
  178.     printf("interruption sp:%08x\r\n",g_VlaueSp);
  179.     HalDisplayTaskInfo();
  180.     EXTI_ClearITPendingBit(EXTI_Line0);     /* Clear Flag */
  181.   }
  182.   HalIntExit();
  183.   FREE_INT_SP();
  184. }
復(fù)制代碼
原理圖: 無(wú)
仿真: 無(wú)
代碼: HarmonyOS.7z (335.05 KB, 下載次數(shù): 17)

評(píng)分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎(jiǎng)勵(lì)!

查看全部評(píng)分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏3 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

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

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