XWOS Standard

Basic types, concepts, and habits of XWOS

Basic Types

All data types of XWOS that can determine the bit width are called basic data types , defined as follows:

  • xwu8_t : 8-bit unsigned integer
  • xws8_t : 8-bit signed integer
  • xwu16_t : 16-bit unsigned integer
  • xws16_t : 16-bit signed integer
  • xwu32_t : 32-bit unsigned integer
  • xws32_t : 32-bit signed integer
  • xwu64_t : 64-bit unsigned integer
  • xws64_t : 64-bit signed integer
  • xwsz_t : Unsigned size
  • xwssz_t : Signed size
  • xwstk_t : Unsigned stack frame should be consistent with the pointer bit width.
  • xwptr_t : Unsigned pointer integer value should be consistent with the pointer bit width.
  • xwreg_t : Unsigned register integer value should be consistent with the pointer bit width.
  • xwsreg_t : Signed register integer value should be consistent with the pointer bit width.
  • xwer_t : Signed error code should be consistent with the pointer bit width.
  • xwsq_t : Unsigned sequence value/position/offset value should be consistent with the pointer bit width.
  • xwssq_t : Signed sequence value/position/offset value should be consistent with the pointer bit width.
  • xwsid_t : Signed ID value should be consistent with the pointer bit width.
  • xwid_t : Unsigned ID value should be consistent with the pointer bit width.
  • typedef void (* xwisr_f)(void) : Interrupt function pointer
  • xwirq_t : Signed interrupt number. A negative interrupt number indicates a system exception, and a positive interrupt number indicates an external interrupt.
  • xwpr_t : Signed priority value
  • xwbmp_t : Unsigned bitmap
  • xwtm_t : time value (64-bit signed integer, unit: nanosecond)
  • xwlfq_t : lock-free queue
  • typedef void (* ctor_f)(void * /*obj*/) : constructor function pointer
  • typedef void (* dtor_f)(void * /*obj*/) : destructor function pointer
  • typedef xws64_t (* xwsc_f)(void * /*arg*/, ...) : system call function pointer

Data type naming conventions

When reading XWOS source code, users should pay attention to the implicit meanings of the following naming conventions:

  • For smaller data, XWOS will define it as a type through typedef . This type is the same as the basic data type . When passing parameters between functions, it is passed directly, and type_t * will not be used to pass pointers unless it is returning data.
    • The name is usually in the form of type_t , the function pointer is in the form of type_f , and the [object descriptor](../Xwobj##Object Dscriptor) is Then it is xwobj_d .
  • For large data structures, XWOS does not use typedef to omit the keyword struct , in order to remind the reader that this is a large structure. When passing it as a parameter, the data is referenced by passing a pointer。
  • In addition to object descriptors xwobj_d , XWOS uses typedef to define a data type based on whether the data type can define an atomic type.

Atom Type

All basic data types are prefixed with atomic_ indicating the atomic type of this type. For example: _Atomic xwsq_t is equivalent to __xwcc_atomic xwsq_t and is also equivalent to atomic_xwsq_t . Variables of atomic type can be operated using the atomic operation library , or using the functions defined in the standard C header file <stdatomic.h> .

System Bits

XWOS supports both 32-bit and 64-bit CPUs.

Time

XWOS uses a 64-bit signed integer xwtm_t to represent time in nanoseconds and provides a series of operation functions.

For details, refer to the header file xwos/osal/time.h .

Object

xwos_object It is the base class of all XWOS objects.

Object Descriptor

[Object Descriptor](../Xwobj##Object Descriptor) is a mechanism introduced by XWOS to solve the problem of wild object pointers.

Scheduler

Scheduler is used to manage CPU resources. In a multi-core system, XWOS will create an independent scheduler for each CPU.

Tick ​​Timer

The tick timer is an important component of the operating system kernel. It generates fixed-frequency interrupts for the scheduler, allowing the code scheduled by the operating system to run periodically. At the same time, the tick timer also provides a unit time interval reference for the timing function of the operating system.

Threads

The basic scheduling unit in the scheduler is the thread . The thread is bound to the scheduler.

Software Timer

Software timers implemented based on the tick timer are also bound to the scheduler.

Lock Mechanism

The locking mechanisms of XWOS are:

  • Mutex Lock : A lock that prevents two threads from competing for memory data and is not available for other contexts, such as interrupts.
  • Spin Lock : A lock that prevents any context from competing for memory data.
  • Sequence Lock : An improved version of the spin lock, which can be divided into read lock and write lock. The read lock can be shared, and the write lock is exclusive.

Synchronization Mechanism

The basic synchronization mechanism of XWOS :

Communication Mechanism

Based on the basic synchronization mechanism , XWOS middleware named XWMD provides a communication mechanism between threads: