You are on page 1of 35

Huawei LiteOS Architecture

Copyright © 2019 Huawei Technologies Co., Ltd. All rights reserved.


Foreword
⚫ Huawei LiteOS, a one-stop software platform for developers, makes IoT
terminals easier to develop and connect, and provides smarter services,
better user experience, and more secure data.

Page 2 Copyright © 2019 Huawei Technologies Co., Ltd. All rights reserved.
Objectives
⚫ After completing this course, you will be able to:
 Master the Huawei LiteOS architecture.

 Master the basic kernel modules of Huawei LiteOS, understand the principles of
each module, and describe the functions of each module.

 Understand the functions of the Huawei LiteOS framework.

 Understand the Huawei LiteOS application programming interface (API)


function.

Page 3 Copyright © 2019 Huawei Technologies Co., Ltd. All rights reserved.
Contents
1. Huawei LiteOS Kernel

2. Huawei LiteOS Framework

3. Huawei LiteOS APIs

Page 4 Copyright © 2019 Huawei Technologies Co., Ltd. All rights reserved.
Huawei LiteOS Framework
⚫ Huawei LiteOS is a lightweight IoT OS developed by Huawei. This system complies
with the BSD-3 open source license agreement and can be widely used in smart
homes, wearable devices, Internet of Vehicles (IOV), urban public services,
manufacturing and so on.
Industry applications

Sensing Low power

Security framework
Interconnection
framework consumption

IDE tools
AI JS engine

LiteOS lightweight kernel

Page 5 Copyright © 2019 Huawei Technologies Co., Ltd. All rights reserved.
Huawei LiteOS Kernel
⚫ Huawei LiteOS Kernel, as the kernel of the
LiteOS, is the simplest Huawei LiteOS,
Basic kernel
which consists of basic OS components Memory
Dynamic memory
Time management
such as task management, memory System time
Static memory

management, time management, Tick Message queue

communication mechanism, interrupt Software timer


IPC
Event

management, queue management, event

synchronization
Hardware
Semaphore
management, and timer. The Huawei

Task
Hardware interrupt
Mutex
LiteOS Kernel can run independently. Exception

Hardware timer Task Scheduling


⚫ In addition, the tickless mechanism is
supported to better adapt to low-power Hardware abstraction layer
consumption scenarios.
Third-party MCU/Chip

Page 6 Copyright © 2019 Huawei Technologies Co., Ltd. All rights reserved.
Huawei LiteOS Kernel—Task
⚫ A task is the minimum running unit to compete for system resources. A task can
use or wait for system resources such as Central Processing Unit (CPU) and
memory and run independently.

⚫ A task can be created, deleted, delayed, suspended, resumed, locked, and


unlocked for task scheduling.

⚫ The task scheduling mechanism is based on priority-based preemption. Tasks with


the same priority can be scheduled in time slice rotation mode.

⚫ The Huawei LiteOS tasks have 32 priorities: 0-31. The highest priority is 0, and the
lowest is 31. A task with a higher priority can preempt a task with a lower one. A
task with a lower priority can be scheduled only after the task with a higher one is
blocked or ended.

Page 7 Copyright © 2019 Huawei Technologies Co., Ltd. All rights reserved.
Task Programming Instance
⚫ Task interface description:

Function Category Interface Name Description


Task creation and deletion LOS_TaskCreate Creates a task, so that the task is ready for scheduling.
LOS_TaskDelete Deletes a task.
Task status control LOS_TaskResume Resumes a suspended task.
LOS_TaskSuspend Suspends a task.
LOS_TaskDelay Delays a task.
Task scheduling control LOS_TaskLock Locks a task.
LOS_TaskUnlock Unlocks a task.
⚫ Programming instance (Example: los_api_task.c)

⚫ Compilation result:

Page 8 Copyright © 2019 Huawei Technologies Co., Ltd. All rights reserved.
Huawei LiteOS Kernel—Memory Management
⚫ Memory is a very important resource in a system. Memory management, a
core function of the OS, is to initialize, allocate, and release memory
resources.

⚫ Huawei LiteOS provides two types of memory management algorithms:


membox for static memory allocation, and bestfit, bestfit_little, and two-
level segregated fit (tlsf) for dynamic memory allocation.

⚫ In addition, memory statistics and memory overwriting detection functions


are provided.

Page 9 Copyright © 2019 Huawei Technologies Co., Ltd. All rights reserved.
Huawei LiteOS Kernel—Dynamic Memory
⚫ A random-size of memory block in the dynamic memory pool is allocated to a user.

