What is porting in RTOS [closed] - porting

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 2 years ago.
Improve this question
I recently started learning about RTOS’s and came across the subject “porting”. I always tought that I could copy the RTOS files from github, paste it in my project and use it without any problems on any device. So I am a little confused about porting. I have two questions:
What is porting in terms of RTOS?
Why do I need porting of RTOS’s?
Thanks in advance,
Arjon

Porting is the act of taking software written to run on one system and modifying it so it runs on another system. From Wikipedia,
In software engineering, porting is the process of adapting software for the purpose of achieving some form of execution in a computing environment that is different from the one that a given program (meant for such execution) was originally designed for
And,
When code is not compatible with a particular operating system or architecture, the code must be [ported] to the new system.
And,
Porting is also the term used when a video game designed to run on one platform, be it an arcade, video game console, or personal computer, is converted to run on a different platform
In other words, you have some software you want to run on a real-time operating system (RTOS). That software was not written to run on RTOS, and will fail unless it is modified accordingly. It must be ported to RTOS before it can run. If you don't port the software, it will not run on the new system.
The nature and scope of those modifications depends on the software and the specific RTOS.

An RTOS interacts directly with processor and platform hardware. When an RTOS is designed to run of different hardware, you necessarily have target specific code to adapt the generic code to the specific hardware and processor architecture.
As a minimum an RTOS requires a system timer generating an interrupt, and to perform context switch it requires direct access to the processor registers in order to restore the context, set the stack pointer for the task to switch to and effect a jump by setting the program counter - that cannot be done with generic code since it requires intimate hardware knowledge.
The "port" of an RTOS requires code written specifically for the target platform including code to handle the timer interrupt, select which timer will be used as the system timer, and effect a context switch. Often much of this code must be written in assembler for direct register access which is necessarily architecture specific.
In addition to the kernel scheduler, depending on the scope of the RTOS in terms of the services it provides, there may be code required to deal with target specific MMU/MPU support and I/O drivers for filesystems, networking etc.

Related

