Business technology background with digital elements and modern interface
Modular Electronics,Citizen Electronics,Electronic Theory Blog - ramplights.com

How to design a small embedded operating system

**Foreword** The main goal of this paper is to design a basic embedded operating system that focuses on implementing a simple task scheduler. While it may not qualify as a full-fledged operating system, it embodies the core concepts of a small embedded OS and serves as an introduction to how real-time systems operate. **First, the Multi-Task Mechanism** In a single CPU environment, true multitasking isn’t possible. Instead, different tasks take turns using the CPU, which gives the illusion of parallel execution due to the fast switching between tasks. This is known as the multitasking mechanism. Real-time systems are characterized by predictable response times, typically within milliseconds, allowing them to react quickly to external events. **Second, Task States** A task can be in one of several states: ready, running, or suspended. - **Running State**: Only one task is running at a time, using the CPU. - **Ready State**: A task is waiting for its turn to use the CPU. - **Suspended State**: A task is waiting for specific conditions to be met before it can run again. ![Task States](http://i.bosscdn.com/blog/o4/YB/AF/qgonSARkk-AACI7qloXwg576.jpg) **Third, Transitioning to the Ready State** To manage task readiness, we use a 32-bit variable called `OSRdyTbl`. Each bit represents a task’s status—1 means ready, 0 means not ready. Two macros help manage these transitions: - `OSSetPrioRdy(prio)` sets the corresponding bit to 1. - `OSDelPrioRdy(prio)` clears the bit to 0. Tasks are independent and do not directly communicate with each other. To exchange information, mechanisms like semaphores, message queues, and mailboxes are used. **Fourth, What is Preemptive Scheduling?** Preemptive scheduling involves the system selecting the highest-priority ready task to run. If a higher-priority task becomes ready, it immediately takes over the CPU from the current task. This ensures the most critical tasks are always executed first. **Fifth, Time Management in Multitasking Systems** Multitasking systems require a "heartbeat" to manage timing. This is usually provided by a timer interrupt, generating regular clock ticks. The `OSTimeDly` function uses these ticks to delay a task. When the delay expires, the task is moved back to the ready state. ![Time Management](http://i.bosscdn.com/blog/o4/YB/AF/qgosWATDbuAABrUqlU-vw588.jpg) **How to Achieve Multitasking?** Each task must have its own program code, stack, and data storage. Even though they share the same CPU, they operate independently. For example, each task has a private stack where local variables are stored, ensuring no interference between tasks. **Tips: Reentrancy and Mutual Exclusion** If multiple tasks access shared resources, data corruption may occur. To prevent this, functions should be reentrant (using local variables) or mutual exclusion mechanisms like semaphores should be used. **6.1 How Does a Task Have Its Own Program Code?** Each task is essentially a function that runs in a loop. The program code is separate, and tasks communicate through defined interfaces rather than direct interaction. **6.2 How a Task Has Its Own Stack and Data Storage** Each task needs a private stack to store local variables and function parameters. This stack is managed by the Task Control Block (TCB), which keeps track of the stack pointer and other relevant data. **What Is a Task Control Block?** The TCB holds all the necessary information about a task, including its stack pointer and delay count. It acts as a container for the task's context, enabling efficient task switching. ![Task Control Block](http://i.bosscdn.com/blog/o4/YB/AF/qgowCAYYiEAABVxhm_M_c236.png) **6.3 How Does a Task Have Its Own CPU?** Although only one CPU exists, tasks share it through context switching. When a task is interrupted, its state is saved, and the next task is loaded. This process mimics having a dedicated CPU for each task. **6.4 How to Implement Preemptive Scheduling?** Preemptive scheduling ensures the highest-priority ready task gets the CPU. This can happen either when a task voluntarily yields control (e.g., via `OSTimeDly`) or when a higher-priority task becomes available after an interrupt. **6.5 Suspend/Resume Task** - **Suspend Task**: Use `OSTaskSuspend()` to remove a task from the ready list and trigger a context switch. - **Resume Task**: Use `OSTaskResume()` to bring a suspended task back to the ready state, allowing it to run again. By understanding these fundamental components, we gain insight into how embedded systems manage tasks efficiently and reliably.

Ultrasonic Sensor

Yuhai Company is engaged to research and development of piezoelectric products and related piezoelectric products, the related piezoelectric products includes the piezo sensors and transducer.


The ultrasonic transducer is a kind of transducer that converts the ultrasonic signal into electric signal, or vice versa. Ultrasound transmitter and receiver is a transducer that can transmit and receive ultrasound. Ultrasound sensor is a kind of sensor, in essence, it is also a transmitter and receiver. The working principle of this kind of equipment is similar to that of radar and sonar. Active ultrasonic sensors can emit and receive reflected waves, and determine the distance of the target by measuring the time interval between transmission and reception. Passive ultrasonic sensor is actually a microphone that can convert ultrasonic signal into electrical signal.

According to the working principle and materials used, the ultrasonic transducer has piezoelectric transducer, electrostatic transducer (capacitive transducer), magnetostrictive transducer, electromagnetic acoustic transducer, mechanical transducer and other types [1].

Ultrasonic Sensor,Piezo Sensor,Ultrasonic Piezo Disc,Ultrasonic Piezo Elements

Zibo Yuhai Electronic Ceramic Co., Ltd. , https://www.yhpiezo.com