⚫ All memory blocks are linked together using linked lists. A TLSF has multiple linked
lists. When a memory block is released to the memory pool, the idle blocks before
and after the memory block are linked automatically. Each block starts with a
header structure for management. Allocated blocks also have this header structure.

⚫ Advantages
 Allocation on demand; large blocks are cost-effective.

⚫ Disadvantages
 Memory waste in case of massive small blocks due to the header for management

 Fragments in the memory pool

 High performance overheads


Page 10 Copyright © 2019 Huawei Technologies Co., Ltd. All rights reserved.
Huawei LiteOS Kernel—Static Memory
⚫ A preset (fixed)-size of memory block in the static memory pool is allocated to a
user during initialization.

⚫ It is also called an object pool, though essentially an object array.

⚫ Advantages
 High performance, compared with that of dynamic memory management

 High efficiency in memory allocation and releasing, because of no header structure for
management in each block

 No fragment in the static memory pool

⚫ Disadvantages
 Fixed size, not allocated on demand

 Lame for large object management


Page 11 Copyright © 2019 Huawei Technologies Co., Ltd. All rights reserved.
Memory Management Programming Instance
⚫ Memory management interface description:
Function Category Interface Name Description
Initializes a fixed-size of dynamic memory
Memory initialization LOS_MemInit
pool.
Allocates a fixed-size of memory from the
Dynamic memory allocation LOS_MemAlloc
dynamic memory pool.
Dynamic memory release LOS_MemFree Releases the allocated memory.

⚫ Programming instance (Example: los_api_task.c)

⚫ Compilation result:

Page 12 Copyright © 2019 Huawei Technologies Co., Ltd. All rights reserved.
Huawei LiteOS Kernel—Interrupt
⚫ An interrupt refers to the process in which the CPU stops to execute a new program when
necessary.

⚫ With the interrupt mechanism, the CPU can execute other tasks when the peripherals do
not require the CPU. When the peripherals require the CPU, the CPU can interrupt the
current task to respond to the interrupt request by generating the interrupt signal. In this
way, the CPU does not need to spend a lot of time in waiting and querying the peripheral
status.

⚫ Huawei LiteOS supports interrupt response and interrupt non-response.

⚫ An interrupt can be initialized, created, started, stopped, resumed, enabled, and masked.

Page 13 Copyright © 2019 Huawei Technologies Co., Ltd. All rights reserved.
Inter-Task Communication
⚫ The multi-task synchronization, mutual exclusion, and communication of
Huawei LiteOS are as follows:
 Queue

 Event

 Semaphore

 Mutex

Page 14 Copyright © 2019 Huawei Technologies Co., Ltd. All rights reserved.
Huawei LiteOS Kernel—Queue
⚫ A queue, also called message queue, is a data structure commonly used for
inter-task communication. A queue receives messages of variable lengths
from tasks or interrupts and determines whether to store messages in its
own space based on interfaces.

⚫ When a user processes a service, the message queue provides an


asynchronous processing mechanism. The user is allowed to put a message
into a queue but do not process it immediately. In addition, the queue can
buffer messages, which is used to transfer data between tasks.

⚫ A queue can be created, deleted, sent, and received.

Page 15 Copyright © 2019 Huawei Technologies Co., Ltd. All rights reserved.
Huawei LiteOS Kernel—Event
⚫ An event is a mechanism for implementing communication between tasks. It can be used to
implement synchronization between tasks. However, event communication can only be
communication of event type and does not involve data transmission.

⚫ An event is not associated with a task. Events are independent of each other. A 32-bit
variable is used to identify the type of an event that occurs in a task. Each bit indicates an
event type. There are 31 event types (the 25th digitbit is reserved). The value 0 indicates
that the event does not occur, and the value 1 indicates that the event already occurs.

⚫ A task can be awaken by multiple events:


 A task is awaken for processing after an arbitrary event occurs.

 A task is awaken for processing after several events occur.

 Sending the same event type to a task for multiple times is equivalent to sending the event type to
the task only once.

Page 16 Copyright © 2019 Huawei Technologies Co., Ltd. All rights reserved.
Huawei LiteOS Kernel—Semaphore
⚫ A semaphore, as a mechanism for inter-task communication, enables tasks
to access system resources synchronously or access critical resources
exclusively. Typically, a semaphore is used to coordinate a group of
competing tasks to access to critical resources.

⚫ A semaphore places a limit on the number of tasks accessing the same


resource concurrently. When the number of tasks accessing the same
resource reaches the maximum, other tasks that attempt to obtain the
resource are blocked until the semaphore is released.

