OS Kernel Layer

Last Updated on : 2022-11-24 09:20:05download

The generic system service components based on the characteristics of the IoT operating system are encapsulated in the APIs of the OS kernel layer.


The APIs shield the differences in hardware and systems, which makes software compatible with different systems and chip platforms. Common system services are also available, including secure data storage, secure boot, secure memory management, messages, timers, job queues, and events.

Your required OS features and software can be implemented simply by making API calls in the OS kernel and application layers respectively, which can notably boost your development efficiency.

Data storage

The differences in chips, operating systems, resources, and performances across various IoT platforms can be huge. But there are common requirements of IoT hardware for storage.

  • High security with respect to privacy protection.
  • High reliability to cope with unpredictable and uncontrollable situations.
  • Excellent performance to ensure smooth user experience.

TuyaOS provides an encrypted key-value database for the file system and flash memory. Shielding the differences in the hardware and operating systems, TuyaOS enables a safe, reliable, and efficient data storage service.

Memory management

For more information about the function description of ADC peripherals, see Memory Management.

Message processing

The message queue provides the common capability of message processing. Create a message, register the message callback, and send the message ID to implement asynchronous messaging as well as serial processing.

In TuyaOS, all messages are processed in the cmmod task. You should minimize complex logic processing in the message callback to ensure messaging efficiency. Otherwise, stack overflow might occur.


The millisecond timer is supported. You can create, start, tailor, and delete a timer. Two types of timers are available.

  • TIMER_ONCE: A non-repeating timer executes once and then invalidates itself automatically. Then, you can delete it.
  • TIMER_CYCLE: A repeating timer executes and then reschedules itself on the same run loop until you stop or delete it.

When a timer works with the message queue, the scheduled message processing can be implemented. Create a message and register the callback for scheduled messages to trigger scheduled messaging and perform serial processing.

Job queue

The common asynchronous task scheduler can send a task to a specified job queue. Tasks will be processed serially. You can create a job queue as needed and schedule tasks.

Event management

TuyaOS provides a lightweight event notification library, with the following features.

  • Flexible publish/subscribe messaging allows publishers to publish data to any topic from anywhere at any time.
  • Lightweight event notification inside the process, with about 400 lines of code.
  • The library can run on any platform thanks to the cross-platform feature of the TuyaOS.
  • Typically, events are called synchronously. The cross-platform feature enables you to use the work queue or timer queue in the subscription function to implement a multithreading asynchronous mechanism.