12 Star 102 Fork 104

OpenHarmony / utils_native_lite

Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
Clone or Download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

Utils

Overview

The Utils repository stores basic components of OpenHarmony. These basic components are used by OpenHarmony subsystems and upper-layer applications.

The Utils library provides the following capabilities on different platforms:

  • LiteOS Cortex-M (Hi3861 platform): key value (KV) store, file operations, timer, and system attribute dumping
  • LiteOS Cortex-A (Hi3516 or Hi3518 platform): KV store, timer, JavaScript APIs for device query and data storage, and system attribute dumping

Table 1 Utils capabilities

Module

Platform

Description

KV store

LiteOS Cortex-M and LiteOS Cortex-A

Provides KV storage for applications.

File operation

LiteOS Cortex-M

Provides unified file operation interfaces that can be used on different underlying chip components.

Timer

LiteOS Cortex-M and LiteOS Cortex-A

Provides unified timer operation interfaces that can be used on different underlying chip components.

JavaScript API

LiteOS Cortex-A

Provides JavaScript APIs for obtaining device information and storing data.

System attribute dumping

LiteOS Cortex-M and LiteOS Cortex-A

Provides the command line tool for dumping system attributes.

Directory Structure

utils/native/lite/              # Root directory
├── file                        # Implementation of the file system APIs
├── hals                        # HAL directory
│   └── file                    # Header files of the hardware abstraction layer for file operations
├── include                     # Header files of external APIs
├── js                          # JavaScript APIs
│   └── builtin
│       ├── common
│       ├── deviceinfokit       # Device information kit
│       ├── filekit             # File kit
│       └── kvstorekit          # KV store kit
├── kal                         # KAL directory
│   └── timer                   # KAL implementation of the timer
├── kv_store	                # KV store implementation
│   ├── innerkits               # Internal KV store APIs
│   └── src	                    # KV store source file
├── memory
│   └── include                 # Memory pool management APIs
├── os_dump                     # System attribute dumping
└── timer_task                  # Timer implementation

Usage

  • KV store

    // Store or update the value of a key.
    const char key1[] = "key_sample";
    const char defValue[] = "test case of key value store.";
    int ret = UtilsSetValue(key1, defValue);
    
    // Obtain the value of the key.
    char value1[32] = {0};
    ret = UtilsGetValue(key1, value1, 32);
    
    // Delete the value of the key.
    UtilsDeleteValue(key1);
  • File operation

    // Open or create a file.
    const char fileName[] = "testfile";
    int fd = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS | O_TRUNC_FS, 0);
    
    // Write a specified length of data into a file with the specified file descriptor.
    const char defValue[] = "test case of file system.";
    int ret = UtilsFileWrite(fd, defValue, strlen(defValue));
    
    // Close a file with a specified file descriptor.
    UtilsFileClose(fd);
    
    // Obtain the file size.
    int fileLen = 0;
    ret = UtilsFileStat(fileName, &fileLen);
    printf("file size = %d\n", fileLen);
    
    // Adjust the read and write position offset in a file.
    int fd1 = UtilsFileOpen(fileName, O_RDWR_FS, 0);
    ret = UtilsFileSeek(fd1, 5, SEEK_SET_FS);
    
    // Read a specified length of data from a file with the specified file descriptor and write the data into the buffer.
    char buf[32] = {0};
    int readLen = UtilsFileRead(fd1, buf, 32);
    ret = UtilsFileClose(fd1);
    printf("read len = %d : buf = %s\n", readLen, buf);
    
    // Delete a specified file.
    ret = UtilsFileDelete(fileName);
  • System attribute dumping

    LiteOS Cortex-M kernel: Run the following command over the serial port to dump the current system parameters:

    AT+SYSPARA

    LiteOS Cortex-A kernel: Run the os_dump command in the bin directory to dump the current system parameters:

    ./bin/os_dump syspara

Repositories Involved

Utils

utils_native_lite

About

Utils library | 公共基础库 expand collapse
C and 3 more languages
Apache-2.0
Cancel

Releases (1)

All

OpenHarmony

Contributors

All

Activities

Load More
can not load any more
1
https://git.oschina.net/openharmony/utils_native_lite.git
git@git.oschina.net:openharmony/utils_native_lite.git
openharmony
utils_native_lite
utils_native_lite
master

Search