804 Star 2.4K Fork 1.2K

GVPHuawei LiteOS / LiteOS

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
development-guide.md 59.07 KB
一键复制 编辑 原始数据 按行查看 历史

Development Guide

Usage Scenarios

Queues are used for communication between tasks to implement asynchronous message processing. In addition, the message sender and recipient do not need to communicate with each other because they are decoupled.

Functions

The queue module of Huawei LiteOS provides the following functions. For details about the APIs, see the API reference.

Function Category

API

Description

Creating or deleting a message queue

LOS_QueueCreate

Creates a message queue whose the queue space is dynamically allocated by the system.

LOS_QueueCreateStatic

Creates a message queue whose queue space is allocated by the user and transferred to the API.

LOS_QueueDelete

Deletes a specified queue based on the queue ID.

Read/Write queue (without the content contained in the address)

LOS_QueueRead

Reads the specified head node data in the queue. The node data in a queue is an address.

LOS_QueueWrite

Writes the value of the input parameter bufferAddr (that is, the buffer address) to the tail node of a specified queue.

LOS_QueueWriteHead

Write the value of the input parameter bufferAddr (that is, the buffer address) to the head node of a specified queue.

Read/Write queue (with the content contained in the address)

LOS_QueueReadCopy

Reads data from the head node of a specified queue.

LOS_QueueWriteCopy

Writes the data saved in the input parameter bufferAddr to the tail node of a specified queue.

LOS_QueueWriteHeadCopy

Writes the data saved in the input parameter bufferAddr to the head node of a specified queue.

Obtaining queue information

LOS_QueueInfoGet

Obtains information about a specified queue, including the queue ID, queue length, message node size, head node, tail node, number of readable nodes, number of writable nodes, tasks waiting for read operations, tasks waiting for write operations, and tasks waiting for mail operations.

Queue Error Codes

Error codes are returned for operations that may fail to be performed to quickly locate error causes.

No.

Definition

Error Code

Description

Reference Solution

1

LOS_ERRNO_QUEUE_MAXNUM_ZERO

0x02000600

The maximum number of queues supported by the system is 0.

The maximum number of queues supported by the system must be greater than 0. If the queue module is not used, set LOSCFG_BASE_IPC_QUEUE to NO.

2

LOS_ERRNO_QUEUE_NO_MEMORY

0x02000601

Failed to apply for memory from the dynamic memory pool during queue initialization.

Set the configuration item OS_SYS_MEM_SIZE to a larger system dynamic memory pool, or reduce the maximum number of queues supported by the system.

3

LOS_ERRNO_QUEUE_CREATE_NO_MEMORY

0x02000602

Failed to apply for memory from the dynamic memory pool during queue creation.

Set OS_SYS_MEM_SIZE to a larger system dynamic memory pool, or reduce the length and message node size of the queue to be created.

4

LOS_ERRNO_QUEUE_SIZE_TOO_BIG

0x02000603

The message node size exceeds the upper limit during queue creation.

Change the input parameter for message node size to ensure that the size does not exceed the upper limit.

5

LOS_ERRNO_QUEUE_CB_UNAVAILABLE

0x02000604

No idle queue exists in the system during queue creation.

Increase the maximum number of queues supported by the system.

6

LOS_ERRNO_QUEUE_NOT_FOUND

0x02000605

The queue ID transferred to the API for deleting a queue is greater than or equal to the maximum number of queues supported by the system.

Ensure that the queue ID is valid.

7

LOS_ERRNO_QUEUE_PEND_IN_LOCK

0x02000606

When a task is locked, the queue used by the task cannot block the wait for message writing or reading.

Unlock the locked task before using a queue.

8

LOS_ERRNO_QUEUE_TIMEOUT

0x02000607

Waiting for processing the queue timed out.

Check that the configured timeout interval is proper.

9

LOS_ERRNO_QUEUE_IN_TSKUSE

0x02000608

The queue is involved in a blocked task and cannot be deleted.

Enables tasks to obtain resources instead of being blocked in the queue.

10

LOS_ERRNO_QUEUE_WRITE_IN_INTERRUPT

0x02000609

The queue cannot be written in block mode in the interrupt handler.

Set the write queue to non-block mode, that is, set the timeout interval of the write queue to 0.

11

LOS_ERRNO_QUEUE_NOT_CREATE

0x0200060a

The queue has not been created.

Create the queue or replace it with an existing queue.

12

LOS_ERRNO_QUEUE_IN_TSKWRITE

0x0200060b

The read and write operations in the queue are not synchronized.

Synchronize the read and write operations in the queue. Specifically, multiple tasks are not allowed to concurrently read data from or write data into the same queue.

13

LOS_ERRNO_QUEUE_CREAT_PTR_NULL

0x0200060c

For the API for creating a queue, the input parameter for saving the queue ID is a null pointer.

