[TOC] ## What is OSAL? Today, a classmate suddenly asked me if I had ever worked on OSAL. I was confused, so I found the answer on the search engine and found that it is a very practical thing. OSAL (operating system abstraction layer) is a system resource management mechanism with multi-tasking as the core. It implements some functions similar to RTOS, but it cannot be called a true RTOS because it does not support task suspension, task preemption and other functions. However, this mechanism implements very concise code and occupies very few resources. For embedded platforms with very tight resources, it can complete relatively complex logical functions and is a very powerful framework. **The concept of OSAL** was introduced by `TI` in the `ZIGBEE` protocol stack - `Z-STACK`. You can search `z-stack` on the official website to download the relevant source code, which includes the source code for the implementation of the `OSAL` mechanism; ## Source code installation [Z-Stack.3.0.2.exe](https://en.eeworld.com/bbs/forum.php?mod=attachment&aid=NDQ0MDk1fDI5ZDYxN2E5MWM1NjQxODJkYmI0NDlmOTIxMGYzN2ZhfDE3MzE2MjY5OTY%3D&request=yes&_f=.exe) Currently the latest version on the official website, download and install it locally; ![]()
After the installation is complete, you can go to the installation directory and find the corresponding source code. However, this is basically the `zigbee` protocol stack, so the `OSAL` related part is in the path shown in the figure below;
## OSAL transplantation You can try to transplant the `OSAL` framework to the microcontroller for testing. Here is a repository [OSAL](https://github.com/hotsauce1861/osal.git) on `GitHub` , and the specific transplantation method can be tested on the `Linux` platform, ``` c void osal_main(void) { //Initialize system hardware, peripherals, etc. //Disable interrupts HAL_DISABLE_INTERRUPTS(); //OSAL operating system initialization osal_init_system(); //Add tasks osal_add_Task(print_task_init, print_task_event_process, 1); osal_add_Task(statistics_task_init, statistics_task_event_process, 2); //Initialize the added tasks osal_Task_init(); osal_mem_kick(); //Enable interrupts HAL_ENABLE_INTERRUPTS(); //Set the initial task event. The task event that needs to be automatically polled when powered on can be added here. //Start the osal system and will not return to osal_start_system(); } ``` Later I plan to port it to `STM32`, which should be good. I have seen many schedulers before, but I don't think they are as powerful as `OSAL`.