找回密码
 立即注册

QQ登录

只需一步,快速开始

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

鸿蒙系统移植到CH32V307单片机上

[复制链接]
跳转到指定楼层
楼主
鸿蒙系统开始被越来越多的设备所应用,它是一款基于物联网的操作系统,本例程是把它移植到CH32V307这个国产32位单片机上面,让越来越多的朋友使用华为的操作系统,系统已经移植好,大家下载之后可直接使用,无需关心移植的复杂过程。
以下是系统工程目录:


以下是鸿蒙系统目录:



以下是部分展示的代码:
  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;/* 高优先级 */
  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;/* 低优先级 */
  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.   /* 中断栈使用的是原来调用main设置的值,将中断栈和线程栈分开,这样线程跳中断,中断函数如果嵌套深度较大,不至于
  168.    * 线程栈被压满溢出,但是采用当前方式,线程进中断时,编译器保存到的16个caller寄存器任然压入线程栈,如果需要希
  169.    * 望caller寄存器压入中断栈,则中断函数的入口和出口需要使用汇编,中间调用用户中断处理函数即可,详见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. }
复制代码
原理图: 无
仿真: 无
代码: HarmonyOS.7z (335.05 KB, 下载次数: 11)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏3 分享淘帖 顶 踩
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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