When used to the use of bare metal and began to feel that there are a lot of things not perfect, especially when encountering one of the delay function in the run when the special embarrassment, a lot of things can not be done, only wait until the completion of this thing delay to continue I use the board is STM32F4VET6 board ...
There are many ways to implement "at the same time" to run multiple tasks (the FPGA that is meant to be processed in parallel is no longer necessary)
1. Interrupts
2. State machine
3. Embedded OS
Of course, the most recommended is the use of embedded OS, in a number of embedded OS, the choice of a lot of, linux,ucos,freertos and so on
In the industrial control industry to use the most and easy to learn should be considered Ucos, and Ucos is divided into II and III, you can directly start UCOSIII, more functions, the use of a large number of people.
Recommended information: "Embedded RTOs uc/os-iii"--jean J. Labrosse "embedded real-time operating system UC/OS-III application Development"--jean J. Labrosse on-the-fly Atom UCOSIII Tutorial
In accordance with the tutorial on the right atom of the LED source code, directly transplanted into the UCOSIII, in fact, the transplant process is a variety of copy replacement, although still do not understand the specific reasons for this replacement but still do, Now only need to know how to use the API function call and the entire operating system composition and the functions of the various parts, and so on after the use of proficiency to seriously learn Ucos source.
After porting the UCOSIII and using the Task Scheduler to make the LED lights shine, this becomes my first UCOSIII project and can also be a template for all other projects. It is necessary to look back at some of the problems in the project after the migration:
Tick Timer Systick(This timer is exactly the same as in the authoritative guide for CORTEXM3,M4, you can refer to the authoritative guide for inquiries)
This timer is designed to use a timer dedicated to the operating system, creating a heartbeat rhythm for the OS and, of course, making some high-precision delays.
* * consists of 4 registers:
Control and Status registers
Reload Registers
Current Value Register
Calibrating a value register (usually not used) * *
There are altogether 3 files under the System folder provided by the punctual atom
sys.c/h
delay.c/h
usart.c/h
where sys.c/h and bare metal use the same code.
The tick timer is used in the DELAY.C to delay the operation.
#if system_support_os //If system_support_os is defined, it indicates that the OS is supported (not limited to ucos).
Macro Definition Content
#endif
Many are content that is compiled only after the operating system has been defined
void Delay_init (U8 sysclk)
{
#if system_support_os //if required to support OS.
U32 Reload;
#endif
Systick_clksourceconfig (SYSTICK_CLKSOURCE_HCLK_DIV8);//systick uses an external clock source
FAC_US=SYSCLK/8; Whether you use Os,fac_us or not, you need to use
#if system_support_os //If you need to support the OS.
RELOAD=SYSCLK/8; The number of units per second is K
reload*=1000000/delay_ostickspersec; According to Delay_ostickspersec set overflow time
//reload is 24 bit register, maximum value: 16777216, at 72M, about 1.86s or so
Fac_ms=1000/delay_ ostickspersec; Represents the minimum unit systick->ctrl|=systick_ctrl_tickint_msk;//the OS can delay to
turn on SysTick interrupts
systick->load=reload; Interrupts once per 1/os_ticks_per_sec second
systick->ctrl|=systick_ctrl_enable_msk; Open Systick
#else
fac_ms= (U16) fac_us*1000; Non-OS, represents the number of systick clocks required for each Ms
#endif
}
Clock-selected external clock (168M clock)
sysclk=168
Fac_us=168/8=21 (regardless of whether the OS is defined, this is required)
Reload (this is going to reload in the tick timer)
Delay_ostickspersec is the heartbeat frequency, you can see the source of the definition, this is the 200Hz
That is, every 1000000/delay_ostickspersec (US) heartbeat once, 5ms heartbeat once.
Systick frequency 21MHz, cycle time is 1/21 us
The value of the reload should be
21*1000000/delay_ostickspersec
So if you want to use a different heartbeat, you just need to modify the corresponding heartbeat frequency parameter definition.
In Delay_us and Delay_ms, if the delay time is less than the heartbeat time, task scheduling cannot be caused by using delay.
usart.c file changes in the serial interrupt function add two more words
#if system_support_os //using Ucos operating system
osintenter ();
...//The contents of the interrupt function
#if system_support_os
osintexit (); Exit Interrupt
#endif
Write interrupt function later also need to write Osintenter () and Osintexit ()
The rest of the same.
In short, now successfully transplanted UCOSIII operating system, further learning Ucos task management knowledge, including task creation, deletion, and various tasks of switching.