Software Design of Embedded Systems Based on NucleusPLUS
2026-04-06 08:24:29··#1
Abstract : This paper introduces the working mechanism, software system design, and embedded real-time multitasking operating system (RTOS) Nucleus PLUS of the ion mobility spectrometer, focusing on its specific implementation in the ion mobility spectrometer. Keywords : Embedded system; Real-time operating system; Task; Migration time Introduction In today's society, drug smuggling is rampant, posing a threat to people's lives and property and social stability. At the same time, atmospheric monitoring and the surveillance of toxic gases are urgent. The developed ion mobility spectrometer is a dedicated detector utilizing IMS (ion mobility spectroscopy). Under specific temperature, pressure, and electric field conditions, it accurately measures the migration time of ions across a fixed distance under the influence of an electric field to identify whether a suspected substance contains certain chemical molecules. It can also issue alarm information for certain specific chemical substances, thus enabling the detection of drugs and toxic gases. The working principle of this system is as follows: Through detail matching, the specific components of the substance are identified by extracting the peak position (i.e., the migration time) of the plasma map of the ionized substance. The system's principle block diagram is shown in Figure 1. [align=center] Figure 1 System Principle Block Diagram[/align] The ion mobility spectrometer needs to read real-time data and perform analysis and processing, requiring the processing of 1000 ion signal data every 25ms, and has a certain real-time performance. At the same time, it also needs to read and control the temperature, gas pressure, voltage and other data in the ion tube. When the equipment is analyzing, it is required to quickly determine the composition of the substance (within 20 seconds), and this process involves a large amount of real-time data processing. It can be seen that the embedded system of the ion mobility spectrometer has high requirements for capacity and speed, not only for real-time data processing, but also for controlling multiple parameters. In order to ensure the reliability of the system and improve development efficiency, an embedded real-time operating system must be introduced into the ion mobility spectrometer. Embedded RTOS Selection There are many operating systems that can be used for embedded system software development, but the key is to choose a suitable embedded real-time operating system. In the design of the real-time system of the ion mobility spectrometer, our requirements for the embedded RTOS are as follows: (1) Real-time performance When using it, the speed of process calling and processing must be guaranteed, because the sample information detected needs to be analyzed and processed in a timely manner. (2) Stability As the software platform for system design, it needs to have considerable stability. This ensures that the ion mobility spectrometer detection system can correctly perform the predetermined actions even under varying external environments such as air pressure and temperature. (3) Small kernel size Due to the limited hardware resources of the entire system (we are equipped with 2M FLASH), the source code must be small enough to be written into memory and improve operating efficiency. Considering all factors, we chose the embedded real-time operating system Nucleus PLUS. Nucleus PLUS is a preemptive multitasking operating system kernel designed for real-time embedded applications by ATI (Accelerated Technology Inc.), a well-known RTOS manufacturer in the United States. 95% of its code is written in ANSI C, which is very easy to port and supports most types of processors. Nucleus PLUS is a set of C function libraries. The application code is linked with the kernel function to generate a target code, which is downloaded to the RAM of the target board or directly burned into the ROM of the target board for execution. In a typical target environment, the Nucleus PLUS kernel code area is generally no more than 20K bytes in size, and the kernel size is very small. Features of Nucleus PLUS The system architecture of the Nucleus PLUS kernel is shown in Figure 2. The main purpose of the Nucleus PLUS kernel is to manage the competitive execution of real-time tasks, provide various conveniences for applications, quickly respond to external events, and achieve real-time performance. Nucleus PLUS provides the following support for system development: multi-task management, tasks can share CPU resources according to priority and time slice, communicate through mailboxes, queues, and pipes, and synchronization and mutual exclusion between tasks are achieved through semaphores, event groups, and signals; Nucleus PLUS provides both dynamic and partitioned memory management mechanisms, and also provides timers to handle periodic events and task sleep and suspension timeouts. Nucleus PLUS calls these mechanisms software components, and provides a series of system calls for each software component. The interaction between tasks and Nucleus PLUS takes place through the interface of system calls. As shown in Figure 2, using the Nucleus PLUS development platform, users only need to write task code and interrupt service routine code. System calls are used in these code to interact with Nucleus PLUS, which then schedules multiple tasks to execute in parallel, achieving CPU sharing. Since Nucleus PLUS shares CPU resources based on priority and time-slice, the real-time performance of the system can be guaranteed as long as the priorities of the tasks and interrupt service routines are set properly. [align=center] Figure 2 Nucleus PLUS System Structure[/align] Multitasking Management In the Nucleus PLUS real-time operating system, a task is equivalent to a process in a time-sharing operating system. In the Nucleus PLUS operating system, tasks can be divided into five basic states: running, ready, suspended, terminated, and completed, as detailed in Table 1. [align=center]Table 1 Five Task States[/align] Only one task can be in the running state at any given time. A task in the suspended state can be transitioned to the ready state by certain system calls or events. A task in the running state also becomes ready after being preempted by a higher-priority task. In the ready state, the task has acquired all the resources required for execution, except for CPU control. Task Scheduling Nucleus PLUS has two scheduling methods: priority scheduling and time-slice scheduling, as shown in Figure 3. When a higher-priority task becomes ready, Nucleus PLUS interrupts the lower-priority task, saves its context, and runs the higher-priority task first. [align=center]Figure 3 Task Scheduling Diagram[/align] This is preemption. Priority scheduling ensures that higher-priority tasks run first. Tasks of the same priority can also take turns using CPU resources using time slices. The user only needs to specify the time slice size for each task. Nucleus PLUS calculates the task's running time through clock interrupts. When the task's time slice is exhausted, Nucleus PLUS automatically switches tasks. NucleusP LUS implements task scheduling using a data structure similar to a doubly linked list array, TCD_Priority_List. System Software Design **BSP Establishment:** Based on the RTOS programming model, the software design proceeds in two steps. First, the BSP is established. This involves configuring the system according to the target environment and establishing the board-level support program (BSP, equivalent to the BIOS of a standard PC). It mainly completes system initialization and hardware-related device drivers, guiding the target machine hardware to a defined state. This is implemented using functions such as Board_Init(), INTInitia_lize(), UARTInit(), and LCDInit(). **Software Function Description and Multi-Task Function Division:** Based on the working principle of the ion mobility spectrometer, the software must implement modules such as real-time data acquisition (ion signals and analog quantities of each channel), real-time control (constant temperature control on the ion tube, maintaining constant flow in the gas path, and real-time tracking and control of the high-voltage power supply, overall current, overall temperature, and test paper status), keyboard response, menu graphical display, and communication interface with the PC. The functions of the first two modules are closely related to time, and are detailed below: a1 Completes serial A/D sampling every 10ms, simultaneously sampling data from 16 internal channels. High real-time requirements. b1 Uses a CPLD to open a gate signal every 25ms, acquiring 1000 ion signal data. Very high real-time requirements. c1 Completes calculations of various temperature control laws every 10ms, maintaining each temperature at the set point. d1 After the user presses the analysis button, it analyzes the predetermined temperature to be reached within a few seconds, and the entire analysis must be completed within 20 seconds. e1 Promptly responds to user commands via the keyboard and displays the corresponding information on the LCD screen. g1 Immediately alarms upon detecting prohibited components. g1 Communicates with a PC, allowing modification of the sample library and operating parameters stored in the serial flash memory, or transmission of the stored sample library and alarm results to the PC. Based on the DARTS design methodology, we have divided these functional requirements into the following ten tasks: MainTask: The main task, responsible for receiving messages from the main queue, communicating with other tasks based on message type, and activating different tasks. UITask: Graphical interface display task. MCTask: Multi-channel data acquisition task. RCTask: Real-time temperature control task. MVTask: Data transfer task. ANTask: Analysis and processing task. ALTask: Alarm handling task. AVTask: Plasma image processing task. KBTask: Keyboard scanning task. SCTask: Communication with PC task. Using NucleusPLUS as the development platform, we first use Application_Initialize(void *first_available_memory) as the entry point. All the above tasks are defined here. Multi-channel data acquisition, real-time control, and analysis tasks are implemented using timers, while keyboard scanning is implemented using interrupts. The plasma image processing and peak position extraction algorithms directly affect the extraction of migration time, which is one of the difficulties in software implementation. Plasma images generated from ion signals sampled within a single cycle often contain interference and numerous spikes, making it impossible to accurately identify peaks and thus obtain migration times. To address this, we take 1000 sampling points per cycle. First, we employ an algorithmic averaging filter to calculate the arithmetic mean of the sampled signals from multiple cycles: y[i] = (y1[i] + y2[i] + ... + yn[i]) / n, removing random interference signals. Then, we use a transverse averaging filter: y[i] = (y[i+1] + y[i+2] + ... + y[i+m]) / m to reduce spikes in the plasma image. Finally, we average the multiple y[i] values obtained using the above methods. After multiple processing steps of the sampled values, a relatively clear plasma image can be obtained. The key to correctly extracting peak positions is to identify the peaks themselves. Peak extraction is not simply a matter of finding the optimal value. When a substance contains multiple components, multiple peaks will appear. Based on the fundamental properties of substances, they generally contain no more than 20 components, so a maximum of 20 peaks need to be identified. Furthermore, the processed plasma image is not without glitches; two peaks separated by tens of microseconds often have only one true peak. To solve this problem, we first identify the first peak and use a trial-and-error method to measure its approximate width. Then, we identify a hypothetical second peak. If the distance between the two peaks is less than the width of the first peak, the second peak is considered merely a glitch in the first peak, and the second peak is discarded. Otherwise, the second peak is retained, and we continue searching for a third peak, using the width of the peak adjacent to the third peak as the comparison. This process continues until all peaks have been identified. The program for measuring the peak width using the trial-and-error method is as follows: ... if (PeakPosition[maxm-1]>PeakPosition) {low=PeakPosition;high=PeakPosition[maxm-1];} else {low=PeakPosition[maxm-1];high=PeakPosition;} for (m=low;m<=hight;m++) if (SignalStrength[m]>=Pvalue) Pinstant=SignalStrength[m]; if (Pinstant==Pvalue) { maxm-=1; Pwidth+=10;∥Increase the peak width width=Pwidth;} ... Once the peak and its position are found, the migration time is easily obtained. Conclusion The multi-tasking mechanism of the real-time operating system kernel not only meets the real-time requirements of application systems but also simplifies the system development and design process. It decomposes a complex problem into multiple sub-problems, which are then implemented using tasks. This, to a certain extent, ensures the real-time performance and reliability of ion mobility spectrometers. However, task partitioning is an art in real-time multi-tasking system design. Different people will partition the tasks for the same system differently, leading to variations in system performance. Determining the optimal task partitioning method requires continuous refinement during the actual development of real-time systems. This paper mainly introduces the design of an embedded ion mobility spectrometer system based on Nucleus PLUS, which will soon be useful in the detection of drugs, explosives, and other substances.