Ensure that the input parameter is not a null pointer.

14

LOS_ERRNO_QUEUE_PARA_ISZERO

0x0200060d

For the API for creating a queue, the queue length or message node size is 0.

Input correct queue length and message node size.

15

LOS_ERRNO_QUEUE_INVALID

0x0200060e

The queue ID transferred to the API for reading data from a queue, writing data to queue, or obtaining the queue information is greater than or equal to the maximum number of queues supported by the system.

Ensure that the queue ID is valid.

16

LOS_ERRNO_QUEUE_READ_PTR_NULL

0x0200060f

The pointer transferred to the read queue API is null.

Ensure that the input parameter is not a null pointer.

17

LOS_ERRNO_QUEUE_READSIZE_IS_INVALID

0x02000610

The size of the buffer transferred to the read queue API is 0 or greater than 0xFFFB.

The input buffer size must be greater than 0 and less than 0xFFFC.

18

LOS_ERRNO_QUEUE_WRITE_PTR_NULL

0x02000612

The buffer pointer transferred to the write queue API is null.

Ensure that the input parameter is not a null pointer.

19

LOS_ERRNO_QUEUE_WRITESIZE_ISZERO

0x02000613

The size of the buffer transferred to the write queue API is 0.

Input a correct buffer size.

20

LOS_ERRNO_QUEUE_WRITE_SIZE_TOO_BIG

0x02000615

The size of the buffer transferred to the write queue API is greater than the message node size of the queue.

Reduce the buffer size or increase the message node size of the queue.

21

LOS_ERRNO_QUEUE_ISFULL

0x02000616

No idle node is available when data is written to the queue.

Before writing data to a queue, ensure that there is an available idle node in the queue or use the block mode to write data to the queue. That is, set the timeout interval of the write queue to a value greater than 0.

22

LOS_ERRNO_QUEUE_PTR_NULL

0x02000617

The pointer transferred to the API for obtaining queue information is null.

Ensure that the input parameter is not a null pointer.

23

LOS_ERRNO_QUEUE_READ_IN_INTERRUPT

0x02000618

The queue cannot be read in block mode in an interrupt handler.

Set the read queue to non-block mode, that is, set the timeout interval of the read queue to 0.

24

LOS_ERRNO_QUEUE_MAIL_HANDLE_INVALID

0x02000619

When the memory block of the mail queue in CMSIS-RTOS 1.0 is released, the input mail queue ID is invalid.

Ensure that the input mail queue ID is correct.

25

LOS_ERRNO_QUEUE_MAIL_PTR_INVALID

0x0200061a

When the memory block of the mail queue in CMSIS-RTOS 1.0 is released, the pointer of the input mail memory pool is null.

Input non-null mail memory pool pointer.

26

LOS_ERRNO_QUEUE_MAIL_FREE_ERROR

0x0200061b

The memory block of the mail queue in CMSIS-RTOS 1.0 failed to be released.

Input non-null memory block pointer of the mail queue.

27

LOS_ERRNO_QUEUE_ISEMPTY

0x0200061d

The queue is empty.

Before reading a queue, ensure that there are unread messages in the queue or use the block mode to read the queue, that is, set the read queue timeout interval to a value greater than 0.

28

LOS_ERRNO_QUEUE_READ_SIZE_TOO_SMALL

0x0200061f

The size of the read buffer transferred to the read queue API is less than the message node size of the queue.

Increase the buffer size or reduce the message node size of the queue.

NOTICE:

  • For details about the error code definition, see Error Codes. Bits 8–15 belong to the queue module, and the value is 0x06.
  • The error codes 0x11 and 0x14 in the queue module are not defined and cannot be used.

Development Process

The typical process of using the queue module is as follows:

  1. Run the make menuconfig command and choose Kernel > Enable Queue to configure the queue module.

    Configuration Item

    Description

    Value Range

    Default Value

    Dependency

    LOSCFG_BASE_IPC_QUEUE

    Whether to tailor the queue module.

    YES/NO

    YES

    None

    LOSCFG_QUEUE_STATIC_ALLOCATION

    Whether to create a queue whose memory is allocated by users.

    YES/NO

    NO

    LOSCFG_BASE_IPC_QUEUE

    LOSCFG_BASE_IPC_QUEUE_LIMIT

    Maximum number of queues supported by the system.

    <65535

    1024

    LOSCFG_BASE_IPC_QUEUE

  2. Create a queue. After the queue is created, you can obtain the queue ID.

  3. Write data to the queue.

  4. Read the queue.

  5. Obtain the queue information.

  6. Delete the queue.

Platform Differences

None

C
1
https://gitee.com/LiteOS/LiteOS.git
git@gitee.com:LiteOS/LiteOS.git
LiteOS
LiteOS
LiteOS
master

搜索帮助