|
鴻蒙系統(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)工程目錄:
a1.PNG (19.8 KB, 下載次數(shù): 23)
下載附件
2024-1-5 15:43 上傳
以下是鴻蒙系統(tǒng)目錄:
b2.PNG (10.71 KB, 下載次數(shù): 29)
下載附件
2024-1-5 15:44 上傳
以下是部分展示的代碼:
- /*
- * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * 3. Neither the name of the copyright holder nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific prior written
- * permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- #include "debug.h"
- #include "los_tick.h"
- #include "los_task.h"
- #include "los_config.h"
- #include "los_interrupt.h"
- #include "los_debug.h"
- #include "los_compiler.h"
- /* Global define */
- /* Global Variable */
- __attribute__((aligned (8))) UINT8 g_memStart[LOSCFG_SYS_HEAP_SIZE];
- UINT32 g_VlaueSp=0;
- /*********************************************************************
- * @fn taskSampleEntry2
- *
- * @brief taskSampleEntry2 program.
- *
- * @return none
- */
- VOID taskSampleEntry2(VOID)
- {
- while(1) {
- LOS_TaskDelay(5000);
- printf("taskSampleEntry2 running,task2 SP:%08x\n",__get_SP());
- }
- }
- /*********************************************************************
- * @fn taskSampleEntry1
- *
- * @brief taskSampleEntry1 program.
- *
- * @return none
- */
- VOID taskSampleEntry1(VOID)
- {
- while(1) {
- LOS_TaskDelay(1000);
- printf("taskSampleEntry1 running,task1 SP:%08x\n",__get_SP());
- }
- }
- /*********************************************************************
- * @fn EXTI0_INT_INIT
- *
- * @brief Initializes EXTI0 collection.
- *
- * @return none
- */
- void EXTI0_INT_INIT(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure={0};
- EXTI_InitTypeDef EXTI_InitStructure={0};
- NVIC_InitTypeDef NVIC_InitStructure={0};
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO|RCC_APB2Periph_GPIOA,ENABLE);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- /* GPIOA ----> EXTI_Line0 */
- GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource0);
- EXTI_InitStructure.EXTI_Line=EXTI_Line0;
- EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
- EXTI_InitStructure.EXTI_LineCmd = ENABLE;
- EXTI_Init(&EXTI_InitStructure);
- NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 4;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- }
- /*********************************************************************
- * @fn taskSample
- *
- * @brief taskSample program.
- *
- * @return none
- */
- UINT32 taskSample(VOID)
- {
- UINT32 uwRet;
- UINT32 taskID1,taskID2;
- TSK_INIT_PARAM_S stTask={0};
- stTask.pfnTaskEntry = (TSK_ENTRY_FUNC)taskSampleEntry1;
- stTask.uwStackSize = 0X500;
- stTask.pcName = "taskSampleEntry1";
- stTask.usTaskPrio = 6;/* 高優(yōu)先級(jí) */
- uwRet = LOS_TaskCreate(&taskID1, &stTask);
- if (uwRet != LOS_OK) {
- printf("create task1 failed\n");
- }
- stTask.pfnTaskEntry = (TSK_ENTRY_FUNC)taskSampleEntry2;
- stTask.uwStackSize = 0X500;
- stTask.pcName = "taskSampleEntry2";
- stTask.usTaskPrio = 7;/* 低優(yōu)先級(jí) */
- uwRet = LOS_TaskCreate(&taskID2, &stTask);
- if (uwRet != LOS_OK) {
- printf("create task2 failed\n");
- }
- EXTI0_INT_INIT();
- return LOS_OK;
- }
- /*********************************************************************
- * @fn main
- *
- * @brief Main program.
- *
- * @return none
- */
- LITE_OS_SEC_TEXT_INIT int main(void)
- {
- unsigned int ret;
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
- SystemCoreClockUpdate();
- Delay_Init();
- USART_Printf_Init(115200);
-
- printf("SystemClk:%d\r\n",SystemCoreClock);
- printf( "ChipID:%08x\r\n", DBGMCU_GetCHIPID() );
- ret = LOS_KernelInit();
- taskSample();
- if (ret == LOS_OK)
- {
- LOS_Start();
- }
- while (1) {
- __asm volatile("nop");
- }
- }
- /*********************************************************************
- * @fn EXTI0_IRQHandler
- *
- * @brief This function handles EXTI0 Handler.
- *
- * @return none
- */
- void EXTI0_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
- void EXTI0_IRQHandler(void)
- {
- /* 中斷棧使用的是原來(lái)調(diào)用main設(shè)置的值,將中斷棧和線程棧分開(kāi),這樣線程跳中斷,中斷函數(shù)如果嵌套深度較大,不至于
- * 線程棧被壓滿溢出,但是采用當(dāng)前方式,線程進(jìn)中斷時(shí),編譯器保存到的16個(gè)caller寄存器任然壓入線程棧,如果需要希
- * 望caller寄存器壓入中斷棧,則中斷函數(shù)的入口和出口需要使用匯編,中間調(diào)用用戶中斷處理函數(shù)即可,詳見(jiàn)los_exc.S
- * 中的ipq_entry例子
- * */
- GET_INT_SP();
- HalIntEnter();
- if(EXTI_GetITStatus(EXTI_Line0)!=RESET)
- {
- g_VlaueSp= __get_SP();
- printf("Run at EXTI:");
- printf("interruption sp:%08x\r\n",g_VlaueSp);
- HalDisplayTaskInfo();
- EXTI_ClearITPendingBit(EXTI_Line0); /* Clear Flag */
- }
- HalIntExit();
- FREE_INT_SP();
- }
復(fù)制代碼 原理圖: 無(wú)
仿真: 無(wú)
代碼:
HarmonyOS.7z
(335.05 KB, 下載次數(shù): 17)
2024-1-5 19:29 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
評(píng)分
-
查看全部評(píng)分
|