Page 17 Copyright © 2019 Huawei Technologies Co., Ltd. All rights reserved.
Huawei LiteOS Kernel—Mutex
⚫ A mutex is a special binary semaphore used to exclusively process shared
resources.

⚫ A mutex only has two statuses at any time: unlocked or locked.


 When a mutex is held by a task, the mutex is locked and the task obtains the
ownership of the mutex.

 When the task releases the mutex, the mutex is unlocked and the task loses the
ownership of the mutex. When a task holds a mutex, other tasks cannot unlock
or hold the mutex.

Page 18 Copyright © 2019 Huawei Technologies Co., Ltd. All rights reserved.
Huawei LiteOS Kernel—Time Management
⚫ Time management is based on the system clock. Time management provides all
time-related services for applications.
 When the output pulse generated by a timer or counter triggers an interrupt, the system
clock is generated. The system clock is generally defined as an integer or a long integer.
The period of the output pulse is called a "Tick". The system clock is also called time
scale or Tick. The duration of a Tick can be configured statically.

 The timing unit is second or millisecond, while the unit of the chip CPU timing is Tick.
When a user needs to perform an operation on the system, for example, task suspension
or delay, the user needs to input a value in second. In this case, unit conversion is
required.

Page 19 Copyright © 2019 Huawei Technologies Co., Ltd. All rights reserved.
Huawei LiteOS Kernel—Timer
⚫ Hardware timers are limited and cannot meet user requirements. Huawei
LiteOS provides the software timer function.

⚫ The software timer is a timer that is simulated by software depending on


Tick. After the configured Tick counts are reached, a user-defined callback
function is invoked. The timing precision is related to the period of the Tick.

⚫ The software timers are unlimited and can be created as required.

Page 20 Copyright © 2019 Huawei Technologies Co., Ltd. All rights reserved.
Features of Huawei LiteOS Kernel
⚫ Low power consumption, high real-time performance, and high stability

⚫ Ultra-small kernel; basic kernel can be tailored to less than 10 KB

⚫ Dynamic loading and distributed loading

⚫ Static tailoring

Page 21 Copyright © 2019 Huawei Technologies Co., Ltd. All rights reserved.
Contents
1. Huawei LiteOS Kernel

2. Huawei LiteOS Framework

3. Huawei LiteOS APIs

Page 22 Copyright © 2019 Huawei Technologies Co., Ltd. All rights reserved.
Huawei LiteOS SDK
⚫ Huawei LiteOS software development kit (SDK) includes the device-cloud
interconnection component, JS engine, and smart sensing framework.
User applications

Business process on carrier platform


FOTA upgrade SOTA upgrade
Interconnection
Component

LwM2M MQTT

Component
Attention adapter Automatically

Enhanced
CoAP UART configured
TLS Abstract module
DTLS Device PnP

Socket adapter layer Low power


consumption DTLS+
TCP/UDP
IPv4 IPv6
...
SIMCom SIM800 WiFi ESP8266 Quectel BC95/BC28

Tickless mechanism Memory management IPC


LiteOS kernel
Scheduler Interrupt management Exception Handling

Page 23 Copyright © 2019 Huawei Technologies Co., Ltd. All rights reserved.
Device-Cloud Interconnection Component
⚫ As an independent component, the LiteOS SDK device-cloud interconnection
component does not depend on specific chip architecture or network hardware
type and can be easily integrated into various communication modules, such as
the Narrow Band Internet of Things (NB-IoT) module, enhanced Machine-Type
Communication (eMTC) module, Wi-Fi module, Global System for Mobile
Communications (GSM) module, and Ethernet hardware.

⚫ The device-cloud interconnection component provides device-cloud collaboration


capabilities and integrates a full set of IoT interconnection protocol stacks such as
Lightweight Machine-To-Machine (LwM2M), Constrained Application Protocol
(CoAP), mbed TLS, and Lightweight IP (LwIP).

Page 24 Copyright © 2019 Huawei Technologies Co., Ltd. All rights reserved.
Software Architecture of Device-Cloud
Interconnection Component

IoT cloud
platform
IoT cloud
platform

Chip/Module/MCU
Chip/Module/MCU

Single Module/MCU MCU + Chip/Module

Page 25 Copyright © 2019 Huawei Technologies Co., Ltd. All rights reserved.
Interconnection Framework

Cloud Application profile


