ARM Cortex M3 (i)
Operating Systems in Industrial
Applications
5 Operating Systems
Industrial computing often deals with the
programming of small systems without
many resources.
If we increase the complexity of the hardware or the
algorithms to be used, we will need another application
that offers us the functions of the system
Operating System
Industrial application
•
runs in user mode
Operating System
•
in supervisor mode
Application
industrial
Operating System
Hardware
2
5 Operating Systems
Task or Process Program running
Task is any program that is loaded in
memory from which it is processed by the CPU.
Characteristics of the tasks
They should be as independent as possible from the rest of the tasks.
They should not share data with other tasks
Will have systems to exchange information with external (I / O)
and with the rest of tasks (synchronization)
Will have own memory areas [19659002] 3
5 Operating Systems
Multitasking
Monotarea.
Computer system that can only maintain one
application program loaded in memory simultaneously
Multitasking.
Allows several programs simultaneously
Parallelism of fat grain. -> It gives the feeling that several
independent jobs are executed in parallel
It takes advantage of the waiting times of a task for
to execute other tasks instructions
4
5 Operating Systems
Processes
The Operating System is responsible for managing time,
synchronizing and communicating with each other processes
Allows tasks to work while others wait for other events [19659002] In the same system there may be real-time tasks with
tasks without strict temporal requirements
The Operating System is responsible for ensuring that they
comply with the tasks of TR
5
5 Operating Systems
Time of
wait for
events
Task for
real time
Planific
ad
Task for
real time [19659002] Task with
operations of
I / O
Despac
hador
CPU
Task in
execution
Time
of
computation
Time of
] access to
I / O
STOP
task of
computation
intensive
Figure -. Collaboration between planner and dispatcher.
6
5 Operating Systems
Processes
Process Can be viewed as resource containers
Tasks that execute code
Memory
File descriptors
] Objects that indicate software or hardware elements that are in use
7
5 Operating Systems
If an application needs to perform more than one
job, how do we structure it?
Solution 1
Make an application that executes in order all the work
that must be done.
Advantages
Simple
Disadvantage
Not efficient. If one of the jobs is accessing hardware, the entire
application must wait for the hardware to respond
8
5 Operating Systems
If an application needs to perform more than one
job How do we structure it?
Solution 2
Divide the entire application into jobs, and assign each of them to a
process.
If I need to communicate data between them, use communication methods
between processes (pipes, sockets, memory buffers, …)
Advantages
You can increase the performance of the application
Decreases the response time by the ejec. parallel
Disadvantage
Resources are duplicated
Interprocess communication can become slow
9
5 Operating Systems
If an application needs to make more than one [19659002] work, how do we structure it?
Solution 3
Allow a parallel execution of the different works in the same
process
I do not need to communicate data between the flows, since these can access
to all the resources [19659002] Subprocesses (or light
processes or threads)
10
5 Operating Systems
The process is a container of the resources used by the
application
Memory
File descriptors
Objects that indicate software or hardware elements that are in use
Y ……………. threads used
11
5 Operating Systems
Threads
Each process will have at least one thread
Threads are code execution entities, tasks that [19659002] share resources
State of a thread defines it
Its own stack [196590] 02] The registers of the user-level processor
An internal structure of the core with additional information of the status of
thread
In the stack is where the fundamental part of its
state is stored , which mainly includes its state
12
5 Operating Systems
Threads
All resources are shared by all threads of the process
Global variables and dynamic memory (as we saw is in the area of
memory allocated to the code part) will be shared by all
processes Concurrency problem
13
5 Operating Systems
Threads
States of one thread
List
Blocked
Running
Finished
14
5 Operating Systems
Wire Creation.
Multithreaded operating systems offer users the
way to create threads.
We in this subject will be based on a System
Operational supported by Cortex-M3: RTX.
RTX is a real-time operating system created for
devices based on the Cortex-M processor. The Kernel of
RTX can be used to create applications that perform several
tasks at the same time. It allows the programming of user applications
using the C and C ++ standard and compiled with
ARMCC, GCC or IAR compilator.
15
5 Operating Systems
Thread Creation.
The CMSIS-RTOS is an API (Application Programming Interface)
common for RTOS. It provides a standard programming interface that
is portable for many RTOS and therefore allows templates of
Software, middleware, libraries and other components supported by RTOS
RTX CMSIS-RTOS manages resources of the micro implements the
concept of parallel threads that run simultaneously.
16
5 Operating Systems
Thread Creation.
osThreadId osThreadCreate (const osThreadDef_t * thread_def, void * argument)
Create a thread and add it to the list of Active Threads in the state of READY
Parameters:
[19659002]
[entrada] thread_def Pointer to a thread definition made by osThreadDef and referenced by
osThread.
[entrada] argument Pointer to a variable that is passed to the thread function as an argument of
input. t.
returns: ID of the thread to be referenced by other functions or NULL in case of error.
Starts thread assigned to a function and adds it to the active thread list, establishing its status as
READY. The function of the thread receives the argument as argument of the function when it is
started. When the priority of the created thread function is higher than the RUNNING thread, the created thread
starts immediately and becomes the new RUNNING thread.
17
5 Operating Systems
Creation of Threads.
The definition of a thread is carried out in two phases:
First the function to be executed is defined
void FuncionHilo (void const * arg);
The thread type is then defined
osThreadDef (funtion_name, priority, instances, stacksize)
The priority of the thread will have the values
osPriorityIdle = -3,
osPriorityLow = -2,
osPriorityBelowNormal = -1,
osPriorityNormal = 0,
osPriorityAboveNormal = +1,
osPriorityHigh = +2,
osPriorityRealtime = + 3,
osPriorityError = 0x84
Instances: maximum number of threads with this definition that will be created.
StackSize. Size of the thread stack (in bytes). 0-> Standard size.
18
5 Operating Systems
19
5 Operating Systems
Thread Creation.
Example
#include "cmsis_os.h"
void Thread_1 (void const * arg); // function prototype for Thread_1
osThreadDef (Thread_1, osPriorityNormal, 1, 0); // define Thread_1
void ThreadCreate_example (void) {
osThreadId id;
id = osThreadCreate (osThread (Thread_1), NULL); // create the thread
if (id == NULL) [19659002] {// handle thread creation
// Failed to create a thread
}
osThreadTerminate (id); // stop the thread
}
20
5 Operating Systems [19659002] Creation of threads.
osThreadId osThreadGetId (void)
Returns the identifier osThreadId of the thread that calls it
osStatus osThreadTerminate (osThreadId thread_id)
Finishes the execution of the thread that calls it and it deletes it from the list of Active Threads.
osStatus osThreadSetPriority (osThreadId thread_id, osPriority priority)
C set the priority of the thread thread to the priority priority.
21
5 Operating Systems
Concurrency
If two systems intend to simultaneously use the same
resource they are said to use it concurrently [19659002] That may cause errors
of code modifications of shared memory.
Hardware device data corruption
22
5 Operating Systems
Code in C language
int main (int argc, char ** argv)
{
int iNum , iCubo, iCont;
printf ("Enter a number:");
scanf ("% d", & iNum);
iCubo = iNum;
if (! CheckNumber (iNum))
{
printf ("Invalid number");
return -1;
}
for (iCont = 0; iCont <2; ++ iCont)
iCube * = iNum;
printf (" nThe cube of% d is% d n",
iNum, iCubo);
return 0;
}
int CheckNumber (int num)
{
if (num> 1000)
return 0;
return 1;
}
23
5 Operating Systems
Code in C language
int main (int argc, char ** argv)
{
int iNum, iCubo, iCont;
printf ("Enter a number:");
scanf ("% d", & iNum);
iCubo = iNum;
if (! CheckNumber (iNum))
{
printf ("Invalid number");
return -1;
}
for (iCont = 0; iCont <2; ++ iCo
.
from Nettech Post http://bit.ly/2FEizWZ
No hay comentarios:
Publicar un comentario