📜 ⬆️ ⬇️

Compact OS for ARM processors

“It seems that perfection is achieved not when there is nothing more to add, but when there is nothing more to remove."

(Antoine de Saint-Exupery)

image


On the topic of learning programming embedded systems, real-time OS, Assembler and C, let me introduce a very simple operating system StartOS.
')
Purpose:

- if you need to create a device that starts working 1-2 seconds after power on and is able to respond to signals from the outside world within microseconds;
- for quick creation of object management systems with data output to the Internet;
- working out ideas, algorithms, making prototype devices;
- gaining experience in programming embedded systems in the C and Assembler languages;
- obtaining full access to the "hardware" of a computer device, for example, to develop self-modifying programs.

Some properties of the system:

Ready time after power on: <1 s
The amount of binary program code: <40 kB

The system occupies a small amount in the upper addresses of the RAM, providing the user with a standard program load in the lower addresses of the RAM. The autostart of the user program is present, if the system detects the file START.BIN on the memory card, it starts automatically.

The main functions of the system:

Initialization of SoC (System on Chip, systems on a chip) and other external devices. Loading user programs into memory and providing them with an interface to system functions:

- work with LCD in text and graphic modes (text output, pixels, lines, BMP images, save / restore screen area ...);
- input coordinates X, Y pen from the touch screen;
- work with real time clock (RTC);
- reading data from analog-to-digital converters (ADC);
- reading data from digital ports;
- read / write characters and lines in the COM port;
- output to pulse-width modulators (PWM, PWM) and piezo-dynamics;
- input-output packets of the Ethernet network using the built-in controller;
- reading and writing files;
- server-client for the Internet;
- work with a video camera.

The system is implemented on boards of Samsung or FriendlyARM developers with Samsung processors. Full documentation is available on these processors and boards.

So, a little more visual. It is better to see once, so the link to the video:



The system is a bit more complicated for ARM Cortex-A8:



And, of course, the “Hello, World!” Code (with the creeping line to the same):

char txt [ ]={"Hello"}; void Main(void) { int i; for ( i = 134; i > 8; --i ) { // X Y String Print_String ( i, 150, "Hello, World!"); Print_String ( i, 170, txt); Delay (20); // Delay 20 mS } Exit (); // Exit to OS } 

Same on the Assembler:

 ;    , Hello.s.     100  (!) ;       StartOS.c _Exit EQU 7 ; SysTrap _Exit _Delay EQU 10 ; SysTrap _Delay _Print_String EQU 122 ; SysTrap _Print_String PRESERVE8 ;   8  AREA INIT, CODE, READONLY ; . ,   ENTRY ;    ;______     __________ LDR r0, =0x33ffff08 ;    LDR r1, [r0,#0xE8] ; STR r1, [r0] ; ;    ,  . 4  ; MRS r0,cpsr ; BIC r0,r0,#0xDF ; ORR r1,r0,#0x13 ; MSR cpsr_cxsf,r1 ;___     ;   ... ; -           ;----   LDR r2, text1 ;    1   r2 MOV r1,#30 ;  Y     r1 MOV r0,#25 ;  X    r0 SWI _Print_String ;   (Print_String(25,30,text1)) ;----   ---- ADR r2, text2 ;    text 2  r2 MOV r1,#70 ; Y  r1 MOV r0,#25 ; X r0 SWI _Print_String ;  (Print_String(25,70,"Hello, ARM Assembler!")) LDR r0, millis ;      5000  r0 ;     (, 500ms)  : MOV r0,#500 SWI _Delay ;  (Delay 5s) SWI _Exit ;      ,    text1 DCD txt ;   "Hello" text2 DCB "Hello, ARM Assembler!",0 ;      DCB 0,0 ;    32-  (*4 ) millis DCD 5000 ;  5000   5  DCB 0,0 ;  txt DCB "Hello",0 ;   H, e, l, l, o  0 END ;   - ! 

The background to the creation of the system is as follows. The author is aware that writing "home" operating systems is a very responsible, risky business (and doesn’t promise the creators anything but criticism). But as they say, life made. So how did this happen?

It was like this: a board was found for the developers of FriendlyARM Mini2440, very cheap and with a large selection of peripherals. After using Atmel AVR controllers in the applicator of self-adhesive labels, I wanted to continue the development of the latter.

At that time (2010), the Mini2440 cost $ 80, about 2,400 rubles, which was comparable to the cost of the sensors in the applicator. The Mini2440 was demonstrated to the head of one company, who approved its application and assured that “if we succeed in programming it, we will make orders”. Success in programming meant using the device in real time, when signals from the sensors are processed in microseconds, and did not take long to wait. After 2 months, the program, which was wired into NAND, successfully controlled the stepper motor and was loaded 1 second after power up. But here, as it happens, the manager had already fallen into a stupor and just stopped. While he was silent, time passed, and the author decided to use the moment for some development.

In order not to insert the initialization code into the project each time, it was decided to do this once and for all, and load the application programs into the memory from the SD card directly into the memory and run from there.

There is an approach, for example, in ARM7 STM32 controllers, when a user program is compiled along with a proprietary library for working with external devices. In this case, the company does not disclose its proprietary source code, the user program calls the proprietary subroutines at the addresses in memory.

At the same time, the author knew the "insides" of the operating systems, such as DEC's RT-11, we used on Electronics-60, DVK-2 ... 4 and others. Were well studied BIOS IBM PC AT, MS DOS, Palm OS. All of these systems used the classic approach - the use of software interrupts. That is, the OS is located in the upper memory addresses, and the user program is from the beginning of the memory and called the operating system subroutines, passing the number of the program interrupt in the command that actually causes the interrupt.

Thus, in the developed system, the program interrupt mechanism is applied via the SWI command (SVC). The system code is located at the top addresses, and user programs are loaded directly to the beginning of the memory and run. We will not compare with existing systems, suffice it to say that the system turned out with the minimum volume, the maximum possible speed and "hard" real time. We can always know very precisely at what point in time which team is running and what is happening.

The name of the system was conceived as an entry-level system, starting. After Google search, the choice fell on StartOS and this name was registered (sadly, some time later, a Linux clone on some part of the planet was also renamed StartOS).

At the request of users, a TCP IP Stack was added to the system and the Server and Client were made. And added a program to work with a video camera. By the way, after powering on the board, after two seconds a picture from the camera appears on the screen.

Examples of programs are presented to work with almost all external devices mounted on the board. You can create programs in ADS1.2 (Metrowerks CodeWarrior), IAR, Keil, and others.

Documentation, examples and more can be found here and here .

Since the FriendlyARM Mini2440 developer board is already outdated (although it is suitable for many projects), the author has ported the system to a more modern Mini210s board. By the way, many users used StartOS on Samsung boards and successfully.

Regards to the community
Anatoly Poplemenov, engineer

PS: I ask you to take real-time systems seriously, for example, if the system controlling the train hangs, the watchdog will work, it will restart and will work again after 1 second. Not for nothing, the rover Curiosity plows the expanses of Mars under the control of the RT system uCOS company Micrium.

Source: https://habr.com/ru/post/276633/


All Articles