Updated on 2025-12-04 GMT+08:00

OS Selection and Adaptation

The IoT Device SDK Tiny adapts to multiple OSs, such as LiteOS, Nova OS, Linux, μC/OS-II, macOS, and FreeRTOS. You can also adapt to your own OS as required.

OS Adaptation

The IoT Device SDK Tiny is compatible with various IoT OSs, including LiteOS, FreeRTOS, macOS, Linux, Nova OS, and μC/OS-II. It depends on the underlying OS for functionality, requiring OS adaptation. You can integrate the module or microcontroller unit (MCU) vendor's built-in OS to enable IoT Device SDK Tiny to connect to Huawei Cloud and other cloud services.

The IoT Device SDK Tiny provides the Operating System Abstraction Layer (OSAL) to decouple the SDK components from the specific OS. This allows vendors to register their OSs with the OSAL to use SDK components, involving mapping core kernel-related functions, such as task operations, semaphores, mutexes, and memory management APIs. Further information can be found in the adapted OS implementation file. The SDK queue utilizes mutexes and semaphores for implementation, eliminating the need for additional adaptation. The final calling sequence is as follows: osal_init() > os_imp_init() > osal_install(). os_imp_init is a weak symbol function. You need to implement it as required and call osal_install() to register system services.

TCP/IP Adaptation

For the IoT Device SDK Tiny, the network protocol stack is determined by the underlying OS. When a third-party OS is used, network transmission APIs can be abstracted. Only protocol stack APIs need to be provided. All network transmission APIs invoked in the IoT Device SDK Tiny will finally invoke the functions registered by users.

The IoT Device SDK Tiny also provides an abstraction layer (SAL). You can call the link_sal_install function to register their TCP/IP capabilities. In addition, you must implement the link_tcpip_imp_init function, which is a weak symbol. During the SDK initialization, the calling sequence is as follows: link_tcp_ip_init > link_tcpip_imp_init > link_sal_install. TCP/IP capabilities can only be used after this initialization is complete. For details, see the sal_imp.h header file. The SDK already includes pre-built adaptations for TCP/IP capabilities provided by software or modules like lwIP, ESP8266, and L716. If you have a third-party component or module, you can use these existing implementations as a reference.

Adaptation Details

  • Various OSs have distinct task priority requirements, necessitating corresponding adjustments to the task creation functions within the IoT Device SDK Tiny. The default priority sequence in this SDK ranges from 0 to 31, with 0 representing the highest priority and 31 the lowest.
  • Some compilation architectures may vary in their support for virtual reference functions and the compilation method. Adjustments to the implementation are necessary.
  • If the preceding components are available in the SDK, you can adapt and tailor them as required.
  • The source files and library files can be retained and adapted based on the compilation architecture. The following provides an example of the iot_config.h file. In the example, the interface of version V5 is used. You can focus on the SDK entry function link_main.c, which contains how to use macro definitions to control the files to be compiled.
    //enable cJSON
    #define CONFIG_CJSON_ENABLE 1
    
    //enable LinkLog 
    #define CONFIG_LINKLOG_ENABLE 1
    
    //enable queue
    #define CONFIG_LINKQUEUE_ENABLE 1
    
    //enable DTLS_AL link_main
    #define CONFIG_DTLS_AL_ENABLE 1
    #define CONFIG_MBEDTLS_ENABLE 1
    #define CONFIG_MBEDTLS_PSK 1
    
    
    // enable MQTT link_main
    #define CONFIG_PAHO_MQTT 1
    #define CONFIG_MQTT_AL_ENABLE 1
    
    // enable tcpip
    #define CONFIG_TCPIP_AL_ENABLE 1
    
    //choose paho_mqtt or lite_mqtt
    //#define CONFIG_PAHO_MQTT 1  
    
    
    //paho_mqtt_port.c use them
    #define CONFIG_PAHO_CONNECT_TIMEOUT 10000
    #define CONFIG_PAHO_CMD_TIMEOUT 10000
    #define CONFIG_PAHO_LOOPTIMEOUT 10
    #define CONFIG_PAHO_SNDBUF_SIZE 2048
    #define CONFIG_PAHO_RCVBUF_SIZE 2048
    
    //enable OC_MQTT link_main 
    #define CONFIG_OCMQTT_ENABLE 1
    
    //mqtt the profile function tools and implement component oc_mqtt.mk
    #define CONFIG_OC_TINYMQTTV5_ENABLE 1 
    #define CONFIG_OC_MQTTV5_PROFILE 1
    
    #define CONFIG_IOT_LINK_CONFIGFILE "iot_config.h"