How do I create my own RTOS?

Thread Starter

Yash2019

Joined Jan 5, 2022
7
Hello everyone

I am yash here I always visit on this forum but posting question first time.
I am planning to write my own RTOS in c language for 32 bit processor cortex M0. I know there are already freeRTOS and other are available. i just want to learn how to design and code it. I don't think there is any harm in learning it. I know RTOS is not necessary for every real time system but it has an advantage.

I already watched youtube videos, read tutorials, visited many websites but I don't have any idea how to start.

I know here are so many experienced software developer's and I hope someone will help
 

MrSalts

Joined Apr 2, 2020
1,557
Your question is too broad. What answer do you expect from such a broad question? You'll get a broad answer or you'll get thousands of pages of detailed answers (similar to what a textbook about real-time operating systems will give you - or technical specifications from the processor's manufacturer about interrupts and memory allocation in real time OS applications.
If you don't even know where to start, start with a text book or even Wikipedia. Your questions is like, "help me write a novel". I don't know what topic you want or what help you need (grammar, dialog, publishing, character development, ...)

https://en.m.wikipedia.org/wiki/Real-time_operating_system

Also, doing this "for fun" is a big bite for someone inexperienced. Do you have a team to help you?
 

djsfantasi

Joined Apr 11, 2010
8,256
I’m an experienced developer but I wouldn’t consider attempting this. It is a complex task and I wouldn’t have the time.

I think I’d be facing a long research time. Maybe months. Then, almost before I started coding, I’d decide how I’m going to test myRTOS.

I think it would take me months of development, testing and correcting.

I know I don’t have the same motivation as you, so I don’t think I have that much time to invest.

Any OS, never mind an RTOS is a complex undertaking. Real solutions are most often taken on by teams of developers.

Good luck
 

Ya’akov

Joined Jan 27, 2019
5,513
The project of writing an operating system is a huge undertaking. In order to approach it, you first need to understand a range of things that can literally take many years.

My suggestion is first to look at the source for FreeRTOS and work out what it is doing and why. This will give you a roadmap for both learning and ultimately writing your own OS if you still feel the need. You can also contribute to the FreeRTOS project and in that way learn parts of how it works.

Otherwise, my suggestion would be to engage in practical projects whose outcomes can be tested for success and whose horizons are much closer to the present. In doing that, you can build up the knowledge you need to tackle the much larger projects that might interest you.
 

ApacheKid

Joined Jan 12, 2015
617
Hello everyone

I am yash here I always visit on this forum but posting question first time.
I am planning to write my own RTOS in c language for 32 bit processor cortex M0. I know there are already freeRTOS and other are available. i just want to learn how to design and code it. I don't think there is any harm in learning it. I know RTOS is not necessary for every real time system but it has an advantage.

I already watched youtube videos, read tutorials, visited many websites but I don't have any idea how to start.

I know here are so many experienced software developer's and I hope someone will help
Fascinating as these things can be I'd advise against such an undertaking. I'm a very experienced programmer, likely capable of crafting such a thing but I also know that such a project will fail or lead nowhere without serious planning and design and testing.

Have you studied or looked at existing RTOSs for that CPU? if not you'd need to, need to see how they address certain things what kind of policies they provide and enforce.

The up front research needed before even thinking of writing code is considerable.

Ask yourself why you want to do this, what is the true goal, debugging an OS is perhaps the most challenging kind of testing, crashes can mean there's no way to even begin to debug, there can be no logs, breakpoints etc if the OS itself is unstable.
 

nsaspook

Joined Aug 27, 2009
9,466
Hello everyone

I am yash here I always visit on this forum but posting question first time.
I am planning to write my own RTOS in c language for 32 bit processor cortex M0. I know there are already freeRTOS and other are available. i just want to learn how to design and code it. I don't think there is any harm in learning it. I know RTOS is not necessary for every real time system but it has an advantage.

I already watched youtube videos, read tutorials, visited many websites but I don't have any idea how to start.

I know here are so many experienced software developer's and I hope someone will help
It's usually easier to do a port of a existing OS first to get actual hardware experience on a working codebase. There is a huge amount of background knowledge of HW and SW that's needed even for a simple OS port on a new machine.
https://www.electro-tech-online.com...-mz-ef-development-board.153670/#post-1326054
 

Thread Starter

Yash2019

Joined Jan 5, 2022
7
@MrSalts
Your question is too broad. What answer do you expect from such a broad question? [/QUOTE]

I looking help in planning. I figured out RTOS require preemptive scheduling. It can be implemented on scheduling algorithms

There are many algorithm Which algorithm need to selecct to for RTOS?


I’m an experienced developer but I wouldn’t consider attempting this. It is a complex task and I wouldn’t have the time.
Good luck
I have good knowledge of c language. I can invest my time
 

ApacheKid

Joined Jan 12, 2015
617
@MrSalts
Your question is too broad. What answer do you expect from such a broad question?
I looking help in planning. I figured out RTOS require preemptive scheduling. It can be implemented on scheduling algorithms

There are many algorithm Which algorithm need to selecct to for RTOS?



I have good knowledge of c language. I can invest my time
Such a project should should at some point have a stated set of concrete goals, actual target features at a high level that can serve to guide the work and avoid it just drifting into endless hacking.

Have you seen or looked at examples of these? actual real-world project goals for an OS or RTOS?
 

djsfantasi

Joined Apr 11, 2010
8,256
I figured out RTOS require preemptive scheduling. It can be implemented on scheduling algorithms

There are many algorithm Which algorithm need to selecct to for RTOS?
This question indicates that you are still in the early learning stages. It is so general, it cannot be answered. And if you don’t know why, that’s another sign you are not ready to start designing.
I have good knowledge of c language. I can invest my time
This endeavor takes much more than a “good knowledge of C”.
 

ApacheKid

Joined Jan 12, 2015
617
It is interesting to me that when Bill Gates and Paul Allen decided to create a BASIC interpreter for the Altair all those years ago, they did not have access to an Altair to develop and test the interpreter on.

So Paul Allen wrote an 8080 emulator that ran on a DEC minicomputer and they were able to test and debug the interpreter (which Gates crafted) using that emulator, when the time came to demo it on a real Altair in New Mexico, it worked first time.

This shows a good breakdown of the work, each of them had their own meaty chunk to work on.

Why this is relevant here I don't know! but I was thinking how to debug and test an RTOS and wondered if some kind of emulator would be helpful but then again getting a real ARM is trivial so probably no need (other than fatal crashes could be understood better on an emulator - perhaps...)
 

nsaspook

Joined Aug 27, 2009
9,466
It is interesting to me that when Bill Gates and Paul Allen decided to create a BASIC interpreter for the Altair all those years ago, they did not have access to an Altair to develop and test the interpreter on.

So Paul Allen wrote an 8080 emulator that ran on a DEC minicomputer and they were able to test and debug the interpreter (which Gates crafted) using that emulator, when the time came to demo it on a real Altair in New Mexico, it worked first time.

This shows a good breakdown of the work, each of them had their own meaty chunk to work on.

Why this is relevant here I don't know! but I was thinking how to debug and test an RTOS and wondered if some kind of emulator would be helpful but then again getting a real ARM is trivial so probably no need (other than fatal crashes could be understood better on an emulator - perhaps...)
Most modern 32-bit chips that would be suitable for RTOS development have onboard debugging capabilities or at least the link capabilities for a external debugger.
https://www.electronicdesign.com/technologies/dsps/article/21772644/arm-onchip-debug-hardware
https://riscv.org/wp-content/uploads/2019/03/riscv-debug-release.pdf
When a design progresses from simulation to hardware implementation, a user’s control and understanding of the system’s current state drops dramatically. To help bring up and debug low level software and hardware, it is critical to have good debugging support built into the hardware. When a robust OS is running on a core, software can handle many debugging tasks. However, in many scenarios, hardware support is essential. This document outlines a standard architecture for external debug support on RISC-V platforms. This architecture allows a variety of implementations and tradeoffs, which is complementary to the wide range of RISC-V implementations. At the same time, this specification defines common interfaces to allow debugging tools and components to target a variety of platforms based on the RISC-V ISA. System designers may choose to add additional hardware debug support, but this specification defines a standard interface for common functionality.
 

ApacheKid

Joined Jan 12, 2015
617
If I were seriously looking to do something like this, I'd need to first get a very very detailed and rock solid understanding of the device, how it boots, where it boots from as well as rock solid tools, debuggers, compilers and so on, without the right tools and expert level awareness of the device and device family, I'd simply not bother starting, so that right there is at least several months of solid work as I know only a little about the devices.
 

click_here

Joined Sep 22, 2020
533
I'd say that a good place to start is a project spec.

You said that you have done *lots* of reading on this, so you probably know what you want to do (and patronising you about what a RTOS is, or how much work it is going to be would be a waste of time). I'm going to take your word for your research and coding abilities, and assume that this isn't a second account of another user who was asking simular questions the other day ;)

Back to the problem... Before doing anything: Write a program using the thread notation that you want, and then write down how you want it to behave, the expected output, ect... This should be easy.

You need to get a tight definition of expected behaviour. Also, it might expose things that you didn't think of for your spec earlier...

From there you need to think how it might be done, the best architecture, ect...
 

DickCappels

Joined Aug 21, 2008
8,686
A RTOS does not need to start out big. You could start simple and then branch out to more functionality by just writing a simple multitask manager driven by a periodic interrupt, then create some tasks such as reading and writing I/O to get a taste of where you might want to go with it.

After all, this is for learning and not commercial project with a lot of money at risk.
 

Ian Rogers

Joined Dec 12, 2012
988
A RTOS does not need to start out big. You could start simple and then branch out to more functionality by just writing a simple multitask manager driven by a periodic interrupt, then create some tasks such as reading and writing I/O to get a taste of where you might want to go with it.

After all, this is for learning and not commercial project with a lot of money at risk.
Totally agree.. An RTOS can be made small, here are the "few" components..

https://larrylisky.com/2012/07/14/how-to-create-a-small-rtos/

Then make it do what you want!
 
Top