How to do the unit testing on stm32 programming [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
I have STM 32 nucleo board .I have done a program for an embedded functionality. Currently I want to do the unit testing for the functionalities including the peripherals like ADC,SPI,UART..Can anyone suggest the Unit testing framework to test the functionality for the same.
There are two common strategies that I'm aware of:
Make sure you have a good SW component architecture, including a well-defined interface towards HAL/driver components that only take care of access to HW port registers.
Devise a separate verification method for low-level HW-access components, which avoids unit-testing tooling.
To establish such a verification concept, make sure
to avoid any processing logic in HAL/driver components as far as possible.
to avoid any HW dependencies and any non-portable code in the remaining parts of your SW.
Now you can take the HW-free parts of your code to some PC architecture (x86 or whatever) and do all your unit testing with conventional UT tools.
Of course, your UT will miss any errors that are related to the differences between STM32 and your PC.
Note that usually this is not too big a problem because HW-specific features have been "pushed" into the HAL, and in the other parts of the code, you are only looking for logical errors that have nothing to do with the HW/architecture.
I know that this part of the answer talks round your subject instead of providing the solution you were asking for.
Nevertheless, this is what many projects do.
(Develop yourself an STM32 integration for your unit-testing framework, or) buy a commercial unit-testing tool that supports your HW architecture.
STM32 is very popular nowadays, so many commercial tools (Tessy, VectorCast etc.) provide integration that may fit your system.
Note that you also have to select your build toolchain (and possibly the debug adapter) in line with this tool selection, so you have to check some additional constraints.
To get some orientation for your decision between those two strategies, you should consider the question which purpose you are carrying out the unit testing for:
Which kinds of errors are you going to find this way? Which other verification methods are you already applying? Which robustness does your application have to achieve/guarantee - how critical is your application?
Usually, a certain kind/level of criticality corresponds to a certain amount of efforts in order to reduce the probability of residual errors in your software/system as low as reasonably practicable (ALARP). You should make sure to "spend" those efforts in a balanced way so that you find as many errors as possible with every added verification. Unit-testing of low-level code is more tedious and often finds less mistakes (per test case or per working hour) than other sorts of testing.
Do you have to prove a certain level of UT coverage in order to fulfill process criteria like safety standars (e. g., IEC 61508-3 and derived standards), internal company standards, etc.?
Then you have to check what those standards demand for your application, and discuss your strategy with the corresponding assessors.
If such requirements apply to your situation, you will have to convince the assessors that the verification measures applied are sufficient. For professional efficiency, it is crucial that you make up your mind (and start the discussion) which strategy to follow at the beginning of the project.
Edit: I just came across a good discussion of this topic at SoftwareEngineeringStackExchange.
Have a look there.
I suggest Unity the test framework is just a few header files to add to the project. You can augment this with Cmock and Ceedling to build your unit tests on a host machine. You can also use platformio to gather integration test results as shown here. I have not yet figured out if Cmock works on an stm32 board but I may try in the near future.
I have unit tested STM32 code with cmock and ceedling (on Linux) and then some integration tests on target.

FreeRTOS compiler [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 1 year ago.
Improve this question
I just started learning FreeRtos. I have started with "Using the FreeRtos Real Time Kernel" pdf book of Richard Barry.
The book has comprehensive examples and I understood the principles very well but I want to be able to compile this examples somewhere.
Now this may sound like a dumb question but I'm totally new to RTOS :D.
What compiler can I use to compile freeRtos code? I have googled a lot and I found some compiler named Watcom and tried to run some code in it but couldn't and could not find any examples on how to use this compiler.
So basically what I would like is some examples of actually someone showing how to run simple freeRtos code in a compiler then run it and see the actual results in a console.
Any links would be appreciated. Thank you for reading!
FreeRTOS supports a large range of compilers. The officially supported compilers for each officially supported port are listed on the Official FreeRTOS Ports page.
You can use any of the compilers listed (and probably more, but they won't be officially supported). In general, you should be able to keep using what you already use, since FreeRTOS typically supports the standard vendor-supplied compiler of whatever platform you are using.
Normally you run a FreeRTOS application in a stand-alone environment - ie, the system boots directly into your application rather then being loaded by an OS (there may be an intermediate bootloader in some cases).
There is no concept of a "console" in FreeRTOS itself; your application must implement support for stdio or low-level I/O, typically via a UART and a terminal emulator running on the development host or by using semi-hosting via your debugger. This is a mater of porting your standard library rather than an issue for FreeRTOS. The standard library should have some sort fo pirting layer (known as "syscalls" in Newlib, or "Retargetting" in ARM/Keil toolchains for example).
FreeRTOS applications are built using cross-development tools rather than hosted development environments. That is the code is build on a development host using a cross-compiler then loaded to the target hardware and executed. There is a Win32 port of FreeRTOS that allows FreeRTOS applications to be built and executed on a Windows host, but the port is only a simulation, and does not provide hard-real-time scheduling. It is useful for development before hardware is available and testing and debugging using the more sophisticated debugging environment provided by Visual Studio that that typically available to embedded targets.
What you would normally do is select a hardware platform that FreeRTOS supports and meets your application needs, then select a toolchain that supports your hardware platform and is in turn supported by FreeRTOS. For most 32 bit platforms and the 8-bit AtmelAVR platform GNU gcc is near ubiquitous, and many proprietary compilers support GNU extensions for compatability. Unless you choose a particularly obscure toolchain/target combination, you are unlikely to not be able to either port to use an existing port of FreeRTOS.
You can use System Workbench for STM32 if you are using a STM32 based board. System Workbench utilized GCC based compiler and it is very enjoyable to use. You can easily download the wholly cross-platform IDE and the compiler tool from the following link:
System Workbench for STM32

Best IDE for PLC ladder programming [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
Recently I trying to learn Ladder Logic programming for PLCs, but I want to know if there is any IDE to create Ladder programs better that Step7 or cx-programmer? Is there any plugin for Visual Studio or Netbeans that I can use? Finally, is it better to work with PLCs under Linux or Microsoft Windows?
UPDATE 1 : After googling about this, I found out that Ladder programming is not depend on the PLC brand or its model, so I did not mentioned any brand in my question.
What is your goal? In almost all cases, your IDE is dictated by the PLC manufacturer, and your PLC brand is spec'd by the customer when they buy the machine. They spec the PLC because they need to have something that they can go online with for maintenance and troubleshooting. Since the software is proprietary and absurdly expensive, they don't want to get a new software license for every machine in the plant and have to relearn new software, while they are bleeding money of manufacturing downtime.
So if your goal is to enter the industry, you want to find out what plants in country tend to use. In North America it's usually Allen-Bradley a.k.a Rockwell Automation, which is programmed with RSLogix 5000 (edit: the recent versions of RSLogix 5000 have been rebranded as Studio 5000). In Europe, it's typically Seimens, but I have no experience with them.
PLC IDEs are almost always picked hardware first. With some obscure exceptions, you pick the hardware you want to run, and this determines the IDE. The IDEs are all proprietary and unique to each hardware platform. Rockwell Automation alone has three different IDEs to support their hardware lines, all licensed individually and very expensive.
If Omron is the most common in your area, it's a good idea to start with them. Once you get used to one type of PLC, learning more is really easy.
If you don't mind which PLC platform you're using, I really enjoyed my time with RSLogix. They have a free, training-level suite available here:
http://www.ab.com/linked/programmablecontrol/plc/micrologix/downloads.html
I prefer RSLogix 5000. It's one of the easiest to work with and has User Defined Types and Add On Instructions to help with reusability.
ABB has Control Builder (which is the product that I work on), AFAIK when somebody buys our AC800 controller they get the CB for free, at least the so called "Compact version" which is file based. The CB has ladder diagrams as well as all other 1131 languages plus some extensions like Function Diagrams.
Disclaimer Sorry if it sounded like an ad, just very passionate with what I work on.
I am primarily a high level language programmer, but have also done development on various PLC /PAC platforms, including Rockwell, Siemens, and Beckhoff.
If your goal is to merely get an introduction to ladder, nearly anything will due. You can download Beckhoffs TwinCAT software for free. It is only a 30-day license, but you can just continually reinstall every 30 days without issue. The great part of TwinCAT is that it runs on a Windows PC, so you can develop and test code directly on the PC and don't need actual Beckhoff hardware to play with. The ladder is a bit quirky, but the statement list portion is by far one of the more powerful. If you are a C-programmer you will feel very comfortable with Beckhoff, because they have duplicated a lot of C-like functions (e.g. memcpy and setcpy) into their libraries.
The Beckhoff platform is not all that widespread, but it would allow you to learn the principals of ladder and PLC/PAC programming.

PIC Microcontroller Operating System [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I heard it is possible to write an Operating System, using the built in bootloader and a kernel that you write, for the PIC microcontroller. I also heard it has to be a RTOS.
Is this true? Can you actually make an operating system kernel (using C/C++) for PIC?
If yes to 1, are there any examples of this?
If yes to 1, would you need any type of software to create the kernel?
Is Microchip the only company that makes PIC microcontrollers?
Can the PIC microcontroller be programmed on a mac?
Thanks!
Yes, you can write your own kernel (I have written 2 of my own). Yes you can write it in C for PIC. If you want pre-emptive scheduling, then you're going to have a real tough time avoiding assembly completely when writing the context switch. On the other hand, you can easily write a cooperative kernel purely in C (I have done this myself). (Note that creating an operating system is not a simple task... I'd get your feet wet in pure C first, then USE an OS or two, then try creating one.)
An excellent example of this is FreeRTOS. It has preexisting ports (i.e. MPLAB projects that run without any modification on the Explorer16 demo board) for PIC24F, PIC33F, and PIC32MX (as well as 20-some odd other official ports for other vendors' devices). PIC18F is supported but it's not pretty...
You only need MPLAB to create the kernel (free from Microchip). It can work interchangably with C and assembly. Depending on the processor, there are free versions of their C30 and C32 compilers to go with MPLAB.
PIC is a type of microcontroller, and is a trademark of Microchip. Many other companies make microcontrollers and call them something else (e.g. AVR, LPC, STM32).
Yes, the new version of MPLAB X is supported on Mac, Linux and Windows.
I suggest you check out FreeRTOS.
I second the vote for FreeRTOS; we use this all the time on PIC24 designs. The port works well and doesn't use a ton of memory.
Microchip supports many third party RTOSes.
Most have free demo projects that you can download, build in MPLAB, and program onto an Explorer16 board very easily. You can then experiment to your heart's content.
PIC is not a single architecture. PIC10 differs considerably from PIC24, though they and every PIC in between share some commonality. The MIPS based PIC32 on the other hand is an entirely different architecture. So you have to be clear about what PIC you are referring to.
An OS on a PIC does not have to be and RTOS, but that would be ideally suited to the application domain the devices are used in, so anything that were not real-time capable would be somewhat less useful.
There are many RTOS ports already for PIC.
There is nothing special about about a kernel scheduler in terms of development method, C and in most cases a little assembler are all that are necessary - no special tools. You could use 100% assembler if you wished, and this might be necessary to get the smallest/fastest code, but only if your assembler knowledge is better than the compiler's.
PIC is specific to Microchip, though Parallax SX is more or less a clone. Unlike ARM for example, Microchip do not licence the architecture to third-party chip manufacturers or IP providers. No one would want it in any case IMO; there are far better architectures. ARM Cortex-M is particularly suited to RTOS kernel implementation, and AVR's instruction is designed for efficient translation from C source code. Even the venerable 8051 is well suited to RTOS implementation; its eight register banks make context switches very fast (for up to eight threads), and like ARM, 8051 architecture devices are available from multiple manufacturers.
The hardware stack of PIC 18F CPU is only 31 bytes long. Other RAM memory cannot be used as stack. Even 8051 IRAM memory has 128 byte of stack. I have done RTOS for 8051, ARM and PIC 18F, and feels not good at PIC 18F. If the RAM(16K to 64K) of PIC32 can be used as stack, if the stack pointer is 16 bit long, it will be much better than PIC18F types. Does any one knows that?

Developing an operating system for the x86 architecture [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am planning to develop an operating system for the x86 architecture.
What options of programming languages do I have?
What types of compilers are there available, preferably on a Windows environment?
Are there any good sources that will help me learn more about operating system development?
Is it better to test my operating system on a Virtual Machine or on physical hardware?
Any suggestions?
For my final year project in collage I developed a small x86 OS with a virtual memory manager, a virtual file system and fully preemptive multitasking. I made it open source and the code is heavily commented, check out its source forge page at:
https://github.com/stephenfewer/NoNameOS
From my experience I can recommend the following:
You will need x86 assembly language for various parts, this in unavoidable, but can be kept to a minimum. Fairly quickly you will get running C code, which is a proven choice for OS development. Once you have some sort of memory manager available you can go into C++ if you like (you need some kind of memory manager for things like new and delete).
No matter what language you choose you will still need assembly & C to bring a system from boot where the BIOS leaves you into any useable form.
Ultimately, the primary language you choose will depend on the type of OS you want to develop.
My development environment was the Windows port of the GNU development tools DJGPP along with the NASM assembler. For my IDE I used IBM's Eclipse with the CDT plugin which provides a C/C++ development environment within Eclipse.
For testing I recommend BOCHS, an open source x86 PC emulator. It lets you boot up your OS quickly which is great for testing and can be integrated into eclipse so you can build and run your OS at the push of a button. I would also recommend using both VMWare and a physical PC occasionally as you can pick up on some subtle bugs that way.
P.S. OS development is really fun but is very intensive, mine took the best part of 12 months. My advice is to plan well and your design is key! enjoy :)
Language and compiler depend entirely on what you're attempting to accomplish. I would suggest, though, that you might be approaching the problem from too low a level.
There are materials out there on operating system fundamentals. MIT has OpenCourseware on the subject. Read through Andrew Tannenbaum's Operating Systems series, and look at things like Minix.
Get an idea for what's out there. Start tinkering with things. Borrow ideas, and see where they go. You can reinvent the wheel if you really want, but you'll learn more by building on the works of others.
It doesn't really matter, what language you choose. If the language is Turing-complete, then you can write an OS in it.
However, the expressiveness of the language will make certain kinds of designs very easy or very hard to implement. For example, the "liveliness" and dynamism of the old Smalltalk OSs depends on the fact that they are implemented in Smalltalk. You could do that in C, too, but it would probably be so hard that you wouldn't even think about it. JavaScript or Ruby OTOH would probably be a great fit.
Microsoft Research's Singularity is another example. It simply couldn't be implemented in anything other than Sing#, Spec# and C# (or similar languages), because so much of the architecture is dependent on the static type safety and static verifiability of those languages.
One thing to keep in mind: the design space for OSs implemented in C is pretty much fully explored. There's literally thousands of them. In other languages, however, you might actually discover something that nobody has discovered before! There's only about a dozen or so OSs written in Java, about half a dozen in C#, something on the order of two OSs in Haskell, only one in Python and none in Ruby or JavaScript.
Try writing an OS in Erlang or Io, and see how that influences your thinking about Operating Systems!
There is an OS course offered at the University of Maryland that utilizes GeekOS. This is a small, extensively commented OS designed for educational purposes which can be run using the Bochs or QEMU emulators.
For an example of how it is used in a course, check out a previous offering of the course at the class webpage. There, you will find assignments where you have to add different functionality to GeekOS.
Its a great way to get familiar with a small and simple OS that runs on the x86 architecture.
You might want to look up XINU. it's a tiny OS for x86 that isn't really used for anything other than to be dissected by students.
Use ANSI C, and start off with an emulator.
When you port over to a real machine, there will be some assembler code. Context switching and interrupt handling (for instance) is easier to write in assembler.
Andy Tannenbaum has written a good book on OS. Many other good ones exist.
Good luck! There is nothing quite like haveing written your own OS, however small.
Also check out the OSDev.org which have all information you need to get started.
I've done that once for a 386SX, which was on a PCI board. A good source on how to start a X86 cpu in protected mode is the source code of linux. It's just a few assembly statements. After that you can use gcc to compile your C code. The result is objectcode in ELF format. I wrote my own linker, to make a program out of the objectcode. And yes, it worked! Good luck.
Be sure to check out the answers to my question:
How to get started in operating system development
Without a doubt, I'd use Ada. It's the best general-purpose systems-programming language I have come across, bar none. One example, Ada's much better for specifying bit layout of objects in a record than C. Ada also supports overlaying records on specific memory locations. C requires you to play with pointers to acheive the same effect. That works, but is more error-prone. Ada also has language support for interrupts.
Another: Safety. Ada defaults to bound checking array assignments, but allows you to turn it off when you need it. C "defaults" to no bound checking on arrays,so you have to do it yourself manually whenever you want it. Time has shown that this is not the right default. You will forget one where it is needed. Buffer overflow exploits are the single most common security flaw used by crackers. They have whole websites explainng how to find and use them.
As for learning about doing this, the two books I'm aware of are XINU (Unix backwards, nothing to do with Scientology), and Project Oberon. The first was used in my Operating Systems graduate course, and the second was written by Nikalus Wirth, creator of Pascal.
If you are making a full OS, you will need to use a range of languages. I would expect Assembly, C and C++ at the very least.
I would use a Virtual Machine for most of the testing.
C most probably...all major OS-es have been written in C/C++ or Objective-C(Apple)
If you want write an OS then you need a couple of people. A OS can not write a single people. I think it is better to work on existing OS projects
Reactos --> C, Assembler
SharpOS --> C#
JNode --> Java
This is only a short list of OS projects. How you can see there is a project for every possible language.