preface

OpenHarmony is coming out with its first open source and only supports LitEOS-A, so it’s worth learning about LiteOS here. Harmony may not be used at work, but a single spark can start a prairie fire and help improve the lot ecology. Let’s start with MCU, porting LiteOS.

link

  • LiteOS source link

  • The development board has been ported

  • Q&A

  • Huawei Developer Community

  • Huawei LiteOS official tutorial

  • My source

    • Contains bare – metal source code
    • LiteOS Project template
    • Other LiteOS demo and note

reference

  • A wildfire
  • The above link

Record of the draft

  • Most of the content in los_init.c has been moved to los_config.c, so you can see what’s in there
  • To use software timers, message queues must be used, otherwise software timers will not be used.

Porting (2018)

  • It is not recommended to obtain the latest (do not use 202003) push version *) version of the default only support GCC, and MDK official migration tutorial is not out. Therefore, the source code for LiteRTOS can only be obtained at Github to migrate LiteRTOS. (As at 20200922)

  • There are two migration schemes:

    • Hard interrupt takeover scheme
    • Do not take over interrupt schemes
  • The hard interrupt takeover scheme is more difficult to migrate than the non-takeover interrupt scheme. Therefore, note taking does not take over the interrupt scheme this time.

Migration acquisition (The kernel architecture (M)

* RAM > 8K * ROM > 20KCopy the code
  • Bare machine and empty engineering
    • Can run the main function properly
    • This migration is based on STM32F103VCT6
  • LiteOS source
    • As of 20200922, it is not recommended to obtain the latest source code pushed by the official, because the latest version only supports GCC by default, and MDK official migration tutorial has not been published. (You can try to obtain the latest version + completion of an earlier version)
    • You are advised to obtain the version promoted around 2018.
  • The source code for this tutorial is from the 2018 version, and it will also be explained against the new version.

Major Folder Analysis

Official code guide * This link is the latest version of the file analysis, and the following will be different, according to the actual download version guide *

  • arch
    • arm
      • Arm-m: indicates the codes related to M core interrupt, scheduling, and TICK
      • Common: cmSIS core interface common to arm cores
  • components
    • Cmsis: Implementation of the CMSIS OS interface provided by LiteOS
  • kernel
    • base
      • Core: LiteOS basic kernel code file, including queuing, task scheduling, soft timer, time slice, and other functions
      • OM: Files related to error handling
      • Include: A header file used internally by the LiteOS kernel
      • Ipc: Code files related to IPC communication in LiteOS, including events, semaphores, message queues, mutex, etc
      • Mem: Kernel memory management code in LiteOS
      • Misc: Memory alignment and millisecond sleep
    • Include: LiteOS Open kernel header file
    • extenden
      • Ticless: Low power framework code

Migration process

1. Copy files

  • Create the LiteOS folder on the project path
  • Copy the LiteOS source codeThe arch, cmsis(Cmsis OS interface implementation provided by LiteOS)

And kernel into the project LiteOS folder.

  • Copy LiteOS source code correspondingdemosOS_CONFIGFolder to the above path.
    • OS_CONFIG Specifies the configuration file used for kernel configuration and tailoring.
  • Copy a folder from the Keil installation directory to the projectEngineering/Libraries/CMSIS.
    • Installation path A folder in the installation directory. The reference path is:D: \ Keil_v5 / ARM/Pack/ARM \ CMSIS \ 4.2.0 \ CMSIS \ Include
    • Transplantation of reason
      • Avoid compilation errors caused by the absence of relevant header files in the porting process on other computers.

2. Create a project group

4 new project clusters:

  • LiteOS/cmsis
    • Add the cmsis_liteos.c file
  • LiteOS/kernelAll the.c files you need)
    • \LiteOS\kernel\base\coreAll dot c files
    • \LiteOS\kernel\base\ipcAll dot c files
    • \LiteOS\kernel\base\mem\bestfit_littleAll dot c files
    • \LiteOS\kernel\base\mem\commonAll dot c files
    • \LiteOS\kernel\base\mem\memboxAll dot c files
    • \LiteOS\kernel\base\miscAll dot c files
    • \LiteOS\kernel\base\omAll dot c files
    • \LiteOS\kernel\extended\ticklessAll dot c files
    • \LiteOS\kernel los_init.c
  • LiteOS/arch
    • \LiteOS\arch\arm\arm-m\srcAll dot c files
    • \LiteOS\arch\arm\arm-m\cortex-m? \keil los_dispatch_keil.S
      • ? : represents which kernel chip needs to be ported to. Such as architecture (m3.
  • LiteOS/config
    • \LiteOS\OS_CONFIG
      • Los_builddef. H (optional)
      • Los_printf. H (optional)
      • target_config.h

3. Add the header file path

Reference pictures:

Compatible with C99 mode

  • Select C99 Mode from Target ->C/C++->Language/Code Generation
  • Type in the Target ->C/C++->MiscControls box– diag_suppress,47,177,186,223,1295 = 1
    • It means ignore the numbers

5. Kernel configuration and tailoring (non-takeover interrupt STM32F103VCT6)

  • Mainly in thetarget_config.hFile configuration, specific content directly look at the source code, here list a few main points:
    • Modify header file#include "stm32f1xx.h"for#include "stm32f10x.h"
    • The macroOS_SYS_CLOCK
      • Indicates the CPU frequency
      • For example, if STM32VCT6 is set to 72MHz, the value is 72000000
    • The macroLOSCFG_BASE_CORE_TICK_PER_SECOND
      • RTOS heartbeat
        • For STM32F10x, the value ranges from 1ms to 10ms. If the value is 1ms, the value is 1000UL
    • Memory address
      • Macro BOARD_SRAM_START_ADDR

        • Based on the actual address of the RAM configuration in the compiler, this is 0x20000000.
      • Macro BOARD_SRAM_SIZE_KB

        • The memory allocated for system use is the total stack managed by the RTOS. This is set to 20.

6. Mask two interrupts in bare devices

Comment out PendSV and SysTick interrupts in the stm32fxxx_it.c file.

  • SysTick
    • Mainly provides the heartbeat.
  • PendSV
    • This exception can enter the task scheduling detection and schedule.

7. Improve your code

This project is based on the naked machine frame prepared by me, you can refer to the need.

  • Add the following header files to the lssappconfig.h file:
/* ********************************************************************************************************* * OS * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
#include "target_config.h" 
#include "los_sys.h"
#include "los_typedef.h"
#include "los_task.ph" 
#include "los_sem.h" 
Copy the code
  • No nonsense, directly on the main. C file (read the source code is much more convenient than the text tutorial)
    • Main reference source code
      • Task creation function
      • Start the process
    • The source of the start process is the task to create task scheme.
/** ****************************************************************************** * @file main.c * @author lss * @version V1.0 * @date 2020-xx-xx * @brief Main function file * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * @ attention * * experiment platform: LZM * Wechat: qabc132321 ****************************************************************************** */
  
/* ********************************************************************************************************* * INCLUDE * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
/* APP Config File */
#include "LssAppConfig.h"
/* prv */
#include "userMemoryConfig.h"

/* task */
#include "LedTask.h"
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * the board information [note] revise * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
BoardInfo_t BoardInfo = {    .name = "LSS TEST",
                                        .boardType = 0,
                                        .boardNum = 0};/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * the firmware version * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
#if defined(__CC_ARM) // Compiler dependent
const unsigned MCU_VERSION1_ENTRY __attribute__((at(ParameterSectionVEntry))) = SystemProgramAddressEntry;
const unsigned MCU_VERSION1_SIZE     __attribute__((at(ParameterSectionVEntry+0X04))) = SystemProgramAddressSize;
const unsigned CRP_VERSION1_NUM     __attribute__((at(ParameterSectionVEntry+0X08))) = (0x01000000);
#endif

/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * function declarations * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
void vStartTask (void );
                                        
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * handle variable declarations * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
static UINT32 xStartTask_Handle           = NULL;
UINT32 xLedTask_Handle                      = NULL;  / / the LED task


/** * @brief Creates a vStartTask task * @param * @retval * @author LZM */
static UINT32 Creat_vStartTask_Task(a)
{
	// Define the return type of a create task, initialized to the return value of success
	UINT32 uwRet = LOS_OK;			
	// Define a parameter structure for creating a task
	TSK_INIT_PARAM_S task_init_param;	

	task_init_param.usTaskPrio = lssConfigvStartTaskPRIO;	/* Task priority, the smaller the value, the higher the priority */
	task_init_param.pcName = "Start_Task";/* Task name */
	task_init_param.pfnTaskEntry = (TSK_ENTRY_FUNC)vStartTask;/* Task function entry */
	task_init_param.uwStackSize = lssConfigvStartTaskSIZE;		/* Stack size */

	uwRet = LOS_TaskCreate(&xStartTask_Handle, &task_init_param);/* Create a task */
	return uwRet;
}
                                        
/** * @brief Creates a vLedTask * @param * @retval * @author LZM */
static UINT32 Creat_vLedTask_Task(a)
{{
	// Define the return type of a create task, initialized to the return value of success
	UINT32 uwRet = LOS_OK;			
	
	TSK_INIT_PARAM_S task_init_param;	

	task_init_param.usTaskPrio = lssConfigvLedTaskPRIO;
	task_init_param.pcName = "Led Task";
	task_init_param.pfnTaskEntry = (TSK_ENTRY_FUNC)vLedTask;
	task_init_param.uwStackSize = lssConfigvLedTaskSIZE;

	uwRet = LOS_TaskCreate(&xLedTask_Handle, &task_init_param);
	return uwRet;
}
                                        
/** * @brief Create an application task * @param * @retval * @author LZM */
void vStartTask (void )
{
    UINT32 uwRet = LOS_OK;
    UINTPTR uvIntSave;    
    // enter critical
    taskENTER_CRITICAL(uvIntSave);   
    uwRet = Creat_vLedTask_Task();
	if(uwRet ! = LOS_OK) { ; }// Delete this task
    LOS_TaskDelete(xStartTask_Handle);     
    // Exit critical
    taskEXIT_CRITICAL(uvIntSave);    
}
                                        
                                                                       
                                        
/** * @brief mian function * @param * @retval * @author LZM */
int main(void)
{	
    uint32_t uwRet = LOS_OK;  // Define a return value for task creation, which defaults to success
    
	/ / BSP initialization
	bspInit();	
    
    /* LiteOS kernel initialization */
	uwRet = LOS_KernelInit();
    if(uwRet ! = LOS_OK) { ; }/* Create create task */
    uwRet = Creat_vStartTask_Task();
    if(uwRet ! = LOS_OK) { ; }/* Enable LiteOS task scheduling */
    LOS_Start();
    
	while(1);
}
Copy the code