Lamp management
platform CoAP
system
Street lamp
Gateway
controller
IoT
Application Application Application LiteOS/ gateway
profile profile profile 6LowPAN
MCU
CoAP CoAP CoAP Node
Lightweight UDP TCP/UDP TCP/UDP
Lightweight IP IP IP
Adaptation from
heterogeneous
protocols to IP
IEEE 802.11 IEEE 802.15.4
NB-IoT protocol
protocol protocol
Huawei LiteOS
Mesh network
NB-IoT device Wi-Fi ZigBee device
device Optimized Mesh network (self-organizing),
Interconnection framework ensures interconnection connects a large number of terminals.
between terminals running different protocols.
Page 26 Copyright © 2019 Huawei Technologies Co., Ltd. All rights reserved.
Smart Sensing Framework
⚫ The smart sensing framework provides unified management of sensors.

Pedomete Heart rate Environment


r detection checking
...

Unified sensing algorithm library


Multiple sensor
Fingerprint Motion Heart rate Environment ...
algorithm algorithm algorithm sensing algorithm terminals

Unified sensor interaction management


Sensor manager Configuring Sampling Reporting ...

Unified driver interface


BSP manager Open Read Write Ioctl ...

SPI I2C UART GPIO DMA

Temperature and Light Accelero Heart rate


Gyroscope
humidity sensor sensor meter sensor

Page 27 Copyright © 2019 Huawei Technologies Co., Ltd. All rights reserved.
Security Framework
Device-cloud security Whitelist

Cloud authorization and Bidirectional device Device management


authentication authentication (using LwM2M)

API authentication Whitelist DTLS


SafeArea

Transmission
Secure ID Bidirectional device RPL

security
authentication
Terminal
security
Key management Security firmware/Application Network layer security
upgrade

Secure storage Secure boot Data link layer security

Page 28 Copyright © 2019 Huawei Technologies Co., Ltd. All rights reserved.
JS Running Engine—MapleJS
⚫ MapleJS: enables advanced IoT dynamic languages to help developers focus on application
development.

Industry applications (smart city, smart home, industry IoT, ...)


services
Smart

Shared repository IoT development framework Toolsets

Smart home device HOTA Network IDE


Event-driven
capability library, smart adaptation port/UART
programming Commission &
JS programming

phone sensor capability library commissioning


environment

Network Optimization
library, industrial control Module-driven OS adaptation
adaptation
device capability library... programming
library
library Language check
tool
Deployment tool
MapleJS engine
Automatic
ECMA Automatic Static/dynamic Standard generation tool
language Compiler memory program library
...
features management optimization (libm/libc)

LiteOS Open APIs


LiteOS

Interconnection framework Security framework

Kernel

Page 29 Copyright © 2019 Huawei Technologies Co., Ltd. All rights reserved.
JS running Engine
⚫ High-Performance and Lightweight JS Virtual Machine (VM)
 Optimized design for devices with severely limited resources

 The JS framework, JS VM, and OS collaborate to optimize performance and reduce


power consumption.

 Provides independent user space and application isolation to ensure application security.

⚫ Advantages of the JS Framework


 Applications decoupled from the OS and upgraded without burning

 Simplified system integration across hardware platforms and middlewares

 Compatible with a large number of third-party libraries

 High-level language abstraction, hiding some programming details

Page 30 Copyright © 2019 Huawei Technologies Co., Ltd. All rights reserved.
Contents
1. Huawei LiteOS Kernel

2. Huawei LiteOS Framework

3. Huawei LiteOS APIs

Page 31 Copyright © 2019 Huawei Technologies Co., Ltd. All rights reserved.
Huawei LiteOS API
⚫ The open API shields bottom-layer differences so that application
developers only need to focus on application development at upper layers.

⚫ User-friendly compatibility enables developers who are familiar with


application development on the Linux system to smoothly switch to the
Huawei LiteOS for development. In addition, the simplified kernel of the
Huawei LiteOS is easier for developers to understand.

⚫ For example, based on APIs provided by the device-cloud interconnection


component, developers quickly implement secure and reliable connections
to Huawei IoT platform OceanConnect with only a few steps.

Page 32 Copyright © 2019 Huawei Technologies Co., Ltd. All rights reserved.
Quiz
1. Which of the following functions belong to Huawei LiteOS kernel? ( )
A. Task B. Process C. Time management D. Memory management

2. Describe functions of the Huawei LiteOS interconnection framework, sensing


framework, and security framework.

Page 33 Copyright © 2019 Huawei Technologies Co., Ltd. All rights reserved.
Summary
⚫ Huawei LiteOS Architecture

⚫ Huawei LiteOS Kernel and its principles and functions

⚫ Huawei LiteOS Framework and Its Functions

⚫ Huawei LiteOS APIs

Page 34 Copyright © 2019 Huawei Technologies Co., Ltd. All rights reserved.
Thank You
www.huawei.com

You might also like